mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: trim memory wiki fixture setup
This commit is contained in:
@@ -55,10 +55,10 @@ describe("applyMemoryWikiMutation", () => {
|
||||
it("updates page metadata without overwriting existing human notes", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-apply-",
|
||||
initialize: true,
|
||||
});
|
||||
|
||||
const targetPath = path.join(rootDir, "entities", "alpha.md");
|
||||
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
||||
await fs.writeFile(
|
||||
targetPath,
|
||||
renderWikiMarkdown({
|
||||
|
||||
@@ -1,18 +1,43 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { appendMemoryHostEvent } from "openclaw/plugin-sdk/memory-host-events";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../api.js";
|
||||
import { syncMemoryWikiBridgeSources } from "./bridge.js";
|
||||
import { createMemoryWikiTestHarness } from "./test-helpers.js";
|
||||
|
||||
const { createTempDir, createVault } = createMemoryWikiTestHarness();
|
||||
const { createVault } = createMemoryWikiTestHarness();
|
||||
|
||||
describe("syncMemoryWikiBridgeSources", () => {
|
||||
let fixtureRoot = "";
|
||||
let caseId = 0;
|
||||
|
||||
beforeAll(async () => {
|
||||
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-wiki-bridge-suite-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (!fixtureRoot) {
|
||||
return;
|
||||
}
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function nextCaseRoot(name: string): string {
|
||||
return path.join(fixtureRoot, `case-${caseId++}-${name}`);
|
||||
}
|
||||
|
||||
async function createBridgeWorkspace(name: string): Promise<string> {
|
||||
const workspaceDir = nextCaseRoot(name);
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
return workspaceDir;
|
||||
}
|
||||
|
||||
it("imports public memory-core artifacts and stays idempotent across reruns", async () => {
|
||||
const workspaceDir = await createTempDir("memory-wiki-bridge-ws-");
|
||||
const workspaceDir = await createBridgeWorkspace("workspace");
|
||||
const { rootDir: vaultDir, config } = await createVault({
|
||||
prefix: "memory-wiki-bridge-vault-",
|
||||
rootDir: nextCaseRoot("vault"),
|
||||
config: {
|
||||
vaultMode: "bridge",
|
||||
bridge: {
|
||||
@@ -83,7 +108,7 @@ describe("syncMemoryWikiBridgeSources", () => {
|
||||
});
|
||||
|
||||
it("returns a no-op result outside bridge mode", async () => {
|
||||
const { config } = await createVault({ prefix: "memory-wiki-isolated-" });
|
||||
const { config } = await createVault({ rootDir: nextCaseRoot("isolated") });
|
||||
|
||||
const result = await syncMemoryWikiBridgeSources({ config });
|
||||
|
||||
@@ -99,9 +124,9 @@ describe("syncMemoryWikiBridgeSources", () => {
|
||||
});
|
||||
|
||||
it("imports the public memory event journal when followMemoryEvents is enabled", async () => {
|
||||
const workspaceDir = await createTempDir("memory-wiki-bridge-events-ws-");
|
||||
const workspaceDir = await createBridgeWorkspace("events-workspace");
|
||||
const { rootDir: vaultDir, config } = await createVault({
|
||||
prefix: "memory-wiki-bridge-events-vault-",
|
||||
rootDir: nextCaseRoot("events-vault"),
|
||||
config: {
|
||||
vaultMode: "bridge",
|
||||
bridge: {
|
||||
@@ -151,9 +176,9 @@ describe("syncMemoryWikiBridgeSources", () => {
|
||||
});
|
||||
|
||||
it("prunes stale bridge pages when the source artifact disappears", async () => {
|
||||
const workspaceDir = await createTempDir("memory-wiki-bridge-prune-ws-");
|
||||
const workspaceDir = await createBridgeWorkspace("prune-workspace");
|
||||
const { rootDir: vaultDir, config } = await createVault({
|
||||
prefix: "memory-wiki-bridge-prune-vault-",
|
||||
rootDir: nextCaseRoot("prune-vault"),
|
||||
config: {
|
||||
vaultMode: "bridge",
|
||||
bridge: {
|
||||
|
||||
@@ -78,11 +78,11 @@ describe("memory-wiki cli", () => {
|
||||
});
|
||||
|
||||
it("registers apply metadata and preserves the page body", async () => {
|
||||
const { rootDir, config } = await createCliVault({
|
||||
initialize: true,
|
||||
});
|
||||
const { rootDir, config } = await createCliVault();
|
||||
const targetPath = path.join(rootDir, "entities", "alpha.md");
|
||||
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(rootDir, "entities", "alpha.md"),
|
||||
targetPath,
|
||||
renderWikiMarkdown({
|
||||
frontmatter: {
|
||||
pageType: "entity",
|
||||
|
||||
@@ -11,11 +11,15 @@ describe("lintMemoryWikiVault", () => {
|
||||
it("detects duplicate ids, provenance gaps, contradictions, and open questions", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-lint-",
|
||||
initialize: true,
|
||||
config: {
|
||||
vault: { renderMode: "obsidian" },
|
||||
},
|
||||
});
|
||||
await Promise.all(
|
||||
["entities", "concepts", "sources"].map((dir) =>
|
||||
fs.mkdir(path.join(rootDir, dir), { recursive: true }),
|
||||
),
|
||||
);
|
||||
|
||||
const duplicate = renderWikiMarkdown({
|
||||
frontmatter: {
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { createMemoryWikiTestHarness } from "./test-helpers.js";
|
||||
import { syncMemoryWikiUnsafeLocalSources } from "./unsafe-local.js";
|
||||
|
||||
const { createTempDir, createVault } = createMemoryWikiTestHarness();
|
||||
const { createVault } = createMemoryWikiTestHarness();
|
||||
|
||||
describe("syncMemoryWikiUnsafeLocalSources", () => {
|
||||
let fixtureRoot = "";
|
||||
let caseId = 0;
|
||||
|
||||
beforeAll(async () => {
|
||||
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-wiki-unsafe-suite-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (!fixtureRoot) {
|
||||
return;
|
||||
}
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function nextCaseRoot(name: string): string {
|
||||
return path.join(fixtureRoot, `case-${caseId++}-${name}`);
|
||||
}
|
||||
|
||||
async function createPrivateDir(name: string): Promise<string> {
|
||||
const privateDir = nextCaseRoot(name);
|
||||
await fs.mkdir(privateDir, { recursive: true });
|
||||
return privateDir;
|
||||
}
|
||||
|
||||
it("imports explicit private paths and preserves unsafe-local provenance", async () => {
|
||||
const privateDir = await createTempDir("memory-wiki-private-");
|
||||
const privateDir = await createPrivateDir("private");
|
||||
|
||||
await fs.mkdir(path.join(privateDir, "nested"), { recursive: true });
|
||||
await fs.writeFile(path.join(privateDir, "nested", "state.md"), "# internal state\n", "utf8");
|
||||
@@ -18,7 +43,7 @@ describe("syncMemoryWikiUnsafeLocalSources", () => {
|
||||
await fs.writeFile(directPath, "private log\n", "utf8");
|
||||
|
||||
const { rootDir: vaultDir, config } = await createVault({
|
||||
prefix: "memory-wiki-unsafe-vault-",
|
||||
rootDir: nextCaseRoot("vault"),
|
||||
config: {
|
||||
vaultMode: "unsafe-local",
|
||||
unsafeLocal: {
|
||||
@@ -49,13 +74,13 @@ describe("syncMemoryWikiUnsafeLocalSources", () => {
|
||||
});
|
||||
|
||||
it("prunes stale unsafe-local pages when configured files disappear", async () => {
|
||||
const privateDir = await createTempDir("memory-wiki-private-prune-");
|
||||
const privateDir = await createPrivateDir("private-prune");
|
||||
|
||||
const secretPath = path.join(privateDir, "secret.md");
|
||||
await fs.writeFile(secretPath, "# private\n", "utf8");
|
||||
|
||||
const { rootDir: vaultDir, config } = await createVault({
|
||||
prefix: "memory-wiki-unsafe-prune-vault-",
|
||||
rootDir: nextCaseRoot("prune-vault"),
|
||||
config: {
|
||||
vaultMode: "unsafe-local",
|
||||
unsafeLocal: {
|
||||
|
||||
Reference in New Issue
Block a user