@sleep2agi/commhub-server 0.9.0-preview.240 → 0.9.0-preview.241
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.241",
|
|
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",
|
|
@@ -865,7 +865,7 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
865
865
|
// allowed = 没打 frozen 标 ⇒ 变不变都可以,本测试不管
|
|
866
866
|
// excluded = 会变且不该被 pinned ⇒ 必须存在并在正向对照里出现(见下)
|
|
867
867
|
// 窗口显式:WINDOW_MS 写在断言里,而不是「两次读一下大概就行」。
|
|
868
|
-
test("frozen_at_boot fields
|
|
868
|
+
test("frozen_at_boot fields do not change within a declared window (and this does NOT prove the pinning is correct)", async () => {
|
|
869
869
|
const { HEALTH_FIELD_META } = await import("./server.js");
|
|
870
870
|
const WINDOW_MS = 1200;
|
|
871
871
|
expect(WINDOW_MS).toBeGreaterThan(0); // 窗口为 0 的「没变」不构成读数
|
|
@@ -1296,7 +1296,7 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
1296
1296
|
// 谓词落在**名字**上而不是「源码里出现了减法」(外部复核:
|
|
1297
1297
|
// 「`startedAt` / `lastSuccessAt` 也是减法算出来的但**稳**;只扫减法会漏掉无条件的那个」)。
|
|
1298
1298
|
// 分母必须报出来:命中 0 个差值字段 ⇒ 这条断言是真空真。
|
|
1299
|
-
test("
|
|
1299
|
+
test("difference-shaped fields name both endpoints in the same payload (proves endpoints exist, not that the value is right)", async () => {
|
|
1300
1300
|
const { HEALTH_FIELD_META } = await import("./server.js");
|
|
1301
1301
|
const DIFFY = /(age|elapsed|uptime|remaining|ttl|delta|drift|lag)/i;
|
|
1302
1302
|
const named = Object.keys(HEALTH_FIELD_META).filter((k) => DIFFY.test(k));
|
|
@@ -157,6 +157,14 @@ describe("GET /api/skills", () => {
|
|
|
157
157
|
const back = await get(`/api/providers?network_id=${ownerNet}`, ownerToken);
|
|
158
158
|
expect(back.body.state).toBe("configured");
|
|
159
159
|
expect(back.body.counts.models_enabled).toBeGreaterThan(0);
|
|
160
|
+
|
|
161
|
+
// 2026-10-31 —— **形状测试必须先证明输入彼此不同,再断言各自属性**
|
|
162
|
+
// (外部复核 ③:「顺序不能反:先断言几种形状的字节两两不等,再断言各自含有应有的属性;
|
|
163
|
+
// 反过来时『四种其实是一种』也能全绿。」)
|
|
164
|
+
// 这里是三态:删掉 state 之后,三份载荷必须两两不同 —— 否则「三态」只是同一个载荷换了标签。
|
|
165
|
+
const strip = (b: any) => { const { state: _s, ...rest } = b; return JSON.stringify(rest); };
|
|
166
|
+
const three = [strip(before.body), strip(disabled.body), strip(back.body)];
|
|
167
|
+
expect(new Set(three).size).toBe(3);
|
|
160
168
|
});
|
|
161
169
|
|
|
162
170
|
test("a member of another network is refused", async () => {
|
|
@@ -457,7 +465,7 @@ describe("GET /api/providers", () => {
|
|
|
457
465
|
// 「白名单管『怎么写』,这条管『写几处』」)。
|
|
458
466
|
// 这两张状态映射各自只能有**一处定义**,且必须被生产代码**至少读一次**:
|
|
459
467
|
// 只有定义、没有读取 ⇒ 它是一张装饰表(写 1 处、读 0 处)。
|
|
460
|
-
test("status maps are defined exactly once and
|
|
468
|
+
test("status maps are defined exactly once and read by production code (a comment mentioning them does not count)", async () => {
|
|
461
469
|
const { readFileSync, readdirSync, statSync } = await import("node:fs");
|
|
462
470
|
const { join } = await import("node:path");
|
|
463
471
|
const root = join(import.meta.dir);
|
|
@@ -518,9 +526,19 @@ describe("GET /api/providers", () => {
|
|
|
518
526
|
const { PROVIDER_WRITE_ERROR_CODES: CODES, PROVIDER_WRITE_STATUS: STATUS, providerWriteStatus: statusOf } =
|
|
519
527
|
await import("./hub-provider-config.js");
|
|
520
528
|
const CLOSED = new Set([400, 401, 403, 404, 409, 500, 503]);
|
|
529
|
+
// 2026-10-31 —— **把「恒真的断言」换成能假的那条**(外部复核 (a):
|
|
530
|
+
// 「同一个字面量 code 有两个 id 生产者,而选择依据是另一个观测量 ⇒
|
|
531
|
+
// 两条测试都没覆盖第二个分支 ⇒ `observed.id === body.error.diagnosticId` 永远成立」)。
|
|
532
|
+
//
|
|
533
|
+
// 本仓原来这里写的是 `expect(statusOf(code)).toBe(STATUS[code])` ——
|
|
534
|
+
// 而 statusOf 的实现就是 `STATUS[code] ?? 500` ⇒ 对表里的码**恒真**,
|
|
535
|
+
// 它证明不了任何东西(把状态表整个改成 200 它也绿,只要两边一起改)。
|
|
536
|
+
// ⇒ 换成两条能假、且各自守一件事的断言:
|
|
537
|
+
// ① 码清单与状态表的**键集相等**(新增一个码却没给状态 ⇒ 红)
|
|
538
|
+
// ② 每个值落在 HTTP 闭集里(有人写 299 / 0 ⇒ 红)
|
|
539
|
+
expect(Object.keys(STATUS).sort()).toEqual([...CODES].sort());
|
|
521
540
|
for (const code of CODES) {
|
|
522
|
-
expect(
|
|
523
|
-
expect(CLOSED.has(statusOf(code))).toBe(true);
|
|
541
|
+
expect(CLOSED.has(STATUS[code])).toBe(true);
|
|
524
542
|
}
|
|
525
543
|
// 镜像(must-fire):一个**不在表里**的码必须落到 500,不能落 400
|
|
526
544
|
const bogus = statusOf("definitely_not_a_listed_code" as any);
|
|
@@ -103,6 +103,16 @@ describe("assignee never contradicts a validated owner/agent_owner reference", (
|
|
|
103
103
|
expect(manual.status).toBe(200);
|
|
104
104
|
expect(manual.body.requirement.assignee).toBe("王工");
|
|
105
105
|
|
|
106
|
+
// 2026-10-31 —— **双向可测**(外部复核 ④:
|
|
107
|
+
// 「改粒度维度 ⇒ 结果变(确实相关);改其它维度 ⇒ 结果不变(确实无关)。
|
|
108
|
+
// 只做前一向时,一个『什么都相关』的模型也能满足它。」)
|
|
109
|
+
// 第一向(相关)上面已经有了:改 agent_owner ⇒ assignee 跟着变。
|
|
110
|
+
// 这一向(无关):改一个**不相干**的字段(name),assignee 必须**不变**。
|
|
111
|
+
const renamed = await send("PATCH", `/api/requirements/${id}?network_id=${NET}`, { name: "改个名字而已" });
|
|
112
|
+
expect(renamed.status).toBe(200);
|
|
113
|
+
expect(renamed.body.requirement.name).toBe("改个名字而已");
|
|
114
|
+
expect(renamed.body.requirement.assignee).toBe("asg-probe"); // 与上面那条同一张卡
|
|
115
|
+
|
|
106
116
|
// 两者**同时存在**时读侧以引用为准(这是有意的取舍:引用写入时被校验过,自由文本没有)。
|
|
107
117
|
// 记录在这里,免得下一个人把它当成 bug 再改回去。
|
|
108
118
|
const both = await send("PATCH", `/api/requirements/${id}?network_id=${NET}`, { assignee: "王工" });
|
package/src/server.ts
CHANGED
|
@@ -1756,6 +1756,33 @@ const startedAtIso = new Date(Date.now() - Math.floor(process.uptime() * 1000)).
|
|
|
1756
1756
|
|
|
1757
1757
|
const BOOT_KERNEL_START = detectKernelStart(startedAtIso);
|
|
1758
1758
|
|
|
1759
|
+
/**
|
|
1760
|
+
* 2026-10-31 —— **两条上传路径的两个逐字相同的生产者,收成一个**。
|
|
1761
|
+
*
|
|
1762
|
+
* 头像上传与文件上传各自写了一份 `earlyReject`(withCors + Connection: close)
|
|
1763
|
+
* 和一份 429 限流头(X-RateLimit-*)。计数报告实测:`x-ratelimit-limit` 等三个头各有 2 处写出点。
|
|
1764
|
+
* ⇒ 改一处只改了一半,而**没有任何测试会因为两处不一致而红**。
|
|
1765
|
+
*
|
|
1766
|
+
* 判据:这个值有几个生产者?>1 时,正确说法是「改掉了其中的 1/N」。
|
|
1767
|
+
*/
|
|
1768
|
+
function uploadEarlyReject(req: Request, res: Response): Response {
|
|
1769
|
+
// pre-drain 拒绝统一关闭连接:keepalive 上残留的 multipart 未读字节会把
|
|
1770
|
+
// 下一个请求读成垃圾。
|
|
1771
|
+
const wrapped = withCors(req, res);
|
|
1772
|
+
wrapped.headers.set("Connection", "close");
|
|
1773
|
+
return wrapped;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
function uploadRateLimitHeaders(rate: { resetAt: number; retryAfterMs?: number }): Record<string, string> {
|
|
1777
|
+
const headers: Record<string, string> = {
|
|
1778
|
+
"X-RateLimit-Limit": String(60),
|
|
1779
|
+
"X-RateLimit-Remaining": "0",
|
|
1780
|
+
"X-RateLimit-Reset": String(Math.floor(rate.resetAt / 1000)),
|
|
1781
|
+
};
|
|
1782
|
+
if (rate.retryAfterMs) headers["Retry-After"] = String(Math.ceil(rate.retryAfterMs / 1000));
|
|
1783
|
+
return headers;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1759
1786
|
function withCors(req: Request, res: Response): Response {
|
|
1760
1787
|
const headers = corsHeaders(req);
|
|
1761
1788
|
for (const [k, v] of Object.entries(headers)) {
|
|
@@ -2387,11 +2414,7 @@ return Bun.serve({
|
|
|
2387
2414
|
if (url.pathname === "/api/auth/me/avatar/upload" && req.method === "POST") {
|
|
2388
2415
|
// pre-drain 拒绝统一关闭连接:keepalive 上残留的 multipart 未读字节会把
|
|
2389
2416
|
// 下一个请求读成垃圾(与 /api/upload 的 earlyReject 同一理由)。
|
|
2390
|
-
const earlyReject = (res: Response): Response =>
|
|
2391
|
-
const wrapped = withCors(req, res);
|
|
2392
|
-
wrapped.headers.set("Connection", "close");
|
|
2393
|
-
return wrapped;
|
|
2394
|
-
};
|
|
2417
|
+
const earlyReject = (res: Response): Response => uploadEarlyReject(req, res);
|
|
2395
2418
|
const token = req.headers.get("Authorization")?.replace("Bearer ", "");
|
|
2396
2419
|
if (!token) return earlyReject(Response.json({ ok: false, error: "token required" }, { status: 401 }));
|
|
2397
2420
|
const resolved = resolveToken(token);
|
|
@@ -2404,12 +2427,7 @@ return Bun.serve({
|
|
|
2404
2427
|
const rateKey = authCtx?.tokenId ?? `ip:${getClientIP(req, server)}`;
|
|
2405
2428
|
const rate = sharedUploadRateLimiter.check(rateKey);
|
|
2406
2429
|
if (!rate.allowed) {
|
|
2407
|
-
const headers
|
|
2408
|
-
"X-RateLimit-Limit": String(60),
|
|
2409
|
-
"X-RateLimit-Remaining": "0",
|
|
2410
|
-
"X-RateLimit-Reset": String(Math.floor(rate.resetAt / 1000)),
|
|
2411
|
-
};
|
|
2412
|
-
if (rate.retryAfterMs) headers["Retry-After"] = String(Math.ceil(rate.retryAfterMs / 1000));
|
|
2430
|
+
const headers = uploadRateLimitHeaders(rate);
|
|
2413
2431
|
return earlyReject(new Response(
|
|
2414
2432
|
JSON.stringify({ ok: false, error: "rate_limited", message: "Upload rate limit exceeded (60/hour). Try again later.", retry_after_ms: rate.retryAfterMs }),
|
|
2415
2433
|
{ status: 429, headers: { ...headers, "Content-Type": "application/json; charset=utf-8" } },
|
|
@@ -5083,11 +5101,7 @@ return Bun.serve({
|
|
|
5083
5101
|
// just made it visible under aggregate `bun test` with a 12MiB
|
|
5084
5102
|
// upload immediately followed by another request. Per-file green
|
|
5085
5103
|
// hides this class of bug.
|
|
5086
|
-
const earlyReject = (res: Response): Response =>
|
|
5087
|
-
const wrapped = withCors(req, res);
|
|
5088
|
-
wrapped.headers.set("Connection", "close");
|
|
5089
|
-
return wrapped;
|
|
5090
|
-
};
|
|
5104
|
+
const earlyReject = (res: Response): Response => uploadEarlyReject(req, res);
|
|
5091
5105
|
const authErr = requireAuth(req);
|
|
5092
5106
|
if (authErr) return earlyReject(authErr);
|
|
5093
5107
|
|
|
@@ -5097,12 +5111,7 @@ return Bun.serve({
|
|
|
5097
5111
|
const rateKey = authCtx?.tokenId ?? `ip:${getClientIP(req, server)}`;
|
|
5098
5112
|
const rate = sharedUploadRateLimiter.check(rateKey);
|
|
5099
5113
|
if (!rate.allowed) {
|
|
5100
|
-
const headers
|
|
5101
|
-
"X-RateLimit-Limit": String(60),
|
|
5102
|
-
"X-RateLimit-Remaining": "0",
|
|
5103
|
-
"X-RateLimit-Reset": String(Math.floor(rate.resetAt / 1000)),
|
|
5104
|
-
};
|
|
5105
|
-
if (rate.retryAfterMs) headers["Retry-After"] = String(Math.ceil(rate.retryAfterMs / 1000));
|
|
5114
|
+
const headers = uploadRateLimitHeaders(rate);
|
|
5106
5115
|
return earlyReject(new Response(
|
|
5107
5116
|
JSON.stringify({ ok: false, error: "rate_limited", message: "Upload rate limit exceeded (60/hour). Try again later.", retry_after_ms: rate.retryAfterMs }),
|
|
5108
5117
|
{ status: 429, headers: { ...headers, "Content-Type": "application/json; charset=utf-8" } }, // #426 — legacy clients default to ISO-8859-1 without charset
|