-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_prompt_test.go
More file actions
81 lines (76 loc) · 2.47 KB
/
Copy pathsystem_prompt_test.go
File metadata and controls
81 lines (76 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package acpruntime
import "testing"
func TestWithSystemPromptHelpers(t *testing.T) {
replace := WithSystemPrompt("Be concise.")
if len(replace) != 1 || replace[SystemPromptMetaKey] != "Be concise." {
t.Fatalf("WithSystemPrompt = %#v", replace)
}
appendMeta := WithAppendSystemPrompt("Prefer small diffs.")
if len(appendMeta) != 1 || appendMeta[AppendSystemPromptMetaKey] != "Prefer small diffs." {
t.Fatalf("WithAppendSystemPrompt = %#v", appendMeta)
}
}
func TestMergeMeta(t *testing.T) {
out := MergeMeta(
WithSystemPrompt("host"),
map[string]any{"custom": "v", "nested": map[string]any{"a": 1}},
map[string]any{"custom": "override"},
nil,
)
if out[SystemPromptMetaKey] != "host" {
t.Fatalf("system prompt lost: %#v", out)
}
if out["custom"] != "override" {
t.Fatalf("later key should win: %#v", out)
}
nested, ok := out["nested"].(map[string]any)
if !ok || nested["a"] != 1 {
t.Fatalf("nested meta lost: %#v", out["nested"])
}
if MergeMeta() != nil {
t.Fatalf("empty MergeMeta should be nil")
}
}
func TestPrepareAgentSessionStartAcceptsWithSystemPromptHelper(t *testing.T) {
profile := ResolveAgentProfile(Agent{Type: CodexACPRegistryID})
agent, meta, err := prepareAgentSessionStart(profile, StartSessionOptions{
Agent: Agent{Type: CodexACPRegistryID, Command: "npm"},
Meta: MergeMeta(WithSystemPrompt("via helper"), map[string]any{"x": 1}),
})
if err != nil {
t.Fatalf("prepareAgentSessionStart() error = %v", err)
}
if meta["x"] != 1 {
t.Fatalf("meta = %#v", meta)
}
if _, ok := meta[SystemPromptMetaKey]; ok {
t.Fatalf("reserved key should be consumed: %#v", meta)
}
cfg := decodeCodexConfig(t, agent.Env["CODEX_CONFIG"])
if cfg["instructions"] != "via helper" {
t.Fatalf("cfg = %#v", cfg)
}
}
func TestPrepareAgentSessionStartCodexAppendUsesDeveloperInstructions(t *testing.T) {
profile := ResolveAgentProfile(Agent{Type: CodexACPRegistryID})
agent, _, err := prepareAgentSessionStart(profile, StartSessionOptions{
Agent: Agent{
Type: CodexACPRegistryID,
Command: "npm",
Env: map[string]string{
"CODEX_CONFIG": `{"developer_instructions":"existing"}`,
},
},
Meta: WithAppendSystemPrompt("more"),
})
if err != nil {
t.Fatalf("prepareAgentSessionStart() error = %v", err)
}
cfg := decodeCodexConfig(t, agent.Env["CODEX_CONFIG"])
if cfg["developer_instructions"] != "existing\n\nmore" {
t.Fatalf("cfg = %#v", cfg)
}
if _, ok := cfg["instructions"]; ok {
t.Fatalf("append should not set instructions: %#v", cfg)
}
}