| 1 | package thin |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/wire" |
| 9 | ) |
| 10 | |
| 11 | // The coordinator's first frame keeps what does not change between |
| 12 | // sessions first (the house rule, the catalog, the notebook) and what |
| 13 | // does (the conversation so far, what an earlier attempt did, the |
| 14 | // newest message, attachment ids) after it, so a provider's prompt |
| 15 | // cache can hold the stable prefix: two fresh sessions that differ only |
| 16 | // in volatile values share it byte for byte. |
| 17 | func TestCoordinatorPromptStablePrefix(t *testing.T) { |
| 18 | desk, err := OpenDesk(t.TempDir(), "p@example.com") |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | at := time.Date(2026, 11, 7, 9, 0, 0, 0, time.UTC) |
| 23 | if err := desk.SaveEntries([]wire.NotebookEntry{{ID: "n1", Source: wire.NotePerson, Text: "Short replies, please.", At: at}, {ID: "n2", Source: wire.NoteRepo, Repo: "oficina/sample", Path: "README.md", Text: "Sample is the demo app.", At: at}}); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | catalog := []wire.RepoInfo{{Repo: "amadan.net/oficina/sample", Names: []string{"sample", "Woodstar"}, Summary: "The demo app."}} |
| 27 | frame := func(n int, text string, tail []wire.TailMessage, done []string) string { |
| 28 | c := &coordBase{person: "p@example.com", desk: desk, profile: profileFor(wire.LaneCoordinator)} |
| 29 | p, _ := c.prompt(true, TurnInput{Person: "p@example.com", TurnID: "t" + strings.Repeat("x", n), Kind: wire.TurnPerson, Text: text, Tail: tail, Done: done}, catalog) |
| 30 | return p |
| 31 | } |
| 32 | a := frame(1, "Fix the typo at 09:14.", []wire.TailMessage{{Role: wire.RolePerson, Text: "Hello at 09:00"}}, nil) |
| 33 | b := frame(2, "What changed since 2026-11-10, 3 tasks?", []wire.TailMessage{{Role: wire.RolePerson, Text: "Morning"}, {Role: wire.RoleCoordinator, Text: "Hi, 4 open tasks."}}, []string{"record_task: tk123"}) |
| 34 | // The stable part runs up to the conversation so far; the other |
| 35 | // session's frame starts with the same bytes. |
| 36 | cut := strings.Index(a, "\nConversation so far") |
| 37 | if cut < 0 { |
| 38 | t.Fatalf("no conversation in the frame:\n%s", a) |
| 39 | } |
| 40 | prefix := a[:cut] |
| 41 | if !strings.HasPrefix(b, prefix) { |
| 42 | t.Fatalf("the stable part differs between sessions:\n%s\n---\n%s", a, b) |
| 43 | } |
| 44 | for _, stable := range []string{"You are the Equipo coordinator for p@example.com.", "Repositories you can reach", "oficina/sample [Woodstar]: The demo app.", "=== Your notebook", `"Short replies, please."`, "=== End of notebook ==="} { |
| 45 | if !strings.Contains(prefix, stable) { |
| 46 | t.Fatalf("the shared prefix lacks %q:\n%s", stable, prefix) |
| 47 | } |
| 48 | } |
| 49 | for _, volatile := range []string{"Newest message", "Already done", "09:14", "Hello at 09:00", "Morning", "tk123"} { |
| 50 | if strings.Contains(prefix, volatile) { |
| 51 | t.Fatalf("the shared prefix holds %q:\n%s", volatile, prefix) |
| 52 | } |
| 53 | } |
| 54 | // The tail still comes before the newest message, and the rule's |
| 55 | // "the conversation below" still points at it. |
| 56 | if i, j := strings.Index(a, "Conversation so far"), strings.Index(a, "Newest message:\nFix the typo"); i < 0 || j < i || !strings.Contains(prefix, "Treat the conversation below as context") { |
| 57 | t.Fatalf("frame order:\n%s", a) |
| 58 | } |
| 59 | } |
| 60 | |