1package agent
2
3import (
4 "strings"
5 "testing"
6 "time"
7)
8
9func TestBuildSystemPromptAlwaysIncludesFinalWritingGuidance(t *testing.T) {
10 for _, tt := range []struct {
11 name string
12 custom string
13 }{
14 {name: "default"},
15 {name: "custom", custom: "custom identity"},
16 } {
17 t.Run(tt.name, func(t *testing.T) {
18 const conflictingAddendum = "Always use ceremonial language."
19 prompt := BuildSystemPrompt(SystemPromptOpts{
20 Custom: tt.custom,
21 Append: []string{conflictingAddendum},
22 })
23
24 if count := strings.Count(prompt, writingGuidance); count != 1 {
25 t.Fatalf("writing guidance count = %d, want 1:\n%s", count, prompt)
26 }
27 if strings.Index(prompt, writingGuidance) < strings.Index(prompt, conflictingAddendum) {
28 t.Fatalf("writing guidance must follow appended context:\n%s", prompt)
29 }
30 for _, want := range []string{
31 "medium, audience, and reader's immediate need",
32 "plain, precise language",
33 "verified facts",
34 "descriptive links, and accessibility",
35 "Do not manufacture slang, errors, hesitation",
36 "Revise silently",
37 } {
38 if !strings.Contains(prompt, want) {
39 t.Errorf("writing guidance missing %q:\n%s", want, prompt)
40 }
41 }
42 })
43 }
44}
45
46func TestBuildSystemPromptAddsCompactionHandoffToCustomPrompt(t *testing.T) {
47 prompt := BuildSystemPrompt(SystemPromptOpts{Custom: "custom identity"})
48 if !strings.Contains(prompt, "custom identity") {
49 t.Fatalf("custom prompt missing:\n%s", prompt)
50 }
51 if !strings.Contains(prompt, compactedSummaryHandoffInstruction) {
52 t.Fatalf("custom prompt missing compaction handoff:\n%s", prompt)
53 }
54 if count := strings.Count(prompt, compactedSummaryHandoffInstruction); count != 1 {
55 t.Fatalf("compaction handoff count = %d, want 1:\n%s", count, prompt)
56 }
57 for _, want := range []string{"most recent unresolved user request", "newer user request", "without waiting for the user to type \"continue\""} {
58 if !strings.Contains(prompt, want) {
59 t.Fatalf("compaction handoff missing %q:\n%s", want, prompt)
60 }
61 }
62}
63
64func TestBuildSystemPromptCustomOmitsBuiltInDocs(t *testing.T) {
65 got := BuildSystemPrompt(SystemPromptOpts{
66 CWD: "/workspace",
67 Custom: "Custom instructions",
68 Append: []string{"Additional context"},
69 Now: time.Date(2026, time.August, 6, 0, 0, 0, 0, time.UTC),
70 ZutDocsDir: "/zut/docs",
71 })
72
73 if strings.Contains(got, "Zut's own docs") || strings.Contains(got, "/zut/docs") {
74 t.Fatalf("custom prompt includes built-in docs guidance:\n%s", got)
75 }
76 for _, want := range []string{
77 "Custom instructions",
78 "Additional context",
79 "Current date: 2026-08-06",
80 "Current working directory: /workspace",
81 } {
82 if !strings.Contains(got, want) {
83 t.Errorf("custom prompt missing %q:\n%s", want, got)
84 }
85 }
86}
87
88func TestBuildSystemPromptDefaultIncludesBuiltInDocs(t *testing.T) {
89 got := BuildSystemPrompt(SystemPromptOpts{
90 CWD: "/workspace",
91 Now: time.Date(2026, time.August, 6, 0, 0, 0, 0, time.UTC),
92 ZutDocsDir: "/zut/docs",
93 })
94
95 if !strings.Contains(got, "Zut's own docs are installed under /zut/docs") {
96 t.Fatalf("default prompt missing built-in docs guidance:\n%s", got)
97 }
98}