@sleep2agi/commhub-server 0.9.0-preview.236 → 0.9.0-preview.237

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.236",
3
+ "version": "0.9.0-preview.237",
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",
@@ -480,6 +480,22 @@ describe("GET /api/providers", () => {
480
480
  // 而语义已经不是你想的那个。」)
481
481
  // ⇒ 读点必须落在**路由文件**里(server.ts),否则等于表有了、用法另有其处。
482
482
  // 位置:读点必须落在**实现或路由**里(不是只落在注释里)
483
+ // 2026-10-31 —— **兜底不许把「我们的缺陷」说成「客户端的错」**:
484
+ // 表里查不到的码 ⇒ 归因指向了错误的行动方(返回 400 会让客户端去改自己的请求)。
485
+ // 判据同「遍历每个抛点断言它不等于 catch-all」:逐个码断言它映射到**自己那一格**,
486
+ // 再断言未登记的码落 500 而不是 400。
487
+ const { PROVIDER_WRITE_ERROR_CODES: CODES, PROVIDER_WRITE_STATUS: STATUS, providerWriteStatus: statusOf } =
488
+ await import("./hub-provider-config.js");
489
+ const CLOSED = new Set([400, 401, 403, 404, 409, 500, 503]);
490
+ for (const code of CODES) {
491
+ expect(statusOf(code)).toBe(STATUS[code]);
492
+ expect(CLOSED.has(statusOf(code))).toBe(true);
493
+ }
494
+ // 镜像(must-fire):一个**不在表里**的码必须落到 500,不能落 400
495
+ const bogus = statusOf("definitely_not_a_listed_code" as any);
496
+ expect(bogus).toBe(500);
497
+ expect(bogus).not.toBe(400);
498
+
483
499
  const readerFiles = new Set(readers.map((r) => String(r.f).split("/").pop()));
484
500
  expect(readerFiles.size).toBeGreaterThan(0);
485
501
  expect([...readerFiles].some((f) => f === "server.ts" || f === "hub-provider-config.ts" || f === "requirements.ts")).toBe(true);
@@ -50,8 +50,19 @@ export const PROVIDER_WRITE_STATUS: Record<ProviderWriteErrorCode, number> = {
50
50
  hub_provider_save_failed: 500,
51
51
  vault_unavailable: 503,
52
52
  };
53
- export function providerWriteStatus(code: string): number {
54
- return (PROVIDER_WRITE_STATUS as Record<string, number>)[code] ?? 400;
53
+ /**
54
+ * 码 → HTTP 状态。
55
+ *
56
+ * 2026-10-31 —— 参数类型从 `string` 收紧到 `ProviderWriteErrorCode`:
57
+ * 之前签名收 `string`,于是「表里加码、忘了加状态」在**调用点**不会被类型拦住
58
+ * (编译器只看见一个字符串)。而 `Record<ProviderWriteErrorCode, number>` 只在
59
+ * 「用类型化的键去索引」时才保证穷尽 —— 签名放宽就等于把穷尽性丢了。
60
+ *
61
+ * 兜底也改了方向:`?? 400` 会告诉客户端「你的请求不对」,而表里查不到的码是**我们**的缺陷
62
+ * ⇒ 归因指向了错误的行动方。现在兜底返回 500(服务端错误),并让测试断言它不被 400 顶替。
63
+ */
64
+ export function providerWriteStatus(code: ProviderWriteErrorCode): number {
65
+ return PROVIDER_WRITE_STATUS[code] ?? 500;
55
66
  }
56
67
  const idValid = (id: unknown) => typeof id === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(id);
57
68
  function auth(h: Human, write: boolean, owner = false) {