Skip to content

Commit d7046b0

Browse files
committed
test: stub the freshness-retry sleep so the capture-parity test doesn't real-wait
The #1264 capture-parity regression exercised the real Android sharp-drop retry, which awaited the real ~250 ms `sleep` delay — repo guidance forbids real-time waits in unit tests. Mock `sleep` (the delay the retry path in snapshot-capture.ts awaits) to a no-op at the module level, so the retry BRANCH still executes (loop runs, retries, re-captures) without a wall-clock wait. The test still proves the branch: two on-device dispatches and use of the retried fresh tree (overlay present). Verified it still fails on the pre-fix single-shot path (1 dispatch) with the delay stubbed, so the stub does not make it vacuous. No production change; the delay stub needs no DI seam since `sleep` is a plain module export. Refs #1264
1 parent 529cb0f commit d7046b0

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎src/daemon/handlers/__tests__/session-replay-divergence.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ vi.mock('../../../core/dispatch.ts', async (importOriginal) => {
88
return { ...actual, dispatchCommand: vi.fn(async () => ({})), resolveTargetDevice: vi.fn() };
99
});
1010

11+
// Stub the Android freshness-retry delay to a no-op so the capture-parity test
12+
// exercises the retry BRANCH without a real wall-clock wait (repo guidance:
13+
// no real-time sleeps in unit tests). This is the exact `sleep` the retry path
14+
// in `snapshot-capture.ts` (`capturePostActionAwareSnapshot`) awaits; making it
15+
// instant does not change control flow — the loop still runs, retries, and
16+
// re-captures — so the test still proves two dispatches and use of the retried
17+
// tree. No other test in this file triggers a sleep path.
18+
vi.mock('../../../utils/timeouts.ts', async (importOriginal) => {
19+
const actual = await importOriginal<typeof import('../../../utils/timeouts.ts')>();
20+
return { ...actual, sleep: vi.fn(async () => {}) };
21+
});
22+
1123
import { dispatchCommand } from '../../../core/dispatch.ts';
1224
import {
1325
makeAndroidSession,
@@ -825,7 +837,8 @@ test('buildReplayFailureDivergence: a mass-covered app with no actionable overla
825837
// on-device dump is a stale, near-empty tree (sharp node-count drop, no
826838
// meaningful content → the `sharp-drop` retry trigger), and only the RETRIED
827839
// second dump contains the system overlay. The divergence must reflect the
828-
// retried tree.
840+
// retried tree. The retry delay (`sleep`) is stubbed to a no-op at the top of
841+
// this file, so the retry BRANCH runs without a real wall-clock wait.
829842
test('buildReplayFailureDivergence: routes through the freshness-retry wrapper and uses the retried fresh tree, not the first stale dump (#1264 capture parity)', async () => {
830843
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-replay-divergence-fresh-'));
831844
const sessionStore = new SessionStore(path.join(root, 'sessions'));

0 commit comments

Comments
 (0)