Files
oh-my-pi/packages/coding-agent/test/core/python-executor-per-call.test.ts
T
can1357 b2c94bef1a refactor(deps): restructured codebase to use centralized pi-utils package
- Created new @oh-my-pi/pi-utils workspace package with shared utilities for logging, process management, stream handling, and temporary directory management.
- Migrated all packages to use centralized logger from @oh-my-pi/pi-utils instead of local winston implementations.
- Replaced custom process spawning and stream reading implementations with standardized cspawn and readLines utilities across all modules.
- Converted synchronous file operations and process spawning to async patterns using Bun shell syntax and fs/promises.
- Added streaming edit abort functionality with configurable setting to abort on patch preview failures.
- Updated test framework from vitest to bun:test across all test suites.
2026-01-20 05:33:21 +01:00

52 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { createTempDirSync } from "@oh-my-pi/pi-utils";
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";
using tempDir = createTempDirSync("@omp-python-executor-per-call-");
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: tempDir.path,
});
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;
}
});
});