@sleep2agi/commhub-server 0.9.0-preview.230 → 0.9.0-preview.231

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.230",
3
+ "version": "0.9.0-preview.231",
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",
@@ -663,6 +663,25 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
663
663
  // #3174 —— stall_count / last_stall_at 原来只有 [startedAt, now] 这个**隐含**窗口:
664
664
  // 单独引用它,读者会把「计数器归零」读成「从未卡过」。
665
665
  // ⇒ 现在窗口两端跟着读数一起走(event_loop.since / event_loop.observed_at)。
666
+ // 2026-10-31 —— **0 只能作为读数出现,不能冒充「没测」**(外部复核 ④:
667
+ // 「『未取』被系统翻译成『正常』——而零恰好是最好看的那个值」)。
668
+ // event_loop 的计数类字段天然可能是 0(真的没停顿)。所以必须能区分:
669
+ // 窗口存在 ⇒ 0 是「这段时间内没有停顿」(读数)
670
+ // 窗口为零长 ⇒ 0 是「还没测」(不是读数)
671
+ // 断言:窗口两端必须同时存在,且 since ≤ observed_at;窗口为空时**不得**声称 0 是结论。
672
+ test("zero-valued stall counters carry a window, so 0 is a reading rather than 'not measured'", async () => {
673
+ const body = await (await fetch(`${BASE}/health`)).json() as any;
674
+ const el = body.event_loop;
675
+ const since = Date.parse(el.since), observed = Date.parse(el.observed_at);
676
+ expect(Number.isFinite(since)).toBe(true);
677
+ expect(Number.isFinite(observed)).toBe(true);
678
+ expect(observed).toBeGreaterThanOrEqual(since);
679
+ if (el.stall_count === 0) {
680
+ // 0 停顿 + 正长度窗口 = 读数;0 停顿 + 零长度窗口 = 还没测,此时不能当成「没有停顿」
681
+ expect(observed - since).toBeGreaterThan(0);
682
+ }
683
+ });
684
+
666
685
  describe("event_loop carries its own window (no implicit [startedAt, now])", () => {
667
686
  test("both ends are present, and they are ordered", async () => {
668
687
  const body = await (await fetch(`${BASE}/health`)).json() as any;
@@ -406,4 +406,32 @@ describe("GET /api/providers", () => {
406
406
  db.run(`DELETE FROM nodes WHERE node_id = ?1`, [nodeId]);
407
407
  }
408
408
  });
409
+
410
+ // 2026-10-31 —— **格式约束与数量约束分开**(外部复核 (a):
411
+ // 「白名单管『怎么写』,这条管『写几处』」)。
412
+ // 这两张状态映射各自只能有**一处定义**,且必须被生产代码**至少读一次**:
413
+ // 只有定义、没有读取 ⇒ 它是一张装饰表(写 1 处、读 0 处)。
414
+ test("status maps are defined exactly once and actually read by production code", async () => {
415
+ const { readFileSync, readdirSync, statSync } = await import("node:fs");
416
+ const { join } = await import("node:path");
417
+ const root = join(import.meta.dir);
418
+ const walk = (dir: string, out: string[] = []): string[] => {
419
+ for (const name of readdirSync(dir)) {
420
+ const full = join(dir, name);
421
+ if (statSync(full).isDirectory()) walk(full, out);
422
+ else if (name.endsWith(".ts") && !name.endsWith(".test.ts")) out.push(full);
423
+ }
424
+ return out;
425
+ };
426
+ const files = walk(root).map((f) => ({ f, src: readFileSync(f, "utf8") }));
427
+ for (const name of ["PROVIDER_WRITE_STATUS", "TAG_CREATE_STATUS"]) {
428
+ const defs = files.filter(({ src }) => src.includes(`export const ${name}`));
429
+ expect(defs.length).toBe(1);
430
+ const readers = files.flatMap(({ f, src }) =>
431
+ src.split("\n").map((line, i) => ({ line, f, i }))
432
+ .filter(({ line }) => line.includes(name) && !line.includes(`export const ${name}`)));
433
+ // 「读」= 出现但不是定义行(索引 / 展开 / 断言都算)
434
+ expect(readers.length).toBeGreaterThan(0);
435
+ }
436
+ });
409
437
  });