cb5bbbf382
- Eliminated core/ directory (252 files, 23 subdirs → distributed)
- Reduced max nesting from 9 levels to 5 levels
- Promoted tool subdirs to top level: exa/, lsp/, patch/, task/, web/
- Merged web-scrapers/ + web-search/ into web/{scrapers,search}/
- Flattened modes/interactive/ to modes/
- Split execution/ into: ipy/ (python), exec/ (bash), ssh/
- Renamed ipy/python-*.ts to ipy/*.ts (executor, kernel, etc.)
- Flattened cursor/exec-bridge.ts to cursor.ts
- Created logical groupings: config/, session/, extensibility/, export/
- Updated all imports across 500+ files
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/ipy/kernel";
|
|
import type { ToolSession } from "$c/tools/index";
|
|
import { createTools } from "$c/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();
|
|
});
|
|
});
|