Skip to content

Commit 4c1d62e

Browse files
thymikeeclaude
andauthored
test: stop two tests failing on timing and megapixels (#1526)
Both of these blocked unrelated PRs today and neither is auto-retryable: #1419's contention retry declines find.test.ts as outside its enumerated list, and slow-gate failures cannot be re-checked by a rerun. Each occurrence costs a manual re-run. find.test.ts 'wait captures fresh snapshots while polling' asserted exactly 2 dispatches. The wait loop polls at a 300ms interval against a 350ms budget, and its last sleep consumes whatever remains, so it lands exactly on remainingMs() === 0 — a sleep returning a millisecond early admits a third poll. The count was never assertable. The test's actual subject is that each poll re-captures instead of reusing the first tree, so it now asserts that: at least two captures, every one a snapshot. The sibling assertion at the top of the file is left alone: it takes its count from mockResolvedValueOnce ordering, not from the clock. apps.test.ts built 1206x2622 (iPhone 16 Pro, 3.2 megapixels) source PNGs to prove two rescale ratios. Both sources are now 126x273 — still divisible by 3, so the /3 and 2/3 arithmetic stays exact — with expectations updated to match. Measured on this machine: the density test 1021ms -> 34ms, the retry test 1176ms -> 233ms, the file's test time 2.48s -> 1.00s. Both suites pass: 18/18 find, 54/54 apps. Claude-Session: https://claude.ai/code/session_01RXQLYV7etZx3gcXsUsrQJ8 Co-authored-by: Claude <[email protected]>
1 parent 2e0ed0a commit 4c1d62e

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎src/daemon/handlers/__tests__/find.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,13 @@ test('handleFindCommands wait captures fresh snapshots while polling', async ()
751751
if (!response.ok) {
752752
expect(response.error.message).toContain('find wait timed out');
753753
}
754-
expect(mockDispatch).toHaveBeenCalledTimes(2);
754+
// What this test guards is that every poll re-captures instead of reusing the first tree.
755+
// The exact poll count is a timing artifact and is not assertable: the loop's last sleep
756+
// consumes whatever remains of the budget, so it lands on `remainingMs() === 0`, and a
757+
// sleep that returns a millisecond early admits one more poll. Pinning this to 2 made the
758+
// test fail under CI load on unrelated PRs. Assert the property, not the artifact.
759+
expect(mockDispatch.mock.calls.length).toBeGreaterThanOrEqual(2);
760+
expect(mockDispatch.mock.calls.every(([, command]) => command === 'snapshot')).toBe(true);
755761
});
756762

757763
test('handleFindCommands click omits refsGeneration — a mutating find never issues a pinnable ref (ADR 0014)', async () => {

‎src/platforms/apple/core/__tests__/apps.test.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ test('screenshotIos retries simulator capture timeouts and eventually succeeds',
127127
const outPath = path.join(tmpDir, 'screen.png');
128128
const sourcePngPath = path.join(tmpDir, 'source.png');
129129

130-
await fs.writeFile(sourcePngPath, PNG.sync.write(new PNG({ width: 1206, height: 2622 })));
130+
// Dimensions divisible by 3 so the implicit density-1 rescale (against the stub's native
131+
// scale 3) stays exact. This test is about capture retry, not resolution, so the source is
132+
// small rather than the 1206x2622 iPhone 16 Pro frame it used to allocate and resize —
133+
// 3.2 megapixels to prove arithmetic that 34k pixels prove just as well (1176ms -> 233ms).
134+
await fs.writeFile(sourcePngPath, PNG.sync.write(new PNG({ width: 126, height: 273 })));
131135

132136
await fs.writeFile(
133137
xcrunPath,
@@ -205,8 +209,8 @@ test('screenshotIos retries simulator capture timeouts and eventually succeeds',
205209
try {
206210
await screenshotIos(IOS_TEST_SIMULATOR, outPath);
207211
const png = PNG.sync.read(await fs.readFile(outPath));
208-
assert.equal(png.width, 402);
209-
assert.equal(png.height, 874);
212+
assert.equal(png.width, 42);
213+
assert.equal(png.height, 91);
210214
assert.equal(await fs.readFile(screenshotCountPath, 'utf8'), '3\n');
211215

212216
const logLines = (await fs.readFile(commandLogPath, 'utf8')).trim().split('\n').filter(Boolean);
@@ -246,7 +250,11 @@ test('screenshotIos keeps requested simulator pixel density', async () => {
246250
const outPath = path.join(tmpDir, 'screen.png');
247251
const sourcePngPath = path.join(tmpDir, 'source.png');
248252

249-
await fs.writeFile(sourcePngPath, PNG.sync.write(new PNG({ width: 1206, height: 2622 })));
253+
// Both dimensions divisible by 3 so the 2/3 rescale (density 2 against the stub's native
254+
// scale 3) stays exact. What this pins is that ratio, not an absolute resolution: it used
255+
// to allocate and resize a 1206x2622 iPhone 16 Pro frame — 3.2 megapixels, ~90x more than
256+
// the arithmetic needs (1021ms -> 34ms).
257+
await fs.writeFile(sourcePngPath, PNG.sync.write(new PNG({ width: 126, height: 273 })));
250258
await fs.writeFile(
251259
xcrunPath,
252260
[
@@ -279,8 +287,8 @@ test('screenshotIos keeps requested simulator pixel density', async () => {
279287
try {
280288
await screenshotIos(IOS_TEST_SIMULATOR, outPath, { pixelDensity: 2 });
281289
const png = PNG.sync.read(await fs.readFile(outPath));
282-
assert.equal(png.width, 804);
283-
assert.equal(png.height, 1748);
290+
assert.equal(png.width, 84);
291+
assert.equal(png.height, 182);
284292
} finally {
285293
process.env.PATH = previousPath;
286294
if (previousScreenshotSourceFile === undefined)

0 commit comments

Comments
 (0)