Files
oh-my-pi/packages/coding-agent/test/core/python-executor-per-call.test.ts
T
can1357 ec801665bc refactor(env): migrated environment variables from OMP_ to PI_ prefix and centralized access via getEnv()
- Migrated environment variable access from direct process.env to centralized getEnv() utility function across all packages.
- Renamed environment variable prefix from OMP_ to PI_ throughout codebase (e.g., OMP_CODING_AGENT_DIR -> PI_CODING_AGENT_DIR).
- Removed automatic environment variable migration from PI_ to OMP_ prefixes via migrate-env.ts module.
- Removed env setting from configuration schema and applyEnvironmentVariables() method from settings.
- Updated CI/CD build configuration to use PI_COMPILED flag instead of OMP_COMPILED.
- Changed venvPath property in PythonRuntime from nullable (string | null) to optional (string | undefined).
2026-02-05 02:55:01 +01:00

52 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { executePython } from "@oh-my-pi/pi-coding-agent/ipy/executor";
import type { KernelExecuteOptions, KernelExecuteResult } from "@oh-my-pi/pi-coding-agent/ipy/kernel";
import { PythonKernel } from "@oh-my-pi/pi-coding-agent/ipy/kernel";
import { TempDir } from "@oh-my-pi/pi-utils";
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.PI_PYTHON_SKIP_CHECK = "1";
using tempDir = TempDir.createSync("@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",
timeoutMs: 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;
}
});
});