test: expand memory cli coverage
This commit is contained in:
@@ -20,6 +20,7 @@ vi.mock("../agents/agent-scope.js", () => ({
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
getMemorySearchManager.mockReset();
|
getMemorySearchManager.mockReset();
|
||||||
|
process.exitCode = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("memory cli", () => {
|
describe("memory cli", () => {
|
||||||
@@ -96,4 +97,53 @@ describe("memory cli", () => {
|
|||||||
expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector error: load failed"));
|
expect(log).toHaveBeenCalledWith(expect.stringContaining("Vector error: load failed"));
|
||||||
expect(close).toHaveBeenCalled();
|
expect(close).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("closes manager after index", async () => {
|
||||||
|
const { registerMemoryCli } = await import("./memory-cli.js");
|
||||||
|
const { defaultRuntime } = await import("../runtime.js");
|
||||||
|
const close = vi.fn(async () => {});
|
||||||
|
const sync = vi.fn(async () => {});
|
||||||
|
getMemorySearchManager.mockResolvedValueOnce({
|
||||||
|
manager: {
|
||||||
|
sync,
|
||||||
|
close,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
||||||
|
const program = new Command();
|
||||||
|
program.name("test");
|
||||||
|
registerMemoryCli(program);
|
||||||
|
await program.parseAsync(["memory", "index"], { from: "user" });
|
||||||
|
|
||||||
|
expect(sync).toHaveBeenCalledWith({ reason: "cli", force: false });
|
||||||
|
expect(close).toHaveBeenCalled();
|
||||||
|
expect(log).toHaveBeenCalledWith("Memory index updated.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("closes manager after search error", async () => {
|
||||||
|
const { registerMemoryCli } = await import("./memory-cli.js");
|
||||||
|
const { defaultRuntime } = await import("../runtime.js");
|
||||||
|
const close = vi.fn(async () => {});
|
||||||
|
const search = vi.fn(async () => {
|
||||||
|
throw new Error("boom");
|
||||||
|
});
|
||||||
|
getMemorySearchManager.mockResolvedValueOnce({
|
||||||
|
manager: {
|
||||||
|
search,
|
||||||
|
close,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const error = vi.spyOn(defaultRuntime, "error").mockImplementation(() => {});
|
||||||
|
const program = new Command();
|
||||||
|
program.name("test");
|
||||||
|
registerMemoryCli(program);
|
||||||
|
await program.parseAsync(["memory", "search", "oops"], { from: "user" });
|
||||||
|
|
||||||
|
expect(search).toHaveBeenCalled();
|
||||||
|
expect(close).toHaveBeenCalled();
|
||||||
|
expect(error).toHaveBeenCalledWith(expect.stringContaining("Memory search failed: boom"));
|
||||||
|
expect(process.exitCode).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ describe("memory index", () => {
|
|||||||
const results = await result.manager.search("alpha");
|
const results = await result.manager.search("alpha");
|
||||||
expect(results.length).toBeGreaterThan(0);
|
expect(results.length).toBeGreaterThan(0);
|
||||||
expect(results[0]?.path).toContain("memory/2026-01-12.md");
|
expect(results[0]?.path).toContain("memory/2026-01-12.md");
|
||||||
|
const status = result.manager.status();
|
||||||
|
expect(status.sourceCounts).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
source: "memory",
|
||||||
|
files: status.files,
|
||||||
|
chunks: status.chunks,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects reading non-memory paths", async () => {
|
it("rejects reading non-memory paths", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user