Skip to content

Commit e43dd7a

Browse files
committed
test(settle): keep a daemon-route dismissal asserting the confirmation, and pin the parity gap
The review on this PR found that padding the provider-scenario dialog past the arming rule's size bound (SHARED_SCREEN_NODES) silently removed the only test that checked the 1.5s confirmation through the daemon: the transition stopped being broad (4 of 6 identities survive), so `waitedMs >= 1_500` had to become `captures in 2..3`. Revert that padding, which restores the unpadded dialog and its original assertion; all four provider-scenario cases pass on this rule. Add the parity case the review asked for: the same presented sheet dismissed from an interactive baseline (4 nodes, as `snapshot -i` projects it) and from a full-tree read of the same screen (6 nodes), both asserted to confirm. Measured on the injected clock, the interactive baseline confirms for 1,502ms and the full-tree baseline for 27ms with `settled: true` either way — #1831's guard lost on the route whose baseline happens to be the richer flavour. Marked `fails`, so the lane stays green and the case turns red ("expected to fail but passed") the moment #3565's `presentedSurface` replaces the count bound: that red is the signal to drop the marker, and the assertion is the rewrite's acceptance test.
1 parent 76bbe24 commit e43dd7a

2 files changed

Lines changed: 252 additions & 136 deletions

File tree

‎src/daemon/__tests__/generic-settle.test.ts‎

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type SettlePayload = {
7575
captures: number;
7676
quietMs: number;
7777
timeoutMs: number;
78+
waitedMs: number;
7879
refsGeneration?: number;
7980
diff?: {
8081
summary: { additions: number; removals: number; unchanged: number };
@@ -113,7 +114,7 @@ async function emulateCaptureSnapshotForSession(
113114
}
114115

115116
function mockCommandDispatch(
116-
snapshots: Array<typeof BEFORE_NODES>,
117+
snapshots: RawSnapshotNode[][],
117118
producer: NonNullable<GenericSettleTree['producer']> = 'apple-runner',
118119
) {
119120
let snapshotCalls = 0;
@@ -554,6 +555,138 @@ test('back --settle attaches no diff across a sheet-to-app surface change and di
554555
expect(stored.snapshot?.iosSystemSurfaceBundleId).toBeUndefined();
555556
});
556557

558+
// The same presented sheet, as the two capture flavours leave it on the session. A `pageSheet`
559+
// offered by an interactive capture carries only the surface — the content underneath is not
560+
// hittable, so it drops out of the projection (4 nodes on the iPhone 18 Pro sim, October 2026) —
561+
// while a full read of the very same screen also reports the covered content (6 nodes). Arming the
562+
// broad-transition confirmation must not depend on which flavour produced the baseline.
563+
const PRESENTED_SHEET_INTERACTIVE_NODES: RawSnapshotNode[] = [
564+
{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 390, height: 844 } },
565+
{
566+
index: 1,
567+
parentIndex: 0,
568+
type: 'StaticText',
569+
label: 'Allow notifications?',
570+
rect: { x: 10, y: 450, width: 370, height: 22 },
571+
},
572+
{
573+
index: 2,
574+
parentIndex: 0,
575+
type: 'Button',
576+
label: 'Continue',
577+
rect: { x: 10, y: 600, width: 370, height: 44 },
578+
hittable: true,
579+
},
580+
{
581+
index: 3,
582+
parentIndex: 0,
583+
type: 'Button',
584+
label: 'Cancel',
585+
rect: { x: 10, y: 660, width: 370, height: 44 },
586+
hittable: true,
587+
},
588+
];
589+
590+
const PRESENTED_SHEET_FULL_NODES: RawSnapshotNode[] = [
591+
...PRESENTED_SHEET_INTERACTIVE_NODES,
592+
{
593+
index: 4,
594+
parentIndex: 0,
595+
type: 'Other',
596+
label: 'CoveredContent',
597+
rect: { x: 0, y: 0, width: 390, height: 440 },
598+
},
599+
{
600+
index: 5,
601+
parentIndex: 0,
602+
type: 'Button',
603+
label: 'Open settings',
604+
rect: { x: 10, y: 120, width: 370, height: 44 },
605+
},
606+
];
607+
608+
/** The app screen the sheet is dismissed from, which is what every settle capture then reads. */
609+
const SHEET_DISMISSED_NODES: RawSnapshotNode[] = [
610+
{ index: 0, type: 'Application', rect: { x: 0, y: 0, width: 390, height: 844 } },
611+
{
612+
index: 1,
613+
parentIndex: 0,
614+
type: 'StaticText',
615+
label: 'Signed in as demo',
616+
rect: { x: 10, y: 80, width: 200, height: 22 },
617+
},
618+
{
619+
index: 2,
620+
parentIndex: 0,
621+
type: 'Button',
622+
label: 'Home',
623+
rect: { x: 10, y: 120, width: 370, height: 44 },
624+
hittable: true,
625+
},
626+
{
627+
index: 3,
628+
parentIndex: 0,
629+
type: 'TabBar',
630+
label: 'Tab Bar',
631+
rect: { x: 0, y: 800, width: 390, height: 44 },
632+
},
633+
];
634+
635+
/**
636+
* `back --settle` over a sheet left on the session by a capture of one given flavour, which is how
637+
* the generic route picks its baseline (`generic-settle.ts` reads the stored tree directly). The
638+
* flavour is the only thing the two callers vary; the settle loop's budget arithmetic runs on the
639+
* injected clock, so neither waits real time.
640+
*/
641+
async function dismissSheetFromBaseline(
642+
sessionName: string,
643+
baseline: RawSnapshotNode[],
644+
): Promise<SettlePayload> {
645+
const sessionStore = makeSessionStore();
646+
seedSession(sessionName, sessionStore, { nodes: baseline });
647+
mockCommandDispatch([SHEET_DISMISSED_NODES]);
648+
const response = await dispatchGeneric({
649+
sessionName,
650+
sessionStore,
651+
command: 'back',
652+
flags: { settle: true, settleQuietMs: 25, timeoutMs: 30_000 },
653+
clock: fakeClock(),
654+
});
655+
return expectOkData(response).settle as SettlePayload;
656+
}
657+
658+
// PARITY GAP — ASSERTED, AND CURRENTLY UNMET. Arming the confirmation here reads the baseline's node
659+
// count, so the same sheet disarms when the baseline arrives as a full read (6 nodes) instead of an
660+
// interactive one (4). Both transitions ARE broad — the dismissed screen keeps only the Application
661+
// identity from either baseline — so the only thing that differs is which flavour
662+
// `resolveSettleBaseline` handed the loop. Measured at this head on the injected clock: the
663+
// interactive baseline confirms for 1,502ms, the full-tree baseline for 27ms, and `settled: true`
664+
// either way. Marked `fails` so the suite states the gap without turning the lane red; when #3565's
665+
// producer-stamped `presentedSurface` replaces the count bound, vitest reports this as
666+
// "expected to fail but passed" — that failure is the signal to drop the marker, and the assertion
667+
// is the acceptance criterion for the rewrite.
668+
test.fails('the confirmation arms for one presented sheet whichever baseline flavour the route holds', async () => {
669+
const interactive = await dismissSheetFromBaseline(
670+
'generic-settle-dismiss-sheet-interactive',
671+
PRESENTED_SHEET_INTERACTIVE_NODES,
672+
);
673+
const full = await dismissSheetFromBaseline(
674+
'generic-settle-dismiss-sheet-full',
675+
PRESENTED_SHEET_FULL_NODES,
676+
);
677+
678+
expect(interactive.settled).toBe(true);
679+
expect(full.settled).toBe(true);
680+
expect(
681+
interactive.waitedMs,
682+
'interactive baseline did not confirm the dismissal',
683+
).toBeGreaterThanOrEqual(1_500);
684+
expect(
685+
full.waitedMs,
686+
`full-tree baseline lost the #1831 confirmation: ${full.waitedMs}ms vs the interactive baseline's ${interactive.waitedMs}ms`,
687+
).toBeGreaterThanOrEqual(1_500);
688+
});
689+
557690
test('the settle observation runs after the post-gesture stabilization marker', async () => {
558691
const sessionStore = makeSessionStore();
559692
const sessionName = 'generic-settle-order';

0 commit comments

Comments
 (0)