fix: stabilize extension shard tests

This commit is contained in:
Peter Steinberger
2026-04-07 09:42:06 +01:00
parent ad49549c92
commit 81f48384cb
3 changed files with 47 additions and 19 deletions

View File

@@ -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", () => ({

View File

@@ -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",
},
]);
});
});

View File

@@ -35,18 +35,24 @@ async function collectWorkspaceArtifacts(params: {
agentIds: string[];
}): Promise<MemoryPluginPublicArtifact[]> {
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");