Files
oh-my-pi/packages/coding-agent/test/tool-execution-args.test.ts
T
2026-06-06 16:00:31 +02:00

35 lines
1.1 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import { initTheme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
import type { TUI } from "@oh-my-pi/pi-tui";
import { ToolExecutionComponent } from "../src/modes/components/tool-execution";
describe("ToolExecutionComponent.updateArgs (F8 — no clone, ref-eq fast path)", () => {
let initialized = false;
afterEach(() => {
vi.restoreAllMocks();
});
async function makeComponent(args: unknown) {
if (!initialized) {
await initTheme();
initialized = true;
}
const uiStub = { requestRender() {} } as unknown as TUI;
return new ToolExecutionComponent("bash", args, {}, undefined, uiStub);
}
it("does NOT call structuredClone in updateArgs (caller already owns isolation)", async () => {
const cloneSpy = vi.spyOn(globalThis, "structuredClone");
const component = await makeComponent({ command: "ls" });
cloneSpy.mockClear();
// Simulate event-controller.ts: each delta builds a fresh spread.
for (let i = 0; i < 5; i++) {
component.updateArgs({ command: `ls -l ${i}` });
}
expect(cloneSpy).not.toHaveBeenCalled();
});
});