mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
test: reuse memory-wiki temp fixtures
This commit is contained in:
@@ -1,14 +1,27 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { Command } from "commander";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { registerWikiCli } from "./cli.js";
|
||||
import { parseWikiMarkdown, renderWikiMarkdown } from "./markdown.js";
|
||||
import { createMemoryWikiTestHarness } from "./test-helpers.js";
|
||||
|
||||
const { createVault } = createMemoryWikiTestHarness();
|
||||
let suiteRoot = "";
|
||||
let caseIndex = 0;
|
||||
|
||||
describe("memory-wiki cli", () => {
|
||||
beforeAll(async () => {
|
||||
suiteRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-wiki-cli-suite-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (suiteRoot) {
|
||||
await fs.rm(suiteRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(process.stdout, "write").mockImplementation(
|
||||
(() => true) as typeof process.stdout.write,
|
||||
@@ -21,8 +34,20 @@ describe("memory-wiki cli", () => {
|
||||
process.exitCode = undefined;
|
||||
});
|
||||
|
||||
async function createCliVault(options?: {
|
||||
config?: Parameters<typeof createVault>[0]["config"];
|
||||
initialize?: boolean;
|
||||
}) {
|
||||
return createVault({
|
||||
prefix: "memory-wiki-cli-",
|
||||
rootDir: path.join(suiteRoot, `case-${caseIndex++}`),
|
||||
initialize: options?.initialize,
|
||||
config: options?.config,
|
||||
});
|
||||
}
|
||||
|
||||
it("registers apply synthesis and writes a synthesis page", async () => {
|
||||
const { rootDir, config } = await createVault({ prefix: "memory-wiki-cli-" });
|
||||
const { rootDir, config } = await createCliVault();
|
||||
const program = new Command();
|
||||
program.name("test");
|
||||
registerWikiCli(program, config);
|
||||
@@ -52,8 +77,7 @@ describe("memory-wiki cli", () => {
|
||||
});
|
||||
|
||||
it("registers apply metadata and preserves the page body", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-cli-",
|
||||
const { rootDir, config } = await createCliVault({
|
||||
initialize: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
@@ -113,8 +137,7 @@ cli note
|
||||
});
|
||||
|
||||
it("runs wiki doctor and sets a non-zero exit code when warnings exist", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-cli-",
|
||||
const { rootDir, config } = await createCliVault({
|
||||
config: {
|
||||
obsidian: { enabled: true, useOfficialCli: true },
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../api.js";
|
||||
import { renderWikiMarkdown } from "./markdown.js";
|
||||
import { getMemoryWikiPage, searchMemoryWiki } from "./query.js";
|
||||
@@ -15,12 +16,36 @@ vi.mock("openclaw/plugin-sdk/memory-host-search", () => ({
|
||||
}));
|
||||
|
||||
const { createVault } = createMemoryWikiTestHarness();
|
||||
let suiteRoot = "";
|
||||
let caseIndex = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
getActiveMemorySearchManagerMock.mockReset();
|
||||
getActiveMemorySearchManagerMock.mockResolvedValue({ manager: null, error: "unavailable" });
|
||||
});
|
||||
|
||||
beforeAll(async () => {
|
||||
suiteRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-wiki-query-suite-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (suiteRoot) {
|
||||
await fs.rm(suiteRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
async function createQueryVault(options?: {
|
||||
config?: Parameters<typeof createVault>[0]["config"];
|
||||
initialize?: boolean;
|
||||
}) {
|
||||
return createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
rootDir: path.join(suiteRoot, `case-${caseIndex++}`),
|
||||
initialize: options?.initialize,
|
||||
config: options?.config,
|
||||
});
|
||||
}
|
||||
|
||||
function createAppConfig(): OpenClawConfig {
|
||||
return {
|
||||
agents: {
|
||||
@@ -58,8 +83,7 @@ function createMemoryManager(overrides?: {
|
||||
|
||||
describe("searchMemoryWiki", () => {
|
||||
it("finds wiki pages by title and body", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
@@ -80,8 +104,7 @@ describe("searchMemoryWiki", () => {
|
||||
});
|
||||
|
||||
it("surfaces bridge provenance for imported source pages", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
@@ -115,8 +138,7 @@ describe("searchMemoryWiki", () => {
|
||||
});
|
||||
|
||||
it("includes active memory results when shared search and all corpora are enabled", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
config: {
|
||||
search: { backend: "shared", corpus: "all" },
|
||||
@@ -159,8 +181,7 @@ describe("searchMemoryWiki", () => {
|
||||
});
|
||||
|
||||
it("allows per-call corpus overrides without changing config defaults", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
config: {
|
||||
search: { backend: "shared", corpus: "wiki" },
|
||||
@@ -201,8 +222,7 @@ describe("searchMemoryWiki", () => {
|
||||
});
|
||||
|
||||
it("keeps memory search disabled when the backend is local", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
config: {
|
||||
search: { backend: "local", corpus: "all" },
|
||||
@@ -244,8 +264,7 @@ describe("searchMemoryWiki", () => {
|
||||
|
||||
describe("getMemoryWikiPage", () => {
|
||||
it("reads wiki pages by relative path and slices line ranges", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
@@ -272,8 +291,7 @@ describe("getMemoryWikiPage", () => {
|
||||
});
|
||||
|
||||
it("returns provenance for imported wiki source pages", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
});
|
||||
await fs.writeFile(
|
||||
@@ -312,8 +330,7 @@ describe("getMemoryWikiPage", () => {
|
||||
});
|
||||
|
||||
it("falls back to active memory reads when memory corpus is selected", async () => {
|
||||
const { config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { config } = await createQueryVault({
|
||||
initialize: true,
|
||||
config: {
|
||||
search: { backend: "shared", corpus: "memory" },
|
||||
@@ -352,8 +369,7 @@ describe("getMemoryWikiPage", () => {
|
||||
});
|
||||
|
||||
it("allows per-call get overrides to bypass wiki and force memory fallback", async () => {
|
||||
const { rootDir, config } = await createVault({
|
||||
prefix: "memory-wiki-query-",
|
||||
const { rootDir, config } = await createQueryVault({
|
||||
initialize: true,
|
||||
config: {
|
||||
search: { backend: "shared", corpus: "wiki" },
|
||||
|
||||
Reference in New Issue
Block a user