@sleep2agi/commhub-server 0.9.0-preview.232 → 0.9.0-preview.233
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/hub-catalog-read-http.test.ts +29 -0
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.233",
|
|
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),只保证不产生孤立代理。
|
|
@@ -434,4 +434,33 @@ describe("GET /api/providers", () => {
|
|
|
434
434
|
expect(readers.length).toBeGreaterThan(0);
|
|
435
435
|
}
|
|
436
436
|
});
|
|
437
|
+
|
|
438
|
+
// 2026-10-31 —— **枚举里不能有打不中的值**(外部复核:
|
|
439
|
+
// 「5 值枚举里 2 个不可达(stage_missing / id_not_uuid)——那是装饰,
|
|
440
|
+
// 而读者会以为那两条分支存在且被测过」)。
|
|
441
|
+
// 判据:每个成员的字面量必须在**生产源码**里出现(类型声明行不算)。
|
|
442
|
+
test("every enum member is actually produced somewhere in production code", async () => {
|
|
443
|
+
const { readFileSync, readdirSync, statSync } = await import("node:fs");
|
|
444
|
+
const { join } = await import("node:path");
|
|
445
|
+
const walk = (dir: string, out: string[] = []): string[] => {
|
|
446
|
+
for (const name of readdirSync(dir)) {
|
|
447
|
+
const full = join(dir, name);
|
|
448
|
+
if (statSync(full).isDirectory()) walk(full, out);
|
|
449
|
+
else if (name.endsWith(".ts") && !name.endsWith(".test.ts")) out.push(full);
|
|
450
|
+
}
|
|
451
|
+
return out;
|
|
452
|
+
};
|
|
453
|
+
const prod = walk(join(import.meta.dir)).map((f) => readFileSync(f, "utf8")).join("\n");
|
|
454
|
+
const enums: Record<string, string[]> = {
|
|
455
|
+
version_source: ["embedded_env", "package_json", "read_failed", "empty_value"],
|
|
456
|
+
provider_selection_state: ["never_switched", "pending", "applied", "failed"],
|
|
457
|
+
};
|
|
458
|
+
for (const [label, members] of Object.entries(enums)) {
|
|
459
|
+
const dead = members.filter((m) => !new RegExp(`["']${m}["']`).test(prod));
|
|
460
|
+
if (dead.length) {
|
|
461
|
+
throw new Error(`${label} 里有打不中成员(生产源码没出现过这个字面量):${dead.join(", ")}\n` +
|
|
462
|
+
" ⇒ 要么删掉该成员,要么补上产出它的分支;留着等于给读者一条不存在的分支。");
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
});
|
|
437
466
|
});
|