Files
reverse-engineering-anything/src/process/capturedProviderOutput.test.ts
T
morluto 0d35ea065d refactor(process): build provider captured output through one owner (#11330)
* refactor(process): build provider captured output through one owner

* fix(process): report only declared diagnostics on successful provider results
2026-11-16 03:46:35 +08:00

46 lines
1.3 KiB
TypeScript

import { expect, it } from "vitest";
import {
capturedProviderOutput,
providerResultDiagnostics,
} from "./capturedProviderOutput.js";
import type { ProviderProcessSnapshot } from "./ProviderProcess.js";
const snapshot = (
overrides: Partial<ProviderProcessSnapshot> = {},
): ProviderProcessSnapshot => ({
stdout: { text: "head", bytes: 4, observedBytes: 4096 },
stderr: { text: "", bytes: 0, observedBytes: 0 },
exitCode: undefined,
signal: undefined,
...overrides,
});
it("keeps the retained text beside the bytes the process wrote", () => {
expect(
capturedProviderOutput(snapshot({ diagnosticTruncated: true })),
).toEqual({
stdout: "head",
stderr: "",
stdout_bytes: 4096,
stderr_bytes: 0,
exit_code: null,
signal: null,
truncated: true,
});
});
it("narrows to the three fields a successful result declares", () => {
expect(
providerResultDiagnostics(
capturedProviderOutput(snapshot({ exitCode: 0, signal: null })),
),
).toStrictEqual({ stdout: "head", stderr: "", truncated: false });
});
it("reports exit facts and an untruncated capture as observed", () => {
expect(
capturedProviderOutput(snapshot({ exitCode: 2, signal: null })),
).toMatchObject({ exit_code: 2, signal: null, truncated: false });
});