tui: add local shell execution for !-prefixed lines

This commit is contained in:
Vignesh Natarajan
2026-01-22 11:35:13 -08:00
committed by Peter Steinberger
parent c1e50b7184
commit 5fd699d0bf
3 changed files with 235 additions and 5 deletions

View File

@@ -0,0 +1,74 @@
import { describe, expect, it, vi } from "vitest";
import { createEditorSubmitHandler } from "./tui.js";
describe("createEditorSubmitHandler", () => {
it("routes lines starting with ! to handleBangLine", () => {
const editor = {
setText: vi.fn(),
addToHistory: vi.fn(),
};
const handleCommand = vi.fn();
const sendMessage = vi.fn();
const handleBangLine = vi.fn();
const onSubmit = createEditorSubmitHandler({
editor,
handleCommand,
sendMessage,
handleBangLine,
});
onSubmit("!ls");
expect(handleBangLine).toHaveBeenCalledTimes(1);
expect(handleBangLine).toHaveBeenCalledWith("!ls");
expect(sendMessage).not.toHaveBeenCalled();
expect(handleCommand).not.toHaveBeenCalled();
});
it("treats a lone ! as a normal message", () => {
const editor = {
setText: vi.fn(),
addToHistory: vi.fn(),
};
const handleCommand = vi.fn();
const sendMessage = vi.fn();
const handleBangLine = vi.fn();
const onSubmit = createEditorSubmitHandler({
editor,
handleCommand,
sendMessage,
handleBangLine,
});
onSubmit("!");
expect(handleBangLine).not.toHaveBeenCalled();
expect(sendMessage).toHaveBeenCalledTimes(1);
expect(sendMessage).toHaveBeenCalledWith("!");
});
it("does not trim input", () => {
const editor = {
setText: vi.fn(),
addToHistory: vi.fn(),
};
const handleCommand = vi.fn();
const sendMessage = vi.fn();
const handleBangLine = vi.fn();
const onSubmit = createEditorSubmitHandler({
editor,
handleCommand,
sendMessage,
handleBangLine,
});
onSubmit(" hello ");
expect(sendMessage).toHaveBeenCalledWith(" hello ");
expect(editor.addToHistory).toHaveBeenCalledWith(" hello ");
});
});