Files
oh-my-pi/packages/coding-agent/test/tools/python-fallback.test.ts
T
can1357 79079e6ecd feat(coding-agent): added plan mode with approval workflow and tool gating
- Plan mode provides structured workflow where agents propose plans for user approval before execution.
- Added plan:// internal URL protocol for accessing plan files and injecting plan-mode context into subagent prompts.
- Added plan mode toggle shortcut and paused status indicator in status line.
- Fixed plan reference injection to properly pass workflow state to plan-mode system prompts.
- Improved autocomplete fuzzy matching to support subsequence matching for skill suggestions.
2026-01-25 19:35:26 +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", "exit_plan_mode"]);
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();
});
});