ReMe/github-pages/tests/generated-content.test.mjs
star-nebula d792f450e5
feat(integrations): add ZCode memory plugin (#707)
* feat(integrations): add ZCode memory plugin

Package ReMe lifecycle hooks, MCP tools, and the reme-memory skill as an installable ZCode plugin. The hook queues completed turns locally and retries delivery from later sessions so transient service failures do not lose memory.

* fix(zcode): resolve pre-commit failures without blocking delivery

* fix(zcode): honor disabled memory, keep one prompt copy, document setup

Address the review on the ZCode integration:

- config.example.json ships an empty api_url so the default single-port
  deployment is derived from mcp_url instead of pointing at a port the
  default `reme start` does not open.
- remember_prompt writes a single cache record per turn: a payload without
  a turn ID is read back from latest.json, so the extra hashed copy left
  plaintext prompt text behind after the turn was delivered.
- flush_worker re-reads auto_memory before delivering and leaves pending
  files untouched when recording was disabled mid-flight; it also uses a
  worker.rerun marker so a delivery request arriving while another pass
  holds the lock triggers a rescan instead of being dropped.
- README/README_ZH now follow the Qoder guide: dependency install, model
  credentials, an executable `reme start` with an explicit workspace,
  platform-specific commands, empty-api_url derivation, the
  memory_interval example vs default, MCP reconnect after endpoint
  changes, a health_check/version check before the memory test, and a
  qualified statement about the async hook field and the detached worker.
- Regression tests cover all four behaviors.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* docs(zcode): state the verified ZCode build

Name the build the plugin was verified on and the reason compatibility
rests on payload fields rather than a version number.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* test(zcode): name unused flush_all config with an underscore

* fix(zcode): make worker handoff race-safe and honor the recording switch

The rerun marker was written only after a failed lock acquisition, so a
contender suspended between the failed acquire and the marker write left a
queued session and a marker with no worker to process them. The worker now
publishes its request before contending for the lock, which leaves exactly two
outcomes: the owner sees the marker and scans again, or the lock is free and
this worker delivers itself.

worker.rerun also dropped force semantics, so a SessionStart force request lost
to a Stop owner whose rerun pass then stayed non-forced. A separate, never
downgraded worker.force marker keeps the stronger request until the next pass.

The auto_memory switch was checked once at worker entry and the snapshot reused
for every batch, so disabling recording during a run still submitted later
batches. The switch is now rechecked before every network submission and unsent
queue files are preserved when it is disabled.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(zcode): claim worker requests atomically and scope them by endpoint

The force marker was read with exists() and removed with unlink(), so a
SessionStart contender that published worker.rerun and worker.force while a
force=False owner held the lock had its request deleted by a pass that never
saw it; the owner then delivered unforced and both markers were gone. Requests
are now consumed by one atomic rename that returns whether this pass owns the
force request, so a marker published after that step stays on disk for the
next pass.

worker.lock, worker.rerun and worker.force lived in the shared data directory
while the queues are endpoint-scoped. An old-endpoint worker awaiting its
acknowledgement therefore blocked a worker for a newly configured endpoint and
then consumed its request while rescanning only the old queue. Scheduling
state now lives under workers/<endpoint digest>, beside the queue it serves,
so each endpoint's request reaches a worker that scans that endpoint.

validate_config resolved the default Asia/Shanghai without checking whether an
IANA database exists, so a Windows host without tzdata failed with "timezone
must be an IANA timezone". Missing timezone data and an invalid key now report
different errors, and the setup docs install tzdata on Windows and state what a
missing database logs.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* style(zcode): satisfy pre-commit on the timezone and endpoint tests

Add the trailing comma add-trailing-comma expects in the missing-timezone-data
error and rename the unused call() argument in the endpoint-switch regression
test, so Pre-commit stays green without touching behavior.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-25 11:21:28 +08:00

239 lines
12 KiB
JavaScript

import assert from "node:assert/strict";
import { access, readFile } from "node:fs/promises";
import path from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import { runInNewContext } from "node:vm";
import { parse as parseYaml } from "yaml";
import { legacyRoutes } from "../../docs/.vitepress/legacy-routes.mjs";
const siteDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const repoDir = path.resolve(siteDir, "..");
const generatedDir = path.join(siteDir, ".generated", "site");
test("generates every required bilingual guide", async () => {
const names = [
"overview.md",
"configuration.md",
"services.md",
"docker.md",
"operations.md",
"integrations.md",
"plugin_development.md",
"faq.md",
"reference/cli.md",
"reference/jobs.md",
"benchmarks/memlens.md",
"benchmarks/mobilemem.md",
];
for (const language of ["zh", "en"]) {
for (const name of names) await access(path.join(generatedDir, language, name));
}
await access(path.join(generatedDir, "zh/integrations/claude-code.md"));
await access(path.join(generatedDir, "en/integrations/claude-code.md"));
await access(path.join(generatedDir, "en/integrations/codex.md"));
await access(path.join(generatedDir, "zh/integrations/codex.md"));
await access(path.join(generatedDir, "en/integrations/qoder.md"));
await access(path.join(generatedDir, "zh/integrations/qoder.md"));
await access(path.join(generatedDir, "en/integrations/zcode.md"));
await access(path.join(generatedDir, "zh/integrations/zcode.md"));
await access(path.join(generatedDir, "zh/integrations/hermes.md"));
await access(path.join(generatedDir, "en/integrations/hermes.md"));
await access(path.join(generatedDir, "zh/integrations/dsh.md"));
await access(path.join(generatedDir, "en/integrations/dsh.md"));
await access(path.join(generatedDir, "zh/integrations/openclaw.md"));
await access(path.join(generatedDir, "en/integrations/openclaw.md"));
await access(path.join(generatedDir, "public/figures/dsh/reme-status-overview.png"));
for (const name of ["qwenpaw.png", "deepseek-harness.svg", "openclaw.svg", "claude-code.png", "hermes.svg", "zvec.ico", "faiss.png"]) {
await access(path.join(generatedDir, "public/ecosystem", name));
}
});
test("maps mirrored pages back to their canonical repository sources", async () => {
const sourceMap = JSON.parse(await readFile(path.join(generatedDir, ".source-map.json"), "utf8"));
assert.equal(sourceMap["zh/overview.md"], "README_ZH.md");
assert.equal(sourceMap["en/overview.md"], "README.md");
assert.equal(sourceMap["en/integrations/dsh.md"], "integrations/dsh/README.md");
assert.equal(sourceMap["zh/integrations/openclaw.md"], "integrations/openclaw/README_ZH.md");
assert.equal(sourceMap["en/integrations/claude-code.md"], "integrations/claude_code/README.md");
assert.equal(sourceMap["zh/integrations/claude-code.md"], "integrations/claude_code/README_ZH.md");
assert.equal(sourceMap["en/integrations/codex.md"], "integrations/codex/README.md");
assert.equal(sourceMap["zh/integrations/codex.md"], "integrations/codex/README_ZH.md");
assert.equal(sourceMap["en/integrations/qoder.md"], "integrations/qoder/README.md");
assert.equal(sourceMap["zh/integrations/qoder.md"], "integrations/qoder/README_ZH.md");
assert.equal(sourceMap["en/integrations/zcode.md"], "integrations/zcode/README.md");
assert.equal(sourceMap["zh/integrations/zcode.md"], "integrations/zcode/README_ZH.md");
assert.equal(sourceMap["en/integrations/hermes.md"], "integrations/hermes_agent/README.md");
assert.equal(sourceMap["zh/plugins/lme.md"], "plugins/lme/README_ZH.md");
assert.equal(sourceMap["en/reference/jobs.md"], "reme/config/default.yaml");
for (const language of ["zh", "en"]) {
for (const benchmark of ["memlens", "mobilemem"]) {
assert.equal(
sourceMap[`${language}/benchmarks/${benchmark}.md`],
`benchmark/${benchmark}/docs/${language}/evaluation.md`,
);
}
}
});
test("preserves legacy MemLens addresses and anchors with a generated redirect", async () => {
for (const language of ["zh", "en"]) {
const legacy = await readFile(path.join(generatedDir, language, "memlens_256k_evaluation.md"), "utf8");
const frontmatter = parseYaml(legacy.split("---")[1]);
assert.deepEqual(frontmatter.head[0], ["meta", { name: "robots", content: "noindex" }]);
assert.match(legacy, /\[MemLens-256K\]\(\.\/benchmarks\/memlens\.md\)/);
let destination;
runInNewContext(frontmatter.head[1][2], {
window: { location: { hash: "#evaluation-settings", replace: (value) => { destination = value; } } },
});
for (const base of ["/", "/ReMe/"]) {
for (const extension of ["", ".html"]) {
const oldUrl = `https://reme-docs.local${base}${language}/memlens_256k_evaluation${extension}`;
const target = new URL(destination, oldUrl);
assert.equal(target.pathname, `${base}${language}/benchmarks/memlens`);
assert.equal(target.hash, "#evaluation-settings");
}
}
}
});
test("publishes the canonical benchmark chart for both blog languages", async () => {
const name = "memlens-256k-four-models-judge.svg";
const source = await readFile(path.join(repoDir, "benchmark/memlens/docs/figure", name), "utf8");
const published = await readFile(path.join(generatedDir, "public/figures/benchmarks/memlens", name), "utf8");
assert.equal(published, source);
});
test("publishes the root READMEs as localized project overviews", async () => {
const english = await readFile(path.join(generatedDir, "en/overview.md"), "utf8");
const chinese = await readFile(path.join(generatedDir, "zh/overview.md"), "utf8");
assert.match(english, /^---\ntitle: ReMe Overview/m);
assert.match(chinese, /^---\ntitle: ReMe 项目介绍/m);
assert.match(english, /href="\/zh\/overview"/);
assert.match(chinese, /href="\/en\/overview"/);
assert.match(english, /https:\/\/reme\.agentscope\.io\/en\/blog_20260920/);
assert.doesNotMatch(english, /https:\/\/reme\.agentscope\.io\/zh\/blog_20260920/);
assert.match(chinese, /https:\/\/reme\.agentscope\.io\/zh\/blog_20260920/);
assert.match(english, /\[ReMe Memory Tags\]/);
assert.match(chinese, /\[给记忆加上“标签”\]/);
assert.match(english, /src="\.\.\/figure\/design-philosophy\.svg"/);
assert.match(english, /\(https:\/\/reme\.agentscope\.io\/en\/memory_search\)/);
assert.match(chinese, /\(https:\/\/reme\.agentscope\.io\/zh\/memory_search\)/);
});
test("publishes portable and accurate DSH instructions", async () => {
const english = await readFile(path.join(generatedDir, "en/integrations/dsh.md"), "utf8");
const chinese = await readFile(path.join(generatedDir, "zh/integrations/dsh.md"), "utf8");
assert.doesNotMatch(english, /\/Users\//);
assert.doesNotMatch(chinese, /\/Users\//);
assert.match(english, /runtime counters refresh every 5 seconds/);
assert.match(chinese, /每 5 秒仅刷新 DSH 插件的运行时计数/);
});
test("keeps Claude Code language switches on the documentation site", async () => {
const english = await readFile(path.join(generatedDir, "en/integrations/claude-code.md"), "utf8");
const chinese = await readFile(path.join(generatedDir, "zh/integrations/claude-code.md"), "utf8");
assert.match(english, /\[中文说明\]\(\/zh\/integrations\/claude-code\)/);
assert.match(chinese, /\[English\]\(\/en\/integrations\/claude-code\)/);
assert.doesNotMatch(english, /\]\([^)]*README_ZH\.md\)/);
assert.doesNotMatch(chinese, /\]\([^)]*README\.md\)/);
});
test("keeps Qoder language switches on the documentation site", async () => {
const english = await readFile(path.join(generatedDir, "en/integrations/qoder.md"), "utf8");
const chinese = await readFile(path.join(generatedDir, "zh/integrations/qoder.md"), "utf8");
assert.match(english, /\[中文说明\]\(\/zh\/integrations\/qoder\)/);
assert.match(chinese, /\[English\]\(\/en\/integrations\/qoder\)/);
assert.doesNotMatch(english, /\]\([^)]*README_ZH\.md\)/);
assert.doesNotMatch(chinese, /\]\([^)]*README\.md\)/);
});
test("keeps ZCode language switches on the documentation site", async () => {
const english = await readFile(path.join(generatedDir, "en/integrations/zcode.md"), "utf8");
const chinese = await readFile(path.join(generatedDir, "zh/integrations/zcode.md"), "utf8");
assert.match(english, /\[中文说明\]\(\/zh\/integrations\/zcode\)/);
assert.match(chinese, /\[English\]\(\/en\/integrations\/zcode\)/);
assert.doesNotMatch(english, /\]\([^)]*README_ZH\.md\)/);
assert.doesNotMatch(chinese, /\]\([^)]*README\.md\)/);
});
test("publishes OpenClaw and Hermes integration figures with site-safe links", async () => {
for (const [page, integration] of [
["en/integrations/openclaw.md", "openclaw"],
["zh/integrations/openclaw.md", "openclaw"],
["en/integrations/hermes.md", "hermes"],
]) {
const content = await readFile(path.join(generatedDir, page), "utf8");
const images = [...content.matchAll(/!\[[^\]]*\]\(([^)]+)\)/g)];
assert.ok(images.length, `${page}: screenshots must exist`);
for (const [, source] of images) {
assert.ok(source.startsWith(`/figures/${integration}/`), `${page}: ${source}`);
await access(path.join(generatedDir, "public", source.slice(1)));
}
}
const hermesEnglish = await readFile(path.join(generatedDir, "en/integrations/hermes.md"), "utf8");
assert.match(hermesEnglish, /\(\/zh\/integrations\/hermes\)/);
});
test("generates the callable Job reference from default.yaml", async () => {
const config = parseYaml(await readFile(path.join(repoDir, "reme/config/default.yaml"), "utf8"));
const callableJobs = Object.entries(config.jobs)
.filter(([, job]) => !["background", "cron"].includes(job.backend))
.map(([name]) => name);
for (const language of ["zh", "en"]) {
const reference = await readFile(path.join(generatedDir, language, "reference", "jobs.md"), "utf8");
for (const job of callableJobs) assert.ok(reference.includes(`### ${"`"}${job}${"`"}`), job);
}
});
test("keeps generated content disposable and excludes internal plans", async () => {
await assert.rejects(access(path.join(generatedDir, "plans")));
await access(path.join(generatedDir, ".vitepress", "config.mts"));
await access(path.join(generatedDir, "public", "reme-icon.svg"));
await access(path.join(generatedDir, "public", "reme-logo.svg"));
assert.equal(
(await readFile(path.join(generatedDir, "public", "CNAME"), "utf8")).trim(),
"reme.agentscope.io",
);
});
test("maps every legacy query-string document ID to a generated page", async () => {
assert.equal(legacyRoutes["en-quick_start"], "/en/quick_start");
assert.equal(legacyRoutes["agents-guide"], "https://github.com/agentscope-ai/ReMe/blob/main/AGENTS.md");
for (const [id, route] of Object.entries(legacyRoutes)) {
if (route.startsWith("https://")) continue;
assert.match(route, /^\/(?:zh|en)\//, id);
const relative = route.endsWith("/") ? `${route.slice(1)}index.md` : `${route.slice(1)}.md`;
await access(path.join(generatedDir, relative));
}
});
test("tracks every generated input in documentation CI and deployment", async () => {
const requiredPaths = [
"reme/config/default.yaml",
"integrations/claude_code/README.md",
"integrations/claude_code/README_ZH.md",
"integrations/codex/README.md",
"integrations/codex/README_ZH.md",
"integrations/codex/figures/**",
"integrations/qoder/README.md",
"integrations/qoder/README_ZH.md",
"integrations/zcode/README.md",
"integrations/zcode/README_ZH.md",
"integrations/hermes_agent/README.md",
"integrations/hermes_agent/figures/**",
"integrations/dsh/README*.md",
"integrations/dsh/figures/**",
"integrations/openclaw/README*.md",
"integrations/openclaw/figures/**",
"benchmark/toolmemory/gitcha.png",
"benchmark/memlens/docs/**",
"benchmark/mobilemem/docs/**",
];
for (const workflow of ["ci-docs.yml", "deploy-docs.yml"]) {
const source = await readFile(path.join(repoDir, ".github/workflows", workflow), "utf8");
for (const requiredPath of requiredPaths) assert.ok(source.includes(requiredPath), `${workflow}: ${requiredPath}`);
}
});