@sleep2agi/commhub-server 0.9.0-preview.257 → 0.9.0-preview.259
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 +2 -2
- package/package.json +1 -1
- package/src/agent-acl-http.test.ts +5 -0
- package/src/agent-acl-slice3-http.test.ts +168 -0
- package/src/api-nodes-shape.test.ts +38 -2
- package/src/auth-abuse-counters.test.ts +125 -0
- package/src/auth-abuse-counters.ts +122 -0
- package/src/binding-generation-http.test.ts +10 -1
- package/src/clone-node.test.ts +7 -0
- package/src/create-node-blocked-gate.test.ts +9 -0
- package/src/create-node-error-domain.test.ts +124 -0
- package/src/daemon-provider-snapshots.test.ts +9 -1
- package/src/daemon-token-owner-http.test.ts +54 -0
- package/src/departments-agent-count.test.ts +7 -0
- package/src/departments-mcp-error-domain.test.ts +135 -0
- package/src/expiry-counters.ts +6 -2
- package/src/expiry-evidence-db.test.ts +15 -0
- package/src/inbox-count-sse.test.ts +8 -0
- package/src/list-ack-error-domain.test.ts +108 -0
- package/src/mcp-projects-events-http.test.ts +3 -0
- package/src/mcp-write-network-resolution.test.ts +15 -0
- package/src/network-scope.ts +24 -0
- package/src/node-daemon-bindings.test.ts +12 -2
- package/src/node-files-transport.test.ts +3 -0
- package/src/node-logs-transport.test.ts +3 -0
- package/src/node-security-write-gate.test.ts +72 -0
- package/src/probe-provider-error-domain.test.ts +141 -0
- package/src/provider-skill-error-domain.test.ts +130 -0
- package/src/provider-tools-shape.test.ts +16 -1
- package/src/requirement-participant-notify-http.test.ts +4 -0
- package/src/requirements-mcp.test.ts +17 -1
- package/src/rules-file-transport.test.ts +38 -4
- package/src/schedule-agent-mcp-http.test.ts +12 -1
- package/src/scheduled-requirement-wake-http.test.ts +5 -1
- package/src/server.ts +25 -5
- package/src/skillhub-http.test.ts +4 -2
- package/src/start-request-error-domain.test.ts +182 -0
- package/src/start-skill-error-domain.test.ts +122 -0
- package/src/task-consumption.test.ts +6 -0
- package/src/task-idempotency-mcp.test.ts +6 -0
- package/src/task-not-found-error-domain.test.ts +76 -0
- package/src/update-node-config-error-domain.test.ts +107 -0
package/src/network-scope.ts
CHANGED
|
@@ -266,6 +266,30 @@ export function canRestWriteNetwork(authCtx: { userId: string; networkId: string
|
|
|
266
266
|
return !isAgentRestricted(authCtx.userId, networkId);
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* 能不能改**节点自身的安全配置**(permission-mode / rest-allowlist / peer-allowlist)。
|
|
271
|
+
*
|
|
272
|
+
* 这一类比 canRestWriteNetwork **更严**:后者放行任何非 viewer 成员,而改白名单等于
|
|
273
|
+
* 改这台节点还能做什么,所以只许 节点主人 / 网络 owner / 网络 admin / Hub 管理员
|
|
274
|
+
* (RFC-041 §2.3 / §2.4)。
|
|
275
|
+
*
|
|
276
|
+
* 为什么单独具名而不是复用 canRestWriteNetwork:两处调用点看起来在讲同一件事
|
|
277
|
+
* ("谁能改这个节点"),但强度差在被调函数里 —— 合并的方向是**放宽**,不是重构。
|
|
278
|
+
* 具名之后,静态检查只要认一个名字;不具名时,新写的路由会照抄它附近那一行,
|
|
279
|
+
* 而"附近那一行"是哪一种取决于作者当时读到哪段代码。
|
|
280
|
+
*/
|
|
281
|
+
export function canRestWriteNodeSecurity(
|
|
282
|
+
authCtx: { userId: string } | null,
|
|
283
|
+
ownerUserId: string | null,
|
|
284
|
+
networkRole: string | null,
|
|
285
|
+
isAdmin: boolean,
|
|
286
|
+
): boolean {
|
|
287
|
+
if (isAdmin) return true;
|
|
288
|
+
if (!authCtx) return false;
|
|
289
|
+
if (ownerUserId && ownerUserId === authCtx.userId) return true;
|
|
290
|
+
return networkRole === "owner" || networkRole === "admin";
|
|
291
|
+
}
|
|
292
|
+
|
|
269
293
|
/** 旧的「成员且不是 viewer」判据,不看 Agent 授权。只给人类侧写入用。 */
|
|
270
294
|
export function canRestWriteNetworkAsHuman(authCtx: { userId: string; networkId: string | null } | null, networkId: string | null, isAdmin: boolean): boolean {
|
|
271
295
|
if (!authCtx) return true; // legacy global token or open dev mode
|
|
@@ -61,8 +61,18 @@ test("adopted stop/start complete through existing protocol; revocation removes
|
|
|
61
61
|
expect((await call(d.list_my_children)).children[0].lifecycle_state).toBe("stopped");
|
|
62
62
|
const start = await call(u.start_node, { child_node_id: CHILD, network_id: NET }); expect(start.ok).toBe(true);
|
|
63
63
|
expect((await call(d.get_start_request, { request_id: start.request_id })).ok).toBe(true);
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// #3309 分支 —— ack_start_request 的**成功出口**(此前只钉了它的三条失败分支:
|
|
65
|
+
// request_not_found / not_your_request / cross_network_request)。
|
|
66
|
+
// 先接住再断言,形状由这次真实调用给出。
|
|
67
|
+
const startedAck = await call(d.ack_start_request, { request_id: start.request_id, status: "started", child_pid: 4321 });
|
|
68
|
+
expect(startedAck.ok).toBe(true);
|
|
69
|
+
expect(Object.keys(startedAck).sort()).toEqual(["ok", "status"]);
|
|
70
|
+
// #3275 批次 4 —— 先接住再断言(同变量口径)
|
|
71
|
+
const unadopted = await call(u.unadopt_node, { node_id: CHILD });
|
|
72
|
+
// #3275 批次 4 —— unadopt_node 两键 {ok, status}(实测):status 说明解绑后的生命周期档,
|
|
73
|
+
// 少了它,调用方只知「成功」,不知「现在是哪一档」。
|
|
74
|
+
expect(Object.keys(unadopted).sort()).toEqual(["ok", "status"]);
|
|
75
|
+
expect(unadopted.ok).toBe(true);
|
|
66
76
|
expect((await call(d.list_my_children)).children).toHaveLength(0);
|
|
67
77
|
expect((await call(u.stop_node, { child_node_id: CHILD, daemon_node_id: DAEMON, network_id: NET })).ok).toBe(false);
|
|
68
78
|
});
|
|
@@ -251,6 +251,9 @@ describe("who may ask, and who may read the answer", () => {
|
|
|
251
251
|
const other = await connect(asUserOtherLogin);
|
|
252
252
|
try {
|
|
253
253
|
const enq = await u.call("list_node_skills", { alias: SESSION_ALIAS });
|
|
254
|
+
// #3275 批次 4 —— list_node_skills 走的是**与 read/write/tail 同一条下发通道**
|
|
255
|
+
// (所以外层是三键 ok/op/request_id);技能清单本体在 get_rules_file_request 里回。
|
|
256
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
254
257
|
expect(await other.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, status: "pending" });
|
|
255
258
|
} finally { await u.close(); await other.close(); }
|
|
256
259
|
}, 20_000);
|
|
@@ -131,6 +131,9 @@ describe("round trip", () => {
|
|
|
131
131
|
const a = await connect(asA);
|
|
132
132
|
try {
|
|
133
133
|
const enq = await u.call("tail_node_logs", { node_id: NODE_A_ID, network_id: NET, lines: 99999 > 2000 ? 2000 : 1, level: "warn", grep: "boom", since_ts: 5, path: "/etc/passwd" });
|
|
134
|
+
// #3275 批次 4 —— tail_node_logs 与 read_node_rules_file 是**同一套请求通道**(op 不同),
|
|
135
|
+
// 所以外层同形三键;钉它等于钉住「日志与规则文件共用一条下发通道」这个事实。
|
|
136
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
134
137
|
expect(enq).toMatchObject({ ok: true, op: "logs_tail" });
|
|
135
138
|
const pulled = (await a.call("get_rules_file_request", {})).request;
|
|
136
139
|
expect(pulled.op).toBe("logs_tail");
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// #3314 — 「改节点安全配置」的授权判据必须是**一个具名函数**,并且比
|
|
2
|
+
// 「往网络里写」更严(member 不行)。
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要这条测试:这两件事在调用点长得一样(都是 `if (!<条件>) 403`),
|
|
5
|
+
// 而强度差在被调函数里 —— canRestWriteNetwork 放行任何非 viewer 成员,
|
|
6
|
+
// 改白名单则只许 节点主人 / 网络 owner / 网络 admin / Hub 管理员。
|
|
7
|
+
// 一旦有人为了「统一写法」把它们合并,方向是**放宽**,而放宽不会让任何
|
|
8
|
+
// 现有测试变红:现有夹具全是 owner / admin 探针。
|
|
9
|
+
//
|
|
10
|
+
// 所以这里直接钉两件事:
|
|
11
|
+
// 1. 矩阵:owner_user / network owner / network admin / hub admin 放行,
|
|
12
|
+
// member / viewer / 陌生人 / 无身份 拒绝;
|
|
13
|
+
// 2. 不对称:同一个 member 在 canRestWriteNetwork 下放行、在这条门下拒绝 ——
|
|
14
|
+
// 如果哪天两者相等,这条测试先红,而不是等一条新写的路由把白名单改了。
|
|
15
|
+
|
|
16
|
+
import { test } from "node:test";
|
|
17
|
+
import assert from "node:assert/strict";
|
|
18
|
+
import { canRestWriteNodeSecurity } from "./network-scope.js";
|
|
19
|
+
|
|
20
|
+
const OWNER_ID = "u-node-owner";
|
|
21
|
+
const ADMIN_ID = "u-node-admin";
|
|
22
|
+
const MEMBER_ID = "u-member";
|
|
23
|
+
const VIEWER_ID = "u-viewer";
|
|
24
|
+
const STRANGER_ID = "u-stranger";
|
|
25
|
+
|
|
26
|
+
function ctx(userId: string) {
|
|
27
|
+
return { userId };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
test("node security gate: 节点主人可以改", () => {
|
|
31
|
+
assert.equal(canRestWriteNodeSecurity(ctx(OWNER_ID), OWNER_ID, null, false), true);
|
|
32
|
+
// 主人即使在该网络里没有角色(节点被挪过网络)仍然可以改自己的节点
|
|
33
|
+
assert.equal(canRestWriteNodeSecurity(ctx(OWNER_ID), OWNER_ID, "member", false), true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("node security gate: 网络 owner / admin 可以改别人的节点", () => {
|
|
37
|
+
assert.equal(canRestWriteNodeSecurity(ctx("u-net-owner"), "u-other", "owner", false), true);
|
|
38
|
+
assert.equal(canRestWriteNodeSecurity(ctx("u-net-admin"), "u-other", "admin", false), true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("node security gate: Hub 管理员可以改(且不依赖任何角色)", () => {
|
|
42
|
+
assert.equal(canRestWriteNodeSecurity(ctx(ADMIN_ID), "u-other", null, true), true);
|
|
43
|
+
assert.equal(canRestWriteNodeSecurity(ctx(ADMIN_ID), null, null, true), true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("node security gate: 普通成员 / viewer / 陌生人 / 无身份 全部拒绝", () => {
|
|
47
|
+
assert.equal(canRestWriteNodeSecurity(ctx(MEMBER_ID), "u-other", "member", false), false);
|
|
48
|
+
assert.equal(canRestWriteNodeSecurity(ctx(VIEWER_ID), "u-other", "viewer", false), false);
|
|
49
|
+
assert.equal(canRestWriteNodeSecurity(ctx(STRANGER_ID), "u-other", null, false), false);
|
|
50
|
+
assert.equal(canRestWriteNodeSecurity(null, "u-other", "owner", false), false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("node security gate: 孤儿节点(owner_user_id 为 null)不会被任何人「顺走」", () => {
|
|
54
|
+
// 没有主人的节点只能由网络 owner/admin 或 Hub 管理员改;
|
|
55
|
+
// 否则任意登录用户都能认领一台陌生节点的安全配置。
|
|
56
|
+
assert.equal(canRestWriteNodeSecurity(ctx(STRANGER_ID), null, null, false), false);
|
|
57
|
+
assert.equal(canRestWriteNodeSecurity(ctx("u-net-admin"), null, "admin", false), true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("node security gate 比 canRestWriteNetwork 更严:member 是分界线", async () => {
|
|
61
|
+
// 这条断言的意义不是「两个函数都写对了」,而是「它们**不允许**相等」。
|
|
62
|
+
// 若有人把它们合并成一个,下面两行里必然有一行红。
|
|
63
|
+
const { canRestWriteNetworkAsHuman } = await import("./network-scope.js");
|
|
64
|
+
// canRestWriteNetworkAsHuman 对 member 放行(!== viewer),对 stranger 拒绝。
|
|
65
|
+
// 这里用 userId 到一个不存在网络的方式调用,避免依赖真实 DB 角色:
|
|
66
|
+
// networkId=null ⇒ 非 admin 一律 false。所以真正的不对称要在有角色的网络里比,
|
|
67
|
+
// 那需要 DB 夹具;本测试只钉住「两者不是同一个函数」这个形状。
|
|
68
|
+
assert.notEqual(canRestWriteNodeSecurity, canRestWriteNetworkAsHuman);
|
|
69
|
+
// 纯函数层面的不对称:网络角色为 member 时,安全门拒绝(上面已断言),
|
|
70
|
+
// 而「写网络」那侧的判据只排除 viewer —— 记录在这里作为可读对照。
|
|
71
|
+
assert.equal(canRestWriteNodeSecurity(ctx(MEMBER_ID), "u-other", "member", false), false);
|
|
72
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// #3309 第四条口径 —— `probe_provider_model` 的 4 个 error 字面量此前在测试里**一次都没出现过**:
|
|
2
|
+
//
|
|
3
|
+
// insufficient_role_for_probe / provider_not_found / provider_disabled / secret_not_in_vault
|
|
4
|
+
//
|
|
5
|
+
// 现有的 provider-tools-shape.test.ts 覆盖的是**成功路径**(provider 存在、model 存在、
|
|
6
|
+
// daemon 存在、vault 里有 key)—— 于是这四条拒绝分支从来没被走过。
|
|
7
|
+
//
|
|
8
|
+
// 这里逐个真的触发一次,并断言 `error` 的**确切值**。特别钉住相邻两条不能混:
|
|
9
|
+
//
|
|
10
|
+
// provider 不存在 ⇒ provider_not_found
|
|
11
|
+
// provider 存在但停用 ⇒ provider_disabled
|
|
12
|
+
//
|
|
13
|
+
// 只断言 ok===false 时两者同形,而处置相反(前者要建,后者只要启用)。
|
|
14
|
+
// 代码注释里也写了这条意图("Distinguish not found from disabled so the dashboard
|
|
15
|
+
// can render the right error")—— 注释没有读数,断言才有。
|
|
16
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
17
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
|
+
import { db } from "./db.js";
|
|
19
|
+
import { registerTools } from "./tools.js";
|
|
20
|
+
import { stopBackgroundProbeTimersForTest } from "./probe.js";
|
|
21
|
+
|
|
22
|
+
// vault 根密钥存在时 vaultGet 才会「查而不得」(返回 null),否则它自己抛错走另一个分支。
|
|
23
|
+
process.env.ANET_HUB_SECRET_VAULT_KEY ||= "43".repeat(32);
|
|
24
|
+
|
|
25
|
+
const NET = "net_probe_err";
|
|
26
|
+
const ADMIN = "u_probe_err_admin";
|
|
27
|
+
const MEMBER = "u_probe_err_member";
|
|
28
|
+
const PROVIDER = "prov_err";
|
|
29
|
+
const DAEMON = "node_probe_err_daemon";
|
|
30
|
+
|
|
31
|
+
type ToolHandler = (args: any) => Promise<any>;
|
|
32
|
+
|
|
33
|
+
function handlers(userId: string): Record<string, ToolHandler> {
|
|
34
|
+
const server = new McpServer({ name: "t", version: "0" }) as any;
|
|
35
|
+
const tools: Record<string, ToolHandler> = {};
|
|
36
|
+
const orig = server.tool.bind(server);
|
|
37
|
+
server.tool = (name: string, desc: string, schema: any, handler: ToolHandler) => {
|
|
38
|
+
tools[name] = handler;
|
|
39
|
+
return orig(name, desc, schema, handler);
|
|
40
|
+
};
|
|
41
|
+
registerTools(server, undefined, NET, userId, null, false, null);
|
|
42
|
+
return tools;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function callProbe(userId: string, args: Record<string, unknown>) {
|
|
46
|
+
const r = await handlers(userId).probe_provider_model(args);
|
|
47
|
+
return JSON.parse(r.content[0].text);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const base = { provider_id: PROVIDER, model_name: "probe-model", daemon_node_id: DAEMON };
|
|
51
|
+
|
|
52
|
+
// 2026-11-01 —— **精确键集,写成集合相等**(不是计数、也不是「有这几个字段」)。
|
|
53
|
+
// 计数可以被换名满足;字段级断言放过多给的键。两者都放过「换名 + 少给」这种最常见的结构变动。
|
|
54
|
+
function expectKeys(obj: Record<string, unknown>, want: string[]) {
|
|
55
|
+
expect(Object.keys(obj).sort(), "键集合必须完全等于期望").toEqual([...want].sort());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function cleanup() {
|
|
59
|
+
db.run("DELETE FROM provider_models WHERE provider_id = ?1", [PROVIDER]);
|
|
60
|
+
db.run("DELETE FROM providers WHERE network_id = ?1", [NET]);
|
|
61
|
+
db.run("DELETE FROM network_members WHERE network_id = ?1", [NET]);
|
|
62
|
+
db.run("DELETE FROM nodes WHERE network_id = ?1", [NET]);
|
|
63
|
+
db.run("DELETE FROM networks WHERE network_id = ?1", [NET]);
|
|
64
|
+
db.run("DELETE FROM users WHERE user_id IN (?1, ?2)", [ADMIN, MEMBER]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function seed(opts: { enabled: number; secretKey: string }) {
|
|
68
|
+
cleanup();
|
|
69
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [ADMIN]);
|
|
70
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [MEMBER]);
|
|
71
|
+
db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, ADMIN]);
|
|
72
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [ADMIN, NET]);
|
|
73
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'member', datetime('now'))", [MEMBER, NET]);
|
|
74
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, runtime, model, channels, config_snapshot,
|
|
75
|
+
hostname, created_at, updated_at, lifecycle_state)
|
|
76
|
+
VALUES (?1, 'probe-err-daemon', 'probe-err-daemon', ?2, 'claude-agent-sdk', 'm', '[]', '{}', 'host-e',
|
|
77
|
+
datetime('now'), datetime('now'), 'active')`, [DAEMON, NET]);
|
|
78
|
+
db.run(`INSERT INTO providers (provider_id, network_id, name, vendor, base_url, secret_key_ref, created_at, created_by, enabled)
|
|
79
|
+
VALUES (?1, ?2, 'err-provider', 'anthropic', 'https://api.anthropic.com', ?3, ?4, ?5, ?6)`,
|
|
80
|
+
[PROVIDER, NET, opts.secretKey, Date.now(), ADMIN, opts.enabled]);
|
|
81
|
+
db.run(`INSERT INTO provider_models (model_id, provider_id, model_name, display_name, created_at)
|
|
82
|
+
VALUES ('pm_err', ?1, 'probe-model', 'Probe Model', ?2)`, [PROVIDER, Date.now()]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
beforeEach(() => seed({ enabled: 1, secretKey: "PROBE_ERR_ABSENT" }));
|
|
86
|
+
afterAll(() => { stopBackgroundProbeTimersForTest(); cleanup(); });
|
|
87
|
+
|
|
88
|
+
describe("#3309 probe_provider_model 错误值域:四条拒绝各有一条会红的断言", () => {
|
|
89
|
+
test("成员(非 owner/admin)⇒ error === insufficient_role_for_probe", async () => {
|
|
90
|
+
const r = await callProbe(MEMBER, base);
|
|
91
|
+
expect(r.ok).toBe(false);
|
|
92
|
+
expect(r.error).toBe("insufficient_role_for_probe");
|
|
93
|
+
// 拒绝体还带着「需要什么角色 / 调用者是什么角色」—— 否则读的人只知道被拒,不知道为什么。
|
|
94
|
+
expect(r.required_role).toBe("admin");
|
|
95
|
+
expect(r.caller_role).toBe("member");
|
|
96
|
+
expectKeys(r, ["ok", "error", "required_role", "caller_role"]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("provider 不存在 ⇒ error === provider_not_found", async () => {
|
|
100
|
+
const r = await callProbe(ADMIN, { ...base, provider_id: "prov_does_not_exist" });
|
|
101
|
+
expect(r.ok).toBe(false);
|
|
102
|
+
expect(r.error).toBe("provider_not_found");
|
|
103
|
+
expect(r.provider_id).toBe("prov_does_not_exist");
|
|
104
|
+
expectKeys(r, ["ok", "error", "provider_id"]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("provider 存在但停用 ⇒ error === provider_disabled(**不是** provider_not_found)", async () => {
|
|
108
|
+
seed({ enabled: 0, secretKey: "PROBE_ERR_ABSENT" });
|
|
109
|
+
const r = await callProbe(ADMIN, base);
|
|
110
|
+
expect(r.ok).toBe(false);
|
|
111
|
+
expect(r.error).toBe("provider_disabled");
|
|
112
|
+
// 这两条的区别就是这张测试存在的理由:一个要建、一个只要启用。
|
|
113
|
+
expect(r.error).not.toBe("provider_not_found");
|
|
114
|
+
expect(r.hint).toContain("enabled:true");
|
|
115
|
+
expectKeys(r, ["ok", "error", "provider_id", "hint"]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("provider 引用的密钥不在 vault ⇒ error === secret_not_in_vault,且带上键名", async () => {
|
|
119
|
+
const r = await callProbe(ADMIN, base);
|
|
120
|
+
expect(r.ok).toBe(false);
|
|
121
|
+
expect(r.error).toBe("secret_not_in_vault");
|
|
122
|
+
expect(r.key).toBe("PROBE_ERR_ABSENT");
|
|
123
|
+
expectKeys(r, ["ok", "error", "key"]);
|
|
124
|
+
// 键名是标识不是凭据:报出来才能让人去补哪一把。
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("四条的形状都**没有** code 字段(现状,不是契约)", async () => {
|
|
128
|
+
const cases = [
|
|
129
|
+
await callProbe(MEMBER, base),
|
|
130
|
+
await callProbe(ADMIN, { ...base, provider_id: "prov_does_not_exist" }),
|
|
131
|
+
];
|
|
132
|
+
seed({ enabled: 0, secretKey: "PROBE_ERR_ABSENT" });
|
|
133
|
+
cases.push(await callProbe(ADMIN, base));
|
|
134
|
+
seed({ enabled: 1, secretKey: "PROBE_ERR_ABSENT" });
|
|
135
|
+
cases.push(await callProbe(ADMIN, base));
|
|
136
|
+
for (const r of cases) {
|
|
137
|
+
expect(r.ok).toBe(false);
|
|
138
|
+
expect(Object.prototype.hasOwnProperty.call(r, "code")).toBe(false);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// #3309 读数覆盖第六批 —— 四个 error 字面量此前在测试里一次都没出现过:
|
|
2
|
+
//
|
|
3
|
+
// upsert_provider : insufficient_role_for_provider / provider_name_conflict
|
|
4
|
+
// review_skill : skill_review_admin_required / skill_not_pending
|
|
5
|
+
//
|
|
6
|
+
// 两对各有一个「只差一层」的近邻,而处置完全不同:
|
|
7
|
+
// insufficient_role_for_provider ↔ provider_name_conflict
|
|
8
|
+
// 换人提权 ↔ 换个名字(或先删旧的)
|
|
9
|
+
// skill_review_admin_required ↔ skill_not_pending
|
|
10
|
+
// 换人提权 ↔ 这个技能已经被审过,不必再审
|
|
11
|
+
//
|
|
12
|
+
// 只断言 ok===false 时,四条与「网络不通」「id 不存在」同形。
|
|
13
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
14
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
15
|
+
import { db } from "./db.js";
|
|
16
|
+
import { registerTools } from "./tools.js";
|
|
17
|
+
|
|
18
|
+
// vault 根密钥必须存在,否则 upsert_network_secret 直接失败(与 provider-tools-shape.test.ts 同一做法)。
|
|
19
|
+
process.env.ANET_HUB_SECRET_VAULT_KEY ||= "44".repeat(32);
|
|
20
|
+
|
|
21
|
+
const NET = "net_6th_err";
|
|
22
|
+
const ADMIN = "u_6th_admin";
|
|
23
|
+
const MEMBER = "u_6th_member";
|
|
24
|
+
const SKILL = "skill_6th_pending";
|
|
25
|
+
|
|
26
|
+
type ToolHandler = (args: any) => Promise<{ content: Array<{ type: "text"; text: string }> }>;
|
|
27
|
+
|
|
28
|
+
function handlers(userId: string): Record<string, ToolHandler> {
|
|
29
|
+
const server = new McpServer({ name: "t", version: "0" }) as any;
|
|
30
|
+
const out: Record<string, ToolHandler> = {};
|
|
31
|
+
const orig = server.tool.bind(server);
|
|
32
|
+
server.tool = (n: string, d: string, s: any, h: ToolHandler) => { out[n] = h; return orig(n, d, s, h); };
|
|
33
|
+
registerTools(server, undefined, NET, userId, null, false, null);
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function call(userId: string, name: string, args: Record<string, unknown>) {
|
|
38
|
+
const r = await handlers(userId)[name](args as any);
|
|
39
|
+
return JSON.parse(r.content[0].text) as { ok?: boolean; error?: string; [k: string]: unknown };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function cleanup() {
|
|
43
|
+
try { db.run("DELETE FROM provider_models WHERE provider_id IN (SELECT provider_id FROM providers WHERE network_id = ?1)", [NET]); } catch {}
|
|
44
|
+
try { db.run("DELETE FROM providers WHERE network_id = ?1", [NET]); } catch {}
|
|
45
|
+
try { db.run("DELETE FROM skillhub_skills WHERE network_id = ?1", [NET]); } catch {}
|
|
46
|
+
try { db.run("DELETE FROM network_secrets WHERE network_id = ?1", [NET]); } catch {}
|
|
47
|
+
try { db.run("DELETE FROM network_members WHERE network_id = ?1", [NET]); } catch {}
|
|
48
|
+
try { db.run("DELETE FROM networks WHERE network_id = ?1", [NET]); } catch {}
|
|
49
|
+
try { db.run("DELETE FROM users WHERE user_id IN (?1, ?2)", [ADMIN, MEMBER]); } catch {}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function seed() {
|
|
53
|
+
cleanup();
|
|
54
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [ADMIN]);
|
|
55
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [MEMBER]);
|
|
56
|
+
db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, ADMIN]);
|
|
57
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [ADMIN, NET]);
|
|
58
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'member', datetime('now'))", [MEMBER, NET]);
|
|
59
|
+
db.run(
|
|
60
|
+
`INSERT INTO skillhub_skills (skill_id, network_id, slug, name, description, content, content_hash, version,
|
|
61
|
+
status, source_type, created_at, updated_at)
|
|
62
|
+
VALUES (?1, ?2, 'sixth', 'Sixth', 'd', 'body', 'h', '1.0.0', 'published', 'user',
|
|
63
|
+
datetime('now'), datetime('now'))`,
|
|
64
|
+
[SKILL, NET],
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
beforeEach(seed);
|
|
69
|
+
afterAll(cleanup);
|
|
70
|
+
|
|
71
|
+
describe("#3309 upsert_provider / review_skill 的错误值域", () => {
|
|
72
|
+
test("成员建 provider ⇒ insufficient_role_for_provider(带 required_role / caller_role)", async () => {
|
|
73
|
+
const r = await call(MEMBER, "upsert_provider", {
|
|
74
|
+
name: "sixth-provider", vendor: "anthropic", base_url: "https://api.anthropic.com",
|
|
75
|
+
secret_key_ref: "SIXTH_KEY", models: [],
|
|
76
|
+
});
|
|
77
|
+
expect(r.ok).toBe(false);
|
|
78
|
+
expect(r.error).toBe("insufficient_role_for_provider");
|
|
79
|
+
expect(r.required_role).toBe("admin");
|
|
80
|
+
expect(r.caller_role).toBe("member");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("同名 provider 第二次入库 ⇒ provider_name_conflict(带 name)", async () => {
|
|
84
|
+
// 先把 vault key 备好,否则会先撞 secret_not_in_vault,走不到 UNIQUE 那一步。
|
|
85
|
+
const sec = await call(ADMIN, "upsert_network_secret", { key: "SIXTH_KEY", value: "sk-sixth-not-real" });
|
|
86
|
+
expect(sec.ok).toBe(true);
|
|
87
|
+
const args = {
|
|
88
|
+
name: "sixth-dup", vendor: "anthropic", base_url: "https://api.anthropic.com",
|
|
89
|
+
secret_key_ref: "SIXTH_KEY", models: [],
|
|
90
|
+
};
|
|
91
|
+
const first = await call(ADMIN, "upsert_provider", args);
|
|
92
|
+
expect(first.ok).toBe(true);
|
|
93
|
+
const second = await call(ADMIN, "upsert_provider", args);
|
|
94
|
+
expect(second.ok).toBe(false);
|
|
95
|
+
expect(second.error).toBe("provider_name_conflict");
|
|
96
|
+
expect(second.name).toBe("sixth-dup");
|
|
97
|
+
// 与 insufficient_role 的区别:这不是权限问题,换个名字就好。
|
|
98
|
+
expect(second.error).not.toBe("insufficient_role_for_provider");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("成员审技能 ⇒ skill_review_admin_required", async () => {
|
|
102
|
+
const r = await call(MEMBER, "review_skill", { skill_id: SKILL, decision: "published" });
|
|
103
|
+
expect(r.ok).toBe(false);
|
|
104
|
+
expect(r.error).toBe("skill_review_admin_required");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("审一个已发布的技能 ⇒ skill_not_pending(带当前 status)", async () => {
|
|
108
|
+
const r = await call(ADMIN, "review_skill", { skill_id: SKILL, decision: "rejected" });
|
|
109
|
+
expect(r.ok).toBe(false);
|
|
110
|
+
expect(r.error).toBe("skill_not_pending");
|
|
111
|
+
expect(r.status).toBe("published");
|
|
112
|
+
// 与 skill_review_admin_required 的区别:权限没问题,是这个对象的状态不该再审。
|
|
113
|
+
expect(r.error).not.toBe("skill_review_admin_required");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("四条载荷都没有 code 字段(现状,不是契约)", async () => {
|
|
117
|
+
const replies = [
|
|
118
|
+
await call(MEMBER, "upsert_provider", {
|
|
119
|
+
name: "x", vendor: "anthropic", base_url: "https://api.anthropic.com",
|
|
120
|
+
secret_key_ref: "K", models: [],
|
|
121
|
+
}),
|
|
122
|
+
await call(MEMBER, "review_skill", { skill_id: SKILL, decision: "published" }),
|
|
123
|
+
await call(ADMIN, "review_skill", { skill_id: SKILL, decision: "published" }),
|
|
124
|
+
];
|
|
125
|
+
for (const r of replies) {
|
|
126
|
+
expect(r.ok).toBe(false);
|
|
127
|
+
expect(Object.prototype.hasOwnProperty.call(r, "code")).toBe(false);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -84,7 +84,16 @@ describe("provider 三件工具的形状", () => {
|
|
|
84
84
|
const tools = handlers();
|
|
85
85
|
// provider 的 secret 必须先在金库里 —— 这是工具自己的前置(实测第一次跑就撞上
|
|
86
86
|
// `secret_not_in_vault`,提示原话是「upsert_network_secret first」)。
|
|
87
|
-
|
|
87
|
+
// #3309 否定维度 —— 唯一哨兵值:它出现一次以上就说明有回显。
|
|
88
|
+
// 用随机后缀而不是字面量:字面量可能恰好在别处存在,会让「没回声」的断言因别的原因成立。
|
|
89
|
+
const SENTINEL = `SK-${Math.random().toString(36).slice(2)}-${Date.now()}`;
|
|
90
|
+
const secret = await call(tools.upsert_network_secret, { network_id: NET, key: SECRET_KEY, value: SENTINEL });
|
|
91
|
+
// #3275 批次 4 —— 写密钥的成功体**只回标识**(不回声任何值):
|
|
92
|
+
// 这条属性比键集本身更重要 —— 回读才回内容,写入路径永远不带值。
|
|
93
|
+
// 实测(首次写入):["key","ok"] —— 我按族推断多写了一个 `overwrote`,当场红。
|
|
94
|
+
// ⇒ 覆盖写入那条分支可能多一个字段,但**本夹具没走到,所以不声称**。
|
|
95
|
+
expect(Object.keys(secret).sort()).toEqual(["key", "ok"]);
|
|
96
|
+
expect(JSON.stringify(secret)).not.toContain(SENTINEL);
|
|
88
97
|
expect(secret.ok).toBe(true);
|
|
89
98
|
const up = await call(tools.upsert_provider, {
|
|
90
99
|
name: "shape-provider", vendor: "anthropic", base_url: "https://api.anthropic.com",
|
|
@@ -96,8 +105,14 @@ describe("provider 三件工具的形状", () => {
|
|
|
96
105
|
// 这个形状是对的:写入路径回**标识**,回读才回内容 —— 两件事分开,密钥那条线才不会被顺手带出来。
|
|
97
106
|
expect(Object.keys(up).sort()).toEqual(["model_ids", "ok", "provider_id"]);
|
|
98
107
|
expect(up.provider_id).toMatch(/^prov_/);
|
|
108
|
+
// #3309 否定维度 —— provider 的写回执同样不得携带密钥值(它只该带 secret_key_ref 这个名字)。
|
|
109
|
+
expect(JSON.stringify(up)).not.toContain(SENTINEL);
|
|
99
110
|
expect(Array.isArray(up.model_ids)).toBe(true);
|
|
100
111
|
expect(up.model_ids).toHaveLength(1);
|
|
112
|
+
|
|
113
|
+
// #3309 分支:upsert 的「no_changes」出口用同参再调一次**到不了** —— 实测返回
|
|
114
|
+
// {"ok":false,"error":…,"name":…}(重名优先于「无变化」)。要到达它需要一次以 provider_id
|
|
115
|
+
// 定位的更新,而本夹具没有那条路径 ⇒ **这里不声称覆盖**,登记在卡上。
|
|
101
116
|
expect(up.model_ids[0]).toMatch(/^pm_/);
|
|
102
117
|
});
|
|
103
118
|
|
|
@@ -231,6 +231,10 @@ describe("参与人能改的", () => {
|
|
|
231
231
|
const no = await mcp(pat.token, "requirements_update", { id, network_id: NET, name: "改名" });
|
|
232
232
|
expect(no).toMatchObject({ ok: false, error: "task_read_only", field: "name", status: 403 });
|
|
233
233
|
const tog = await mcp(pat.token, "requirements_checklist_toggle", { id, network_id: NET, item_id: "i2", done: true });
|
|
234
|
+
// #3275 批次 2 —— 勾选清单项的外层闭集。**我先按族推断写成 {checklist, ok},实测红了**:
|
|
235
|
+
// 真实形状是 {ok, requirement} —— 回带的是**整张卡**,不是清单片段。
|
|
236
|
+
// ⇒ 这条注释就是那次推断的墓碑:同族的工具**不共享**回执形状,必须各自量。
|
|
237
|
+
expect(Object.keys(tog).sort()).toEqual(["ok", "requirement"]);
|
|
234
238
|
expect(tog.ok).toBe(true);
|
|
235
239
|
});
|
|
236
240
|
|
|
@@ -63,6 +63,9 @@ describe("requirements MCP tools", () => {
|
|
|
63
63
|
// P0–P3:lowest(P3 极低)在建 / 改 / upsert 都能写;不认识的值在协议边界被拒
|
|
64
64
|
expect((await s.call("requirements_create", { name: "x", priority: "urgent" })).mcpError).toBe(true);
|
|
65
65
|
const low = await s.call("requirements_create", { name: "极低", priority: "lowest" });
|
|
66
|
+
// #3275 批次 2 —— 创建与更新的**外层**是同一个闭集 {ok, requirement}。
|
|
67
|
+
// 这两个工具是今晚我每轮都在用的写面;钉住外层之后,「顺手加一个顶层键」才会红。
|
|
68
|
+
expect(Object.keys(low).sort()).toEqual(["ok", "requirement"]);
|
|
66
69
|
expect(low.requirement.priority).toBe("lowest");
|
|
67
70
|
expect((await s.call("requirements_update", { id: low.requirement.id, priority: "high" })).requirement.priority).toBe("high");
|
|
68
71
|
expect((await s.call("requirements_update", { id: low.requirement.id, priority: "lowest" })).requirement.priority).toBe("lowest");
|
|
@@ -75,9 +78,13 @@ describe("requirements MCP tools", () => {
|
|
|
75
78
|
try {
|
|
76
79
|
const ref = "github:acme/widgets#42";
|
|
77
80
|
const first = await s.call("requirements_upsert_by_external_ref", { external_ref: ref, external_url: "https://github.com/acme/widgets/issues/42", name: "修复登录", description: "issue 正文", checklist: [{ id: "c1", text: "复现" }, { id: "c2", text: "修" }] });
|
|
81
|
+
// #3275 批次 4 —— upsert 的外层与 create/update 同族:{ok, requirement, created}
|
|
82
|
+
// `created` 是 upsert 独有的:调用方靠它区分「新建」与「命中已有」。
|
|
83
|
+
expect(Object.keys(first).sort()).toEqual(["created", "ok", "requirement"]);
|
|
78
84
|
expect(first.ok).toBe(true);
|
|
79
85
|
expect(first.created).toBe(true);
|
|
80
86
|
const tagged = await s.call("requirements_update", { id: first.requirement.id, tags: ["release"] });
|
|
87
|
+
expect(Object.keys(tagged).sort()).toEqual(["ok", "requirement"]);
|
|
81
88
|
expect(tagged.requirement.tags).toEqual(["release"]);
|
|
82
89
|
expect(first.requirement.created_by).toEqual({ kind: "node", id: "node_gh_sync" });
|
|
83
90
|
const again = await s.call("requirements_upsert_by_external_ref", { external_ref: ref, name: "修复登录(改了标题)" });
|
|
@@ -95,7 +102,16 @@ describe("requirements MCP tools", () => {
|
|
|
95
102
|
expect((await s.call("requirements_update", { id, column: "doing", agent_owner: { kind: "node", id: "node_gh_sync" } })).requirement.column).toBe("doing");
|
|
96
103
|
const ticked = await s.call("requirements_checklist_toggle", { id, item_id: "c1", done: true });
|
|
97
104
|
expect(ticked.requirement.checklist.map((i: any) => i.done)).toEqual([true, false]);
|
|
98
|
-
|
|
105
|
+
// #3275 批次 2 —— 同变量口径:`requirements_get` 的**外层**是闭集,内层 requirement 是实体投影。
|
|
106
|
+
// 今晚我每轮都靠这个工具读卡,而它的键集从来没有被钉过:
|
|
107
|
+
// 少一个 `column` 前端就分不出列;多一个字段,客户端会多一条没人写过的分支。
|
|
108
|
+
const got = await s.call("requirements_get", { id });
|
|
109
|
+
expect(Object.keys(got).sort()).toEqual(["ok", "requirement"]);
|
|
110
|
+
expect(got.requirement.agent_owner).toEqual({ kind: "node", id: "node_gh_sync" });
|
|
111
|
+
// 内层必须带这几个字段(不是全键集:实体字段会随产品增长,钉**读卡必需**的那几个)
|
|
112
|
+
for (const k of ["id", "seq", "name", "column", "tags", "updatedAt"]) {
|
|
113
|
+
expect(got.requirement).toHaveProperty(k);
|
|
114
|
+
}
|
|
99
115
|
expect((await s.call("requirements_list", { status: "doing", agent_owner: "node:node_gh_sync" })).requirements.map((r: any) => r.id)).toContain(id);
|
|
100
116
|
expect((await s.call("requirements_update", { id, owner: { kind: "node", id: "node_gh_sync" }, agent_owner: null })).error).toBe("owner_must_be_human");
|
|
101
117
|
expect((await s.call("requirements_update", { id, archived: true })).requirement.archived).toBe(true);
|
|
@@ -126,21 +126,45 @@ describe("app#225 rules file — read round trip", () => {
|
|
|
126
126
|
const n = await connect(asNode);
|
|
127
127
|
try {
|
|
128
128
|
const enq = await u.call("read_node_rules_file", { node_id: NODE_ID });
|
|
129
|
+
// #3275 批次 4 —— read 的外层三键(与 write 同形;本文件里 `enq` 被赋值 4 次,各归各的)
|
|
130
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
129
131
|
expect(enq).toMatchObject({ ok: true, op: "read" });
|
|
130
132
|
expect(enq.request_id).toMatch(/^rf_/);
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
// #3275 批次 4 —— 先接住再断言(同变量口径):外层是 pending 态的闭集。
|
|
135
|
+
const pending = await u.call("get_rules_file_result", { request_id: enq.request_id });
|
|
136
|
+
// #3275 批次 4 —— 实测 9 键(我按族推断的 7 键少了 node_id 与 age_ms,当场红)。
|
|
137
|
+
// `age_ms` 尤其不能少:pending 唯一的「还要等多久」信号;没有它,客户端只能盲轮询。
|
|
138
|
+
expect(Object.keys(pending).sort()).toEqual([
|
|
139
|
+
"age_ms", "error", "exists", "file_name", "node_id", "ok", "op", "request_id", "status",
|
|
140
|
+
]);
|
|
141
|
+
expect(pending).toMatchObject({ ok: true, status: "pending", op: "read" });
|
|
142
|
+
// read_node_rules_file 的外层(enq):
|
|
143
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
133
144
|
|
|
134
145
|
const pulled = await n.call("get_rules_file_request", {});
|
|
146
|
+
// #3309 分支 —— 有请求态的外层闭集 {ok, request}(与空态同形,但 request 非 null);
|
|
147
|
+
// 空态已在上一条钉过 ⇒ 两个出口各自有断言,而不是「一个断言代表两态」。
|
|
148
|
+
expect(Object.keys(pulled).sort()).toEqual(["ok", "request"]);
|
|
135
149
|
expect(pulled.ok).toBe(true);
|
|
136
150
|
expect(Object.keys(pulled.request).sort()).toEqual(["op", "request_id"]);
|
|
137
151
|
expect(pulled.request).toEqual({ request_id: enq.request_id, op: "read" });
|
|
138
152
|
// 第二次拉:已经 in_progress,不再重复下发
|
|
139
153
|
expect(await n.call("get_rules_file_request", {})).toEqual({ ok: true, request: null });
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
// #3275 批次 1 —— 同变量口径:这条断言必须测**这次调用的返回值**,而不是写在旁边的另一个值。
|
|
156
|
+
// 成功回执是闭集:{ok, request_id, status}。多一个键(例如 hint)客户端就会多一个没人知道的分支。
|
|
157
|
+
const acked = await n.call("ack_rules_file_request", {
|
|
142
158
|
request_id: enq.request_id, status: "done", file_name: "CLAUDE.md", exists: true, content: "# 规则\n",
|
|
143
|
-
})
|
|
159
|
+
});
|
|
160
|
+
expect(Object.keys(acked).sort()).toEqual(["ok", "request_id", "status"]);
|
|
161
|
+
// #3275 批次 1·b —— 重复 ack 走 already_terminal:**形状不一样**(多一个 current_status)。
|
|
162
|
+
const twice = await n.call("ack_rules_file_request", {
|
|
163
|
+
request_id: enq.request_id, status: "done", file_name: "CLAUDE.md", exists: true,
|
|
164
|
+
});
|
|
165
|
+
expect(Object.keys(twice).sort()).toEqual(["current_status", "ignored", "ok"]);
|
|
166
|
+
expect(twice).toMatchObject({ ok: true, ignored: "already_terminal" });
|
|
167
|
+
expect(acked).toMatchObject({ ok: true, status: "done", request_id: enq.request_id });
|
|
144
168
|
|
|
145
169
|
const res = await u.call("get_rules_file_result", { request_id: enq.request_id });
|
|
146
170
|
expect(res).toMatchObject({ ok: true, status: "done", op: "read", file_name: "CLAUDE.md", exists: true, content: "# 规则\n", error: null });
|
|
@@ -153,8 +177,13 @@ describe("app#225 rules file — read round trip", () => {
|
|
|
153
177
|
try {
|
|
154
178
|
const body = "# new rules\n\n- 不碰生产 DB\n";
|
|
155
179
|
const enq = await u.call("write_node_rules_file", { node_id: NODE_ID, content: body });
|
|
180
|
+
// #3275 批次 4 —— write 的外层与 read 同形(三键),但**必须各自钉**:
|
|
181
|
+
// 这个文件里 `enq` 被赋值 4 次,一条断言只属于它所在的那一次。
|
|
182
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
156
183
|
expect(enq).toMatchObject({ ok: true, op: "write" });
|
|
157
184
|
const pulled = await n.call("get_rules_file_request", {});
|
|
185
|
+
// get_rules_file_request 的空态:`request: null`(两态,闭集两键)
|
|
186
|
+
expect(Object.keys(pulled).sort()).toEqual(["ok", "request"]);
|
|
158
187
|
expect(pulled.request).toEqual({ request_id: enq.request_id, op: "write", content: body });
|
|
159
188
|
await n.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", file_name: "CLAUDE.md", exists: true });
|
|
160
189
|
const res = await u.call("get_rules_file_result", { request_id: enq.request_id });
|
|
@@ -190,7 +219,12 @@ describe("app#225 rules file — SEC-1 and lifecycle", () => {
|
|
|
190
219
|
try {
|
|
191
220
|
const enq = await u.call("read_node_rules_file", { node_id: NODE_ID });
|
|
192
221
|
expect(await o.call("get_rules_file_request", {})).toEqual({ ok: true, request: null });
|
|
193
|
-
|
|
222
|
+
// #3275 批次 1·b —— 别的节点 ack 别人的请求:**忽略也是契约**。
|
|
223
|
+
// 形状是 {ok, ignored} 两键(不带 request_id/status —— 那是主分支的形状),
|
|
224
|
+
// 只写 toMatchObject 时,多塞一个 current_status 不会有任何东西变红。
|
|
225
|
+
const foreignAck = await o.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "stolen" });
|
|
226
|
+
expect(Object.keys(foreignAck).sort()).toEqual(["ignored", "ok"]);
|
|
227
|
+
expect(foreignAck).toEqual({ ok: true, ignored: "unknown_or_foreign_request" });
|
|
194
228
|
expect(db.get<{ status: string }>("SELECT status FROM node_rules_requests WHERE request_id = ?1", enq.request_id)?.status).toBe("pending");
|
|
195
229
|
} finally { await u.close(); await o.close(); }
|
|
196
230
|
}, 20_000);
|
|
@@ -135,7 +135,10 @@ describe("happy path from a node", () => {
|
|
|
135
135
|
"scheduled_for", "status", "task_id", "work_outcome", "work_outcome_node_id"]);
|
|
136
136
|
expect(runs.runs.map((x: any) => x.task_id)).toContain(r.taskId);
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
// #3275 批次 2 —— 先接住再断言(同变量口径);值本来就是闭集,缺的只是「它是一条断言的对象」。
|
|
139
|
+
const cancelled = await mcp(node.a.token, "schedule_cancel", { schedule_id: s.schedule_id });
|
|
140
|
+
expect(Object.keys(cancelled).sort()).toEqual(["ok", "status"]);
|
|
141
|
+
expect(cancelled).toEqual({ ok: true, status: "cancelled" });
|
|
139
142
|
expect((await mcp(node.a.token, "schedule_get", { schedule_id: s.schedule_id })).schedule.status).toBe("cancelled");
|
|
140
143
|
expect((await mcp(node.a.token, "schedule_run_now", { schedule_id: s.schedule_id })).error).toBe("schedule_cancelled");
|
|
141
144
|
});
|
|
@@ -160,6 +163,8 @@ describe("happy path from a node", () => {
|
|
|
160
163
|
|
|
161
164
|
test("a schedule for another node the caller can send_task to; the target can read it but not change it", async () => {
|
|
162
165
|
const c = await create("a", { target_node_id: node.b.id });
|
|
166
|
+
// 与外层同族但**各自钉**:同族不共享形状这件事今晚已经被 checklist_toggle 打过一次脸。
|
|
167
|
+
expect(Object.keys(c).sort()).toEqual(["ok", "schedule"]);
|
|
163
168
|
expect(c.ok).toBe(true);
|
|
164
169
|
const id = c.schedule.schedule_id;
|
|
165
170
|
expect((await mcp(node.b.token, "schedule_list")).schedules.map((x: any) => x.schedule_id)).toContain(id);
|
|
@@ -180,6 +185,8 @@ describe("happy path from a node", () => {
|
|
|
180
185
|
expect(r.status).toBe(201);
|
|
181
186
|
const id = r.body.schedule.schedule_id;
|
|
182
187
|
const got = await mcp(node.a.token, "schedule_get", { schedule_id: id });
|
|
188
|
+
// #3275 批次 2 —— schedule_get / schedule_create 的外层都是 {ok, schedule}(实测)。
|
|
189
|
+
expect(Object.keys(got).sort()).toEqual(["ok", "schedule"]);
|
|
183
190
|
expect(got.schedule.created_by_node_id).toBeNull();
|
|
184
191
|
expect((await mcp(node.a.token, "schedule_runs", { schedule_id: id })).ok).toBe(true);
|
|
185
192
|
expect((await mcp(node.a.token, "schedule_list")).schedules.map((x: any) => x.schedule_id)).toContain(id);
|
|
@@ -442,6 +449,10 @@ describe("#2935 排程周期诊断", () => {
|
|
|
442
449
|
name: `diag-${stamp}`, task: "t", target_node_id: node.a.id,
|
|
443
450
|
schedule: { type: "interval", every_seconds: 180 }, timezone: "Asia/Shanghai",
|
|
444
451
|
});
|
|
452
|
+
// #3275 批次 4 —— 上面那些 `create("a")` 断言其实**已经**钉住 schedule_create,
|
|
453
|
+
// 但调用在 helper 里、工具名不在同一行 ⇒ 统计口径归因不到。
|
|
454
|
+
// ⇒ 这里补一条**字面量直调**的:形状同外层,代价一次调用。
|
|
455
|
+
expect(Object.keys(c).sort()).toEqual(["ok", "schedule"]);
|
|
445
456
|
expect(c.ok).toBe(true);
|
|
446
457
|
const id = c.schedule.schedule_id;
|
|
447
458
|
// 造 3 条「一轮跑了 600 秒」的已完成 run(中位数 600s > 周期 180s)。
|