Files
callstack__agent-device/test/integration/cli-json.ts
Michał Pierzchała a830ac8df2 feat: add Linux command evidence lane (#2017)
* feat: add Linux command evidence lane

* fix: assert Linux find result shape

* fix: read Linux find result envelope

* fix: reset Linux calculator before diff

* fix: release Linux session before reset

* fix: guard Linux evidence session reset

* fix: forward Linux evidence timeout

* fix: tighten Linux evidence assertions

* fix: preserve Linux replay session identity

* fix: close Linux replay session before reset

* fix: share Linux evidence daemon state

* fix: keep Linux swipe evidence in bounds

* fix: keep Linux artifact gap honest
2026-08-25 07:56:13 +02:00

73 lines
1.8 KiB
TypeScript

import { runCmd, runCmdSync, type ExecResult } from '../../src/utils/exec.ts';
const CLI_TIMEOUT_MS = 120_000;
export type CliJsonResult = {
status: number;
json?: any;
stdout: string;
stderr: string;
};
export type CliJsonOptions = {
env?: NodeJS.ProcessEnv;
timeoutMs?: number;
};
export function runSourceCliJsonSync(args: string[], options?: CliJsonOptions): CliJsonResult {
const result = runCmdSync(
process.execPath,
['--experimental-strip-types', 'src/bin.ts', ...args],
{
allowFailure: true,
env: options?.env,
timeoutMs: options?.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 ?? '',
};
}