@sleep2agi/commhub-server 0.9.0-preview.8 → 0.9.0-preview.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -10
- package/bin/commhub.ts +92 -11
- package/package.json +5 -5
- package/src/ack-create-request-transport.test.ts +159 -0
- package/src/ack-create-request.test.ts +5 -5
- package/src/admin-delete-network-http.test.ts +228 -0
- package/src/admin-networks-http.test.ts +88 -0
- package/src/agent-access-batch.test.ts +210 -0
- package/src/agent-access.ts +478 -0
- package/src/agent-acl-groups-http.test.ts +247 -0
- package/src/agent-acl-http.test.ts +520 -0
- package/src/agent-acl-slice3-http.test.ts +267 -0
- package/src/agent-groups-perf.test.ts +190 -0
- package/src/alias-filter.test.ts +72 -0
- package/src/alias-filter.ts +32 -0
- package/src/api-host-supervisors-can-create-nodes.test.ts +350 -0
- package/src/api-host-supervisors-fallback.test.ts +271 -0
- package/src/api-nodes-shape.test.ts +26 -10
- package/src/auth-sessions-http.test.ts +250 -0
- package/src/auth-validate.test.ts +5 -1
- package/src/auth.ts +450 -31
- package/src/avatar-validate.test.ts +163 -0
- package/src/avatar-validate.ts +103 -0
- package/src/blocked-exit-on-reply.test.ts +122 -0
- package/src/boot-side-effect.test.ts +124 -0
- package/src/commhub-bin-args.test.ts +85 -0
- package/src/config-apply-sec1.test.ts +107 -0
- package/src/config-apply-validate.test.ts +92 -0
- package/src/config-apply-validate.ts +81 -3
- package/src/create-node-blocked-gate.test.ts +356 -0
- package/src/create-node-tool-schema.test.ts +39 -0
- package/src/create-node-validate.test.ts +89 -1
- package/src/create-node-validate.ts +89 -7
- package/src/create-node-workdir.test.ts +255 -0
- package/src/create-node.ts +46 -1
- package/src/dashboard-slash-routing-http.test.ts +107 -0
- package/src/db-adapter-guard.test.ts +148 -0
- package/src/db-adapter-translate.test.ts +128 -0
- package/src/db-adapter.ts +323 -87
- package/src/db-timestamp.test.ts +38 -0
- package/src/db-timestamp.ts +15 -0
- package/src/db.ts +805 -33
- package/src/delivered-without-push.test.ts +140 -0
- package/src/desktop-message-seam.test.ts +150 -0
- package/src/desktop-message.test.ts +368 -0
- package/src/dm-file-scope-http.test.ts +178 -0
- package/src/ext-token-shared.test.ts +60 -0
- package/src/ext-validation-regression.test.ts +131 -0
- package/src/external-schedule-edits-http.test.ts +321 -0
- package/src/external-schedule-edits-timestamps.test.ts +64 -0
- package/src/external-schedule-edits.ts +327 -0
- package/src/file-download-authz-dev-open.test.ts +135 -0
- package/src/file-download-authz.test.ts +404 -0
- package/src/file-download-date-bucket.test.ts +436 -0
- package/src/file-network-scope-dev-open.test.ts +97 -0
- package/src/file-network-scope.test.ts +732 -0
- package/src/health-redaction.test.ts +642 -0
- package/src/http-gzip.test.ts +94 -0
- package/src/http-gzip.ts +110 -0
- package/src/hub-timestamp.test.ts +38 -0
- package/src/hub-timestamp.ts +27 -0
- package/src/human-dm.ts +215 -0
- package/src/inbox-count-sse.test.ts +310 -0
- package/src/inbox-count.ts +29 -0
- package/src/index.ts +15 -2331
- package/src/lifecycle-guard.ts +50 -0
- package/src/mcp-route-label-http.test.ts +120 -0
- package/src/mcp-write-network-resolution.test.ts +429 -0
- package/src/member-audit-network-id-http.test.ts +93 -0
- package/src/member-presence-http.test.ts +206 -0
- package/src/messages-ack-by-agent-http.test.ts +142 -0
- package/src/migrate-sqlite-to-pg.test.ts +47 -0
- package/src/migrate-sqlite-to-pg.ts +263 -0
- package/src/network-name-http.test.ts +75 -0
- package/src/network-scope.ts +224 -0
- package/src/node-attrs-validate.ts +88 -0
- package/src/node-attrs.test.ts +217 -0
- package/src/node-create-request-status-http.test.ts +92 -0
- package/src/node-files-transport.test.ts +344 -0
- package/src/node-id-alias.test.ts +188 -0
- package/src/node-lifecycle-controllable.test.ts +64 -0
- package/src/node-lifecycle-controllable.ts +51 -0
- package/src/node-logs-transport.test.ts +263 -0
- package/src/node-request-retention.test.ts +281 -0
- package/src/node-request-retention.ts +120 -0
- package/src/node-skills-transport.test.ts +209 -0
- package/src/node-token-privilege-http.test.ts +149 -0
- package/src/observer-avatar-http.test.ts +429 -0
- package/src/observer-push.test.ts +252 -0
- package/src/package-version-consistency.test.ts +25 -0
- package/src/peer-reply-atomic.test.ts +455 -0
- package/src/peer-reply-capability.test.ts +70 -0
- package/src/pg-worker.ts +87 -0
- package/src/push.ts +284 -7
- package/src/redact-tokens.test.ts +65 -0
- package/src/redact-tokens.ts +40 -0
- package/src/rename.ts +7 -2
- package/src/reply-target-derivation.test.ts +96 -0
- package/src/report-status-host-schema.test.ts +211 -0
- package/src/report-status-resume-id-handover.test.ts +150 -0
- package/src/require-explicit-test-db.ts +9 -0
- package/src/requirement-events-http.test.ts +257 -0
- package/src/requirement-events.test.ts +45 -0
- package/src/requirement-events.ts +143 -0
- package/src/requirement-notify.ts +134 -0
- package/src/requirement-participant-notify-http.test.ts +309 -0
- package/src/requirement-tag-ops-http.test.ts +266 -0
- package/src/requirement-tags.ts +89 -0
- package/src/requirements-completed-at-migration.test.ts +70 -0
- package/src/requirements-etag-http.test.ts +91 -0
- package/src/requirements-http.test.ts +709 -0
- package/src/requirements-list-slim-http.test.ts +315 -0
- package/src/requirements-mcp.test.ts +163 -0
- package/src/requirements-migrate.ts +225 -0
- package/src/requirements-people-http.test.ts +114 -0
- package/src/requirements-priority-lowest.test.ts +114 -0
- package/src/requirements-search-http.test.ts +182 -0
- package/src/requirements-search.test.ts +32 -0
- package/src/requirements-search.ts +138 -0
- package/src/requirements-seq-http.test.ts +193 -0
- package/src/requirements-seq-migration.test.ts +63 -0
- package/src/requirements-start-date.test.ts +125 -0
- package/src/requirements-stats-http.test.ts +288 -0
- package/src/requirements-stats.ts +164 -0
- package/src/requirements-upgrade-e2e.test.ts +126 -0
- package/src/requirements-upgrade-migration.test.ts +98 -0
- package/src/requirements.ts +1439 -0
- package/src/resolve-port.test.ts +57 -0
- package/src/resolve-port.ts +44 -0
- package/src/response-charset.test.ts +130 -0
- package/src/rest-explicit-columns-http.test.ts +216 -0
- package/src/rest-identity.test.ts +129 -0
- package/src/rest-identity.ts +100 -0
- package/src/rest-projections.ts +68 -0
- package/src/rest-write-network-resolution.test.ts +133 -0
- package/src/restricted-files.ts +73 -0
- package/src/retention.ts +15 -3
- package/src/route-callers-http.test.ts +120 -0
- package/src/route-timing.test.ts +211 -0
- package/src/route-timing.ts +258 -0
- package/src/rules-file-duplicate-alias.test.ts +234 -0
- package/src/rules-file-session-target.test.ts +207 -0
- package/src/rules-file-transport.test.ts +237 -0
- package/src/runtime-label.test.ts +22 -0
- package/src/runtime-label.ts +21 -0
- package/src/scheduled-doorbell-nodeless-session.test.ts +130 -0
- package/src/scheduled-reply-unread-http.test.ts +212 -0
- package/src/scheduled-run-terminal.test.ts +268 -0
- package/src/scheduled-skip-blocking-task.test.ts +120 -0
- package/src/scheduled-tasks-http.test.ts +638 -0
- package/src/scheduled-tasks.ts +597 -0
- package/src/send-dedup-request-id.test.ts +229 -0
- package/src/send-reply-agent-warning.test.ts +202 -0
- package/src/send-reply-alias-optional.test.ts +131 -0
- package/src/send-reply-attachments.test.ts +458 -0
- package/src/send_dedup.test.ts +54 -0
- package/src/send_dedup.ts +52 -6
- package/src/serve-error.test.ts +38 -0
- package/src/serve-error.ts +27 -0
- package/src/server.ts +4522 -0
- package/src/shared/external-schedule-contract.ts +60 -0
- package/src/side-thread-command-transport.test.ts +312 -0
- package/src/side-thread-command-transport.ts +318 -0
- package/src/side-thread-http-integration.test.ts +233 -0
- package/src/side-thread-http.ts +504 -0
- package/src/side-thread-production.test.ts +72 -0
- package/src/side-thread-production.ts +118 -0
- package/src/side-thread.test.ts +1067 -0
- package/src/side-thread.ts +2499 -0
- package/src/skillhub-http.test.ts +108 -0
- package/src/sqlite-close-checkpoint.test.ts +78 -0
- package/src/start-node.test.ts +109 -0
- package/src/status-alias-filter-http.test.ts +106 -0
- package/src/status-node-id-filter-http.test.ts +161 -0
- package/src/stop-delete-node.test.ts +1164 -0
- package/src/task-access-http.test.ts +379 -0
- package/src/task-access.ts +307 -0
- package/src/task-auth-origin-http.test.ts +91 -0
- package/src/task-auth-origin.test.ts +24 -0
- package/src/task-auth-origin.ts +7 -0
- package/src/task-consumption.test.ts +482 -0
- package/src/task-diagnostic-http.test.ts +149 -0
- package/src/task-diagnostic.test.ts +115 -0
- package/src/task-diagnostic.ts +118 -0
- package/src/task-idempotency-mcp.test.ts +142 -0
- package/src/task-idempotency.test.ts +60 -0
- package/src/task-idempotency.ts +75 -0
- package/src/task-lifecycle-watcher.test.ts +204 -0
- package/src/task-lifecycle-watcher.ts +49 -0
- package/src/task-network-resolution-http.test.ts +141 -0
- package/src/tasks-pagination-http.test.ts +141 -0
- package/src/tools-list-json-schema.test.ts +66 -0
- package/src/tools.ts +3534 -343
- package/src/update-provider.test.ts +65 -0
- package/src/upload-early-reject-guard.test.ts +155 -0
- package/src/uploads-http.test.ts +97 -15
- package/src/uploads.test.ts +66 -0
- package/src/uploads.ts +138 -5
- package/src/user-inbox-by-agent-http.test.ts +161 -0
- package/src/user-inbox-netid-notnull.test.ts +122 -0
- package/src/user-inbox-read-http.test.ts +223 -0
- package/src/user-inbox-schema.test.ts +54 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// #1281 — 子节点生命周期工具的参数名统一(node_id ⇄ child_node_id)。
|
|
2
|
+
//
|
|
3
|
+
// 分叉现状(origin/main 2976adb2):stop_node / start_node / delete_node 用
|
|
4
|
+
// `child_node_id`,restart_node / update_node_config 用 `node_id`,指向同一个
|
|
5
|
+
// 子节点。调用方按一个工具的习惯给另一个传就吃 -32602。修复:5 个工具都同时
|
|
6
|
+
// 接受两个名字(canonical = node_id,child_node_id 兼容 alias),解析收敛到一个
|
|
7
|
+
// 模块级 helper resolveNodeIdArg。
|
|
8
|
+
//
|
|
9
|
+
// 两向 witnessed-red(本文件即判据):
|
|
10
|
+
// · schema 层:每个工具的**历史用名**始终 parse 成功(证明没破已发布契约),
|
|
11
|
+
// **新增别名**在修复前 parse 失败(缺必填字段)、修复后成功。
|
|
12
|
+
// · handler 层:resolveNodeIdArg 纯函数 —— 二选一至少一必填、都传须相等。
|
|
13
|
+
// · 真实 handler 路径:stop_node 用 node_id / child_node_id 都能穿到
|
|
14
|
+
// resolveDaemonForChild(不再被 node_id_required 挡),都传冲突 → node_id_conflict。
|
|
15
|
+
//
|
|
16
|
+
// 对 pre-fix 见红的证明方式(评审可复现):把 tools.ts 里任一工具的
|
|
17
|
+
// `...NODE_ID_ALIAS_FIELDS` 还原成原来的单名字段(如 stop_node 的
|
|
18
|
+
// `child_node_id: z.string()...regex(...)`),本文件对应工具的「新增别名 parse 成功」
|
|
19
|
+
// 断言立即变红 —— 证明该断言有判别力,不是恒真。
|
|
20
|
+
|
|
21
|
+
import { describe, expect, test, beforeAll } from "bun:test";
|
|
22
|
+
import { mkdtempSync } from "fs";
|
|
23
|
+
import { join } from "path";
|
|
24
|
+
import { tmpdir } from "os";
|
|
25
|
+
|
|
26
|
+
process.env.COMMHUB_DB = process.env.COMMHUB_DB || (mkdtempSync(join(tmpdir(), "anet-1281-")) + "/commhub.db");
|
|
27
|
+
|
|
28
|
+
import { z } from "zod/v4";
|
|
29
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
30
|
+
import { registerTools, resolveNodeIdArg } from "./tools.js";
|
|
31
|
+
|
|
32
|
+
type ToolHandler = (args: any) => Promise<{ content: { type: "text"; text: string }[] }>;
|
|
33
|
+
|
|
34
|
+
// Capture BOTH the raw zod shape and the handler for every tool, so the
|
|
35
|
+
// schema-layer assertions run against the exact object server.tool received.
|
|
36
|
+
function buildCaptured() {
|
|
37
|
+
const schemas: Record<string, any> = {};
|
|
38
|
+
const handlers: Record<string, ToolHandler> = {};
|
|
39
|
+
const server = new McpServer({ name: "t1281", version: "0" }) as any;
|
|
40
|
+
const origTool = server.tool.bind(server);
|
|
41
|
+
server.tool = (name: string, _desc: string, schema: any, handler: ToolHandler) => {
|
|
42
|
+
schemas[name] = schema; handlers[name] = handler;
|
|
43
|
+
return origTool(name, _desc, schema, handler);
|
|
44
|
+
};
|
|
45
|
+
const origRegisterTool = server.registerTool?.bind(server);
|
|
46
|
+
if (origRegisterTool) {
|
|
47
|
+
server.registerTool = (name: string, cfg: any, handler: ToolHandler) => {
|
|
48
|
+
schemas[name] = cfg?.inputSchema ?? cfg; handlers[name] = handler;
|
|
49
|
+
return origRegisterTool(name, cfg, handler);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
registerTools(server, undefined, null, "user_1281", null, false, null);
|
|
53
|
+
return { schemas, handlers };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let SCHEMAS: Record<string, any> = {};
|
|
57
|
+
let HANDLERS: Record<string, ToolHandler> = {};
|
|
58
|
+
beforeAll(() => { const c = buildCaptured(); SCHEMAS = c.schemas; HANDLERS = c.handlers; });
|
|
59
|
+
|
|
60
|
+
async function call(name: string, args: any) {
|
|
61
|
+
const r = await HANDLERS[name](args);
|
|
62
|
+
return JSON.parse(r.content[0].text);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Per tool: the historically-required id name, the newly-added alias, and
|
|
66
|
+
// the OTHER required fields the shape needs so a safeParse isolates the id
|
|
67
|
+
// field rather than tripping on an unrelated missing field.
|
|
68
|
+
const TOOLS = [
|
|
69
|
+
{ name: "stop_node", historic: "child_node_id", added: "node_id", extra: {} },
|
|
70
|
+
{ name: "start_node", historic: "child_node_id", added: "node_id", extra: {} },
|
|
71
|
+
{ name: "delete_node", historic: "child_node_id", added: "node_id", extra: { confirm_alias: "some-alias" } },
|
|
72
|
+
{ name: "restart_node", historic: "node_id", added: "child_node_id", extra: {} },
|
|
73
|
+
{ name: "update_node_config", historic: "node_id", added: "child_node_id", extra: { base_revision: 0, patch: {} } },
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const VALID_ID = "node_test_1281";
|
|
77
|
+
|
|
78
|
+
describe("#1281 schema layer — every lifecycle tool accepts BOTH node_id and child_node_id", () => {
|
|
79
|
+
for (const t of TOOLS) {
|
|
80
|
+
test(`${t.name}: historic name '${t.historic}' still parses (published contract intact)`, () => {
|
|
81
|
+
const shape = z.object(SCHEMAS[t.name]);
|
|
82
|
+
const r = shape.safeParse({ [t.historic]: VALID_ID, ...t.extra });
|
|
83
|
+
expect(r.success).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test(`${t.name}: added alias '${t.added}' parses (was -32602 pre-#1281 → RED without the fix)`, () => {
|
|
87
|
+
const shape = z.object(SCHEMAS[t.name]);
|
|
88
|
+
const r = shape.safeParse({ [t.added]: VALID_ID, ...t.extra });
|
|
89
|
+
expect(r.success).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test(`${t.name}: both names present + equal parses (schema layer permissive; conflict caught in handler)`, () => {
|
|
93
|
+
const shape = z.object(SCHEMAS[t.name]);
|
|
94
|
+
const r = shape.safeParse({ node_id: VALID_ID, child_node_id: VALID_ID, ...t.extra });
|
|
95
|
+
expect(r.success).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("#1281 resolveNodeIdArg — the single resolution helper", () => {
|
|
101
|
+
test("node_id only → resolves to node_id", () => {
|
|
102
|
+
expect(resolveNodeIdArg({ node_id: "node_a" })).toEqual({ ok: true, node_id: "node_a" });
|
|
103
|
+
});
|
|
104
|
+
test("child_node_id only → resolves to it (back-compat)", () => {
|
|
105
|
+
expect(resolveNodeIdArg({ child_node_id: "node_b" })).toEqual({ ok: true, node_id: "node_b" });
|
|
106
|
+
});
|
|
107
|
+
test("both present + EQUAL → resolves (no conflict)", () => {
|
|
108
|
+
expect(resolveNodeIdArg({ node_id: "node_c", child_node_id: "node_c" })).toEqual({ ok: true, node_id: "node_c" });
|
|
109
|
+
});
|
|
110
|
+
test("both present + DIFFERENT → node_id_conflict (catches A/B fat-finger)", () => {
|
|
111
|
+
const r = resolveNodeIdArg({ node_id: "node_a", child_node_id: "node_b" });
|
|
112
|
+
expect(r.ok).toBe(false);
|
|
113
|
+
expect((r as any).error).toBe("node_id_conflict");
|
|
114
|
+
});
|
|
115
|
+
test("neither present → node_id_required", () => {
|
|
116
|
+
const r = resolveNodeIdArg({});
|
|
117
|
+
expect(r.ok).toBe(false);
|
|
118
|
+
expect((r as any).error).toBe("node_id_required");
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("#1281 real handler path — stop_node routes both names to the same place", () => {
|
|
123
|
+
// stop_node calls resolveNodeIdArg FIRST, then resolveDaemonForChild. A
|
|
124
|
+
// fabricated id has no create-request row → daemon_not_resolvable. The
|
|
125
|
+
// point is that BOTH names get PAST the id gate to that same downstream
|
|
126
|
+
// error (proving the alias flows through), and the two error branches fire.
|
|
127
|
+
test("node_id (new name) flows through → daemon_not_resolvable, NOT node_id_required", async () => {
|
|
128
|
+
const r = await call("stop_node", { node_id: VALID_ID });
|
|
129
|
+
expect(r.ok).toBe(false);
|
|
130
|
+
expect(r.error).toBe("daemon_not_resolvable");
|
|
131
|
+
});
|
|
132
|
+
test("child_node_id (old name) flows through → daemon_not_resolvable (back-compat intact)", async () => {
|
|
133
|
+
const r = await call("stop_node", { child_node_id: VALID_ID });
|
|
134
|
+
expect(r.ok).toBe(false);
|
|
135
|
+
expect(r.error).toBe("daemon_not_resolvable");
|
|
136
|
+
});
|
|
137
|
+
test("neither → node_id_required (before any daemon resolution)", async () => {
|
|
138
|
+
const r = await call("stop_node", { force: true });
|
|
139
|
+
expect(r.ok).toBe(false);
|
|
140
|
+
expect(r.error).toBe("node_id_required");
|
|
141
|
+
});
|
|
142
|
+
test("both differ → node_id_conflict (before any daemon resolution)", async () => {
|
|
143
|
+
const r = await call("stop_node", { node_id: "node_a", child_node_id: "node_b" });
|
|
144
|
+
expect(r.ok).toBe(false);
|
|
145
|
+
expect(r.error).toBe("node_id_conflict");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("app#196 —— 「解析不到 daemon」的两种情况必须给不同的话", () => {
|
|
150
|
+
// 🔴 生产实测(2026-08-28):218 个节点里 207 个是 `n_…`(有人直接
|
|
151
|
+
// `anet node start` 起的),它们**根本没有 daemon**。原先这两种情况
|
|
152
|
+
// 打印同一句 `pass daemon_node_id explicitly` —— 对那 207 个来说,
|
|
153
|
+
// **这句建议的前提是假的**,照着做只会走进死路。
|
|
154
|
+
const HAND_STARTED = "n_73687f17"; // 手工起的节点,真实形状
|
|
155
|
+
const DAEMON_CHILD = "node_test_1281"; // daemon 建的子节点
|
|
156
|
+
|
|
157
|
+
test("手工起的节点 → not_daemon_managed,并且**不**建议传 daemon_node_id", async () => {
|
|
158
|
+
const r = await call("stop_node", { node_id: HAND_STARTED });
|
|
159
|
+
expect(r.ok).toBe(false);
|
|
160
|
+
expect(r.error).toBe("not_daemon_managed");
|
|
161
|
+
// 🔴 这一条是本组的核心:旧文案的那句建议**不能**再出现在这条路径上。
|
|
162
|
+
expect(r.message).not.toContain("pass daemon_node_id explicitly");
|
|
163
|
+
// 而且要告诉他真正能走的那条路。
|
|
164
|
+
expect(r.message).toContain("anet node stop");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("daemon 建的子节点(无 create-request 行) → 仍是 daemon_not_resolvable", async () => {
|
|
168
|
+
const r = await call("stop_node", { node_id: DAEMON_CHILD });
|
|
169
|
+
expect(r.ok).toBe(false);
|
|
170
|
+
expect(r.error).toBe("daemon_not_resolvable");
|
|
171
|
+
expect(r.message).toContain("pass daemon_node_id explicitly");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("delete_node 走同一条判别(两个调用点不能只改一个)", async () => {
|
|
175
|
+
const r = await call("delete_node", { node_id: HAND_STARTED, confirm_alias: "x" });
|
|
176
|
+
expect(r.ok).toBe(false);
|
|
177
|
+
expect(r.error).toBe("not_daemon_managed");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// 🔴 反向见证:两种情况必须**真的不同**。若有人把判别改成恒定一支,
|
|
181
|
+
// 上面三条里至少一条会红 —— 但那还不够明显,所以这里直接断言两者不等。
|
|
182
|
+
test("两种情况的 error 与 message 都不相同", async () => {
|
|
183
|
+
const a = await call("stop_node", { node_id: HAND_STARTED });
|
|
184
|
+
const b = await call("stop_node", { node_id: DAEMON_CHILD });
|
|
185
|
+
expect(a.error).not.toBe(b.error);
|
|
186
|
+
expect(a.message).not.toBe(b.message);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
childNodeIdForCreateRequest,
|
|
4
|
+
buildControllableMap,
|
|
5
|
+
isLifecycleControllable,
|
|
6
|
+
} from "./node-lifecycle-controllable.js";
|
|
7
|
+
|
|
8
|
+
// app#196 —— 桌面端对 218 个节点里的 207 个(95%)显示了「停止/重启/删除」,
|
|
9
|
+
// 而那三个工具的 schema 是 regex(/^node_[a-z0-9_-]+$/),那 207 个是 n_ 开头,
|
|
10
|
+
// 点下去只会看到一段 zod 正则原文。
|
|
11
|
+
describe("childNodeIdForCreateRequest —— 推导规则", () => {
|
|
12
|
+
test("cr_ 前缀 → node_ 前缀,其余部分逐字保留", () => {
|
|
13
|
+
// 🔴 这一对是 2026-08-28 生产 hub 日志里真实的 create-node finalize 行,
|
|
14
|
+
// 不是我按注释造的。
|
|
15
|
+
expect(childNodeIdForCreateRequest("cr_59723b24-8372-4270-9b3c-1552e592a09f"))
|
|
16
|
+
.toBe("node_59723b24-8372-4270-9b3c-1552e592a09f");
|
|
17
|
+
});
|
|
18
|
+
test("不是 cr_ 开头的一律 null —— 不猜、不截断", () => {
|
|
19
|
+
expect(childNodeIdForCreateRequest("node_abc")).toBeNull();
|
|
20
|
+
expect(childNodeIdForCreateRequest("n_abc")).toBeNull();
|
|
21
|
+
expect(childNodeIdForCreateRequest("abc")).toBeNull();
|
|
22
|
+
expect(childNodeIdForCreateRequest("cr_")).toBeNull(); // 只有前缀,没有主体
|
|
23
|
+
});
|
|
24
|
+
test("非字符串输入不抛,返回 null", () => {
|
|
25
|
+
for (const v of [undefined, null, 123, {}, []]) {
|
|
26
|
+
expect(childNodeIdForCreateRequest(v as any)).toBeNull();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("isLifecycleControllable —— 判据不是 id 前缀", () => {
|
|
32
|
+
const map = buildControllableMap([
|
|
33
|
+
{ request_id: "cr_aaa", daemon_node_id: "node_daemon_x" },
|
|
34
|
+
{ request_id: "cr_bbb", daemon_node_id: "node_daemon_y" },
|
|
35
|
+
{ request_id: "not-a-request", daemon_node_id: "node_daemon_z" }, // 应被丢弃
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
test("有创建记录的 → 可控", () => {
|
|
39
|
+
expect(isLifecycleControllable("node_aaa", null, map)).toBe(true);
|
|
40
|
+
expect(map.get("node_aaa")).toBe("node_daemon_x");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("🔴 光有 node_ 前缀但没有创建记录 → 不可控", () => {
|
|
44
|
+
// 这条是本模块存在的理由:前缀是实现细节,不是判据。
|
|
45
|
+
expect(isLifecycleControllable("node_never_created", null, map)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("手工起的 n_ 节点 → 不可控(那 207 个)", () => {
|
|
49
|
+
expect(isLifecycleControllable("n_22b777bf", null, map)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("🔴 daemon 自己可控 —— 它在 node_create_requests 里没有记录", () => {
|
|
53
|
+
// 漏掉这条会把 3 个 daemon 从可控名单里误删。
|
|
54
|
+
expect(isLifecycleControllable("node_daemon_39bd1eeae3ee", "host_supervisor", map)).toBe(true);
|
|
55
|
+
// 正控:同一个 id 但 role 不是 host_supervisor ⇒ 仍不可控,
|
|
56
|
+
// 证明上面那条过是因为 role,不是因为 id 恰好带 node_ 前缀。
|
|
57
|
+
expect(isLifecycleControllable("node_daemon_39bd1eeae3ee", null, map)).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("坏的 request_id 不会污染映射", () => {
|
|
61
|
+
expect(map.has("node_not-a-request")).toBe(false);
|
|
62
|
+
expect(map.size).toBe(2);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* app#196 —— 哪些节点能走 stop_node / restart_node / delete_node。
|
|
3
|
+
*
|
|
4
|
+
* 抽成独立模块而不是写在 /api/nodes 的路由里,因为路由里的内联逻辑测不到 ——
|
|
5
|
+
* 现有的 api-nodes-shape.test.ts 是直跑 handler 的 SQL,拿不到映射步骤。
|
|
6
|
+
* 🔴 「不可测」本身就是一个设计信号,不是测试的问题。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** 子节点 id 由创建请求 id 确定性推导。
|
|
10
|
+
*
|
|
11
|
+
* 🔴 这条规则我用真实一对验过,不是只读注释:
|
|
12
|
+
* cr_59723b24-8372-4270-9b3c-1552e592a09f → node_59723b24-8372-4270-9b3c-…
|
|
13
|
+
* (2026-08-28 生产 hub 日志的 `create-node finalize` 行)
|
|
14
|
+
*
|
|
15
|
+
* 非 `cr_` 开头的一律返回 null —— 不猜,不截断。 */
|
|
16
|
+
export function childNodeIdForCreateRequest(requestId: unknown): string | null {
|
|
17
|
+
if (typeof requestId !== "string") return null;
|
|
18
|
+
if (!requestId.startsWith("cr_")) return null;
|
|
19
|
+
const rest = requestId.slice(3);
|
|
20
|
+
if (!rest) return null;
|
|
21
|
+
return `node_${rest}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 由创建记录建出「child node_id → daemon node_id」的映射。 */
|
|
25
|
+
export function buildControllableMap(
|
|
26
|
+
createRequests: Array<{ request_id?: unknown; daemon_node_id?: unknown }>,
|
|
27
|
+
): Map<string, string> {
|
|
28
|
+
const m = new Map<string, string>();
|
|
29
|
+
for (const cr of createRequests) {
|
|
30
|
+
const child = childNodeIdForCreateRequest(cr?.request_id);
|
|
31
|
+
if (!child) continue;
|
|
32
|
+
m.set(child, typeof cr?.daemon_node_id === "string" ? cr.daemon_node_id : "");
|
|
33
|
+
}
|
|
34
|
+
return m;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 一个节点能不能走生命周期操作。
|
|
38
|
+
*
|
|
39
|
+
* 🔴 判据**不是 id 前缀**。前缀是实现细节;判据是 node_create_requests 里真有创建记录。
|
|
40
|
+
*
|
|
41
|
+
* 例外:daemon 自己(role=host_supervisor)也能被 restart/stop,而它在
|
|
42
|
+
* node_create_requests 里**没有**记录(它不是被别的 daemon 创建的)—— 单独放行。
|
|
43
|
+
* 漏掉这一条会把可控的 daemon 判成不可控。 */
|
|
44
|
+
export function isLifecycleControllable(
|
|
45
|
+
nodeId: unknown,
|
|
46
|
+
role: unknown,
|
|
47
|
+
controllable: Map<string, string>,
|
|
48
|
+
): boolean {
|
|
49
|
+
if (role === "host_supervisor") return true;
|
|
50
|
+
return typeof nodeId === "string" && controllable.has(nodeId);
|
|
51
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// Node run-log view — tail_node_logs rides the rules-file queue + doorbell (op logs_tail).
|
|
2
|
+
//
|
|
3
|
+
// Hub-side contract verified here:
|
|
4
|
+
// 1. report_status { logs_capable: true } is sticky and set only by the node's
|
|
5
|
+
// own token; /api/status-shaped rows expose it.
|
|
6
|
+
// 2. The pulled request carries only the normalised filter JSON — no path field
|
|
7
|
+
// exists anywhere in the tool schema; unknown args are dropped.
|
|
8
|
+
// 3. Who may ask: user logins only (node tokens refused); the network owner/admin,
|
|
9
|
+
// or the node's owner (nodes.owner_user_id). A member who does not own the
|
|
10
|
+
// node, a viewer, and a user of another network are refused before any row.
|
|
11
|
+
// 4. Who may read: only the token that asked (like the project folder).
|
|
12
|
+
// 5. Storage: the result is handed out ONCE — the first terminal read purges
|
|
13
|
+
// result_content and the filter JSON; the second read says content_purged.
|
|
14
|
+
// An unread terminal result is purged by the sweep after LOGS_CONTENT_TTL_MS.
|
|
15
|
+
// 6. Own single-flight lane; logs acks may carry up to 1 MiB.
|
|
16
|
+
//
|
|
17
|
+
// 跑法:cd server && COMMHUB_DB=/tmp/logs-transport.db bun test src/node-logs-transport.test.ts
|
|
18
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
19
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
20
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
21
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
22
|
+
import { db } from "./db.js";
|
|
23
|
+
import { registerTools } from "./tools.js";
|
|
24
|
+
import { LOGS_CONTENT_TTL_MS, sweepNodeRequestContent } from "./node-request-retention.js";
|
|
25
|
+
|
|
26
|
+
const NET = "net_logs_t";
|
|
27
|
+
const OTHER_NET = "net_logs_t_other";
|
|
28
|
+
const OWNER = "u_logs_net_owner";
|
|
29
|
+
const MEMBER = "u_logs_member_owns_a";
|
|
30
|
+
const MEMBER2 = "u_logs_member_plain";
|
|
31
|
+
const VIEWER = "u_logs_viewer";
|
|
32
|
+
const OUTSIDER = "u_logs_outsider";
|
|
33
|
+
const NODE_A = "logs-node-a";
|
|
34
|
+
const NODE_B = "logs-node-b";
|
|
35
|
+
const NODE_A_ID = "node_logs_a";
|
|
36
|
+
const NODE_B_ID = "node_logs_b";
|
|
37
|
+
const T_A = "tok_logs_node_a";
|
|
38
|
+
const T_B = "tok_logs_node_b";
|
|
39
|
+
|
|
40
|
+
function cleanup() {
|
|
41
|
+
for (const net of [NET, OTHER_NET]) {
|
|
42
|
+
for (const t of ["node_rules_requests", "sessions", "nodes", "api_tokens", "network_members", "networks"]) {
|
|
43
|
+
try { db.run(`DELETE FROM ${t} WHERE network_id = ?1`, [net]); } catch {}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const u of [OWNER, MEMBER, MEMBER2, VIEWER, OUTSIDER]) {
|
|
47
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [u]); } catch {}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function seedWorld() {
|
|
52
|
+
for (const u of [OWNER, MEMBER, MEMBER2, VIEWER, OUTSIDER]) {
|
|
53
|
+
db.run(`INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))`, [u, u]);
|
|
54
|
+
}
|
|
55
|
+
db.run(`INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?2, ?3, datetime('now'))`, [NET, NET, OWNER]);
|
|
56
|
+
db.run(`INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?2, ?3, datetime('now'))`, [OTHER_NET, OTHER_NET, OUTSIDER]);
|
|
57
|
+
const member = (u: string, net: string, role: string) =>
|
|
58
|
+
db.run(`INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, ?3, datetime('now'))`, [u, net, role]);
|
|
59
|
+
member(OWNER, NET, "owner");
|
|
60
|
+
member(MEMBER, NET, "member");
|
|
61
|
+
member(MEMBER2, NET, "member");
|
|
62
|
+
member(VIEWER, NET, "viewer");
|
|
63
|
+
member(OUTSIDER, OTHER_NET, "owner");
|
|
64
|
+
const node = (id: string, alias: string, owner: string | null) => db.run(
|
|
65
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, datetime('now'), datetime('now'))`,
|
|
66
|
+
[id, alias, alias, NET, owner],
|
|
67
|
+
);
|
|
68
|
+
node(NODE_A_ID, NODE_A, MEMBER);
|
|
69
|
+
node(NODE_B_ID, NODE_B, OWNER);
|
|
70
|
+
const tok = (id: string, alias: string, bound: string) => db.run(
|
|
71
|
+
`INSERT INTO api_tokens (token_id, user_id, network_id, scope, name, token_hash, expires_at, revoked_at, bound_node_id) VALUES (?1, ?2, ?3, 'network', ?4, ?5, NULL, NULL, ?6)`,
|
|
72
|
+
[id, OWNER, NET, `node:${alias}`, `hash_${id}`, bound],
|
|
73
|
+
);
|
|
74
|
+
tok(T_A, NODE_A, NODE_A_ID);
|
|
75
|
+
tok(T_B, NODE_B, NODE_B_ID);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type Identity = { net: string | null; user: string; alias: string; isNetworkToken: boolean; tokenId: string };
|
|
79
|
+
const asOwner: Identity = { net: null, user: OWNER, alias: OWNER, isNetworkToken: false, tokenId: "tok_logs_owner_login" };
|
|
80
|
+
const asOwnerOtherLogin: Identity = { ...asOwner, tokenId: "tok_logs_owner_login_2" };
|
|
81
|
+
const asMember: Identity = { net: null, user: MEMBER, alias: MEMBER, isNetworkToken: false, tokenId: "tok_logs_member_login" };
|
|
82
|
+
const asMember2: Identity = { net: null, user: MEMBER2, alias: MEMBER2, isNetworkToken: false, tokenId: "tok_logs_member2_login" };
|
|
83
|
+
const asViewer: Identity = { net: null, user: VIEWER, alias: VIEWER, isNetworkToken: false, tokenId: "tok_logs_viewer_login" };
|
|
84
|
+
const asOutsider: Identity = { net: null, user: OUTSIDER, alias: OUTSIDER, isNetworkToken: false, tokenId: "tok_logs_outsider_login" };
|
|
85
|
+
const asA: Identity = { net: NET, user: OWNER, alias: NODE_A, isNetworkToken: true, tokenId: T_A };
|
|
86
|
+
const asB: Identity = { net: NET, user: OWNER, alias: NODE_B, isNetworkToken: true, tokenId: T_B };
|
|
87
|
+
|
|
88
|
+
async function connect(id: Identity) {
|
|
89
|
+
const server = new McpServer({ name: "logs-test", version: "1" });
|
|
90
|
+
registerTools(server, undefined, id.net, id.user, id.alias, id.isNetworkToken, id.tokenId);
|
|
91
|
+
const client = new Client({ name: "logs-client", version: "1" });
|
|
92
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
93
|
+
await server.connect(st);
|
|
94
|
+
await client.connect(ct);
|
|
95
|
+
const call = async (name: string, args: Record<string, unknown>) => {
|
|
96
|
+
const r: any = await client.callTool({ name, arguments: args });
|
|
97
|
+
const first = r.content?.[0];
|
|
98
|
+
if (!first || first.type !== "text") throw new Error(`no text result from ${name}: ${JSON.stringify(r).slice(0, 300)}`);
|
|
99
|
+
try { return JSON.parse(first.text); } catch { return { raw: first.text, isError: r.isError === true }; }
|
|
100
|
+
};
|
|
101
|
+
const close = async () => { await client.close(); await server.close(); };
|
|
102
|
+
return { call, close };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const rowCount = () => db.get<{ n: number }>("SELECT COUNT(*) AS n FROM node_rules_requests WHERE network_id = ?1", NET)!.n;
|
|
106
|
+
const row = (id: string) => db.get<any>("SELECT op, content, result_content, content_purged_at FROM node_rules_requests WHERE request_id = ?1", id);
|
|
107
|
+
const SAMPLE = JSON.stringify({ files: ["2026-09-29.log"], lines: [{ ts: 1, level: "info", text: "[10:00:00] [INFO ] [x] hello", key: "2026-09-29.log:0" }], truncated: false, matched: 1, now_ts: 2 });
|
|
108
|
+
|
|
109
|
+
beforeEach(() => { cleanup(); seedWorld(); });
|
|
110
|
+
afterAll(cleanup);
|
|
111
|
+
|
|
112
|
+
describe("logs_capable", () => {
|
|
113
|
+
test("set by the node's own token, sticky, not settable by a user login", async () => {
|
|
114
|
+
const a = await connect(asA);
|
|
115
|
+
try {
|
|
116
|
+
await a.call("report_status", { resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, logs_capable: true });
|
|
117
|
+
await a.call("report_status", { resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID });
|
|
118
|
+
} finally { await a.close(); }
|
|
119
|
+
expect(db.get<{ c: number }>("SELECT logs_capable AS c FROM sessions WHERE alias = ?1 AND network_id = ?2", NODE_A, NET)?.c).toBe(1);
|
|
120
|
+
const u = await connect(asOwner);
|
|
121
|
+
try {
|
|
122
|
+
await u.call("report_status", { resume_id: "user-logs-report", alias: NODE_B, status: "idle", network_id: NET, logs_capable: true });
|
|
123
|
+
} finally { await u.close(); }
|
|
124
|
+
expect(db.get<{ c: number }>("SELECT logs_capable AS c FROM sessions WHERE alias = ?1 AND network_id = ?2", NODE_B, NET)?.c ?? 0).toBe(0);
|
|
125
|
+
}, 20_000);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("round trip", () => {
|
|
129
|
+
test("the node pulls only the normalised filter JSON (no path), acks, the asker reads it once", async () => {
|
|
130
|
+
const u = await connect(asOwner);
|
|
131
|
+
const a = await connect(asA);
|
|
132
|
+
try {
|
|
133
|
+
const enq = await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET, lines: 99999 > 2000 ? 2000 : 1, level: "warn", grep: "boom", since_ts: 5, path: "/etc/passwd" });
|
|
134
|
+
expect(enq).toMatchObject({ ok: true, op: "logs_tail" });
|
|
135
|
+
const pulled = (await a.call("get_rules_file_request", {})).request;
|
|
136
|
+
expect(pulled.op).toBe("logs_tail");
|
|
137
|
+
expect(JSON.parse(pulled.content)).toEqual({ lines: 2000, level: "warn", grep: "boom", since_ts: 5 });
|
|
138
|
+
expect(pulled.content).not.toContain("passwd");
|
|
139
|
+
expect(await a.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", file_name: "logs", exists: true, content: SAMPLE })).toMatchObject({ ok: true, status: "done" });
|
|
140
|
+
|
|
141
|
+
const first = await u.call("get_rules_file_result", { request_id: enq.request_id, network_id: NET });
|
|
142
|
+
expect(first).toMatchObject({ ok: true, op: "logs_tail", status: "done", content: SAMPLE });
|
|
143
|
+
// Read-once: purged in the same call, including the filter JSON.
|
|
144
|
+
expect(row(enq.request_id)).toMatchObject({ result_content: null, content: null });
|
|
145
|
+
expect(row(enq.request_id).content_purged_at).toBeGreaterThan(0);
|
|
146
|
+
const second = await u.call("get_rules_file_result", { request_id: enq.request_id, network_id: NET });
|
|
147
|
+
expect(second.content).toBeUndefined();
|
|
148
|
+
expect(second.content_purged).toBe(true);
|
|
149
|
+
} finally { await u.close(); await a.close(); }
|
|
150
|
+
}, 20_000);
|
|
151
|
+
|
|
152
|
+
test("lines above 2000 are refused by the schema; bad level refused", async () => {
|
|
153
|
+
const u = await connect(asOwner);
|
|
154
|
+
try {
|
|
155
|
+
expect((await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET, lines: 2001 })).ok).not.toBe(true);
|
|
156
|
+
expect((await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET, level: "debug" })).ok).not.toBe(true);
|
|
157
|
+
expect(rowCount()).toBe(0);
|
|
158
|
+
} finally { await u.close(); }
|
|
159
|
+
}, 20_000);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("who may ask", () => {
|
|
163
|
+
test("node tokens are refused — for other nodes and for themselves", async () => {
|
|
164
|
+
const a = await connect(asA);
|
|
165
|
+
try {
|
|
166
|
+
expect(await a.call("tail_node_logs", { node_id: NODE_B_ID })).toMatchObject({ ok: false, error: "node_token_cannot_read_logs" });
|
|
167
|
+
expect(await a.call("tail_node_logs", { node_id: NODE_A_ID })).toMatchObject({ ok: false, error: "node_token_cannot_read_logs" });
|
|
168
|
+
expect(rowCount()).toBe(0);
|
|
169
|
+
} finally { await a.close(); }
|
|
170
|
+
}, 20_000);
|
|
171
|
+
|
|
172
|
+
test("node owner yes; plain member no; viewer no; network owner yes", async () => {
|
|
173
|
+
const m = await connect(asMember);
|
|
174
|
+
const m2 = await connect(asMember2);
|
|
175
|
+
const v = await connect(asViewer);
|
|
176
|
+
const o = await connect(asOwner);
|
|
177
|
+
try {
|
|
178
|
+
expect(await m.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET })).toMatchObject({ ok: true });
|
|
179
|
+
expect(await m.call("tail_node_logs", { node_id: NODE_B_ID, network_id: NET })).toMatchObject({ ok: false, error: "logs_permission_denied" });
|
|
180
|
+
expect(await m2.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET })).toMatchObject({ ok: false, error: "logs_permission_denied" });
|
|
181
|
+
expect((await v.call("tail_node_logs", { node_id: NODE_B_ID, network_id: NET })).ok).toBe(false);
|
|
182
|
+
expect(await o.call("tail_node_logs", { node_id: NODE_B_ID, network_id: NET })).toMatchObject({ ok: true });
|
|
183
|
+
expect(rowCount()).toBe(2);
|
|
184
|
+
} finally { await m.close(); await m2.close(); await v.close(); await o.close(); }
|
|
185
|
+
}, 20_000);
|
|
186
|
+
|
|
187
|
+
test("a user of another network is refused (cross network)", async () => {
|
|
188
|
+
const x = await connect(asOutsider);
|
|
189
|
+
try {
|
|
190
|
+
const r1 = await x.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET });
|
|
191
|
+
expect(r1.ok).toBe(false);
|
|
192
|
+
const r2 = await x.call("tail_node_logs", { node_id: NODE_A_ID, network_id: OTHER_NET });
|
|
193
|
+
expect(r2).toMatchObject({ ok: false, error: "cross_network_node" });
|
|
194
|
+
expect(rowCount()).toBe(0);
|
|
195
|
+
} finally { await x.close(); }
|
|
196
|
+
}, 20_000);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("who may read", () => {
|
|
200
|
+
test("only the login that asked; another login of the same user, node tokens and the serving node cannot", async () => {
|
|
201
|
+
const u = await connect(asOwner);
|
|
202
|
+
const other = await connect(asOwnerOtherLogin);
|
|
203
|
+
const b = await connect(asB);
|
|
204
|
+
const a = await connect(asA);
|
|
205
|
+
try {
|
|
206
|
+
const enq = await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET });
|
|
207
|
+
await a.call("get_rules_file_request", {});
|
|
208
|
+
await a.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: SAMPLE });
|
|
209
|
+
expect(await other.call("get_rules_file_result", { request_id: enq.request_id, network_id: NET })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
210
|
+
expect(await b.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
211
|
+
expect(await a.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
212
|
+
// Those refusals did not consume the read-once result.
|
|
213
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id, network_id: NET })).toMatchObject({ status: "done", content: SAMPLE });
|
|
214
|
+
} finally { await u.close(); await other.close(); await b.close(); await a.close(); }
|
|
215
|
+
}, 20_000);
|
|
216
|
+
|
|
217
|
+
test("node B never pulls or acks node A's logs request", async () => {
|
|
218
|
+
const u = await connect(asOwner);
|
|
219
|
+
const a = await connect(asA);
|
|
220
|
+
const b = await connect(asB);
|
|
221
|
+
try {
|
|
222
|
+
const enq = await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET });
|
|
223
|
+
expect((await b.call("get_rules_file_request", {})).request).toBeNull();
|
|
224
|
+
expect(await b.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{\"forged\":true}" })).toMatchObject({ ignored: "unknown_or_foreign_request" });
|
|
225
|
+
expect((await a.call("get_rules_file_request", {})).request.request_id).toBe(enq.request_id);
|
|
226
|
+
} finally { await u.close(); await a.close(); await b.close(); }
|
|
227
|
+
}, 20_000);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("storage and lanes", () => {
|
|
231
|
+
test("an unread terminal result is purged by the sweep after the logs TTL; other ops keep theirs", async () => {
|
|
232
|
+
const u = await connect(asOwner);
|
|
233
|
+
const a = await connect(asA);
|
|
234
|
+
try {
|
|
235
|
+
const enq = await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET });
|
|
236
|
+
const rules = await u.call("read_node_rules_file", { node_id: NODE_A_ID, network_id: NET });
|
|
237
|
+
await a.call("get_rules_file_request", {});
|
|
238
|
+
await a.call("get_rules_file_request", {});
|
|
239
|
+
await a.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: SAMPLE });
|
|
240
|
+
await a.call("ack_rules_file_request", { request_id: rules.request_id, status: "done", content: "# rules" });
|
|
241
|
+
sweepNodeRequestContent(Date.now() + LOGS_CONTENT_TTL_MS - 5_000);
|
|
242
|
+
expect(row(enq.request_id).result_content).toBe(SAMPLE);
|
|
243
|
+
sweepNodeRequestContent(Date.now() + LOGS_CONTENT_TTL_MS + 5_000);
|
|
244
|
+
expect(row(enq.request_id)).toMatchObject({ result_content: null, content: null });
|
|
245
|
+
expect(row(rules.request_id).result_content).toBe("# rules");
|
|
246
|
+
} finally { await u.close(); await a.close(); }
|
|
247
|
+
}, 20_000);
|
|
248
|
+
|
|
249
|
+
test("own single-flight lane; a 1 MiB-class ack is accepted", async () => {
|
|
250
|
+
const u = await connect(asOwner);
|
|
251
|
+
const a = await connect(asA);
|
|
252
|
+
try {
|
|
253
|
+
expect(await u.call("list_node_files", { node_id: NODE_A_ID, network_id: NET })).toMatchObject({ ok: true });
|
|
254
|
+
const first = await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET });
|
|
255
|
+
expect(first).toMatchObject({ ok: true });
|
|
256
|
+
expect(await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET })).toMatchObject({ ok: false, error: "request_in_flight", existing_request_id: first.request_id });
|
|
257
|
+
await a.call("get_rules_file_request", {});
|
|
258
|
+
await a.call("get_rules_file_request", {});
|
|
259
|
+
const big = "x".repeat(700 * 1024);
|
|
260
|
+
expect(await a.call("ack_rules_file_request", { request_id: first.request_id, status: "done", content: big })).toMatchObject({ ok: true, status: "done" });
|
|
261
|
+
} finally { await u.close(); await a.close(); }
|
|
262
|
+
}, 20_000);
|
|
263
|
+
});
|