- add local shell runner + denial notice + tests - docs: describe ! local shell usage - lint: drop unused Slack upload contentType - cleanup: remove stray Swabble pins Thanks @vignesh07. Co-authored-by: Vignesh Natarajan <vigneshnatarajan92@gmail.com>
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { createLocalShellRunner } from "./tui-local-shell.js";
|
|
|
|
const createSelector = () => {
|
|
const selector = {
|
|
onSelect: undefined as ((item: { value: string; label: string }) => void) | undefined,
|
|
onCancel: undefined as (() => void) | undefined,
|
|
render: () => ["selector"],
|
|
invalidate: () => {},
|
|
};
|
|
return selector;
|
|
};
|
|
|
|
describe("createLocalShellRunner", () => {
|
|
it("logs denial on subsequent ! attempts without re-prompting", async () => {
|
|
const messages: string[] = [];
|
|
const chatLog = {
|
|
addSystem: (line: string) => {
|
|
messages.push(line);
|
|
},
|
|
};
|
|
const tui = { requestRender: vi.fn() };
|
|
const openOverlay = vi.fn();
|
|
const closeOverlay = vi.fn();
|
|
let lastSelector: ReturnType<typeof createSelector> | null = null;
|
|
const createSelectorSpy = vi.fn(() => {
|
|
lastSelector = createSelector();
|
|
return lastSelector;
|
|
});
|
|
const spawnCommand = vi.fn();
|
|
|
|
const { runLocalShellLine } = createLocalShellRunner({
|
|
chatLog,
|
|
tui,
|
|
openOverlay,
|
|
closeOverlay,
|
|
createSelector: createSelectorSpy,
|
|
spawnCommand,
|
|
});
|
|
|
|
const firstRun = runLocalShellLine("!ls");
|
|
expect(openOverlay).toHaveBeenCalledTimes(1);
|
|
lastSelector?.onSelect?.({ value: "no", label: "No" });
|
|
await firstRun;
|
|
|
|
await runLocalShellLine("!pwd");
|
|
|
|
expect(messages).toContain("local shell: not enabled");
|
|
expect(messages).toContain("local shell: not enabled for this session");
|
|
expect(createSelectorSpy).toHaveBeenCalledTimes(1);
|
|
expect(spawnCommand).not.toHaveBeenCalled();
|
|
});
|
|
});
|