Files
callstack__agent-device/test/integration/provider-scenarios/assertions.ts
Michał Pierzchała e832325e87 refactor(substrate): split host mechanics into @agent-device/host-kit capability ports (#2088)
* refactor: split generic host mechanics into @agent-device/host-kit (#2082 W1)

The shared src/utils closure that blocked the platform-family moves lands
on declared owners: generic host mechanics form a new private
@agent-device/host-kit package between kernel and capture-kit, and
capture-kit keeps capture, snapshot, and recording behavior, depending on
host-kit for the mechanics it needs. tar-stream and yauzl move with the
archive code.

Every seam's exported subpaths are pinned in package-boundaries.test.ts,
the layering model ranks the new zone, R13's allow-list names it, and each
seam carries an exact eager-closure row. ADR-0019's substrate amendment
describes the layout.

Tests that mocked two of the moved modules separately became duplicate
same-seam vi.mock factories, where the second silently replaced the first;
those are merged, and the mocks that production code reaches past are
pinned at their injection points instead.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* refactor(host-kit): one narrow capability port per export

The four technical barrels (exec/fs/values/request) grouped by category
rather than by capability, so a consumer needing one mechanic evaluated
unrelated ones. Each export is now a single capability over the host
machine: command, process, diagnostics, retry, archive, file, request,
version. A port re-exports only what a consumer of that capability uses,
and every port carries its own eager-closure row.

Most of the old values barrel was never host mechanics. Pure record
readers, config-source values, result text, memoization, async scoping,
coordinate validation, and device-scope parsing touch no process, file, or
environment, so they join kernel's other primitives instead.

Closures fall accordingly: capture-kit's png-worker-client from 20 to 10,
png-resize from 28 to 18, session-teardown from 79 to 68, and the CLI from
386 to 380.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* chore: drop the migration inventories and trim the touched comments

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* docs: trim the touched host-kit and mutation-lane comments

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* docs: keep tool directives only in the touched files

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* docs: keep tool directives only across the touched tree

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* fix: point the Swift parity comment at the real TS twin and test

The W1 move rewrote this citation to packages/contracts/src/mobile-snapshot-semantics.ts,
which does not exist: the module went to capture-kit while isTapPointInsideViewport itself
went to packages/contracts/src/snapshot-visibility.ts. The TS test line was left pointing at
the pre-move path. Both now resolve.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

* fix: repoint comment citations at the homes this refactor moved them to

The W1 move left ~20 comment citations pointing at src/utils/*.ts and
src/request/*.ts paths that no longer exist. Each now names the capability
port that owns the symbol, which survives further file moves:

  exec -> host-kit/command          host-process, owner-identity -> host-kit/process
  diagnostics -> host-kit/diagnostics   atomic-file, process-lock -> host-kit/file
  retry -> host-kit/retry           request progress/cancel -> host-kit/request
  version -> host-kit/version       ttl-memo, source-value, parsing, device-isolation,
                                    keyed-lock, success-text -> kernel subpaths

Comment-only; no closure, budget, or behavior change. ADR citations are left
as written, being dated records of the decision rather than live references.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018VngeKZH6zBuJzNBk5YzUH

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-28 07:46:48 +02:00

116 lines
3.7 KiB
TypeScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import { PNG } from '@agent-device/capture-kit/png';
import type { ProviderScenarioRpcResult } from './harness.ts';
export function assertCommandCall(calls: readonly string[][], expected: readonly string[]): void {
assert.ok(
calls.some((call) => arrayEqual(call, expected)),
`Expected command call ${JSON.stringify(expected)} in ${JSON.stringify(calls)}`,
);
}
export function assertFlatToolCall(
calls: Array<[string, ...string[]]>,
expected: [string, ...string[]],
): void {
assert.ok(
calls.some((call) => arrayEqual(call, expected)),
`Expected tool call ${JSON.stringify(expected)} in ${JSON.stringify(calls)}`,
);
}
export function assertFlatToolCallStartsWith(
calls: Array<[string, ...string[]]>,
expected: [string, ...string[]],
): void {
assert.ok(
calls.some((call) => arrayStartsWith(call, expected)),
`Expected tool call starting with ${JSON.stringify(expected)} in ${JSON.stringify(calls)}`,
);
}
export function assertRpcOk<TData extends Record<string, unknown> = Record<string, unknown>>(
response: ProviderScenarioRpcResult,
): TData {
assert.equal(response.statusCode, 200, JSON.stringify(response.json));
assert.equal(response.json?.error, undefined, JSON.stringify(response.json));
return (response.json?.result?.data ?? {}) as TData;
}
export function assertRpcError(
response: ProviderScenarioRpcResult,
code: string,
message: RegExp,
): Record<string, unknown> {
assert.equal(response.statusCode, 200, JSON.stringify(response.json));
assert.equal(response.json?.error?.data?.code, code, JSON.stringify(response.json));
assert.match(response.json?.error?.message ?? '', message);
return (response.json?.error?.data ?? {}) as Record<string, unknown>;
}
export function assertRecordingStarted(
response: ProviderScenarioRpcResult,
options: { outPath?: string; showTouches?: boolean } = {},
): void {
const data = assertRpcOk<{
recording?: unknown;
outPath?: unknown;
showTouches?: unknown;
}>(response);
assert.equal(data.recording, 'started');
if (options.outPath !== undefined) {
assert.equal(data.outPath, options.outPath);
}
if ('showTouches' in options) {
assert.equal(data.showTouches, options.showTouches);
}
}
export function assertRecordingStopped(
response: ProviderScenarioRpcResult,
outPath: string,
options: { showTouches?: boolean } = {},
): void {
const data = assertRpcOk<{
recording?: unknown;
outPath?: unknown;
showTouches?: unknown;
artifacts?: Array<{ path?: unknown }>;
}>(response);
assert.equal(data.recording, 'stopped');
assert.equal(data.outPath, outPath);
if ('showTouches' in options) {
assert.equal(data.showTouches, options.showTouches);
}
assert.equal(data.artifacts?.[0]?.path, outPath);
}
export function arrayEqual(left: readonly string[], right: readonly string[]): boolean {
return left.length === right.length && left.every((value, index) => value === right[index]);
}
function arrayStartsWith(left: readonly string[], right: readonly string[]): boolean {
return right.every((value, index) => left[index] === value);
}
export function validPng(): Buffer {
const png = new PNG({ width: 64, height: 64 });
png.data.fill(255);
return PNG.sync.write(png);
}
function pngSignature(): Buffer {
return Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
}
export function assertPngFile(filePath: string): void {
assert.deepEqual(fs.readFileSync(filePath).subarray(0, 8), pngSignature());
}
export function assertPngDimensions(filePath: string, width: number, height: number): void {
const png = PNG.sync.read(fs.readFileSync(filePath));
assert.equal(png.width, width);
assert.equal(png.height, height);
}