Memory: harden readFile ENOENT handling

This commit is contained in:
Vignesh Natarajan
2026-02-19 22:21:17 -08:00
committed by Vignesh
parent f3f47886ba
commit ec4198954a
3 changed files with 121 additions and 25 deletions

View File

@@ -12,11 +12,16 @@ let searchImpl: () => Promise<unknown[]> = async () => [
source: "memory" as const,
},
];
let readFileImpl: () => Promise<unknown> = async () => "";
type MemoryReadParams = { relPath: string; from?: number; lines?: number };
type MemoryReadResult = { text: string; path: string };
let readFileImpl: (params: MemoryReadParams) => Promise<MemoryReadResult> = async (params) => ({
text: "",
path: params.relPath,
});
const stubManager = {
search: vi.fn(async () => await searchImpl()),
readFile: vi.fn(async () => await readFileImpl()),
readFile: vi.fn(async (params: MemoryReadParams) => await readFileImpl(params)),
status: () => ({
backend,
files: 1,
@@ -59,7 +64,7 @@ beforeEach(() => {
source: "memory" as const,
},
];
readFileImpl = async () => ""; // default: return empty string
readFileImpl = async (params: MemoryReadParams) => ({ text: "", path: params.relPath });
vi.clearAllMocks();
});
@@ -170,7 +175,7 @@ describe("memory tools", () => {
});
it("does not throw when memory_get fails", async () => {
readFileImpl = async () => {
readFileImpl = async (_params: MemoryReadParams) => {
throw new Error("path required");
};
@@ -191,7 +196,7 @@ describe("memory tools", () => {
});
it("returns empty text without error when file does not exist (ENOENT)", async () => {
readFileImpl = async () => {
readFileImpl = async (_params: MemoryReadParams) => {
return { text: "", path: "memory/2026-02-19.md" };
};