Files
callstack__agent-device/test/integration/cli-json.ts
Claude 49a59d1073 refactor(contracts): put host-command vocabulary under ./host, not ./platform
Review point: exec is not platform vocabulary. "Platform" in this codebase
means device family — apple/android/web — and a finished host command is
about the HOST machine. Consumers confirm it: 20 platforms, 8 daemon, 3
utils, 3 tests. Platforms are the loudest consumer, not the owner, and
placing the type by who-uses-it rather than what-it-is put it in the wrong
domain.

`ExecResult` moves to a new `@agent-device/contracts/host` subpath, and the
R11 export ratchet records it (33 subpaths).

Not the `@agent-device/host` package #1490 rejected: that rejection was
about a package absorbing exec/version/project-root POLICY. This is the
vocabulary half of the same split — the policy stays in src/utils/exec.ts,
which is exactly why the rejection stands.
2026-08-07 15:56:17 +00:00

72 lines
1.7 KiB
TypeScript

import type { ExecResult } from '@agent-device/contracts/host';
import { runCmd, runCmdSync } from '../../src/utils/exec.ts';
const CLI_TIMEOUT_MS = 120_000;
export type CliJsonResult = {
status: number;
json?: any;
stdout: string;
stderr: string;
};
export function runSourceCliJsonSync(
args: string[],
options?: { env?: NodeJS.ProcessEnv },
): CliJsonResult {
const result = runCmdSync(
process.execPath,
['--experimental-strip-types', 'src/bin.ts', ...args],
{
allowFailure: true,
env: options?.env,
timeoutMs: CLI_TIMEOUT_MS,
},
);
return cliJsonResult(result);
}
export async function runBuiltCliJson(
args: string[],
env: NodeJS.ProcessEnv,
options?: { timeoutMs?: number },
): Promise<CliJsonResult> {
const result = await runCmd(process.execPath, ['bin/agent-device.mjs', ...args], {
allowFailure: true,
env,
timeoutMs: options?.timeoutMs ?? CLI_TIMEOUT_MS,
});
return cliJsonResult(result);
}
export function formatResultDebug(step: string, args: string[], result: CliJsonResult): string {
const jsonText =
result.json === undefined ? '(unparseable)' : JSON.stringify(result.json, null, 2);
return [
`step: ${step}`,
`command: agent-device ${args.join(' ')}`,
`status: ${result.status}`,
`stderr:`,
result.stderr || '(empty)',
`stdout:`,
result.stdout || '(empty)',
`json:`,
jsonText,
].join('\n');
}
function cliJsonResult(result: ExecResult): CliJsonResult {
let json: any;
try {
json = JSON.parse(result.stdout ?? '');
} catch {
json = undefined;
}
return {
status: result.exitCode,
json,
stdout: json ? '<JSON output>' : (result.stdout ?? ''),
stderr: result.stderr ?? '',
};
}