From 87a04ca6f815d3c8f17be1ee0bb54dc8ead6b901 Mon Sep 17 00:00:00 2001 From: Epinephrine Date: Thu, 12 Nov 2026 17:58:31 +0900 Subject: [PATCH 1/2] test(gui): await the target-switch layout commit before assertions --- gui/tests/codex-account-pool-target-switch.test.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/tests/codex-account-pool-target-switch.test.tsx b/gui/tests/codex-account-pool-target-switch.test.tsx index c0f34182ab0..34117fe5beb 100644 --- a/gui/tests/codex-account-pool-target-switch.test.tsx +++ b/gui/tests/codex-account-pool-target-switch.test.tsx @@ -143,7 +143,12 @@ async function switchTarget(targetKey: string, releasePrevious: () => void) { configureApiTargets(relay("/same", targetKey)); actEnvironment(false); try { - root!.render(); + // A timer scheduled before React commits can win the race on a loaded runner. + // Observe the layout commit itself; release the old read in that same phase so + // the regression still exercises the interval before passive effects run. + await new Promise(resolve => { + root!.render( { releasePrevious(); resolve(); }} />); + }); await new Promise(resolve => setTimeout(resolve, 0)); } finally { actEnvironment(true); From 92bff195de8bf433f7ba0e0482c5dc9061d6cb1c Mon Sep 17 00:00:00 2001 From: luvs01 Date: Mon, 16 Nov 2026 09:19:09 +0900 Subject: [PATCH 2/2] test(gui): wait for the new target read to reach in-flight state The layout-commit wait still could not prove the new target's passive-effect read had started: the hook kicks it from a passive effect plus a queued microtask, so a trailing zero-delay timer could observe only two reads on a loaded runner (the still-open review finding). Wait until the fixture's own in-flight state is painted instead: refreshing turns true only after the read's fetch was issued and React committed the new counter, so the timer becomes a yield between observations rather than an effect-ordering assumption. Releasing the old read stays in the layout phase, preserving the regression window. Verified: bun test tests/codex-account-pool-target-switch.test.tsx -> 13 pass / 0 fail / 86 assertions (4 runs); bun run build (tsc -b + vite + vite classic) passed; git diff --check passed. Baseline and change both emit the same flaky not-wrapped-in-act noise, so none is introduced. --- gui/tests/codex-account-pool-target-switch.test.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gui/tests/codex-account-pool-target-switch.test.tsx b/gui/tests/codex-account-pool-target-switch.test.tsx index 34117fe5beb..f1f8761009f 100644 --- a/gui/tests/codex-account-pool-target-switch.test.tsx +++ b/gui/tests/codex-account-pool-target-switch.test.tsx @@ -149,7 +149,15 @@ async function switchTarget(targetKey: string, releasePrevious: () => void) { await new Promise(resolve => { root!.render( { releasePrevious(); resolve(); }} />); }); - await new Promise(resolve => setTimeout(resolve, 0)); + // The new target's first read is kicked from a passive effect plus a queued + // microtask, so the layout commit alone cannot prove it started. Wait until the + // in-flight state is painted: `refreshing` turns true only after the read's + // fetch was issued and React committed the new counter. The timer is the yield + // between observations, not an assumption that effects have completed. + for (let spins = 0; seen?.refreshing !== true; spins += 1) { + if (spins >= 1000) throw new Error("the new target's read never reached in-flight state"); + await new Promise(resolve => setTimeout(resolve, 0)); + } } finally { actEnvironment(true); }