-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_test.go
More file actions
190 lines (172 loc) · 6 KB
/
run_test.go
File metadata and controls
190 lines (172 loc) · 6 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package main
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestInitWorkerMatchesEmbeddedPrompt(t *testing.T) {
got, err := promptForRole("worker")
if err != nil {
t.Fatalf("promptForRole(worker): %v", err)
}
wantBytes, err := os.ReadFile(filepath.Join("prompts", "worker.md"))
if err != nil {
t.Fatalf("read prompts/worker.md: %v", err)
}
if got != string(wantBytes) {
t.Fatalf("init worker prompt mismatch")
}
}
// writeManagedPromptFile is the helper used by `lalia run` to drop the role
// prompt into a harness instructions file. `lalia prompt` no longer writes —
// this test exercises the helper directly.
func TestWriteManagedPromptFileRespectsOverwriteMarker(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
prompt, err := promptForRole("worker")
if err != nil {
t.Fatalf("promptForRole: %v", err)
}
path := filepath.Join(dir, "LALIA.md")
if err := writeManagedPromptFile(path, prompt, false); err != nil {
t.Fatalf("writeManagedPromptFile create: %v", err)
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read LALIA.md: %v", err)
}
if !strings.HasPrefix(string(data), managedPromptMarker+"\n") {
t.Fatalf("LALIA.md missing managed marker prefix")
}
if err := os.WriteFile(path, []byte("custom content\n"), 0644); err != nil {
t.Fatalf("seed custom LALIA.md: %v", err)
}
if err := writeManagedPromptFile(path, prompt, false); err == nil {
t.Fatalf("expected overwrite refusal for unmarked file")
}
if err := writeManagedPromptFile(path, prompt, true); err != nil {
t.Fatalf("force overwrite should succeed: %v", err)
}
}
func TestRunHarnessClaudeWritesPromptAndExecsHarness(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
stubBin := filepath.Join(dir, "bin")
if err := os.MkdirAll(stubBin, 0755); err != nil {
t.Fatalf("mkdir stub bin: %v", err)
}
logPath := filepath.Join(dir, "claude.log")
writeStub(t, filepath.Join(stubBin, "claude"), logPath)
t.Setenv("PATH", stubBin+string(os.PathListSeparator)+os.Getenv("PATH"))
if err := runHarness("worker", "--claude-code", false, []string{"--dry-run"}); err != nil {
t.Fatalf("runHarness claude: %v", err)
}
if _, err := os.Stat(filepath.Join(dir, "LALIA.md")); err != nil {
t.Fatalf("LALIA.md not written: %v", err)
}
args := readStubArgs(t, logPath)
want := []string{"--append-system-prompt-file", "LALIA.md", "--dry-run"}
if strings.Join(args, "\n") != strings.Join(want, "\n") {
t.Fatalf("claude argv=%v want=%v", args, want)
}
}
func TestRunHarnessCodexWritesPromptAndExecsWithConfigOverride(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
stubBin := filepath.Join(dir, "bin")
if err := os.MkdirAll(stubBin, 0755); err != nil {
t.Fatalf("mkdir stub bin: %v", err)
}
logPath := filepath.Join(dir, "codex.log")
writeStub(t, filepath.Join(stubBin, "codex"), logPath)
t.Setenv("PATH", stubBin+string(os.PathListSeparator)+os.Getenv("PATH"))
if err := runHarness("worker", "--codex", false, []string{"--continue"}); err != nil {
t.Fatalf("runHarness codex: %v", err)
}
if _, err := os.Stat(filepath.Join(dir, "LALIA.md")); err != nil {
t.Fatalf("LALIA.md not written: %v", err)
}
args := readStubArgs(t, logPath)
if len(args) < 3 {
t.Fatalf("codex argv too short: %v", args)
}
if args[0] != "-c" {
t.Fatalf("codex arg0=%q want -c", args[0])
}
if !strings.HasPrefix(args[1], "experimental_instructions_file=") {
t.Fatalf("codex config override missing: %q", args[1])
}
if !strings.Contains(args[1], filepath.Join(dir, "LALIA.md")) {
t.Fatalf("codex config override path missing: %q", args[1])
}
if args[2] != "--continue" {
t.Fatalf("codex passthrough arg missing: %v", args)
}
}
func TestRunHarnessCopilotRefusesUnmarkedFileWithoutForce(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
path := filepath.Join(dir, ".github", "copilot-instructions.md")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir .github: %v", err)
}
if err := os.WriteFile(path, []byte("manual instructions\n"), 0644); err != nil {
t.Fatalf("seed copilot file: %v", err)
}
err := runHarness("worker", "--copilot", false, nil)
if err == nil {
t.Fatalf("expected refusal for unmarked copilot instructions")
}
if !strings.Contains(err.Error(), "refusing to overwrite unmarked") {
t.Fatalf("unexpected error: %v", err)
}
}
func TestColdPathsInitPromptRunWithoutDaemonOrRegister(t *testing.T) {
dir := t.TempDir()
t.Chdir(dir)
t.Setenv("LALIA_HOME", filepath.Join(dir, "lalia-home"))
t.Setenv("LALIA_WORKSPACE", filepath.Join(dir, "workspace"))
if _, err := promptForRole("worker"); err != nil {
t.Fatalf("promptForRole worker: %v", err)
}
if err := writeManagedPromptFile(filepath.Join(dir, "LALIA.md"), workerPrompt, false); err != nil {
t.Fatalf("writeManagedPromptFile: %v", err)
}
stubBin := filepath.Join(dir, "bin")
if err := os.MkdirAll(stubBin, 0755); err != nil {
t.Fatalf("mkdir stub bin: %v", err)
}
writeStub(t, filepath.Join(stubBin, "claude"), filepath.Join(dir, "claude.log"))
writeStub(t, filepath.Join(stubBin, "codex"), filepath.Join(dir, "codex.log"))
writeStub(t, filepath.Join(stubBin, "copilot"), filepath.Join(dir, "copilot.log"))
t.Setenv("PATH", stubBin+string(os.PathListSeparator)+os.Getenv("PATH"))
if err := runHarness("worker", "--claude-code", false, nil); err != nil {
t.Fatalf("cold run claude: %v", err)
}
if err := runHarness("worker", "--codex", false, nil); err != nil {
t.Fatalf("cold run codex: %v", err)
}
if err := runHarness("worker", "--copilot", false, nil); err != nil {
t.Fatalf("cold run copilot: %v", err)
}
}
func writeStub(t *testing.T, path, logPath string) {
t.Helper()
script := "#!/bin/sh\nprintf '%s\\n' \"$@\" > \"" + logPath + "\"\n"
if err := os.WriteFile(path, []byte(script), 0755); err != nil {
t.Fatalf("write stub %s: %v", path, err)
}
}
func readStubArgs(t *testing.T, logPath string) []string {
t.Helper()
data, err := os.ReadFile(logPath)
if err != nil {
t.Fatalf("read stub log %s: %v", logPath, err)
}
raw := strings.TrimSpace(string(data))
if raw == "" {
return nil
}
return strings.Split(raw, "\n")
}