Repository navigation
test(api): isolate loopback ports across worker processes - #891
Conversation
The ChatGPT sign-in flow binds the loopback port OpenAI registered for its public client, 127.0.0.1:1455. Several test files drive that flow, so running a lane in worker processes makes them compete for one machine-wide resource: the loser gets a spurious 503 ChatGptOAuthPortBusyError and the file that raised it loses its remaining cases. Running the suite at all also collides with a real `codex login` on the developer's machine. The loopback server now reports the port it actually bound, and both the authorize request and the token exchange derive their redirect URI from it instead of from the constant. Production still binds the registered port, so the redirect URI it sends is unchanged. setChatGptLoopbackPortForTest lets the test environment pin the port to 0, so every test process takes an OS-assigned one; the two cases that need a busy port now hold one themselves rather than squatting on a well-known number. The provider-agnostic loopback test shared the same shape with a fixed port 14559 and is fixed the same way. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
Every API test process creates ~/.mangostudio-test-<pid>-<worker> and nothing
ever removed it, so each run left one more behind: this checkout had 3178 of
them, 13 MB, in the user's home directory. `process.on('exit')` does not fire
under the Bun test runner, but an `afterAll` registered by the shared setup
does — once per isolate with `--isolate`, once per process without it — so the
directory is gone by the time the runner exits either way.
The worker component of that name was reading BUN_WORKER_ID, which Bun does
not set; every directory ever created was suffixed `-0`. Bun 1.3.14 exports
BUN_TEST_WORKER_ID, so the name now identifies the worker it belongs to. The
pid was already doing the isolating, so this changes no behaviour beyond the
name.
Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
The parallelism section carried the flag semantics and the cost table but not what actually breaks when the worker count goes up. It now names the one race the integration lane had, states the rule it came from — never bind a well-known port in a test, ask for 0 and read the bound port back — and records the reproduction technique that made an intermittent failure reliable: pin the run to CI's core count with taskset and capture whole logs. It also records the unit lane's remaining blocker as upstream, with the measurements, so the next reader does not spend the day re-deriving that the google-auth-library frames in the stack are the messenger rather than the cause. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
PR head: Commits — 6 commitsBase
Full commit messages
|
| Metric | Base | Head | Δ |
|---|---|---|---|
| Wall clock (shared jobs) | 9m 4s | 19m 11s | 🔴 ▲ +10m 7s |
| Critical path | Test / Unit & Integration Tests · 7m 15s |
Test / Unit & Integration Tests · 7m 33s |
🔴 ▲ +18s |
Since previous PR run: 9m 2s → 19m 11s (🔴 ▲ +10m 9s)
Five slowest head jobs
| Job | Base | Head | Δ |
|---|---|---|---|
Test / Unit & Integration Tests |
7m 15s | 7m 33s | 🔴 ▲ +18s |
Smoke — Browser / Chromium smoke suite |
2m 4s | 6m 44s | 🔴 ▲ +4m 40s |
Distribution / Build immutable distribution |
3m 30s | 3m 5s | 🟢 ▼ -25s |
QA Metrics / Collect |
1m 32s | 1m 37s | 🔴 ▲ +5s |
Smoke — Binary / Binary windows-arm64 |
45s | 49s | 🔴 ▲ +4s |
QA Gate — Coverage & Quality
Base: c10501b • Head: bdda098 • generated 2026-08-19T08:21:04.094Z
✅ No attention signals — collected metrics look healthy against base.
LoC (code): 🔴 ▲ +61 • Line coverage (all workspaces): ⚪ ▲ = 0 • Quick check: pass • Duplication: 🟢 ▼ -0pp • Bundle gzip: ⚪ ▲ = 0 • Locked deps: ⚪ ▲ = 0 • Tests passed: 🟢 ▲ +2
Metric details (coverage, LoC, bundle, dependencies, tests, duplication, tooling)
Coverage
API/shared/runtime branches and statements are source-derived from LCOV line hits because Bun LCOV does not emit branch or statement records.
| Workspace | Metric | Base | Head | Δ |
|---|---|---|---|---|
| frontend | lines | 86.19% (13,713/15,911) | 86.19% (13,713/15,911) | ⚪ ▲ = 0 |
| frontend | statements | 76.07% (7,825/10,287) | 76.07% (7,825/10,287) | ⚪ ▲ = 0 |
| frontend | functions | 72.75% (2,411/3,314) | 72.75% (2,411/3,314) | ⚪ ▲ = 0 |
| frontend | branches | 68.04% (5,636/8,283) | 68.04% (5,636/8,283) | ⚪ ▲ = 0 |
| api | lines | 82.25% (69,555/84,568) | 82.25% (69,566/84,579) | ⚪ ▲ = 0 |
| api | statements | 81.43% (28,008/34,395) | 81.44% (28,018/34,405) | 🟢 ▲ +0.01pp |
| api | functions | 85.03% (7,016/8,251) | 85.02% (7,017/8,253) | 🔴 ▼ -0.01pp |
| api | branches | 49.75% (10,469/21,043) | 49.75% (10,473/21,051) | ⚪ ▲ = 0 |
| shared | lines | 97.85% (14,380/14,696) | 97.85% (14,380/14,696) | ⚪ ▲ = 0 |
| shared | statements | 94.68% (2,618/2,765) | 94.68% (2,618/2,765) | ⚪ ▲ = 0 |
| shared | functions | 92.87% (430/463) | 92.87% (430/463) | ⚪ ▲ = 0 |
| shared | branches | 60.82% (902/1,483) | 60.82% (902/1,483) | ⚪ ▲ = 0 |
| runtime | lines | 81.90% (25,785/31,484) | 81.89% (25,783/31,484) | 🔴 ▼ -0.01pp |
| runtime | statements | 79.02% (9,472/11,987) | 79.00% (9,470/11,987) | 🔴 ▼ -0.02pp |
| runtime | functions | 78.02% (1,988/2,548) | 78.02% (1,988/2,548) | ⚪ ▲ = 0 |
| runtime | branches | 48.96% (3,635/7,425) | 48.94% (3,634/7,425) | 🔴 ▼ -0.02pp |
Lines of Code
| Workspace | Base | Head | Δ |
|---|---|---|---|
| frontend | 590 files / 68,052 lines | 590 files / 68,052 lines | files ⚪ ▲ = 0 • code ⚪ ▲ = 0 |
| api | 989 files / 144,569 lines | 989 files / 144,630 lines | files ⚪ ▲ = 0 • code 🔴 ▲ +61 |
| shared | 197 files / 27,217 lines | 197 files / 27,217 lines | files ⚪ ▲ = 0 • code ⚪ ▲ = 0 |
| runtime | 833 files / 42,015 lines | 833 files / 42,015 lines | files ⚪ ▲ = 0 • code ⚪ ▲ = 0 |
| total | 2,609 files / 281,853 lines | 2,609 files / 281,914 lines | files ⚪ ▲ = 0 • code 🔴 ▲ +61 |
Frontend Bundle
| Metric | Base | Head | Δ |
|---|---|---|---|
| gzip total | 843.1 KiB | 843.1 KiB | ⚪ ▲ = 0 |
| gzip JavaScript | 827.2 KiB | 827.2 KiB | ⚪ ▲ = 0 |
| gzip CSS | 15.0 KiB | 15.0 KiB | ⚪ ▲ = 0 |
| gzip HTML | 947 B | 947 B | ⚪ ▲ = 0 |
| tracked files | 35 | 35 | ⚪ ▲ = 0 |
Dependencies
| Metric | Base | Head | Δ |
|---|---|---|---|
| locked packages | 859 | 859 | ⚪ ▲ = 0 |
| direct dependencies | 43 | 43 | ⚪ ▲ = 0 |
| direct devDependencies | 41 | 41 | ⚪ ▲ = 0 |
| workspace manifests | 5 | 5 | ⚪ ▲ = 0 |
Tests
Single full-suite pass (unit + integration, from the coverage run).
| Base | Head | Δ passed |
|---|---|---|
| 6,564 passed (root 6,564 / frontend 0 / api 0 / shared 0 / runtime 0) · exit 0 · 409s | 6,566 passed (root 6,566 / frontend 0 / api 0 / shared 0 / runtime 0) · exit 0 · 417s | 🟢 ▲ +2 |
Code Duplication (jscpd)
| Metric | Base | Head | Δ |
|---|---|---|---|
| clones | 1,233 | 1,233 | ⚪ ▲ = 0 |
| duplicated lines | 14,477 | 14,476 | 🟢 ▼ -1 |
| percentage | 4.12% | 4.12% | 🟢 ▼ -0pp |
Repo Tooling
| Metric | Base | Head | Δ |
|---|---|---|---|
| Full repo check | pass | pass | ⚪ ▲ = 0 |
| TS errors (total) | 0 | 0 | ⚪ ▲ = 0 |
| Circular dependencies | 0 | 0 | ⚪ ▲ = 0 |
Every measurement of the epoll_ctl abort comes from one WSL2 host, and epoll_ctl is kernel surface, so "the unit lane cannot take worker parallelism" was a wider claim than the evidence carries. Say what was measured and where, and mark the runner case as untested rather than implied. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
The previous commit marked the runner case untested. It has now been tested: a non-blocking matrix on ubuntu-latest reproduced the abort in 2 of 36 runs of the unit lane at four workers, on a 4-core Azure kernel, so it is a property of the lane rather than of one WSL2 box. The same matrix ran the integration lane 12 times without a failure at 50.6s, which is the other half of the answer — that lane is ready, the unit lane is not. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
It is oven-sh/bun#37968, already reproduced and root-caused by Bun — a leaked epoll registration on a reused stdio descriptor at the isolate global swap — with a fix open at oven-sh/bun#38008. Naming it saves the next reader the investigation, and gives them the one thing worth checking first: whether the fix has shipped. Its recommended workaround, regular files instead of pipes, made the failure likelier rather than rarer in this suite, so the note says to measure before adopting it. Signed-off-by: Julio Polycarpo <julio@polycarpo.dev>
Summary
1455callback.Changes
0.redirect_uriconsistently for authorization and token exchange; update busy-port tests to arrange collisions explicitly.BUN_TEST_WORKER_IDfor test config paths, and remove those paths inafterAll.Test Plan
bun run checkpassesbun run testpassesbun run buildpasses@mangostudio/shared/i18n(no new UI strings)Screenshots / GIFs
Not applicable — backend, test infrastructure, and documentation changes only.
Notes
No new environment variables, schema changes, or breaking changes. Production continues to bind the registered ChatGPT callback port. The unit lane remains without worker parallelism pending upstream Bun fixes; the integration lane is covered by the passing CI test job.