Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/daemon/__tests__/interaction-outcome-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
buildInteractionSurfaceSignature,
classifyBaselineSurfaceEvidence,
classifyInteractionSurfaceChange,
discriminatingSurfaceChangedWithinRect,
markPendingInteractionOutcome,
stripInternalInteractionFlags,
} from '../interaction-outcome-policy.ts';
Expand Down Expand Up @@ -411,3 +412,58 @@ function makeSnapshotWithExtraText(label: string, y = 100): SnapshotState {
],
};
}

// ---------------------------------------------------------------------------
// discriminatingSurfaceChangedWithinRect (#2714 review): a whole-surface
// difference that lives outside the region a command acted on is not that
// command's doing. Measured on the Android tester, the status bar changed on
// its own over a list that never moved. The strict key-matched view stays
// owned here; this only narrows the region it is asked about.
// ---------------------------------------------------------------------------

const LIST_RECT = { x: 0, y: 150, width: 390, height: 600 };

function rowAt(index: number, y: number) {
return {
type: 'StaticText',
identifier: `row-${index}`,
label: `Row ${index}`,
rect: { x: 12, y, width: 300, height: 24 },
} as SnapshotState['nodes'][number];
}

function surfaceWithClock(clock: string, secondRowY: number) {
return [
{
type: 'Image',
identifier: 'status-clock',
label: clock,
rect: { x: 12, y: 12, width: 40, height: 18 },
} as SnapshotState['nodes'][number],
rowAt(1, 200),
rowAt(2, secondRowY),
];
}

test('discriminatingSurfaceChangedWithinRect reads a movement inside the region', () => {
const before = buildInteractionSurfaceSignature(surfaceWithClock('2:40', 300));
const after = buildInteractionSurfaceSignature(surfaceWithClock('2:40', 420));

assert.equal(discriminatingSurfaceChangedWithinRect(before, after, LIST_RECT), true);
});

test('discriminatingSurfaceChangedWithinRect does not read a movement outside the region', () => {
const before = buildInteractionSurfaceSignature(surfaceWithClock('2:40', 300));
const after = buildInteractionSurfaceSignature(surfaceWithClock('2:41', 300));

// The whole surface did change — that is the trap this reader exists to refuse.
assert.equal(classifyBaselineSurfaceEvidence(before, after), 'changed');
assert.equal(discriminatingSurfaceChangedWithinRect(before, after, LIST_RECT), false);
});

test('discriminatingSurfaceChangedWithinRect counts content appearing inside the region', () => {
const before = buildInteractionSurfaceSignature(surfaceWithClock('2:40', 300));
const after = buildInteractionSurfaceSignature([...surfaceWithClock('2:40', 300), rowAt(3, 640)]);

assert.equal(discriminatingSurfaceChangedWithinRect(before, after, LIST_RECT), true);
});
Loading
Loading