mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 17:14:33 +00:00
Memory: share ENOENT helpers
This commit is contained in:
committed by
Vignesh
parent
14a3af212d
commit
5542a43623
@@ -1079,6 +1079,42 @@ describe("QmdMemoryManager", () => {
|
||||
readFileSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("returns empty text when a qmd workspace file does not exist", async () => {
|
||||
const { manager } = await createManager();
|
||||
const result = await manager.readFile({ relPath: "ghost.md" });
|
||||
expect(result).toEqual({ text: "", path: "ghost.md" });
|
||||
await manager.close();
|
||||
});
|
||||
|
||||
it("returns empty text when a qmd file disappears before partial read", async () => {
|
||||
const relPath = "qmd-window.md";
|
||||
const absPath = path.join(workspaceDir, relPath);
|
||||
await fs.writeFile(absPath, "one\ntwo\nthree", "utf-8");
|
||||
|
||||
const { manager } = await createManager();
|
||||
|
||||
const realOpen = fs.open;
|
||||
let injected = false;
|
||||
const openSpy = vi
|
||||
.spyOn(fs, "open")
|
||||
.mockImplementation(async (...args: Parameters<typeof realOpen>) => {
|
||||
const [target, options] = args;
|
||||
if (!injected && typeof target === "string" && path.resolve(target) === absPath) {
|
||||
injected = true;
|
||||
const err = new Error("gone") as NodeJS.ErrnoException;
|
||||
err.code = "ENOENT";
|
||||
throw err;
|
||||
}
|
||||
return realOpen(target, options);
|
||||
});
|
||||
|
||||
const result = await manager.readFile({ relPath, from: 2, lines: 1 });
|
||||
expect(result).toEqual({ text: "", path: relPath });
|
||||
|
||||
openSpy.mockRestore();
|
||||
await manager.close();
|
||||
});
|
||||
|
||||
it("reuses exported session markdown files when inputs are unchanged", async () => {
|
||||
const writeFileSpy = vi.spyOn(fs, "writeFile");
|
||||
const sessionsDir = path.join(stateDir, "agents", agentId, "sessions");
|
||||
|
||||
Reference in New Issue
Block a user