Skip to content

test: harden all recursive rmSync teardowns with retry options - #1655

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-29_test-teardown-rm-retry
Sep 29, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-29_test-teardown-rm-retry

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

New shared test util tests/tmp-rm.ts:

export function rmrf(target: string | URL): void {
  rmSync(target, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
}

Replaces all 354 bare rmSync(dir, { recursive: true, force: true }) teardown calls across 91 test files (count via exact paren-balanced parse of every rmSync( call in tests/ — my issue reply said 339/87 from a coarser regex; the parsed number is authoritative). Orphaned named rmSync imports dropped in the 44 files where nothing else used them.

Why

Bare recursive rmSync throws ENOTEMPTY on loaded CI runners when a spawned child (proxy under test) recreates entries between rimraf's readdir and rmdir. Node's internal rimraf only retries transient errors (ENOTEMPTY, EACCES, EPERM, EMFILE, EBUSY) when maxRetries is set; without it the first ENOTEMPTY propagates straight into the test's finally and turns a green suite red. Observed: CI run 36520549393, issue1086-chain-self-exemption T3, ubuntu-latest Node 22 — all assertions passed, throw came from teardown line 317.

The precedent for the fix already exists in-tree at tests/issue1086-chain-self-exemption.test.ts:663 (maxRetries: 10, retryDelay: 50); this PR just gives the rest of the tree the same hardening through one shared helper instead of 91 inline option sets.

Worst-case added teardown latency per path is bounded (~2.75s, linear retryDelay * attempt backoff), only on runners that actually hit the race.

Scope / behavior

  • Test-only change. No product code touched. No config surface touched. No wire/persistence/config behavior change — cleanup retry options cannot affect what any test asserts.
  • Single-file non-recursive fs.rmSync(path, { force: true }) sites (17, e.g. store.test.ts:245, proxy-persist.test.ts:275,479) deliberately left alone: no recursive means no rmdir race.
  • Best-effort try/catch teardown sites keep their catch around rmrf.
  • One pre-existing oddity preserved as-is: watchdog-health*.test.ts awaited the synchronous rmSync — converted, still sync, still harmless.

Pre-flight

  • npm run typecheck: PASS
  • npm test full suite: 3174 pass / 0 fail / 16 skipped (first local run had exactly one failure — issue1452-socket-hardening stall-guard timing flake under parallel load, 12/12 green in isolation, zero logic diff in that file beyond import+teardown; second full run fully green)
  • npm run build: PASS
  • Root tsconfig.json error set compared against clean master baseline: identical modulo line numbers (904 pre-existing test-lane type errors, none new)

Fixes #1646

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-29_test-teardown-rm-retry (7480989)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1610-pr.1655.92d3297

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1655.tgz
npm install -g package

Install instructions are refreshed on each push.

ework-agent added 3 commits September 29, 2026 14:52
Bare rmSync(dir, {recursive, force}) in test teardowns throws ENOTEMPTY on
loaded CI runners when a spawned child recreates entries between readdir and
rmdir (observed: issue1086-chain T3 on ubuntu-latest Node 22, run
36520549393). Node's rimraf only retries transient errors when maxRetries is
set, so a shared tests/tmp-rm.ts rmrf() with maxRetries:10/retryDelay:50 now
replaces all 354 bare recursive teardown calls across 91 test files, matching
the precedent already at issue1086-chain-self-exemption.test.ts:663. Orphaned
named rmSync imports dropped where no longer used. Test-only change.
The mechanical rmSync->rmrf replacement dropped the space after the closing brace in 44 node:fs import lines ('writeFileSync }from'). Valid TS, wrong style; pure formatting fix.
…se (#1646)

Rebase onto master pulled in tests/zcode-native.test.ts additions (PR #1648) that postdate this branch's base; they carry the same bare recursive teardown pattern. Same root cause, same scope.
@ranxianglei
ranxianglei force-pushed the 2026-09-29_test-teardown-rm-retry branch from 09dca22 to 7480989 Compare September 29, 2026 07:01
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review of PR #1655 (in progress — interim report)

Pulled the branch and audited it against the description before touching anything.

Description claims — all verified against the actual diff:

  • 354 bare recursive rmSync teardowns removed / 355 rmrf( lines added (= 354 call sites + the definition in tests/tmp-rm.ts), 91 test files importing the helper (90 via ./tmp-rm.ts, tests/e2e/e2e-registry.test.ts via ../tmp-rm.ts). Zero bare recursive rmSync left anywhere in tests/.
  • Every removed non-import rmSync line contained recursive: true; every added rmSync line lives only inside tmp-rm.ts. Single-file non-recursive { force: true } sites untouched, as claimed.
  • No orphaned rmSync imports remain in any file; best-effort try/catch teardown sites keep their catch around rmrf; the watchdog-health* awaited-sync oddity preserved as-is; the test: teardown rmSync ENOTEMPTY race — most test cleanups lack retry options (CI ubuntu-latest Node 22 flake) #1646 precedent site itself was converted to rmrf(root).
  • Scope confirmed test-only: zero product code, no config surface, no wire/persistence behavior touched.

Two problems found and fixed directly on the PR branch:

  1. Style defect in the mechanical replacement: 44 files ended with import { … }from "node:fs"; (space dropped between the brace and from). Valid TS, but a real blemish introduced by this PR — fixed in commit test: restore missing space between import braces and 'from' (#1655).
  2. Stale base: master moved to b1ba2209 (zcode work, PR feat(zcode): route:"all" default with per-entry exemptions — unified fix for #1621 #1622 #1623 #1648) since this branch forked. Rebased cleanly (one textual conflict in tests/zcode-native.test.ts imports — resolved by union). The rebase pulled in 15 new bare recursive rmSync teardowns that master's zcode commits added to tests/zcode-native.test.ts after this branch's base — same root cause, same scope, so they're converted to rmrf(dir) too (test: harden the 15 rmSync sites added by #1648 zcode work after rebase (#1646)). Without this, the PR's own invariant ("no bare recursive teardown left") would be false on merge.

Fresh pre-flight on the rebased head (74809894, = origin/2026-09-29_test-teardown-rm-retry):

  • npm run typecheck: PASS
  • npm test full suite: 3195 pass / 0 fail / 16 skipped (higher count than the original 3174 because master's zcode tests joined; the known issue1452-socket-hardening stall-guard flake did not appear)
  • npm run build: PASS

Pushed to the PR branch. CI is currently running on 74809894 (e2e job already green); I'll confirm here when the full matrix lands.

中文摘要:审查了本 PR(teardown rmSync 加重试选项),发现并修复了机械替换丢空格(44 文件)和 rebase 后 master 新增的 15 处同款裸 rmSync,本地全量预检通过,等 CI 全绿即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — CI fully green, ready to merge

① Original issue direction (#1646): correct root cause. The defect producer is the bare recursive rmSync teardown itself — Node's internal rimraf only retries transient errors (ENOTEMPTY, EACCES, EPERM, EMFILE, EBUSY) when maxRetries is set, so the first race between the proxy-under-test recreating entries and rmdir propagates into finally and turns a green suite red (observed: CI run 36520549393, issue1086-chain-self-exemption T3, ubuntu-latest Node 22, all assertions had passed). Fixing the retry options at the teardown call sites is fixing the source, not masking a symptom — litmus test holds: if the same race surfaces in any future test file, the shared-helper convention covers it as long as new files use rmrf.

② Regression audit — existing behaviors touched by the diff: the diff is 100% under tests/ (91 test files + new tests/tmp-rm.ts; zero product code, zero config surface, zero wire/persistence/format change). Per-file existing behavior checked: assertion logic untouched everywhere (diff-level proof: every removed non-import line was exactly a recursive rmSync(…, { recursive: true, force: true }) call, every added line is an import or rmrf( call); best-effort try/catch teardowns keep their catch around rmrf (mitm / admin-origin / admin-probe / tunnel-guard / ca-combined); single-file non-recursive { force: true } sites (17) deliberately untouched — no recursive means no rmdir race; the watchdog-health* awaited-sync oddity preserved as-is (still sync, still harmless); the #1646 precedent site converted to rmrf(root) so the tree uses one idiom. Worst-case added teardown latency ~2.75 s/path, only on runners that actually hit the race. No behavior drift of any kind.

③ Code review: tests/tmp-rm.ts is minimal and correct (maxRetries: 10, retryDelay: 50 matches the in-tree precedent at tests/issue1086-chain-self-exemption.test.ts:663). Counts verified by full-diff parse: 354 call sites removed / 355 rmrf( lines added (incl. definition), 91 importing files, zero bare recursive rmSync left in tests/ at head, zero orphaned rmSync imports.

④ Test validity: the gate is the real thing — full suite across the whole CI matrix (ubuntu 22/24, windows 22/24) plus e2e lanes, i.e. the loaded-runner environments where the race lives. All green below.

⑤ Diff cleanliness: clean — one linear history, every line serves the PR's purpose. My two additions are clearly-labeled in-scope fixes: the 44-file }from spacing repair, and converting the 15 new bare teardowns that master's zcode commits (#1648) added to tests/zcode-native.test.ts after this branch's base (same root cause, same scope; without them the PR's own invariant would be false on merge). Branch rebased onto current master b1ba2209 (one import-block conflict resolved by union).

Final state on head 74809894 (= origin/2026-09-29_test-teardown-rm-retry):

  • Local pre-flight: typecheck PASS · full suite 3195 pass / 0 fail / 16 skipped · build PASS
  • CI: all 13 checks success (ubuntu 22/24, windows 22/24, build-artifact, version-guard, e2e, hermetic registry e2e, pi/codex/opencode/dsh native lanes, codex CODEX_HOME overlay)
  • GitHub reports the PR mergeable: yes

Merging stays human-only per repo rules — #1655

中文摘要:审查并加固了本 PR(teardown rmSync 加 maxRetries 重试):修了机械替换丢空格(44 文件)、rebase 到最新 master 并补转 zcode 新增的 15 处同款裸 rmSync,本地与 CI(含 Windows 矩阵)全绿,可以合并。

@ranxianglei
ranxianglei merged commit e979449 into master Sep 29, 2026
13 checks passed
ranxianglei pushed a commit that referenced this pull request Sep 29, 2026
…1655 hardening dropped the import but missed this call)

Drive-by fix for a pre-existing master breakage found while reviewing
PR #1703: master's CI is red because this finally block calls rmSync,
which #1646/#1655 removed from the imports when converting teardowns to
the retry-hardened rmrf helper (tests/tmp-rm.ts). Every other teardown
in this file already uses rmrf; this one was missed. Without it, every
PR merge-ref run fails here.
This was referenced Sep 29, 2026
ranxianglei added a commit that referenced this pull request Oct 1, 2026
…s import in the #1655 teardown sweep

Rebase onto master removed the old base's rmSync import; the two new
#1577 doctor tests called it bare (same class as #1707). rmrf(base)
matches every other cleanup in this file.
@github-actions github-actions Bot mentioned this pull request Oct 2, 2026
@ranxianglei
ranxianglei deleted the 2026-09-29_test-teardown-rm-retry branch October 15, 2026 05:32
ranxianglei pushed a commit that referenced this pull request Oct 18, 2026
…PTY flake)

Last holdout of the #1646/#1655 teardown-hardening sweep: cleanup() used bare fs.rmSync, so a dying race child's tsx transform-cache write could outlive the parent's delete and fail the whole suite with ENOTEMPTY on Windows even though the lease assertions passed. Aligns with the repo-wide maxRetries/retryDelay pattern. Found while triaging red CI on the #3701 WS byte-budget branch.
LoveDoLove pushed a commit to LoveDoLove-Forked-Projects/billion-context that referenced this pull request Oct 19, 2026
…PTY)

tests/overlay-busy-lock.test.ts:27 was a bare-rmSync holdout from the ranxianglei#1655 sweep (family ranxianglei#1646/ranxianglei#1194/ranxianglei#1208/ranxianglei#2799/ranxianglei#2908). On the windows-22 CI shard its cleanup races tsx transform-cache writes left behind by the six racing children after SIGTERM and fails with ENOTEMPTY although every lease assertion passed (observed on PR ranxianglei#3706's CI run). Adopts the repo-standard { maxRetries: 10, retryDelay: 100 } pattern (tests/storage-replicas.test.ts:103 et al.). Pre-existing holdout, kept out of ranxianglei#3706's diff on purpose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: teardown rmSync ENOTEMPTY race — most test cleanups lack retry options (CI ubuntu-latest Node 22 flake)

1 participant