test: align cli runtime mocks with output runtime

This commit is contained in:
Peter Steinberger
2026-03-22 17:29:28 -07:00
parent 7bd12f4b37
commit 976eefe373
15 changed files with 37 additions and 47 deletions

View File

@@ -12,6 +12,8 @@ const defaultRuntime = {
writeStdout: vi.fn(),
writeJson: vi.fn(),
exit: vi.fn(),
writeStdout: vi.fn(),
writeJson: vi.fn(),
};
const passwordKey = () => ["pass", "word"].join("");

View File

@@ -39,12 +39,13 @@ vi.mock("../runtime.js", async (importOriginal) => {
return {
...actual,
defaultRuntime: {
...actual.defaultRuntime,
log: (...args: unknown[]) => mockLog(...args),
error: (...args: unknown[]) => mockError(...args),
exit: (code: number) => mockExit(code),
writeStdout: (value: string) => mockLog(value.endsWith("\n") ? value.slice(0, -1) : value),
writeJson: (value: unknown, space = 2) =>
mockLog(JSON.stringify(value, null, space > 0 ? space : undefined)),
exit: (code: number) => mockExit(code),
},
};
});

View File

@@ -34,6 +34,8 @@ vi.mock("../runtime.js", () => ({
exit: (code: number) => {
throw new Error(`__exit__:${code}`);
},
writeStdout: vi.fn(),
writeJson: vi.fn(),
},
}));

View File

@@ -37,6 +37,9 @@ vi.mock("../../runtime.js", () => ({
exit: (code: number) => {
throw new Error(`__exit__:${code}`);
},
writeStdout: (value: string) => runtimeLogs.push(value),
writeJson: (value: unknown, space = 2) =>
runtimeLogs.push(JSON.stringify(value, null, space > 0 ? space : undefined)),
},
}));

View File

@@ -27,15 +27,15 @@ export const defaultRuntime: LifecycleRuntimeHarness = {
runtimeLogs.push(args.map((arg) => String(arg)).join(" "));
},
error: vi.fn(),
exit: vi.fn((code: number) => {
throw new Error(`__exit__:${code}`);
}),
writeStdout: vi.fn((value: string) => {
runtimeLogs.push(value.endsWith("\n") ? value.slice(0, -1) : value);
}),
writeJson: vi.fn((value: unknown, space = 2) => {
runtimeLogs.push(JSON.stringify(value, null, space > 0 ? space : undefined));
}),
exit: vi.fn((code: number) => {
throw new Error(`__exit__:${code}`);
}),
};
export const service: LifecycleServiceHarness = {

View File

@@ -21,6 +21,8 @@ const runtime = {
runtime.log(JSON.stringify(value, null, space > 0 ? space : undefined));
}),
exit: vi.fn(),
writeStdout: vi.fn((value: string) => runtime.log(value)),
writeJson: vi.fn((value: unknown, space = 2) => runtime.log(JSON.stringify(value, null, space))),
};
vi.mock("../gateway/call.js", () => ({

View File

@@ -43,6 +43,8 @@ vi.mock("../runtime.js", () => ({
writeJson: (value: unknown, space = 2) =>
mocks.log(JSON.stringify(value, null, space > 0 ? space : undefined)),
exit: (...args: unknown[]) => mocks.exit(...args),
writeStdout: (...args: unknown[]) => mocks.log(...args),
writeJson: (value: unknown, space = 2) => mocks.log(JSON.stringify(value, null, space)),
},
}));

View File

@@ -19,6 +19,8 @@ vi.mock("../runtime.js", () => ({
writeJson: (value: unknown, space = 2) =>
mockLog(JSON.stringify(value, null, space > 0 ? space : undefined)),
exit: (code: number) => mockExit(code),
writeStdout: (value: string) => mockLog(value),
writeJson: (value: unknown, space = 2) => mockLog(JSON.stringify(value, null, space)),
},
}));

View File

@@ -59,7 +59,11 @@ afterEach(() => {
describe("memory cli", () => {
function spyRuntimeLogs() {
return vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
const logSpy = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
vi.spyOn(defaultRuntime, "writeJson").mockImplementation((value: unknown, space = 2) => {
logSpy(JSON.stringify(value, null, space));
});
return logSpy;
}
function spyRuntimeJson() {

View File

@@ -15,6 +15,10 @@ const mocks = vi.hoisted(() => ({
exit: vi.fn(() => {
throw new Error("exit");
}),
writeStdout: vi.fn((value: string) => mocks.runtime.log(value)),
writeJson: vi.fn((value: unknown, space = 2) =>
mocks.runtime.log(JSON.stringify(value, null, space)),
),
},
loadConfig: vi.fn(),
runCommandWithTimeout: vi.fn(),

View File

@@ -26,9 +26,9 @@ vi.mock("../runtime.js", () => ({
defaultRuntime: {
error: vi.fn(),
log: vi.fn(),
exit: vi.fn(),
writeStdout: vi.fn(),
writeJson: vi.fn(),
exit: vi.fn(),
},
}));

View File

@@ -30,6 +30,12 @@ export function createCliRuntimeCapture(): CliRuntimeCapture {
exit: (code: number) => {
throw new Error(`__exit__:${code}`);
},
writeStdout: (value: string) => {
runtimeLogs.push(value);
},
writeJson: (value: unknown, space = 2) => {
runtimeLogs.push(JSON.stringify(value, null, space > 0 ? space : undefined));
},
},
resetRuntimeCapture: () => {
runtimeLogs.length = 0;

View File

@@ -16,6 +16,8 @@ const defaultRuntime = {
defaultRuntime.log(JSON.stringify(value, null, space));
}),
exit: vi.fn(),
writeStdout: vi.fn(),
writeJson: vi.fn(),
};
vi.mock("./update-cli/update-command.js", () => ({

View File

@@ -139,11 +139,11 @@ vi.mock("../runtime.js", () => ({
defaultRuntime: {
log: runtimeLog,
error: runtimeError,
exit: runtimeExit,
writeStdout: vi.fn((value: string) =>
runtimeLog(value.endsWith("\n") ? value.slice(0, -1) : value),
),
writeJson: runtimeWriteJson,
exit: runtimeExit,
},
}));

View File

@@ -35,30 +35,14 @@
"file": "src/cron/isolated-agent/run.cron-model-override.test.ts",
"reason": "Measured ~25% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent/run.skill-filter.test.ts",
"reason": "Measured ~15% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent/run.owner-auth.test.ts",
"reason": "Measured ~19% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent.lane.test.ts",
"reason": "Measured ~14% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent.direct-delivery-forum-topics.test.ts",
"reason": "Measured ~11% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent.auth-profile-propagation.test.ts",
"reason": "Measured ~22% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent.delivers-response-has-heartbeat-ok-but-includes.test.ts",
"reason": "Measured ~12% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/isolated-agent/delivery-dispatch.named-agent.test.ts",
"reason": "Measured ~14% faster under threads than forks on this host while keeping the file green."
@@ -67,30 +51,6 @@
"file": "src/cron/isolated-agent.subagent-model.test.ts",
"reason": "Measured ~21% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/service.store-load-invalid-main-job.test.ts",
"reason": "Measured ~16% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/service.store-migration.test.ts",
"reason": "Measured ~14% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/service.failure-alert.test.ts",
"reason": "Measured ~17% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/service.persists-delivered-status.test.ts",
"reason": "Measured ~15% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/session-reaper.test.ts",
"reason": "Measured ~12% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/cron/service.session-reaper-in-finally.test.ts",
"reason": "Measured ~21% faster under threads than forks on this host while keeping the file green."
},
{
"file": "src/infra/outbound/deliver.test.ts",
"reason": "Terminates cleanly under threads, but not process forks on this host."