e22d123009
- Converted readdirSync, readFileSync, and statSync to async readdir, readFile, stat across skills and agent discovery. - Made scanDirectoryForSkills async and refactored custom directory scanning to use Promise.all for concurrent processing. - Updated agent discovery to use fs/promises for async file reading and refactored helper patterns. - Added AgentParsingError exception class for better error handling during agent parsing. - Added filesystem error type guards (isEnoent, isEacces, isPerm, etc.) to pi-utils for safe error checking. - Added color manipulation utilities to pi-utils for accessibility features. - Added color-blind mode setting to settings manager. - Migrated plugins, settings, and config modules from sync to async file operations. - Updated error handling to use new pi-utils type guards for type-safe checking.
52 lines
1.5 KiB
TypeScript
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.OMP_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;
|
|
}
|
|
});
|
|
});
|