Skip to content

test(cli): migrate dedup_test.go to t.Chdir + lock isolation ratchet 163->151 (ag-4nif #dedup-tchdir)#773

Merged
boshu2 merged 3 commits into
mainfrom
test/ag-4nif-tchdir-setenv-w1
Jun 6, 2026
Merged

test(cli): migrate dedup_test.go to t.Chdir + lock isolation ratchet 163->151 (ag-4nif #dedup-tchdir)#773
boshu2 merged 3 commits into
mainfrom
test/ag-4nif-tchdir-setenv-w1

Conversation

@boshu2
Copy link
Copy Markdown
Owner

@boshu2 boshu2 commented Jun 6, 2026

What

Migrate dedup_test.go's 6 manual origDir, _ := os.Getwd(); os.Chdir(tmp); defer os.Chdir(origDir) blocks to Go 1.20+ t.Chdir(tmp) — auto-restores cwd and refuses t.Parallel, pre-empting the latent flake class flagged by ag-4nif / ag-k38x (raw forms mutate process-global cwd). No t.Parallel in the file; behavior-preserving.

Each block held two os.Chdir( references (the call + the defer restore), so 6 blocks drop the repo-wide test-isolation count by 12 (163→151). I lowered BASELINE_CHDIR in scripts/check-test-isolation.sh to lock the gain (the ratchet is only-goes-down).

Scope / no-collision note

os.Chdir only. The 3 redundant os.Setenv restores in rpi_reliability_test.go are already handled by the open PR #772 (ag-k38x) — I deliberately do not touch that file here, to avoid a merge collision (an earlier draft of this branch did; it was reverted). ag-k38x is the canonical tracker; ag-4nif/ag-y4ac are duplicates — worth closing as dup-of-ag-k38x during triage.

Evidence

bash scripts/check-test-isolation.sh        # PASS (os.Chdir=151/151, os.Setenv=22/22)
cd cli
go build ./...                              # OK
go vet ./cmd/ao/                            # No issues found
go test ./cmd/ao/ -run 'TestRunDedup|TestMergeDedupGroups' -count=1   # 17 pass
gofmt -l                                     # clean

Net: −19 / +8 across dedup_test.go + the ratchet baseline.

Closes-scenario: ag-4nif#dedup-tchdir
Bounded-context: BC5-Runtime
Evidence: ratchet PASS + go build/vet/test (17 pass) + gofmt clean

@github-actions github-actions Bot added the cli label Jun 6, 2026
…163->151 (ag-4nif #dedup-tchdir)

Migrate dedup_test.go's 6 manual `os.Getwd()/os.Chdir/defer-restore` blocks to
Go 1.20+ t.Chdir(tmp), which auto-restores cwd AND refuses t.Parallel —
pre-empting the latent flake class flagged by ag-4nif/ag-k38x. No t.Parallel in
the file; behavior-preserving.

Each block held two `os.Chdir(` refs (the call + the defer), so 6 blocks drop
the repo-wide test-isolation count by 12 (163->151). Lower BASELINE_CHDIR in
scripts/check-test-isolation.sh to lock the gain (the ratchet is only-goes-down).

Scope: os.Chdir only. The 3 redundant os.Setenv restores in rpi_reliability_test.go
are already handled by the open PR #772 (ag-k38x), so they are deliberately NOT
touched here to avoid a merge collision. ag-k38x is the canonical tracker;
ag-4nif/ag-y4ac are its duplicates.

Closes-scenario: ag-4nif#dedup-tchdir
Bounded-context: BC5-Runtime
Evidence: scripts/check-test-isolation.sh PASS (os.Chdir=151/151); go build ./... + go vet ./cmd/ao + go test ./cmd/ao -run 'TestRunDedup|TestMergeDedupGroups' (17 pass); gofmt clean
@boshu2 boshu2 force-pushed the test/ag-4nif-tchdir-setenv-w1 branch from 4af5f3d to e268d0b Compare June 6, 2026 06:50
@boshu2 boshu2 changed the title test(cli): migrate to t.Chdir/t.Setenv auto-restore (ag-4nif #tchdir-setenv-wave1) test(cli): migrate dedup_test.go to t.Chdir + lock isolation ratchet 163->151 (ag-4nif #dedup-tchdir) Jun 6, 2026
boshu2 added a commit that referenced this pull request Jun 6, 2026
…e-tchdir-w2) (#786)

## What
Collapse 7 identical `os.Getwd()` + `os.Chdir(tmpDir)` +
`t.Cleanup(restore)` blocks in `cli/cmd/ao/curate_test.go` to
`t.Chdir(tmpDir)`. Bare downstream `err =` first-uses promoted to `err
:=` (the removed block held the only function-scope `err`).

## Why
`t.Chdir` auto-restores cwd on cleanup **and** refuses to run under
`t.Parallel` — pre-empting the process-global-cwd flake class (cf.
ag-jfzs). This is one wave of the ag-k38x / ag-y4ac test-isolation sweep
(`finish-the-job`: ~133 sites already use the safe idiom).

## Scope / collision-safety
- `os.Chdir` in `_test.go`: **163 → 149 (-14)**. `os.Setenv` untouched
(owned by in-flight setenv ratchet **PR #772**).
- **`BASELINE_CHDIR` intentionally NOT lowered** — that single line is
the contention point with in-flight **PR #772/#773**; the ratchet stays
green because count-below-baseline is a NOTE, not a failure (`149 <=
163`). A later wave locks the baseline once those settle.
- Non-overlapping with PR #772 (rpi setenv) and PR #773 (dedup_test.go
os.Chdir).

## Verification
- `gofmt -l` clean · `go build ./...` · `go vet ./cmd/ao` clean
- `go test ./cmd/ao -run TestCurate` → 14 pass
- `scripts/check-test-isolation.sh` → PASS (os.Chdir=149/163,
os.Setenv=22/22)
- `scripts/pre-push-gate.sh --fast` → passed

Closes-scenario: ag-y4ac#curate-tchdir-w2
Bounded-context: BC5-Runtime
Evidence: .ntm/bo-queue/2026-06-06-ag-y4ac-pr-curate-tchdir.md
@boshu2 boshu2 merged commit 3bab897 into main Jun 6, 2026
16 checks passed
@boshu2 boshu2 deleted the test/ag-4nif-tchdir-setenv-w1 branch June 6, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant