Files
openclaw/extensions/memory-wiki/src/tool.test.ts
clawsweeper[bot] 9dc7bd4d05 fix(memory-wiki): make wiki_lint tool output path-safe (#83687)
Summary:
- The PR updates the memory-wiki `wiki_lint` tool to show vault-relative lint report paths in tool text and details, keeps the core linter/CLI result absolute, adds regression coverage, and adds a changelog entry.
- Reproducibility: yes. there is a high-confidence source reproduction path: current main returns the linter's ... tPath` in `wiki_lint` text and raw details. I did not execute the harness because this review is read-only.

Automerge notes:
- PR branch already contained follow-up commit before automerge: fix(memory-wiki): make wiki_lint tool output path-safe

Validation:
- ClawSweeper review passed for head df5c7db151.
- Required merge gates passed before the squash merge.

Prepared head SHA: df5c7db151
Review: https://github.com/openclaw/openclaw/pull/83687#issuecomment-4479682214

Co-authored-by: LLagoon3 <choonarm3@gmail.com>
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com>
Approved-by: takhoffman
Co-authored-by: takhoffman <781889+takhoffman@users.noreply.github.com>
2026-05-18 16:34:11 +00:00

79 lines
3.0 KiB
TypeScript

import fs from "node:fs/promises";
import path from "node:path";
import { describe, expect, it } from "vitest";
import type { ResolvedMemoryWikiConfig } from "./config.js";
import { createWikiApplyTool, createWikiLintTool } from "./tool.js";
import { lintMemoryWikiVault } from "./lint.js";
import { createMemoryWikiTestHarness } from "./test-helpers.js";
function asSchemaObject(value: unknown): Record<string, unknown> {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
throw new Error("Expected JSON schema object");
}
return value as Record<string, unknown>;
}
describe("memory-wiki tools", () => {
const harness = createMemoryWikiTestHarness();
it("allows provenance metadata in wiki_apply claim evidence", () => {
const tool = createWikiApplyTool({} as ResolvedMemoryWikiConfig);
const applyProperties = asSchemaObject(asSchemaObject(tool.parameters).properties);
const claimsSchema = asSchemaObject(applyProperties.claims);
const claimSchema = asSchemaObject(claimsSchema.items);
const claimProperties = asSchemaObject(claimSchema.properties);
const evidenceSchema = asSchemaObject(claimProperties.evidence);
const evidenceArraySchema = asSchemaObject(evidenceSchema.items);
const evidenceProperties = asSchemaObject(evidenceArraySchema.properties);
expect(Object.keys(evidenceProperties).toSorted()).toEqual([
"confidence",
"kind",
"lines",
"note",
"path",
"privacyTier",
"sourceId",
"updatedAt",
"weight",
]);
expect(evidenceProperties.confidence).toEqual({ type: "number", minimum: 0, maximum: 1 });
});
it("returns tool-safe relative report paths from wiki_lint", async () => {
const { rootDir, config } = await harness.createVault({ initialize: true });
await fs.mkdir(path.join(rootDir, "syntheses"), { recursive: true });
await fs.writeFile(
path.join(rootDir, "syntheses", "bad.md"),
[
"---",
"id: synth-bad",
"pageType: synthesis",
"title: Bad Page",
"---",
"",
"This links to [[Missing Page]].",
].join("\n"),
"utf8",
);
const tool = createWikiLintTool(config);
const result = await tool.execute("lint-call", {});
const text = result.content.find((part) => part.type === "text")?.text ?? "";
const details = asSchemaObject(result.details);
expect(text).toContain("Report: reports/lint.md");
expect(text).not.toContain(rootDir);
expect(details.reportPath).toBe("reports/lint.md");
expect(details).not.toHaveProperty("vaultRoot");
expect(JSON.stringify(details)).not.toContain(rootDir);
expect(asSchemaObject(details.issuesByCategory).links).toEqual(
expect.arrayContaining([expect.objectContaining({ code: "broken-wikilink" })]),
);
const lintResult = await lintMemoryWikiVault(config);
expect(path.isAbsolute(lintResult.reportPath)).toBe(true);
expect(lintResult.reportPath).toContain(rootDir);
});
});