Repository navigation
test: poll for proxy-origin in claude hook e2e (fixes #1031 flake) - #1033
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1033Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1033.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到。这是已完成的 PR(#1033),按规范不重做——正在拉取分支核对代码、检查 CI 状态,稍后给出结论。 Acknowledged — this is a completed PR, so I'm reviewing rather than redoing it: fetching |
The proxy writes <state>/billion-context/proxy-origin inside its 'listening' callback, which runs AFTER the kernel starts accepting TCP connects on the port. The hook-e2e assertions therefore race: waitForPort can return while the file is still absent (#1031, ~1-in-4 full-suite runs, ENOENT at the immediate readFileSync). Add waitForInstanceFile (bounded 30s poll, 50ms interval; non-ENOENT errors rethrow; timeout = hard failure) and use it at the three spawn-path reads in the hook e2e tests. Post-attach settled-state reads and the cleanup sweep keep their immediate reads by design.
c8004b0 to
2e6e58d
Compare
[bot] 🏷 ## Review complete — ✅ mergeable 中文摘要:修复了 claude hook e2e 里 proxy-origin 文件的竞态(端口已可连接但文件尚未落盘时的一次性 What I verifiedDiff matches the description exactly. Single file
Settled-state reads keep immediate reads by design: Root-cause claim holds against current master. Stale base handled. The branch was 14 commits behind master, and 5 of those touched this same test file (the #964 claude-hook work) — a hot-file collision risk. I cherry-picked the commit onto current master ( Verification on the rebased head (run locally):
Branch updated. Force-pushed the rebased commit to Merge when ready: #1033 |
What
Fixes #1031 —
hook e2e: a healthy proxy on ANOTHER port is never attached (static URL)flaked withENOENT ... proxy-origin(~1 in 4 full-suite runs).Test-only change to
tests/claude-native.test.ts(+21/-3):waitForInstanceFile(file, ms): bounded poll (50ms interval) for<state>/billion-context/proxy-origin; non-ENOENT errors rethrow; still absent past the deadline = hard failure with a clear message.waitForPortnow use it (static-URL test ×2, second-run test ×1). Post-attach settled-state reads and the cleanup sweep keep immediate reads by design.Why this is the right layer
The race is real and structural, verified empirically before touching anything:
proxy-originsynchronously inside its'listening'callback (src/server.tsannounceListening). The kernel starts accepting TCP connects on the port before that callback runs — a micro-repro of the exact pattern (child http server writing a marker in'listening', parent tight-polling fresh ports, n=300) shows the port connectable with the marker absent in 23/300 runs (~7.7%) unloaded, widening under load.[bind, write]window, e.g. when startup is delayed under full-suite concurrency and the test's first successful port probe lands inside the window.readFileSyncafterwaitForPort. The issue's suggested fix (poll for the file / await a deterministic signal, keep negative assertions on settled state) is exactly what this implements.The poll also converts the residual "file never written" case (swallowed error in
announceListening's best-effort try/catch) from a racy ENOENT into a deterministic timeout failure — no more false greens or false reds depending on timing luck.Verification
npm run typecheckgreen (src); root tsconfig clean for the touched file (pre-existing unrelated errors inws-upgrade.test.ts/zero-config-routing.test.tsunchanged).tests/claude-native.test.ts×4 back-to-back: 23/23 pass each run.npm test: 2020 tests, 2018 pass, 0 fail, 2 skipped (expected skips).No wire/config/persistence changes; both compression modes unaffected.