chore: checkpoint turso and ai runtime work

This commit is contained in:
Agent Board
2026-07-03 23:20:16 +08:00
parent a75b3d11f9
commit 36d027a4a1
67 changed files with 4224 additions and 914 deletions
+72 -3
View File
@@ -3,9 +3,11 @@ const { spawn } = require("node:child_process");
const net = require("node:net");
const { test } = require("node:test");
const {
buildDefaultOpencodeCommand,
buildDefaultOpenHubCommand,
resolveBackendExecutable,
ensurePortFree,
isHttpHealthy,
isPortFree,
resolveOpenHubHealthPlan,
resolveRuntimePlan,
@@ -129,12 +131,48 @@ test("默认热启动计划只使用 mnote-web 作为 3000 owner", () => {
assert.deepEqual(plan.mnoteWebEnv, {
MNOTE_WEB_BIND: "0.0.0.0:3000",
MNOTE_WEB_PUBLIC_BIND: "127.0.0.1:3000",
MNOTE_KNOWLEDGE_PROVIDER: "lightrag_legacy",
MNOTE_OPENCODE_BASE_URL: "http://127.0.0.1:4096",
MNOTE_OPENHUB_BASE_URL: "http://127.0.0.1:18080",
MNOTE_OPENHUB_DISABLE_GIT_SNAPSHOT_RESTORE: "1",
MNOTE_CONTROL_PLANE_BACKEND: "libsql-local",
MNOTE_TURSO_LOCAL_PATH: "/mnt/Data1T/Mnote_data/control-plane/control-plane-libsql.db",
});
});
test("热启动计划支持 libSQL local 控制面后端", () => {
const plan = resolveRuntimePlan({
FRONTEND_PORT: "3000",
MNOTE_CONTROL_PLANE_BACKEND: "libsql-local",
});
assert.equal(plan.mnoteWebEnv.MNOTE_CONTROL_PLANE_BACKEND, "libsql-local");
assert.equal(
plan.mnoteWebEnv.MNOTE_TURSO_LOCAL_PATH,
"/mnt/Data1T/Mnote_data/control-plane/control-plane-libsql.db",
);
assert.equal(plan.mnoteWebEnv.MNOTE_CONTROL_PLANE_DB_PATH, undefined);
});
test("热启动计划拒绝 SQLite runtime fallback", () => {
assert.throws(
() => resolveRuntimePlan({
FRONTEND_PORT: "3000",
MNOTE_CONTROL_PLANE_BACKEND: "sqlite",
}),
/不再支持 SQLite control-plane fallback/,
);
});
test("显式配置知识库 provider 时透传给 MNote host", () => {
const plan = resolveRuntimePlan({
FRONTEND_PORT: "3000",
MNOTE_KNOWLEDGE_PROVIDER: "weknora",
});
assert.equal(plan.mnoteWebEnv.MNOTE_KNOWLEDGE_PROVIDER, "weknora");
});
test("默认跳过 FastAPI 后端,只有显式开启时才启动", () => {
assert.equal(shouldStartBackend({}), false);
assert.equal(shouldStartBackend({ ENABLE_BACKEND: "1" }), true);
@@ -161,7 +199,7 @@ test("OpenHub health plan 包含 FastAPI、Redis、opencode 和默认关闭 Git
});
assert.equal(plan.enabled, true);
assert.equal(plan.openhub.url, "http://127.0.0.1:18081/health");
assert.equal(plan.openhub.url, "http://127.0.0.1:18081/api/health");
assert.equal(plan.openhub.required, true);
assert.equal(plan.redis.url, "http://127.0.0.1:6379/health");
assert.equal(plan.redis.skipped, false);
@@ -175,7 +213,38 @@ test("OpenHub health plan 包含 FastAPI、Redis、opencode 和默认关闭 Git
test("OpenHub 默认命令只启动 FastAPI,不包含 snapshot/restore 写操作", () => {
const command = buildDefaultOpenHubCommand(18082);
assert.match(command, /uvicorn app\.main:app/);
assert.match(command, /app\.main:app/);
assert.match(command, /--host "?0\.0\.0\.0"?/);
assert.match(command, /--port 18082/);
assert.doesNotMatch(command, /snapshot|restore|revert|kill-port/i);
assert.match(command, /\/mnt\/Data1T\/Mnote_data\/openhub\/OpenHub\/smart-query-backend/);
assert.match(command, /MNOTE_OPENHUB_DISABLE_GIT_SNAPSHOT_RESTORE="1"/);
assert.doesNotMatch(command, /git\s+(snapshot|restore|revert)|kill-port/i);
});
test("opencode 默认命令使用 OpenHub 专用运行目录", () => {
const command = buildDefaultOpencodeCommand(18085);
assert.match(command, /\/mnt\/Data1T\/Mnote_data\/openhub\/opencode-runtime/);
assert.match(command, /\/mnt\/Data1T\/Mnote_data\/openhub\/opencode-home/);
assert.match(command, /HOME=/);
assert.match(command, /XDG_CONFIG_HOME=/);
assert.doesNotMatch(command, /已检测到现有 opencode/);
assert.match(command, /opencode serve --hostname=127\.0\.0\.1 --port 18085 --print-logs/);
});
test("isHttpHealthy 只把 2xx HTTP health 视为可复用服务", async () => {
const server = net.createServer((socket) => {
socket.once("data", () => {
socket.end("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK");
});
});
await new Promise((resolve, reject) => {
server.listen(0, "127.0.0.1", resolve);
server.once("error", reject);
});
const { port } = server.address();
try {
assert.equal(await isHttpHealthy(`http://127.0.0.1:${port}/health`), true);
} finally {
server.close();
}
});