


























@@ -3,8 +3,8 @@ import type { Dirent } from "node:fs";
33import fs from "node:fs/promises";
44import os from "node:os";
55import path from "node:path";
6-import { describe, expect, it, vi } from "vitest";
7-import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope.js";
6+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
7+import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope-config.js";
88import type { OpenClawConfig } from "../../../../src/config/config.js";
99import { resolveMemoryBackendConfig } from "./backend-config.js";
1010@@ -54,6 +54,23 @@ const customQmdCollections = (
5454const customCollectionPaths = (resolved: ResolvedMemoryBackendConfig): string[] =>
5555customQmdCollections(resolved).map((collection) => collection.path);
565657+let fixtureRoot: string;
58+let fixtureId = 0;
59+60+beforeAll(async () => {
61+fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-"));
62+});
63+64+afterAll(async () => {
65+await fs.rm(fixtureRoot, { recursive: true, force: true });
66+});
67+68+async function createFixtureDir(name: string): Promise<string> {
69+const dir = path.join(fixtureRoot, `${name}-${fixtureId++}`);
70+await fs.mkdir(dir, { recursive: true });
71+return dir;
72+}
73+5774describe("resolveMemoryBackendConfig", () => {
5875it("defaults to builtin backend when config missing", () => {
5976const cfg = { agents: { defaults: { workspace: "/tmp/memory-test" } } } as OpenClawConfig;
@@ -261,65 +278,57 @@ describe("resolveMemoryBackendConfig", () => {
261278});
262279263280it("keeps symlinked workspace paths agent-scoped when deciding custom collection names", async () => {
264-const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-"));
281+const tmpRoot = await createFixtureDir("symlinked-workspace");
265282const workspaceDir = path.join(tmpRoot, "workspace");
266283const workspaceAliasDir = path.join(tmpRoot, "workspace-alias");
267-try {
268-await fs.mkdir(workspaceDir, { recursive: true });
269-await fs.symlink(workspaceDir, workspaceAliasDir);
270-const cfg = {
271-agents: {
272-defaults: { workspace: workspaceDir },
273-list: [{ id: "main", default: true, workspace: workspaceDir }],
274-},
275-memory: {
276-backend: "qmd",
277-qmd: {
278-includeDefaultMemory: false,
279-paths: [{ path: workspaceAliasDir, name: "workspace", pattern: "**/*.md" }],
280-},
284+await fs.mkdir(workspaceDir, { recursive: true });
285+await fs.symlink(workspaceDir, workspaceAliasDir);
286+const cfg = {
287+agents: {
288+defaults: { workspace: workspaceDir },
289+list: [{ id: "main", default: true, workspace: workspaceDir }],
290+},
291+memory: {
292+backend: "qmd",
293+qmd: {
294+includeDefaultMemory: false,
295+paths: [{ path: workspaceAliasDir, name: "workspace", pattern: "**/*.md" }],
281296},
282-} as OpenClawConfig;
283-const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
284-const names = collectionNames(resolved);
285-expect(names.has("workspace-main")).toBe(true);
286-expect(names.has("workspace")).toBe(false);
287-} finally {
288-await fs.rm(tmpRoot, { recursive: true, force: true });
289-}
297+},
298+} as OpenClawConfig;
299+const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
300+const names = collectionNames(resolved);
301+expect(names.has("workspace-main")).toBe(true);
302+expect(names.has("workspace")).toBe(false);
290303});
291304292305it("keeps unresolved child paths under a symlinked workspace agent-scoped", async () => {
293-const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-"));
306+const tmpRoot = await createFixtureDir("symlinked-child");
294307const realRootDir = path.join(tmpRoot, "real-root");
295308const aliasRootDir = path.join(tmpRoot, "alias-root");
296309const workspaceDir = path.join(realRootDir, "workspace");
297310const workspaceAliasDir = path.join(aliasRootDir, "workspace");
298-try {
299-await fs.mkdir(workspaceDir, { recursive: true });
300-await fs.symlink(realRootDir, aliasRootDir);
301-const cfg = {
302-agents: {
303-defaults: { workspace: workspaceDir },
304-list: [{ id: "main", default: true, workspace: workspaceDir }],
305-},
306-memory: {
307-backend: "qmd",
308-qmd: {
309-includeDefaultMemory: false,
310-paths: [
311-{ path: path.join(workspaceAliasDir, "notes"), name: "notes", pattern: "**/*.md" },
312-],
313-},
311+await fs.mkdir(workspaceDir, { recursive: true });
312+await fs.symlink(realRootDir, aliasRootDir);
313+const cfg = {
314+agents: {
315+defaults: { workspace: workspaceDir },
316+list: [{ id: "main", default: true, workspace: workspaceDir }],
317+},
318+memory: {
319+backend: "qmd",
320+qmd: {
321+includeDefaultMemory: false,
322+paths: [
323+{ path: path.join(workspaceAliasDir, "notes"), name: "notes", pattern: "**/*.md" },
324+],
314325},
315-} as OpenClawConfig;
316-const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
317-const names = collectionNames(resolved);
318-expect(names.has("notes-main")).toBe(true);
319-expect(names.has("notes")).toBe(false);
320-} finally {
321-await fs.rm(tmpRoot, { recursive: true, force: true });
322-}
326+},
327+} as OpenClawConfig;
328+const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
329+const names = collectionNames(resolved);
330+expect(names.has("notes-main")).toBe(true);
331+expect(names.has("notes")).toBe(false);
323332});
324333325334it("resolves qmd update timeout overrides", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。