|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { test } from 'vitest'; |
| 3 | +import type { InteractionGuarantee } from '../../../src/contracts/interaction-guarantees.ts'; |
| 4 | +import { makeSnapshotState } from '../../../src/__tests__/test-utils/index.ts'; |
| 5 | +import { assertRpcError, assertRpcOk } from '../provider-scenarios/assertions.ts'; |
| 6 | +import { scenarioName } from './coverage-manifest.ts'; |
| 7 | +import { COORDINATE_COVERAGE } from './coordinate.coverage.ts'; |
| 8 | +import { viewportOnlySnapshot } from './fixtures.ts'; |
| 9 | +import { createContractDevice } from './runtime-harness.ts'; |
| 10 | +import { runnerTapEntry, runnerTapErrorEntry, withIosContractDaemon } from './daemon-harness.ts'; |
| 11 | + |
| 12 | +// ADR 0011 Layer 3, coordinate path: raw x/y tap, intentionally minimal |
| 13 | +// semantics. Path forcing is natural: a point target never resolves nodes. |
| 14 | + |
| 15 | +const scenario = (guarantee: InteractionGuarantee): string => |
| 16 | + scenarioName(COORDINATE_COVERAGE, guarantee); |
| 17 | + |
| 18 | +test(scenario('offscreen'), async () => { |
| 19 | + const device = createContractDevice(viewportOnlySnapshot(), { |
| 20 | + tap: async () => ({ ok: true }), |
| 21 | + }); |
| 22 | + |
| 23 | + const result = await device.interactions.click( |
| 24 | + { kind: 'point', x: 500, y: 500 }, |
| 25 | + { session: 'default' }, |
| 26 | + ); |
| 27 | + |
| 28 | + // Coordinate semantics: the escape hatch forwards the tap but must warn — |
| 29 | + // never a silent out-of-viewport no-op, never a refusal. |
| 30 | + assert.equal(result.kind, 'point'); |
| 31 | + assert.match(result.warning ?? '', /outside the last-known viewport \(400x800\)/); |
| 32 | +}); |
| 33 | + |
| 34 | +test(scenario('verifyEvidence'), async () => { |
| 35 | + let captureCount = 0; |
| 36 | + const device = createContractDevice(viewportOnlySnapshot(), { |
| 37 | + captureSnapshot: async () => { |
| 38 | + captureCount += 1; |
| 39 | + if (captureCount === 1) return { snapshot: viewportOnlySnapshot() }; |
| 40 | + return { snapshot: makeSnapshotState([]) }; |
| 41 | + }, |
| 42 | + tap: async () => ({ ok: true }), |
| 43 | + }); |
| 44 | + |
| 45 | + const result = await device.interactions.click( |
| 46 | + { kind: 'point', x: 10, y: 20 }, |
| 47 | + { session: 'default', verify: true }, |
| 48 | + ); |
| 49 | + |
| 50 | + assert.equal(result.kind, 'point'); |
| 51 | + assert.ok(result.evidence); |
| 52 | + assert.equal(result.evidence?.changedFromBefore, true); |
| 53 | +}); |
| 54 | + |
| 55 | +test(scenario('errorTaxonomy'), async () => { |
| 56 | + await withIosContractDaemon( |
| 57 | + [runnerTapErrorEntry(new Error('runner tap crashed'))], |
| 58 | + async (daemon) => { |
| 59 | + const press = await daemon.callCommand('press', ['100', '200']); |
| 60 | + // An unclassified backend failure gets the shared fallback classification |
| 61 | + // from normalizeError: stable code, original message, actionable hint. |
| 62 | + const error = assertRpcError(press, 'UNKNOWN', /runner tap crashed/); |
| 63 | + assert.ok(typeof error.hint === 'string' && error.hint.length > 0); |
| 64 | + assert.ok(typeof error.diagnosticId === 'string'); |
| 65 | + }, |
| 66 | + ); |
| 67 | +}); |
| 68 | + |
| 69 | +test(scenario('responseConstruction'), async () => { |
| 70 | + await withIosContractDaemon([runnerTapEntry({ x: 100, y: 200 })], async (daemon) => { |
| 71 | + const press = await daemon.callCommand('press', ['100', '200']); |
| 72 | + const data = assertRpcOk(press); |
| 73 | + // Canonical point response set: the tapped coordinates, no fabricated |
| 74 | + // identity fields (the path has no resolved node by design). |
| 75 | + assert.equal(data.x, 100); |
| 76 | + assert.equal(data.y, 200); |
| 77 | + assert.equal(data.ref, undefined); |
| 78 | + assert.equal(data.selector, undefined); |
| 79 | + }); |
| 80 | +}); |
0 commit comments