Files
oh-my-pi/packages/coding-agent/test/core/python-executor-per-call.test.ts
T
can1357 92ec2550d2 refactor(coding-agent): reorganized test files to proper test directory structure
- Moved test files from src/core to test/core directory.
- Moved test files from src/core/tools to test/tools directory.
- Moved test files from src/discovery to test/discovery directory.
- Updated import paths to reflect new test file locations.
2026-01-19 00:07:23 +01:00

50 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { executePython } from "../../src/core/python-executor";
import type { KernelExecuteOptions, KernelExecuteResult } from "../../src/core/python-kernel";
import { PythonKernel } from "../../src/core/python-kernel";
interface KernelStub {
execute: (code: string, options?: KernelExecuteOptions) => Promise<KernelExecuteResult>;
shutdown: () => Promise<void>;
}
describe("executePython (per-call)", () => {
it("shuts down kernel on timed-out cancellation", async () => {
process.env.OMP_PYTHON_SKIP_CHECK = "1";
let shutdownCalls = 0;
const kernel: KernelStub = {
execute: async () => ({
status: "ok",
cancelled: true,
timedOut: true,
stdinRequested: false,
}),
shutdown: async () => {
shutdownCalls += 1;
},
};
const kernelClass = PythonKernel as unknown as {
start: (options: { cwd: string }) => Promise<KernelStub>;
};
const originalStart = kernelClass.start;
kernelClass.start = async () => kernel;
try {
const result = await executePython("sleep(10)", {
kernelMode: "per-call",
timeout: 2000,
cwd: "/tmp",
});
expect(result.cancelled).toBe(true);
expect(result.exitCode).toBeUndefined();
expect(result.output).toContain("Command timed out after 2 seconds");
expect(shutdownCalls).toBe(1);
} finally {
kernelClass.start = originalStart;
}
});
});