7d0b8cf8dc
/memory stats and /memory diagnose fall back to a generic
'Memory <action> is not available for the <backend.id> backend.'
message whenever the active backend's stats/diagnose hook is
undefined. For every real backend (hindsight, mnemopi, local) this
reads fine, but the off backend isn't a backend a user picked among
several stats-capable options - it's the no-op state memory falls
back to by default - so the same template renders as 'Memory stats
is not available for the off backend.', which reads as an odd,
almost self-contradictory warning.
Special-case backend.id === "off" with wording that matches the
phrasing offBackend.status() already uses elsewhere ('Memory backend
is off.'), and add a unit test covering both the off-backend wording
and the unchanged generic fallback for a real backend (local) that
simply has no stats hook.
The regression test only asserts on a mocked showWarning call and
never renders Markdown, so it doesn't need a real theme instance;
drop the global dark-theme setup/teardown to avoid leaving the
process-wide theme singleton mutated for later suites in the same
Bun process.
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
|
|
import { resetSettingsForTest, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { CommandController } from "@oh-my-pi/pi-coding-agent/modes/controllers/command-controller";
|
|
import type { InteractiveModeContext } from "@oh-my-pi/pi-coding-agent/modes/types";
|
|
|
|
function createMemoryContext(backend: string) {
|
|
const showWarning = vi.fn();
|
|
const ctx = {
|
|
settings: Settings.isolated({ "memory.backend": backend }),
|
|
sessionManager: { getCwd: () => "/tmp/project" },
|
|
session: undefined,
|
|
showWarning,
|
|
} as unknown as InteractiveModeContext;
|
|
return { ctx, showWarning };
|
|
}
|
|
|
|
describe("CommandController /memory stats and /memory diagnose", () => {
|
|
beforeEach(() => {
|
|
resetSettingsForTest();
|
|
});
|
|
|
|
afterEach(() => {
|
|
resetSettingsForTest();
|
|
});
|
|
|
|
it("tells the user memory is off instead of naming a nonexistent 'off backend' for /memory stats", async () => {
|
|
const { ctx, showWarning } = createMemoryContext("off");
|
|
const controller = new CommandController(ctx);
|
|
|
|
await controller.handleMemoryCommand("/memory stats");
|
|
|
|
expect(showWarning).toHaveBeenCalledWith("Memory backend is off — there is nothing to show.");
|
|
});
|
|
|
|
it("tells the user memory is off instead of naming a nonexistent 'off backend' for /memory diagnose", async () => {
|
|
const { ctx, showWarning } = createMemoryContext("off");
|
|
const controller = new CommandController(ctx);
|
|
|
|
await controller.handleMemoryCommand("/memory diagnose");
|
|
|
|
expect(showWarning).toHaveBeenCalledWith("Memory backend is off — there is nothing to show.");
|
|
});
|
|
|
|
it("still names the backend when a real backend simply has no stats hook", async () => {
|
|
const { ctx, showWarning } = createMemoryContext("local");
|
|
const controller = new CommandController(ctx);
|
|
|
|
await controller.handleMemoryCommand("/memory stats");
|
|
|
|
expect(showWarning).toHaveBeenCalledWith("Memory stats is not available for the local backend.");
|
|
});
|
|
});
|