fix: tui local shell consent UX (#1463)
- 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>
This commit is contained in:
54
src/tui/tui-local-shell.test.ts
Normal file
54
src/tui/tui-local-shell.test.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user