turbo-editors/turbo-corepublic Fork 0
v1.0.2
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

trace_test.go · 67 lines · 2.1 KBGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 15h ago1package acp_test
2
3import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8
📦 Turbo Core f3ade8d k33g 8h ago9 "rickub.com/turbo-editors/turbo-core/acp"
🛟 Updated. 28d5985 k33g 15h ago10)
11
12func TestAnUpdateThatCannotBeDecodedIsCountedAndNamed(t *testing.T) {
13 session, agent := start(t, acp.Options{})
14 id := agent.handshake()
15 waitFor(t, "ready", session.Ready)
16
17 // input as a string, where the protocol has an object. An agent that did
18 // this would otherwise have its commands vanish without a trace.
19 agent.update(id, `{"sessionUpdate":"available_commands_update","availableCommands":[{"name":"web","input":"query"}]}`)
20 agent.update(id, `{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"still here"}}`)
21 waitFor(t, "the message after it", func() bool {
22 return textOf(session.Entries(), acp.EntryAgent) == "still here"
23 })
24
25 if session.Unknown() != 1 {
26 t.Errorf("Unknown() = %d, want the undecodable update counted", session.Unknown())
27 }
28 got := session.Unreadable()
29 if !strings.HasPrefix(got, "available_commands_update: ") {
30 t.Errorf("Unreadable() = %q, want it to name the update's kind", got)
31 }
32 if len(session.Commands()) != 0 {
33 t.Error("a half-decoded command list was kept")
34 }
35}
36
37func TestTheTraceRecordsEachLineInEachDirection(t *testing.T) {
38 path := filepath.Join(t.TempDir(), "acp.log")
39 t.Setenv(acp.TraceEnv, path)
40
41 agent, stream := newFakeAgent(t)
42 session := acp.NewSession(acp.TraceStreamForTest(stream), acp.Agent{Name: "Bob"}, t.TempDir(), acp.Options{})
43 agent.handshake()
44 waitFor(t, "ready", session.Ready)
45 _ = session.Close() // flushes the trace
46
47 data, err := os.ReadFile(path)
48 if err != nil {
49 t.Fatalf("reading the trace: %v", err)
50 }
51 text := string(data)
52
53 for _, want := range []string{"-> ", `"method":"initialize"`, "<- ", `"sessionId"`} {
54 if !strings.Contains(text, want) {
55 t.Errorf("the trace lacks %q:\n%s", want, text)
56 }
57 }
58 lines := strings.Split(strings.TrimSpace(text), "\n")
59 if len(lines) != 4 {
60 t.Errorf("the trace has %d lines, want the four messages of a handshake:\n%s", len(lines), text)
61 }
62 for _, line := range lines {
63 if !strings.Contains(line, " -> ") && !strings.Contains(line, " <- ") {
64 t.Errorf("a traced line has no direction mark: %q", line)
65 }
66 }
67}