mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:50:45 +00:00
perf: trim agent workspace imports
This commit is contained in:
@@ -3,8 +3,8 @@ import type { Dirent } from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope.js";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope-config.js";
|
||||
import type { OpenClawConfig } from "../../../../src/config/config.js";
|
||||
import { resolveMemoryBackendConfig } from "./backend-config.js";
|
||||
|
||||
@@ -54,6 +54,23 @@ const customQmdCollections = (
|
||||
const customCollectionPaths = (resolved: ResolvedMemoryBackendConfig): string[] =>
|
||||
customQmdCollections(resolved).map((collection) => collection.path);
|
||||
|
||||
let fixtureRoot: string;
|
||||
let fixtureId = 0;
|
||||
|
||||
beforeAll(async () => {
|
||||
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
async function createFixtureDir(name: string): Promise<string> {
|
||||
const dir = path.join(fixtureRoot, `${name}-${fixtureId++}`);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
|
||||
describe("resolveMemoryBackendConfig", () => {
|
||||
it("defaults to builtin backend when config missing", () => {
|
||||
const cfg = { agents: { defaults: { workspace: "/tmp/memory-test" } } } as OpenClawConfig;
|
||||
@@ -261,65 +278,57 @@ describe("resolveMemoryBackendConfig", () => {
|
||||
});
|
||||
|
||||
it("keeps symlinked workspace paths agent-scoped when deciding custom collection names", async () => {
|
||||
const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-"));
|
||||
const tmpRoot = await createFixtureDir("symlinked-workspace");
|
||||
const workspaceDir = path.join(tmpRoot, "workspace");
|
||||
const workspaceAliasDir = path.join(tmpRoot, "workspace-alias");
|
||||
try {
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
await fs.symlink(workspaceDir, workspaceAliasDir);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: { workspace: workspaceDir },
|
||||
list: [{ id: "main", default: true, workspace: workspaceDir }],
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
await fs.symlink(workspaceDir, workspaceAliasDir);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: { workspace: workspaceDir },
|
||||
list: [{ id: "main", default: true, workspace: workspaceDir }],
|
||||
},
|
||||
memory: {
|
||||
backend: "qmd",
|
||||
qmd: {
|
||||
includeDefaultMemory: false,
|
||||
paths: [{ path: workspaceAliasDir, name: "workspace", pattern: "**/*.md" }],
|
||||
},
|
||||
memory: {
|
||||
backend: "qmd",
|
||||
qmd: {
|
||||
includeDefaultMemory: false,
|
||||
paths: [{ path: workspaceAliasDir, name: "workspace", pattern: "**/*.md" }],
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
|
||||
const names = collectionNames(resolved);
|
||||
expect(names.has("workspace-main")).toBe(true);
|
||||
expect(names.has("workspace")).toBe(false);
|
||||
} finally {
|
||||
await fs.rm(tmpRoot, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
|
||||
const names = collectionNames(resolved);
|
||||
expect(names.has("workspace-main")).toBe(true);
|
||||
expect(names.has("workspace")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps unresolved child paths under a symlinked workspace agent-scoped", async () => {
|
||||
const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), "qmd-backend-config-"));
|
||||
const tmpRoot = await createFixtureDir("symlinked-child");
|
||||
const realRootDir = path.join(tmpRoot, "real-root");
|
||||
const aliasRootDir = path.join(tmpRoot, "alias-root");
|
||||
const workspaceDir = path.join(realRootDir, "workspace");
|
||||
const workspaceAliasDir = path.join(aliasRootDir, "workspace");
|
||||
try {
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
await fs.symlink(realRootDir, aliasRootDir);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: { workspace: workspaceDir },
|
||||
list: [{ id: "main", default: true, workspace: workspaceDir }],
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
await fs.symlink(realRootDir, aliasRootDir);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: { workspace: workspaceDir },
|
||||
list: [{ id: "main", default: true, workspace: workspaceDir }],
|
||||
},
|
||||
memory: {
|
||||
backend: "qmd",
|
||||
qmd: {
|
||||
includeDefaultMemory: false,
|
||||
paths: [
|
||||
{ path: path.join(workspaceAliasDir, "notes"), name: "notes", pattern: "**/*.md" },
|
||||
],
|
||||
},
|
||||
memory: {
|
||||
backend: "qmd",
|
||||
qmd: {
|
||||
includeDefaultMemory: false,
|
||||
paths: [
|
||||
{ path: path.join(workspaceAliasDir, "notes"), name: "notes", pattern: "**/*.md" },
|
||||
],
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
|
||||
const names = collectionNames(resolved);
|
||||
expect(names.has("notes-main")).toBe(true);
|
||||
expect(names.has("notes")).toBe(false);
|
||||
} finally {
|
||||
await fs.rm(tmpRoot, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId: "main" });
|
||||
const names = collectionNames(resolved);
|
||||
expect(names.has("notes-main")).toBe(true);
|
||||
expect(names.has("notes")).toBe(false);
|
||||
});
|
||||
|
||||
it("resolves qmd update timeout overrides", () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope.js";
|
||||
import { resolveAgentWorkspaceDir } from "../../../../src/agents/agent-scope-config.js";
|
||||
import { parseDurationMs } from "../../../../src/cli/parse-duration.js";
|
||||
import type { OpenClawConfig } from "../../../../src/config/config.js";
|
||||
import type { SessionSendPolicyConfig } from "../../../../src/config/types.base.js";
|
||||
|
||||
Reference in New Issue
Block a user