7b5af2dd9f
- converted relative imports to path aliases ($c/*, $ai/*, $tui/*, etc.) across all packages - added per-package tsconfig.json with complete path mappings for runtime resolution - set importModuleSpecifier to non-relative for IDE auto-import preferences - updated dev script to run from monorepo root for consistent path resolution
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import { describe, expect, it, vi } from "bun:test";
|
|
import * as pythonKernelModule from "$c/core/python-kernel";
|
|
import type { ToolSession } from "$c/core/tools/index";
|
|
import { createTools } from "$c/core/tools/index";
|
|
|
|
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();
|
|
});
|
|
});
|