Previously only 4 commands (/plan, /goal, /mcp, /ssh) stored their text in history via per-handler addToHistory calls. All other built-in slash commands were silently skipped because executeBuiltinSlashCommand returned true before the input controller's addToHistory was reached. - Centralize history recording in the input controller after successful slash command dispatch, for both Enter and Ctrl+Enter submit paths. - Remove all 10 per-command addToHistory calls from slash command handlers to prevent duplicates. - Add shouldSkipHistory() security filter to exclude commands that may carry secrets: /login <url> (OAuth callback with code=/state= params) and /mcp add --token <token> (bearer token). - Add regression tests for the security filter (8 cases). - Update 7 existing test files to remove handler-level addToHistory assertions (now the input controller's responsibility).
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "bun:test";
|
|
import type { InteractiveModeContext } from "@oh-my-pi/pi-coding-agent/modes/types";
|
|
import { executeBuiltinSlashCommand } from "@oh-my-pi/pi-coding-agent/slash-commands/builtin-registry";
|
|
|
|
function createRuntime() {
|
|
const handleRenameCommand = vi.fn(async () => {});
|
|
const showError = vi.fn();
|
|
const setText = vi.fn();
|
|
const addToHistory = vi.fn();
|
|
return {
|
|
handleRenameCommand,
|
|
showError,
|
|
setText,
|
|
addToHistory,
|
|
runtime: {
|
|
ctx: {
|
|
editor: { setText, addToHistory } as unknown as InteractiveModeContext["editor"],
|
|
showError,
|
|
handleRenameCommand,
|
|
} as unknown as InteractiveModeContext,
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("/rename slash command", () => {
|
|
it("routes the title through the rename handler and saves the full command to history", async () => {
|
|
const harness = createRuntime();
|
|
|
|
const handled = await executeBuiltinSlashCommand("/rename my session", harness.runtime);
|
|
|
|
expect(handled).toBe(true);
|
|
expect(harness.setText).toHaveBeenCalledWith("");
|
|
expect(harness.handleRenameCommand).toHaveBeenCalledWith("my session");
|
|
});
|
|
|
|
it("handles a blank /rename invocation without error", async () => {
|
|
const harness = createRuntime();
|
|
|
|
const handled = await executeBuiltinSlashCommand("/rename ", harness.runtime);
|
|
|
|
expect(handled).toBe(true);
|
|
expect(harness.showError).toHaveBeenCalledWith("Usage: /rename <title>");
|
|
expect(harness.setText).toHaveBeenCalledWith("");
|
|
expect(harness.handleRenameCommand).not.toHaveBeenCalled();
|
|
});
|
|
});
|