Files
oh-my-pi/packages/coding-agent/test/tools/python-execution.test.ts
T
can1357 fa881fd508 refactor: removed voice control and git features from coding-agent
- Removed voice control and TTS features from coding-agent package.
- Removed git tool integration and worktree management from coding-agent.
- Deleted entire git-tool package and all git operations.
- Inlined OpenAI Codex prompt utilities and removed provider exports.
2026-01-21 08:09:15 +01:00

66 lines
1.9 KiB
TypeScript

import { describe, expect, it, vi } from "bun:test";
import { createTempDirSync } from "@oh-my-pi/pi-utils";
import * as pythonExecutor from "../../src/core/python-executor";
import type { ToolSession } from "../../src/core/tools/index";
import { PythonTool } from "../../src/core/tools/python";
function createSession(cwd: string): ToolSession {
return {
cwd,
hasUI: false,
getSessionFile: () => "session-file",
getSessionSpawns: () => "*",
settings: {
getImageAutoResize: () => true,
getLspFormatOnWrite: () => true,
getLspDiagnosticsOnWrite: () => true,
getLspDiagnosticsOnEdit: () => false,
getEditFuzzyMatch: () => true,
getBashInterceptorEnabled: () => true,
getBashInterceptorSimpleLsEnabled: () => true,
getBashInterceptorRules: () => [],
getPythonToolMode: () => "ipy-only",
getPythonKernelMode: () => "per-call",
},
};
}
describe("python tool execution", () => {
it("passes kernel options from settings and args", async () => {
const tempDir = createTempDirSync("@python-tool-");
const executeSpy = vi.spyOn(pythonExecutor, "executePython").mockResolvedValue({
output: "ok",
exitCode: 0,
cancelled: false,
truncated: false,
displayOutputs: [],
stdinRequested: false,
});
const tool = new PythonTool(createSession(tempDir.path));
const result = await tool.execute(
"call-id",
{ code: "print('hi')", timeoutMs: 5000, workdir: tempDir.path, reset: true },
undefined,
undefined,
undefined,
);
expect(executeSpy).toHaveBeenCalledWith(
"print('hi')",
expect.objectContaining({
cwd: tempDir.path,
timeoutMs: 5000,
sessionId: `session:session-file:workdir:${tempDir.path}`,
kernelMode: "per-call",
reset: true,
}),
);
const text = result.content.find((item) => item.type === "text")?.text;
expect(text).toBe("ok");
executeSpy.mockRestore();
tempDir.remove();
});
});