@sleep2agi/commhub-server 0.9.0-preview.249 → 0.9.0-preview.250

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/build-info.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
- "commit": "d2467f4b821dcc83e47970737b2c2fe65086d270",
3
+ "commit": "bdafec51e863f48faff870f6489a8a77579a42dd",
4
4
  "dirty": false,
5
- "built_at": "2026-10-31T19:32:17.279Z",
5
+ "built_at": "2026-10-31T19:42:20.517Z",
6
6
  "source": "ci"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.249",
3
+ "version": "0.9.0-preview.250",
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",
@@ -180,6 +180,43 @@ describe("#460 REST /api/task", () => {
180
180
  expect(r.body.layers.map((l: any) => l.layer)).toEqual(["tui", "model_auth"]);
181
181
  });
182
182
 
183
+ // #3271 —— 第二道闸:**从未取走过任务**的目标。与降级闸同形(409 + force 只有人能用)。
184
+ // 这条覆盖的是 REST /api/task 这条派单面;MCP send_task 走同一个判据函数。
185
+ test("🔴 连续 3 次过期且从未消费 ⇒ 409 target_never_consumes,拒绝体带 window_since", async () => {
186
+ const { noteNeverConsumedExpiry, resetNeverConsumedExpiryCountersForTest } = await import("./expiry-counters.js");
187
+ setHealth(HEALTHY);
188
+ resetNeverConsumedExpiryCountersForTest();
189
+ for (let i = 0; i < 3; i += 1) noteNeverConsumedExpiry(TARGET);
190
+ const before = taskCount();
191
+ const r = await postTask(ownerToken, {});
192
+ expect(r.status).toBe(409);
193
+ expect(r.body.ok).toBe(false);
194
+ expect(r.body.error).toBe("target_never_consumes");
195
+ expect(r.body.alias).toBe(TARGET);
196
+ expect(r.body.expiries).toBe(3);
197
+ expect(typeof r.body.window_since).toBe("string");
198
+ expect(r.body.message).toContain("force:true");
199
+ expect(taskCount()).toBe(before); // 一行都没写
200
+ resetNeverConsumedExpiryCountersForTest();
201
+ });
202
+
203
+ test("🔴 同一目标带 force(用户令牌)⇒ 放行;节点令牌带 force 仍被拒", async () => {
204
+ const { noteNeverConsumedExpiry, resetNeverConsumedExpiryCountersForTest } = await import("./expiry-counters.js");
205
+ // 健康报告也要是好的:否则先被降级闸拦下,这条测的就不是新闸了(我第一次就栽在这)。
206
+ setHealth(HEALTHY);
207
+ resetNeverConsumedExpiryCountersForTest();
208
+ try {
209
+ for (let i = 0; i < 3; i += 1) noteNeverConsumedExpiry(TARGET);
210
+ expect((await postTask(ownerToken, { force: true })).status).toBe(200);
211
+ // 节点令牌那一半在**判据层**钉(expiry-counters.test.ts:forceAllowed=false 时 force 不算)。
212
+ // 这里不重复断言:节点令牌会先撞上「降级闸」(健康报告按网络取,节点令牌没有网络 ⇒ 取值不同),
213
+ // 于是这条会变成在测两个闸的**先后顺序**,而不是在测这一道闸 —— 今天已经因为类似的原因误读两次了。
214
+ } finally {
215
+ // 计数器是**进程级**状态:不清干净会污染后面的用例(我第一次就漏了 finally)。
216
+ resetNeverConsumedExpiryCountersForTest();
217
+ }
218
+ });
219
+
183
220
  test("expired login alone is refused", async () => {
184
221
  setHealth({ bridge: "ok", model_auth: "expired" });
185
222
  expect((await postTask(ownerToken)).body.error).toBe("node_degraded");
package/src/server.ts CHANGED
@@ -122,7 +122,7 @@ import { createProductionSideThreadTransport } from "./side-thread-production.js
122
122
  import { parseHubTimestamp } from "./hub-timestamp";
123
123
  import { logTaskRejection } from "./task-rejection-log.js";
124
124
  import { taskRejectionCounters } from "./rejection-counters.js";
125
- import { neverConsumedExpiryCounters, noteNeverConsumedExpiry } from "./expiry-counters.js";
125
+ import { neverConsumedExpiryCounters, noteNeverConsumedExpiry, neverConsumeGate } from "./expiry-counters.js";
126
126
  import { legacyLicenseField, licenseStateOf } from "./license-state.js";
127
127
  import { AVATAR_FIELD, avatarUrl, inspectAvatarImage, isMultipart, isValidAvatarVersion, MAX_AVATAR_BYTES, MAX_AVATAR_STORAGE_BYTES } from "./user-avatar-image.js";
128
128
 
@@ -5827,6 +5827,17 @@ return Bun.serve({
5827
5827
  const hg = assertNodeHealthy(targetAlias, taskNetId ?? null, { force: body.force === true, forceAllowed: !restAuth?.networkId });
5828
5828
  if (!hg.ok) return reject(withCors(req, Response.json(hg, { status: 409 })));
5829
5829
  }
5830
+ // #3271 —— 与 MCP send_task 同一道闸(**两个派单面必须同形**,否则修了一个、另一个照旧)。
5831
+ // 拒绝体与 MCP 路径逐字相同,只是走 409(REST 既有语义)。
5832
+ {
5833
+ const gate = neverConsumeGate({
5834
+ alias: targetAlias,
5835
+ counters: neverConsumedExpiryCounters(),
5836
+ force: body.force === true,
5837
+ forceAllowed: !restAuth?.networkId,
5838
+ });
5839
+ if (!gate.ok) return reject(withCors(req, Response.json(gate, { status: 409 })));
5840
+ }
5830
5841
  // #500 step 2 — what is already queued on the target, read BEFORE this task is written (advice only, never blocks).
5831
5842
  const queueInfo = dispatchQueueInfo(targetAlias, taskNetId, target.session?.status, ttlSeconds);
5832
5843
  // Mirror send_task MCP: write inbox + tasks rows in a single