Files
oh-my-pi/packages/coding-agent/test/slash-commands/move.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

49 lines
1.6 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 handleMoveCommand = vi.fn(async () => {});
const showError = vi.fn();
const setText = vi.fn();
const addToHistory = vi.fn();
return {
handleMoveCommand,
showError,
setText,
addToHistory,
runtime: {
ctx: {
editor: { setText, addToHistory } as unknown as InteractiveModeContext["editor"],
showError,
handleMoveCommand,
} as unknown as InteractiveModeContext,
},
};
}
describe("/move slash command", () => {
it("routes the path through the move handler and saves the full command to history", async () => {
const harness = createRuntime();
const handled = await executeBuiltinSlashCommand("/move /tmp/project", harness.runtime);
expect(handled).toBe(true);
expect(harness.addToHistory).toHaveBeenCalledWith("/move /tmp/project");
expect(harness.setText).toHaveBeenCalledWith("");
expect(harness.handleMoveCommand).toHaveBeenCalledWith("/tmp/project");
});
it("does not add a blank /move invocation to history", async () => {
const harness = createRuntime();
const handled = await executeBuiltinSlashCommand("/move ", harness.runtime);
expect(handled).toBe(true);
expect(harness.addToHistory).not.toHaveBeenCalled();
expect(harness.showError).toHaveBeenCalledWith("Usage: /move <path>");
expect(harness.setText).toHaveBeenCalledWith("");
expect(harness.handleMoveCommand).not.toHaveBeenCalled();
});
});