From 81f48384cbbb93e381798b5f05bc4e530d087da3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 7 Apr 2026 09:42:06 +0100 Subject: [PATCH] fix: stabilize extension shard tests --- .../mattermost/src/mattermost/send.test.ts | 7 ++++ .../memory-core/src/public-artifacts.test.ts | 33 ++++++++++++++----- .../memory-core/src/public-artifacts.ts | 26 +++++++++------ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/extensions/mattermost/src/mattermost/send.test.ts b/extensions/mattermost/src/mattermost/send.test.ts index dfc0a6dfc94..be3d0bad287 100644 --- a/extensions/mattermost/src/mattermost/send.test.ts +++ b/extensions/mattermost/src/mattermost/send.test.ts @@ -45,6 +45,13 @@ vi.mock("openclaw/plugin-sdk/config-runtime", () => ({ vi.mock("openclaw/plugin-sdk/text-runtime", () => ({ convertMarkdownTables: vi.fn((text: string) => text), + normalizeOptionalString: vi.fn((value: string | null | undefined) => { + if (typeof value !== "string") { + return undefined; + } + const normalized = value.trim(); + return normalized.length > 0 ? normalized : undefined; + }), })); vi.mock("./accounts.js", () => ({ diff --git a/extensions/memory-core/src/public-artifacts.test.ts b/extensions/memory-core/src/public-artifacts.test.ts index fd6a631fae0..caf67f7bd35 100644 --- a/extensions/memory-core/src/public-artifacts.test.ts +++ b/extensions/memory-core/src/public-artifacts.test.ts @@ -24,7 +24,7 @@ describe("listMemoryCorePublicArtifacts", () => { }); it("lists public workspace artifacts with stable kinds", async () => { - const workspaceDir = path.join(fixtureRoot, "workspace"); + const workspaceDir = path.join(fixtureRoot, "workspace-stable-kinds"); await fs.mkdir(path.join(workspaceDir, "memory", "dreaming"), { recursive: true }); await fs.writeFile(path.join(workspaceDir, "MEMORY.md"), "# Durable Memory\n", "utf8"); await fs.writeFile( @@ -60,14 +60,6 @@ describe("listMemoryCorePublicArtifacts", () => { agentIds: ["main"], contentType: "markdown", }, - { - kind: "memory-root", - workspaceDir, - relativePath: "memory.md", - absolutePath: path.join(workspaceDir, "memory.md"), - agentIds: ["main"], - contentType: "markdown", - }, { kind: "daily-note", workspaceDir, @@ -94,4 +86,27 @@ describe("listMemoryCorePublicArtifacts", () => { }, ]); }); + + it("lists lowercase memory root when only the legacy filename exists", async () => { + const workspaceDir = path.join(fixtureRoot, "workspace-lowercase-root"); + await fs.mkdir(workspaceDir, { recursive: true }); + await fs.writeFile(path.join(workspaceDir, "memory.md"), "# Legacy Durable Memory\n", "utf8"); + + const cfg: OpenClawConfig = { + agents: { + list: [{ id: "main", default: true, workspace: workspaceDir }], + }, + }; + + await expect(listMemoryCorePublicArtifacts({ cfg })).resolves.toEqual([ + { + kind: "memory-root", + workspaceDir, + relativePath: "memory.md", + absolutePath: path.join(workspaceDir, "memory.md"), + agentIds: ["main"], + contentType: "markdown", + }, + ]); + }); }); diff --git a/extensions/memory-core/src/public-artifacts.ts b/extensions/memory-core/src/public-artifacts.ts index 4dfc3d5fa2e..501b67f7568 100644 --- a/extensions/memory-core/src/public-artifacts.ts +++ b/extensions/memory-core/src/public-artifacts.ts @@ -35,18 +35,24 @@ async function collectWorkspaceArtifacts(params: { agentIds: string[]; }): Promise { const artifacts: MemoryPluginPublicArtifact[] = []; + const workspaceEntries = new Set( + (await fs.readdir(params.workspaceDir, { withFileTypes: true }).catch(() => [])) + .filter((entry) => entry.isFile()) + .map((entry) => entry.name), + ); for (const relativePath of ["MEMORY.md", "memory.md"]) { - const absolutePath = path.join(params.workspaceDir, relativePath); - if (await pathExists(absolutePath)) { - artifacts.push({ - kind: "memory-root", - workspaceDir: params.workspaceDir, - relativePath, - absolutePath, - agentIds: [...params.agentIds], - contentType: "markdown", - }); + if (!workspaceEntries.has(relativePath)) { + continue; } + const absolutePath = path.join(params.workspaceDir, relativePath); + artifacts.push({ + kind: "memory-root", + workspaceDir: params.workspaceDir, + relativePath, + absolutePath, + agentIds: [...params.agentIds], + contentType: "markdown", + }); } const memoryDir = path.join(params.workspaceDir, "memory");