From 8826ddb6b63b2a3a00069e872e292d28bda32d4f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 12 Aug 2026 02:06:35 +0000 Subject: [PATCH 1/2] Add tests for ZkrMemoryManager.readFile This adds three new tests for the `readFile` functionality: - A test that invalid zkr paths correctly throw "invalid zkr memory path". - A test that reads are correctly mapped to the underlying CLI "get" command with extracted params. - A test validating the pagination logic (extracting line subsets) and truncation values using the `from` and `lines` parameter. Co-authored-by: undivisible <136312656+undivisible@users.noreply.github.com> --- plugins/openclaw/index.test.ts | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/plugins/openclaw/index.test.ts b/plugins/openclaw/index.test.ts index ea51f79..d91db5c 100644 --- a/plugins/openclaw/index.test.ts +++ b/plugins/openclaw/index.test.ts @@ -117,6 +117,80 @@ describe("zkr OpenClaw tools", () => { manager.readFile({ relPath: "zkr://source/s-1", from: 0 }), ).rejects.toThrow("positive integers"); }); + + test("rejects invalid zkr memory paths", async () => { + const manager = new ZkrMemoryHost({}, async () => ({}) as never).manager( + "agent-1", + ); + await expect( + manager.readFile({ relPath: "invalid-path" }), + ).rejects.toThrow("invalid zkr memory path"); + await expect( + manager.readFile({ relPath: "zkr://unknown/123" }), + ).rejects.toThrow("invalid zkr memory path"); + }); + + test("maps exact reads to the zkr CLI contract", async () => { + const calls: unknown[][] = []; + const run = async (...args: unknown[]) => { + calls.push(args); + return { excerpt: "line1\nline2\nline3" }; + }; + const manager = new ZkrMemoryHost( + { tenant: "tenant", person: "person", database: "test.db" }, + run as never, + ).manager("agent-1"); + + await manager.readFile({ relPath: "zkr://claim/c-1" }); + + expect(calls).toEqual([ + [ + "get", + { + tenant_id: "tenant", + person_id: "person", + target: { kind: "claim", id: "c-1" }, + }, + { tenant: "tenant", person: "person", database: "test.db" }, + ], + ]); + }); + + test("slices exact reads using from and lines with pagination logic", async () => { + const run = async () => ({ excerpt: "line1\nline2\nline3\nline4\nline5" }); + const manager = new ZkrMemoryHost({}, run as never).manager("agent-1"); + + // test default behaviour (from 1, lines 50, all fit) + const resultAll = await manager.readFile({ relPath: "zkr://source/s-1" }); + expect(resultAll).toMatchObject({ + text: "line1\nline2\nline3\nline4\nline5", + path: "zkr://source/s-1", + from: 1, + lines: 5, + truncated: false, + }); + expect(resultAll).not.toHaveProperty("nextFrom"); + + // test specific slice that hits the end + const resultEnd = await manager.readFile({ relPath: "zkr://source/s-1", from: 4, lines: 2 }); + expect(resultEnd).toMatchObject({ + text: "line4\nline5", + from: 4, + lines: 2, + truncated: false, + }); + expect(resultEnd).not.toHaveProperty("nextFrom"); + + // test truncation slice + const resultTruncated = await manager.readFile({ relPath: "zkr://source/s-1", from: 2, lines: 2 }); + expect(resultTruncated).toMatchObject({ + text: "line2\nline3", + from: 2, + lines: 2, + truncated: true, + nextFrom: 4, + }); + }); }); describe("zkr OpenClaw memory capability", () => { From c7073e0bac4924ed00609fac4e75d38be4f55d18 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 12 Aug 2026 02:09:10 +0000 Subject: [PATCH 2/2] Add tests for ZkrMemoryManager.readFile This fixes formatting errors and adds three new tests for the `readFile` functionality: - A test that invalid zkr paths correctly throw "invalid zkr memory path". - A test that reads are correctly mapped to the underlying CLI "get" command with extracted params. - A test validating the pagination logic (extracting line subsets) and truncation values using the `from` and `lines` parameter. Co-authored-by: undivisible <136312656+undivisible@users.noreply.github.com> --- plugins/openclaw/index.test.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/openclaw/index.test.ts b/plugins/openclaw/index.test.ts index d91db5c..10400d4 100644 --- a/plugins/openclaw/index.test.ts +++ b/plugins/openclaw/index.test.ts @@ -122,9 +122,9 @@ describe("zkr OpenClaw tools", () => { const manager = new ZkrMemoryHost({}, async () => ({}) as never).manager( "agent-1", ); - await expect( - manager.readFile({ relPath: "invalid-path" }), - ).rejects.toThrow("invalid zkr memory path"); + await expect(manager.readFile({ relPath: "invalid-path" })).rejects.toThrow( + "invalid zkr memory path", + ); await expect( manager.readFile({ relPath: "zkr://unknown/123" }), ).rejects.toThrow("invalid zkr memory path"); @@ -172,7 +172,11 @@ describe("zkr OpenClaw tools", () => { expect(resultAll).not.toHaveProperty("nextFrom"); // test specific slice that hits the end - const resultEnd = await manager.readFile({ relPath: "zkr://source/s-1", from: 4, lines: 2 }); + const resultEnd = await manager.readFile({ + relPath: "zkr://source/s-1", + from: 4, + lines: 2, + }); expect(resultEnd).toMatchObject({ text: "line4\nline5", from: 4, @@ -182,7 +186,11 @@ describe("zkr OpenClaw tools", () => { expect(resultEnd).not.toHaveProperty("nextFrom"); // test truncation slice - const resultTruncated = await manager.readFile({ relPath: "zkr://source/s-1", from: 2, lines: 2 }); + const resultTruncated = await manager.readFile({ + relPath: "zkr://source/s-1", + from: 2, + lines: 2, + }); expect(resultTruncated).toMatchObject({ text: "line2\nline3", from: 2,