@sleep2agi/commhub-server 0.9.0-preview.219 → 0.9.0-preview.220
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/agent-acl-slice3-http.test.ts +388 -1
- package/src/config-apply-validate.test.ts +68 -0
- package/src/config-apply-validate.ts +69 -0
- package/src/cors-origins.test.ts +40 -0
- package/src/create-node-network-id.test.ts +12 -0
- package/src/department-heads-http.test.ts +20 -0
- package/src/departments-agent-count.test.ts +3 -0
- package/src/etag-of.test.ts +57 -0
- package/src/event-loop-lag.ts +20 -0
- package/src/health-anon-readers.ts +59 -0
- package/src/health-host-disk-2756.test.ts +23 -1
- package/src/health-redaction.test.ts +1063 -0
- package/src/hub-catalog-read-http.test.ts +79 -0
- package/src/hub-provider-config.test.ts +17 -0
- package/src/hub-provider-config.ts +19 -0
- package/src/license-state.test.ts +56 -0
- package/src/license-state.ts +48 -0
- package/src/list-host-supervisors.test.ts +10 -0
- package/src/mcp-projects-events-http.test.ts +3 -0
- package/src/mcp-write-network-resolution.test.ts +3 -0
- package/src/node-caller-identity-http.test.ts +9 -1
- package/src/node-health-dispatch-http.test.ts +58 -2
- package/src/node-health-guard.ts +16 -0
- package/src/node-skills-transport.test.ts +3 -0
- package/src/opencode-v2-catalog.ts +4 -0
- package/src/redact-tokens.test.ts +22 -1
- package/src/redact-tokens.ts +4 -1
- package/src/rejection-counters.test.ts +72 -0
- package/src/rejection-counters.ts +173 -0
- package/src/requirement-events-http.test.ts +27 -0
- package/src/route-callers-http.test.ts +1 -1
- package/src/serve-error.test.ts +35 -0
- package/src/serve-error.ts +33 -4
- package/src/server.ts +913 -17
- package/src/shared/probe-host-allowlist-drift.test.ts +45 -0
- package/src/skillhub-http.test.ts +35 -1
- package/src/status-read-cache.ts +8 -1
- package/src/task-late-reply-http.test.ts +7 -0
- package/src/task-rejection-log.ts +10 -1
- package/src/tmux-allowlist.test.ts +48 -0
- package/src/tool-audience.ts +10 -3
- package/src/tools.ts +99 -15
|
@@ -109,6 +109,35 @@ describe("GET /api/skills", () => {
|
|
|
109
109
|
expect(slugs).toContain("hc-pending");
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
// 2026-10-31 —— **两条「providers」读的是不同的表**,而空数组在载荷里长得一样:
|
|
113
|
+
// GET /api/providers → hub_provider_configs | MCP list_providers → providers / provider_models
|
|
114
|
+
// 客户端「没有可选模型」既可能是前者空,也可能是后者空 ⇒ 必须能在载荷里区分。
|
|
115
|
+
test("an empty registry says which table it read, and whether the CLI registry has rows", async () => {
|
|
116
|
+
const { db } = await import("./db.js");
|
|
117
|
+
// strangerNet 里没有 hub_provider_configs 行;先看「两张表都空」这一档
|
|
118
|
+
const before = await get(`/api/providers?network_id=${strangerNet}`, strangerToken);
|
|
119
|
+
expect(before.status).toBe(200);
|
|
120
|
+
expect(before.body.state).toBe("unconfigured");
|
|
121
|
+
expect(before.body.source_table).toBe("hub_provider_configs");
|
|
122
|
+
expect(before.body.counts.providers).toBe(0);
|
|
123
|
+
expect(before.body.hint).toContain("hub_provider_configs");
|
|
124
|
+
|
|
125
|
+
// 再给 CLI 注册表塞一行(另一张表),本端点**仍然为空**,但 hint 必须改口
|
|
126
|
+
db.run(
|
|
127
|
+
`INSERT OR REPLACE INTO providers (provider_id, network_id, name, vendor, base_url, secret_key_ref, created_at, created_by, enabled)
|
|
128
|
+
VALUES ('hc-cli-only', ?1, 'hc-cli-only', 'openai', 'https://api.example.com', 'K', ?2, 'test', 1)`,
|
|
129
|
+
[strangerNet, Date.now()],
|
|
130
|
+
);
|
|
131
|
+
const after = await get(`/api/providers?network_id=${strangerNet}`, strangerToken);
|
|
132
|
+
expect(after.body.providers).toHaveLength(0); // 本端点还是空
|
|
133
|
+
expect(after.body.counts.providers_in_cli_registry).toBeGreaterThan(0);
|
|
134
|
+
expect(after.body.hint).toContain("不会自动出现在本端点");
|
|
135
|
+
// 反向:有行时不该带 hint(载荷不变胖,且「有理由」与「没理由」可区分)
|
|
136
|
+
const owner = await get(`/api/providers?network_id=${ownerNet}`, ownerToken);
|
|
137
|
+
expect(owner.body.state).toBe("configured");
|
|
138
|
+
expect("hint" in owner.body).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
|
|
112
141
|
test("a member of another network is refused", async () => {
|
|
113
142
|
const r = await get(`/api/skills?network_id=${ownerNet}`, strangerToken);
|
|
114
143
|
expect(r.status).toBe(403);
|
|
@@ -184,4 +213,54 @@ describe("GET /api/providers", () => {
|
|
|
184
213
|
expect(r.status).toBe(403);
|
|
185
214
|
expect(r.body.error).toBe("user_token_required");
|
|
186
215
|
});
|
|
216
|
+
// 2026-10-31 —— **写侧原来只有 MCP**:客户端能显示「还没有 provider」,却没办法把它变成「有」。
|
|
217
|
+
// 这条把「第一行」确认成一次 HTTP 调用,并核对三件事:落库、读回来一致、revision 冲突是 409。
|
|
218
|
+
test("PUT /api/providers creates the first row, and the read side sees it", async () => {
|
|
219
|
+
const body = {
|
|
220
|
+
revision: 0,
|
|
221
|
+
provider: {
|
|
222
|
+
id: "hc-first", label: "First Provider", enabled: true,
|
|
223
|
+
protocol: "openai-chat-completions", baseUrl: "https://api.example.com/v1",
|
|
224
|
+
models: ["gpt-x"], key: "sk-test-not-a-real-secret",
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
const r = await fetch(`${base}/api/providers?network_id=${ownerNet}`, {
|
|
228
|
+
method: "PUT",
|
|
229
|
+
headers: { Authorization: `Bearer ${ownerToken}`, "content-type": "application/json" },
|
|
230
|
+
body: JSON.stringify(body),
|
|
231
|
+
});
|
|
232
|
+
const saved = await r.json() as any;
|
|
233
|
+
expect(r.status).toBe(200);
|
|
234
|
+
expect(saved.ok).toBe(true);
|
|
235
|
+
expect(saved.provider.id).toBe("hc-first");
|
|
236
|
+
expect(saved.provider.revision).toBe(1);
|
|
237
|
+
// 密钥永不回显
|
|
238
|
+
expect(JSON.stringify(saved)).not.toContain("sk-test-not-a-real-secret");
|
|
239
|
+
|
|
240
|
+
const read = await get(`/api/providers?network_id=${ownerNet}`, ownerToken);
|
|
241
|
+
const ids = read.body.providers.map((p: any) => p.id);
|
|
242
|
+
expect(ids).toContain("hc-first");
|
|
243
|
+
|
|
244
|
+
// 用旧 revision 再写一次 ⇒ 409(乐观锁;这正是「两个人同时改」的那一格)
|
|
245
|
+
const stale = await fetch(`${base}/api/providers?network_id=${ownerNet}`, {
|
|
246
|
+
method: "PUT",
|
|
247
|
+
headers: { Authorization: `Bearer ${ownerToken}`, "content-type": "application/json" },
|
|
248
|
+
body: JSON.stringify({ ...body, revision: 0, provider: { ...body.provider, label: "Second Writer" } }),
|
|
249
|
+
});
|
|
250
|
+
expect(stale.status).toBe(409);
|
|
251
|
+
expect((await stale.json() as any).error).toBe("hub_provider_revision_conflict");
|
|
252
|
+
|
|
253
|
+
// 别的网络成员不许写
|
|
254
|
+
const foreign = await fetch(`${base}/api/providers?network_id=${ownerNet}`, {
|
|
255
|
+
method: "PUT",
|
|
256
|
+
headers: { Authorization: `Bearer ${strangerToken}`, "content-type": "application/json" },
|
|
257
|
+
body: JSON.stringify({ ...body, revision: 1 }),
|
|
258
|
+
});
|
|
259
|
+
expect(foreign.status).toBe(403);
|
|
260
|
+
|
|
261
|
+
// 清理:这条测试造了一行,后面的断言按「1 行」计数,不能留痕
|
|
262
|
+
const { db } = await import("./db.js");
|
|
263
|
+
db.run(`DELETE FROM hub_provider_configs WHERE network_id = ?1 AND provider_id = 'hc-first'`, [ownerNet]);
|
|
264
|
+
});
|
|
265
|
+
|
|
187
266
|
});
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
// 2026-10-31 —— **本地直跑会看到 3 条红,那不是回归**。
|
|
2
|
+
// 这 7 条里有 3 条(HTTP 端点 / names-only 密钥 / daemon 队列)依赖
|
|
3
|
+
// `.github/workflows/hub-provider-core.yml` 里的容器环境(`tests/test907-hub-provider/run.sh`,
|
|
4
|
+
// `--network none` + 特定 host 映射);在仓外 `bun test src/hub-provider-config.test.ts`
|
|
5
|
+
// 会看到 `status: "failed"`(服务端 URL 走不到 secure transport)。
|
|
6
|
+
// ⇒ 按本仓规矩把环境依赖写在文件头:否则下一个人会把 3 条环境红当成自己改坏的。
|
|
7
|
+
// ⇒ 判定这条文件是否健康,看那套 Docker 测试,不看本地 bun test。
|
|
8
|
+
|
|
1
9
|
import './require-explicit-test-db';
|
|
2
10
|
import { afterAll, beforeEach, expect, test } from 'bun:test';
|
|
3
11
|
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
@@ -101,6 +109,15 @@ test('actual Hub tool atomically saves encrypted Provider; metadata read and con
|
|
|
101
109
|
const human = client(); const result = await save(human); expect(result.ok).toBe(true);
|
|
102
110
|
expect(result.provider).toMatchObject({ id: 'shared', revision: 1, source: 'hub', credential_present: true, compatible_runtimes: ['codex-tui'] });
|
|
103
111
|
const read = await human('daemon_provider_snapshot', { action: 'hub_read', id: 'hub', network_id: net }); expect(read.providers).toHaveLength(1);
|
|
112
|
+
// 2026-10-31 —— **精确键集**(#3171):客户端「可选模型」这一面直接消费这两个投影,
|
|
113
|
+
// 而多给一个键(尤其 secret_key_ref)在这条线上是最严重的那类改动。
|
|
114
|
+
// 实际四键(我第一版漏了 network_id —— 断言当场纠正)。
|
|
115
|
+
expect(Object.keys(read).sort()).toEqual(["network_id", "ok", "providers", "source"]);
|
|
116
|
+
// provider 视图实际 12 键(我第一版写了 6 个,漏了 baseUrl/enabled/models/protocol/updated_at/verification)
|
|
117
|
+
expect(Object.keys(result.provider).sort()).toEqual([
|
|
118
|
+
"baseUrl", "compatible_runtimes", "credential_present", "enabled", "id", "label",
|
|
119
|
+
"models", "protocol", "revision", "source", "updated_at", "verification",
|
|
120
|
+
]);
|
|
104
121
|
expect(JSON.stringify([result, read])).not.toContain(key);
|
|
105
122
|
expect(await save(human)).toMatchObject({ ok: false, error: 'hub_provider_revision_conflict' });
|
|
106
123
|
const secret = db.get<any>('SELECT ciphertext FROM network_secrets WHERE network_id=?1', net);
|
|
@@ -40,7 +40,26 @@ function publicRow(networkId: string, stored: Row, exposeRef = false) {
|
|
|
40
40
|
export function readHubProviders(h: Human, exposeRefs = false) {
|
|
41
41
|
const refusal = auth(h, false); if (refusal) return refusal;
|
|
42
42
|
const rows = db.all<Row>('SELECT revision,config_json,secret_key_ref,updated_at FROM hub_provider_configs WHERE network_id=?1 ORDER BY provider_id', h.networkId!);
|
|
43
|
+
// 2026-10-31 —— **这个端点的空数组也必须自报家门**(与 MCP list_providers 同一课)。
|
|
44
|
+
// 关键事实:两条「providers」读的是**不同的表** ——
|
|
45
|
+
// GET /api/providers → hub_provider_configs(网络自有的 provider 配置,本函数)
|
|
46
|
+
// MCP list_providers → providers / provider_models
|
|
47
|
+
// 于是「客户端没有可选模型」既可能是「这张表空」,也可能是「另一张表空」,
|
|
48
|
+
// 而两者在载荷里长得一模一样。⇒ 在 source 之外再说清 state 与「另一处叫什么」。
|
|
49
|
+
const otherSource = db.get<{ cnt: number }>(
|
|
50
|
+
'SELECT COUNT(*) AS cnt FROM providers WHERE network_id=?1 AND enabled=1', h.networkId!);
|
|
51
|
+
const otherCount = otherSource?.cnt ?? 0;
|
|
52
|
+
const state = rows.length > 0 ? 'configured' as const : 'unconfigured' as const;
|
|
43
53
|
return { ok: true as const, network_id: h.networkId!, source: 'hub' as const,
|
|
54
|
+
// 读的是哪张表 —— 名字直接写出来,避免下一个人拿这个结果去解释另一个接口
|
|
55
|
+
source_table: 'hub_provider_configs' as const,
|
|
56
|
+
state,
|
|
57
|
+
counts: { providers: rows.length, providers_in_cli_registry: otherCount },
|
|
58
|
+
...(state === 'unconfigured' ? {
|
|
59
|
+
hint: otherCount > 0
|
|
60
|
+
? '本端点读 hub_provider_configs(网络自有 provider 配置),此处为空;但要给客户端选模型,还需要这里至少一行 —— CLI 注册表里的 ' + otherCount + ' 条不会自动出现在本端点。'
|
|
61
|
+
: '本端点读 hub_provider_configs,此处为空,且 CLI 注册表(providers)也是 0 条 ⇒ 客户端没有任何可选模型;需要管理员先录入第一行。',
|
|
62
|
+
} : {}),
|
|
44
63
|
...(exposeRefs ? { secret_reference_supported: true } : {}), providers: rows.map(r => publicRow(h.networkId!, r, exposeRefs)) };
|
|
45
64
|
}
|
|
46
65
|
export function putHubProvider(h: Human, revision: number, input: unknown) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// 2026-10-31 —— license 三态契约。
|
|
2
|
+
//
|
|
3
|
+
// 四条断言对应四种输入,第四种(查询失败)在旧实现里会直接 500 掉整个 /health:
|
|
4
|
+
// known : 有行且有 type
|
|
5
|
+
// absent : 查询成功、无行
|
|
6
|
+
// unknown: 有行但 type 空(数据不全)—— 修法与 absent 不同
|
|
7
|
+
// unknown: 查询失败 —— 修法与 absent 不同,且**不许拖垮 /health**
|
|
8
|
+
|
|
9
|
+
import { describe, expect, test } from "bun:test";
|
|
10
|
+
import { legacyLicenseField, licenseStateOf } from "./license-state";
|
|
11
|
+
|
|
12
|
+
describe("licenseStateOf", () => {
|
|
13
|
+
test("known: a row with a non-empty type", () => {
|
|
14
|
+
expect(licenseStateOf({ type: "pro" })).toEqual({ kind: "known", type: "pro" });
|
|
15
|
+
expect(licenseStateOf({ type: " team " })).toEqual({ kind: "known", type: "team" });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("absent: query succeeded and there is no row", () => {
|
|
19
|
+
expect(licenseStateOf(null)).toEqual({ kind: "absent" });
|
|
20
|
+
expect(licenseStateOf(undefined)).toEqual({ kind: "absent" });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("unknown(row_without_type): a row exists but the type is empty — different fix from absent", () => {
|
|
24
|
+
expect(licenseStateOf({ type: "" })).toEqual({ kind: "unknown", reason: "license_row_without_type" });
|
|
25
|
+
expect(licenseStateOf({ type: " " })).toEqual({ kind: "unknown", reason: "license_row_without_type" });
|
|
26
|
+
expect(licenseStateOf({})).toEqual({ kind: "unknown", reason: "license_row_without_type" });
|
|
27
|
+
expect(licenseStateOf({ type: 42 })).toEqual({ kind: "unknown", reason: "license_row_without_type" });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("unknown(query_failed) wins over the row — a failed query tells us nothing about the row", () => {
|
|
31
|
+
expect(licenseStateOf({ type: "pro" }, true)).toEqual({ kind: "unknown", reason: "license_query_failed" });
|
|
32
|
+
expect(licenseStateOf(null, true)).toEqual({ kind: "unknown", reason: "license_query_failed" });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("the three states are mutually exclusive — no input yields two of them", () => {
|
|
36
|
+
const kinds = new Set([
|
|
37
|
+
licenseStateOf({ type: "pro" }).kind,
|
|
38
|
+
licenseStateOf(null).kind,
|
|
39
|
+
licenseStateOf({ type: "" }).kind,
|
|
40
|
+
licenseStateOf(null, true).kind,
|
|
41
|
+
]);
|
|
42
|
+
// known / absent / unknown —— 只有三种 kind,且 unknown 有两条不同 reason
|
|
43
|
+
expect([...kinds].sort()).toEqual(["absent", "known", "unknown"]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("legacyLicenseField", () => {
|
|
48
|
+
test("stays byte-identical to the old expression for every input", () => {
|
|
49
|
+
expect(legacyLicenseField({ type: "pro" })).toBe("pro");
|
|
50
|
+
expect(legacyLicenseField({ type: "" })).toBe("none");
|
|
51
|
+
expect(legacyLicenseField({})).toBe("none");
|
|
52
|
+
expect(legacyLicenseField(null)).toBe("none");
|
|
53
|
+
// 非字符串 type 旧实现也回 "none"(`license?.type || "none"` 的真值语义)
|
|
54
|
+
expect(legacyLicenseField({ type: 0 as unknown })).toBe("none");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// 2026-10-31 —— `license` 字段的三值化。
|
|
2
|
+
//
|
|
3
|
+
// 现状:`/health` 只给 `license: license?.type || "none"`。
|
|
4
|
+
// 而 "none" 同时覆盖三种不同的事:
|
|
5
|
+
// · 查询成功、确实没有 license 行 → 去授权能修
|
|
6
|
+
// · 查询成功、有行但 type 为空/缺失 → 数据不全,补行能修
|
|
7
|
+
// · 查询失败 → 补一次取数能修
|
|
8
|
+
//
|
|
9
|
+
// ⇒ 三种的**修法不同**,却共用一个字符串。这正是那条:
|
|
10
|
+
// 「空值折叠的方向,总是朝着『让你继续往下走』」—— 这里的方向是「当成没有授权」。
|
|
11
|
+
//
|
|
12
|
+
// 🔴 absent 与 unknown 的区别是**谁能修**:
|
|
13
|
+
// absent = 我们知道它不在(改配置/去授权)
|
|
14
|
+
// unknown = 没人去看 / 看失败了(补一次取数)
|
|
15
|
+
// 混成一个值之后,修法也一起混了。
|
|
16
|
+
//
|
|
17
|
+
// 兼容:`license` 字段保留一个版本(语义不精确,勿用于判据),
|
|
18
|
+
// 判据请用 `license_state`。等外部读者迁移完再下线旧字段。
|
|
19
|
+
|
|
20
|
+
export type LicenseState =
|
|
21
|
+
| { kind: "known"; type: string }
|
|
22
|
+
| { kind: "absent" }
|
|
23
|
+
| { kind: "unknown"; reason: "license_query_failed" | "license_row_without_type" };
|
|
24
|
+
|
|
25
|
+
export interface LicenseRow {
|
|
26
|
+
type?: unknown;
|
|
27
|
+
expires_at?: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 纯函数:把「一次查询的结果」映射成三态。
|
|
32
|
+
*
|
|
33
|
+
* @param row 查询到的行;null/undefined 表示查询成功但没有行
|
|
34
|
+
* @param failed 查询是否抛错(抛错时 row 无意义)
|
|
35
|
+
*/
|
|
36
|
+
export function licenseStateOf(row: LicenseRow | null | undefined, failed = false): LicenseState {
|
|
37
|
+
if (failed) return { kind: "unknown", reason: "license_query_failed" };
|
|
38
|
+
if (!row) return { kind: "absent" };
|
|
39
|
+
const type = typeof row.type === "string" ? row.type.trim() : "";
|
|
40
|
+
if (!type) return { kind: "unknown", reason: "license_row_without_type" };
|
|
41
|
+
return { kind: "known", type };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 兼容字段的渲染(保持与旧行为逐字相同,便于逐步下线)。 */
|
|
45
|
+
export function legacyLicenseField(row: LicenseRow | null | undefined): string {
|
|
46
|
+
const type = row && typeof row.type === "string" ? row.type : "";
|
|
47
|
+
return type || "none";
|
|
48
|
+
}
|
|
@@ -181,6 +181,16 @@ describe("list_host_supervisors HANDLER tests (RFC-026 §9.2, PR2 v2)", () => {
|
|
|
181
181
|
const handler = buildToolHandler(userA);
|
|
182
182
|
const reply = await callList(handler, { network_id: NET_ALPHA });
|
|
183
183
|
expect(reply.ok).toBe(true);
|
|
184
|
+
// 2026-10-31 —— **精确键集**(#3171):这条响应此前只断言了 daemons[].alias,
|
|
185
|
+
// 于是「多给一个顶层键」不会被发现 —— 而这是个按网络隔离的列表,多给一格就是泄露。
|
|
186
|
+
// 实际三键(我第一版漏了 count —— 断言当场纠正)。
|
|
187
|
+
// ⚠️ 这条预期值来自**实现**(读实际响应),不是来自规格 —— 它是变更探测器,不是契约。
|
|
188
|
+
// 契约来源是 RFC-026 §P2-A 的验收行(`count=2`)与它的示例;
|
|
189
|
+
// 2026-10-31 实测发现**两份不一致**(示例漏了 count),已把示例补上。
|
|
190
|
+
// ⇒ 判据:一条键集断言的依据必须能指到「哪一份规格/哪一次观测」;
|
|
191
|
+
// 指不到,它只能防变化,不能证明正确。
|
|
192
|
+
expect(Object.keys(reply).sort()).toEqual(["count", "daemons", "ok"]);
|
|
193
|
+
expect((reply as any).count).toBe(2); // 与 RFC §P2-A 的验收行同值
|
|
184
194
|
const aliases = (reply.daemons ?? []).map(d => d.alias).sort();
|
|
185
195
|
expect(aliases).toEqual(["alpha-daemon-1", "alpha-daemon-2"]);
|
|
186
196
|
});
|
|
@@ -94,6 +94,9 @@ describe("projects_create / projects_update", () => {
|
|
|
94
94
|
const id = created.project.id as string;
|
|
95
95
|
expect(created.project.name).toBe("mpe-项目甲");
|
|
96
96
|
const renamed = await mcp(U.owner.token, "projects_update", { network_id: NET, id, name: "mpe-项目乙", color: "#16a34a" });
|
|
97
|
+
// 2026-10-31 —— **精确键集**(#3171):项目更新回执是 `{ok, project}` 两键;
|
|
98
|
+
// 多给一格(比如回显整个项目集合)会让「一次更新」变成「一次列表」。
|
|
99
|
+
expect(Object.keys(renamed).sort()).toEqual(["ok", "project"]);
|
|
97
100
|
expect(renamed.project.name).toBe("mpe-项目乙");
|
|
98
101
|
expect(renamed.project.color).toBe("#16a34a");
|
|
99
102
|
expect((await mcp(U.owner.token, "projects_update", { network_id: NET, id, archived: true })).project.archived).toBe(true);
|
|
@@ -211,6 +211,9 @@ describe("utok single-network auto-resolve (no network_id argument)", () => {
|
|
|
211
211
|
const t = makeTask(A1, "delivered", "x517 g1 cancel_task");
|
|
212
212
|
const r = await call(tools["cancel_task"], { task_id: t });
|
|
213
213
|
expect(r.ok).toBe(true);
|
|
214
|
+
// 2026-10-31 —— **同变量口径的精确键集**(#3171):这条断言绑的是本次调用的结果变量 r。
|
|
215
|
+
// 实际三键(我第一版只写了 ok —— 断言当场纠正)。
|
|
216
|
+
expect(Object.keys(r).sort()).toEqual(["cancelled", "ok", "task_id"]);
|
|
214
217
|
expect(taskById(t)?.status).toBe("cancelled");
|
|
215
218
|
});
|
|
216
219
|
|
|
@@ -998,7 +998,15 @@ function activityTask(nodeId: string, alias: string, network = NET) {
|
|
|
998
998
|
}
|
|
999
999
|
const activitySnap = (id: string) => db.get<any>("SELECT status, consumed_at, runtime_submitted_at, started_at, thread_id, turn_id, last_activity_at FROM tasks WHERE task_id = ?1", id);
|
|
1000
1000
|
async function consumeActivityTask(context: {task_id: string; thread_id: string; turn_id: string}) {
|
|
1001
|
-
|
|
1001
|
+
const consumed = await tool(leaseTok.token, "mark_tasks_consumed", { task_ids: [context.task_id], task_contexts: [context] });
|
|
1002
|
+
expect(consumed.ok).toBe(true);
|
|
1003
|
+
// 2026-10-31 —— **精确键集**(#3171):这条响应此前只断言 ok。
|
|
1004
|
+
// 键集来自实现(变更探测器);契约来源是 tools.ts 的描述与本文件的消费方。
|
|
1005
|
+
expect(Object.keys(consumed).sort()).toEqual(["ok", "tasks"]);
|
|
1006
|
+
// 拒绝形状:不带 task_id 的拒绝只有两键(多一个就把「通用错误」变成「某条任务的错误」)
|
|
1007
|
+
const denied = await tool(leaseTok.token, "mark_tasks_consumed", { task_ids: ["nope", "nope"], task_contexts: [] });
|
|
1008
|
+
expect(denied.ok).toBe(false);
|
|
1009
|
+
expect(Object.keys(denied).sort()).toEqual(["error", "ok"]);
|
|
1002
1010
|
}
|
|
1003
1011
|
const renewActivity = (token: string, contexts: Array<{task_id: string; thread_id: string; turn_id: string}>) => tool(token, "mark_tasks_consumed", { task_ids: contexts.map(c => c.task_id), task_contexts: contexts, activity_only: true });
|
|
1004
1012
|
|
|
@@ -97,11 +97,49 @@ describe("#460 which layers count as degraded", () => {
|
|
|
97
97
|
expect(degradedLayers({ tui: { ok: false, reason: "sleep-placeholder" } }).map(l => [l.layer, l.reason, l.label])).toEqual([["tui", "sleep-placeholder", "TUI 被占位(sleep)"]]);
|
|
98
98
|
expect(degradedLayers({ model_auth: "revoked" }).map(l => l.label)).toEqual(["需要重新登录"]);
|
|
99
99
|
expect(degradedLayers({ model_auth: "expired" }).map(l => l.label)).toEqual(["登录已过期"]);
|
|
100
|
+
// 2026-10-31 —— `reason` 有两个生产者(节点上报 vs Hub 合成 "unreachable"),
|
|
101
|
+
// 所以 origin 是唯一能把两者分开的一格。上游可以**原样声明** "unreachable",
|
|
102
|
+
// 因此改名 / 拆分 catch / 加前缀都不构成判别力(`:148` 同形)。
|
|
103
|
+
expect(degradedLayers(DOWN_APP).map(l => [l.layer, l.origin])).toEqual([["app_server", "node"]]);
|
|
104
|
+
expect(degradedLayers({ app_server: { ok: false, rtt_ms: null, last_error: null } }).map(l => [l.reason, l.origin])).toEqual([["unreachable", "hub"]]);
|
|
105
|
+
// must-fire:两边都写出 "unreachable" 时,只有 origin 不同 —— 这条就是那一格存在的理由
|
|
106
|
+
expect(degradedLayers({ app_server: { ok: false, rtt_ms: null, last_error: "unreachable" } }).map(l => [l.reason, l.origin])).toEqual([["unreachable", "node"]]);
|
|
107
|
+
expect(degradedLayers({ tui: { ok: false, reason: "sleep-placeholder" } })[0].origin).toBe("node");
|
|
108
|
+
|
|
100
109
|
// 修法只指向本节点重新登录,不教人拷别人的凭据
|
|
101
110
|
expect(degradedLayers({ model_auth: "revoked" })[0].hint).toContain("不要拷别的节点的 auth.json");
|
|
102
111
|
});
|
|
103
112
|
});
|
|
104
113
|
|
|
114
|
+
// 2026-10-31 —— **属性断言**(外部复核 ④:「键集契约只能对工厂断言,不能对样本断言」)。
|
|
115
|
+
// degradedLayers(health) 是工厂:它对**任意** health 形状都必须产出同一种元素形状。
|
|
116
|
+
// 这里枚举 2×2×5×2 = 40 种组合,断言每个元素的键集恒为那五个。
|
|
117
|
+
describe("degradedLayers 是工厂:任意 health 组合下元素键集不变", () => {
|
|
118
|
+
test("40 种组合,元素键集恒为 {layer,reason,origin,label,hint}", () => {
|
|
119
|
+
const seen = new Set<string>();
|
|
120
|
+
for (const appOk of [true, false]) {
|
|
121
|
+
for (const tuiOk of [true, false]) {
|
|
122
|
+
for (const auth of ["ok", "revoked", "expired", "unknown", undefined]) {
|
|
123
|
+
for (const lastErr of [null, "refused"]) {
|
|
124
|
+
const health: any = {
|
|
125
|
+
bridge: "ok",
|
|
126
|
+
app_server: appOk ? { ok: true, rtt_ms: 1, last_error: null }
|
|
127
|
+
: { ok: false, rtt_ms: null, last_error: lastErr },
|
|
128
|
+
...(tuiOk === undefined ? {} : { tui: { ok: tuiOk, reason: "sleep-placeholder" } }),
|
|
129
|
+
...(auth === undefined ? {} : { model_auth: auth }),
|
|
130
|
+
};
|
|
131
|
+
for (const layer of degradedLayers(health)) {
|
|
132
|
+
seen.add(Object.keys(layer).sort().join(","));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// 排序后的顺序是字典序(label 在 layer 前)——我第一版按定义顺序写,被断言当场纠正。
|
|
139
|
+
expect([...seen]).toEqual(["hint,label,layer,origin,reason"]);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
105
143
|
describe("#460 REST /api/task", () => {
|
|
106
144
|
test("unknown health (old agent-node) → dispatched exactly as before", async () => {
|
|
107
145
|
const before = taskCount();
|
|
@@ -126,6 +164,7 @@ describe("#460 REST /api/task", () => {
|
|
|
126
164
|
expect(r.body.alias).toBe(TARGET);
|
|
127
165
|
expect(r.body.layers.map((l: any) => l.layer)).toEqual(["app_server"]);
|
|
128
166
|
expect(r.body.layers[0].reason).toContain("ECONNREFUSED");
|
|
167
|
+
expect(r.body.layers[0].origin).toBe("node");
|
|
129
168
|
expect(r.body.message).toContain("App Server 断开");
|
|
130
169
|
expect(r.body.hint).toContain("force=true");
|
|
131
170
|
expect(r.body.force_allowed).toBe(true);
|
|
@@ -265,13 +304,30 @@ describe("#460 /api/status carries `degraded` only for degraded nodes", () => {
|
|
|
265
304
|
});
|
|
266
305
|
test("degraded → light and full rows list the failing layers with the app's labels", async () => {
|
|
267
306
|
setHealth({ bridge: "ok", app_server: { ok: false, rtt_ms: null, last_error: "refused" }, model_auth: "revoked" });
|
|
307
|
+
// 2026-10-31 —— 加了 `origin`(reason 的生产者)。这是**加字段**,不是改语义:
|
|
308
|
+
// 少这一格,「节点说自己不可达」与「Hub 问不到节点」在响应里同形。
|
|
268
309
|
const want = [
|
|
269
|
-
{ layer: "app_server", label: "App Server 断开", reason: "refused" },
|
|
270
|
-
{ layer: "model_auth", label: "需要重新登录", reason: "revoked" },
|
|
310
|
+
{ layer: "app_server", label: "App Server 断开", reason: "refused", origin: "node" },
|
|
311
|
+
{ layer: "model_auth", label: "需要重新登录", reason: "revoked", origin: "node" },
|
|
271
312
|
];
|
|
272
313
|
expect((await row(true)).degraded).toEqual(want);
|
|
273
314
|
expect((await row(false)).degraded).toEqual(want);
|
|
274
315
|
});
|
|
316
|
+
// 2026-10-31 —— **两个面必须说同一件事**(外部复核那条「共用的是解析还是判据」)。
|
|
317
|
+
// 同一个节点健康,经两条路到达用户:
|
|
318
|
+
// ① /api/task 的 409 `layers`(派发被拒时当场告诉他哪层坏了)
|
|
319
|
+
// ② /api/status 行里的 `degraded`(列表里一直可见)
|
|
320
|
+
// 二者都由 degradedLayers() 产出,但**没有任何测试保证两个面一致** ——
|
|
321
|
+
// 只要有人在其中一处 map 里漏掉 `origin`,两处就会开始说不同的版本。
|
|
322
|
+
test("parity: 409 layers and status degraded describe the same failure", async () => {
|
|
323
|
+
setHealth({ bridge: "ok", app_server: { ok: false, rtt_ms: null, last_error: "refused" }, model_auth: "revoked" });
|
|
324
|
+
const r = await postTask(ownerToken);
|
|
325
|
+
expect(r.status).toBe(409);
|
|
326
|
+
const fromTask = (r.body.layers as any[]).map((l) => [l.layer, l.reason, l.origin]);
|
|
327
|
+
const fromStatus = ((await row(false)).degraded as any[]).map((l) => [l.layer, l.reason, l.origin]);
|
|
328
|
+
expect(fromTask).toEqual(fromStatus);
|
|
329
|
+
});
|
|
330
|
+
|
|
275
331
|
test("stale → no `degraded`", async () => {
|
|
276
332
|
setHealth(DOWN_APP, Date.now() - NODE_HEALTH_TTL_MS - 1_000);
|
|
277
333
|
expect("degraded" in (await row(true))).toBe(false);
|
package/src/node-health-guard.ts
CHANGED
|
@@ -19,6 +19,17 @@ export type DegradedLayer = {
|
|
|
19
19
|
layer: "app_server" | "tui" | "model_auth";
|
|
20
20
|
/** 机器可读的原因:app_server 的错误摘要 / tui 的 reason / model_auth 的状态。 */
|
|
21
21
|
reason: string;
|
|
22
|
+
/**
|
|
23
|
+
* 2026-10-31 —— `reason` 是**谁写的**。
|
|
24
|
+
*
|
|
25
|
+
* `app_server.reason` 有两个生产者:节点上报的 `last_error`(≤200 任意串),
|
|
26
|
+
* 和 Hub 在自己这边合成的字面量 `"unreachable"`(节点没报错误摘要时)。
|
|
27
|
+
* 两者在同一个字段里 ⇒ 读者无法区分「节点说它 unreachable」与「Hub 根本没能问到节点」。
|
|
28
|
+
*
|
|
29
|
+
* ⇒ 改名 / 拆分 catch 都拦不住:**上游可以原样声明 `"unreachable"`**(`:148` 同形)。
|
|
30
|
+
* 所以判别力只能来自一个独立的来源字段。
|
|
31
|
+
*/
|
|
32
|
+
origin: "node" | "hub";
|
|
22
33
|
/** 给人看的一句(中文,与 app 的「降级」徽标同一套措辞)。 */
|
|
23
34
|
label: string;
|
|
24
35
|
hint: string;
|
|
@@ -39,6 +50,9 @@ export function degradedLayers(health: NodeHealth | null | undefined): DegradedL
|
|
|
39
50
|
out.push({
|
|
40
51
|
layer: "app_server",
|
|
41
52
|
reason: (health.app_server.last_error || "unreachable").slice(0, 200),
|
|
53
|
+
// 没有 upstream 摘要时这个串是**我们**写的;有则逐字是节点的。
|
|
54
|
+
// ⚠️ 节点自己也可以报 "unreachable" ⇒ 只有这一格能分辨。
|
|
55
|
+
origin: health.app_server.last_error ? "node" : "hub",
|
|
42
56
|
label: "App Server 断开",
|
|
43
57
|
hint: "节点的 codex app-server 端口没有响应:在节点所在机器上重启该节点(anet node restart <别名>)",
|
|
44
58
|
});
|
|
@@ -47,6 +61,7 @@ export function degradedLayers(health: NodeHealth | null | undefined): DegradedL
|
|
|
47
61
|
out.push({
|
|
48
62
|
layer: "tui",
|
|
49
63
|
reason: health.tui.reason,
|
|
64
|
+
origin: "node",
|
|
50
65
|
label: TUI_LABEL[health.tui.reason] ?? "TUI 不可用",
|
|
51
66
|
hint: "共存 TUI 不在运行:在节点所在机器上重新拉起该节点的 TUI(anet node restart <别名>)",
|
|
52
67
|
});
|
|
@@ -55,6 +70,7 @@ export function degradedLayers(health: NodeHealth | null | undefined): DegradedL
|
|
|
55
70
|
out.push({
|
|
56
71
|
layer: "model_auth",
|
|
57
72
|
reason: health.model_auth,
|
|
73
|
+
origin: "node",
|
|
58
74
|
label: health.model_auth === "revoked" ? "需要重新登录" : "登录已过期",
|
|
59
75
|
hint: "该节点自己的 CODEX_HOME 需要重新登录(在那台机器上:CODEX_HOME=<节点目录>/codex-home codex login);不要拷别的节点的 auth.json",
|
|
60
76
|
});
|
|
@@ -148,6 +148,9 @@ describe("list / read by alias reach a session with no nodes row", () => {
|
|
|
148
148
|
try {
|
|
149
149
|
const enq = await u.call("read_node_skill", { alias: SESSION_ALIAS, name: "ship" });
|
|
150
150
|
expect(enq).toMatchObject({ ok: true, op: "skill_read" });
|
|
151
|
+
// 2026-10-31 —— **精确键集**(#3171):此前只 matchObject 了两个字段。
|
|
152
|
+
// 这条响应是「入队回执」,多一个键就意味着回执开始夹带请求内容(那是另一条通道)。
|
|
153
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
151
154
|
const pulled = await s.call("get_rules_file_request", {});
|
|
152
155
|
expect(pulled.request).toEqual({ request_id: enq.request_id, op: "skill_read", content: "ship" });
|
|
153
156
|
const payload = JSON.stringify({ name: "ship", scope: "project", path_rel: ".claude/skills/ship/SKILL.md", description: "d", content: "# ship" });
|
|
@@ -21,6 +21,10 @@ const SECRET = /^(sk-|gh[pousr]_|github_pat_|xox[baprs]-|AKIA|AIza|ya29\.|glpat-
|
|
|
21
21
|
|
|
22
22
|
export const CATALOG_ERROR_CODES = [
|
|
23
23
|
"invalid_target", "unauthorized", "unavailable", "invalid_response", "scope_mismatch", "too_large",
|
|
24
|
+
// 2026-10-31 —— 两格新增,都要与 agent-node 侧的手工联合类型同步:
|
|
25
|
+
// "unexpected" 兜底不许点名因果(原先把非目录错误一律报 "unavailable")
|
|
26
|
+
// "directory_not_ascii" 传输层结构性限制:OpenCode 只认 header,而 header 运不了非 ASCII
|
|
27
|
+
"unexpected", "directory_not_ascii",
|
|
24
28
|
] as const;
|
|
25
29
|
export type CatalogErrorCode = (typeof CATALOG_ERROR_CODES)[number];
|
|
26
30
|
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { redactTokens, redactMessageRow } from "./redact-tokens.js";
|
|
2
|
+
import { TOKEN_PATTERNS, redactTokens, redactMessageRow } from "./redact-tokens.js";
|
|
3
|
+
|
|
4
|
+
// 2026-10-31 —— **计数管「有没有少」,集合管「有没有被换」**(外部复核:
|
|
5
|
+
// 「删一条加一条,数不变,而遮掉的东西变了」)。
|
|
6
|
+
// 这份清单是凭据形状的**唯一防线**,所以它需要的是身份断言,不是规模断言。
|
|
7
|
+
test("credential shape list is pinned by identity, not by count", () => {
|
|
8
|
+
// ① 规模:少了要红
|
|
9
|
+
expect(TOKEN_PATTERNS).toHaveLength(5);
|
|
10
|
+
// ② 身份:换了也要红(把 sk- 换成 bearer、把 ghp_ 换成 gho_ 都会落在这里)
|
|
11
|
+
expect(TOKEN_PATTERNS.map((r) => r.source).sort()).toEqual([
|
|
12
|
+
"\\b(ghp_)[A-Za-z0-9]{20,}",
|
|
13
|
+
"\\b(github_pat_)[A-Za-z0-9_]{20,}",
|
|
14
|
+
"\\b(ntok_|utok_|atok_)[A-Za-z0-9_-]{6,}",
|
|
15
|
+
"\\b(sk-)[A-Za-z0-9_-]{16,}",
|
|
16
|
+
"\\b(xox[bpoars]-)[A-Za-z0-9-]{10,}",
|
|
17
|
+
].sort());
|
|
18
|
+
// ③ 前提:每条都必须带一个捕获组(前缀要保留给人看),且必须是全局的(一次替换多处)
|
|
19
|
+
for (const re of TOKEN_PATTERNS) {
|
|
20
|
+
expect(re.global).toBe(true);
|
|
21
|
+
expect(re.source.includes("(")).toBe(true);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
3
24
|
|
|
4
25
|
describe("#1459 ③ redact-at-read", () => {
|
|
5
26
|
test("🔴 各种前缀形状都被遮住,且前缀保留(读者仍知道泄漏的是哪一类)", () => {
|
package/src/redact-tokens.ts
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* 🔴 前缀用**捕获组显式声明**,不靠"切到第一个下划线"之类的推断 ——
|
|
13
13
|
* 第一版就是那么写的,`github_pat_xxx` 被切成了 `github_`,把"这是哪一类
|
|
14
14
|
* 凭据"这个唯一有用的信息也遮掉了。声明比推断短,也不会错。 */
|
|
15
|
-
|
|
15
|
+
// 2026-10-31 —— 导出这份清单,是因为**「条数对」不等于「内容是同一套」**
|
|
16
|
+
// (外部复核:「删一条加一条,数不变,而遮掉的东西变了」)。
|
|
17
|
+
// 只断言 length=5 的门,对「把 sk- 换成 bearer 」这种换手完全无感。
|
|
18
|
+
export const TOKEN_PATTERNS: ReadonlyArray<RegExp> = [
|
|
16
19
|
/\b(ntok_|utok_|atok_)[A-Za-z0-9_-]{6,}/g, // 本仓自己的 token
|
|
17
20
|
/\b(github_pat_)[A-Za-z0-9_]{20,}/g, // GitHub fine-grained PAT(必须排在 ghp_ 之前无关,但更长的前缀先声明更清楚)
|
|
18
21
|
/\b(ghp_)[A-Za-z0-9]{20,}/g, // GitHub classic PAT
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// 2026-10-31 —— 拒绝原因计数的契约。
|
|
2
|
+
//
|
|
3
|
+
// 三条断言对应三条设计约束(见 rejection-counters.ts):
|
|
4
|
+
// ① 按 reason 分桶(不是只有一个总数)
|
|
5
|
+
// ② 键有限/可枚举(客户端塞不了长串把键空间撑爆)
|
|
6
|
+
// ③ 快照有序(两次读数可比;无序 Map 会让“同一个计数器”看起来在变)
|
|
7
|
+
|
|
8
|
+
import { describe, expect, test, beforeEach } from "bun:test";
|
|
9
|
+
import {
|
|
10
|
+
recordTaskRejection,
|
|
11
|
+
taskRejectionCounters,
|
|
12
|
+
resetTaskRejectionCounters,
|
|
13
|
+
} from "./rejection-counters.js";
|
|
14
|
+
|
|
15
|
+
beforeEach(() => resetTaskRejectionCounters());
|
|
16
|
+
|
|
17
|
+
describe("taskRejectionCounters", () => {
|
|
18
|
+
test("buckets by status+code — a bare total would count frequency and hide the reason", () => {
|
|
19
|
+
recordTaskRejection(401, "unauthorized");
|
|
20
|
+
recordTaskRejection(401, "unauthorized");
|
|
21
|
+
recordTaskRejection(400, "model_package_request_invalid");
|
|
22
|
+
recordTaskRejection(403, "runtime_sdk_csrf_invalid");
|
|
23
|
+
const c = taskRejectionCounters();
|
|
24
|
+
expect(c.total).toBe(4);
|
|
25
|
+
expect(c.by_reason).toEqual({
|
|
26
|
+
"400:model_package_request_invalid": 1,
|
|
27
|
+
"401:unauthorized": 2,
|
|
28
|
+
"403:runtime_sdk_csrf_invalid": 1,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("missing or non-string code falls into `unknown` — never silently merges into another bucket", () => {
|
|
33
|
+
recordTaskRejection(500, undefined);
|
|
34
|
+
recordTaskRejection(500, null);
|
|
35
|
+
recordTaskRejection(500, 42);
|
|
36
|
+
const c = taskRejectionCounters();
|
|
37
|
+
expect(c.by_reason["500:unknown"]).toBe(3);
|
|
38
|
+
expect(c.total).toBe(3);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("sanitizes the code so a client cannot inflate the key space", () => {
|
|
42
|
+
recordTaskRejection(400, "../../etc/passwd " + "x".repeat(200));
|
|
43
|
+
const c = taskRejectionCounters();
|
|
44
|
+
const keys = Object.keys(c.by_reason);
|
|
45
|
+
expect(keys.length).toBe(1);
|
|
46
|
+
// 只保留 \w . : - 且截断到 48 —— 键里不可能出现路径分隔或空白。
|
|
47
|
+
expect(keys[0]).toMatch(/^400:[A-Za-z0-9_.:-]+$/);
|
|
48
|
+
expect(keys[0].length).toBeLessThanOrEqual(48 + "400:".length);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("snapshot is sorted and capped, with the overflow folded into `other`", () => {
|
|
52
|
+
for (let i = 0; i < 70; i += 1) recordTaskRejection(400, `code_${String(i).padStart(3, "0")}`);
|
|
53
|
+
const c = taskRejectionCounters();
|
|
54
|
+
const keys = Object.keys(c.by_reason);
|
|
55
|
+
expect(c.total).toBe(70);
|
|
56
|
+
expect(keys.length).toBe(65); // 64 个桶 + other
|
|
57
|
+
expect(c.by_reason.other).toBe(6);
|
|
58
|
+
// 有序:每次遍历顺序一致(否则两次快照无法比较)。
|
|
59
|
+
const sorted = [...keys.filter((k) => k !== "other")].sort();
|
|
60
|
+
expect(keys.filter((k) => k !== "other")).toEqual(sorted);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("empty state is a readable zero, not an absent field", () => {
|
|
64
|
+
expect(taskRejectionCounters()).toEqual({ scope: "process_lifetime", total: 0, by_reason: {} });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// 2026-10-31 —— null 的第三个成因:记录还在日志里,只是不在这个窗口里。
|
|
68
|
+
// 那个事实必须由**数据**说出来,不能只写在注释里(读者不会去看注释)。
|
|
69
|
+
test("scope names the counter's lifetime, so a zero cannot be read as 'never happened'", () => {
|
|
70
|
+
expect(taskRejectionCounters().scope).toBe("process_lifetime");
|
|
71
|
+
});
|
|
72
|
+
});
|