@sleep2agi/commhub-server 0.9.0-preview.232 → 0.9.0-preview.234
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 +1 -1
- package/src/clip.ts +4 -2
- package/src/health-redaction.test.ts +19 -0
- package/src/hub-catalog-read-http.test.ts +44 -1
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.234",
|
|
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",
|
package/src/clip.ts
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
* `s.slice(0, n)` 数的是 UTF-16 code unit,而一个 emoji(或任何 BMP 外字符)占两个。
|
|
10
10
|
* 若第 n 个位置正好落在高代理与低代理之间,切出来的字符串含**孤立高代理**:
|
|
11
11
|
* · JSON.stringify 会把它写成 "\ud83d"(语法上合法)
|
|
12
|
-
* ·
|
|
13
|
-
*
|
|
12
|
+
* · 2026-10-31 更正(外部复核实测):Node 编码时**不是报错**,而是把孤立代理替换成 U+FFFD(efbfbd)
|
|
13
|
+
* ⇒ 危害是**静默、不可逆、非单射**:两种不同的坏输入会编码成同一个字节串,
|
|
14
|
+
* 而「日志里那一串」从此既不能 join、也不能反推原文。
|
|
15
|
+
* · 所以这里要防的不是「非法 UTF-8」,是「**悄悄换掉一个字符**」。
|
|
14
16
|
*
|
|
15
17
|
* 本函数只在边界上处理:若切点落在代理对中间,就少取一个 code unit,保证输出始终是
|
|
16
18
|
* 「合法 UTF-16 子串」。**它不改变长度上限的语义**(仍然是 ≤ max),只保证不产生孤立代理。
|
|
@@ -1187,6 +1187,25 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
1187
1187
|
expect(Math.abs(derived - body.uptime)).toBeLessThanOrEqual(5);
|
|
1188
1188
|
});
|
|
1189
1189
|
|
|
1190
|
+
// 2026-10-31 —— **响应头也不能泄露指纹**(外部复核:「匿名 /health 响应头里不得出现
|
|
1191
|
+
// git / commit / build(sha|id) 类头;这两条不需要会话就能读 ⇒ 它们回答『我站在哪一层』,
|
|
1192
|
+
// 不是『我有没有登录』」)。
|
|
1193
|
+
// 为什么需要它:body 有白名单,**头没有**。将来有人把 build id 塞进 `X-Build-Id`,
|
|
1194
|
+
// body 侧断言全绿,而匿名读者已经拿到了指纹。
|
|
1195
|
+
test("anonymous /health exposes no fingerprint-bearing response header", async () => {
|
|
1196
|
+
const res = await fetch(`${BASE}/health`);
|
|
1197
|
+
expect(res.status).toBe(200);
|
|
1198
|
+
const names = [...res.headers.keys()].map((k) => k.toLowerCase());
|
|
1199
|
+
const forbidden = names.filter((n) => /git|commit|build[-_]?(sha|id)?/.test(n));
|
|
1200
|
+
if (forbidden.length) {
|
|
1201
|
+
throw new Error(`匿名 /health 出现了指纹类响应头:${forbidden.join(", ")}\n` +
|
|
1202
|
+
" ⇒ body 白名单不覆盖响应头;要么删掉这个头,要么它只在鉴权分支发。");
|
|
1203
|
+
}
|
|
1204
|
+
// 镜像:同一个端点在**鉴权**分支下可以有 X-* 头,但也不能有指纹 —— 迄今也没有;
|
|
1205
|
+
// 这条留作记录:若哪天加了,必须先在白名单测试里显式放行。
|
|
1206
|
+
expect(forbidden).toEqual([]);
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1190
1209
|
test("no dead entries: every allow-listed key is actually served to anonymous callers", async () => {
|
|
1191
1210
|
const { PUBLIC_HEALTH_KEYS } = await import("./server.js");
|
|
1192
1211
|
const plain = await (await fetch(`${BASE}/health`)).json() as any;
|
|
@@ -429,9 +429,52 @@ describe("GET /api/providers", () => {
|
|
|
429
429
|
expect(defs.length).toBe(1);
|
|
430
430
|
const readers = files.flatMap(({ f, src }) =>
|
|
431
431
|
src.split("\n").map((line, i) => ({ line, f, i }))
|
|
432
|
-
.filter(({ line }) => line.includes(name) && !line.includes(`export const ${name}`))
|
|
432
|
+
.filter(({ line }) => line.includes(name) && !line.includes(`export const ${name}`))
|
|
433
|
+
// 2026-10-31 —— **注释不是读点**:`// 状态码来自穷尽表(PROVIDER_WRITE_STATUS…)`
|
|
434
|
+
// 会满足「读到过」而实际上没有任何代码用它。这正是本仓实测到的形态。
|
|
435
|
+
.filter(({ line }) => {
|
|
436
|
+
const t = line.trim();
|
|
437
|
+
return !t.startsWith("//") && !t.startsWith("*") && !t.startsWith("/*");
|
|
438
|
+
}));
|
|
433
439
|
// 「读」= 出现但不是定义行(索引 / 展开 / 断言都算)
|
|
434
440
|
expect(readers.length).toBeGreaterThan(0);
|
|
441
|
+
// 2026-10-31 —— **计数 = 1 还不够,位置也要在集合内**(外部复核:
|
|
442
|
+
// 「只断言计数 1 ⇒ 留下的是『1 个读点,它自己另搞一套』—— 完全满足计数 1,
|
|
443
|
+
// 而语义已经不是你想的那个。」)
|
|
444
|
+
// ⇒ 读点必须落在**路由文件**里(server.ts),否则等于表有了、用法另有其处。
|
|
445
|
+
// 位置:读点必须落在**实现或路由**里(不是只落在注释里)
|
|
446
|
+
const readerFiles = new Set(readers.map((r) => String(r.f).split("/").pop()));
|
|
447
|
+
expect(readerFiles.size).toBeGreaterThan(0);
|
|
448
|
+
expect([...readerFiles].some((f) => f === "server.ts" || f === "hub-provider-config.ts" || f === "requirements.ts")).toBe(true);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// 2026-10-31 —— **枚举里不能有打不中的值**(外部复核:
|
|
453
|
+
// 「5 值枚举里 2 个不可达(stage_missing / id_not_uuid)——那是装饰,
|
|
454
|
+
// 而读者会以为那两条分支存在且被测过」)。
|
|
455
|
+
// 判据:每个成员的字面量必须在**生产源码**里出现(类型声明行不算)。
|
|
456
|
+
test("every enum member is actually produced somewhere in production code", async () => {
|
|
457
|
+
const { readFileSync, readdirSync, statSync } = await import("node:fs");
|
|
458
|
+
const { join } = await import("node:path");
|
|
459
|
+
const walk = (dir: string, out: string[] = []): string[] => {
|
|
460
|
+
for (const name of readdirSync(dir)) {
|
|
461
|
+
const full = join(dir, name);
|
|
462
|
+
if (statSync(full).isDirectory()) walk(full, out);
|
|
463
|
+
else if (name.endsWith(".ts") && !name.endsWith(".test.ts")) out.push(full);
|
|
464
|
+
}
|
|
465
|
+
return out;
|
|
466
|
+
};
|
|
467
|
+
const prod = walk(join(import.meta.dir)).map((f) => readFileSync(f, "utf8")).join("\n");
|
|
468
|
+
const enums: Record<string, string[]> = {
|
|
469
|
+
version_source: ["embedded_env", "package_json", "read_failed", "empty_value"],
|
|
470
|
+
provider_selection_state: ["never_switched", "pending", "applied", "failed"],
|
|
471
|
+
};
|
|
472
|
+
for (const [label, members] of Object.entries(enums)) {
|
|
473
|
+
const dead = members.filter((m) => !new RegExp(`["']${m}["']`).test(prod));
|
|
474
|
+
if (dead.length) {
|
|
475
|
+
throw new Error(`${label} 里有打不中成员(生产源码没出现过这个字面量):${dead.join(", ")}\n` +
|
|
476
|
+
" ⇒ 要么删掉该成员,要么补上产出它的分支;留着等于给读者一条不存在的分支。");
|
|
477
|
+
}
|
|
435
478
|
}
|
|
436
479
|
});
|
|
437
480
|
});
|