Skip to content

Commit 3365850

Browse files
gtrrz-victorclaude
andcommitted
test(claudecode): harden SessionEnd timeout assertions
Guard the Stop-hook index so a missing install fails with a clear message instead of an index-out-of-range panic, and assert the production settings.json omits the timeout field entirely rather than only checking the parsed value is zero (which an explicit "timeout": 0 would also satisfy). Addresses PR review feedback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 01KY9V2889KFJ2JKFW066NRW6Q
1 parent 455b6ed commit 3365850

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

cmd/entire/cli/agent/claudecode/hooks_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ func TestInstallHooks_LocalDevSessionEndTimeout(t *testing.T) {
490490
}
491491

492492
// Scoping: other local-dev hooks must not inherit the timeout.
493+
if len(settings.Hooks.Stop) == 0 || len(settings.Hooks.Stop[0].Hooks) == 0 {
494+
t.Fatal("expected a Stop hook to be installed")
495+
}
493496
if got := settings.Hooks.Stop[0].Hooks[0].Timeout; got != 0 {
494497
t.Errorf("local-dev Stop timeout = %d, want 0 (timeout is SessionEnd-only)", got)
495498
}
@@ -511,6 +514,16 @@ func TestInstallHooks_LocalDevSessionEndTimeout(t *testing.T) {
511514
if got := settings.Hooks.SessionEnd[0].Hooks[0].Timeout; got != 0 {
512515
t.Errorf("production SessionEnd timeout = %d, want 0 (dev-only)", got)
513516
}
517+
518+
// Stronger than the parsed check: prove the field is omitted entirely
519+
// (omitempty), not written as an explicit "timeout": 0.
520+
raw, err := os.ReadFile(filepath.Join(tempDir, ".claude", "settings.json"))
521+
if err != nil {
522+
t.Fatalf("failed to read settings.json: %v", err)
523+
}
524+
if strings.Contains(string(raw), "timeout") {
525+
t.Errorf("production settings.json must not contain any timeout field, got:\n%s", raw)
526+
}
514527
})
515528
}
516529

0 commit comments

Comments
 (0)