Skip to content

Commit 87341fb

Browse files
committed
test: fix track1 acceptance schema drift
1 parent cacc459 commit 87341fb

6 files changed

Lines changed: 65 additions & 18 deletions

File tree

cmd/gc/cmd_hook.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func shellWorkQueryWithEnv(command, dir string, env []string) (string, error) {
158158
cmd.Dir = dir
159159
}
160160
if env != nil {
161-
cmd.Env = env
161+
cmd.Env = workQueryEnvForDir(env, dir)
162162
}
163163
out, err := cmd.Output()
164164
if err != nil {
@@ -167,6 +167,22 @@ func shellWorkQueryWithEnv(command, dir string, env []string) (string, error) {
167167
return string(out), nil
168168
}
169169

170+
// workQueryEnvForDir ensures the subprocess environment does not carry a
171+
// stale inherited PWD when exec.Cmd.Dir points somewhere else. Some shells
172+
// (notably macOS /bin/sh) preserve the inherited PWD instead of recomputing
173+
// it from the real working directory, which breaks hook work_query commands
174+
// that inspect $PWD.
175+
func workQueryEnvForDir(env []string, dir string) []string {
176+
if env == nil {
177+
return nil
178+
}
179+
if dir == "" {
180+
return env
181+
}
182+
out := removeEnvKey(append([]string(nil), env...), "PWD")
183+
return append(out, "PWD="+dir)
184+
}
185+
170186
// doHook is the pure logic for gc hook. Runs the work query and outputs
171187
// results based on mode. Without inject: prints raw output, returns 0 if
172188
// work, 1 if empty. With inject: wraps in <system-reminder>, always returns 0.

cmd/gc/cmd_hook_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,26 @@ max = 5
485485
}
486486
}
487487

488+
func TestWorkQueryEnvForDirOverridesInheritedPWD(t *testing.T) {
489+
env := []string{
490+
"PATH=/tmp/bin",
491+
"PWD=/tmp/stale",
492+
"GC_CITY=/tmp/city",
493+
}
494+
495+
got := workQueryEnvForDir(env, "/tmp/rig")
496+
497+
if strings.Contains(strings.Join(got, "\n"), "PWD=/tmp/stale") {
498+
t.Fatalf("workQueryEnvForDir preserved stale PWD: %v", got)
499+
}
500+
if !strings.Contains(strings.Join(got, "\n"), "PWD=/tmp/rig") {
501+
t.Fatalf("workQueryEnvForDir missing updated PWD: %v", got)
502+
}
503+
if !strings.Contains(strings.Join(got, "\n"), "PATH=/tmp/bin") {
504+
t.Fatalf("workQueryEnvForDir dropped unrelated env: %v", got)
505+
}
506+
}
507+
488508
func TestCmdHookExportsResolvedIdentityForFixedAgentQuery(t *testing.T) {
489509
t.Setenv("GC_TMUX_SESSION", "host-session")
490510
clearGCEnv(t)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

test/acceptance/gastown_smoke_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestGastownSmoke(t *testing.T) {
6868
if err != nil {
6969
return err
7070
}
71-
if info.IsDir() || !strings.HasSuffix(path, ".md.tmpl") {
71+
if info.IsDir() || !strings.HasSuffix(path, ".template.md") {
7272
return nil
7373
}
7474

@@ -99,7 +99,7 @@ func TestGastownSmoke(t *testing.T) {
9999
t.Fatalf("walking packs dir: %v", err)
100100
}
101101
if count == 0 {
102-
t.Fatal("no .md.tmpl files found in packs/")
102+
t.Fatal("no .template.md files found in packs/")
103103
}
104104
})
105105

test/acceptance/migration_regression_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ func TestRegression_GastownConfig(t *testing.T) {
9999
}
100100
})
101101

102-
// Fallback resolution: gastown's non-fallback dog overrides maintenance's fallback.
102+
// Schema 2 keeps a single maintenance fallback dog, then Gastown patches
103+
// it with themed runtime fields instead of replacing it with a second dog.
103104
t.Run("FallbackAgentResolution", func(t *testing.T) {
104105
count := agentCount(cfg, "dog")
105106
if count != 1 {
@@ -108,12 +109,21 @@ func TestRegression_GastownConfig(t *testing.T) {
108109

109110
for _, a := range cfg.Agents {
110111
if a.Name == "dog" {
111-
if a.Fallback {
112-
t.Error("dog agent has fallback=true; gastown's non-fallback should have won")
112+
if !a.Fallback {
113+
t.Error("dog agent should retain maintenance fallback=true under schema 2 patching")
113114
}
114115
if len(a.SessionLive) == 0 {
115116
t.Error("dog agent has no session_live; expected gastown's themed dog")
116117
}
118+
if !strings.Contains(a.WorkDir, ".gc/agents/dogs/") {
119+
t.Errorf("dog work_dir = %q, want gastown dog workdir override", a.WorkDir)
120+
}
121+
if !strings.Contains(a.PromptTemplate, "maintenance/agents/dog/prompt.template.md") {
122+
t.Errorf("dog prompt_template = %q, want maintenance dog prompt via gastown patch", a.PromptTemplate)
123+
}
124+
if !strings.Contains(a.OverlayDir, "maintenance/agents/dog/overlay") {
125+
t.Errorf("dog overlay_dir = %q, want maintenance dog overlay via gastown patch", a.OverlayDir)
126+
}
117127
break
118128
}
119129
}
@@ -225,21 +235,21 @@ func TestRegression_GastownPackArtifacts(t *testing.T) {
225235

226236
// PR #2939: prompt referenced nonexistent /ralph-loop slash command.
227237
t.Run("PromptsRender", func(t *testing.T) {
228-
promptDirs := []string{
229-
filepath.Join(c.Dir, "packs", "gastown", "prompts"),
230-
filepath.Join(c.Dir, "packs", "maintenance", "prompts"),
238+
packDirs := []string{
239+
filepath.Join(c.Dir, "packs", "gastown"),
240+
filepath.Join(c.Dir, "packs", "maintenance"),
231241
}
232242

233243
count := 0
234-
for _, dir := range promptDirs {
244+
for _, dir := range packDirs {
235245
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
236246
if err != nil {
237247
return err
238248
}
239249
if info.IsDir() {
240250
return nil
241251
}
242-
if !strings.HasSuffix(path, ".md.tmpl") {
252+
if !strings.HasSuffix(path, ".template.md") {
243253
return nil
244254
}
245255
count++
@@ -266,7 +276,7 @@ func TestRegression_GastownPackArtifacts(t *testing.T) {
266276
}
267277

268278
if count == 0 {
269-
t.Fatal("no .md.tmpl files found in materialized packs")
279+
t.Fatal("no .template.md files found in materialized packs")
270280
}
271281
t.Logf("validated %d prompt template files", count)
272282
})

test/acceptance/tutorial_goldens/tutorial01_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ func TestTutorial01Cities(t *testing.T) {
4141
})
4242

4343
t.Run("gc init ~/my-city", func(t *testing.T) {
44-
ws.noteWarning("tutorial 01 documents the interactive wizard, but the acceptance harness uses the equivalent non-interactive `gc init ~/my-city --provider claude` path because the wizard requires a real TTY")
45-
out, err := ws.runShell("gc init ~/my-city --provider claude", "")
44+
ws.noteWarning("tutorial 01 documents the interactive wizard, but the acceptance harness uses the equivalent non-interactive `gc init ~/my-city --provider claude --skip-provider-readiness` path because the wizard requires a real TTY and CI does not carry interactive Claude auth")
45+
out, err := ws.runShell("gc init ~/my-city --provider claude --skip-provider-readiness", "")
4646
if err != nil {
4747
t.Fatalf("gc init wizard: %v\n%s", err, out)
4848
}
4949
for _, want := range []string{
5050
"Welcome to Gas City!",
5151
`Initialized city "my-city" with default provider "claude".`,
52-
"Registering city with supervisor",
52+
"Skipping provider readiness checks",
5353
} {
5454
if !strings.Contains(out, want) {
5555
t.Fatalf("gc init output missing %q:\n%s", want, out)
@@ -74,7 +74,7 @@ func TestTutorial01Cities(t *testing.T) {
7474
wsProvider := newTutorialWorkspace(t)
7575
wsProvider.attachDiagnostics(t, "tutorial-01-provider-branch")
7676

77-
out, err := wsProvider.runShell("gc init ~/my-city --provider claude", "")
77+
out, err := wsProvider.runShell("gc init ~/my-city --provider claude --skip-provider-readiness", "")
7878
if err != nil {
7979
t.Fatalf("gc init --provider claude: %v\n%s", err, out)
8080
}
@@ -98,7 +98,7 @@ func TestTutorial01Cities(t *testing.T) {
9898
if err != nil {
9999
t.Fatalf("ls: %v\n%s", err, out)
100100
}
101-
for _, want := range []string{"city.toml", "formulas", "orders", "prompts"} {
101+
for _, want := range []string{"city.toml", "pack.toml", "formulas", "orders", "agents"} {
102102
if !strings.Contains(out, want) {
103103
t.Fatalf("ls output missing %q:\n%s", want, out)
104104
}
@@ -114,7 +114,7 @@ func TestTutorial01Cities(t *testing.T) {
114114
`name = "my-city"`,
115115
`provider = "claude"`,
116116
`name = "mayor"`,
117-
`prompt_template = "prompts/mayor.md"`,
117+
`prompt_template = "agents/mayor/prompt.template.md"`,
118118
} {
119119
if !strings.Contains(out, want) {
120120
t.Fatalf("city.toml missing %q:\n%s", want, out)

0 commit comments

Comments
 (0)