Files
oh-my-pi/packages/coding-agent/test/tools/python-execution.test.ts
T
can1357 cb5bbbf382 refactor(coding-agent): flattened directory structure, eliminated core/ folder
- Eliminated core/ directory (252 files, 23 subdirs → distributed)
- Reduced max nesting from 9 levels to 5 levels
- Promoted tool subdirs to top level: exa/, lsp/, patch/, task/, web/
- Merged web-scrapers/ + web-search/ into web/{scrapers,search}/
- Flattened modes/interactive/ to modes/
- Split execution/ into: ipy/ (python), exec/ (bash), ssh/
- Renamed ipy/python-*.ts to ipy/*.ts (executor, kernel, etc.)
- Flattened cursor/exec-bridge.ts to cursor.ts
- Created logical groupings: config/, session/, extensibility/, export/
- Updated all imports across 500+ files
2026-01-23 12:24:47 +01:00

70 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 "$c/ipy/executor";
import type { ToolSession } from "$c/tools/index";
import { PythonTool } from "$c/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,
totalLines: 1,
totalBytes: 2,
outputLines: 1,
outputBytes: 2,
displayOutputs: [],
stdinRequested: false,
});
const tool = new PythonTool(createSession(tempDir.path));
const result = await tool.execute(
"call-id",
{ cells: [{ code: "print('hi')" }], timeout: 5, cwd: tempDir.path, reset: true },
undefined,
undefined,
undefined,
);
expect(executeSpy).toHaveBeenCalledWith(
"print('hi')",
expect.objectContaining({
cwd: tempDir.path,
timeoutMs: 5000,
sessionId: `session:session-file:cwd:${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();
});
});