refactor(fs): migrated remaining sync file operations to async
- 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.
This commit is contained in:
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
||||
import { disposeAllKernelSessions, 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 { createTempDirSync } from "@oh-my-pi/pi-utils";
|
||||
import { TempDir } from "@oh-my-pi/pi-utils";
|
||||
|
||||
class FakeKernel {
|
||||
executeCalls = 0;
|
||||
@@ -57,18 +57,18 @@ describe("executePython kernel reuse", () => {
|
||||
});
|
||||
|
||||
it("reuses kernels for session mode", async () => {
|
||||
using tempDir = createTempDirSync("@python-kernel-session-");
|
||||
await executePython("print('one')", { cwd: tempDir.path, sessionId: "session-a", kernelMode: "session" });
|
||||
await executePython("print('two')", { cwd: tempDir.path, sessionId: "session-a", kernelMode: "session" });
|
||||
using tempDir = TempDir.createSync("@python-kernel-session-");
|
||||
await executePython("print('one')", { cwd: tempDir.path(), sessionId: "session-a", kernelMode: "session" });
|
||||
await executePython("print('two')", { cwd: tempDir.path(), sessionId: "session-a", kernelMode: "session" });
|
||||
|
||||
expect(startCalls).toBe(1);
|
||||
expect(kernels[0]?.executeCalls).toBe(2);
|
||||
});
|
||||
|
||||
it("creates and disposes per-call kernels", async () => {
|
||||
using tempDir = createTempDirSync("@python-kernel-session-");
|
||||
await executePython("print('one')", { cwd: tempDir.path, kernelMode: "per-call" });
|
||||
await executePython("print('two')", { cwd: tempDir.path, kernelMode: "per-call" });
|
||||
using tempDir = TempDir.createSync("@python-kernel-session-");
|
||||
await executePython("print('one')", { cwd: tempDir.path(), kernelMode: "per-call" });
|
||||
await executePython("print('two')", { cwd: tempDir.path(), kernelMode: "per-call" });
|
||||
|
||||
expect(startCalls).toBe(2);
|
||||
expect(kernels[0]?.shutdownCalls).toBe(1);
|
||||
@@ -76,10 +76,10 @@ describe("executePython kernel reuse", () => {
|
||||
});
|
||||
|
||||
it("resets the session kernel when requested", async () => {
|
||||
using tempDir = createTempDirSync("@python-kernel-session-");
|
||||
await executePython("print('one')", { cwd: tempDir.path, sessionId: "session-b", kernelMode: "session" });
|
||||
using tempDir = TempDir.createSync("@python-kernel-session-");
|
||||
await executePython("print('one')", { cwd: tempDir.path(), sessionId: "session-b", kernelMode: "session" });
|
||||
await executePython("print('two')", {
|
||||
cwd: tempDir.path,
|
||||
cwd: tempDir.path(),
|
||||
sessionId: "session-b",
|
||||
kernelMode: "session",
|
||||
reset: true,
|
||||
|
||||
Reference in New Issue
Block a user