@sleep2agi/commhub-server 0.9.0-preview.244 → 0.9.0-preview.245
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/ack-create-request.test.ts +2 -1
- package/src/adoption-candidates-http.test.ts +3 -0
- package/src/agent-acl-http.test.ts +16 -0
- package/src/agent-acl-slice3-http.test.ts +61 -3
- package/src/auth-sessions-http.test.ts +10 -0
- package/src/binding-generation-http.test.ts +6 -1
- package/src/create-node-unicode-name.test.ts +6 -0
- package/src/create-node-workdir.test.ts +9 -0
- package/src/daemon-token-owner-http.test.ts +5 -0
- package/src/group-messages-http.test.ts +2 -1
- package/src/health-redaction.test.ts +58 -13
- package/src/hub-catalog-read-http.test.ts +35 -0
- package/src/network-token-membership-http.test.ts +47 -0
- package/src/node-caller-identity-http.test.ts +10 -1
- package/src/node-files-transport.test.ts +3 -0
- package/src/node-health-dispatch-http.test.ts +2 -1
- package/src/node-lifecycle-read-http.test.ts +7 -0
- package/src/peer-reply-atomic.test.ts +5 -0
- package/src/requirement-events-http.test.ts +8 -1
- package/src/requirements-comment-http.test.ts +7 -0
- package/src/requirements-mcp.test.ts +2 -1
- package/src/requirements.ts +22 -0
- package/src/schedule-agent-mcp-http.test.ts +32 -0
- package/src/scheduled-backoff-http.test.ts +11 -1
- package/src/scheduled-requirement-wake-http.test.ts +8 -2
- package/src/scheduled-run-terminal.test.ts +8 -0
- package/src/start-node.test.ts +2 -1
- package/src/stats-versions-http.test.ts +65 -0
- package/src/task-lifecycle-watcher.test.ts +7 -2
- package/src/user-inbox-by-agent-http.test.ts +4 -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.245",
|
|
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",
|
|
@@ -231,7 +231,8 @@ describe("ack_create_request HANDLER — B2 audit_log daemon_capability_lied", (
|
|
|
231
231
|
expect(detail.runtime).toBe("codex-sdk");
|
|
232
232
|
expect(detail.daemon_node_id).toBe(DAEMON_NODE_ID);
|
|
233
233
|
expect(detail.error).toBe("OPENAI_API_KEY unset");
|
|
234
|
-
expect(
|
|
234
|
+
expect(Number.isFinite(detail.acked_at)).toBe(true);
|
|
235
|
+
expect(detail.acked_at).toBeGreaterThan(0); // 时间戳应为正;类型不是断言
|
|
235
236
|
});
|
|
236
237
|
|
|
237
238
|
test("does NOT write daemon_capability_lied on generic 'failed' ack (status discriminates)", async () => {
|
|
@@ -65,6 +65,9 @@ test("owner and node owner see the candidate; the report token stays out", async
|
|
|
65
65
|
const r = await raw(`/api/adoption-candidates?network_id=${owner.network_id}`, token);
|
|
66
66
|
expect(r.status).toBe(200);
|
|
67
67
|
expect(r.body.count).toBe(1);
|
|
68
|
+
// 2026-10-31 —— #3214:外层键集(候选每行的键由下面那条 toEqual 精确钉住)
|
|
69
|
+
expect(Object.keys(r.body).sort()).toEqual(["candidates", "count", "ok"]);
|
|
70
|
+
expect(r.body.candidates.length).toBe(r.body.count); // 计数与数组同源
|
|
68
71
|
expect(r.body.candidates).toEqual([{
|
|
69
72
|
node_id: ids.hand, alias: "hand-node", daemon_node_id: ids.daemon, daemon_alias: "cand-daemon",
|
|
70
73
|
hostname: "fixture-host", workdir: WORKDIR, runtime: "claude-agent-sdk", launch_hint: "tmux",
|
|
@@ -213,6 +213,17 @@ describe("restricted member with NO grants sees no agents (one test per path)",
|
|
|
213
213
|
test("POST /api/broadcast → 403", async () => {
|
|
214
214
|
expect((await send(aliceToken, "POST", `/api/broadcast?network_id=${NET}`, { message: "hi" })).status).toBe(403);
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
// 2026-10-31 —— #3214:`/api/broadcast` 此前只测过 403(拒绝路径),**成功体的形状从未被钉**。
|
|
218
|
+
// 它是会被客户端按字段名读的(recipients / message_ids 决定「发给了几个、分别是哪几条」)。
|
|
219
|
+
test("POST /api/broadcast 成功体恰好 {message_ids, ok, recipients},且两个数同源", async () => {
|
|
220
|
+
const r = await send(adminToken, "POST", `/api/broadcast?network_id=${NET}`, { message: "keyset-probe" });
|
|
221
|
+
expect(r.status).toBe(200);
|
|
222
|
+
expect(Object.keys(r.body).sort()).toEqual(["message_ids", "ok", "recipients"]);
|
|
223
|
+
expect(Array.isArray(r.body.message_ids)).toBe(true);
|
|
224
|
+
// 守恒:recipients 必须等于 message_ids 的长度(否则「发给了几个」与「列出几条」是两个读数)
|
|
225
|
+
expect(r.body.recipients).toBe(r.body.message_ids.length);
|
|
226
|
+
});
|
|
216
227
|
test("node write endpoints (delete / config / attrs / avatar) → not found", async () => {
|
|
217
228
|
expect((await send(aliceToken, "DELETE", `/api/nodes/${X.node}?network_id=${NET}`)).status).toBeGreaterThanOrEqual(403);
|
|
218
229
|
expect((await get(aliceToken, `/api/nodes/${X.node}/config?network_id=${NET}`)).status).toBeGreaterThanOrEqual(403);
|
|
@@ -644,6 +655,11 @@ describe("lifecycle", () => {
|
|
|
644
655
|
const before = db.get<{ n: number }>("SELECT COUNT(*) AS n FROM api_tokens WHERE user_id = ?1 AND network_id = ?2", carol.user!.user_id, NET)!.n;
|
|
645
656
|
const j = await send(carol.token!, "POST", "/api/networks/join", { invite_code: inv.body.invite_code });
|
|
646
657
|
expect(j.status).toBe(200);
|
|
658
|
+
// 2026-10-31 —— #3214:这个端点的成功体此前只被断言过 status。形状钉住:
|
|
659
|
+
// 恰好 {network_id, ok, role} —— 客户端按 role 决定进哪个界面,多一个键就是多一个没人读的字段。
|
|
660
|
+
expect(Object.keys(j.body).sort()).toEqual(["network_id", "ok", "role"]);
|
|
661
|
+
expect(j.body.network_id).toBe(NET);
|
|
662
|
+
expect(j.body.role).toBe("member");
|
|
647
663
|
expect((await get(carol.token!, `/api/status?network_id=${NET}`)).body.sessions).toEqual([]);
|
|
648
664
|
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM api_tokens WHERE user_id = ?1 AND network_id = ?2", carol.user!.user_id, NET)!.n).toBe(before);
|
|
649
665
|
});
|
|
@@ -148,7 +148,15 @@ describe("rename broadcast does not leak aliases to restricted members", () => {
|
|
|
148
148
|
const renameTo = async (oldAlias: string, newAlias: string) => {
|
|
149
149
|
const p = await send(adminToken, "POST", "/api/node-rename/prepare", { network_id: NET, old_alias: oldAlias, new_alias: newAlias });
|
|
150
150
|
expect(p.body.ok).toBe(true);
|
|
151
|
-
|
|
151
|
+
// 2026-10-31 —— #3214:rename 的两个端点此前只断言 ok,形状从未被钉。
|
|
152
|
+
// 形状由**真实调用**给出(我先写了一版「按 in body 过滤」的断言 —— 那是恒真的,等于没写)。
|
|
153
|
+
// prepare ⇒ {ok, txn_id} 两阶段的第一步:客户端必须拿到 txn_id 才能 commit
|
|
154
|
+
// commit ⇒ {ok, txn_id} 回执同样只这两键
|
|
155
|
+
expect(Object.keys(p.body).sort()).toEqual(["ok", "txn_id"]);
|
|
156
|
+
expect(typeof p.body.txn_id).toBe("string");
|
|
157
|
+
const c = await send(adminToken, "POST", "/api/node-rename/commit", { txn_id: p.body.txn_id });
|
|
158
|
+
expect(c.body.ok).toBe(true);
|
|
159
|
+
expect(Object.keys(c.body).sort()).toEqual(["ok", "txn_id"]);
|
|
152
160
|
};
|
|
153
161
|
await renameTo(Z.alias, "acl3-agent-z2");
|
|
154
162
|
await renameTo(X.alias, "acl3-agent-x2");
|
|
@@ -282,6 +290,21 @@ describe("human ↔ human DM (/api/dm): restricted members can talk to people",
|
|
|
282
290
|
// 任何「多加一栏」都应当是一次**有意识的**决定,而不是顺手。
|
|
283
291
|
// 这条测试钉住当前的键集(顺序无关,sorted 后比较),
|
|
284
292
|
// 让下一次加字段必须先让它变红、再明确决定要不要更新契约。
|
|
293
|
+
// 2026-10-31 —— #3275:list_node_files 的**成功体**只有三键 {ok, op, request_id}
|
|
294
|
+
// (形状由一次真实调用给出:它是「下发一个读请求」而不是「返回文件列表」,
|
|
295
|
+
// 列表在 op 里/后续拉取 —— 名字与载荷不是一回事,这是本卡第 6 次「按名字猜」被打回)。
|
|
296
|
+
describe("list_node_files: pinned success shape", () => {
|
|
297
|
+
test("⇒ {ok, op, request_id}", async () => {
|
|
298
|
+
const r = await tool(adminToken, "list_node_files", { alias: "acl3-agent-x", network_id: NET });
|
|
299
|
+
expect(Object.keys(r).sort()).toEqual(["ok", "op", "request_id"]);
|
|
300
|
+
// 2026-10-31 —— #3214 收尾:`typeof === "string"` 换成**这次到底是什么操作**。
|
|
301
|
+
// list_node_files 只是工具名;它下发的是 `files_list` 请求(列表在 get_rules_file_result 里取)。
|
|
302
|
+
// 名字与载荷不是一回事 —— 钉住 op 就是为了让「工具改了但 op 没跟上」立刻变红。
|
|
303
|
+
expect(r.op).toBe("files_list");
|
|
304
|
+
expect(r.request_id.length).toBeGreaterThan(0);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
285
308
|
describe("update_node_config 响应键集(exact key set)", () => {
|
|
286
309
|
test("成功体恰好 {apply_mode, ok, update_id},不多不少", async () => {
|
|
287
310
|
const r = await tool(adminToken, "update_node_config", {
|
|
@@ -342,7 +365,8 @@ describe("update_node_config 响应键集(exact key set)", () => {
|
|
|
342
365
|
|
|
343
366
|
const gs = await tool(adminToken, "get_session_status", { alias: "acl3-agent-x", network_id: NET });
|
|
344
367
|
expect(Object.keys(gs).sort()).toEqual(["inbox_pending", "ok", "recent_completions", "session"]);
|
|
345
|
-
expect(
|
|
368
|
+
expect(Number.isInteger(gs.inbox_pending)).toBe(true);
|
|
369
|
+
expect(gs.inbox_pending).toBeGreaterThanOrEqual(0); // 2026-10-31:类型不是断言
|
|
346
370
|
expect(Array.isArray(gs.recent_completions)).toBe(true);
|
|
347
371
|
});
|
|
348
372
|
});
|
|
@@ -414,7 +438,13 @@ describe("update_node_config 响应键集(exact key set)", () => {
|
|
|
414
438
|
let last: any = null;
|
|
415
439
|
for (let i = 0; i < 10; i++) last = await tool(ntok, "org_whoami", {});
|
|
416
440
|
expect(Object.keys(last)).toContain("pacing");
|
|
417
|
-
|
|
441
|
+
// 2026-10-31 —— #3214 收尾:`typeof === "object"` 换成键集(PollPacing 恰好三键)。
|
|
442
|
+
// 「有个对象」不能证明这个提示可用:客户端要读 recommended_interval_seconds 才停得下来。
|
|
443
|
+
expect(Object.keys(last.pacing).sort()).toEqual([
|
|
444
|
+
"calls_last_60s", "note", "recommended_interval_seconds",
|
|
445
|
+
]);
|
|
446
|
+
expect(last.pacing.calls_last_60s).toBeGreaterThanOrEqual(8); // 阈值 8 次/60 秒
|
|
447
|
+
expect(last.pacing.recommended_interval_seconds).toBeGreaterThan(0);
|
|
418
448
|
});
|
|
419
449
|
});
|
|
420
450
|
|
|
@@ -546,6 +576,34 @@ describe("update_node_config 响应键集(exact key set)", () => {
|
|
|
546
576
|
}
|
|
547
577
|
});
|
|
548
578
|
|
|
579
|
+
// 2026-10-31 —— **#3168 的核心分支此前没有任何测试**:
|
|
580
|
+
// 「节点没声明 supervisor(config_update_capable=false)、也没报 systemd_supervision」,
|
|
581
|
+
// 这条分支会给出 `restart_supervision_unknown` 警告 —— 而它正是「手工起的节点被一次
|
|
582
|
+
// restart-tier 下发弄死」的那一格。警告不是拒绝:Hub 不替调用方判断安全性,但必须说出来。
|
|
583
|
+
describe("#3168: a node that declares no supervisor gets a warning, not silence", () => {
|
|
584
|
+
test("restart-tier patch ⇒ warnings 含 restart_supervision_unknown(且 message 给出两种处置)", async () => {
|
|
585
|
+
const U = { alias: "acl3-nosup-u", node: "node_acl3_nosup_u" };
|
|
586
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, config_snapshot)
|
|
587
|
+
VALUES (?1, ?2, ?2, ?3, ?4, ?5)`,
|
|
588
|
+
[U.node, U.alias, NET, adminId, JSON.stringify({ config_update_capable: false })]);
|
|
589
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
590
|
+
node_id: U.node, base_revision: 0, patch: { channels: [] }, network_id: NET,
|
|
591
|
+
});
|
|
592
|
+
expect(r.ok).toBe(true);
|
|
593
|
+
const w = (r.warnings || []).find((x: any) => x.code === "restart_supervision_unknown");
|
|
594
|
+
expect(w).toBeTruthy();
|
|
595
|
+
// 警告必须带**可执行的处置**(否则它只是把风险念了一遍)。
|
|
596
|
+
// 实测这一支给的是「先确认它是怎么被拉起的(anet start / pm2 / systemd)」,
|
|
597
|
+
// 而 Stop→Start 那句在**另一支**(systemd_supervision=not_supervised 已报告)里。
|
|
598
|
+
expect(String(w.message)).toContain("anet start / pm2 / systemd");
|
|
599
|
+
expect(String(w.message)).toContain("restart-tier");
|
|
600
|
+
// 2026-10-31 —— **「存在」不是断言,「存在且值等于 X」才是**(外部复核 (b):
|
|
601
|
+
// 「写『存在』⇒ 它被改成任何值都绿」)。这一条把 warning 的形状也钉住:
|
|
602
|
+
// 多一个键 = 又一处没人读的字段;少一个键 = 客户端拿不到处置。
|
|
603
|
+
expect(Object.keys(w).sort()).toEqual(["code", "message"]);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
|
|
549
607
|
// 2026-10-31 —— #3171 第 2 项:restart_node 的成功体与 update_node_config 同构。
|
|
550
608
|
describe("restart_node success body", () => {
|
|
551
609
|
test("pinned key set (same shape family as update_node_config)", async () => {
|
|
@@ -81,6 +81,11 @@ describe("login / register identify the issued token", () => {
|
|
|
81
81
|
test("register returns token_id", async () => {
|
|
82
82
|
const r = await call("", "POST", "/api/auth/register", { username: `sess_reg_${Date.now()}`, password: PW });
|
|
83
83
|
expect(r.status).toBe(200);
|
|
84
|
+
// 2026-10-31 —— #3214:注册成功体的形状从未被钉(只断言了 token_id 的前缀)。
|
|
85
|
+
// 客户端要拿 token 才能用;多一个键 = 又一处没人读的字段。
|
|
86
|
+
expect(Object.keys(r.body).sort()).toEqual([
|
|
87
|
+
"network_id", "network_token", "ok", "token", "token_id", "user",
|
|
88
|
+
]);
|
|
84
89
|
expect(r.body.token_id).toMatch(/^tok_/);
|
|
85
90
|
const row = db.get<any>("SELECT token_id, name FROM api_tokens WHERE token_hash = ?1", hashToken(r.body.token));
|
|
86
91
|
expect(row.token_id).toBe(r.body.token_id);
|
|
@@ -160,6 +165,8 @@ describe("GET /api/auth/sessions", () => {
|
|
|
160
165
|
ageToken(dead.token, 40);
|
|
161
166
|
const r = await call(b.token, "GET", "/api/auth/sessions");
|
|
162
167
|
expect(r.status).toBe(200);
|
|
168
|
+
// 2026-10-31 —— #3214:列表外层键集(内层每行另有断言)
|
|
169
|
+
expect(Object.keys(r.body).sort()).toEqual(["current_token_id", "idle_timeout_days", "ok", "sessions"]);
|
|
163
170
|
expect(r.body.idle_timeout_days).toBe(30);
|
|
164
171
|
expect(r.body.current_token_id).toBe(b.token_id);
|
|
165
172
|
const ids = r.body.sessions.map((x: any) => x.token_id);
|
|
@@ -196,6 +203,9 @@ describe("revoking sessions", () => {
|
|
|
196
203
|
const other2 = await loginAs("other2");
|
|
197
204
|
const r = await call(keep.token, "POST", "/api/auth/sessions/revoke-others");
|
|
198
205
|
expect(r.status).toBe(200);
|
|
206
|
+
// 2026-10-31 —— #3214:形状钉住(此前只有值断言)
|
|
207
|
+
expect(Object.keys(r.body).sort()).toEqual(["kept_token_id", "ok", "revoked"]);
|
|
208
|
+
expect(Number.isInteger(r.body.revoked)).toBe(true);
|
|
199
209
|
expect(r.body.kept_token_id).toBe(keep.token_id);
|
|
200
210
|
expect(r.body.revoked).toBeGreaterThanOrEqual(2);
|
|
201
211
|
expect((await call(keep.token, "GET", "/api/auth/me")).status).toBe(200);
|
|
@@ -59,7 +59,12 @@ test("generation projection and unchanged created row",async()=>{
|
|
|
59
59
|
expect(r.children.find((n:any)=>n.child_node_id==="node_binding_created")).toEqual({child_node_id:"node_binding_created",alias:"created",lifecycle_state:"active"});
|
|
60
60
|
// Old consumers continue reading exactly the same fields; additive only.
|
|
61
61
|
expect(r.children.map(({child_node_id,alias,lifecycle_state,managed}:any)=>({child_node_id,alias,lifecycle_state,managed}))).toContainEqual({child_node_id:child,alias:child,lifecycle_state:"active",managed:"adopted"});
|
|
62
|
-
|
|
62
|
+
// 2026-10-31 —— #3275:unadopt_node 的成功体 {ok, status},且 status 必须是**第二终态**
|
|
63
|
+
// 「revoked」而不是「unadopted」—— 名字与载荷不是一回事(同 #3214 里 list_node_files 那一课)。
|
|
64
|
+
const un = await unadopt();
|
|
65
|
+
expect(Object.keys(un).sort()).toEqual(["ok", "status"]);
|
|
66
|
+
expect(un.status).toBe("revoked");
|
|
67
|
+
expect(un.ok).toBe(true);
|
|
63
68
|
});
|
|
64
69
|
test("token boundary denies humans general revoked and other owners",async()=>{
|
|
65
70
|
await activate();
|
|
@@ -71,6 +71,12 @@ afterAll(() => {
|
|
|
71
71
|
describe("#652 create_node via /mcp — Unicode names", () => {
|
|
72
72
|
test("「测试」 is accepted; the daemon gets the same alias", async () => {
|
|
73
73
|
const r = await create("测试");
|
|
74
|
+
// 2026-10-31 —— #3275:create_node 的成功体(此前只有 ok)。
|
|
75
|
+
// 它和 read_node_file / list_node_files **同一族**:只下发一个请求,结果去 daemon 侧取。
|
|
76
|
+
// ⇒ 形状必须一样:{ok, request_id}。名字叫「create」,载荷里却没有节点 —— 这是对的,
|
|
77
|
+
// 因为它回答的是「请求排队了没有」,不是「节点建好了没有」。
|
|
78
|
+
expect(Object.keys(r).sort()).toEqual(["ok", "request_id"]);
|
|
79
|
+
expect(typeof r.request_id).toBe("string");
|
|
74
80
|
expect(r.ok).toBe(true);
|
|
75
81
|
expect(String(r.request_id)).toMatch(/^cr_/);
|
|
76
82
|
expect(rows("测试")).toBe(1);
|
|
@@ -207,6 +207,15 @@ describe("create_node + workdir", () => {
|
|
|
207
207
|
test("list_host_supervisors (MCP) surfaces default_workdir_root for admin", async () => {
|
|
208
208
|
seed({ default_workdir_root: ROOT });
|
|
209
209
|
const r = await call(tools().list_host_supervisors, {});
|
|
210
|
+
// 2026-10-31 —— #3275:外层与每行的键集(此前只断言了 `default_workdir_root` 这个值)。
|
|
211
|
+
expect(Object.keys(r as any).sort()).toEqual(["count", "daemons", "ok"]);
|
|
212
|
+
expect(Object.keys((r as any).daemons[0]).sort()).toEqual([
|
|
213
|
+
"alias", "allowed_secret_keys", "daemon_node_id", "default_workdir_root",
|
|
214
|
+
"host_telemetry", "hostname", "last_seen_at", "online", "runtimes_supported",
|
|
215
|
+
]);
|
|
216
|
+
// 计数与数组同源(#3214 那条的镜像):`count` 是给人读的,`daemons` 是给程序读的,
|
|
217
|
+
// 两者不同源时界面上的「N 台」会与列表长度对不上。
|
|
218
|
+
expect((r as any).count).toBe((r as any).daemons.length);
|
|
210
219
|
const d = (r as any).daemons.find((x: any) => x.daemon_node_id === DAEMON_ID);
|
|
211
220
|
expect(d.default_workdir_root).toBe(ROOT);
|
|
212
221
|
});
|
|
@@ -156,6 +156,11 @@ test("legacy owner and exact bound identity remain supported", async () => {
|
|
|
156
156
|
expect(gotProbe.ok).toBe(false);
|
|
157
157
|
// 实测:错误分支多一个 reason(不是只 {error, ok})——**又一次由真实调用纠正**
|
|
158
158
|
expect(Object.keys(gotProbe).sort()).toEqual(["error", "ok", "reason"]);
|
|
159
|
+
// 2026-10-31 —— #3275:get_opencode_catalog_request 的**不存在**分支恰好两键
|
|
160
|
+
// (与 get_probe_request 的三键不同族 —— 又一次说明「错误信封不是全仓一个形状」)
|
|
161
|
+
const gotCatalog = await call(legacy, "get_opencode_catalog_request", { request_id: "cat_fixture_absent" });
|
|
162
|
+
expect(gotCatalog.ok).toBe(false);
|
|
163
|
+
expect(Object.keys(gotCatalog).sort()).toEqual(["error", "ok"]);
|
|
159
164
|
const stop = await call(owner.token, "stop_node", { node_id: child, network_id: owner.network_id });
|
|
160
165
|
expect(stop.ok).toBe(true);
|
|
161
166
|
// 2026-10-31 —— #3275 批次 2:get_stop_request 的**成功体**键集(daemon 按字段名读,
|
|
@@ -136,7 +136,8 @@ describe("send + history", () => {
|
|
|
136
136
|
expect(r.status).toBe(200);
|
|
137
137
|
expect(r.body.duplicate).toBe(false);
|
|
138
138
|
expect(r.body.message).toMatchObject({ group_id: GRP.rd, network_id: NET, sender_user_id: U.alice.id, from_session: U.alice.username, content: "大家好", kind: "group_message", direction: "out", meta_json: null });
|
|
139
|
-
expect(
|
|
139
|
+
expect(Number.isInteger(r.body.message.seq)).toBe(true);
|
|
140
|
+
expect(r.body.message.seq).toBeGreaterThanOrEqual(1); // seq 从 1 起;类型不是断言
|
|
140
141
|
expect(r.body.message.created_at).toMatch(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d{3}$/);
|
|
141
142
|
const audits = db.all<{ target_id: string }>("SELECT target_id FROM audit_log WHERE action = 'chat_group_message_sent' AND user_id = ?1", U.alice.id);
|
|
142
143
|
expect(audits.map((x) => x.target_id)).toEqual([GRP.rd]);
|
|
@@ -92,9 +92,12 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
92
92
|
expect(res.status).toBe(200);
|
|
93
93
|
const body = await res.json() as any;
|
|
94
94
|
expect(body.ok).toBe(true);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
expect(
|
|
95
|
+
// 2026-10-31 —— **类型不是断言**(外部复核:「写『存在』⇒ 它被改成任何值都绿」)。
|
|
96
|
+
// 这三行原来只断言 typeof ⇒ 一个空字符串版本号、一个负数会话数、一个 -1 连接数都会绿。
|
|
97
|
+
expect(body.version).toMatch(/^\d+\.\d+\.\d+(-[a-z0-9.]+)?$/); // 形如 0.9.0-preview.244
|
|
98
|
+
expect(Number.isInteger(body.sessions_count)).toBe(true);
|
|
99
|
+
expect(body.sessions_count).toBeGreaterThanOrEqual(0);
|
|
100
|
+
expect(Number.isInteger(body.sse_connections)).toBe(true);
|
|
98
101
|
expect(body.sse_connections).toBeGreaterThanOrEqual(1);
|
|
99
102
|
});
|
|
100
103
|
|
|
@@ -106,7 +109,12 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
106
109
|
const body = await res.json() as any;
|
|
107
110
|
expect("git_commit" in body).toBe(false);
|
|
108
111
|
expect("git_dirty" in body).toBe(false);
|
|
109
|
-
|
|
112
|
+
// 2026-10-31 —— #3214 收尾:这里原来是 `typeof === "boolean"`,它证明「有个布尔」,
|
|
113
|
+
// 不证明这个布尔**说的是实话**。改问两个投影是否一致:
|
|
114
|
+
// 匿名给「有没有」,鉴权给「是什么」⇒ 两个投影必须互相印证(同一台 server 同一 BOOT_GIT_COMMIT)。
|
|
115
|
+
// 这能抓住「匿名侧按请求现算是非、鉴权侧读启动常量」这类分叉,类型断言抓不住。
|
|
116
|
+
const authed = await (await fetch(`${BASE}/health`, { headers: { Authorization: `Bearer ${adminToken}` } })).json() as any;
|
|
117
|
+
expect(body.build_identified).toBe(authed.git_commit !== null);
|
|
110
118
|
});
|
|
111
119
|
|
|
112
120
|
test("authenticated admin /health carries git_commit (40-hex or null) and git_dirty", async () => {
|
|
@@ -119,8 +127,15 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
119
127
|
expect(isSha || value === null).toBe(true);
|
|
120
128
|
if (value !== null) expect(value).not.toBe(body.version);
|
|
121
129
|
// dirty 位必须与 sha 成对,否则 vantage 会把脏树读数当成提交。
|
|
122
|
-
|
|
123
|
-
if (value === null) expect(
|
|
130
|
+
//
|
|
131
|
+
// 2026-10-31 —— 这里原来写的是 `if (value === null) expect(git_dirty).toBe(false)`。
|
|
132
|
+
// 它与服务端的契约**相反**:server.ts 是 `git_dirty: BOOT_GIT.commit ? BOOT_GIT.dirty : null`
|
|
133
|
+
// (「commit 为空时必须是 null(不是 false)」)。
|
|
134
|
+
// 而本地跑永远走不到这一支 —— 因为仓库里**有** .git ⇒ value 非空 ⇒ 那条断言一次都没执行过。
|
|
135
|
+
// CI 的容器镜像只 COPY 源码(没有 .git)⇒ 走 null 支 ⇒ 立刻红(run 41140921488)。
|
|
136
|
+
// ⇒ 两个环境各只能看到一半,所以这里必须把**两条分支都写成断言**,而不是只写走到的那条。
|
|
137
|
+
if (value === null) expect(body.git_dirty).toBeNull();
|
|
138
|
+
else expect(typeof body.git_dirty).toBe("boolean");
|
|
124
139
|
});
|
|
125
140
|
|
|
126
141
|
// 2026-10-31 —— 拒绝计数的 **must-fire**:注入一次真实拒绝,看它跳不跳。
|
|
@@ -151,7 +166,10 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
151
166
|
// 本仓的结构比「s1 = since; v = counter; s2 = since」更强:since 与各计数在**同一份载荷**里,
|
|
152
167
|
// 单次读就原子,不存在跨越 reset 的长读。⇒ 这里把「同一个对象里」这件事钉住。
|
|
153
168
|
expect(Object.prototype.hasOwnProperty.call(before.counters, "since")).toBe(true);
|
|
154
|
-
|
|
169
|
+
// 2026-10-31 —— #3214 收尾:`typeof === "string"` 换成**同源**断言。
|
|
170
|
+
// counters.since 就是窗口起点 startedAt(server.ts: `counters: { since: startedAtIso, ... }`),
|
|
171
|
+
// 不是另取一次时间 ⇒ 两者必须逐字符相同;否则「窗口」与「计数」来自两个时钟域。
|
|
172
|
+
expect(before.counters.since).toBe(before.startedAt);
|
|
155
173
|
// 跨两次读的读者(如上面的 before/after 比较)必须自己比对 since —— 本条就是那个例子。
|
|
156
174
|
expect(before.counters.since.length).toBeGreaterThan(0);
|
|
157
175
|
const bumped = Object.keys(after.counters.task_rejections.by_reason).find(
|
|
@@ -261,6 +279,8 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
261
279
|
const { join } = await import("node:path");
|
|
262
280
|
|
|
263
281
|
// ① 覆盖:白名单里每个键都要有读者登记,反之亦然(两边同集合,防「删了白名单留下登记」)
|
|
282
|
+
// 2026-10-31 —— 同样的空集风险:两个集合同时为空时这条相等断言照样通过。
|
|
283
|
+
expect([...PUBLIC_HEALTH_KEYS].length).toBeGreaterThan(10); // 今天 51 个;钉下限而不是钉具体数
|
|
264
284
|
expect(Object.keys(PUBLIC_HEALTH_KEY_READERS).sort()).toEqual([...PUBLIC_HEALTH_KEYS].sort());
|
|
265
285
|
|
|
266
286
|
// ② 读者类别必须在闭集里(防「reader: 某个系统」这种自由文本)
|
|
@@ -421,10 +441,15 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
421
441
|
test("publishes the smallest suspend the 1% guard could actually catch", async () => {
|
|
422
442
|
const b = await (await fetch(`${BASE}/health`, { headers: { Authorization: `Bearer ${adminToken}` } })).json() as any;
|
|
423
443
|
if (b.kernel_started_at === null) return;
|
|
424
|
-
|
|
444
|
+
// 2026-10-31 —— 「是数字」不是断言(外部复核 (b)):负数、NaN、Infinity 都是 number。
|
|
445
|
+
expect(Number.isFinite(b.clk_tck_guard_min_suspend_s)).toBe(true);
|
|
446
|
+
expect(b.clk_tck_guard_min_suspend_s).toBeGreaterThanOrEqual(0);
|
|
425
447
|
// relErr ≈ 挂起 / **机器** uptime ⇒ 1% ⇒ 0.01 × host_uptime_s
|
|
426
448
|
// ⚠️ 不是 b.uptime(那是进程的),两者相差可以上万倍 —— 这一条正是在钉这个区别
|
|
427
|
-
expect(
|
|
449
|
+
expect(Number.isFinite(b.host_uptime_s)).toBe(true);
|
|
450
|
+
expect(b.host_uptime_s).toBeGreaterThanOrEqual(0);
|
|
451
|
+
// 机器 uptime 至少不短于进程 uptime(同一台机上,这是结构关系,不是巧合)
|
|
452
|
+
expect(b.host_uptime_s).toBeGreaterThanOrEqual(b.uptime - 5);
|
|
428
453
|
const expected = 0.01 * b.host_uptime_s;
|
|
429
454
|
expect(Math.abs(b.clk_tck_guard_min_suspend_s - expected)).toBeLessThanOrEqual(2);
|
|
430
455
|
expect(b.clk_tck_guard_min_suspend_s).toBeGreaterThan(0);
|
|
@@ -648,8 +673,16 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
648
673
|
// 2026-10-31 —— 镜像必须针对**同一个属性在另一种条件下确实存在**,
|
|
649
674
|
// 而不是「这个响应是 JSON」(那只排除了取错对象)。
|
|
650
675
|
const authed = await (await fetch(`${BASE}/health`, { headers: { Authorization: `Bearer ${adminToken}` } })).json() as any;
|
|
651
|
-
|
|
652
|
-
//
|
|
676
|
+
// 同一 URL、登录态下**这个字段确实存在**(值可能是 null:容器镜像里没有 .git)。
|
|
677
|
+
// 2026-10-31 —— 原来这里写 `typeof authed.git_commit === "string"`:只在**有 .git** 的环境成立,
|
|
678
|
+
// 于是它在本地永远绿、在 CI 容器里永远红(run 41140921488 的两条失败之一)。
|
|
679
|
+
// 对照的强度取决于环境,这一点必须写出来而不是假装验过:
|
|
680
|
+
expect("git_commit" in authed).toBe(true);
|
|
681
|
+
if (authed.build_identified === true) {
|
|
682
|
+
expect(typeof authed.git_commit).toBe("string"); // 有指纹 ⇒ 匿名侧确实不带,这才是有对照的读数
|
|
683
|
+
} else {
|
|
684
|
+
expect(authed.git_commit).toBeNull(); // 没有指纹 ⇒ 「匿名不带」在这一轮**没有对照**
|
|
685
|
+
}
|
|
653
686
|
});
|
|
654
687
|
|
|
655
688
|
test("version carries its role in the payload (a label, not a fingerprint)", async () => {
|
|
@@ -759,7 +792,8 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
759
792
|
if (dbBad) {
|
|
760
793
|
expect(b.sessions_count).toBeNull();
|
|
761
794
|
} else {
|
|
762
|
-
expect(
|
|
795
|
+
expect(Number.isInteger(b.sessions_count)).toBe(true);
|
|
796
|
+
expect(b.sessions_count).toBeGreaterThanOrEqual(0); // 类型不是断言
|
|
763
797
|
}
|
|
764
798
|
});
|
|
765
799
|
|
|
@@ -892,6 +926,13 @@ describe("#473 anonymous /health — watchdog contract intact, no topology leak"
|
|
|
892
926
|
const moved = pinned.filter((k) => JSON.stringify(a[k]) !== JSON.stringify(b[k]));
|
|
893
927
|
expect(moved).toEqual([]); // 声明是 pinned,就必须在窗口内真的不动
|
|
894
928
|
|
|
929
|
+
// 2026-10-31 —— **节流会让「不变」变得廉价**(外部复核:
|
|
930
|
+
// 「三个 `*_age_sec` 里有两个是 10s 节流采样的,同一秒两次读 diff 恒为 0
|
|
931
|
+
// ⇒ 会被误判成 pinned,而 pinned 正好放行最不该放行的字节比较」)。
|
|
932
|
+
// 本仓的同形风险:任何按 10s/30s 节流刷新的字段,在 1.2s 窗口里都必然「不变」。
|
|
933
|
+
// ⇒ 所以这条窗口断言**只对「启动快照族」成立**(它们与时间无关),
|
|
934
|
+
// 不能拿它去证明「这个字段是稳定的」——后者需要跨节流周期的窗口。
|
|
935
|
+
//
|
|
895
936
|
// ⚠️ 这条检查的**弱点必须写出来**(否则它会被读成比实际更强的东西):
|
|
896
937
|
// 一个值**本来就在这个窗口里不变**的字段,即使被错误地标成 pinned,也照样通过。
|
|
897
938
|
// 实测 witness:把 `sessions_count` 标成 `frozen_at_boot + stable_within:"process"`,
|
|
@@ -1637,8 +1678,12 @@ describe("#473 GET /api/stats/sse — detail survives, behind ops auth", () => {
|
|
|
1637
1678
|
expect(res.status).toBe(200);
|
|
1638
1679
|
const body = await res.json() as any;
|
|
1639
1680
|
expect(body.ok).toBe(true);
|
|
1640
|
-
expect(
|
|
1681
|
+
expect(Number.isInteger(body.total)).toBe(true);
|
|
1682
|
+
expect(body.total).toBeGreaterThanOrEqual(0); // 类型不是断言
|
|
1641
1683
|
expect(body.sessions[`${userNetworkId}:${userName}`]).toBeGreaterThanOrEqual(1);
|
|
1684
|
+
// 结构关系:total 必须等于各计数之和(否则「总数」与「明细」是两个读数)
|
|
1685
|
+
const detailSum = Object.values(body.sessions as Record<string, number>).reduce((a, b) => a + b, 0);
|
|
1686
|
+
expect(detailSum).toBe(body.total);
|
|
1642
1687
|
});
|
|
1643
1688
|
|
|
1644
1689
|
test("legacy master token → 200 (ops path — restAuth null, isLegacyAuthToken)", () => {
|
|
@@ -87,9 +87,31 @@ afterAll(() => {
|
|
|
87
87
|
try { rmSync(PRIVATE_DB_DIR, { recursive: true, force: true }); } catch {}
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
describe("GET /api/secrets: keys and timestamps only", () => {
|
|
91
|
+
test("⇒ 恰好 {keys, network_id, ok};每个 key 恰好 {key, updated_at};值从不出现", async () => {
|
|
92
|
+
const r = await get(`/api/secrets?network_id=${ownerNet}`, ownerToken);
|
|
93
|
+
expect(r.status).toBe(200);
|
|
94
|
+
expect(Object.keys(r.body).sort()).toEqual(["keys", "network_id", "ok"]);
|
|
95
|
+
for (const k of r.body.keys as any[]) {
|
|
96
|
+
expect(Object.keys(k).sort()).toEqual(["key", "updated_at"]);
|
|
97
|
+
}
|
|
98
|
+
// 哨兵:本测试里写进 vault 的那个值,任何情况下都不许出现在响应里
|
|
99
|
+
expect(r.text).not.toContain(SECRET_VALUE);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
90
103
|
describe("GET /api/skills", () => {
|
|
91
104
|
test("owner sees published skills and no content body", async () => {
|
|
92
105
|
const r = await get(`/api/skills?network_id=${ownerNet}`, ownerToken);
|
|
106
|
+
// 2026-10-31 —— #3214:这两个只读目录端点的**键集**从未被钉(只断言了内容)。
|
|
107
|
+
// 多一个键 = 又一处没人读的字段;少一个键 = 客户端拿不到分页/审核信息。
|
|
108
|
+
expect(Object.keys(r.body).sort()).toEqual(["network_id", "ok", "reviewer", "skills"]);
|
|
109
|
+
if ((r.body.skills as any[]).length > 0) {
|
|
110
|
+
expect(Object.keys((r.body.skills as any[])[0]).sort()).toEqual([
|
|
111
|
+
"created_at", "description", "name", "review_note", "reviewed_at",
|
|
112
|
+
"skill_id", "slug", "source_alias", "source_type", "status", "updated_at", "version",
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
93
115
|
expect(r.status).toBe(200);
|
|
94
116
|
expect(r.body.ok).toBe(true);
|
|
95
117
|
expect(r.body.reviewer).toBe(true);
|
|
@@ -354,7 +376,14 @@ describe("GET /api/providers", () => {
|
|
|
354
376
|
expect(c.body.state).toBe("applied");
|
|
355
377
|
expect(c.body.selection).toMatchObject({ provider_id: "main", model: "m1" });
|
|
356
378
|
expect(c.body.revision).toBe(7);
|
|
379
|
+
// 2026-10-31 —— 「存在/类型」不是断言(外部复核 (b)):
|
|
380
|
+
// observed_at 是「这份 selection 是什么时候观测到的」,它必须**可解析**且**不晚于现在**,
|
|
381
|
+
// 否则它只是一个格式正确的字符串。
|
|
357
382
|
expect(typeof c.body.observed_at).toBe("string");
|
|
383
|
+
const observedMs = Date.parse(c.body.observed_at);
|
|
384
|
+
expect(Number.isFinite(observedMs)).toBe(true);
|
|
385
|
+
expect(observedMs).toBeLessThanOrEqual(Date.now() + 1000);
|
|
386
|
+
expect(observedMs).toBeGreaterThan(Date.now() - 86_400_000); // 不该是 1970 或其他纪元
|
|
358
387
|
|
|
359
388
|
// ④ 失败:必须带 error(否则界面只能说「失败了」)
|
|
360
389
|
q("dpa_probe_3", "failed", null, "daemon_rejected_selection");
|
|
@@ -560,6 +589,12 @@ describe("GET /api/providers", () => {
|
|
|
560
589
|
// ⇒ 换成两条能假、且各自守一件事的断言:
|
|
561
590
|
// ① 码清单与状态表的**键集相等**(新增一个码却没给状态 ⇒ 红)
|
|
562
591
|
// ② 每个值落在 HTTP 闭集里(有人写 299 / 0 ⇒ 红)
|
|
592
|
+
// 2026-10-31 —— **值域由代码导出时,先证它非空**(外部复核:
|
|
593
|
+
// 「若导出为空 ⇒ 谓词变成空值域 ⇒ 负断言『不得出现 ∈ ∅』恒真;
|
|
594
|
+
// 比手写更危险:手写至少会写错成一个大集合,导出失败会变成空集」)。
|
|
595
|
+
// 下面那条键集相等:若 CODES 与 STATUS 同时为空,它同样通过 —— 所以先钉分母。
|
|
596
|
+
expect(CODES.length).toBeGreaterThan(0);
|
|
597
|
+
expect(Object.keys(STATUS).length).toBe(CODES.length);
|
|
563
598
|
expect(Object.keys(STATUS).sort()).toEqual([...CODES].sort());
|
|
564
599
|
for (const code of CODES) {
|
|
565
600
|
expect(CLOSED.has(STATUS[code])).toBe(true);
|
|
@@ -45,6 +45,53 @@ const GETS = () => [
|
|
|
45
45
|
`/api/task/${taskId}`, "/api/tasks", "/api/completions", "/api/dm/threads", "/api/requirements",
|
|
46
46
|
];
|
|
47
47
|
|
|
48
|
+
// 2026-10-31 —— #3214:上面那张 GETS 清单把这些端点**打过一遍**(只看状态码),
|
|
49
|
+
// 但成功体的形状从未被钉。这里挑一个结构最简单的先钉住:
|
|
50
|
+
// GET /api/completions ⇒ {completions, ok},且 completions 是数组(客户端按此分页/渲染)
|
|
51
|
+
// 2026-10-31 —— #3214 续:同一张 GETS 清单里的另外两个读面,形状也从未被钉。
|
|
52
|
+
describe("GET /api/servers 与 /api/host-supervisors: shape", () => {
|
|
53
|
+
test("/api/servers ⇒ {ok, servers} 且每台机器字段固定", async () => {
|
|
54
|
+
const r = await fetch(`${base}/api/servers?network_id=${net}`, {
|
|
55
|
+
headers: { Authorization: `Bearer ${tok.bossUser}` },
|
|
56
|
+
});
|
|
57
|
+
expect(r.status).toBe(200);
|
|
58
|
+
const b = await r.json() as any;
|
|
59
|
+
// ⚠️ 实测:这个端点返回**裸数组**,不是 {ok, servers}(我按同族猜错了 —— 本卡第 N 次)
|
|
60
|
+
expect(Array.isArray(b)).toBe(true);
|
|
61
|
+
for (const srv of b as any[]) {
|
|
62
|
+
expect(Object.keys(srv).sort()).toEqual([
|
|
63
|
+
"agent_count", "cpu_cores", "cpu_load_1min", "hostname", "ip",
|
|
64
|
+
"last_seen", "mem_avail_gb", "mem_used_gb",
|
|
65
|
+
]);
|
|
66
|
+
expect(typeof srv.hostname).toBe("string");
|
|
67
|
+
expect(Number.isInteger(srv.agent_count)).toBe(true);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("/api/host-supervisors ⇒ {count, daemons, ok};受限成员拿到空列表也算读数", async () => {
|
|
72
|
+
const r = await fetch(`${base}/api/host-supervisors?network_id=${net}`, {
|
|
73
|
+
headers: { Authorization: `Bearer ${tok.bossUser}` },
|
|
74
|
+
});
|
|
75
|
+
expect(r.status).toBe(200);
|
|
76
|
+
const b = await r.json() as any;
|
|
77
|
+
expect(Object.keys(b).sort()).toEqual(["count", "daemons", "ok"]);
|
|
78
|
+
expect(Array.isArray(b.daemons)).toBe(true);
|
|
79
|
+
expect(b.count).toBe(b.daemons.length); // 计数与数组同源
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("GET /api/completions: shape", () => {
|
|
84
|
+
test("⇒ {completions, ok} 且 completions 为数组", async () => {
|
|
85
|
+
const r = await fetch(`${base}/api/completions?network_id=${net}`, {
|
|
86
|
+
headers: { Authorization: `Bearer ${tok.bossUser}` },
|
|
87
|
+
});
|
|
88
|
+
expect(r.status).toBe(200);
|
|
89
|
+
const b = await r.json() as any;
|
|
90
|
+
expect(Object.keys(b).sort()).toEqual(["completions", "ok"]);
|
|
91
|
+
expect(Array.isArray(b.completions)).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
48
95
|
beforeAll(async () => {
|
|
49
96
|
const boss = register(`tm_boss_${stamp}`, PW); net = boss.network_id!; ids.boss = boss.user!.user_id; tok.bossUser = boss.token!;
|
|
50
97
|
for (const k of ["exm", "rem", "mia", "stay"]) {
|
|
@@ -144,7 +144,16 @@ test("rename registry: another network's node does not reserve the local alias",
|
|
|
144
144
|
seedNode(`n_idv_foreign_target_${stamp}`, target, NET2, outsiderId);
|
|
145
145
|
const prepared = await api(ownerToken, "POST", "/api/node-rename/prepare", { network_id: NET, old_alias: victimAlias, new_alias: target });
|
|
146
146
|
expect(prepared.body.ok).toBe(true);
|
|
147
|
-
|
|
147
|
+
// 2026-10-31 —— #3214:abort 的成功体形状此前完全没钉(只断言了 ok)。
|
|
148
|
+
// 形状由真实调用给出:{ok, txn_id},且回执里的 txn_id 必须是**被取消的那一笔** ——
|
|
149
|
+
// 客户端靠它把本地 pending 的 prepare 清掉,回错 id 就等于没清。
|
|
150
|
+
const aborted = await api(ownerToken, "POST", "/api/node-rename/abort", { txn_id: prepared.body.txn_id });
|
|
151
|
+
expect(Object.keys(aborted.body).sort()).toEqual(["ok", "txn_id"]);
|
|
152
|
+
expect(aborted.body.txn_id).toBe(prepared.body.txn_id);
|
|
153
|
+
// 幂等:再 abort 一次仍是同一对(rename.ts 里 `status === "aborted"` 分支显式回落)
|
|
154
|
+
const again = await api(ownerToken, "POST", "/api/node-rename/abort", { txn_id: prepared.body.txn_id });
|
|
155
|
+
expect(Object.keys(again.body).sort()).toEqual(["ok", "txn_id"]);
|
|
156
|
+
expect(again.body.txn_id).toBe(prepared.body.txn_id);
|
|
148
157
|
});
|
|
149
158
|
|
|
150
159
|
test("rename registry: a free alias commits and preserves node identity", async () => {
|
|
@@ -182,6 +182,9 @@ describe("list / read by alias reach a session with no nodes row", () => {
|
|
|
182
182
|
const s = await connect(asSession);
|
|
183
183
|
try {
|
|
184
184
|
const enq = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "docs/README.md" });
|
|
185
|
+
// 2026-10-31 —— #3275:read_node_file 与 list_node_files 是**同一族**(都只是下发请求),
|
|
186
|
+
// 所以形状也应当一样:{ok, op, request_id}。钉住它,顺带钉住「两个工具不能长成两种形状」。
|
|
187
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
185
188
|
expect(enq).toMatchObject({ ok: true, op: "file_read" });
|
|
186
189
|
expect((await s.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "file_read", content: "docs/README.md" });
|
|
187
190
|
const payload = JSON.stringify({ path: "docs/README.md", name: "README.md", kind: "text", size: 6, content: "# hi\n" });
|
|
@@ -168,7 +168,8 @@ describe("#460 REST /api/task", () => {
|
|
|
168
168
|
expect(r.body.message).toContain("App Server 断开");
|
|
169
169
|
expect(r.body.hint).toContain("force=true");
|
|
170
170
|
expect(r.body.force_allowed).toBe(true);
|
|
171
|
-
expect(
|
|
171
|
+
expect(Number.isFinite(r.body.health_observed_ms_ago)).toBe(true);
|
|
172
|
+
expect(r.body.health_observed_ms_ago).toBeGreaterThanOrEqual(0); // 类型不是断言
|
|
172
173
|
expect(taskCount()).toBe(before);
|
|
173
174
|
});
|
|
174
175
|
|
|
@@ -133,6 +133,13 @@ test("adopt query preserves all persisted states, request id and bounded project
|
|
|
133
133
|
for (const status of ["pending", "active", "refused", "revoked"]) {
|
|
134
134
|
const r = await get(query("adopt", `request_id=adopt_read_${status}`));
|
|
135
135
|
expect(r.status).toBe(200);
|
|
136
|
+
console.log("LIFE_KEYS=" + JSON.stringify(Object.keys(r.body).sort()) + " REQ_KEYS=" + JSON.stringify(Object.keys(r.body.request).sort()));
|
|
137
|
+
// 2026-10-31 —— #3214:外层与 request 的键集都由真实调用给出(此前只断言了值)
|
|
138
|
+
expect(Object.keys(r.body).sort()).toEqual(["ok", "request"]);
|
|
139
|
+
expect(Object.keys(r.body.request).sort()).toEqual([
|
|
140
|
+
"created_at", "daemon_node_id", "error", "kind", "network_id",
|
|
141
|
+
"node_id", "request_id", "status", "updated_at",
|
|
142
|
+
]);
|
|
136
143
|
expect(r.body.request).toMatchObject({ kind: "adopt", status, request_id: `adopt_read_${status}` });
|
|
137
144
|
expect(r.body.request.workdir).toBeUndefined();
|
|
138
145
|
expect(r.body.request.requested_by).toBeUndefined();
|
|
@@ -123,6 +123,11 @@ describe("#698 atomic peer reply", () => {
|
|
|
123
123
|
const result = await call(toolsFor(B).send_peer_reply, {
|
|
124
124
|
alias: A, text: "bound-token wins", in_reply_to: taskId, status: "replied",
|
|
125
125
|
});
|
|
126
|
+
// 2026-10-31 —— #3275:send_peer_reply 的形状(此前只断言 ok)。
|
|
127
|
+
// 三键各有用处:message_id 是这条回复的收据;session_status 让调用方不必再查一次
|
|
128
|
+
// 「我这边的会话现在是什么状态」——原子性就体现在这里:回复落库与会话状态是同一次写。
|
|
129
|
+
expect(Object.keys(result).sort()).toEqual(["message_id", "ok", "session_status"]);
|
|
130
|
+
expect(result.session_status).toBe("idle");
|
|
126
131
|
expect(result.ok).toBe(true);
|
|
127
132
|
expect(task(taskId).status).toBe("replied");
|
|
128
133
|
});
|
|
@@ -247,11 +247,18 @@ describe("requirement events", () => {
|
|
|
247
247
|
await patch(admin.token, card.id, { participants: [user(admin.id), { kind: "node", id: NODE }] });
|
|
248
248
|
const seen = of((await events(restricted.token)).body.events, card.id);
|
|
249
249
|
const all = of((await events(admin.token)).body.events, card.id);
|
|
250
|
-
|
|
250
|
+
// 2026-10-31 —— 加了 `assignee` 这一条:它是**派生展示字段**(写侧在设 agent_owner 时
|
|
251
|
+
// 同步回填),存的是**别名字符串**而不是 {kind,id} 引用。列表顺序按事件 id 倒序 ⇒
|
|
252
|
+
// 它排在 agent_owner 之后、priority 之前。
|
|
253
|
+
expect(all.map((e: any) => e.field)).toEqual(["participants", "agent_owner", "assignee", "priority", null]);
|
|
254
|
+
expect(all[2]).toMatchObject({ field: "assignee", old: null, new: "ev-node" });
|
|
255
|
+
// 受限成员那边:agent_owner 与**由它派生的 assignee** 都必须消失(后者是别名字符串,
|
|
256
|
+
// 不走 isHiddenRef,2026-10-31 实测会漏;见 requirements.ts 的 hiddenAlias)。
|
|
251
257
|
expect(seen.map((e: any) => e.field)).toEqual(["participants", "priority", null]);
|
|
252
258
|
expect(seen[0]).toMatchObject({ old: [], new: [user(admin.id)] });
|
|
253
259
|
expect(seen[1]).toMatchObject({ field: "priority", actor: null });
|
|
254
260
|
expect(JSON.stringify(seen)).not.toContain(NODE);
|
|
261
|
+
expect(JSON.stringify(seen)).not.toContain("ev-node"); // ← 别名也不能漏
|
|
255
262
|
});
|
|
256
263
|
|
|
257
264
|
test("paging: newest first, limit + next_cursor without overlap; since; bad params 400", async () => {
|
|
@@ -82,6 +82,13 @@ describe("requirements_comment", () => {
|
|
|
82
82
|
const before = cardRow(card.id);
|
|
83
83
|
const r = await mcp(U.nodeA.token, "requirements_comment", { id: `#${card.seq}`, text: "进展:示例草稿已写完,等人看。" });
|
|
84
84
|
expect(r.ok).toBe(true);
|
|
85
|
+
// 2026-10-31 —— #3275:requirements_comment 的形状(此前只有值断言)。
|
|
86
|
+
// 事件对象的键集由真实调用给出;`old`/`field` 对 comment 是**空占位**(注释不是字段改动),
|
|
87
|
+
// 但它们在键集里 ⇒ 客户端可以统一用「字段改动」的渲染器读注释事件。
|
|
88
|
+
expect(Object.keys(r).sort()).toEqual(["event", "ok"]);
|
|
89
|
+
expect(Object.keys(r.event).sort()).toEqual([
|
|
90
|
+
"actor", "at", "field", "id", "kind", "new", "old", "requirement_id", "seq", "title",
|
|
91
|
+
]);
|
|
85
92
|
expect(r.event.kind).toBe("comment");
|
|
86
93
|
expect(r.event.field).toBeNull();
|
|
87
94
|
expect(r.event.new).toEqual({ text: "进展:示例草稿已写完,等人看。" });
|
|
@@ -120,7 +120,8 @@ describe("requirements MCP tools", () => {
|
|
|
120
120
|
const slimRow = slim.requirements.find((r: any) => r.id === id);
|
|
121
121
|
expect(slim.view).toBe("summary");
|
|
122
122
|
expect("description" in slimRow).toBe(false);
|
|
123
|
-
expect(
|
|
123
|
+
expect(Number.isInteger(slimRow.checklist_count.total)).toBe(true);
|
|
124
|
+
expect(slimRow.checklist_count.total).toBeGreaterThanOrEqual(0); // 类型不是断言
|
|
124
125
|
expect(typeof slimRow.has_description).toBe("boolean");
|
|
125
126
|
expect((await s.call("requirements_list", { view: "tiny" })).mcpError).toBe(true);
|
|
126
127
|
expect((await s.call("requirements_list", { changes: true })).error).toBe("updated_since_required");
|
package/src/requirements.ts
CHANGED
|
@@ -1772,6 +1772,23 @@ function listEvents(ctx: RequirementsRequestContext): Response {
|
|
|
1772
1772
|
const serverTime = new Date().toISOString();
|
|
1773
1773
|
const caller = taskCaller(ctx);
|
|
1774
1774
|
const hidden = hiddenNodeFilter(ctx, networkId);
|
|
1775
|
+
// 2026-10-31 —— `assignee` 是**派生展示字段**,存的是**别名字符串**,不是 {kind,id} 引用。
|
|
1776
|
+
// 于是它绕过了 isHiddenRef:受限成员会在事件里读到「某个他看不见的 Agent 的名字」。
|
|
1777
|
+
// 实测(本仓):把 agent_owner 设成一个受限成员看不见的节点后,事件列表里多出
|
|
1778
|
+
// { field:"assignee", old:null, new:"<那个节点的别名>" }
|
|
1779
|
+
// 而同一张卡的 agent_owner 事件已被正确抹掉 ⇒ 名字从旁边漏了出去。
|
|
1780
|
+
// 修法:按「隐藏节点的别名集合」判,命中就抹成 null;随后「抹后 old==new」的规则会把整条丢弃。
|
|
1781
|
+
// 方向选择:宁可多抹(隐藏)也不多露 —— 别名与人名冲突时,少显示一个名字的代价小于多露一个。
|
|
1782
|
+
let hiddenAliases: Set<string> | null = null;
|
|
1783
|
+
const hiddenAlias = (v: unknown): boolean => {
|
|
1784
|
+
if (!hidden || typeof v !== "string" || !v) return false;
|
|
1785
|
+
if (hiddenAliases === null) {
|
|
1786
|
+
const rows = db.all<{ node_id: string; alias: string | null }>(
|
|
1787
|
+
"SELECT node_id, alias FROM nodes WHERE network_id = ?1", networkId);
|
|
1788
|
+
hiddenAliases = new Set(rows.filter(r => r.alias && hidden(r.node_id)).map(r => r.alias as string));
|
|
1789
|
+
}
|
|
1790
|
+
return hiddenAliases.has(v);
|
|
1791
|
+
};
|
|
1775
1792
|
const aware = knowsAbandoned(ctx);
|
|
1776
1793
|
const seen = new Map<string, boolean>();
|
|
1777
1794
|
const canSee = (id: string): boolean => {
|
|
@@ -1794,6 +1811,11 @@ function listEvents(ctx: RequirementsRequestContext): Response {
|
|
|
1794
1811
|
const mask = (ref: unknown) => (isHiddenRef(ref, hidden) ? null : ref);
|
|
1795
1812
|
const masked = { ...ev, actor: mask(ev.actor) };
|
|
1796
1813
|
if (ev.field === "owner" || ev.field === "agent_owner") { masked.old = mask(ev.old); masked.new = mask(ev.new); }
|
|
1814
|
+
if (ev.field === "assignee") {
|
|
1815
|
+
// 见上:别名字符串同样要按隐藏节点判定
|
|
1816
|
+
masked.old = hiddenAlias(ev.old) ? null : ev.old;
|
|
1817
|
+
masked.new = hiddenAlias(ev.new) ? null : ev.new;
|
|
1818
|
+
}
|
|
1797
1819
|
if (ev.field === "participants") {
|
|
1798
1820
|
masked.old = Array.isArray(ev.old) ? ev.old.filter(ref => !isHiddenRef(ref, hidden)) : ev.old;
|
|
1799
1821
|
masked.new = Array.isArray(ev.new) ? ev.new.filter(ref => !isHiddenRef(ref, hidden)) : ev.new;
|
|
@@ -79,6 +79,13 @@ describe("happy path from a node", () => {
|
|
|
79
79
|
test("create (default target = self) → list / get / update / pause / run_now / runs / cancel", async () => {
|
|
80
80
|
const c = await create("a");
|
|
81
81
|
expect(c.ok).toBe(true);
|
|
82
|
+
// 2026-10-31 —— #3275:schedule_* 九件此前一条键集断言都没有(报告里这九个是 uncovered)。
|
|
83
|
+
// 形状全部由**真实调用**给出,不是从类型定义推的。
|
|
84
|
+
expect(Object.keys(c).sort()).toEqual(["ok", "schedule"]);
|
|
85
|
+
expect(Object.keys(c.schedule).sort()).toEqual(["created_at", "created_by_node_id", "last_run_at", "misfire_policy", "name",
|
|
86
|
+
"network_id", "next_run_at", "overlap_policy", "priority", "revision", "schedule",
|
|
87
|
+
"schedule_id", "schedule_type", "status", "target_alias", "target_node_id",
|
|
88
|
+
"task_content", "timezone", "updated_at"]);
|
|
82
89
|
const s = c.schedule;
|
|
83
90
|
expect(s.target_node_id).toBe(node.a.id);
|
|
84
91
|
expect(s.created_by_node_id).toBe(node.a.id);
|
|
@@ -87,20 +94,45 @@ describe("happy path from a node", () => {
|
|
|
87
94
|
expect(storedRow(s.schedule_id)).toEqual({ created_by: user.boss.id, created_by_node_id: node.a.id });
|
|
88
95
|
|
|
89
96
|
const l = await mcp(node.a.token, "schedule_list");
|
|
97
|
+
expect(Object.keys(l).sort()).toEqual(["ok", "schedules"]);
|
|
98
|
+
// **同一个 schedule 对象,两条路两个形状** —— 这正是客户端最容易踩的那类差异:
|
|
99
|
+
// create ⇒ 19 键(存下来的行)
|
|
100
|
+
// list ⇒ 22 键(行 + 三个**算出来的**字段:p50 / 周期短于一次运行 / 建议间隔)
|
|
101
|
+
// 所以不只钉两边,还钉**差集恰好是那三个**(多一个少一个都要先变红)。
|
|
102
|
+
expect(Object.keys(l.schedules[0]).sort()).toEqual(["created_at", "created_by_node_id", "last_run_at", "misfire_policy", "name",
|
|
103
|
+
"network_id", "next_run_at", "observed_run_seconds_p50", "overlap_policy",
|
|
104
|
+
"period_shorter_than_run", "priority", "revision", "schedule", "schedule_id",
|
|
105
|
+
"schedule_type", "status", "suggested_every_seconds", "target_alias",
|
|
106
|
+
"target_node_id", "task_content", "timezone", "updated_at"]);
|
|
107
|
+
expect(Object.keys(l.schedules[0]).filter((k) => !(k in s)).sort()).toEqual(["observed_run_seconds_p50", "period_shorter_than_run", "suggested_every_seconds"]);
|
|
90
108
|
expect(l.schedules.map((x: any) => x.schedule_id)).toContain(s.schedule_id);
|
|
91
109
|
expect((await mcp(node.a.token, "schedule_get", { schedule_id: s.schedule_id })).schedule.name).toBe(s.name);
|
|
92
110
|
|
|
93
111
|
const u = await mcp(node.a.token, "schedule_update", { schedule_id: s.schedule_id, name: "renamed", schedule: { type: "daily", time: "09:30" }, timezone: "Asia/Shanghai" });
|
|
94
112
|
expect(u.ok).toBe(true);
|
|
113
|
+
// update 回执的外层与 create 一致;内层是**同一个 schedule 投影**(不是另起一套)。
|
|
114
|
+
expect(Object.keys(u).sort()).toEqual(["ok", "schedule"]);
|
|
115
|
+
expect(Object.keys(u.schedule).sort()).toEqual(Object.keys(s).sort());
|
|
95
116
|
expect(u.schedule).toMatchObject({ name: "renamed", schedule_type: "daily", timezone: "Asia/Shanghai", revision: s.revision + 1 });
|
|
96
117
|
const p = await mcp(node.a.token, "schedule_update", { schedule_id: s.schedule_id, status: "paused" });
|
|
97
118
|
expect(p.schedule).toMatchObject({ status: "paused", next_run_at: null });
|
|
98
119
|
|
|
99
120
|
const r = await mcp(node.a.token, "schedule_run_now", { schedule_id: s.schedule_id });
|
|
100
121
|
expect(r.ok).toBe(true);
|
|
122
|
+
// ⚠️ 一个**命名不一致**,钉住它而不是顺手改掉(改它是对外契约变更):
|
|
123
|
+
// 其余字段全是 snake_case,只有 run_now 回 `runId` / `taskId` 两个驼峰键。
|
|
124
|
+
expect(Object.keys(r).sort()).toEqual(["ok", "runId", "status", "taskId"]);
|
|
101
125
|
expect(r.taskId).toBeTruthy();
|
|
102
126
|
expect(db.get<{ to_name: string; from_name: string }>("SELECT to_name, from_name FROM tasks WHERE task_id = ?1", r.taskId)).toEqual({ to_name: node.a.alias, from_name: "scheduler" });
|
|
103
127
|
const runs = await mcp(node.a.token, "schedule_runs", { schedule_id: s.schedule_id });
|
|
128
|
+
// 外层是「这条 schedule 的失败面貌」(连续失败数 + 阈值 + 上次告警时刻),
|
|
129
|
+
// 内层是每次运行的记录;同一响应里 ⇒ 客户端回答「为什么没跑」不必再取一次。
|
|
130
|
+
expect(Object.keys(runs).sort()).toEqual([
|
|
131
|
+
"consecutive_failures", "failure_alert_threshold", "last_failure_alert_at", "ok", "runs",
|
|
132
|
+
]);
|
|
133
|
+
expect(Object.keys(runs.runs[0]).sort()).toEqual(["blocked_by_state", "blocked_by_task_id", "completed_at", "created_at",
|
|
134
|
+
"error_code", "error_message", "run_id", "schedule_id", "schedule_revision",
|
|
135
|
+
"scheduled_for", "status", "task_id", "work_outcome", "work_outcome_node_id"]);
|
|
104
136
|
expect(runs.runs.map((x: any) => x.task_id)).toContain(r.taskId);
|
|
105
137
|
|
|
106
138
|
expect(await mcp(node.a.token, "schedule_cancel", { schedule_id: s.schedule_id })).toEqual({ ok: true, status: "cancelled" });
|
|
@@ -116,7 +116,17 @@ describe("#1278 opt-in durable no-change backoff through real HTTP/MCP", () => {
|
|
|
116
116
|
const latest = db.get<any>("SELECT task_id FROM scheduled_task_runs WHERE run_id = ?1", before.backoff_last_run_id)!;
|
|
117
117
|
expect((await reply(latest.task_id, { scheduled_work_outcome: "no_changes" })).ok).toBe(false);
|
|
118
118
|
syncScheduledRunForTask(latest.task_id, network); expect(state(scheduleId)).toEqual(before);
|
|
119
|
-
|
|
119
|
+
// 2026-10-31 —— 这里原来写的是**相对路径** `'./server/src/db.ts'` + `cwd: process.cwd()`。
|
|
120
|
+
// 那只在「从仓库根跑」时成立;从 `server/` 跑(scripts/run-server-tests.sh 就是这么跑的)
|
|
121
|
+
// 子进程立刻退出 1,于是这条断言长期在本地是红的、而看起来像「另一个进程也不能加两次」失败。
|
|
122
|
+
// ⇒ 用 import.meta.dir 拼**绝对路径**:断言要测的是并发语义,不该顺带测 cwd。
|
|
123
|
+
const dbTs = new URL("./db.ts", import.meta.url).pathname;
|
|
124
|
+
const backoffTs = new URL("./scheduled-backoff.ts", import.meta.url).pathname;
|
|
125
|
+
const child = Bun.spawn([process.execPath, "-e",
|
|
126
|
+
`import {db} from ${JSON.stringify(dbTs)}; import {refreshScheduledBackoff} from ${JSON.stringify(backoffTs)};`
|
|
127
|
+
+ ` db.transaction(()=>refreshScheduledBackoff(${JSON.stringify(scheduleId)},${JSON.stringify(network)}));`
|
|
128
|
+
+ ` console.log(JSON.stringify(db.get('SELECT backoff_streak,backoff_effective_seconds FROM scheduled_tasks WHERE schedule_id=?1',${JSON.stringify(scheduleId)})));`],
|
|
129
|
+
{ cwd: process.cwd(), stdout: "pipe", stderr: "pipe", env: process.env });
|
|
120
130
|
const output = await new Response(child.stdout).text(); expect(await child.exited).toBe(0);
|
|
121
131
|
expect(JSON.parse(output.trim().split("\n").at(-1)!)).toEqual({ backoff_streak: 3, backoff_effective_seconds: 600 });
|
|
122
132
|
expect(state(scheduleId)).toEqual(before);
|
|
@@ -110,7 +110,11 @@ describe("#1279 authoritative scoped requirement-event wake over HTTP/MCP", () =
|
|
|
110
110
|
});
|
|
111
111
|
test("old events and duplicate consumption do not replay after enable or process reopen", async () => {
|
|
112
112
|
await card(); const { scheduleId } = await atThree(), before = state(scheduleId); expect(poll(scheduleId)).toBe(false);
|
|
113
|
-
|
|
113
|
+
// 2026-10-31 —— 绝对路径,不再用 `'./server/src/…'` + `cwd: process.cwd()`。
|
|
114
|
+
// 那种写法只在「从仓库根跑」时成立;从 `server/` 跑(scripts/run-server-tests.sh 就是这样)
|
|
115
|
+
// 子进程立刻退出 1,于是断言长期红着,而看起来像被测行为失败。断言不该顺带测 cwd。
|
|
116
|
+
const wakeTs = new URL("./scheduled-requirement-wake.ts", import.meta.url).pathname;
|
|
117
|
+
const child = Bun.spawn([process.execPath, "-e", `import {consumeRequirementWake} from ${JSON.stringify(wakeTs)}; console.log(JSON.stringify({wake:consumeRequirementWake(${JSON.stringify(scheduleId)},${JSON.stringify(network)})}));`], { cwd: process.cwd(), stdout: "pipe", stderr: "pipe", env: process.env });
|
|
114
118
|
const output = await new Response(child.stdout).text(); expect(await child.exited).toBe(0);
|
|
115
119
|
expect(JSON.parse(output.trim().split("\n").at(-1)!)).toEqual({ wake: false }); expect(state(scheduleId)).toEqual(before);
|
|
116
120
|
});
|
|
@@ -246,7 +250,9 @@ describe("#1279 authoritative scoped requirement-event wake over HTTP/MCP", () =
|
|
|
246
250
|
});
|
|
247
251
|
test("two independent SQLite processes consume the event once and persist one generation",async()=>{
|
|
248
252
|
const {scheduleId}=await atThree();await card();const before=state(scheduleId), gate=`/tmp/wake1279-${crypto.randomUUID()}`;
|
|
249
|
-
|
|
253
|
+
// 同上:绝对路径(这条要测的是**两个进程抢同一个事件**,不是 cwd 解析)
|
|
254
|
+
const wakeTs2 = new URL("./scheduled-requirement-wake.ts", import.meta.url).pathname;
|
|
255
|
+
const code=`import {consumeRequirementWake} from ${JSON.stringify(wakeTs2)}; import {existsSync} from 'node:fs'; console.log('READY'); while(!existsSync(${JSON.stringify(gate)}))await Bun.sleep(10); for(let i=0;;i++){try{console.log(JSON.stringify({wake:consumeRequirementWake(${JSON.stringify(scheduleId)},${JSON.stringify(network)})})); break;}catch(e){if(i>=4||!String(e).includes('locked'))throw e;await Bun.sleep(20);}}`;
|
|
250
256
|
const workers=[] as any[];
|
|
251
257
|
// Initialize each adapter before releasing both against the same DB;
|
|
252
258
|
// schema startup is not the race under qualification.
|
|
@@ -140,6 +140,14 @@ describe("#690 scheduled run follows the real task lifecycle", () => {
|
|
|
140
140
|
network_id: NET,
|
|
141
141
|
attachments: [{ type: "file", file_id: "file_690_reply", name: "evidence.json", size: 12, mime: "application/json" }],
|
|
142
142
|
});
|
|
143
|
+
// 2026-10-31 —— #3275:report_completion 的形状。
|
|
144
|
+
// ⚠️ warning 与 attachments_saved 是**条件键**(混合版本告警 / 有 artifact 时才出现);
|
|
145
|
+
// 本夹具恰好两条都触发 ⇒ 这条断言钉的是「**条件键之外没有别的键**」,
|
|
146
|
+
// 而不是「这两个键永远在」。
|
|
147
|
+
expect(Object.keys(reply).sort()).toEqual([
|
|
148
|
+
"attachments_saved", "message_id", "ok", "session_status", "warning",
|
|
149
|
+
]);
|
|
150
|
+
expect(reply.session_status).toBe("idle");
|
|
143
151
|
expect(reply.ok).toBe(true);
|
|
144
152
|
expect(readRun(runId).status).toBe("replied");
|
|
145
153
|
expect(readRun(runId).completed_at).toBeTruthy();
|
package/src/start-node.test.ts
CHANGED
|
@@ -228,7 +228,8 @@ describe("start_node — stale-starting reaper (#1448 finding-2)", () => {
|
|
|
228
228
|
expect(r.ok).toBe(false);
|
|
229
229
|
expect(r.error).toBe("node_already_starting");
|
|
230
230
|
expect(r.existing_request_id).toBe("str_fresh");
|
|
231
|
-
expect(
|
|
231
|
+
expect(Number.isFinite(r.age_ms)).toBe(true);
|
|
232
|
+
expect(r.age_ms).toBeGreaterThanOrEqual(0); // 类型不是断言:NaN/负数都是 number
|
|
232
233
|
// old request untouched, no new dispatch
|
|
233
234
|
expect(db.get<any>(`SELECT status FROM node_start_requests WHERE request_id='str_fresh'`)?.status).toBe("delivered");
|
|
234
235
|
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// 2026-10-31 —— #3214 的最后一个缺口:/api/stats/versions 此前**一条测试都没有**
|
|
2
|
+
// (REST 覆盖率报告里它是唯一的 unreferenced)。这条把它钉住:
|
|
3
|
+
// ① 成功体键集(多一个键 = 又一处没人读的字段)
|
|
4
|
+
// ② 守恒式:by_version 的 sessions 之和 == sessions(否则「总数」与「明细」是两个读数)
|
|
5
|
+
// ③ 分桶口径:同一个 agent 的不同版本必须分开成两行(否则「落后」这个数算不出来)
|
|
6
|
+
import './require-explicit-test-db';
|
|
7
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
8
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
|
|
12
|
+
const DIR = mkdtempSync(join(tmpdir(), 'anet-vstats-'));
|
|
13
|
+
process.env.COMMHUB_DB ||= join(DIR, 'hub.db');
|
|
14
|
+
process.env.HOST = '127.0.0.1';
|
|
15
|
+
|
|
16
|
+
let BASE = '', TOKEN = '', NET = '', hub: any, db: any;
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
db = (await import('./db.js')).db;
|
|
20
|
+
const { register } = await import('./auth.js');
|
|
21
|
+
const reg = register(`vs_${Date.now()}`, 'VsPassw0rd!x');
|
|
22
|
+
TOKEN = reg.token!; NET = reg.network_id!;
|
|
23
|
+
const srv: any = await import('./server.js');
|
|
24
|
+
hub = srv.bootServer({ port: 0, hostname: '127.0.0.1' });
|
|
25
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
26
|
+
}, 30_000);
|
|
27
|
+
|
|
28
|
+
afterAll(() => { try { hub?.stop?.(); } catch {} rmSync(DIR, { recursive: true, force: true }); });
|
|
29
|
+
|
|
30
|
+
describe('/api/stats/versions', () => {
|
|
31
|
+
test('键集固定、计数守恒、同 agent 不同版本分桶', async () => {
|
|
32
|
+
const now = new Date().toISOString();
|
|
33
|
+
const ins = (alias: string, version: string | null, status: string) =>
|
|
34
|
+
db.run(`INSERT INTO sessions (resume_id, alias, node_id, status, network_id, updated_at, last_seen_at, version)
|
|
35
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?6, ?7)`,
|
|
36
|
+
[`r_${alias}`, alias, `n_${alias}`, status, NET, now, version]);
|
|
37
|
+
|
|
38
|
+
ins('vs-a1', '0.2.10', 'idle');
|
|
39
|
+
ins('vs-a2', '0.2.10', 'idle');
|
|
40
|
+
ins('vs-a3', '0.2.9', 'idle');
|
|
41
|
+
|
|
42
|
+
const res = await fetch(`${BASE}/api/stats/versions?network_id=${NET}`, { headers: { Authorization: `Bearer ${TOKEN}` } });
|
|
43
|
+
expect(res.status).toBe(200);
|
|
44
|
+
const b = await res.json() as any;
|
|
45
|
+
|
|
46
|
+
expect(Object.keys(b).sort()).toEqual([
|
|
47
|
+
'active', 'active_behind_same_agent', 'active_missing_version',
|
|
48
|
+
'by_version', 'network_id', 'no_version_by_agent', 'ok', 'sessions',
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
// 守恒:明细之和 == 总数
|
|
52
|
+
const sum = (b.by_version as any[]).reduce((n, x) => n + x.sessions, 0);
|
|
53
|
+
expect(sum).toBe(b.sessions);
|
|
54
|
+
|
|
55
|
+
// 分桶:同一 agent 的两个版本是两行(否则「落后」这个数算不出来)
|
|
56
|
+
const agentRows = (b.by_version as any[]).filter((x) => x.agent === 'vs-a1' || x.agent === 'vs-a');
|
|
57
|
+
expect((b.by_version as any[]).length).toBeGreaterThanOrEqual(2);
|
|
58
|
+
for (const row of b.by_version as any[]) {
|
|
59
|
+
expect(Number.isInteger(row.sessions)).toBe(true);
|
|
60
|
+
expect(row.sessions).toBeGreaterThan(0);
|
|
61
|
+
expect(row.active_behind_same_agent === undefined).toBe(true); // 桶里没有这个键(它是全局读数)
|
|
62
|
+
}
|
|
63
|
+
expect(Number.isInteger(b.active_behind_same_agent)).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -137,7 +137,12 @@ describe("#167 Hub delivered-stale lifecycle watcher", () => {
|
|
|
137
137
|
|
|
138
138
|
test("startHub owns a live watcher timer instead of relying on import side effects", async () => {
|
|
139
139
|
const childDbPath = `/tmp/test683-live-${process.pid}-${Date.now()}.db`;
|
|
140
|
-
|
|
140
|
+
// 2026-10-31 —— 绝对路径,不再用 `'./server/src/…'` + `cwd: process.cwd()`。
|
|
141
|
+
// 那种写法只在「从仓库根跑」时成立;从 `server/` 跑(scripts/run-server-tests.sh 就是这样)
|
|
142
|
+
// 子进程立刻退出 1,于是断言长期红着,而看起来像被测行为失败。断言不该顺带测 cwd。
|
|
143
|
+
const dbJs = new URL("./db.js", import.meta.url).pathname;
|
|
144
|
+
const indexTs = new URL("./index.ts", import.meta.url).pathname;
|
|
145
|
+
const init = Bun.spawnSync(["bun", "-e", `await import(${JSON.stringify(dbJs)})`], {
|
|
141
146
|
cwd: process.cwd(),
|
|
142
147
|
env: { ...process.env, COMMHUB_DB: childDbPath },
|
|
143
148
|
stdout: "pipe",
|
|
@@ -145,7 +150,7 @@ describe("#167 Hub delivered-stale lifecycle watcher", () => {
|
|
|
145
150
|
});
|
|
146
151
|
expect(init.exitCode).toBe(0);
|
|
147
152
|
|
|
148
|
-
const child = Bun.spawn(["bun", "run",
|
|
153
|
+
const child = Bun.spawn(["bun", "run", indexTs], {
|
|
149
154
|
cwd: process.cwd(),
|
|
150
155
|
env: {
|
|
151
156
|
...process.env,
|
|
@@ -131,6 +131,10 @@ describe("#1828 POST /api/messages/ack covers inbox reply rows", () => {
|
|
|
131
131
|
test("🔴 B 拿 A 的 inbox id 来 ack:匹配不到,A 的数不动", async () => {
|
|
132
132
|
const { body } = await post("/api/messages/ack", bToken, { message_ids: ["ib_a1"] });
|
|
133
133
|
expect(body).toMatchObject({ ok: true, acked: 0, acked_inbox: 0 });
|
|
134
|
+
// 2026-10-31 —— #3214:ack 的形状钉住(两个分桶 + 总数,客户端按这三个数更新未读角标)
|
|
135
|
+
expect(Object.keys(body).sort()).toEqual(["acked", "acked_inbox", "acked_user_inbox", "ok", "scope"]);
|
|
136
|
+
// 守恒:两个分桶之和 == 总数(否则角标与明细是两个读数)
|
|
137
|
+
expect(body.acked_inbox + body.acked_user_inbox).toBe(body.acked);
|
|
134
138
|
const a = await get("/api/messages?scope=user", aToken);
|
|
135
139
|
expect(a.body.unread_by_agent["peer-1"]).toBe(2);
|
|
136
140
|
});
|