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
80 changes: 47 additions & 33 deletions test/integration/interaction-contract/coordinate.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { test } from 'vitest';
import type { InteractionGuarantee } from '@agent-device/contracts/interaction-guarantees';
import { makeSnapshotState } from '@agent-device/selectors/snapshot-geometry-fixtures';
import { assertRpcError, assertRpcOk } from '../provider-scenarios/assertions.ts';
import { PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS } from '../provider-scenarios/test-timeouts.ts';
import { scenarioName } from './coverage-manifest.ts';
import { COORDINATE_COVERAGE } from './coordinate.coverage.ts';
import { settledWelcomeSnapshot, viewportOnlySnapshot } from './fixtures.ts';
import { createContractDevice } from './runtime-harness.ts';
import { createContractClock, createContractDevice } from './runtime-harness.ts';
import { runnerTapEntry, runnerTapErrorEntry, withIosContractDaemon } from './daemon-harness.ts';

// ADR 0011 Layer 3, coordinate path: raw x/y tap, intentionally minimal
Expand Down Expand Up @@ -63,6 +64,7 @@ test(scenario('settleObservation'), async () => {
return { snapshot: settledWelcomeSnapshot() };
},
tap: async () => ({ ok: true }),
clock: createContractClock(),
});

const result = await device.interactions.press(
Expand All @@ -77,38 +79,50 @@ test(scenario('settleObservation'), async () => {
assert.deepEqual(settle.diff?.summary, { additions: 1, removals: 1, unchanged: 0 });
});

test(scenario('errorTaxonomy'), async () => {
await withIosContractDaemon(
[runnerTapErrorEntry(new Error('runner tap crashed'))],
async (daemon) => {
const press = await daemon.callCommand('press', ['100', '200']);
// An unclassified backend failure gets the shared fallback classification
// from normalizeError: stable code, original message, actionable hint.
const error = assertRpcError(press, 500, 'UNKNOWN', /runner tap crashed/);
assert.ok(typeof error.hint === 'string' && error.hint.length > 0);
assert.ok(typeof error.diagnosticId === 'string');
},
);
});
test(
scenario('errorTaxonomy'),
async () => {
await withIosContractDaemon(
[runnerTapErrorEntry(new Error('runner tap crashed'))],
async (daemon) => {
const press = await daemon.callCommand('press', ['100', '200']);
// An unclassified backend failure gets the shared fallback classification
// from normalizeError: stable code, original message, actionable hint.
const error = assertRpcError(press, 500, 'UNKNOWN', /runner tap crashed/);
assert.ok(typeof error.hint === 'string' && error.hint.length > 0);
assert.ok(typeof error.diagnosticId === 'string');
},
);
},
PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS,
);

test(scenario('responseConstruction'), async () => {
await withIosContractDaemon([runnerTapEntry({ x: 100, y: 200 })], async (daemon) => {
const press = await daemon.callCommand('press', ['100', '200']);
const data = assertRpcOk(press);
// Canonical point response set: the tapped coordinates, no fabricated
// identity fields (the path has no resolved node by design).
assert.equal(data.x, 100);
assert.equal(data.y, 200);
assert.equal(data.ref, undefined);
assert.equal(data.selector, undefined);
});
});
test(
scenario('responseConstruction'),
async () => {
await withIosContractDaemon([runnerTapEntry({ x: 100, y: 200 })], async (daemon) => {
const press = await daemon.callCommand('press', ['100', '200']);
const data = assertRpcOk(press);
// Canonical point response set: the tapped coordinates, no fabricated
// identity fields (the path has no resolved node by design).
assert.equal(data.x, 100);
assert.equal(data.y, 200);
assert.equal(data.ref, undefined);
assert.equal(data.selector, undefined);
});
},
PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS,
);

// Inapplicable cell (ADR 0012), so intentionally absent from the coverage manifest.
test('coordinate resolutionDisclosure: inapplicable — no resolution field is attached', async () => {
await withIosContractDaemon([runnerTapEntry({ x: 100, y: 200 })], async (daemon) => {
const press = await daemon.callCommand('press', ['100', '200']);
const data = assertRpcOk(press);
assert.equal(data.resolution, undefined);
});
});
test(
'coordinate resolutionDisclosure: inapplicable — no resolution field is attached',
async () => {
await withIosContractDaemon([runnerTapEntry({ x: 100, y: 200 })], async (daemon) => {
const press = await daemon.callCommand('press', ['100', '200']);
const data = assertRpcOk(press);
assert.equal(data.resolution, undefined);
});
},
PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS,
);
10 changes: 6 additions & 4 deletions test/integration/interaction-contract/daemon-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
export const CONTRACT_APP = 'com.example.app';
const CONTRACT_DEVICE_ID = PROVIDER_SCENARIO_IOS_SIMULATOR.id;

const SETTLING_CAPTURE_READS = 2;
// The open opts out of post-open stabilization: the lane proves dispatch shape, and the stabilization
// loop would poll the first capture on a 200ms schedule for a screen nothing here watches. The
// harness's own snapshot is then the first capture after the open and reads the first screen once.
// Each scenario's conversation with the runner follows, exactly as scripted.
const SETTLING_CAPTURE_READS = 1;

/**
* Provider-transcript harness for contract scenarios whose path involves the
Expand All @@ -37,9 +41,6 @@ export async function withIosContractDaemon(
run: (daemon: ProviderScenarioHarness, transcript: ProviderScenarioTranscript) => Promise<void>,
options: { saveScript?: boolean | string } = {},
): Promise<void> {
// The scripted open is not read back, so the first capture after it settles over a quiet pair of
// reads and pauses the direct selector path. A snapshot consumes that pair here, keeping each
// scenario's own conversation with the runner exactly as scripted.
const transcript = createProviderTranscript([
...Array.from({ length: SETTLING_CAPTURE_READS }, () =>
runnerSnapshotEntry(FIRST_SCREEN_NODES),
Expand Down Expand Up @@ -74,6 +75,7 @@ export async function withIosContractDaemon(
const open = await daemon.callCommand('open', [CONTRACT_APP], {
platform: 'ios',
udid: CONTRACT_DEVICE_ID,
postGestureStabilization: false,
...(options.saveScript !== undefined ? { saveScript: options.saveScript } : {}),
});
assertRpcOk(open);
Expand Down
Loading
Loading