Files
oh-my-pi/packages/coding-agent/test/tools/python-fallback.test.ts
T
can1357 779ca4872b style(deps): migrated from Prettier to Biome and updated formatting rules
- Removed Prettier configuration files (.prettierignore and .prettierrc) and migrated formatting to Biome.
- Updated Biome configuration from version 2.3.11 to 2.3.12 and changed arrowParentheses rule from 'always' to 'asNeeded'.
- Pinned @biomejs/biome dependency to exact version 2.3.12 in package.json and bun.lock.
- Applied consistent arrow function formatting across 489 files by removing unnecessary parentheses around single parameters.
- Removed blank lines after comment blocks and reorganized imports for consistency across the codebase.
2026-01-24 04:20:19 +01:00

72 lines
2.1 KiB
TypeScript

import { describe, expect, it, vi } from "bun:test";
import * as pythonKernelModule from "@oh-my-pi/pi-coding-agent/ipy/kernel";
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
import { createTools } from "@oh-my-pi/pi-coding-agent/tools";
function createTestSession(overrides: Partial<ToolSession> = {}): ToolSession {
return {
cwd: "/tmp/test",
hasUI: false,
getSessionFile: () => null,
getSessionSpawns: () => "*",
...overrides,
};
}
function createBaseSettings(overrides: Partial<NonNullable<ToolSession["settings"]>> = {}) {
return {
getImageAutoResize: () => true,
getLspFormatOnWrite: () => true,
getLspDiagnosticsOnWrite: () => true,
getLspDiagnosticsOnEdit: () => false,
getEditFuzzyMatch: () => true,
getBashInterceptorEnabled: () => true,
getBashInterceptorSimpleLsEnabled: () => true,
getBashInterceptorRules: () => [],
...overrides,
};
}
describe("createTools python fallback", () => {
it("falls back to bash-only when kernel unavailable", async () => {
const availabilitySpy = vi
.spyOn(pythonKernelModule, "checkPythonKernelAvailability")
.mockResolvedValue({ ok: false, reason: "unavailable" });
const session = createTestSession({
settings: createBaseSettings({
getPythonToolMode: () => "ipy-only",
getPythonKernelMode: () => "session",
}),
});
const tools = await createTools(session, ["python"]);
const names = tools.map(tool => tool.name).sort();
expect(names).toEqual(["bash"]);
availabilitySpy.mockRestore();
});
it("keeps bash when python mode is both but unavailable", async () => {
const availabilitySpy = vi
.spyOn(pythonKernelModule, "checkPythonKernelAvailability")
.mockResolvedValue({ ok: false, reason: "unavailable" });
const session = createTestSession({
settings: createBaseSettings({
getPythonToolMode: () => "both",
getPythonKernelMode: () => "session",
}),
});
const tools = await createTools(session);
const names = tools.map(tool => tool.name);
expect(names).toContain("bash");
expect(names).not.toContain("python");
availabilitySpy.mockRestore();
});
});