Files
oh-my-pi/packages/coding-agent/test/tools/python-fallback.test.ts
T
can1357 ef415e863b feat(coding-agent): refactored settings system with new singleton API and unified schema
- Replaced SettingsManager class with new Settings singleton providing synchronous get/set API and background persistence.
- Introduced settings-schema.ts as single source of truth for all configuration definitions with 100+ settings organized into logical groups.
- Migrated from method-based settings access (getTheme(), setTheme()) to path-based access using dot notation (settings.get('theme'), settings.set('theme', value)).
- Removed 2035-line settings-manager.ts file and replaced with modular settings.ts (693 lines) and settings-schema.ts (836 lines) for improved maintainability.
- Unified settings schema into single source of truth eliminating duplicate definitions across settings-defs.ts and settings-manager.ts.
2026-02-01 08:08:58 +01:00

67 lines
2.0 KiB
TypeScript

import { describe, expect, it, vi } from "bun:test";
import { type SettingPath, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import * as pythonKernelModule from "@oh-my-pi/pi-coding-agent/ipy/kernel";
import { createTools, type ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
function createTestSession(overrides: Partial<ToolSession> = {}): ToolSession {
return {
cwd: "/tmp/test",
hasUI: false,
getSessionFile: () => null,
getSessionSpawns: () => "*",
settings: Settings.isolated(),
...overrides,
};
}
function createSettingsWithOverrides(overrides: Partial<Record<SettingPath, unknown>> = {}): Settings {
return Settings.isolated({
"lsp.formatOnWrite": true,
"bashInterceptor.enabled": true,
...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: createSettingsWithOverrides({
"python.toolMode": "ipy-only",
"python.kernelMode": "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: createSettingsWithOverrides({
"python.toolMode": "both",
"python.kernelMode": "session",
}),
});
const tools = await createTools(session);
const names = tools.map(tool => tool.name);
expect(names).toContain("bash");
expect(names).not.toContain("python");
availabilitySpy.mockRestore();
});
});