Skip to content

Commit 7c608a9

Browse files
committed
test(cmd/ao): replace defer/t.Cleanup os.Chdir with t.Chdir (6 sites, 3 files)
Generator-layer test hygiene cycle. Continues the t.Chdir migration started in PR #177 (which covered 5 cmd/ao test files: plans, dedup, config, metrics_flywheel, metrics_health). This cycle picks up disjoint files so PR #177 and this nightly do not conflict on the same _test.go. Files migrated (6 sites): - batch_forge_test.go (3 sites): TestRunForgeBatch_NoPendingTranscripts, TestRunForgeBatch_DryRunAppliesMaxLimit, TestRunForgeBatch_ProcessesTranscript. In each, replaces the 4-line block `origDir, err := os.Getwd(); ... os.Chdir(tmpDir); ...; t.Cleanup(func() { _ = os.Chdir(origDir) })` with `t.Chdir(tmpDir)`. Subsequent `err = runForgeBatch(...)` becomes `err := runForgeBatch(...)` (the prior implicit declaration came from the os.Getwd line). - batch_promote_test.go (1 site): TestRunBatchPromote_NoPendingCandidates, same pattern. - cobra_commands_test.go (2 sites): TestCobraStatusCommand/json_not_initialized and TestCobraSeedCommand. Pattern is the simpler `defer func() { _ = os.Chdir(orig) }()` form; collapses to `t.Chdir(...)`. Net: -32 lines, +0 logic change. `go test -count=1 ./cmd/ao/...` passes; `go vet ./...` clean; pre-push fast gate passes; full goals measure unchanged (17 pass / 2 fail — the two open-state failures are flywheel-compounding W=8 corpus-bound and go-complexity-ceiling W=6 in-flight via PR #177).
1 parent 6f41dd5 commit 7c608a9

3 files changed

Lines changed: 8 additions & 40 deletions

File tree

cli/cmd/ao/batch_forge_test.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,7 @@ func TestLoadAndFilterTranscripts_RespectsForgedIndex(t *testing.T) {
494494

495495
func TestRunForgeBatch_NoPendingTranscripts(t *testing.T) {
496496
tmpDir := t.TempDir()
497-
origDir, err := os.Getwd()
498-
if err != nil {
499-
t.Fatalf("getwd: %v", err)
500-
}
501-
if err := os.Chdir(tmpDir); err != nil {
502-
t.Fatalf("chdir: %v", err)
503-
}
504-
t.Cleanup(func() { _ = os.Chdir(origDir) })
497+
t.Chdir(tmpDir)
505498

506499
oldBatchDir, oldBatchMax, oldBatchExtract := batchDir, batchMax, batchExtract
507500
oldOutput := output
@@ -521,7 +514,7 @@ func TestRunForgeBatch_NoPendingTranscripts(t *testing.T) {
521514
origStdout := os.Stdout
522515
r, w, _ := os.Pipe()
523516
os.Stdout = w
524-
err = runForgeBatch(nil, nil)
517+
err := runForgeBatch(nil, nil)
525518
w.Close()
526519
os.Stdout = origStdout
527520
if err != nil {
@@ -538,14 +531,7 @@ func TestRunForgeBatch_NoPendingTranscripts(t *testing.T) {
538531

539532
func TestRunForgeBatch_DryRunAppliesMaxLimit(t *testing.T) {
540533
tmpDir := t.TempDir()
541-
origDir, err := os.Getwd()
542-
if err != nil {
543-
t.Fatalf("getwd: %v", err)
544-
}
545-
if err := os.Chdir(tmpDir); err != nil {
546-
t.Fatalf("chdir: %v", err)
547-
}
548-
t.Cleanup(func() { _ = os.Chdir(origDir) })
534+
t.Chdir(tmpDir)
549535

550536
transcriptDir := filepath.Join(tmpDir, "transcripts")
551537
if err := os.MkdirAll(transcriptDir, 0o755); err != nil {
@@ -602,14 +588,7 @@ func TestRunForgeBatch_DryRunAppliesMaxLimit(t *testing.T) {
602588

603589
func TestRunForgeBatch_ProcessesTranscript(t *testing.T) {
604590
tmpDir := t.TempDir()
605-
origDir, err := os.Getwd()
606-
if err != nil {
607-
t.Fatalf("getwd: %v", err)
608-
}
609-
if err := os.Chdir(tmpDir); err != nil {
610-
t.Fatalf("chdir: %v", err)
611-
}
612-
t.Cleanup(func() { _ = os.Chdir(origDir) })
591+
t.Chdir(tmpDir)
613592

614593
transcriptDir := filepath.Join(tmpDir, "transcripts")
615594
if err := os.MkdirAll(transcriptDir, 0o755); err != nil {

cli/cmd/ao/batch_promote_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,7 @@ func TestOutputBatchResult(t *testing.T) {
389389

390390
func TestRunBatchPromote_NoPendingCandidates(t *testing.T) {
391391
tmpDir := t.TempDir()
392-
origDir, err := os.Getwd()
393-
if err != nil {
394-
t.Fatalf("getwd: %v", err)
395-
}
396-
if err := os.Chdir(tmpDir); err != nil {
397-
t.Fatalf("chdir: %v", err)
398-
}
399-
t.Cleanup(func() { _ = os.Chdir(origDir) })
392+
t.Chdir(tmpDir)
400393

401394
oldOutput := output
402395
output = "text"
@@ -413,7 +406,7 @@ func TestRunBatchPromote_NoPendingCandidates(t *testing.T) {
413406
origStdout := os.Stdout
414407
r, w, _ := os.Pipe()
415408
os.Stdout = w
416-
err = runBatchPromote(nil, nil)
409+
err := runBatchPromote(nil, nil)
417410
w.Close()
418411
os.Stdout = origStdout
419412
if err != nil {

cli/cmd/ao/cobra_commands_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,7 @@ func TestCobraStatusCommand(t *testing.T) {
585585

586586
t.Run("json_not_initialized", func(t *testing.T) {
587587
tmp2 := t.TempDir()
588-
orig, _ := os.Getwd()
589-
_ = os.Chdir(tmp2)
590-
defer func() { _ = os.Chdir(orig) }()
588+
t.Chdir(tmp2)
591589

592590
// Reset the output flag
593591
output = "json"
@@ -2336,9 +2334,7 @@ func TestCobraQuickstartHelpers(t *testing.T) {
23362334
t.Fatal(err)
23372335
}
23382336

2339-
orig, _ := os.Getwd()
2340-
_ = os.Chdir(tmp)
2341-
defer func() { _ = os.Chdir(orig) }()
2337+
t.Chdir(tmp)
23422338

23432339
// Capture stdout
23442340
old := os.Stdout

0 commit comments

Comments
 (0)