Skip to content

Commit 989741e

Browse files
TMHSDigitalclaude
andcommitted
fix(cli): read -seeds before opening the -o file (#212)
An unreadable -seeds file failed the run after openOutputs had created the temporary output file but before its deferred Close was registered, so a hidden .<name>.tmp was left beside the -o path (and kept locked on Windows until exit). Seeds are now loaded before outputs are opened. Adds an e2e test that runs with a missing -seeds file and asserts the output directory stays empty. Fixes #212 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXSPwrzd7ZCuX3no7gD
1 parent b1ee267 commit 989741e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎main_e2e_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ func TestE2EFailedRunKeepsOutputFile(t *testing.T) {
192192
}
193193
}
194194

195+
// TestE2EBadSeedsLeavesNoTempFile: an unreadable -seeds file fails the run
196+
// before the -o file is opened, so no temporary file is left beside it (#212).
197+
func TestE2EBadSeedsLeavesNoTempFile(t *testing.T) {
198+
wl := writeFile(t, "wl.txt", e2eWords)
199+
dir := t.TempDir()
200+
outPath := filepath.Join(dir, "out.txt")
201+
202+
code, _ := runCLI(t, "", "-simulate", "-progress=false", "-w", wl, "-o", outPath,
203+
"-seeds", filepath.Join(dir, "missing.json"), "example.com")
204+
if code != 1 {
205+
t.Fatalf("exit %d, want 1", code)
206+
}
207+
if left, _ := os.ReadDir(dir); len(left) != 0 {
208+
t.Fatalf("files left behind: %v", left)
209+
}
210+
}
211+
195212
// runCLIMerged is runCLI with stdout and stderr sharing one stream, like
196213
// `subenum ... 2>&1 | tee log`.
197214
func runCLIMerged(t *testing.T, args ...string) (int, string) {

‎main_session.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ func runWith(a runArgs) (code int) {
9393
}
9494
logVerboseStart(s.f, targetDesc, s.in.maxAttempts, s.out)
9595
}
96-
if !s.loadInputs() || !s.openOutputs() || !s.loadSeeds() {
96+
// Seeds are read before the -o file is opened: a failure after opening
97+
// would return before its deferred Close is registered and leave the
98+
// temporary file behind (#212).
99+
if !s.loadInputs() || !s.loadSeeds() || !s.openOutputs() {
97100
return exitFailure
98101
}
99102
s.setProgress()

0 commit comments

Comments
 (0)