|
| 1 | +import fs from "node:fs/promises"; |
| 2 | +import os from "node:os"; |
1 | 3 | import path from "node:path"; |
2 | 4 | import { describe, expect, it } from "vitest"; |
3 | 5 | import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope.js"; |
@@ -111,6 +113,66 @@ describe("resolveMemoryBackendConfig", () => { |
111 | 113 | expect(devNames.has("workspace-dev")).toBe(true); |
112 | 114 | }); |
113 | 115 |
|
| 116 | + it("preserves explicit custom collection names for paths outside the workspace", () => { |
| 117 | + const cfg = { |
| 118 | + agents: { |
| 119 | + defaults: { workspace: "/workspace/root" }, |
| 120 | + list: [ |
| 121 | + { id: "main", default: true, workspace: "/workspace/root" }, |
| 122 | + { id: "dev", workspace: "/workspace/dev" }, |
| 123 | + ], |
| 124 | + }, |
| 125 | + memory: { |
| 126 | + backend: "qmd", |
| 127 | + qmd: { |
| 128 | + includeDefaultMemory: true, |
| 129 | + paths: [{ path: "/shared/notion-mirror", name: "notion-mirror", pattern: "**/*.md" }], |
| 130 | + }, |
| 131 | + }, |
| 132 | + } as OpenClawConfig; |
| 133 | + const mainResolved = resolveMemoryBackendConfig({ cfg, agentId: "main" }); |
| 134 | + const devResolved = resolveMemoryBackendConfig({ cfg, agentId: "dev" }); |
| 135 | + const mainNames = new Set( |
| 136 | + (mainResolved.qmd?.collections ?? []).map((collection) => collection.name), |
| 137 | + ); |
| 138 | + const devNames = new Set( |
| 139 | + (devResolved.qmd?.collections ?? []).map((collection) => collection.name), |
| 140 | + ); |
| 141 | + expect(mainNames.has("memory-dir-main")).toBe(true); |
| 142 | + expect(devNames.has("memory-dir-dev")).toBe(true); |
| 143 | + expect(mainNames.has("notion-mirror")).toBe(true); |
| 144 | + expect(devNames.has("notion-mirror")).toBe(true); |
| 145 | + }); |
| 146 | + |
| 147 | + it("keeps symlinked workspace paths agent-scoped when deciding custom collection names", async () => { |
| 148 | + const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-")); |
| 149 | + const workspaceDir = path.join(tmpRoot, "workspace"); |
| 150 | + const workspaceAliasDir = path.join(tmpRoot, "workspace-alias"); |
| 151 | + try { |
| 152 | + await fs.mkdir(workspaceDir, { recursive: true }); |
| 153 | + await fs.symlink(workspaceDir, workspaceAliasDir); |
| 154 | + const cfg = { |
| 155 | + agents: { |
| 156 | + defaults: { workspace: workspaceDir }, |
| 157 | + list: [{ id: "main", default: true, workspace: workspaceDir }], |
| 158 | + }, |
| 159 | + memory: { |
| 160 | + backend: "qmd", |
| 161 | + qmd: { |
| 162 | + includeDefaultMemory: false, |
| 163 | + paths: [{ path: workspaceAliasDir, name: "workspace", pattern: "**/*.md" }], |
| 164 | + }, |
| 165 | + }, |
| 166 | + } as OpenClawConfig; |
| 167 | + const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" }); |
| 168 | + const names = new Set((resolved.qmd?.collections ?? []).map((collection) => collection.name)); |
| 169 | + expect(names.has("workspace-main")).toBe(true); |
| 170 | + expect(names.has("workspace")).toBe(false); |
| 171 | + } finally { |
| 172 | + await fs.rm(tmpRoot, { recursive: true, force: true }); |
| 173 | + } |
| 174 | + }); |
| 175 | + |
114 | 176 | it("resolves qmd update timeout overrides", () => { |
115 | 177 | const cfg = { |
116 | 178 | agents: { defaults: { workspace: "/tmp/memory-test" } }, |
@@ -283,6 +345,25 @@ describe("memorySearch.extraPaths integration", () => { |
283 | 345 | expect(paths).toContain(resolveComparablePath("/agent-only")); |
284 | 346 | }); |
285 | 347 |
|
| 348 | + it("keeps unnamed extra paths agent-scoped even when they resolve outside the workspace", () => { |
| 349 | + const cfg = { |
| 350 | + memory: { backend: "qmd" }, |
| 351 | + agents: { |
| 352 | + defaults: { |
| 353 | + workspace: "/workspace/root", |
| 354 | + memorySearch: { |
| 355 | + extraPaths: ["/shared/path"], |
| 356 | + }, |
| 357 | + }, |
| 358 | + }, |
| 359 | + } as OpenClawConfig; |
| 360 | + const result = resolveMemoryBackendConfig({ cfg, agentId: "my-agent" }); |
| 361 | + const customCollections = (result.qmd?.collections ?? []).filter( |
| 362 | + (collection) => collection.kind === "custom", |
| 363 | + ); |
| 364 | + expect(customCollections.map((collection) => collection.name)).toContain("custom-1-my-agent"); |
| 365 | + }); |
| 366 | + |
286 | 367 | it("matches per-agent memorySearch.extraPaths using normalized agent ids", () => { |
287 | 368 | const cfg = { |
288 | 369 | memory: { backend: "qmd" }, |
|
0 commit comments