Files
oh-my-pi/packages/coding-agent/test/slash-commands/tan.test.ts
T
KamijoToma e50ca8d21a Address review feedback: guard blank /btw /tan /omfg and add history regression tests
- Only add /btw, /tan, /omfg to history when their argument is non-empty, so blank invocations rejected by the controller are not persisted.

- Add regression coverage for addToHistory behavior on /btw, /tan, /omfg, /memory, /rename, and /move.
2026-06-18 22:59:59 +08:00

58 lines
2.0 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 handleTanCommand = vi.fn(async () => {});
const setText = vi.fn();
const addToHistory = vi.fn();
return {
handleTanCommand,
setText,
addToHistory,
runtime: {
ctx: {
editor: { setText, addToHistory } as unknown as InteractiveModeContext["editor"],
handleTanCommand,
} as unknown as InteractiveModeContext,
},
};
}
describe("/tan slash command", () => {
it("routes the full work item through the tan handler", async () => {
const harness = createRuntime();
const handled = await executeBuiltinSlashCommand("/tan add a changelog note", harness.runtime);
expect(handled).toBe(true);
expect(harness.addToHistory).toHaveBeenCalledWith("/tan add a changelog note");
expect(harness.setText).toHaveBeenCalledWith("");
expect(harness.handleTanCommand).toHaveBeenCalledWith("add a changelog note");
});
it("preserves the raw multi-word suffix after /tan", async () => {
const harness = createRuntime();
const handled = await executeBuiltinSlashCommand(
"/tan investigate why prompt cache reuse matters here",
harness.runtime,
);
expect(handled).toBe(true);
expect(harness.addToHistory).toHaveBeenCalledWith("/tan investigate why prompt cache reuse matters here");
expect(harness.handleTanCommand).toHaveBeenCalledWith("investigate why prompt cache reuse matters here");
});
it("does not add a blank /tan invocation to history", async () => {
const harness = createRuntime();
const handled = await executeBuiltinSlashCommand("/tan ", harness.runtime);
expect(handled).toBe(true);
expect(harness.addToHistory).not.toHaveBeenCalled();
expect(harness.setText).toHaveBeenCalledWith("");
expect(harness.handleTanCommand).toHaveBeenCalledWith("");
});
});