@sleep2agi/commhub-server 0.9.0-preview.221 → 0.9.0-preview.222
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.
|
|
3
|
+
"version": "0.9.0-preview.222",
|
|
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",
|
|
@@ -1030,6 +1030,30 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
1030
1030
|
// 它却一直躺在那里,看起来「这个字段是公开的」⇒ 下一个人把同名字段加回来时**默认就是公开的**。
|
|
1031
1031
|
// ⇒ 白名单会从「审批记录」退化成「历史残留」。
|
|
1032
1032
|
// 这与今晚那条镜像规则同构:否定断言必须配肯定断言,否则前者可被「永远不给」满足。
|
|
1033
|
+
// 2026-10-31 —— **2×2 的第四格**(外部复核 (e):「等价性断言必须按 (通道 × 配置) 组合进行」)。
|
|
1034
|
+
// 本仓的 /health 有两个维度:谁在读(匿名 / 鉴权)× 有没有带 X-Probe-Nonce。
|
|
1035
|
+
// 前面只覆盖了三格(匿名、匿名+探针、鉴权),**鉴权+探针**这一格没测过 ——
|
|
1036
|
+
// 而它正是「探针回显会不会被鉴权分支吃掉」的唯一读数。
|
|
1037
|
+
test("all four cells of (audience × probe-header) carry the fields they must", async () => {
|
|
1038
|
+
const anon = await (await fetch(`${BASE}/health`)).json() as any;
|
|
1039
|
+
const anonProbe = await (await fetch(`${BASE}/health`, { headers: { "X-Probe-Nonce": "cell-anon" } })).json() as any;
|
|
1040
|
+
const authed = await (await fetch(`${BASE}/health`, { headers: { Authorization: `Bearer ${adminToken}` } })).json() as any;
|
|
1041
|
+
const authedProbe = await (await fetch(`${BASE}/health`, {
|
|
1042
|
+
headers: { Authorization: `Bearer ${adminToken}`, "X-Probe-Nonce": "cell-authed" },
|
|
1043
|
+
})).json() as any;
|
|
1044
|
+
|
|
1045
|
+
// 探针格:带头的两格都必须回显 nonce,且 served_at 都在(窗口两端同域)
|
|
1046
|
+
expect(anonProbe.probe_nonce).toBe("cell-anon");
|
|
1047
|
+
expect(authedProbe.probe_nonce).toBe("cell-authed");
|
|
1048
|
+
for (const body of [anon, anonProbe, authed, authedProbe]) {
|
|
1049
|
+
expect(typeof body.served_at).toBe("string");
|
|
1050
|
+
}
|
|
1051
|
+
// 不带头的一格不该出现 probe_nonce(否则「这一次的凭据」变成常驻字段)
|
|
1052
|
+
expect("probe_nonce" in anon).toBe(false);
|
|
1053
|
+
// 鉴权格必须比匿名格多(否则白名单形同虚设)——第四格同样成立
|
|
1054
|
+
expect(Object.keys(authedProbe).length).toBeGreaterThan(Object.keys(anonProbe).length);
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1033
1057
|
test("no dead entries: every allow-listed key is actually served to anonymous callers", async () => {
|
|
1034
1058
|
const { PUBLIC_HEALTH_KEYS } = await import("./server.js");
|
|
1035
1059
|
const plain = await (await fetch(`${BASE}/health`)).json() as any;
|
|
@@ -109,6 +109,24 @@ afterAll(() => {
|
|
|
109
109
|
try { rmSync(DIR, { recursive: true, force: true }); } catch {}
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
// 2026-10-31 —— **穷尽映射的运行时钉**(外部复核 (c):「应改成 Record<ErrorCode, number> 由 tsc 报红」)。
|
|
113
|
+
// 本仓 server 没有 tsc 门(只有 agent-network 在 e2e-docker 里 typecheck),
|
|
114
|
+
// 所以那条约束只有写成运行时断言才真的存在:
|
|
115
|
+
// 码集合 = TAG_CREATE_ERRORS(唯一来源)|映射键必须与它逐字相等|每个值必须是合法 HTTP 状态
|
|
116
|
+
test("tag create: every error code has a status, and nothing else does", async () => {
|
|
117
|
+
const { TAG_CREATE_ERRORS, TAG_CREATE_STATUS } = await import("./requirements.js");
|
|
118
|
+
expect(Object.keys(TAG_CREATE_STATUS).sort()).toEqual([...TAG_CREATE_ERRORS].sort());
|
|
119
|
+
for (const code of TAG_CREATE_ERRORS) {
|
|
120
|
+
const status = TAG_CREATE_STATUS[code];
|
|
121
|
+
expect(Number.isInteger(status)).toBe(true);
|
|
122
|
+
expect(status).toBeGreaterThanOrEqual(400);
|
|
123
|
+
expect(status).toBeLessThan(500);
|
|
124
|
+
}
|
|
125
|
+
// 反例守卫:默认分支的「未映射 ⇒ 400」不许再出现(那正是被替换掉的那行)
|
|
126
|
+
const src = await (await import("node:fs")).readFileSync(new URL("./requirements.ts", import.meta.url), "utf8");
|
|
127
|
+
expect(src).not.toMatch(/result\.error === "tag_exists" \? 409/);
|
|
128
|
+
});
|
|
129
|
+
|
|
112
130
|
describe("GET /api/requirements/tags", () => {
|
|
113
131
|
test("owner:tags 仍是排序后的字符串数组(旧 App 形状不变),多出 counts / colors / can_manage", async () => {
|
|
114
132
|
const r = await tagsOf(admin.token);
|
package/src/requirements.ts
CHANGED
|
@@ -692,8 +692,13 @@ function networkTagNames(networkId: string): Set<string> {
|
|
|
692
692
|
* 新增一个错误码时它**默认落到 400**,而有些码 400 是错的(冲突应是 409),且没人会提醒你。
|
|
693
693
|
* 改成穷尽表之后,漏一个码 = tsc 红。
|
|
694
694
|
*/
|
|
695
|
-
|
|
696
|
-
|
|
695
|
+
// 2026-10-31 —— **本仓 server 没有 tsc 门**(只有 agent-network 在 e2e-docker 里 typecheck),
|
|
696
|
+
// 所以「漏一个码 = tsc 红」在这里是空头支票。⇒ 用运行时钉住:
|
|
697
|
+
// 码集合由这个数组当**唯一来源**,测试断言映射表的键与它逐字相等。
|
|
698
|
+
// 这样新增一个码只改一处(数组),而「忘了加 status」会红在测试里,不依赖编辑器。
|
|
699
|
+
export const TAG_CREATE_ERRORS = ["tag_exists", "tag_parent_not_found", "tag_depth_exceeded"] as const;
|
|
700
|
+
export type TagCreateError = (typeof TAG_CREATE_ERRORS)[number];
|
|
701
|
+
export const TAG_CREATE_STATUS: Record<TagCreateError, number> = {
|
|
697
702
|
tag_exists: 409,
|
|
698
703
|
tag_parent_not_found: 404,
|
|
699
704
|
tag_depth_exceeded: 400,
|