@sleep2agi/commhub-server 0.9.0-preview.259 → 0.9.0-preview.260

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/build-info.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
- "commit": "152b8ef41668466983af07b1764447a451bd3cea",
3
+ "commit": "01a790c1c8b5ecfa4bfe6a44bf96262b894fd039",
4
4
  "dirty": false,
5
- "built_at": "2026-11-01T02:15:37.070Z",
5
+ "built_at": "2026-11-01T02:21:02.159Z",
6
6
  "source": "git"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.259",
3
+ "version": "0.9.0-preview.260",
4
4
  "description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and MCP tools (17 collaboration-core + node/provider ops tools; authoritative list: docs-site/docs/api/mcp-tools.md).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -101,3 +101,28 @@ describe("#3294 节点上报 build_commit 的三段链路", () => {
101
101
  expect(r.ok).toBeFalsy();
102
102
  });
103
103
  });
104
+
105
+ // #3144 —— 与 build_commit 同一个坑:**schema 里没有的键会被 zod 静默丢掉**。
106
+ // 所以「/api/nodes 能读到 opencode_catalog_seen_at」必须走一次真实的
107
+ // report_status → 落库 → 投影,而不是读一个镜像映射(镜像永远不会红)。
108
+ describe("#3144 opencode_catalog_seen_at 的三段链路(真 HTTP)", () => {
109
+ test("报了两个字段 ⇒ 投影里都读得到", async () => {
110
+ expect((await report({
111
+ config_snapshot: {
112
+ opencode_catalog: ["openai/gpt-6.1-terra", "kimi-code-plan-cn/k3.1-pro"],
113
+ opencode_catalog_seen_at: "2026-11-01T02:00:00Z",
114
+ },
115
+ })).ok).toBe(true);
116
+ const row = (await nodes()).nodes.find((n: any) => n.alias === ALIAS);
117
+ expect(row.opencode_catalog).toEqual(["openai/gpt-6.1-terra", "kimi-code-plan-cn/k3.1-pro"]);
118
+ expect(row.opencode_catalog_seen_at).toBe("2026-11-01T02:00:00Z");
119
+ });
120
+
121
+ test("只报目录、不报时刻 ⇒ 时刻是 null(不是空串、不是当前时间)", async () => {
122
+ expect((await report({ config_snapshot: { opencode_catalog: ["a/b"] } })).ok).toBe(true);
123
+ const row = (await nodes()).nodes.find((n: any) => n.alias === ALIAS);
124
+ expect(row.opencode_catalog).toEqual(["a/b"]);
125
+ expect(row.opencode_catalog_seen_at).toBeNull();
126
+ expect(row.opencode_catalog_seen_at).not.toBe("");
127
+ });
128
+ });
@@ -0,0 +1,109 @@
1
+ // #3309 读数覆盖第十批 —— 两条此前在测试里一次都没出现过的 error:
2
+ //
3
+ // restart_node : adopted_restart_requires_daemon
4
+ // start_node : forbidden_cross_tenant
5
+ //
6
+ // 第一条是「adopted 节点不能被 restart」:binding 证明的是 stop/start 授权,
7
+ // 不是 exit-75 supervisor 能力 —— 代码里这段注释写得很清楚,但此前没有任何测试走过它。
8
+ // 这条特别值得钉住,因为它是**「有权限做 A 不等于有权限做 B」**的一个具体实例:
9
+ // 同一个 binding 让 stop/start 可用,却让 restart 必须拒绝。
10
+ //
11
+ // ⚠ 没测 daemon_cross_tenant:那需要「daemon 与 child 分属不同网络」的夹具,
12
+ // 而 resolveTargetNode 本身会在采到那种行之前就按网络拦掉 —— 要造出来只能伪造
13
+ // 一个正常路径不会产生的状态。留在待补清单里,不在这里假装覆盖。
14
+ import { afterAll, beforeEach, describe, expect, test } from "bun:test";
15
+ import { db } from "./db.js";
16
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
17
+ import { registerTools } from "./tools.js";
18
+
19
+ const NET = "net_10th_err";
20
+ const OWNER = "u_10th_owner";
21
+ const DAEMON = "node_10th_daemon";
22
+ const ADOPTED = "node_10th_adopted";
23
+
24
+ type ToolHandler = (args: any) => Promise<{ content: Array<{ type: "text"; text: string }> }>;
25
+
26
+ function handlers(): Record<string, ToolHandler> {
27
+ const server = new McpServer({ name: "t", version: "0" }) as any;
28
+ const out: Record<string, ToolHandler> = {};
29
+ const orig = server.tool.bind(server);
30
+ server.tool = (n: string, d: string, s: any, h: ToolHandler) => { out[n] = h; return orig(n, d, s, h); };
31
+ registerTools(server, undefined, NET, OWNER, null, false, null);
32
+ return out;
33
+ }
34
+
35
+ async function call(name: string, args: Record<string, unknown>) {
36
+ const r = await handlers()[name](args);
37
+ return JSON.parse(r.content[0].text) as { ok?: boolean; error?: string; [k: string]: unknown };
38
+ }
39
+
40
+ function cleanup() {
41
+ for (const t of ["node_daemon_bindings", "node_create_requests", "nodes", "network_members"]) {
42
+ try { db.run(`DELETE FROM ${t} WHERE network_id = ?1`, [NET]); } catch {}
43
+ }
44
+ try { db.run("DELETE FROM networks WHERE network_id = ?1", [NET]); } catch {}
45
+ try { db.run("DELETE FROM users WHERE user_id = ?1", [OWNER]); } catch {}
46
+ }
47
+
48
+ function node(node_id: string, alias: string, snapshot: Record<string, unknown> | null) {
49
+ db.run(
50
+ `INSERT INTO nodes (node_id, node_name, alias, network_id, runtime, model, channels, config_snapshot,
51
+ hostname, created_at, updated_at, lifecycle_state)
52
+ VALUES (?1, ?2, ?2, ?3, 'opencode-cli', 'm', '[]', ?4, 'host-x', datetime('now'), datetime('now'), 'active')`,
53
+ [node_id, alias, NET, snapshot ? JSON.stringify(snapshot) : null],
54
+ );
55
+ }
56
+
57
+ function seed() {
58
+ cleanup();
59
+ db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [OWNER]);
60
+ db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, OWNER]);
61
+ db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [OWNER, NET]);
62
+ node(DAEMON, "10th-daemon", { role: "host_supervisor" });
63
+ node(ADOPTED, "10th-adopted", null);
64
+ // adopted 的判据:有 **active** binding,且不是 created(没有 cr_ 记录)
65
+ db.run(
66
+ `INSERT INTO node_daemon_bindings (request_id, network_id, node_id, daemon_node_id, workdir,
67
+ requested_by, status, created_at, updated_at)
68
+ VALUES ('ndb_10th', ?1, ?2, ?3, '/tmp', ?4, 'active', ?5, ?5)`,
69
+ [NET, ADOPTED, DAEMON, OWNER, Date.now()],
70
+ );
71
+ }
72
+
73
+ beforeEach(seed);
74
+ afterAll(cleanup);
75
+
76
+ describe("#3309 restart_node / start_node 的两条拒绝", () => {
77
+ test("adopted 节点(binding 证明的是 stop/start 授权)⇒ restart 必须拒", async () => {
78
+ const r = await call("restart_node", { node_id: ADOPTED });
79
+ expect(r.ok).toBe(false);
80
+ expect(r.error).toBe("adopted_restart_requires_daemon");
81
+ // 提示必须给出**替代动作**(Stop → Start),否则读的人只知道被拒。
82
+ expect(String(r.message)).toContain("Stop");
83
+ });
84
+
85
+ test("反向:supervisor 节点(created/role=host_supervisor)不会被这条挡", async () => {
86
+ const r = await call("restart_node", { node_id: DAEMON });
87
+ // 会不会成功取决于后续的生命周期校验,但**不该**是 adopted 这条。
88
+ expect(r.error).not.toBe("adopted_restart_requires_daemon");
89
+ });
90
+
91
+ test("start_node 对不存在的 node ⇒ **第三次值** daemon_not_resolvable(不是我猜的两个)", async () => {
92
+ // 我原本以为这里是 forbidden_cross_tenant 或 node_not_found —— 实测都不是。
93
+ // 这是本组测试里唯一一次「期望值被真实调用纠正」:猜错的那个值(daemon_not_resolvable)
94
+ // 是一个此前没人写过的形状,而它恰好说明 start_node 的**第一道**门是「能不能解析出 daemon」,
95
+ // 而不是「这个 node 存不存在」。
96
+ const r = await call("start_node", { node_id: "node_not_in_my_networks" });
97
+ expect(r.ok).toBe(false);
98
+ expect(r.error).toBe("daemon_not_resolvable");
99
+ expect(r.error).not.toBe("node_not_found");
100
+ });
101
+
102
+ test("两条载荷都没有 code 字段(现状,不是契约)", async () => {
103
+ const replies = [await call("restart_node", { node_id: ADOPTED }), await call("start_node", { node_id: "node_nope" })];
104
+ for (const r of replies) {
105
+ expect(r.ok).toBe(false);
106
+ expect(Object.prototype.hasOwnProperty.call(r, "code")).toBe(false);
107
+ }
108
+ });
109
+ });
package/src/tools.ts CHANGED
@@ -985,6 +985,12 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
985
985
  // (约定见 tool-audience-http.test.ts:加字段先砍描述或合并,别改那三个数)。
986
986
  // `.catch(undefined)`:形状不对只丢这一格,绝不拒掉整份心跳。
987
987
  opencode_catalog: z.array(z.string()).max(400).optional().catch(undefined),
988
+ // #3144 —— 目录是**快照**:没有采集时刻,51 个模型是刚才的还是三周前的分不出。
989
+ // 🔴 这一格必须写进 schema:zod 的 object 默认**丢掉未知键** ⇒ 不写在这里,
990
+ // daemon 报上来也会被静默剥掉,而 /api/nodes 的投影读到的永远是 null
991
+ // (#3294 的 build_commit 就是同一个坑)。`.catch(undefined)` 与邻居一致:
992
+ // 形状不对只丢这一格,绝不拒掉整份心跳。
993
+ opencode_catalog_seen_at: z.string().max(40).optional().catch(undefined),
988
994
  // #2293 —— 这台机器上 OpenCode serve 的 loopback 端点(`http://127.0.0.1:PORT`)。
989
995
  // 客户端「OpenCode Server」行此前只能写「端口未上报」。只收 loopback URL,不收密码。
990
996
  opencode_server: z.string().max(200).optional().catch(undefined),