@sleep2agi/commhub-server 0.9.0-preview.262 → 0.9.0-preview.263
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 +2 -2
- package/package.json +1 -1
- package/src/health-status-reasons.test.ts +60 -0
- package/src/server.ts +14 -0
package/build-info.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.9.0-preview.
|
|
3
|
+
"version": "0.9.0-preview.263",
|
|
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",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// `status_reasons` 的**值域**必须与它的**生产者**逐个对应(外部复核的判据)。
|
|
2
|
+
//
|
|
3
|
+
// ## 为什么这一格值得一条断言
|
|
4
|
+
//
|
|
5
|
+
// `/health.status` 只有两个取值(ok / degraded),而 `status_reasons` 是回答
|
|
6
|
+
// 「ok 到底是**真的没问题**,还是**检查没跑**」的唯一读数。它的值域偏离生产者时:
|
|
7
|
+
//
|
|
8
|
+
// 值域比生产者少 ⇒ 两个成因合并成一个字 ⇒ 读的人分不出该修哪(合并)
|
|
9
|
+
// 值域比生产者多 ⇒ 有原因却没有任何代码会产生它 ⇒ 读者为它设计一条不存在的修法(死值)
|
|
10
|
+
//
|
|
11
|
+
// 两种都不红:`status` 照样是 ok/degraded,`status_reasons` 照样是数组。
|
|
12
|
+
//
|
|
13
|
+
// ## 为什么这一份是**声明**而不是引用
|
|
14
|
+
//
|
|
15
|
+
// push 点保留字面量(`statusReasons.push("db_unreadable")`),`STATUS_REASONS` 只做靶子。
|
|
16
|
+
// 改成 `push(STATUS_REASONS[0])` 之后,抽取只能看见下标、看不见成因,
|
|
17
|
+
// 而「哪一行推了什么」正是这条检查要看的东西。
|
|
18
|
+
//
|
|
19
|
+
// ## 断言
|
|
20
|
+
//
|
|
21
|
+
// ① 源码里所有 `statusReasons.push("X")` 的字面量集合 == STATUS_REASONS
|
|
22
|
+
// ② push 点数 == 不同字面量数(同一个成因不许有两处 push —— 那会让「一个成因」看起来像两个)
|
|
23
|
+
// ③ 每个 STATUS_REASONS 的成员都真的在某处被 push(无死值)
|
|
24
|
+
import { describe, expect, test } from "bun:test";
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
|
|
27
|
+
const src = readFileSync(new URL("./server.ts", import.meta.url), "utf8");
|
|
28
|
+
|
|
29
|
+
/** 源码里所有 `statusReasons.push("literal")` 的字面量(保序、允许重复)。 */
|
|
30
|
+
export function pushedReasonLiterals(source: string): string[] {
|
|
31
|
+
return [...source.matchAll(/statusReasons\s*\.\s*push\(\s*"([a-z0-9_]+)"\s*\)/g)].map((m) => m[1]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("#status_reasons 值域 == 生产者集合", () => {
|
|
35
|
+
test("① push 的字面量集合与 STATUS_REASONS 相等", async () => {
|
|
36
|
+
const { STATUS_REASONS } = await import("./server.js");
|
|
37
|
+
const pushed = new Set(pushedReasonLiterals(src));
|
|
38
|
+
expect([...pushed].sort()).toEqual([...STATUS_REASONS].sort());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("② push 点数 == 不同字面量数(同一个成因不许两处推)", () => {
|
|
42
|
+
const all = pushedReasonLiterals(src);
|
|
43
|
+
expect(all.length).toBe(new Set(all).size);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("③ 没有死值:STATUS_REASONS 每个成员都在源码里被 push 过", async () => {
|
|
47
|
+
const { STATUS_REASONS } = await import("./server.js");
|
|
48
|
+
const pushed = new Set(pushedReasonLiterals(src));
|
|
49
|
+
for (const r of STATUS_REASONS) expect(pushed.has(r)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("④ status 由 reasons 派生,不是独立写的第二个真相", async () => {
|
|
53
|
+
const { statusFromReasons } = await import("./server.js");
|
|
54
|
+
// 空 ⇒ ok;任一 ⇒ degraded。这条同时钉住「ok 不代表检查跑过」——
|
|
55
|
+
// 它只代表「没有成因被推上来」。
|
|
56
|
+
expect(statusFromReasons([])).toBe("ok");
|
|
57
|
+
expect(statusFromReasons(["db_unreadable"])).toBe("degraded");
|
|
58
|
+
expect(statusFromReasons(["db_unreadable", "license_unreadable"])).toBe("degraded");
|
|
59
|
+
});
|
|
60
|
+
});
|
package/src/server.ts
CHANGED
|
@@ -1232,6 +1232,20 @@ export function statusFromReasons(reasons: readonly string[]): "ok" | "degraded"
|
|
|
1232
1232
|
return reasons.length === 0 ? "ok" : "degraded";
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
|
+
/**
|
|
1236
|
+
* 2026-11-01 —— `status_reasons` 的**值域**,与它的生产者逐个对应。
|
|
1237
|
+
*
|
|
1238
|
+
* 为什么要有这一格:`status_reasons` 是「`status: ok` 到底是没问题、还是检查没跑」的唯一读数。
|
|
1239
|
+
* 它的值域若比生产者少 ⇒ 两个成因被合并成一个字(读的人分不出该修哪),
|
|
1240
|
+
* 多 ⇒ 有原因却没有任何代码会产生它(死值,读者会为它设计一条不存在的修法)。
|
|
1241
|
+
*
|
|
1242
|
+
* 🔴 push 点**保留字面量**而不是引用这个常量:抽取判据要看的是「哪一行推了什么」,
|
|
1243
|
+
* 改成 `push(STATUS_REASONS[0])` 之后,那条检查就只能看见下标,看不见成因。
|
|
1244
|
+
* ⇒ 这份常量是**断言的靶子**,不是运行时唯一入口。
|
|
1245
|
+
* 两者的关系由 health-status-reasons.test.ts 断言(集合相等 + 生产者数 == 值数)。
|
|
1246
|
+
*/
|
|
1247
|
+
export const STATUS_REASONS = ["db_unreadable", "license_unreadable"] as const;
|
|
1248
|
+
|
|
1235
1249
|
export const HEALTH_FIELD_META: Readonly<Record<string, HealthFieldMeta>> = {
|
|
1236
1250
|
// ── gauge:聚合 / 粗标签 ─────────────────────────────────────────────
|
|
1237
1251
|
ok: {
|