@khanglvm/outline-cli 0.1.4 → 0.1.6
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/CHANGELOG.md +10 -0
- package/README.md +2 -3
- package/package.json +7 -1
- package/src/entry-integrity-manifest.generated.js +1 -1
- package/.env.test.example +0 -2
- package/AGENTS.md +0 -107
- package/docs/TOOL_CONTRACTS.md +0 -8
- package/scripts/generate-entry-integrity.mjs +0 -123
- package/scripts/release.mjs +0 -353
- package/test/action-gate.unit.test.js +0 -157
- package/test/agent-skills.unit.test.js +0 -144
- package/test/config-store.unit.test.js +0 -121
- package/test/hardening.unit.test.js +0 -3803
- package/test/live.integration.test.js +0 -5136
- package/test/profile-selection.unit.test.js +0 -289
- package/test/security.unit.test.js +0 -113
- package/test/tool-resolution.unit.test.js +0 -333
- package/test/version.unit.test.js +0 -21
|
@@ -1,3803 +0,0 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
|
|
7
|
-
import { CliError } from "../src/errors.js";
|
|
8
|
-
import { ResultStore } from "../src/result-store.js";
|
|
9
|
-
import { TOOL_ARG_SCHEMAS, validateToolArgs } from "../src/tool-arg-schemas.js";
|
|
10
|
-
import { EXTENDED_TOOLS } from "../src/tools.extended.js";
|
|
11
|
-
import { MUTATION_TOOLS } from "../src/tools.mutation.js";
|
|
12
|
-
import { NAVIGATION_TOOLS } from "../src/tools.navigation.js";
|
|
13
|
-
|
|
14
|
-
test("validateToolArgs rejects unknown args by default", () => {
|
|
15
|
-
assert.throws(
|
|
16
|
-
() => validateToolArgs("auth.info", { view: "summary", unexpected: true }),
|
|
17
|
-
(err) => {
|
|
18
|
-
assert.ok(err instanceof CliError);
|
|
19
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
20
|
-
assert.ok(Array.isArray(err.details?.issues));
|
|
21
|
-
assert.ok(err.details.issues.some((issue) => issue.path === "args.unexpected"));
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("validateToolArgs exposes accepted args and closest suggestions", () => {
|
|
28
|
-
assert.throws(
|
|
29
|
-
() => validateToolArgs("auth.info", { vew: "summary", unexpected: true }),
|
|
30
|
-
(err) => {
|
|
31
|
-
assert.ok(err instanceof CliError);
|
|
32
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
33
|
-
assert.deepEqual(err.details?.requiredArgs, []);
|
|
34
|
-
assert.ok(Array.isArray(err.details?.acceptedArgs));
|
|
35
|
-
assert.ok(err.details.acceptedArgs.includes("view"));
|
|
36
|
-
assert.ok(err.details.acceptedArgs.includes("compact"));
|
|
37
|
-
assert.deepEqual(err.details?.unknownArgs, ["vew", "unexpected"]);
|
|
38
|
-
const typoIssue = err.details?.issues?.find((issue) => issue.path === "args.vew");
|
|
39
|
-
assert.deepEqual(typoIssue?.suggestions, ["view"]);
|
|
40
|
-
assert.equal(err.details?.suggestedArgs, undefined);
|
|
41
|
-
assert.match(err.details?.validationHint || "", /Accepted args:/);
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("validateToolArgs supports allowUnknown opt-out", () => {
|
|
48
|
-
const toolName = "__test.allow_unknown";
|
|
49
|
-
TOOL_ARG_SCHEMAS[toolName] = {
|
|
50
|
-
allowUnknown: true,
|
|
51
|
-
properties: {
|
|
52
|
-
known: { type: "string" },
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
assert.doesNotThrow(() => {
|
|
58
|
-
validateToolArgs(toolName, {
|
|
59
|
-
known: "ok",
|
|
60
|
-
extra: true,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
} finally {
|
|
64
|
-
delete TOOL_ARG_SCHEMAS[toolName];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("api.call accepts method or endpoint and rejects when both missing", () => {
|
|
69
|
-
assert.doesNotThrow(() => {
|
|
70
|
-
validateToolArgs("api.call", { method: "documents.info" });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
assert.doesNotThrow(() => {
|
|
74
|
-
validateToolArgs("api.call", { endpoint: "documents.info" });
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
assert.throws(
|
|
78
|
-
() => validateToolArgs("api.call", { body: {} }),
|
|
79
|
-
(err) => {
|
|
80
|
-
assert.ok(err instanceof CliError);
|
|
81
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
82
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.method"));
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("groups.memberships is exposed as a first-class extended wrapper", async () => {
|
|
89
|
-
const contract = EXTENDED_TOOLS["groups.memberships"];
|
|
90
|
-
assert.ok(contract);
|
|
91
|
-
assert.equal(typeof contract.handler, "function");
|
|
92
|
-
assert.equal(contract.usageExample?.tool, "groups.memberships");
|
|
93
|
-
|
|
94
|
-
const calls = [];
|
|
95
|
-
const ctx = {
|
|
96
|
-
profile: { id: "profile-hardening" },
|
|
97
|
-
client: {
|
|
98
|
-
async call(method, body, options) {
|
|
99
|
-
calls.push({ method, body, options });
|
|
100
|
-
return {
|
|
101
|
-
body: {
|
|
102
|
-
data: [{ id: "membership-1", userId: "user-1" }],
|
|
103
|
-
policies: [{ id: "policy-1" }],
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const output = await contract.handler(ctx, {
|
|
111
|
-
id: "group-1",
|
|
112
|
-
limit: 10,
|
|
113
|
-
offset: 0,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
assert.equal(calls.length, 1);
|
|
117
|
-
assert.equal(calls[0].method, "groups.memberships");
|
|
118
|
-
assert.deepEqual(calls[0].body, {
|
|
119
|
-
id: "group-1",
|
|
120
|
-
limit: 10,
|
|
121
|
-
offset: 0,
|
|
122
|
-
});
|
|
123
|
-
assert.equal(calls[0].options?.maxAttempts, 2);
|
|
124
|
-
|
|
125
|
-
assert.equal(output.tool, "groups.memberships");
|
|
126
|
-
assert.equal(output.profile, "profile-hardening");
|
|
127
|
-
assert.deepEqual(output.result, {
|
|
128
|
-
data: [{ id: "membership-1", userId: "user-1" }],
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test("users lifecycle wrappers and documents.users wrapper enforce gating and deterministic envelopes", async () => {
|
|
133
|
-
for (const method of [
|
|
134
|
-
"users.invite",
|
|
135
|
-
"users.update_role",
|
|
136
|
-
"users.activate",
|
|
137
|
-
"users.suspend",
|
|
138
|
-
"documents.users",
|
|
139
|
-
]) {
|
|
140
|
-
assert.ok(EXTENDED_TOOLS[method], `${method} should be registered`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const calls = [];
|
|
144
|
-
const ctx = {
|
|
145
|
-
profile: { id: "profile-hardening" },
|
|
146
|
-
client: {
|
|
147
|
-
async call(method, body, options) {
|
|
148
|
-
calls.push({ method, body, options });
|
|
149
|
-
if (method === "documents.users") {
|
|
150
|
-
return {
|
|
151
|
-
body: {
|
|
152
|
-
data: [{ id: "user-1", documentId: body.id }],
|
|
153
|
-
policies: [{ id: "policy-1" }],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
body: {
|
|
159
|
-
data: { id: `user-op-${calls.length}` },
|
|
160
|
-
policies: [{ id: "policy-1" }],
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const usersRes = await EXTENDED_TOOLS["documents.users"].handler(ctx, {
|
|
168
|
-
id: "doc-1",
|
|
169
|
-
limit: 10,
|
|
170
|
-
offset: 0,
|
|
171
|
-
});
|
|
172
|
-
const inviteRes = await EXTENDED_TOOLS["users.invite"].handler(ctx, {
|
|
173
|
-
email: "new.user@example.com",
|
|
174
|
-
role: "member",
|
|
175
|
-
performAction: true,
|
|
176
|
-
});
|
|
177
|
-
const updateRoleRes = await EXTENDED_TOOLS["users.update_role"].handler(ctx, {
|
|
178
|
-
id: "user-1",
|
|
179
|
-
role: "viewer",
|
|
180
|
-
performAction: true,
|
|
181
|
-
});
|
|
182
|
-
await EXTENDED_TOOLS["users.activate"].handler(ctx, {
|
|
183
|
-
id: "user-1",
|
|
184
|
-
performAction: true,
|
|
185
|
-
});
|
|
186
|
-
const suspendRes = await EXTENDED_TOOLS["users.suspend"].handler(ctx, {
|
|
187
|
-
id: "user-2",
|
|
188
|
-
performAction: true,
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
assert.deepEqual(
|
|
192
|
-
calls.map((call) => call.method),
|
|
193
|
-
["documents.users", "users.invite", "users.update_role", "users.activate", "users.suspend"]
|
|
194
|
-
);
|
|
195
|
-
assert.deepEqual(calls[0].body, { id: "doc-1", limit: 10, offset: 0 });
|
|
196
|
-
assert.deepEqual(calls[1].body, { email: "new.user@example.com", role: "member" });
|
|
197
|
-
assert.deepEqual(calls[2].body, { id: "user-1", role: "viewer" });
|
|
198
|
-
assert.deepEqual(calls[3].body, { id: "user-1" });
|
|
199
|
-
assert.deepEqual(calls[4].body, { id: "user-2" });
|
|
200
|
-
assert.equal(calls[0].options?.maxAttempts, 2);
|
|
201
|
-
assert.equal(calls[1].options?.maxAttempts, 1);
|
|
202
|
-
assert.equal(calls[4].options?.maxAttempts, 1);
|
|
203
|
-
|
|
204
|
-
assert.equal(usersRes.tool, "documents.users");
|
|
205
|
-
assert.deepEqual(usersRes.result, { data: [{ id: "user-1", documentId: "doc-1" }] });
|
|
206
|
-
assert.deepEqual(inviteRes.result, { data: { id: "user-op-2" } });
|
|
207
|
-
assert.deepEqual(updateRoleRes.result, { data: { id: "user-op-3" } });
|
|
208
|
-
assert.deepEqual(suspendRes.result, { data: { id: "user-op-5" } });
|
|
209
|
-
|
|
210
|
-
await assert.rejects(
|
|
211
|
-
() =>
|
|
212
|
-
EXTENDED_TOOLS["users.suspend"].handler(ctx, {
|
|
213
|
-
id: "user-3",
|
|
214
|
-
}),
|
|
215
|
-
(err) => {
|
|
216
|
-
assert.ok(err instanceof CliError);
|
|
217
|
-
assert.match(err.message, /performAction/);
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
);
|
|
221
|
-
assert.equal(calls.length, 5);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("documents.permanent_delete wrapper maps endpoint and enforces action gating", async () => {
|
|
225
|
-
const contract = EXTENDED_TOOLS["documents.permanent_delete"];
|
|
226
|
-
assert.ok(contract);
|
|
227
|
-
assert.equal(typeof contract.handler, "function");
|
|
228
|
-
assert.equal(contract.usageExample?.tool, "documents.permanent_delete");
|
|
229
|
-
|
|
230
|
-
const calls = [];
|
|
231
|
-
const ctx = {
|
|
232
|
-
profile: { id: "profile-hardening" },
|
|
233
|
-
client: {
|
|
234
|
-
async call(method, body, options) {
|
|
235
|
-
calls.push({ method, body, options });
|
|
236
|
-
return {
|
|
237
|
-
body: {
|
|
238
|
-
success: true,
|
|
239
|
-
id: body.id,
|
|
240
|
-
policies: [{ id: "policy-1" }],
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const deleteRes = await contract.handler(ctx, {
|
|
248
|
-
id: "doc-deleted-1",
|
|
249
|
-
performAction: true,
|
|
250
|
-
});
|
|
251
|
-
const deleteResWithPolicies = await contract.handler(ctx, {
|
|
252
|
-
id: "doc-deleted-2",
|
|
253
|
-
includePolicies: true,
|
|
254
|
-
maxAttempts: 4,
|
|
255
|
-
performAction: true,
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
assert.deepEqual(calls, [
|
|
259
|
-
{
|
|
260
|
-
method: "documents.permanent_delete",
|
|
261
|
-
body: { id: "doc-deleted-1" },
|
|
262
|
-
options: { maxAttempts: 1 },
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
method: "documents.permanent_delete",
|
|
266
|
-
body: { id: "doc-deleted-2" },
|
|
267
|
-
options: { maxAttempts: 4 },
|
|
268
|
-
},
|
|
269
|
-
]);
|
|
270
|
-
assert.equal(deleteRes.tool, "documents.permanent_delete");
|
|
271
|
-
assert.equal(deleteRes.profile, "profile-hardening");
|
|
272
|
-
assert.deepEqual(deleteRes.result, {
|
|
273
|
-
success: true,
|
|
274
|
-
id: "doc-deleted-1",
|
|
275
|
-
});
|
|
276
|
-
assert.deepEqual(deleteResWithPolicies.result, {
|
|
277
|
-
success: true,
|
|
278
|
-
id: "doc-deleted-2",
|
|
279
|
-
policies: [{ id: "policy-1" }],
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
await assert.rejects(
|
|
283
|
-
() =>
|
|
284
|
-
contract.handler(ctx, {
|
|
285
|
-
id: "doc-deleted-3",
|
|
286
|
-
}),
|
|
287
|
-
(err) => {
|
|
288
|
-
assert.ok(err instanceof CliError);
|
|
289
|
-
assert.match(err.message, /performAction/);
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
assert.equal(calls.length, 2);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
test("data_attributes wrappers map to dataAttributes RPC methods with action gating", async () => {
|
|
297
|
-
const methods = [
|
|
298
|
-
"data_attributes.list",
|
|
299
|
-
"data_attributes.info",
|
|
300
|
-
"data_attributes.create",
|
|
301
|
-
"data_attributes.update",
|
|
302
|
-
"data_attributes.delete",
|
|
303
|
-
];
|
|
304
|
-
for (const method of methods) {
|
|
305
|
-
assert.ok(EXTENDED_TOOLS[method], `${method} should be registered`);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const calls = [];
|
|
309
|
-
const ctx = {
|
|
310
|
-
profile: { id: "profile-hardening" },
|
|
311
|
-
client: {
|
|
312
|
-
async call(method, body, options) {
|
|
313
|
-
calls.push({ method, body, options });
|
|
314
|
-
if (method === "dataAttributes.delete") {
|
|
315
|
-
return { body: { success: true } };
|
|
316
|
-
}
|
|
317
|
-
return {
|
|
318
|
-
body: {
|
|
319
|
-
data: { id: "attr-1", name: "Status" },
|
|
320
|
-
policies: [{ id: "policy-1" }],
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
const listRes = await EXTENDED_TOOLS["data_attributes.list"].handler(ctx, {
|
|
328
|
-
limit: 10,
|
|
329
|
-
offset: 0,
|
|
330
|
-
});
|
|
331
|
-
const infoRes = await EXTENDED_TOOLS["data_attributes.info"].handler(ctx, { id: "attr-1" });
|
|
332
|
-
await EXTENDED_TOOLS["data_attributes.create"].handler(ctx, {
|
|
333
|
-
name: "Status",
|
|
334
|
-
dataType: "string",
|
|
335
|
-
performAction: true,
|
|
336
|
-
});
|
|
337
|
-
await EXTENDED_TOOLS["data_attributes.update"].handler(ctx, {
|
|
338
|
-
id: "attr-1",
|
|
339
|
-
name: "Status",
|
|
340
|
-
performAction: true,
|
|
341
|
-
});
|
|
342
|
-
const deleteRes = await EXTENDED_TOOLS["data_attributes.delete"].handler(ctx, {
|
|
343
|
-
id: "attr-1",
|
|
344
|
-
performAction: true,
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
assert.deepEqual(
|
|
348
|
-
calls.map((call) => call.method),
|
|
349
|
-
[
|
|
350
|
-
"dataAttributes.list",
|
|
351
|
-
"dataAttributes.info",
|
|
352
|
-
"dataAttributes.create",
|
|
353
|
-
"dataAttributes.update",
|
|
354
|
-
"dataAttributes.delete",
|
|
355
|
-
]
|
|
356
|
-
);
|
|
357
|
-
assert.equal(calls[0].options?.maxAttempts, 2);
|
|
358
|
-
assert.equal(calls[2].options?.maxAttempts, 1);
|
|
359
|
-
assert.equal(calls[4].options?.maxAttempts, 1);
|
|
360
|
-
assert.equal(listRes.tool, "data_attributes.list");
|
|
361
|
-
assert.equal(infoRes.tool, "data_attributes.info");
|
|
362
|
-
assert.deepEqual(listRes.result, {
|
|
363
|
-
data: { id: "attr-1", name: "Status" },
|
|
364
|
-
});
|
|
365
|
-
assert.deepEqual(deleteRes.result, { success: true });
|
|
366
|
-
|
|
367
|
-
await assert.rejects(
|
|
368
|
-
() =>
|
|
369
|
-
EXTENDED_TOOLS["data_attributes.create"].handler(ctx, {
|
|
370
|
-
name: "Status",
|
|
371
|
-
dataType: "string",
|
|
372
|
-
}),
|
|
373
|
-
(err) => {
|
|
374
|
-
assert.ok(err instanceof CliError);
|
|
375
|
-
assert.match(err.message, /performAction/);
|
|
376
|
-
return true;
|
|
377
|
-
}
|
|
378
|
-
);
|
|
379
|
-
assert.equal(calls.length, 5);
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
test("oauth wrappers expose canonical and alias methods with deterministic envelopes", async () => {
|
|
383
|
-
for (const method of [
|
|
384
|
-
"oauth_clients.list",
|
|
385
|
-
"oauth_clients.info",
|
|
386
|
-
"oauth_clients.create",
|
|
387
|
-
"oauth_clients.update",
|
|
388
|
-
"oauth_clients.rotate_secret",
|
|
389
|
-
"oauth_clients.delete",
|
|
390
|
-
"oauth_authentications.list",
|
|
391
|
-
"oauth_authentications.delete",
|
|
392
|
-
"oauthClients.delete",
|
|
393
|
-
"oauthAuthentications.delete",
|
|
394
|
-
]) {
|
|
395
|
-
assert.ok(EXTENDED_TOOLS[method], `${method} should be registered`);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
const calls = [];
|
|
399
|
-
const ctx = {
|
|
400
|
-
profile: { id: "profile-hardening" },
|
|
401
|
-
client: {
|
|
402
|
-
async call(method, body, options) {
|
|
403
|
-
calls.push({ method, body, options });
|
|
404
|
-
if (method === "oauthClients.list") {
|
|
405
|
-
return {
|
|
406
|
-
body: {
|
|
407
|
-
data: [{ id: "oauth-client-1", name: "CLI App" }],
|
|
408
|
-
policies: [{ id: "policy-1" }],
|
|
409
|
-
},
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
if (method === "oauthClients.info") {
|
|
413
|
-
return {
|
|
414
|
-
body: {
|
|
415
|
-
data: { id: body.id ?? "oauth-client-1", name: "CLI App" },
|
|
416
|
-
policies: [{ id: "policy-1" }],
|
|
417
|
-
},
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
if (method === "oauthAuthentications.list") {
|
|
421
|
-
return {
|
|
422
|
-
body: {
|
|
423
|
-
data: [{ oauthClientId: "oauth-client-1", scope: ["read"] }],
|
|
424
|
-
policies: [{ id: "policy-1" }],
|
|
425
|
-
},
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
if (method === "oauthAuthentications.delete") {
|
|
429
|
-
return {
|
|
430
|
-
body: {
|
|
431
|
-
success: true,
|
|
432
|
-
oauthClientId: body.oauthClientId,
|
|
433
|
-
policies: [{ id: "policy-1" }],
|
|
434
|
-
},
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
if (method === "oauthClients.delete") {
|
|
438
|
-
return {
|
|
439
|
-
body: {
|
|
440
|
-
success: true,
|
|
441
|
-
id: body.id,
|
|
442
|
-
policies: [{ id: "policy-1" }],
|
|
443
|
-
},
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
body: {
|
|
448
|
-
data: { id: body.id ?? "oauth-client-1", name: body.name ?? "CLI App" },
|
|
449
|
-
policies: [{ id: "policy-1" }],
|
|
450
|
-
},
|
|
451
|
-
};
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
const listRes = await EXTENDED_TOOLS["oauth_clients.list"].handler(ctx, { limit: 10, offset: 0 });
|
|
457
|
-
const infoRes = await EXTENDED_TOOLS["oauth_clients.info"].handler(ctx, { id: "oauth-client-1" });
|
|
458
|
-
const createRes = await EXTENDED_TOOLS["oauth_clients.create"].handler(ctx, {
|
|
459
|
-
name: "CLI App",
|
|
460
|
-
redirectUris: ["https://example.com/callback"],
|
|
461
|
-
published: true,
|
|
462
|
-
performAction: true,
|
|
463
|
-
});
|
|
464
|
-
await EXTENDED_TOOLS["oauth_clients.update"].handler(ctx, {
|
|
465
|
-
id: "oauth-client-1",
|
|
466
|
-
name: "CLI App v2",
|
|
467
|
-
performAction: true,
|
|
468
|
-
});
|
|
469
|
-
const rotateRes = await EXTENDED_TOOLS["oauth_clients.rotate_secret"].handler(ctx, {
|
|
470
|
-
id: "oauth-client-1",
|
|
471
|
-
performAction: true,
|
|
472
|
-
});
|
|
473
|
-
const deleteRes = await EXTENDED_TOOLS["oauth_clients.delete"].handler(ctx, {
|
|
474
|
-
id: "oauth-client-1",
|
|
475
|
-
performAction: true,
|
|
476
|
-
});
|
|
477
|
-
const authListRes = await EXTENDED_TOOLS["oauth_authentications.list"].handler(ctx, {
|
|
478
|
-
limit: 5,
|
|
479
|
-
offset: 0,
|
|
480
|
-
});
|
|
481
|
-
const authDeleteRes = await EXTENDED_TOOLS["oauth_authentications.delete"].handler(ctx, {
|
|
482
|
-
oauthClientId: "oauth-client-1",
|
|
483
|
-
scope: ["read"],
|
|
484
|
-
performAction: true,
|
|
485
|
-
});
|
|
486
|
-
const aliasClientDeleteRes = await EXTENDED_TOOLS["oauthClients.delete"].handler(ctx, {
|
|
487
|
-
id: "oauth-client-2",
|
|
488
|
-
performAction: true,
|
|
489
|
-
});
|
|
490
|
-
const aliasAuthDeleteRes = await EXTENDED_TOOLS["oauthAuthentications.delete"].handler(ctx, {
|
|
491
|
-
oauthClientId: "oauth-client-2",
|
|
492
|
-
scope: ["write"],
|
|
493
|
-
performAction: true,
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
assert.deepEqual(
|
|
497
|
-
calls.map((call) => call.method),
|
|
498
|
-
[
|
|
499
|
-
"oauthClients.list",
|
|
500
|
-
"oauthClients.info",
|
|
501
|
-
"oauthClients.create",
|
|
502
|
-
"oauthClients.update",
|
|
503
|
-
"oauthClients.rotate_secret",
|
|
504
|
-
"oauthClients.delete",
|
|
505
|
-
"oauthAuthentications.list",
|
|
506
|
-
"oauthAuthentications.delete",
|
|
507
|
-
"oauthClients.delete",
|
|
508
|
-
"oauthAuthentications.delete",
|
|
509
|
-
]
|
|
510
|
-
);
|
|
511
|
-
assert.deepEqual(calls[0].body, { limit: 10, offset: 0 });
|
|
512
|
-
assert.deepEqual(calls[2].body, {
|
|
513
|
-
name: "CLI App",
|
|
514
|
-
redirectUris: ["https://example.com/callback"],
|
|
515
|
-
published: true,
|
|
516
|
-
});
|
|
517
|
-
assert.deepEqual(calls[4].body, { id: "oauth-client-1" });
|
|
518
|
-
assert.deepEqual(calls[7].body, {
|
|
519
|
-
oauthClientId: "oauth-client-1",
|
|
520
|
-
scope: ["read"],
|
|
521
|
-
});
|
|
522
|
-
assert.equal(calls[0].options?.maxAttempts, 2);
|
|
523
|
-
assert.equal(calls[1].options?.maxAttempts, 2);
|
|
524
|
-
assert.equal(calls[2].options?.maxAttempts, 1);
|
|
525
|
-
assert.equal(calls[6].options?.maxAttempts, 2);
|
|
526
|
-
assert.equal(calls[7].options?.maxAttempts, 1);
|
|
527
|
-
assert.equal(calls[8].options?.maxAttempts, 1);
|
|
528
|
-
|
|
529
|
-
assert.equal(listRes.tool, "oauth_clients.list");
|
|
530
|
-
assert.equal(infoRes.tool, "oauth_clients.info");
|
|
531
|
-
assert.equal(createRes.tool, "oauth_clients.create");
|
|
532
|
-
assert.equal(rotateRes.tool, "oauth_clients.rotate_secret");
|
|
533
|
-
assert.equal(authListRes.tool, "oauth_authentications.list");
|
|
534
|
-
assert.equal(authDeleteRes.tool, "oauth_authentications.delete");
|
|
535
|
-
assert.equal(aliasClientDeleteRes.tool, "oauthClients.delete");
|
|
536
|
-
assert.equal(aliasAuthDeleteRes.tool, "oauthAuthentications.delete");
|
|
537
|
-
assert.deepEqual(listRes.result, { data: [{ id: "oauth-client-1", name: "CLI App" }] });
|
|
538
|
-
assert.deepEqual(deleteRes.result, { success: true, id: "oauth-client-1" });
|
|
539
|
-
assert.deepEqual(authListRes.result, {
|
|
540
|
-
data: [{ oauthClientId: "oauth-client-1", scope: ["read"] }],
|
|
541
|
-
});
|
|
542
|
-
assert.deepEqual(authDeleteRes.result, {
|
|
543
|
-
success: true,
|
|
544
|
-
oauthClientId: "oauth-client-1",
|
|
545
|
-
});
|
|
546
|
-
assert.deepEqual(aliasClientDeleteRes.result, {
|
|
547
|
-
success: true,
|
|
548
|
-
id: "oauth-client-2",
|
|
549
|
-
});
|
|
550
|
-
assert.deepEqual(aliasAuthDeleteRes.result, {
|
|
551
|
-
success: true,
|
|
552
|
-
oauthClientId: "oauth-client-2",
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
await assert.rejects(
|
|
556
|
-
() =>
|
|
557
|
-
EXTENDED_TOOLS["oauth_clients.create"].handler(ctx, {
|
|
558
|
-
name: "CLI App",
|
|
559
|
-
redirectUris: ["https://example.com/callback"],
|
|
560
|
-
}),
|
|
561
|
-
(err) => {
|
|
562
|
-
assert.ok(err instanceof CliError);
|
|
563
|
-
assert.match(err.message, /performAction/);
|
|
564
|
-
return true;
|
|
565
|
-
}
|
|
566
|
-
);
|
|
567
|
-
await assert.rejects(
|
|
568
|
-
() =>
|
|
569
|
-
EXTENDED_TOOLS["oauthAuthentications.delete"].handler(ctx, {
|
|
570
|
-
oauthClientId: "oauth-client-3",
|
|
571
|
-
}),
|
|
572
|
-
(err) => {
|
|
573
|
-
assert.ok(err instanceof CliError);
|
|
574
|
-
assert.match(err.message, /performAction/);
|
|
575
|
-
return true;
|
|
576
|
-
}
|
|
577
|
-
);
|
|
578
|
-
assert.equal(calls.length, 10);
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
test("import and file operation wrappers expose deterministic envelopes and action gating", async () => {
|
|
582
|
-
for (const method of [
|
|
583
|
-
"documents.import",
|
|
584
|
-
"documents.import_file",
|
|
585
|
-
"file_operations.list",
|
|
586
|
-
"file_operations.info",
|
|
587
|
-
"file_operations.delete",
|
|
588
|
-
]) {
|
|
589
|
-
assert.ok(EXTENDED_TOOLS[method], `${method} should be registered`);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "outline-cli-import-wrapper-"));
|
|
593
|
-
const filePath = path.join(tmpDir, "legacy-wiki.md");
|
|
594
|
-
await fs.writeFile(filePath, "# Legacy Wiki\n\nImported content.\n", "utf8");
|
|
595
|
-
|
|
596
|
-
const calls = [];
|
|
597
|
-
const ctx = {
|
|
598
|
-
profile: { id: "profile-hardening" },
|
|
599
|
-
client: {
|
|
600
|
-
async call(method, body, options) {
|
|
601
|
-
calls.push({ method, body, options });
|
|
602
|
-
return {
|
|
603
|
-
body: {
|
|
604
|
-
data: { id: `file-op-${calls.length}` },
|
|
605
|
-
policies: [{ id: "policy-1" }],
|
|
606
|
-
},
|
|
607
|
-
};
|
|
608
|
-
},
|
|
609
|
-
},
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
try {
|
|
613
|
-
const importRes = await EXTENDED_TOOLS["documents.import"].handler(ctx, {
|
|
614
|
-
collectionId: "collection-1",
|
|
615
|
-
publish: false,
|
|
616
|
-
performAction: true,
|
|
617
|
-
});
|
|
618
|
-
const importFileRes = await EXTENDED_TOOLS["documents.import_file"].handler(ctx, {
|
|
619
|
-
filePath,
|
|
620
|
-
collectionId: "collection-1",
|
|
621
|
-
publish: false,
|
|
622
|
-
performAction: true,
|
|
623
|
-
});
|
|
624
|
-
const listRes = await EXTENDED_TOOLS["file_operations.list"].handler(ctx, {
|
|
625
|
-
limit: 10,
|
|
626
|
-
offset: 0,
|
|
627
|
-
});
|
|
628
|
-
const infoRes = await EXTENDED_TOOLS["file_operations.info"].handler(ctx, {
|
|
629
|
-
id: "file-op-1",
|
|
630
|
-
});
|
|
631
|
-
const deleteRes = await EXTENDED_TOOLS["file_operations.delete"].handler(ctx, {
|
|
632
|
-
id: "file-op-1",
|
|
633
|
-
performAction: true,
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
assert.deepEqual(
|
|
637
|
-
calls.map((call) => call.method),
|
|
638
|
-
[
|
|
639
|
-
"documents.import",
|
|
640
|
-
"documents.import",
|
|
641
|
-
"fileOperations.list",
|
|
642
|
-
"fileOperations.info",
|
|
643
|
-
"fileOperations.delete",
|
|
644
|
-
]
|
|
645
|
-
);
|
|
646
|
-
assert.deepEqual(calls[0].body, {
|
|
647
|
-
collectionId: "collection-1",
|
|
648
|
-
publish: false,
|
|
649
|
-
});
|
|
650
|
-
assert.equal(calls[0].options?.maxAttempts, 1);
|
|
651
|
-
|
|
652
|
-
assert.equal(calls[1].options?.bodyType, "multipart");
|
|
653
|
-
assert.equal(calls[1].options?.maxAttempts, 1);
|
|
654
|
-
assert.ok(calls[1].body instanceof FormData);
|
|
655
|
-
const multipartEntries = Array.from(calls[1].body.entries());
|
|
656
|
-
const filePart = multipartEntries.find(([key]) => key === "file")?.[1];
|
|
657
|
-
const collectionPart = multipartEntries.find(([key]) => key === "collectionId")?.[1];
|
|
658
|
-
const publishPart = multipartEntries.find(([key]) => key === "publish")?.[1];
|
|
659
|
-
assert.ok(filePart instanceof Blob);
|
|
660
|
-
assert.equal(filePart.name, "legacy-wiki.md");
|
|
661
|
-
assert.equal(collectionPart, "collection-1");
|
|
662
|
-
assert.equal(publishPart, "false");
|
|
663
|
-
|
|
664
|
-
assert.deepEqual(importRes.result, { data: { id: "file-op-1" } });
|
|
665
|
-
assert.deepEqual(importFileRes.result, { data: { id: "file-op-2" } });
|
|
666
|
-
assert.deepEqual(listRes.result, { data: { id: "file-op-3" } });
|
|
667
|
-
assert.deepEqual(infoRes.result, { data: { id: "file-op-4" } });
|
|
668
|
-
assert.deepEqual(deleteRes.result, { data: { id: "file-op-5" } });
|
|
669
|
-
|
|
670
|
-
await assert.rejects(
|
|
671
|
-
() =>
|
|
672
|
-
EXTENDED_TOOLS["documents.import"].handler(ctx, {
|
|
673
|
-
collectionId: "collection-1",
|
|
674
|
-
}),
|
|
675
|
-
(err) => {
|
|
676
|
-
assert.ok(err instanceof CliError);
|
|
677
|
-
assert.match(err.message, /performAction/);
|
|
678
|
-
return true;
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
|
-
|
|
682
|
-
await assert.rejects(
|
|
683
|
-
() =>
|
|
684
|
-
EXTENDED_TOOLS["documents.import_file"].handler(ctx, {
|
|
685
|
-
filePath,
|
|
686
|
-
}),
|
|
687
|
-
(err) => {
|
|
688
|
-
assert.ok(err instanceof CliError);
|
|
689
|
-
assert.match(err.message, /performAction/);
|
|
690
|
-
return true;
|
|
691
|
-
}
|
|
692
|
-
);
|
|
693
|
-
} finally {
|
|
694
|
-
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
test("validateToolArgs covers new scenario wrapper schemas", () => {
|
|
699
|
-
assert.doesNotThrow(() => validateToolArgs("shares.info", { id: "share-1" }));
|
|
700
|
-
assert.doesNotThrow(() => validateToolArgs("templates.create", { title: "Template", data: {} }));
|
|
701
|
-
assert.doesNotThrow(() =>
|
|
702
|
-
validateToolArgs("comments.create", {
|
|
703
|
-
documentId: "doc-1",
|
|
704
|
-
text: "looks good",
|
|
705
|
-
performAction: true,
|
|
706
|
-
})
|
|
707
|
-
);
|
|
708
|
-
assert.doesNotThrow(() =>
|
|
709
|
-
validateToolArgs("events.list", {
|
|
710
|
-
auditLog: true,
|
|
711
|
-
limit: 5,
|
|
712
|
-
view: "summary",
|
|
713
|
-
})
|
|
714
|
-
);
|
|
715
|
-
assert.doesNotThrow(() =>
|
|
716
|
-
validateToolArgs("documents.answer_batch", {
|
|
717
|
-
questions: ["What changed?"],
|
|
718
|
-
concurrency: 1,
|
|
719
|
-
})
|
|
720
|
-
);
|
|
721
|
-
assert.doesNotThrow(() => validateToolArgs("documents.cleanup_test", { deleteMode: "safe" }));
|
|
722
|
-
assert.doesNotThrow(() =>
|
|
723
|
-
validateToolArgs("collections.add_user", {
|
|
724
|
-
id: "collection-1",
|
|
725
|
-
userId: "user-1",
|
|
726
|
-
performAction: true,
|
|
727
|
-
})
|
|
728
|
-
);
|
|
729
|
-
assert.doesNotThrow(() =>
|
|
730
|
-
validateToolArgs("groups.memberships", {
|
|
731
|
-
id: "group-1",
|
|
732
|
-
limit: 20,
|
|
733
|
-
offset: 0,
|
|
734
|
-
view: "summary",
|
|
735
|
-
})
|
|
736
|
-
);
|
|
737
|
-
assert.doesNotThrow(() =>
|
|
738
|
-
validateToolArgs("documents.import", {
|
|
739
|
-
collectionId: "collection-1",
|
|
740
|
-
publish: false,
|
|
741
|
-
performAction: true,
|
|
742
|
-
})
|
|
743
|
-
);
|
|
744
|
-
assert.doesNotThrow(() =>
|
|
745
|
-
validateToolArgs("documents.import_file", {
|
|
746
|
-
filePath: "./tmp/wiki.md",
|
|
747
|
-
collectionId: "collection-1",
|
|
748
|
-
publish: false,
|
|
749
|
-
performAction: true,
|
|
750
|
-
})
|
|
751
|
-
);
|
|
752
|
-
assert.doesNotThrow(() => validateToolArgs("file_operations.list", { limit: 10 }));
|
|
753
|
-
assert.doesNotThrow(() => validateToolArgs("file_operations.info", { id: "file-op-1" }));
|
|
754
|
-
assert.doesNotThrow(() =>
|
|
755
|
-
validateToolArgs("file_operations.delete", { id: "file-op-1", performAction: true })
|
|
756
|
-
);
|
|
757
|
-
|
|
758
|
-
assert.throws(
|
|
759
|
-
() => validateToolArgs("shares.info", {}),
|
|
760
|
-
(err) => {
|
|
761
|
-
assert.ok(err instanceof CliError);
|
|
762
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
763
|
-
return true;
|
|
764
|
-
}
|
|
765
|
-
);
|
|
766
|
-
|
|
767
|
-
assert.throws(
|
|
768
|
-
() => validateToolArgs("templates.update", { title: "Missing id" }),
|
|
769
|
-
(err) => {
|
|
770
|
-
assert.ok(err instanceof CliError);
|
|
771
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
772
|
-
return true;
|
|
773
|
-
}
|
|
774
|
-
);
|
|
775
|
-
|
|
776
|
-
assert.throws(
|
|
777
|
-
() => validateToolArgs("comments.create", { documentId: "doc-1" }),
|
|
778
|
-
(err) => {
|
|
779
|
-
assert.ok(err instanceof CliError);
|
|
780
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.text"));
|
|
781
|
-
return true;
|
|
782
|
-
}
|
|
783
|
-
);
|
|
784
|
-
|
|
785
|
-
assert.throws(
|
|
786
|
-
() => validateToolArgs("webhooks.create", { name: "w", url: "https://example.com", events: [] }),
|
|
787
|
-
(err) => {
|
|
788
|
-
assert.ok(err instanceof CliError);
|
|
789
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.events"));
|
|
790
|
-
return true;
|
|
791
|
-
}
|
|
792
|
-
);
|
|
793
|
-
|
|
794
|
-
assert.throws(
|
|
795
|
-
() => validateToolArgs("documents.answer_batch", { questions: [" "] }),
|
|
796
|
-
(err) => {
|
|
797
|
-
assert.ok(err instanceof CliError);
|
|
798
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.questions[0]"));
|
|
799
|
-
return true;
|
|
800
|
-
}
|
|
801
|
-
);
|
|
802
|
-
|
|
803
|
-
assert.throws(
|
|
804
|
-
() => validateToolArgs("documents.cleanup_test", { deleteMode: "unsafe" }),
|
|
805
|
-
(err) => {
|
|
806
|
-
assert.ok(err instanceof CliError);
|
|
807
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.deleteMode"));
|
|
808
|
-
return true;
|
|
809
|
-
}
|
|
810
|
-
);
|
|
811
|
-
|
|
812
|
-
assert.throws(
|
|
813
|
-
() => validateToolArgs("documents.remove_group", { groupId: "group-1", performAction: true }),
|
|
814
|
-
(err) => {
|
|
815
|
-
assert.ok(err instanceof CliError);
|
|
816
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
817
|
-
return true;
|
|
818
|
-
}
|
|
819
|
-
);
|
|
820
|
-
|
|
821
|
-
assert.throws(
|
|
822
|
-
() => validateToolArgs("documents.import_file", { performAction: true }),
|
|
823
|
-
(err) => {
|
|
824
|
-
assert.ok(err instanceof CliError);
|
|
825
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.filePath"));
|
|
826
|
-
return true;
|
|
827
|
-
}
|
|
828
|
-
);
|
|
829
|
-
|
|
830
|
-
assert.throws(
|
|
831
|
-
() =>
|
|
832
|
-
validateToolArgs("documents.import_file", {
|
|
833
|
-
filePath: "./tmp/wiki.md",
|
|
834
|
-
collectionId: "collection-1",
|
|
835
|
-
parentDocumentId: "doc-1",
|
|
836
|
-
performAction: true,
|
|
837
|
-
}),
|
|
838
|
-
(err) => {
|
|
839
|
-
assert.ok(err instanceof CliError);
|
|
840
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.parentDocumentId"));
|
|
841
|
-
return true;
|
|
842
|
-
}
|
|
843
|
-
);
|
|
844
|
-
|
|
845
|
-
assert.throws(
|
|
846
|
-
() => validateToolArgs("file_operations.info", {}),
|
|
847
|
-
(err) => {
|
|
848
|
-
assert.ok(err instanceof CliError);
|
|
849
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
850
|
-
return true;
|
|
851
|
-
}
|
|
852
|
-
);
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
test("oauth schemas validate canonical wrappers and compatibility aliases", () => {
|
|
856
|
-
assert.doesNotThrow(() => validateToolArgs("oauth_clients.list", { limit: 10, offset: 0 }));
|
|
857
|
-
assert.doesNotThrow(() => validateToolArgs("oauth_clients.info", { id: "oauth-client-1" }));
|
|
858
|
-
assert.doesNotThrow(() => validateToolArgs("oauth_clients.info", { clientId: "pub-client-id" }));
|
|
859
|
-
assert.doesNotThrow(() =>
|
|
860
|
-
validateToolArgs("oauth_clients.create", {
|
|
861
|
-
name: "CLI App",
|
|
862
|
-
redirectUris: ["https://example.com/callback"],
|
|
863
|
-
performAction: true,
|
|
864
|
-
})
|
|
865
|
-
);
|
|
866
|
-
assert.doesNotThrow(() =>
|
|
867
|
-
validateToolArgs("oauth_clients.update", {
|
|
868
|
-
id: "oauth-client-1",
|
|
869
|
-
redirectUris: ["https://example.com/callback"],
|
|
870
|
-
performAction: true,
|
|
871
|
-
})
|
|
872
|
-
);
|
|
873
|
-
assert.doesNotThrow(() =>
|
|
874
|
-
validateToolArgs("oauth_clients.rotate_secret", {
|
|
875
|
-
id: "oauth-client-1",
|
|
876
|
-
performAction: true,
|
|
877
|
-
})
|
|
878
|
-
);
|
|
879
|
-
assert.doesNotThrow(() =>
|
|
880
|
-
validateToolArgs("oauth_clients.delete", { id: "oauth-client-1", performAction: true })
|
|
881
|
-
);
|
|
882
|
-
assert.doesNotThrow(() => validateToolArgs("oauth_authentications.list", { limit: 5, offset: 0 }));
|
|
883
|
-
assert.doesNotThrow(() =>
|
|
884
|
-
validateToolArgs("oauth_authentications.delete", {
|
|
885
|
-
oauthClientId: "oauth-client-1",
|
|
886
|
-
scope: ["read"],
|
|
887
|
-
performAction: true,
|
|
888
|
-
})
|
|
889
|
-
);
|
|
890
|
-
assert.doesNotThrow(() => validateToolArgs("oauthClients.delete", { id: "oauth-client-1", performAction: true }));
|
|
891
|
-
assert.doesNotThrow(() =>
|
|
892
|
-
validateToolArgs("oauthAuthentications.delete", {
|
|
893
|
-
oauthClientId: "oauth-client-1",
|
|
894
|
-
performAction: true,
|
|
895
|
-
})
|
|
896
|
-
);
|
|
897
|
-
|
|
898
|
-
assert.throws(
|
|
899
|
-
() => validateToolArgs("oauth_clients.info", {}),
|
|
900
|
-
(err) => {
|
|
901
|
-
assert.ok(err instanceof CliError);
|
|
902
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
903
|
-
return true;
|
|
904
|
-
}
|
|
905
|
-
);
|
|
906
|
-
assert.throws(
|
|
907
|
-
() => validateToolArgs("oauth_clients.info", { id: "oauth-client-1", clientId: "pub-client-id" }),
|
|
908
|
-
(err) => {
|
|
909
|
-
assert.ok(err instanceof CliError);
|
|
910
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.clientId"));
|
|
911
|
-
return true;
|
|
912
|
-
}
|
|
913
|
-
);
|
|
914
|
-
assert.throws(
|
|
915
|
-
() =>
|
|
916
|
-
validateToolArgs("oauth_clients.create", {
|
|
917
|
-
name: "CLI App",
|
|
918
|
-
redirectUris: [],
|
|
919
|
-
performAction: true,
|
|
920
|
-
}),
|
|
921
|
-
(err) => {
|
|
922
|
-
assert.ok(err instanceof CliError);
|
|
923
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.redirectUris"));
|
|
924
|
-
return true;
|
|
925
|
-
}
|
|
926
|
-
);
|
|
927
|
-
assert.throws(
|
|
928
|
-
() =>
|
|
929
|
-
validateToolArgs("oauth_clients.create", {
|
|
930
|
-
redirectUris: ["https://example.com/callback"],
|
|
931
|
-
performAction: true,
|
|
932
|
-
}),
|
|
933
|
-
(err) => {
|
|
934
|
-
assert.ok(err instanceof CliError);
|
|
935
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.name"));
|
|
936
|
-
return true;
|
|
937
|
-
}
|
|
938
|
-
);
|
|
939
|
-
assert.throws(
|
|
940
|
-
() => validateToolArgs("oauth_authentications.delete", { performAction: true }),
|
|
941
|
-
(err) => {
|
|
942
|
-
assert.ok(err instanceof CliError);
|
|
943
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.oauthClientId"));
|
|
944
|
-
return true;
|
|
945
|
-
}
|
|
946
|
-
);
|
|
947
|
-
assert.throws(
|
|
948
|
-
() =>
|
|
949
|
-
validateToolArgs("oauth_authentications.delete", {
|
|
950
|
-
oauthClientId: "oauth-client-1",
|
|
951
|
-
scope: [],
|
|
952
|
-
performAction: true,
|
|
953
|
-
}),
|
|
954
|
-
(err) => {
|
|
955
|
-
assert.ok(err instanceof CliError);
|
|
956
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.scope"));
|
|
957
|
-
return true;
|
|
958
|
-
}
|
|
959
|
-
);
|
|
960
|
-
assert.throws(
|
|
961
|
-
() => validateToolArgs("oauthClients.delete", { performAction: true }),
|
|
962
|
-
(err) => {
|
|
963
|
-
assert.ok(err instanceof CliError);
|
|
964
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
965
|
-
return true;
|
|
966
|
-
}
|
|
967
|
-
);
|
|
968
|
-
assert.throws(
|
|
969
|
-
() => validateToolArgs("oauthAuthentications.delete", { performAction: true }),
|
|
970
|
-
(err) => {
|
|
971
|
-
assert.ok(err instanceof CliError);
|
|
972
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.oauthClientId"));
|
|
973
|
-
return true;
|
|
974
|
-
}
|
|
975
|
-
);
|
|
976
|
-
});
|
|
977
|
-
|
|
978
|
-
test("documents.permanent_delete schema enforces id and action-gate compatible fields", () => {
|
|
979
|
-
assert.doesNotThrow(() =>
|
|
980
|
-
validateToolArgs("documents.permanent_delete", {
|
|
981
|
-
id: "doc-deleted-1",
|
|
982
|
-
performAction: true,
|
|
983
|
-
maxAttempts: 2,
|
|
984
|
-
view: "summary",
|
|
985
|
-
includePolicies: true,
|
|
986
|
-
})
|
|
987
|
-
);
|
|
988
|
-
|
|
989
|
-
assert.throws(
|
|
990
|
-
() =>
|
|
991
|
-
validateToolArgs("documents.permanent_delete", {
|
|
992
|
-
performAction: true,
|
|
993
|
-
}),
|
|
994
|
-
(err) => {
|
|
995
|
-
assert.ok(err instanceof CliError);
|
|
996
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
997
|
-
return true;
|
|
998
|
-
}
|
|
999
|
-
);
|
|
1000
|
-
|
|
1001
|
-
assert.throws(
|
|
1002
|
-
() =>
|
|
1003
|
-
validateToolArgs("documents.permanent_delete", {
|
|
1004
|
-
id: "doc-deleted-1",
|
|
1005
|
-
performAction: "yes",
|
|
1006
|
-
}),
|
|
1007
|
-
(err) => {
|
|
1008
|
-
assert.ok(err instanceof CliError);
|
|
1009
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.performAction"));
|
|
1010
|
-
return true;
|
|
1011
|
-
}
|
|
1012
|
-
);
|
|
1013
|
-
});
|
|
1014
|
-
|
|
1015
|
-
test("templates.extract_placeholders returns deterministic sorted placeholders and counts", async () => {
|
|
1016
|
-
const contract = EXTENDED_TOOLS["templates.extract_placeholders"];
|
|
1017
|
-
assert.ok(contract);
|
|
1018
|
-
assert.equal(typeof contract.handler, "function");
|
|
1019
|
-
|
|
1020
|
-
const calls = [];
|
|
1021
|
-
const ctx = {
|
|
1022
|
-
profile: { id: "profile-hardening" },
|
|
1023
|
-
client: {
|
|
1024
|
-
async call(method, body, options) {
|
|
1025
|
-
calls.push({ method, body, options });
|
|
1026
|
-
assert.equal(method, "templates.info");
|
|
1027
|
-
return {
|
|
1028
|
-
body: {
|
|
1029
|
-
data: {
|
|
1030
|
-
id: "template-1",
|
|
1031
|
-
title: "Incident Template",
|
|
1032
|
-
data: {
|
|
1033
|
-
type: "doc",
|
|
1034
|
-
content: [
|
|
1035
|
-
{
|
|
1036
|
-
type: "paragraph",
|
|
1037
|
-
content: [{ type: "text", text: "Owner {{owner}} handles {{service_name}}" }],
|
|
1038
|
-
},
|
|
1039
|
-
{
|
|
1040
|
-
type: "paragraph",
|
|
1041
|
-
content: [{ type: "text", text: "Escalate {{owner}} by {{target_date}}" }],
|
|
1042
|
-
},
|
|
1043
|
-
{
|
|
1044
|
-
type: "paragraph",
|
|
1045
|
-
content: [{ type: "text", text: "No placeholder here" }],
|
|
1046
|
-
},
|
|
1047
|
-
],
|
|
1048
|
-
},
|
|
1049
|
-
},
|
|
1050
|
-
},
|
|
1051
|
-
};
|
|
1052
|
-
},
|
|
1053
|
-
},
|
|
1054
|
-
};
|
|
1055
|
-
|
|
1056
|
-
const output = await contract.handler(ctx, { id: "template-1" });
|
|
1057
|
-
|
|
1058
|
-
assert.deepEqual(calls, [
|
|
1059
|
-
{
|
|
1060
|
-
method: "templates.info",
|
|
1061
|
-
body: { id: "template-1" },
|
|
1062
|
-
options: { maxAttempts: 2 },
|
|
1063
|
-
},
|
|
1064
|
-
]);
|
|
1065
|
-
assert.equal(output.tool, "templates.extract_placeholders");
|
|
1066
|
-
assert.equal(output.profile, "profile-hardening");
|
|
1067
|
-
assert.deepEqual(output.result.id, "template-1");
|
|
1068
|
-
assert.deepEqual(output.result.placeholders, ["owner", "service_name", "target_date"]);
|
|
1069
|
-
assert.deepEqual(output.result.counts, [
|
|
1070
|
-
{ key: "owner", count: 2 },
|
|
1071
|
-
{ key: "service_name", count: 1 },
|
|
1072
|
-
{ key: "target_date", count: 1 },
|
|
1073
|
-
]);
|
|
1074
|
-
assert.equal(output.result.meta.placeholderTokenCount, 4);
|
|
1075
|
-
assert.equal(output.result.meta.uniquePlaceholderCount, 3);
|
|
1076
|
-
assert.equal(output.result.meta.textNodeCount, 3);
|
|
1077
|
-
assert.equal(typeof output.result.meta.scannedCharacterCount, "number");
|
|
1078
|
-
assert.ok(output.result.meta.scannedCharacterCount > 0);
|
|
1079
|
-
});
|
|
1080
|
-
|
|
1081
|
-
test("documents.create_from_template enforces strict unresolved placeholders without publishing", async () => {
|
|
1082
|
-
const contract = EXTENDED_TOOLS["documents.create_from_template"];
|
|
1083
|
-
assert.ok(contract);
|
|
1084
|
-
assert.equal(typeof contract.handler, "function");
|
|
1085
|
-
|
|
1086
|
-
const calls = [];
|
|
1087
|
-
const ctx = {
|
|
1088
|
-
profile: { id: "profile-hardening" },
|
|
1089
|
-
client: {
|
|
1090
|
-
async call(method, body, options) {
|
|
1091
|
-
calls.push({ method, body, options });
|
|
1092
|
-
if (method === "documents.create") {
|
|
1093
|
-
return {
|
|
1094
|
-
body: {
|
|
1095
|
-
data: {
|
|
1096
|
-
id: "doc-from-template-1",
|
|
1097
|
-
title: "Incident Runbook",
|
|
1098
|
-
collectionId: "collection-1",
|
|
1099
|
-
parentDocumentId: "",
|
|
1100
|
-
updatedAt: "2026-03-05T00:00:00.000Z",
|
|
1101
|
-
publishedAt: "",
|
|
1102
|
-
urlId: "incident-runbook",
|
|
1103
|
-
emoji: ":memo:",
|
|
1104
|
-
text: "Owner {{owner}} handles {{service_name}} by {{target_date}}",
|
|
1105
|
-
},
|
|
1106
|
-
},
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
if (method === "documents.update") {
|
|
1111
|
-
assert.deepEqual(body, {
|
|
1112
|
-
id: "doc-from-template-1",
|
|
1113
|
-
text: "Owner Alice handles {{service_name}} by {{target_date}}",
|
|
1114
|
-
publish: false,
|
|
1115
|
-
});
|
|
1116
|
-
return {
|
|
1117
|
-
body: {
|
|
1118
|
-
data: {
|
|
1119
|
-
id: "doc-from-template-1",
|
|
1120
|
-
title: "Incident Runbook",
|
|
1121
|
-
collectionId: "collection-1",
|
|
1122
|
-
parentDocumentId: "",
|
|
1123
|
-
updatedAt: "2026-03-05T00:01:00.000Z",
|
|
1124
|
-
publishedAt: "",
|
|
1125
|
-
urlId: "incident-runbook",
|
|
1126
|
-
emoji: ":memo:",
|
|
1127
|
-
text: "Owner Alice handles {{service_name}} by {{target_date}}",
|
|
1128
|
-
},
|
|
1129
|
-
},
|
|
1130
|
-
};
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
1134
|
-
},
|
|
1135
|
-
},
|
|
1136
|
-
};
|
|
1137
|
-
|
|
1138
|
-
const output = await contract.handler(ctx, {
|
|
1139
|
-
templateId: "template-1",
|
|
1140
|
-
title: "Incident Runbook",
|
|
1141
|
-
collectionId: "collection-1",
|
|
1142
|
-
publish: true,
|
|
1143
|
-
placeholderValues: {
|
|
1144
|
-
owner: "Alice",
|
|
1145
|
-
},
|
|
1146
|
-
strictPlaceholders: true,
|
|
1147
|
-
performAction: true,
|
|
1148
|
-
view: "summary",
|
|
1149
|
-
});
|
|
1150
|
-
|
|
1151
|
-
assert.deepEqual(calls, [
|
|
1152
|
-
{
|
|
1153
|
-
method: "documents.create",
|
|
1154
|
-
body: {
|
|
1155
|
-
templateId: "template-1",
|
|
1156
|
-
title: "Incident Runbook",
|
|
1157
|
-
collectionId: "collection-1",
|
|
1158
|
-
publish: false,
|
|
1159
|
-
},
|
|
1160
|
-
options: { maxAttempts: 1 },
|
|
1161
|
-
},
|
|
1162
|
-
{
|
|
1163
|
-
method: "documents.update",
|
|
1164
|
-
body: {
|
|
1165
|
-
id: "doc-from-template-1",
|
|
1166
|
-
text: "Owner Alice handles {{service_name}} by {{target_date}}",
|
|
1167
|
-
publish: false,
|
|
1168
|
-
},
|
|
1169
|
-
options: { maxAttempts: 1 },
|
|
1170
|
-
},
|
|
1171
|
-
]);
|
|
1172
|
-
assert.equal(output.tool, "documents.create_from_template");
|
|
1173
|
-
assert.equal(output.profile, "profile-hardening");
|
|
1174
|
-
assert.equal(output.result.success, false);
|
|
1175
|
-
assert.equal(output.result.code, "STRICT_PLACEHOLDERS_UNRESOLVED");
|
|
1176
|
-
assert.equal(output.result.publishRequested, true);
|
|
1177
|
-
assert.equal(output.result.published, false);
|
|
1178
|
-
assert.equal(output.result.safeBehavior, "left_unpublished_draft");
|
|
1179
|
-
assert.deepEqual(output.result.placeholders.providedKeys, ["owner"]);
|
|
1180
|
-
assert.deepEqual(output.result.placeholders.unresolved, ["service_name", "target_date"]);
|
|
1181
|
-
assert.equal(output.result.placeholders.unresolvedCount, 2);
|
|
1182
|
-
assert.deepEqual(output.result.placeholders.replacedByPlaceholder, [{ key: "owner", count: 1 }]);
|
|
1183
|
-
assert.deepEqual(output.result.actions, {
|
|
1184
|
-
create: true,
|
|
1185
|
-
updateText: true,
|
|
1186
|
-
publish: false,
|
|
1187
|
-
});
|
|
1188
|
-
});
|
|
1189
|
-
|
|
1190
|
-
test("template pipeline schemas enforce strict id and placeholderValues validation", () => {
|
|
1191
|
-
assert.doesNotThrow(() =>
|
|
1192
|
-
validateToolArgs("templates.extract_placeholders", {
|
|
1193
|
-
id: "template-1",
|
|
1194
|
-
})
|
|
1195
|
-
);
|
|
1196
|
-
|
|
1197
|
-
assert.doesNotThrow(() =>
|
|
1198
|
-
validateToolArgs("documents.create_from_template", {
|
|
1199
|
-
templateId: "template-1",
|
|
1200
|
-
title: "Incident Runbook",
|
|
1201
|
-
publish: true,
|
|
1202
|
-
placeholderValues: {
|
|
1203
|
-
owner: "Alice",
|
|
1204
|
-
service_name: "Payments API",
|
|
1205
|
-
},
|
|
1206
|
-
strictPlaceholders: true,
|
|
1207
|
-
view: "summary",
|
|
1208
|
-
performAction: true,
|
|
1209
|
-
})
|
|
1210
|
-
);
|
|
1211
|
-
|
|
1212
|
-
assert.throws(
|
|
1213
|
-
() => validateToolArgs("templates.extract_placeholders", { id: " " }),
|
|
1214
|
-
(err) => {
|
|
1215
|
-
assert.ok(err instanceof CliError);
|
|
1216
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1217
|
-
return true;
|
|
1218
|
-
}
|
|
1219
|
-
);
|
|
1220
|
-
|
|
1221
|
-
assert.throws(
|
|
1222
|
-
() =>
|
|
1223
|
-
validateToolArgs("documents.create_from_template", {
|
|
1224
|
-
templateId: "",
|
|
1225
|
-
performAction: true,
|
|
1226
|
-
}),
|
|
1227
|
-
(err) => {
|
|
1228
|
-
assert.ok(err instanceof CliError);
|
|
1229
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.templateId"));
|
|
1230
|
-
return true;
|
|
1231
|
-
}
|
|
1232
|
-
);
|
|
1233
|
-
|
|
1234
|
-
assert.throws(
|
|
1235
|
-
() =>
|
|
1236
|
-
validateToolArgs("documents.create_from_template", {
|
|
1237
|
-
templateId: "template-1",
|
|
1238
|
-
placeholderValues: {
|
|
1239
|
-
owner: 42,
|
|
1240
|
-
},
|
|
1241
|
-
performAction: true,
|
|
1242
|
-
}),
|
|
1243
|
-
(err) => {
|
|
1244
|
-
assert.ok(err instanceof CliError);
|
|
1245
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.placeholderValues.owner"));
|
|
1246
|
-
return true;
|
|
1247
|
-
}
|
|
1248
|
-
);
|
|
1249
|
-
|
|
1250
|
-
assert.throws(
|
|
1251
|
-
() =>
|
|
1252
|
-
validateToolArgs("documents.create_from_template", {
|
|
1253
|
-
templateId: "template-1",
|
|
1254
|
-
view: "ids",
|
|
1255
|
-
performAction: true,
|
|
1256
|
-
}),
|
|
1257
|
-
(err) => {
|
|
1258
|
-
assert.ok(err instanceof CliError);
|
|
1259
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.view"));
|
|
1260
|
-
return true;
|
|
1261
|
-
}
|
|
1262
|
-
);
|
|
1263
|
-
});
|
|
1264
|
-
|
|
1265
|
-
test("data_attributes schemas and document dataAttributes alignment validate valid and invalid inputs", () => {
|
|
1266
|
-
assert.doesNotThrow(() =>
|
|
1267
|
-
validateToolArgs("data_attributes.list", {
|
|
1268
|
-
limit: 25,
|
|
1269
|
-
offset: 0,
|
|
1270
|
-
view: "summary",
|
|
1271
|
-
})
|
|
1272
|
-
);
|
|
1273
|
-
assert.doesNotThrow(() => validateToolArgs("data_attributes.info", { id: "attr-1" }));
|
|
1274
|
-
assert.doesNotThrow(() =>
|
|
1275
|
-
validateToolArgs("data_attributes.create", {
|
|
1276
|
-
name: "Status",
|
|
1277
|
-
dataType: "list",
|
|
1278
|
-
options: {
|
|
1279
|
-
icon: "status",
|
|
1280
|
-
options: [{ value: "In Progress", color: "#0366d6" }],
|
|
1281
|
-
},
|
|
1282
|
-
performAction: true,
|
|
1283
|
-
})
|
|
1284
|
-
);
|
|
1285
|
-
assert.doesNotThrow(() =>
|
|
1286
|
-
validateToolArgs("data_attributes.update", {
|
|
1287
|
-
id: "attr-1",
|
|
1288
|
-
name: "Status",
|
|
1289
|
-
pinned: true,
|
|
1290
|
-
performAction: true,
|
|
1291
|
-
})
|
|
1292
|
-
);
|
|
1293
|
-
assert.doesNotThrow(() =>
|
|
1294
|
-
validateToolArgs("data_attributes.delete", {
|
|
1295
|
-
id: "attr-1",
|
|
1296
|
-
performAction: true,
|
|
1297
|
-
})
|
|
1298
|
-
);
|
|
1299
|
-
assert.doesNotThrow(() =>
|
|
1300
|
-
validateToolArgs("documents.create", {
|
|
1301
|
-
title: "Release plan",
|
|
1302
|
-
dataAttributes: [{ dataAttributeId: "attr-1", value: "In Progress" }],
|
|
1303
|
-
})
|
|
1304
|
-
);
|
|
1305
|
-
assert.doesNotThrow(() =>
|
|
1306
|
-
validateToolArgs("documents.update", {
|
|
1307
|
-
id: "doc-1",
|
|
1308
|
-
dataAttributes: [{ dataAttributeId: "attr-1", value: "Done" }],
|
|
1309
|
-
performAction: true,
|
|
1310
|
-
})
|
|
1311
|
-
);
|
|
1312
|
-
assert.doesNotThrow(() =>
|
|
1313
|
-
validateToolArgs("documents.safe_update", {
|
|
1314
|
-
id: "doc-1",
|
|
1315
|
-
expectedRevision: 3,
|
|
1316
|
-
dataAttributes: [{ dataAttributeId: "attr-1", value: true }],
|
|
1317
|
-
performAction: true,
|
|
1318
|
-
})
|
|
1319
|
-
);
|
|
1320
|
-
assert.doesNotThrow(() =>
|
|
1321
|
-
validateToolArgs("documents.batch_update", {
|
|
1322
|
-
updates: [
|
|
1323
|
-
{
|
|
1324
|
-
id: "doc-1",
|
|
1325
|
-
dataAttributes: [{ dataAttributeId: "attr-1", value: 42 }],
|
|
1326
|
-
},
|
|
1327
|
-
],
|
|
1328
|
-
performAction: true,
|
|
1329
|
-
})
|
|
1330
|
-
);
|
|
1331
|
-
|
|
1332
|
-
assert.throws(
|
|
1333
|
-
() => validateToolArgs("data_attributes.list", { limit: 251 }),
|
|
1334
|
-
(err) => {
|
|
1335
|
-
assert.ok(err instanceof CliError);
|
|
1336
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.limit"));
|
|
1337
|
-
return true;
|
|
1338
|
-
}
|
|
1339
|
-
);
|
|
1340
|
-
assert.throws(
|
|
1341
|
-
() => validateToolArgs("data_attributes.info", {}),
|
|
1342
|
-
(err) => {
|
|
1343
|
-
assert.ok(err instanceof CliError);
|
|
1344
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1345
|
-
return true;
|
|
1346
|
-
}
|
|
1347
|
-
);
|
|
1348
|
-
assert.throws(
|
|
1349
|
-
() =>
|
|
1350
|
-
validateToolArgs("data_attributes.create", {
|
|
1351
|
-
name: "Status",
|
|
1352
|
-
performAction: true,
|
|
1353
|
-
}),
|
|
1354
|
-
(err) => {
|
|
1355
|
-
assert.ok(err instanceof CliError);
|
|
1356
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.dataType"));
|
|
1357
|
-
return true;
|
|
1358
|
-
}
|
|
1359
|
-
);
|
|
1360
|
-
assert.throws(
|
|
1361
|
-
() =>
|
|
1362
|
-
validateToolArgs("data_attributes.create", {
|
|
1363
|
-
name: "Status",
|
|
1364
|
-
dataType: "date",
|
|
1365
|
-
performAction: true,
|
|
1366
|
-
}),
|
|
1367
|
-
(err) => {
|
|
1368
|
-
assert.ok(err instanceof CliError);
|
|
1369
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.dataType"));
|
|
1370
|
-
return true;
|
|
1371
|
-
}
|
|
1372
|
-
);
|
|
1373
|
-
assert.throws(
|
|
1374
|
-
() =>
|
|
1375
|
-
validateToolArgs("data_attributes.update", {
|
|
1376
|
-
id: "attr-1",
|
|
1377
|
-
performAction: true,
|
|
1378
|
-
}),
|
|
1379
|
-
(err) => {
|
|
1380
|
-
assert.ok(err instanceof CliError);
|
|
1381
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.name"));
|
|
1382
|
-
return true;
|
|
1383
|
-
}
|
|
1384
|
-
);
|
|
1385
|
-
assert.throws(
|
|
1386
|
-
() => validateToolArgs("data_attributes.delete", { performAction: true }),
|
|
1387
|
-
(err) => {
|
|
1388
|
-
assert.ok(err instanceof CliError);
|
|
1389
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1390
|
-
return true;
|
|
1391
|
-
}
|
|
1392
|
-
);
|
|
1393
|
-
assert.throws(
|
|
1394
|
-
() =>
|
|
1395
|
-
validateToolArgs("documents.create", {
|
|
1396
|
-
title: "Release plan",
|
|
1397
|
-
dataAttributes: { dataAttributeId: "attr-1", value: "In Progress" },
|
|
1398
|
-
}),
|
|
1399
|
-
(err) => {
|
|
1400
|
-
assert.ok(err instanceof CliError);
|
|
1401
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.dataAttributes"));
|
|
1402
|
-
return true;
|
|
1403
|
-
}
|
|
1404
|
-
);
|
|
1405
|
-
assert.throws(
|
|
1406
|
-
() =>
|
|
1407
|
-
validateToolArgs("documents.safe_update", {
|
|
1408
|
-
id: "doc-1",
|
|
1409
|
-
expectedRevision: 3,
|
|
1410
|
-
dataAttributes: "invalid",
|
|
1411
|
-
}),
|
|
1412
|
-
(err) => {
|
|
1413
|
-
assert.ok(err instanceof CliError);
|
|
1414
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.dataAttributes"));
|
|
1415
|
-
return true;
|
|
1416
|
-
}
|
|
1417
|
-
);
|
|
1418
|
-
assert.throws(
|
|
1419
|
-
() =>
|
|
1420
|
-
validateToolArgs("documents.batch_update", {
|
|
1421
|
-
updates: [{ id: "doc-1", dataAttributes: { dataAttributeId: "attr-1", value: "In Progress" } }],
|
|
1422
|
-
performAction: true,
|
|
1423
|
-
}),
|
|
1424
|
-
(err) => {
|
|
1425
|
-
assert.ok(err instanceof CliError);
|
|
1426
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.updates[0].dataAttributes"));
|
|
1427
|
-
return true;
|
|
1428
|
-
}
|
|
1429
|
-
);
|
|
1430
|
-
});
|
|
1431
|
-
|
|
1432
|
-
test("users/groups schemas enforce deterministic id selector constraints", () => {
|
|
1433
|
-
assert.doesNotThrow(() => validateToolArgs("users.info", { id: "user-1" }));
|
|
1434
|
-
assert.doesNotThrow(() => validateToolArgs("users.info", { ids: ["user-1", "user-2"] }));
|
|
1435
|
-
assert.doesNotThrow(() => validateToolArgs("groups.info", { id: "group-1" }));
|
|
1436
|
-
assert.doesNotThrow(() => validateToolArgs("groups.info", { ids: ["group-1"] }));
|
|
1437
|
-
|
|
1438
|
-
assert.throws(
|
|
1439
|
-
() => validateToolArgs("users.info", { ids: [] }),
|
|
1440
|
-
(err) => {
|
|
1441
|
-
assert.ok(err instanceof CliError);
|
|
1442
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
1443
|
-
return true;
|
|
1444
|
-
}
|
|
1445
|
-
);
|
|
1446
|
-
|
|
1447
|
-
assert.throws(
|
|
1448
|
-
() => validateToolArgs("users.info", { id: "user-1", ids: ["user-2"] }),
|
|
1449
|
-
(err) => {
|
|
1450
|
-
assert.ok(err instanceof CliError);
|
|
1451
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
1452
|
-
return true;
|
|
1453
|
-
}
|
|
1454
|
-
);
|
|
1455
|
-
|
|
1456
|
-
assert.throws(
|
|
1457
|
-
() => validateToolArgs("groups.info", { ids: [] }),
|
|
1458
|
-
(err) => {
|
|
1459
|
-
assert.ok(err instanceof CliError);
|
|
1460
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
1461
|
-
return true;
|
|
1462
|
-
}
|
|
1463
|
-
);
|
|
1464
|
-
|
|
1465
|
-
assert.throws(
|
|
1466
|
-
() => validateToolArgs("groups.info", { id: "group-1", ids: ["group-2"] }),
|
|
1467
|
-
(err) => {
|
|
1468
|
-
assert.ok(err instanceof CliError);
|
|
1469
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
1470
|
-
return true;
|
|
1471
|
-
}
|
|
1472
|
-
);
|
|
1473
|
-
});
|
|
1474
|
-
|
|
1475
|
-
test("user lifecycle and documents.users schemas enforce required selectors and role enum", () => {
|
|
1476
|
-
assert.doesNotThrow(() =>
|
|
1477
|
-
validateToolArgs("users.invite", {
|
|
1478
|
-
email: "new.user@example.com",
|
|
1479
|
-
role: "member",
|
|
1480
|
-
performAction: true,
|
|
1481
|
-
})
|
|
1482
|
-
);
|
|
1483
|
-
assert.doesNotThrow(() =>
|
|
1484
|
-
validateToolArgs("users.update_role", {
|
|
1485
|
-
id: "user-1",
|
|
1486
|
-
role: "viewer",
|
|
1487
|
-
performAction: true,
|
|
1488
|
-
})
|
|
1489
|
-
);
|
|
1490
|
-
assert.doesNotThrow(() =>
|
|
1491
|
-
validateToolArgs("users.activate", {
|
|
1492
|
-
id: "user-1",
|
|
1493
|
-
performAction: true,
|
|
1494
|
-
})
|
|
1495
|
-
);
|
|
1496
|
-
assert.doesNotThrow(() =>
|
|
1497
|
-
validateToolArgs("users.suspend", {
|
|
1498
|
-
id: "user-1",
|
|
1499
|
-
performAction: true,
|
|
1500
|
-
})
|
|
1501
|
-
);
|
|
1502
|
-
assert.doesNotThrow(() =>
|
|
1503
|
-
validateToolArgs("documents.users", {
|
|
1504
|
-
id: "doc-1",
|
|
1505
|
-
limit: 20,
|
|
1506
|
-
offset: 0,
|
|
1507
|
-
view: "summary",
|
|
1508
|
-
})
|
|
1509
|
-
);
|
|
1510
|
-
|
|
1511
|
-
assert.throws(
|
|
1512
|
-
() => validateToolArgs("users.invite", { performAction: true }),
|
|
1513
|
-
(err) => {
|
|
1514
|
-
assert.ok(err instanceof CliError);
|
|
1515
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.email"));
|
|
1516
|
-
return true;
|
|
1517
|
-
}
|
|
1518
|
-
);
|
|
1519
|
-
assert.throws(
|
|
1520
|
-
() =>
|
|
1521
|
-
validateToolArgs("users.invite", {
|
|
1522
|
-
email: "new.user@example.com",
|
|
1523
|
-
role: "owner",
|
|
1524
|
-
performAction: true,
|
|
1525
|
-
}),
|
|
1526
|
-
(err) => {
|
|
1527
|
-
assert.ok(err instanceof CliError);
|
|
1528
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.role"));
|
|
1529
|
-
return true;
|
|
1530
|
-
}
|
|
1531
|
-
);
|
|
1532
|
-
assert.throws(
|
|
1533
|
-
() =>
|
|
1534
|
-
validateToolArgs("users.update_role", {
|
|
1535
|
-
id: "user-1",
|
|
1536
|
-
performAction: true,
|
|
1537
|
-
}),
|
|
1538
|
-
(err) => {
|
|
1539
|
-
assert.ok(err instanceof CliError);
|
|
1540
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.role"));
|
|
1541
|
-
return true;
|
|
1542
|
-
}
|
|
1543
|
-
);
|
|
1544
|
-
assert.throws(
|
|
1545
|
-
() =>
|
|
1546
|
-
validateToolArgs("users.activate", {
|
|
1547
|
-
performAction: true,
|
|
1548
|
-
}),
|
|
1549
|
-
(err) => {
|
|
1550
|
-
assert.ok(err instanceof CliError);
|
|
1551
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1552
|
-
return true;
|
|
1553
|
-
}
|
|
1554
|
-
);
|
|
1555
|
-
assert.throws(
|
|
1556
|
-
() =>
|
|
1557
|
-
validateToolArgs("users.suspend", {
|
|
1558
|
-
performAction: true,
|
|
1559
|
-
}),
|
|
1560
|
-
(err) => {
|
|
1561
|
-
assert.ok(err instanceof CliError);
|
|
1562
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1563
|
-
return true;
|
|
1564
|
-
}
|
|
1565
|
-
);
|
|
1566
|
-
assert.throws(
|
|
1567
|
-
() => validateToolArgs("documents.users", {}),
|
|
1568
|
-
(err) => {
|
|
1569
|
-
assert.ok(err instanceof CliError);
|
|
1570
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1571
|
-
return true;
|
|
1572
|
-
}
|
|
1573
|
-
);
|
|
1574
|
-
});
|
|
1575
|
-
|
|
1576
|
-
test("groups.create schema requires non-empty memberIds when provided", () => {
|
|
1577
|
-
assert.doesNotThrow(() =>
|
|
1578
|
-
validateToolArgs("groups.create", {
|
|
1579
|
-
name: "Engineering",
|
|
1580
|
-
memberIds: ["user-1"],
|
|
1581
|
-
performAction: true,
|
|
1582
|
-
})
|
|
1583
|
-
);
|
|
1584
|
-
|
|
1585
|
-
assert.throws(
|
|
1586
|
-
() =>
|
|
1587
|
-
validateToolArgs("groups.create", {
|
|
1588
|
-
name: "Engineering",
|
|
1589
|
-
memberIds: [],
|
|
1590
|
-
performAction: true,
|
|
1591
|
-
}),
|
|
1592
|
-
(err) => {
|
|
1593
|
-
assert.ok(err instanceof CliError);
|
|
1594
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.memberIds"));
|
|
1595
|
-
return true;
|
|
1596
|
-
}
|
|
1597
|
-
);
|
|
1598
|
-
});
|
|
1599
|
-
|
|
1600
|
-
test("shares lifecycle schemas enforce deterministic selectors and update requirements", () => {
|
|
1601
|
-
assert.doesNotThrow(() =>
|
|
1602
|
-
validateToolArgs("shares.list", {
|
|
1603
|
-
query: "help docs",
|
|
1604
|
-
limit: 10,
|
|
1605
|
-
offset: 0,
|
|
1606
|
-
sort: "updatedAt",
|
|
1607
|
-
direction: "DESC",
|
|
1608
|
-
view: "summary",
|
|
1609
|
-
})
|
|
1610
|
-
);
|
|
1611
|
-
assert.doesNotThrow(() => validateToolArgs("shares.info", { id: "share-1" }));
|
|
1612
|
-
assert.doesNotThrow(() => validateToolArgs("shares.info", { documentId: "doc-1" }));
|
|
1613
|
-
assert.doesNotThrow(() =>
|
|
1614
|
-
validateToolArgs("shares.create", {
|
|
1615
|
-
documentId: "doc-1",
|
|
1616
|
-
published: true,
|
|
1617
|
-
performAction: true,
|
|
1618
|
-
})
|
|
1619
|
-
);
|
|
1620
|
-
assert.doesNotThrow(() =>
|
|
1621
|
-
validateToolArgs("shares.update", {
|
|
1622
|
-
id: "share-1",
|
|
1623
|
-
published: false,
|
|
1624
|
-
performAction: true,
|
|
1625
|
-
})
|
|
1626
|
-
);
|
|
1627
|
-
assert.doesNotThrow(() => validateToolArgs("shares.revoke", { id: "share-1", performAction: true }));
|
|
1628
|
-
|
|
1629
|
-
assert.throws(
|
|
1630
|
-
() => validateToolArgs("shares.list", { limit: 0 }),
|
|
1631
|
-
(err) => {
|
|
1632
|
-
assert.ok(err instanceof CliError);
|
|
1633
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.limit"));
|
|
1634
|
-
return true;
|
|
1635
|
-
}
|
|
1636
|
-
);
|
|
1637
|
-
|
|
1638
|
-
assert.throws(
|
|
1639
|
-
() => validateToolArgs("shares.info", {}),
|
|
1640
|
-
(err) => {
|
|
1641
|
-
assert.ok(err instanceof CliError);
|
|
1642
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1643
|
-
return true;
|
|
1644
|
-
}
|
|
1645
|
-
);
|
|
1646
|
-
|
|
1647
|
-
assert.throws(
|
|
1648
|
-
() => validateToolArgs("shares.info", { id: "share-1", documentId: "doc-1" }),
|
|
1649
|
-
(err) => {
|
|
1650
|
-
assert.ok(err instanceof CliError);
|
|
1651
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.documentId"));
|
|
1652
|
-
return true;
|
|
1653
|
-
}
|
|
1654
|
-
);
|
|
1655
|
-
|
|
1656
|
-
assert.throws(
|
|
1657
|
-
() => validateToolArgs("shares.create", {}),
|
|
1658
|
-
(err) => {
|
|
1659
|
-
assert.ok(err instanceof CliError);
|
|
1660
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.documentId"));
|
|
1661
|
-
return true;
|
|
1662
|
-
}
|
|
1663
|
-
);
|
|
1664
|
-
|
|
1665
|
-
assert.throws(
|
|
1666
|
-
() => validateToolArgs("shares.update", { id: "share-1" }),
|
|
1667
|
-
(err) => {
|
|
1668
|
-
assert.ok(err instanceof CliError);
|
|
1669
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.published"));
|
|
1670
|
-
return true;
|
|
1671
|
-
}
|
|
1672
|
-
);
|
|
1673
|
-
|
|
1674
|
-
assert.equal(
|
|
1675
|
-
validateToolArgs("shares.update", { id: "share-1", published: "true" }).published,
|
|
1676
|
-
true
|
|
1677
|
-
);
|
|
1678
|
-
|
|
1679
|
-
assert.throws(
|
|
1680
|
-
() => validateToolArgs("shares.update", { id: "share-1", published: "yes" }),
|
|
1681
|
-
(err) => {
|
|
1682
|
-
assert.ok(err instanceof CliError);
|
|
1683
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.published"));
|
|
1684
|
-
return true;
|
|
1685
|
-
}
|
|
1686
|
-
);
|
|
1687
|
-
|
|
1688
|
-
assert.throws(
|
|
1689
|
-
() => validateToolArgs("shares.revoke", { performAction: true }),
|
|
1690
|
-
(err) => {
|
|
1691
|
-
assert.ok(err instanceof CliError);
|
|
1692
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
1693
|
-
return true;
|
|
1694
|
-
}
|
|
1695
|
-
);
|
|
1696
|
-
|
|
1697
|
-
assert.throws(
|
|
1698
|
-
() => validateToolArgs("shares.revoke", { id: "share-1", performAction: "yes" }),
|
|
1699
|
-
(err) => {
|
|
1700
|
-
assert.ok(err instanceof CliError);
|
|
1701
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.performAction"));
|
|
1702
|
-
return true;
|
|
1703
|
-
}
|
|
1704
|
-
);
|
|
1705
|
-
});
|
|
1706
|
-
|
|
1707
|
-
test("documents.apply_patch accepts optional expectedRevision and validates bounds", () => {
|
|
1708
|
-
assert.doesNotThrow(() =>
|
|
1709
|
-
validateToolArgs("documents.apply_patch", {
|
|
1710
|
-
id: "doc-1",
|
|
1711
|
-
patch: "@@ -1,1 +1,1 @@\n-a\n+b",
|
|
1712
|
-
expectedRevision: 3,
|
|
1713
|
-
})
|
|
1714
|
-
);
|
|
1715
|
-
|
|
1716
|
-
assert.throws(
|
|
1717
|
-
() =>
|
|
1718
|
-
validateToolArgs("documents.apply_patch", {
|
|
1719
|
-
id: "doc-1",
|
|
1720
|
-
patch: "@@ -1,1 +1,1 @@\n-a\n+b",
|
|
1721
|
-
expectedRevision: -1,
|
|
1722
|
-
}),
|
|
1723
|
-
(err) => {
|
|
1724
|
-
assert.ok(err instanceof CliError);
|
|
1725
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.expectedRevision"));
|
|
1726
|
-
return true;
|
|
1727
|
-
}
|
|
1728
|
-
);
|
|
1729
|
-
});
|
|
1730
|
-
|
|
1731
|
-
test("documents.apply_patch_safe requires expectedRevision and validates bounds", () => {
|
|
1732
|
-
assert.doesNotThrow(() =>
|
|
1733
|
-
validateToolArgs("documents.apply_patch_safe", {
|
|
1734
|
-
id: "doc-1",
|
|
1735
|
-
patch: "@@ -1,1 +1,1 @@\n-a\n+b",
|
|
1736
|
-
expectedRevision: 3,
|
|
1737
|
-
})
|
|
1738
|
-
);
|
|
1739
|
-
|
|
1740
|
-
assert.throws(
|
|
1741
|
-
() =>
|
|
1742
|
-
validateToolArgs("documents.apply_patch_safe", {
|
|
1743
|
-
id: "doc-1",
|
|
1744
|
-
patch: "@@ -1,1 +1,1 @@\n-a\n+b",
|
|
1745
|
-
}),
|
|
1746
|
-
(err) => {
|
|
1747
|
-
assert.ok(err instanceof CliError);
|
|
1748
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.expectedRevision"));
|
|
1749
|
-
return true;
|
|
1750
|
-
}
|
|
1751
|
-
);
|
|
1752
|
-
|
|
1753
|
-
assert.throws(
|
|
1754
|
-
() =>
|
|
1755
|
-
validateToolArgs("documents.apply_patch_safe", {
|
|
1756
|
-
id: "doc-1",
|
|
1757
|
-
patch: "@@ -1,1 +1,1 @@\n-a\n+b",
|
|
1758
|
-
expectedRevision: -1,
|
|
1759
|
-
}),
|
|
1760
|
-
(err) => {
|
|
1761
|
-
assert.ok(err instanceof CliError);
|
|
1762
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.expectedRevision"));
|
|
1763
|
-
return true;
|
|
1764
|
-
}
|
|
1765
|
-
);
|
|
1766
|
-
});
|
|
1767
|
-
|
|
1768
|
-
test("documents.apply_patch_safe handler enforces gate and required expectedRevision", async () => {
|
|
1769
|
-
const contract = MUTATION_TOOLS["documents.apply_patch_safe"];
|
|
1770
|
-
assert.ok(contract);
|
|
1771
|
-
assert.equal(typeof contract.handler, "function");
|
|
1772
|
-
assert.equal(contract.usageExample?.tool, "documents.apply_patch_safe");
|
|
1773
|
-
|
|
1774
|
-
const calls = [];
|
|
1775
|
-
const ctx = {
|
|
1776
|
-
profile: { id: "profile-hardening" },
|
|
1777
|
-
client: {
|
|
1778
|
-
async call(method, body, options) {
|
|
1779
|
-
calls.push({ method, body, options });
|
|
1780
|
-
return { body: { data: { id: body.id, text: "Old", revision: 7 } } };
|
|
1781
|
-
},
|
|
1782
|
-
},
|
|
1783
|
-
};
|
|
1784
|
-
|
|
1785
|
-
await assert.rejects(
|
|
1786
|
-
() =>
|
|
1787
|
-
contract.handler(ctx, {
|
|
1788
|
-
id: "doc-1",
|
|
1789
|
-
expectedRevision: 7,
|
|
1790
|
-
patch: "@@ -1,1 +1,1 @@\n-Old\n+New",
|
|
1791
|
-
}),
|
|
1792
|
-
(err) => {
|
|
1793
|
-
assert.ok(err instanceof CliError);
|
|
1794
|
-
assert.match(err.message, /performAction/);
|
|
1795
|
-
return true;
|
|
1796
|
-
}
|
|
1797
|
-
);
|
|
1798
|
-
|
|
1799
|
-
await assert.rejects(
|
|
1800
|
-
() =>
|
|
1801
|
-
contract.handler(ctx, {
|
|
1802
|
-
id: "doc-1",
|
|
1803
|
-
patch: "@@ -1,1 +1,1 @@\n-Old\n+New",
|
|
1804
|
-
performAction: true,
|
|
1805
|
-
}),
|
|
1806
|
-
(err) => {
|
|
1807
|
-
assert.ok(err instanceof CliError);
|
|
1808
|
-
assert.equal(err.message, "documents.apply_patch_safe requires args.expectedRevision");
|
|
1809
|
-
return true;
|
|
1810
|
-
}
|
|
1811
|
-
);
|
|
1812
|
-
|
|
1813
|
-
assert.equal(calls.length, 0);
|
|
1814
|
-
});
|
|
1815
|
-
|
|
1816
|
-
test("documents.apply_patch_safe delegates to apply_patch flow with deterministic envelope", async () => {
|
|
1817
|
-
const contract = MUTATION_TOOLS["documents.apply_patch_safe"];
|
|
1818
|
-
assert.ok(contract);
|
|
1819
|
-
|
|
1820
|
-
const conflictCalls = [];
|
|
1821
|
-
const conflictCtx = {
|
|
1822
|
-
profile: { id: "profile-hardening" },
|
|
1823
|
-
client: {
|
|
1824
|
-
async call(method, body, options) {
|
|
1825
|
-
conflictCalls.push({ method, body, options });
|
|
1826
|
-
if (method !== "documents.info") {
|
|
1827
|
-
throw new Error(`unexpected method: ${method}`);
|
|
1828
|
-
}
|
|
1829
|
-
return {
|
|
1830
|
-
body: {
|
|
1831
|
-
data: {
|
|
1832
|
-
id: "doc-1",
|
|
1833
|
-
text: "Old",
|
|
1834
|
-
revision: 8,
|
|
1835
|
-
},
|
|
1836
|
-
},
|
|
1837
|
-
};
|
|
1838
|
-
},
|
|
1839
|
-
},
|
|
1840
|
-
};
|
|
1841
|
-
|
|
1842
|
-
const conflictOutput = await contract.handler(conflictCtx, {
|
|
1843
|
-
id: "doc-1",
|
|
1844
|
-
expectedRevision: 7,
|
|
1845
|
-
patch: "@@ -1,1 +1,1 @@\n-Old\n+New",
|
|
1846
|
-
performAction: true,
|
|
1847
|
-
});
|
|
1848
|
-
|
|
1849
|
-
assert.deepEqual(conflictCalls, [
|
|
1850
|
-
{
|
|
1851
|
-
method: "documents.info",
|
|
1852
|
-
body: { id: "doc-1" },
|
|
1853
|
-
options: { maxAttempts: 2 },
|
|
1854
|
-
},
|
|
1855
|
-
]);
|
|
1856
|
-
assert.deepEqual(conflictOutput, {
|
|
1857
|
-
tool: "documents.apply_patch_safe",
|
|
1858
|
-
profile: "profile-hardening",
|
|
1859
|
-
result: {
|
|
1860
|
-
ok: false,
|
|
1861
|
-
code: "revision_conflict",
|
|
1862
|
-
message: "Document revision changed since last read",
|
|
1863
|
-
id: "doc-1",
|
|
1864
|
-
expectedRevision: 7,
|
|
1865
|
-
actualRevision: 8,
|
|
1866
|
-
updated: false,
|
|
1867
|
-
mode: "unified",
|
|
1868
|
-
previousRevision: 8,
|
|
1869
|
-
},
|
|
1870
|
-
});
|
|
1871
|
-
|
|
1872
|
-
const successCalls = [];
|
|
1873
|
-
const successCtx = {
|
|
1874
|
-
profile: { id: "profile-hardening" },
|
|
1875
|
-
client: {
|
|
1876
|
-
async call(method, body, options) {
|
|
1877
|
-
successCalls.push({ method, body, options });
|
|
1878
|
-
if (method === "documents.info") {
|
|
1879
|
-
return {
|
|
1880
|
-
body: {
|
|
1881
|
-
data: {
|
|
1882
|
-
id: "doc-1",
|
|
1883
|
-
text: "Old",
|
|
1884
|
-
revision: 8,
|
|
1885
|
-
},
|
|
1886
|
-
},
|
|
1887
|
-
};
|
|
1888
|
-
}
|
|
1889
|
-
if (method === "documents.update") {
|
|
1890
|
-
return {
|
|
1891
|
-
body: {
|
|
1892
|
-
data: {
|
|
1893
|
-
id: "doc-1",
|
|
1894
|
-
title: "Runbook",
|
|
1895
|
-
collectionId: "col-1",
|
|
1896
|
-
parentDocumentId: null,
|
|
1897
|
-
revision: 9,
|
|
1898
|
-
updatedAt: "2026-03-05T00:00:00.000Z",
|
|
1899
|
-
publishedAt: null,
|
|
1900
|
-
urlId: "runbook",
|
|
1901
|
-
emoji: "book",
|
|
1902
|
-
text: "New",
|
|
1903
|
-
},
|
|
1904
|
-
},
|
|
1905
|
-
};
|
|
1906
|
-
}
|
|
1907
|
-
throw new Error(`unexpected method: ${method}`);
|
|
1908
|
-
},
|
|
1909
|
-
},
|
|
1910
|
-
};
|
|
1911
|
-
|
|
1912
|
-
const successOutput = await contract.handler(successCtx, {
|
|
1913
|
-
id: "doc-1",
|
|
1914
|
-
expectedRevision: 8,
|
|
1915
|
-
patch: "@@ -1,1 +1,1 @@\n-Old\n+New",
|
|
1916
|
-
performAction: true,
|
|
1917
|
-
view: "summary",
|
|
1918
|
-
});
|
|
1919
|
-
|
|
1920
|
-
assert.deepEqual(successCalls, [
|
|
1921
|
-
{
|
|
1922
|
-
method: "documents.info",
|
|
1923
|
-
body: { id: "doc-1" },
|
|
1924
|
-
options: { maxAttempts: 2 },
|
|
1925
|
-
},
|
|
1926
|
-
{
|
|
1927
|
-
method: "documents.update",
|
|
1928
|
-
body: { id: "doc-1", text: "New", editMode: "replace" },
|
|
1929
|
-
options: { maxAttempts: 1 },
|
|
1930
|
-
},
|
|
1931
|
-
]);
|
|
1932
|
-
|
|
1933
|
-
assert.deepEqual(successOutput, {
|
|
1934
|
-
tool: "documents.apply_patch_safe",
|
|
1935
|
-
profile: "profile-hardening",
|
|
1936
|
-
result: {
|
|
1937
|
-
ok: true,
|
|
1938
|
-
updated: true,
|
|
1939
|
-
id: "doc-1",
|
|
1940
|
-
mode: "unified",
|
|
1941
|
-
previousRevision: 8,
|
|
1942
|
-
currentRevision: 9,
|
|
1943
|
-
data: {
|
|
1944
|
-
id: "doc-1",
|
|
1945
|
-
title: "Runbook",
|
|
1946
|
-
collectionId: "col-1",
|
|
1947
|
-
parentDocumentId: null,
|
|
1948
|
-
revision: 9,
|
|
1949
|
-
updatedAt: "2026-03-05T00:00:00.000Z",
|
|
1950
|
-
publishedAt: null,
|
|
1951
|
-
urlId: "runbook",
|
|
1952
|
-
emoji: "book",
|
|
1953
|
-
excerpt: "New",
|
|
1954
|
-
},
|
|
1955
|
-
},
|
|
1956
|
-
});
|
|
1957
|
-
});
|
|
1958
|
-
|
|
1959
|
-
test("revisions.diff is exposed as a first-class mutation wrapper with deterministic payload", async () => {
|
|
1960
|
-
const contract = MUTATION_TOOLS["revisions.diff"];
|
|
1961
|
-
assert.ok(contract);
|
|
1962
|
-
assert.equal(typeof contract.handler, "function");
|
|
1963
|
-
assert.equal(contract.usageExample?.tool, "revisions.diff");
|
|
1964
|
-
|
|
1965
|
-
const calls = [];
|
|
1966
|
-
const revisionsById = {
|
|
1967
|
-
"rev-base": {
|
|
1968
|
-
id: "rev-base",
|
|
1969
|
-
documentId: "doc-1",
|
|
1970
|
-
title: "Incident RCA",
|
|
1971
|
-
text: "alpha\nbravo\ncharlie",
|
|
1972
|
-
createdAt: "2026-03-01T00:00:00.000Z",
|
|
1973
|
-
createdBy: { id: "user-1", name: "Alice" },
|
|
1974
|
-
},
|
|
1975
|
-
"rev-target": {
|
|
1976
|
-
id: "rev-target",
|
|
1977
|
-
documentId: "doc-1",
|
|
1978
|
-
title: "Incident RCA",
|
|
1979
|
-
text: "alpha\nbeta\ncharlie\ndelta",
|
|
1980
|
-
createdAt: "2026-03-02T00:00:00.000Z",
|
|
1981
|
-
createdBy: { id: "user-2", name: "Bob" },
|
|
1982
|
-
},
|
|
1983
|
-
};
|
|
1984
|
-
|
|
1985
|
-
const ctx = {
|
|
1986
|
-
profile: { id: "profile-hardening" },
|
|
1987
|
-
client: {
|
|
1988
|
-
async call(method, body, options) {
|
|
1989
|
-
calls.push({ method, body, options });
|
|
1990
|
-
assert.equal(method, "revisions.info");
|
|
1991
|
-
return {
|
|
1992
|
-
body: {
|
|
1993
|
-
data: revisionsById[body.id],
|
|
1994
|
-
},
|
|
1995
|
-
};
|
|
1996
|
-
},
|
|
1997
|
-
},
|
|
1998
|
-
};
|
|
1999
|
-
|
|
2000
|
-
const output = await contract.handler(ctx, {
|
|
2001
|
-
id: "doc-1",
|
|
2002
|
-
baseRevisionId: "rev-base",
|
|
2003
|
-
targetRevisionId: "rev-target",
|
|
2004
|
-
hunkLimit: 6,
|
|
2005
|
-
hunkLineLimit: 8,
|
|
2006
|
-
view: "summary",
|
|
2007
|
-
});
|
|
2008
|
-
|
|
2009
|
-
assert.deepEqual(calls, [
|
|
2010
|
-
{
|
|
2011
|
-
method: "revisions.info",
|
|
2012
|
-
body: { id: "rev-base" },
|
|
2013
|
-
options: { maxAttempts: 2 },
|
|
2014
|
-
},
|
|
2015
|
-
{
|
|
2016
|
-
method: "revisions.info",
|
|
2017
|
-
body: { id: "rev-target" },
|
|
2018
|
-
options: { maxAttempts: 2 },
|
|
2019
|
-
},
|
|
2020
|
-
]);
|
|
2021
|
-
|
|
2022
|
-
assert.equal(output.tool, "revisions.diff");
|
|
2023
|
-
assert.equal(output.profile, "profile-hardening");
|
|
2024
|
-
assert.deepEqual(output.result, {
|
|
2025
|
-
ok: true,
|
|
2026
|
-
id: "doc-1",
|
|
2027
|
-
baseRevisionId: "rev-base",
|
|
2028
|
-
targetRevisionId: "rev-target",
|
|
2029
|
-
baseRevision: {
|
|
2030
|
-
id: "rev-base",
|
|
2031
|
-
documentId: "doc-1",
|
|
2032
|
-
title: "Incident RCA",
|
|
2033
|
-
createdAt: "2026-03-01T00:00:00.000Z",
|
|
2034
|
-
createdBy: { id: "user-1", name: "Alice" },
|
|
2035
|
-
},
|
|
2036
|
-
targetRevision: {
|
|
2037
|
-
id: "rev-target",
|
|
2038
|
-
documentId: "doc-1",
|
|
2039
|
-
title: "Incident RCA",
|
|
2040
|
-
createdAt: "2026-03-02T00:00:00.000Z",
|
|
2041
|
-
createdBy: { id: "user-2", name: "Bob" },
|
|
2042
|
-
},
|
|
2043
|
-
stats: {
|
|
2044
|
-
added: 2,
|
|
2045
|
-
removed: 1,
|
|
2046
|
-
changed: 1,
|
|
2047
|
-
unchanged: 2,
|
|
2048
|
-
totalCurrentLines: 3,
|
|
2049
|
-
totalProposedLines: 4,
|
|
2050
|
-
},
|
|
2051
|
-
hunks: [
|
|
2052
|
-
{
|
|
2053
|
-
kind: "change",
|
|
2054
|
-
oldStart: 2,
|
|
2055
|
-
newStart: 2,
|
|
2056
|
-
lines: [
|
|
2057
|
-
{ type: "remove", line: "bravo" },
|
|
2058
|
-
{ type: "add", line: "beta" },
|
|
2059
|
-
],
|
|
2060
|
-
truncated: false,
|
|
2061
|
-
},
|
|
2062
|
-
{
|
|
2063
|
-
kind: "add",
|
|
2064
|
-
oldStart: 4,
|
|
2065
|
-
newStart: 4,
|
|
2066
|
-
lines: [{ type: "add", line: "delta" }],
|
|
2067
|
-
truncated: false,
|
|
2068
|
-
},
|
|
2069
|
-
],
|
|
2070
|
-
truncated: true,
|
|
2071
|
-
});
|
|
2072
|
-
});
|
|
2073
|
-
|
|
2074
|
-
test("revisions.diff schema validates valid and invalid inputs with deterministic issues", () => {
|
|
2075
|
-
assert.doesNotThrow(() =>
|
|
2076
|
-
validateToolArgs("revisions.diff", {
|
|
2077
|
-
id: "doc-1",
|
|
2078
|
-
baseRevisionId: "rev-1",
|
|
2079
|
-
targetRevisionId: "rev-2",
|
|
2080
|
-
includeFullHunks: false,
|
|
2081
|
-
hunkLimit: 8,
|
|
2082
|
-
hunkLineLimit: 12,
|
|
2083
|
-
view: "summary",
|
|
2084
|
-
maxAttempts: 2,
|
|
2085
|
-
})
|
|
2086
|
-
);
|
|
2087
|
-
|
|
2088
|
-
assert.throws(
|
|
2089
|
-
() => validateToolArgs("revisions.diff", {}),
|
|
2090
|
-
(err) => {
|
|
2091
|
-
assert.ok(err instanceof CliError);
|
|
2092
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
2093
|
-
assert.deepEqual(
|
|
2094
|
-
err.details?.issues?.map((issue) => issue.path),
|
|
2095
|
-
["args.id", "args.baseRevisionId", "args.targetRevisionId"]
|
|
2096
|
-
);
|
|
2097
|
-
return true;
|
|
2098
|
-
}
|
|
2099
|
-
);
|
|
2100
|
-
|
|
2101
|
-
assert.throws(
|
|
2102
|
-
() =>
|
|
2103
|
-
validateToolArgs("revisions.diff", {
|
|
2104
|
-
id: "doc-1",
|
|
2105
|
-
baseRevisionId: "rev-1",
|
|
2106
|
-
targetRevisionId: "rev-2",
|
|
2107
|
-
hunkLimit: 0,
|
|
2108
|
-
view: "ids",
|
|
2109
|
-
}),
|
|
2110
|
-
(err) => {
|
|
2111
|
-
assert.ok(err instanceof CliError);
|
|
2112
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
2113
|
-
assert.deepEqual(
|
|
2114
|
-
err.details?.issues?.map((issue) => issue.path),
|
|
2115
|
-
["args.hunkLimit", "args.view"]
|
|
2116
|
-
);
|
|
2117
|
-
return true;
|
|
2118
|
-
}
|
|
2119
|
-
);
|
|
2120
|
-
});
|
|
2121
|
-
|
|
2122
|
-
test("comments.review_queue schema enforces scope selector", () => {
|
|
2123
|
-
assert.doesNotThrow(() =>
|
|
2124
|
-
validateToolArgs("comments.review_queue", {
|
|
2125
|
-
documentIds: ["doc-1"],
|
|
2126
|
-
limitPerDocument: 3,
|
|
2127
|
-
view: "summary",
|
|
2128
|
-
})
|
|
2129
|
-
);
|
|
2130
|
-
|
|
2131
|
-
assert.doesNotThrow(() =>
|
|
2132
|
-
validateToolArgs("comments.review_queue", {
|
|
2133
|
-
collectionId: "col-1",
|
|
2134
|
-
includeReplies: true,
|
|
2135
|
-
})
|
|
2136
|
-
);
|
|
2137
|
-
|
|
2138
|
-
assert.throws(
|
|
2139
|
-
() => validateToolArgs("comments.review_queue", {}),
|
|
2140
|
-
(err) => {
|
|
2141
|
-
assert.ok(err instanceof CliError);
|
|
2142
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.documentIds"));
|
|
2143
|
-
return true;
|
|
2144
|
-
}
|
|
2145
|
-
);
|
|
2146
|
-
});
|
|
2147
|
-
|
|
2148
|
-
test("federated.sync_manifest schema validates timestamp and bounds", () => {
|
|
2149
|
-
assert.doesNotThrow(() =>
|
|
2150
|
-
validateToolArgs("federated.sync_manifest", {
|
|
2151
|
-
query: "policy",
|
|
2152
|
-
since: "2026-01-01T00:00:00.000Z",
|
|
2153
|
-
limit: 5,
|
|
2154
|
-
view: "summary",
|
|
2155
|
-
})
|
|
2156
|
-
);
|
|
2157
|
-
|
|
2158
|
-
assert.throws(
|
|
2159
|
-
() =>
|
|
2160
|
-
validateToolArgs("federated.sync_manifest", {
|
|
2161
|
-
since: "yesterday",
|
|
2162
|
-
}),
|
|
2163
|
-
(err) => {
|
|
2164
|
-
assert.ok(err instanceof CliError);
|
|
2165
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.since"));
|
|
2166
|
-
return true;
|
|
2167
|
-
}
|
|
2168
|
-
);
|
|
2169
|
-
});
|
|
2170
|
-
|
|
2171
|
-
test("federated.sync_probe schema requires ids or queries", () => {
|
|
2172
|
-
assert.doesNotThrow(() =>
|
|
2173
|
-
validateToolArgs("federated.sync_probe", {
|
|
2174
|
-
ids: ["doc-1"],
|
|
2175
|
-
mode: "both",
|
|
2176
|
-
freshnessHours: 6,
|
|
2177
|
-
view: "summary",
|
|
2178
|
-
})
|
|
2179
|
-
);
|
|
2180
|
-
|
|
2181
|
-
assert.throws(
|
|
2182
|
-
() => validateToolArgs("federated.sync_probe", {}),
|
|
2183
|
-
(err) => {
|
|
2184
|
-
assert.ok(err instanceof CliError);
|
|
2185
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
2186
|
-
return true;
|
|
2187
|
-
}
|
|
2188
|
-
);
|
|
2189
|
-
});
|
|
2190
|
-
|
|
2191
|
-
test("federated.permission_snapshot schema requires non-empty ids", () => {
|
|
2192
|
-
assert.doesNotThrow(() =>
|
|
2193
|
-
validateToolArgs("federated.permission_snapshot", {
|
|
2194
|
-
ids: ["doc-1", "doc-2"],
|
|
2195
|
-
includeDocumentMemberships: true,
|
|
2196
|
-
view: "summary",
|
|
2197
|
-
})
|
|
2198
|
-
);
|
|
2199
|
-
|
|
2200
|
-
assert.throws(
|
|
2201
|
-
() => validateToolArgs("federated.permission_snapshot", { ids: [] }),
|
|
2202
|
-
(err) => {
|
|
2203
|
-
assert.ok(err instanceof CliError);
|
|
2204
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
2205
|
-
return true;
|
|
2206
|
-
}
|
|
2207
|
-
);
|
|
2208
|
-
});
|
|
2209
|
-
|
|
2210
|
-
test("documents.plan_terminology_refactor schema validates glossary and scope", () => {
|
|
2211
|
-
assert.doesNotThrow(() =>
|
|
2212
|
-
validateToolArgs("documents.plan_terminology_refactor", {
|
|
2213
|
-
glossary: [
|
|
2214
|
-
{
|
|
2215
|
-
find: "KPI",
|
|
2216
|
-
replace: "Key Performance Indicator",
|
|
2217
|
-
field: "text",
|
|
2218
|
-
},
|
|
2219
|
-
],
|
|
2220
|
-
query: "metrics",
|
|
2221
|
-
includeTitleSearch: true,
|
|
2222
|
-
includeSemanticSearch: true,
|
|
2223
|
-
})
|
|
2224
|
-
);
|
|
2225
|
-
|
|
2226
|
-
assert.throws(
|
|
2227
|
-
() =>
|
|
2228
|
-
validateToolArgs("documents.plan_terminology_refactor", {
|
|
2229
|
-
glossary: [{ find: "SLA", replace: "SLA" }],
|
|
2230
|
-
query: "ops",
|
|
2231
|
-
}),
|
|
2232
|
-
(err) => {
|
|
2233
|
-
assert.ok(err instanceof CliError);
|
|
2234
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.glossary[0].replace"));
|
|
2235
|
-
return true;
|
|
2236
|
-
}
|
|
2237
|
-
);
|
|
2238
|
-
|
|
2239
|
-
assert.throws(
|
|
2240
|
-
() =>
|
|
2241
|
-
validateToolArgs("documents.plan_terminology_refactor", {
|
|
2242
|
-
glossary: [{ find: "SLO", replace: "Service Level Objective" }],
|
|
2243
|
-
}),
|
|
2244
|
-
(err) => {
|
|
2245
|
-
assert.ok(err instanceof CliError);
|
|
2246
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
2247
|
-
return true;
|
|
2248
|
-
}
|
|
2249
|
-
);
|
|
2250
|
-
});
|
|
2251
|
-
|
|
2252
|
-
test("documents.answer and documents.answer_batch schema match handler inputs", () => {
|
|
2253
|
-
assert.doesNotThrow(() =>
|
|
2254
|
-
validateToolArgs("documents.answer", {
|
|
2255
|
-
query: "What changed this week?",
|
|
2256
|
-
})
|
|
2257
|
-
);
|
|
2258
|
-
|
|
2259
|
-
assert.throws(
|
|
2260
|
-
() => validateToolArgs("documents.answer", {}),
|
|
2261
|
-
(err) => {
|
|
2262
|
-
assert.ok(err instanceof CliError);
|
|
2263
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.question"));
|
|
2264
|
-
return true;
|
|
2265
|
-
}
|
|
2266
|
-
);
|
|
2267
|
-
|
|
2268
|
-
assert.doesNotThrow(() =>
|
|
2269
|
-
validateToolArgs("documents.answer_batch", {
|
|
2270
|
-
question: "Where is the runbook?",
|
|
2271
|
-
questions: [{ query: "Who owns incident response?" }],
|
|
2272
|
-
concurrency: 1,
|
|
2273
|
-
})
|
|
2274
|
-
);
|
|
2275
|
-
|
|
2276
|
-
assert.throws(
|
|
2277
|
-
() =>
|
|
2278
|
-
validateToolArgs("documents.answer_batch", {
|
|
2279
|
-
questions: [{}],
|
|
2280
|
-
}),
|
|
2281
|
-
(err) => {
|
|
2282
|
-
assert.ok(err instanceof CliError);
|
|
2283
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.questions[0].question"));
|
|
2284
|
-
return true;
|
|
2285
|
-
}
|
|
2286
|
-
);
|
|
2287
|
-
});
|
|
2288
|
-
|
|
2289
|
-
test("graph schemas enforce selector constraints and strict bounds", () => {
|
|
2290
|
-
assert.doesNotThrow(() =>
|
|
2291
|
-
validateToolArgs("documents.backlinks", {
|
|
2292
|
-
id: "doc-1",
|
|
2293
|
-
limit: 25,
|
|
2294
|
-
offset: 0,
|
|
2295
|
-
direction: "DESC",
|
|
2296
|
-
view: "summary",
|
|
2297
|
-
maxAttempts: 2,
|
|
2298
|
-
})
|
|
2299
|
-
);
|
|
2300
|
-
|
|
2301
|
-
assert.doesNotThrow(() =>
|
|
2302
|
-
validateToolArgs("documents.graph_neighbors", {
|
|
2303
|
-
id: "doc-1",
|
|
2304
|
-
includeBacklinks: true,
|
|
2305
|
-
includeSearchNeighbors: true,
|
|
2306
|
-
searchQueries: ["incident response"],
|
|
2307
|
-
limitPerSource: 10,
|
|
2308
|
-
view: "ids",
|
|
2309
|
-
})
|
|
2310
|
-
);
|
|
2311
|
-
|
|
2312
|
-
assert.doesNotThrow(() =>
|
|
2313
|
-
validateToolArgs("documents.graph_report", {
|
|
2314
|
-
seedIds: ["doc-1", "doc-2"],
|
|
2315
|
-
depth: 2,
|
|
2316
|
-
maxNodes: 50,
|
|
2317
|
-
includeBacklinks: true,
|
|
2318
|
-
includeSearchNeighbors: false,
|
|
2319
|
-
limitPerSource: 6,
|
|
2320
|
-
view: "summary",
|
|
2321
|
-
})
|
|
2322
|
-
);
|
|
2323
|
-
|
|
2324
|
-
assert.throws(
|
|
2325
|
-
() => validateToolArgs("documents.backlinks", { id: "", limit: 251 }),
|
|
2326
|
-
(err) => {
|
|
2327
|
-
assert.ok(err instanceof CliError);
|
|
2328
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
2329
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.limit"));
|
|
2330
|
-
return true;
|
|
2331
|
-
}
|
|
2332
|
-
);
|
|
2333
|
-
|
|
2334
|
-
assert.throws(
|
|
2335
|
-
() => validateToolArgs("documents.graph_neighbors", {}),
|
|
2336
|
-
(err) => {
|
|
2337
|
-
assert.ok(err instanceof CliError);
|
|
2338
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
2339
|
-
return true;
|
|
2340
|
-
}
|
|
2341
|
-
);
|
|
2342
|
-
|
|
2343
|
-
assert.throws(
|
|
2344
|
-
() =>
|
|
2345
|
-
validateToolArgs("documents.graph_neighbors", {
|
|
2346
|
-
id: "doc-1",
|
|
2347
|
-
ids: ["doc-2"],
|
|
2348
|
-
}),
|
|
2349
|
-
(err) => {
|
|
2350
|
-
assert.ok(err instanceof CliError);
|
|
2351
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids"));
|
|
2352
|
-
return true;
|
|
2353
|
-
}
|
|
2354
|
-
);
|
|
2355
|
-
|
|
2356
|
-
assert.throws(
|
|
2357
|
-
() =>
|
|
2358
|
-
validateToolArgs("documents.graph_neighbors", {
|
|
2359
|
-
id: "doc-1",
|
|
2360
|
-
includeBacklinks: false,
|
|
2361
|
-
includeSearchNeighbors: false,
|
|
2362
|
-
}),
|
|
2363
|
-
(err) => {
|
|
2364
|
-
assert.ok(err instanceof CliError);
|
|
2365
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.includeBacklinks"));
|
|
2366
|
-
return true;
|
|
2367
|
-
}
|
|
2368
|
-
);
|
|
2369
|
-
|
|
2370
|
-
assert.throws(
|
|
2371
|
-
() =>
|
|
2372
|
-
validateToolArgs("documents.graph_neighbors", {
|
|
2373
|
-
id: "doc-1",
|
|
2374
|
-
includeSearchNeighbors: false,
|
|
2375
|
-
searchQueries: ["incident response"],
|
|
2376
|
-
}),
|
|
2377
|
-
(err) => {
|
|
2378
|
-
assert.ok(err instanceof CliError);
|
|
2379
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.includeSearchNeighbors"));
|
|
2380
|
-
return true;
|
|
2381
|
-
}
|
|
2382
|
-
);
|
|
2383
|
-
|
|
2384
|
-
assert.throws(
|
|
2385
|
-
() =>
|
|
2386
|
-
validateToolArgs("documents.graph_report", {
|
|
2387
|
-
seedIds: [],
|
|
2388
|
-
}),
|
|
2389
|
-
(err) => {
|
|
2390
|
-
assert.ok(err instanceof CliError);
|
|
2391
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.seedIds"));
|
|
2392
|
-
return true;
|
|
2393
|
-
}
|
|
2394
|
-
);
|
|
2395
|
-
|
|
2396
|
-
assert.throws(
|
|
2397
|
-
() =>
|
|
2398
|
-
validateToolArgs("documents.graph_report", {
|
|
2399
|
-
seedIds: ["doc-1"],
|
|
2400
|
-
depth: 7,
|
|
2401
|
-
}),
|
|
2402
|
-
(err) => {
|
|
2403
|
-
assert.ok(err instanceof CliError);
|
|
2404
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.depth"));
|
|
2405
|
-
return true;
|
|
2406
|
-
}
|
|
2407
|
-
);
|
|
2408
|
-
});
|
|
2409
|
-
|
|
2410
|
-
test("issue reference schemas enforce selector, query, and regex constraints", () => {
|
|
2411
|
-
assert.doesNotThrow(() =>
|
|
2412
|
-
validateToolArgs("documents.issue_refs", {
|
|
2413
|
-
ids: ["doc-1", "doc-2"],
|
|
2414
|
-
issueDomains: ["jira.example.com"],
|
|
2415
|
-
keyPattern: "[A-Z]+-\\d+",
|
|
2416
|
-
view: "summary",
|
|
2417
|
-
maxAttempts: 2,
|
|
2418
|
-
})
|
|
2419
|
-
);
|
|
2420
|
-
|
|
2421
|
-
assert.doesNotThrow(() =>
|
|
2422
|
-
validateToolArgs("documents.issue_ref_report", {
|
|
2423
|
-
query: "incident runbook",
|
|
2424
|
-
collectionId: "collection-1",
|
|
2425
|
-
issueDomains: ["jira.example.com", "github.com"],
|
|
2426
|
-
keyPattern: "[A-Z]+-\\d+",
|
|
2427
|
-
limit: 10,
|
|
2428
|
-
view: "ids",
|
|
2429
|
-
maxAttempts: 2,
|
|
2430
|
-
})
|
|
2431
|
-
);
|
|
2432
|
-
|
|
2433
|
-
assert.throws(
|
|
2434
|
-
() => validateToolArgs("documents.issue_refs", {}),
|
|
2435
|
-
(err) => {
|
|
2436
|
-
assert.ok(err instanceof CliError);
|
|
2437
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.id"));
|
|
2438
|
-
return true;
|
|
2439
|
-
}
|
|
2440
|
-
);
|
|
2441
|
-
|
|
2442
|
-
assert.throws(
|
|
2443
|
-
() =>
|
|
2444
|
-
validateToolArgs("documents.issue_refs", {
|
|
2445
|
-
ids: [""],
|
|
2446
|
-
keyPattern: "[",
|
|
2447
|
-
}),
|
|
2448
|
-
(err) => {
|
|
2449
|
-
assert.ok(err instanceof CliError);
|
|
2450
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.ids[0]"));
|
|
2451
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.keyPattern"));
|
|
2452
|
-
return true;
|
|
2453
|
-
}
|
|
2454
|
-
);
|
|
2455
|
-
|
|
2456
|
-
assert.throws(
|
|
2457
|
-
() =>
|
|
2458
|
-
validateToolArgs("documents.issue_ref_report", {
|
|
2459
|
-
queries: [],
|
|
2460
|
-
limit: 101,
|
|
2461
|
-
}),
|
|
2462
|
-
(err) => {
|
|
2463
|
-
assert.ok(err instanceof CliError);
|
|
2464
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.query"));
|
|
2465
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.queries"));
|
|
2466
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.limit"));
|
|
2467
|
-
return true;
|
|
2468
|
-
}
|
|
2469
|
-
);
|
|
2470
|
-
});
|
|
2471
|
-
|
|
2472
|
-
test("documents.backlinks wraps documents.list with backlinkDocumentId", async () => {
|
|
2473
|
-
const contract = EXTENDED_TOOLS["documents.backlinks"];
|
|
2474
|
-
assert.ok(contract);
|
|
2475
|
-
assert.equal(typeof contract.handler, "function");
|
|
2476
|
-
|
|
2477
|
-
const calls = [];
|
|
2478
|
-
const ctx = {
|
|
2479
|
-
profile: { id: "profile-hardening" },
|
|
2480
|
-
client: {
|
|
2481
|
-
async call(method, body, options) {
|
|
2482
|
-
calls.push({ method, body, options });
|
|
2483
|
-
return {
|
|
2484
|
-
body: {
|
|
2485
|
-
data: [
|
|
2486
|
-
{
|
|
2487
|
-
id: "doc-2",
|
|
2488
|
-
title: "Backlink Source A",
|
|
2489
|
-
},
|
|
2490
|
-
{
|
|
2491
|
-
id: "doc-3",
|
|
2492
|
-
title: "Backlink Source B",
|
|
2493
|
-
},
|
|
2494
|
-
],
|
|
2495
|
-
policies: [{ id: "policy-1" }],
|
|
2496
|
-
},
|
|
2497
|
-
};
|
|
2498
|
-
},
|
|
2499
|
-
},
|
|
2500
|
-
};
|
|
2501
|
-
|
|
2502
|
-
const output = await contract.handler(ctx, {
|
|
2503
|
-
id: "doc-root",
|
|
2504
|
-
limit: 2,
|
|
2505
|
-
offset: 1,
|
|
2506
|
-
sort: "updatedAt",
|
|
2507
|
-
direction: "DESC",
|
|
2508
|
-
view: "ids",
|
|
2509
|
-
maxAttempts: 3,
|
|
2510
|
-
});
|
|
2511
|
-
|
|
2512
|
-
assert.deepEqual(calls, [
|
|
2513
|
-
{
|
|
2514
|
-
method: "documents.list",
|
|
2515
|
-
body: {
|
|
2516
|
-
backlinkDocumentId: "doc-root",
|
|
2517
|
-
limit: 2,
|
|
2518
|
-
offset: 1,
|
|
2519
|
-
sort: "updatedAt",
|
|
2520
|
-
direction: "DESC",
|
|
2521
|
-
},
|
|
2522
|
-
options: { maxAttempts: 3 },
|
|
2523
|
-
},
|
|
2524
|
-
]);
|
|
2525
|
-
assert.equal(output.tool, "documents.backlinks");
|
|
2526
|
-
assert.equal(output.profile, "profile-hardening");
|
|
2527
|
-
assert.deepEqual(output.result, {
|
|
2528
|
-
data: [
|
|
2529
|
-
{ id: "doc-2", title: "Backlink Source A" },
|
|
2530
|
-
{ id: "doc-3", title: "Backlink Source B" },
|
|
2531
|
-
],
|
|
2532
|
-
});
|
|
2533
|
-
});
|
|
2534
|
-
|
|
2535
|
-
test("documents.graph_neighbors returns deterministic nodes and edges", async () => {
|
|
2536
|
-
const contract = EXTENDED_TOOLS["documents.graph_neighbors"];
|
|
2537
|
-
assert.ok(contract);
|
|
2538
|
-
assert.equal(typeof contract.handler, "function");
|
|
2539
|
-
|
|
2540
|
-
const calls = [];
|
|
2541
|
-
const ctx = {
|
|
2542
|
-
profile: { id: "profile-hardening" },
|
|
2543
|
-
client: {
|
|
2544
|
-
async call(method, body, options) {
|
|
2545
|
-
calls.push({ method, body, options });
|
|
2546
|
-
if (method === "documents.info") {
|
|
2547
|
-
return {
|
|
2548
|
-
body: {
|
|
2549
|
-
data: {
|
|
2550
|
-
id: "doc-1",
|
|
2551
|
-
title: "Seed Document",
|
|
2552
|
-
},
|
|
2553
|
-
},
|
|
2554
|
-
};
|
|
2555
|
-
}
|
|
2556
|
-
if (method === "documents.list") {
|
|
2557
|
-
return {
|
|
2558
|
-
body: {
|
|
2559
|
-
data: [
|
|
2560
|
-
{
|
|
2561
|
-
id: "doc-2",
|
|
2562
|
-
title: "Runbook",
|
|
2563
|
-
collectionId: "col-1",
|
|
2564
|
-
parentDocumentId: "",
|
|
2565
|
-
updatedAt: "2026-03-01T00:00:00.000Z",
|
|
2566
|
-
publishedAt: "2026-03-01T00:00:00.000Z",
|
|
2567
|
-
urlId: "runbook",
|
|
2568
|
-
emoji: ":blue_book:",
|
|
2569
|
-
},
|
|
2570
|
-
{
|
|
2571
|
-
id: "doc-3",
|
|
2572
|
-
title: "Escalation Policy",
|
|
2573
|
-
collectionId: "col-1",
|
|
2574
|
-
parentDocumentId: "",
|
|
2575
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
2576
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
2577
|
-
urlId: "escalation-policy",
|
|
2578
|
-
emoji: ":green_book:",
|
|
2579
|
-
},
|
|
2580
|
-
],
|
|
2581
|
-
},
|
|
2582
|
-
};
|
|
2583
|
-
}
|
|
2584
|
-
if (method === "documents.search_titles") {
|
|
2585
|
-
return {
|
|
2586
|
-
body: {
|
|
2587
|
-
data: [
|
|
2588
|
-
{
|
|
2589
|
-
id: "doc-3",
|
|
2590
|
-
title: "Escalation Policy",
|
|
2591
|
-
ranking: 0.9,
|
|
2592
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
2593
|
-
},
|
|
2594
|
-
{
|
|
2595
|
-
id: "doc-4",
|
|
2596
|
-
title: "Incident Checklist",
|
|
2597
|
-
ranking: 0.7,
|
|
2598
|
-
collectionId: "col-2",
|
|
2599
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
2600
|
-
},
|
|
2601
|
-
],
|
|
2602
|
-
},
|
|
2603
|
-
};
|
|
2604
|
-
}
|
|
2605
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
2606
|
-
},
|
|
2607
|
-
},
|
|
2608
|
-
};
|
|
2609
|
-
|
|
2610
|
-
const output = await contract.handler(ctx, {
|
|
2611
|
-
id: "doc-1",
|
|
2612
|
-
includeBacklinks: true,
|
|
2613
|
-
includeSearchNeighbors: true,
|
|
2614
|
-
searchQueries: ["incident"],
|
|
2615
|
-
limitPerSource: 2,
|
|
2616
|
-
view: "summary",
|
|
2617
|
-
});
|
|
2618
|
-
|
|
2619
|
-
assert.deepEqual(
|
|
2620
|
-
calls.map((call) => call.method),
|
|
2621
|
-
["documents.info", "documents.list", "documents.search_titles"]
|
|
2622
|
-
);
|
|
2623
|
-
assert.deepEqual(calls[0], {
|
|
2624
|
-
method: "documents.info",
|
|
2625
|
-
body: { id: "doc-1" },
|
|
2626
|
-
options: { maxAttempts: 2 },
|
|
2627
|
-
});
|
|
2628
|
-
assert.deepEqual(calls[1], {
|
|
2629
|
-
method: "documents.list",
|
|
2630
|
-
body: {
|
|
2631
|
-
backlinkDocumentId: "doc-1",
|
|
2632
|
-
limit: 2,
|
|
2633
|
-
offset: 0,
|
|
2634
|
-
sort: "updatedAt",
|
|
2635
|
-
direction: "DESC",
|
|
2636
|
-
},
|
|
2637
|
-
options: { maxAttempts: 2 },
|
|
2638
|
-
});
|
|
2639
|
-
assert.deepEqual(calls[2], {
|
|
2640
|
-
method: "documents.search_titles",
|
|
2641
|
-
body: {
|
|
2642
|
-
query: "incident",
|
|
2643
|
-
limit: 2,
|
|
2644
|
-
offset: 0,
|
|
2645
|
-
},
|
|
2646
|
-
options: { maxAttempts: 2 },
|
|
2647
|
-
});
|
|
2648
|
-
|
|
2649
|
-
assert.equal(output.tool, "documents.graph_neighbors");
|
|
2650
|
-
assert.equal(output.profile, "profile-hardening");
|
|
2651
|
-
assert.deepEqual(output.result, {
|
|
2652
|
-
sourceIds: ["doc-1"],
|
|
2653
|
-
includeBacklinks: true,
|
|
2654
|
-
includeSearchNeighbors: true,
|
|
2655
|
-
searchQueries: ["incident"],
|
|
2656
|
-
limitPerSource: 2,
|
|
2657
|
-
nodeCount: 4,
|
|
2658
|
-
edgeCount: 4,
|
|
2659
|
-
nodes: [
|
|
2660
|
-
{
|
|
2661
|
-
id: "doc-1",
|
|
2662
|
-
title: "Seed Document",
|
|
2663
|
-
collectionId: "",
|
|
2664
|
-
parentDocumentId: "",
|
|
2665
|
-
updatedAt: "",
|
|
2666
|
-
publishedAt: "",
|
|
2667
|
-
urlId: "",
|
|
2668
|
-
emoji: "",
|
|
2669
|
-
},
|
|
2670
|
-
{
|
|
2671
|
-
id: "doc-2",
|
|
2672
|
-
title: "Runbook",
|
|
2673
|
-
collectionId: "col-1",
|
|
2674
|
-
parentDocumentId: "",
|
|
2675
|
-
updatedAt: "2026-03-01T00:00:00.000Z",
|
|
2676
|
-
publishedAt: "2026-03-01T00:00:00.000Z",
|
|
2677
|
-
urlId: "runbook",
|
|
2678
|
-
emoji: ":blue_book:",
|
|
2679
|
-
},
|
|
2680
|
-
{
|
|
2681
|
-
id: "doc-3",
|
|
2682
|
-
title: "Escalation Policy",
|
|
2683
|
-
collectionId: "col-1",
|
|
2684
|
-
parentDocumentId: "",
|
|
2685
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
2686
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
2687
|
-
urlId: "escalation-policy",
|
|
2688
|
-
emoji: ":green_book:",
|
|
2689
|
-
},
|
|
2690
|
-
{
|
|
2691
|
-
id: "doc-4",
|
|
2692
|
-
title: "Incident Checklist",
|
|
2693
|
-
collectionId: "col-2",
|
|
2694
|
-
parentDocumentId: "",
|
|
2695
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
2696
|
-
publishedAt: "",
|
|
2697
|
-
urlId: "",
|
|
2698
|
-
emoji: "",
|
|
2699
|
-
},
|
|
2700
|
-
],
|
|
2701
|
-
edges: [
|
|
2702
|
-
{
|
|
2703
|
-
sourceId: "doc-1",
|
|
2704
|
-
targetId: "doc-2",
|
|
2705
|
-
type: "backlink",
|
|
2706
|
-
query: "",
|
|
2707
|
-
rank: 1,
|
|
2708
|
-
},
|
|
2709
|
-
{
|
|
2710
|
-
sourceId: "doc-1",
|
|
2711
|
-
targetId: "doc-3",
|
|
2712
|
-
type: "backlink",
|
|
2713
|
-
query: "",
|
|
2714
|
-
rank: 2,
|
|
2715
|
-
},
|
|
2716
|
-
{
|
|
2717
|
-
sourceId: "doc-1",
|
|
2718
|
-
targetId: "doc-3",
|
|
2719
|
-
type: "search",
|
|
2720
|
-
query: "incident",
|
|
2721
|
-
rank: 1,
|
|
2722
|
-
},
|
|
2723
|
-
{
|
|
2724
|
-
sourceId: "doc-1",
|
|
2725
|
-
targetId: "doc-4",
|
|
2726
|
-
type: "search",
|
|
2727
|
-
query: "incident",
|
|
2728
|
-
rank: 2,
|
|
2729
|
-
},
|
|
2730
|
-
],
|
|
2731
|
-
errors: [],
|
|
2732
|
-
});
|
|
2733
|
-
});
|
|
2734
|
-
|
|
2735
|
-
test("documents.graph_report performs bounded BFS with stable output ordering", async () => {
|
|
2736
|
-
const contract = EXTENDED_TOOLS["documents.graph_report"];
|
|
2737
|
-
assert.ok(contract);
|
|
2738
|
-
assert.equal(typeof contract.handler, "function");
|
|
2739
|
-
|
|
2740
|
-
const calls = [];
|
|
2741
|
-
const ctx = {
|
|
2742
|
-
profile: { id: "profile-hardening" },
|
|
2743
|
-
client: {
|
|
2744
|
-
async call(method, body, options) {
|
|
2745
|
-
calls.push({ method, body, options });
|
|
2746
|
-
if (method !== "documents.list") {
|
|
2747
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
2748
|
-
}
|
|
2749
|
-
return {
|
|
2750
|
-
body: {
|
|
2751
|
-
data: [
|
|
2752
|
-
{ id: "doc-2", title: "Neighbor A" },
|
|
2753
|
-
{ id: "doc-3", title: "Neighbor B" },
|
|
2754
|
-
{ id: "doc-4", title: "Neighbor C" },
|
|
2755
|
-
],
|
|
2756
|
-
},
|
|
2757
|
-
};
|
|
2758
|
-
},
|
|
2759
|
-
},
|
|
2760
|
-
};
|
|
2761
|
-
|
|
2762
|
-
const output = await contract.handler(ctx, {
|
|
2763
|
-
seedIds: ["doc-1"],
|
|
2764
|
-
depth: 1,
|
|
2765
|
-
maxNodes: 3,
|
|
2766
|
-
includeBacklinks: true,
|
|
2767
|
-
includeSearchNeighbors: false,
|
|
2768
|
-
limitPerSource: 3,
|
|
2769
|
-
view: "ids",
|
|
2770
|
-
});
|
|
2771
|
-
|
|
2772
|
-
assert.deepEqual(calls, [
|
|
2773
|
-
{
|
|
2774
|
-
method: "documents.list",
|
|
2775
|
-
body: {
|
|
2776
|
-
backlinkDocumentId: "doc-1",
|
|
2777
|
-
limit: 3,
|
|
2778
|
-
offset: 0,
|
|
2779
|
-
sort: "updatedAt",
|
|
2780
|
-
direction: "DESC",
|
|
2781
|
-
},
|
|
2782
|
-
options: { maxAttempts: 2 },
|
|
2783
|
-
},
|
|
2784
|
-
]);
|
|
2785
|
-
assert.equal(output.tool, "documents.graph_report");
|
|
2786
|
-
assert.equal(output.profile, "profile-hardening");
|
|
2787
|
-
assert.deepEqual(output.result, {
|
|
2788
|
-
seedIds: ["doc-1"],
|
|
2789
|
-
requestedSeedCount: 1,
|
|
2790
|
-
depth: 1,
|
|
2791
|
-
exploredDepth: 1,
|
|
2792
|
-
maxNodes: 3,
|
|
2793
|
-
includeBacklinks: true,
|
|
2794
|
-
includeSearchNeighbors: false,
|
|
2795
|
-
limitPerSource: 3,
|
|
2796
|
-
truncated: true,
|
|
2797
|
-
nodeCount: 3,
|
|
2798
|
-
edgeCount: 2,
|
|
2799
|
-
nodes: [
|
|
2800
|
-
{ id: "doc-1", title: "" },
|
|
2801
|
-
{ id: "doc-2", title: "Neighbor A" },
|
|
2802
|
-
{ id: "doc-3", title: "Neighbor B" },
|
|
2803
|
-
],
|
|
2804
|
-
edges: [
|
|
2805
|
-
{
|
|
2806
|
-
sourceId: "doc-1",
|
|
2807
|
-
targetId: "doc-2",
|
|
2808
|
-
type: "backlink",
|
|
2809
|
-
query: "",
|
|
2810
|
-
rank: 1,
|
|
2811
|
-
},
|
|
2812
|
-
{
|
|
2813
|
-
sourceId: "doc-1",
|
|
2814
|
-
targetId: "doc-3",
|
|
2815
|
-
type: "backlink",
|
|
2816
|
-
query: "",
|
|
2817
|
-
rank: 2,
|
|
2818
|
-
},
|
|
2819
|
-
],
|
|
2820
|
-
errors: [],
|
|
2821
|
-
});
|
|
2822
|
-
});
|
|
2823
|
-
|
|
2824
|
-
test("documents.issue_refs extracts deterministic issue URLs and keys per document", async () => {
|
|
2825
|
-
const contract = EXTENDED_TOOLS["documents.issue_refs"];
|
|
2826
|
-
assert.ok(contract);
|
|
2827
|
-
assert.equal(typeof contract.handler, "function");
|
|
2828
|
-
|
|
2829
|
-
const calls = [];
|
|
2830
|
-
const ctx = {
|
|
2831
|
-
profile: { id: "profile-hardening" },
|
|
2832
|
-
client: {
|
|
2833
|
-
async call(method, body, options) {
|
|
2834
|
-
calls.push({ method, body, options });
|
|
2835
|
-
assert.equal(method, "documents.info");
|
|
2836
|
-
|
|
2837
|
-
if (body.id === "doc-1") {
|
|
2838
|
-
return {
|
|
2839
|
-
body: {
|
|
2840
|
-
data: {
|
|
2841
|
-
id: "doc-1",
|
|
2842
|
-
title: "Incident Notes",
|
|
2843
|
-
text:
|
|
2844
|
-
"Ticket ABC-1 and https://jira.example.com/browse/ABC-2 plus https://github.com/acme/repo/issues/42",
|
|
2845
|
-
},
|
|
2846
|
-
},
|
|
2847
|
-
};
|
|
2848
|
-
}
|
|
2849
|
-
if (body.id === "doc-2") {
|
|
2850
|
-
return {
|
|
2851
|
-
body: {
|
|
2852
|
-
data: {
|
|
2853
|
-
id: "doc-2",
|
|
2854
|
-
title: "Release Checklist",
|
|
2855
|
-
text:
|
|
2856
|
-
"OPS-2 and https://jira.example.com/browse/OPS-1 plus https://example.com/out-of-scope",
|
|
2857
|
-
},
|
|
2858
|
-
},
|
|
2859
|
-
};
|
|
2860
|
-
}
|
|
2861
|
-
throw new Error(`Unexpected id: ${body.id}`);
|
|
2862
|
-
},
|
|
2863
|
-
},
|
|
2864
|
-
};
|
|
2865
|
-
|
|
2866
|
-
const output = await contract.handler(ctx, {
|
|
2867
|
-
ids: ["doc-2", "doc-1"],
|
|
2868
|
-
issueDomains: ["jira.example.com", "github.com"],
|
|
2869
|
-
keyPattern: "[A-Z]+-\\d+",
|
|
2870
|
-
view: "ids",
|
|
2871
|
-
maxAttempts: 3,
|
|
2872
|
-
});
|
|
2873
|
-
|
|
2874
|
-
assert.deepEqual(calls, [
|
|
2875
|
-
{
|
|
2876
|
-
method: "documents.info",
|
|
2877
|
-
body: { id: "doc-1" },
|
|
2878
|
-
options: { maxAttempts: 3 },
|
|
2879
|
-
},
|
|
2880
|
-
{
|
|
2881
|
-
method: "documents.info",
|
|
2882
|
-
body: { id: "doc-2" },
|
|
2883
|
-
options: { maxAttempts: 3 },
|
|
2884
|
-
},
|
|
2885
|
-
]);
|
|
2886
|
-
|
|
2887
|
-
assert.equal(output.tool, "documents.issue_refs");
|
|
2888
|
-
assert.equal(output.profile, "profile-hardening");
|
|
2889
|
-
assert.deepEqual(output.result.requestedIds, ["doc-1", "doc-2"]);
|
|
2890
|
-
assert.deepEqual(output.result.issueDomains, ["github.com", "jira.example.com"]);
|
|
2891
|
-
assert.equal(output.result.keyPattern, "[A-Z]+-\\d+");
|
|
2892
|
-
assert.equal(output.result.documentCount, 2);
|
|
2893
|
-
assert.equal(output.result.documentsWithRefs, 2);
|
|
2894
|
-
assert.equal(output.result.refCount, 5);
|
|
2895
|
-
assert.equal(output.result.keyCount, 4);
|
|
2896
|
-
assert.equal(output.result.mentionCount, 5);
|
|
2897
|
-
assert.deepEqual(output.result.keys, ["ABC-1", "ABC-2", "OPS-1", "OPS-2"]);
|
|
2898
|
-
assert.deepEqual(output.result.errors, []);
|
|
2899
|
-
|
|
2900
|
-
assert.deepEqual(output.result.documents, [
|
|
2901
|
-
{
|
|
2902
|
-
document: {
|
|
2903
|
-
id: "doc-1",
|
|
2904
|
-
title: "Incident Notes",
|
|
2905
|
-
},
|
|
2906
|
-
summary: {
|
|
2907
|
-
refCount: 3,
|
|
2908
|
-
urlRefCount: 2,
|
|
2909
|
-
keyRefCount: 2,
|
|
2910
|
-
keyCount: 2,
|
|
2911
|
-
mentionCount: 3,
|
|
2912
|
-
textLength: 98,
|
|
2913
|
-
},
|
|
2914
|
-
keys: ["ABC-1", "ABC-2"],
|
|
2915
|
-
refs: [
|
|
2916
|
-
{
|
|
2917
|
-
key: "",
|
|
2918
|
-
url: "https://github.com/acme/repo/issues/42",
|
|
2919
|
-
domain: "github.com",
|
|
2920
|
-
sources: ["url"],
|
|
2921
|
-
count: 1,
|
|
2922
|
-
},
|
|
2923
|
-
{
|
|
2924
|
-
key: "ABC-1",
|
|
2925
|
-
url: "",
|
|
2926
|
-
domain: "",
|
|
2927
|
-
sources: ["key_pattern"],
|
|
2928
|
-
count: 1,
|
|
2929
|
-
},
|
|
2930
|
-
{
|
|
2931
|
-
key: "ABC-2",
|
|
2932
|
-
url: "https://jira.example.com/browse/ABC-2",
|
|
2933
|
-
domain: "jira.example.com",
|
|
2934
|
-
sources: ["key_pattern", "url"],
|
|
2935
|
-
count: 1,
|
|
2936
|
-
},
|
|
2937
|
-
],
|
|
2938
|
-
},
|
|
2939
|
-
{
|
|
2940
|
-
document: {
|
|
2941
|
-
id: "doc-2",
|
|
2942
|
-
title: "Release Checklist",
|
|
2943
|
-
},
|
|
2944
|
-
summary: {
|
|
2945
|
-
refCount: 2,
|
|
2946
|
-
urlRefCount: 1,
|
|
2947
|
-
keyRefCount: 2,
|
|
2948
|
-
keyCount: 2,
|
|
2949
|
-
mentionCount: 2,
|
|
2950
|
-
textLength: 85,
|
|
2951
|
-
},
|
|
2952
|
-
keys: ["OPS-1", "OPS-2"],
|
|
2953
|
-
refs: [
|
|
2954
|
-
{
|
|
2955
|
-
key: "OPS-1",
|
|
2956
|
-
url: "https://jira.example.com/browse/OPS-1",
|
|
2957
|
-
domain: "jira.example.com",
|
|
2958
|
-
sources: ["key_pattern", "url"],
|
|
2959
|
-
count: 1,
|
|
2960
|
-
},
|
|
2961
|
-
{
|
|
2962
|
-
key: "OPS-2",
|
|
2963
|
-
url: "",
|
|
2964
|
-
domain: "",
|
|
2965
|
-
sources: ["key_pattern"],
|
|
2966
|
-
count: 1,
|
|
2967
|
-
},
|
|
2968
|
-
],
|
|
2969
|
-
},
|
|
2970
|
-
]);
|
|
2971
|
-
});
|
|
2972
|
-
|
|
2973
|
-
test("documents.issue_ref_report resolves candidates via search and extracts deterministic refs", async () => {
|
|
2974
|
-
const contract = EXTENDED_TOOLS["documents.issue_ref_report"];
|
|
2975
|
-
assert.ok(contract);
|
|
2976
|
-
assert.equal(typeof contract.handler, "function");
|
|
2977
|
-
|
|
2978
|
-
const calls = [];
|
|
2979
|
-
const ctx = {
|
|
2980
|
-
profile: { id: "profile-hardening" },
|
|
2981
|
-
client: {
|
|
2982
|
-
async call(method, body, options) {
|
|
2983
|
-
calls.push({ method, body, options });
|
|
2984
|
-
|
|
2985
|
-
if (method === "documents.search_titles") {
|
|
2986
|
-
return {
|
|
2987
|
-
body: {
|
|
2988
|
-
data: [
|
|
2989
|
-
{
|
|
2990
|
-
id: "doc-b",
|
|
2991
|
-
title: "Runbook",
|
|
2992
|
-
collectionId: "col-1",
|
|
2993
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
2994
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
2995
|
-
urlId: "runbook",
|
|
2996
|
-
ranking: 0.8,
|
|
2997
|
-
},
|
|
2998
|
-
{
|
|
2999
|
-
id: "doc-a",
|
|
3000
|
-
title: "Incident Notes",
|
|
3001
|
-
collectionId: "col-1",
|
|
3002
|
-
updatedAt: "2026-03-01T00:00:00.000Z",
|
|
3003
|
-
publishedAt: "2026-03-01T00:00:00.000Z",
|
|
3004
|
-
urlId: "incident-notes",
|
|
3005
|
-
ranking: 0.9,
|
|
3006
|
-
},
|
|
3007
|
-
],
|
|
3008
|
-
},
|
|
3009
|
-
};
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
if (method === "documents.search") {
|
|
3013
|
-
return {
|
|
3014
|
-
body: {
|
|
3015
|
-
data: [
|
|
3016
|
-
{
|
|
3017
|
-
document: {
|
|
3018
|
-
id: "doc-c",
|
|
3019
|
-
title: "Postmortem",
|
|
3020
|
-
collectionId: "col-1",
|
|
3021
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3022
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3023
|
-
urlId: "postmortem",
|
|
3024
|
-
},
|
|
3025
|
-
ranking: 0.95,
|
|
3026
|
-
context: "Contains OPS-77 context",
|
|
3027
|
-
},
|
|
3028
|
-
{
|
|
3029
|
-
document: {
|
|
3030
|
-
id: "doc-a",
|
|
3031
|
-
title: "Incident Notes",
|
|
3032
|
-
collectionId: "col-1",
|
|
3033
|
-
updatedAt: "2026-03-04T00:00:00.000Z",
|
|
3034
|
-
publishedAt: "2026-03-04T00:00:00.000Z",
|
|
3035
|
-
urlId: "incident-notes",
|
|
3036
|
-
},
|
|
3037
|
-
ranking: 0.7,
|
|
3038
|
-
context: "See ABC-9 context",
|
|
3039
|
-
},
|
|
3040
|
-
],
|
|
3041
|
-
},
|
|
3042
|
-
};
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3045
|
-
if (method === "documents.info") {
|
|
3046
|
-
if (body.id === "doc-a") {
|
|
3047
|
-
return {
|
|
3048
|
-
body: {
|
|
3049
|
-
data: {
|
|
3050
|
-
id: "doc-a",
|
|
3051
|
-
title: "Incident Notes",
|
|
3052
|
-
text: "Link https://jira.example.com/browse/ABC-9 and plain ABC-8",
|
|
3053
|
-
},
|
|
3054
|
-
},
|
|
3055
|
-
};
|
|
3056
|
-
}
|
|
3057
|
-
if (body.id === "doc-b") {
|
|
3058
|
-
return {
|
|
3059
|
-
body: {
|
|
3060
|
-
data: {
|
|
3061
|
-
id: "doc-b",
|
|
3062
|
-
title: "Runbook",
|
|
3063
|
-
text: "No issue references here",
|
|
3064
|
-
},
|
|
3065
|
-
},
|
|
3066
|
-
};
|
|
3067
|
-
}
|
|
3068
|
-
if (body.id === "doc-c") {
|
|
3069
|
-
return {
|
|
3070
|
-
body: {
|
|
3071
|
-
data: {
|
|
3072
|
-
id: "doc-c",
|
|
3073
|
-
title: "Postmortem",
|
|
3074
|
-
text:
|
|
3075
|
-
"Track https://jira.example.com/browse/OPS-77 and ignore https://example.com/not-issue",
|
|
3076
|
-
},
|
|
3077
|
-
},
|
|
3078
|
-
};
|
|
3079
|
-
}
|
|
3080
|
-
throw new Error(`Unexpected document id: ${body.id}`);
|
|
3081
|
-
}
|
|
3082
|
-
|
|
3083
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
3084
|
-
},
|
|
3085
|
-
},
|
|
3086
|
-
};
|
|
3087
|
-
|
|
3088
|
-
const output = await contract.handler(ctx, {
|
|
3089
|
-
query: "incident runbook",
|
|
3090
|
-
collectionId: "col-1",
|
|
3091
|
-
issueDomains: ["jira.example.com"],
|
|
3092
|
-
keyPattern: "[A-Z]+-\\d+",
|
|
3093
|
-
limit: 3,
|
|
3094
|
-
view: "summary",
|
|
3095
|
-
maxAttempts: 2,
|
|
3096
|
-
});
|
|
3097
|
-
|
|
3098
|
-
assert.deepEqual(calls[0], {
|
|
3099
|
-
method: "documents.search_titles",
|
|
3100
|
-
body: {
|
|
3101
|
-
query: "incident runbook",
|
|
3102
|
-
collectionId: "col-1",
|
|
3103
|
-
limit: 3,
|
|
3104
|
-
offset: 0,
|
|
3105
|
-
},
|
|
3106
|
-
options: { maxAttempts: 2 },
|
|
3107
|
-
});
|
|
3108
|
-
assert.deepEqual(calls[1], {
|
|
3109
|
-
method: "documents.search",
|
|
3110
|
-
body: {
|
|
3111
|
-
query: "incident runbook",
|
|
3112
|
-
collectionId: "col-1",
|
|
3113
|
-
limit: 3,
|
|
3114
|
-
offset: 0,
|
|
3115
|
-
snippetMinWords: 16,
|
|
3116
|
-
snippetMaxWords: 24,
|
|
3117
|
-
},
|
|
3118
|
-
options: { maxAttempts: 2 },
|
|
3119
|
-
});
|
|
3120
|
-
assert.deepEqual(
|
|
3121
|
-
calls
|
|
3122
|
-
.filter((call) => call.method === "documents.info")
|
|
3123
|
-
.map((call) => call.body.id)
|
|
3124
|
-
.sort(),
|
|
3125
|
-
["doc-a", "doc-b", "doc-c"]
|
|
3126
|
-
);
|
|
3127
|
-
|
|
3128
|
-
assert.equal(output.tool, "documents.issue_ref_report");
|
|
3129
|
-
assert.equal(output.profile, "profile-hardening");
|
|
3130
|
-
assert.deepEqual(output.result.queries, ["incident runbook"]);
|
|
3131
|
-
assert.equal(output.result.collectionId, "col-1");
|
|
3132
|
-
assert.equal(output.result.limit, 3);
|
|
3133
|
-
assert.equal(output.result.candidateCount, 3);
|
|
3134
|
-
assert.deepEqual(
|
|
3135
|
-
output.result.candidates.map((item) => item.id),
|
|
3136
|
-
["doc-c", "doc-a", "doc-b"]
|
|
3137
|
-
);
|
|
3138
|
-
assert.equal(output.result.documentCount, 3);
|
|
3139
|
-
assert.equal(output.result.documentsWithRefs, 2);
|
|
3140
|
-
assert.equal(output.result.refCount, 3);
|
|
3141
|
-
assert.equal(output.result.keyCount, 3);
|
|
3142
|
-
assert.equal(output.result.mentionCount, 3);
|
|
3143
|
-
assert.deepEqual(output.result.keys, ["ABC-8", "ABC-9", "OPS-77"]);
|
|
3144
|
-
assert.deepEqual(output.result.errors, []);
|
|
3145
|
-
assert.equal(output.result.perQuery.length, 1);
|
|
3146
|
-
assert.equal(output.result.perQuery[0].query, "incident runbook");
|
|
3147
|
-
assert.equal(output.result.perQuery[0].hitCount, 3);
|
|
3148
|
-
assert.deepEqual(output.result.documents.map((item) => item.document.id), ["doc-a", "doc-b", "doc-c"]);
|
|
3149
|
-
assert.equal(output.result.documents[0].summary.refCount, 2);
|
|
3150
|
-
assert.equal(output.result.documents[1].summary.refCount, 0);
|
|
3151
|
-
assert.equal(output.result.documents[2].summary.refCount, 1);
|
|
3152
|
-
});
|
|
3153
|
-
|
|
3154
|
-
test("search.research schema accepts precision controls and enforces numeric bounds", () => {
|
|
3155
|
-
assert.doesNotThrow(() =>
|
|
3156
|
-
validateToolArgs("search.research", {
|
|
3157
|
-
query: "incident comms",
|
|
3158
|
-
precisionMode: "precision",
|
|
3159
|
-
minScore: 0.4,
|
|
3160
|
-
diversify: true,
|
|
3161
|
-
diversityLambda: 0.75,
|
|
3162
|
-
rrfK: 50,
|
|
3163
|
-
perQueryView: "ids",
|
|
3164
|
-
perQueryHitLimit: 3,
|
|
3165
|
-
evidencePerDocument: 2,
|
|
3166
|
-
includePerQuery: true,
|
|
3167
|
-
includeExpanded: true,
|
|
3168
|
-
includeCoverage: true,
|
|
3169
|
-
includeBacklinks: true,
|
|
3170
|
-
backlinksLimit: 3,
|
|
3171
|
-
backlinksConcurrency: 2,
|
|
3172
|
-
})
|
|
3173
|
-
);
|
|
3174
|
-
|
|
3175
|
-
assert.throws(
|
|
3176
|
-
() =>
|
|
3177
|
-
validateToolArgs("search.research", {
|
|
3178
|
-
query: "incident comms",
|
|
3179
|
-
minScore: 1.5,
|
|
3180
|
-
}),
|
|
3181
|
-
(err) => {
|
|
3182
|
-
assert.ok(err instanceof CliError);
|
|
3183
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
3184
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.minScore"));
|
|
3185
|
-
return true;
|
|
3186
|
-
}
|
|
3187
|
-
);
|
|
3188
|
-
|
|
3189
|
-
assert.throws(
|
|
3190
|
-
() =>
|
|
3191
|
-
validateToolArgs("search.research", {
|
|
3192
|
-
query: "incident comms",
|
|
3193
|
-
diversityLambda: 1.5,
|
|
3194
|
-
}),
|
|
3195
|
-
(err) => {
|
|
3196
|
-
assert.ok(err instanceof CliError);
|
|
3197
|
-
assert.equal(err.details?.code, "ARG_VALIDATION_FAILED");
|
|
3198
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.diversityLambda"));
|
|
3199
|
-
return true;
|
|
3200
|
-
}
|
|
3201
|
-
);
|
|
3202
|
-
});
|
|
3203
|
-
|
|
3204
|
-
test("URL resolve and canonicalization schemas enforce selectors and bounds", () => {
|
|
3205
|
-
assert.doesNotThrow(() =>
|
|
3206
|
-
validateToolArgs("documents.resolve_urls", {
|
|
3207
|
-
urls: [
|
|
3208
|
-
"https://handbook.example.com/doc/event-tracking-data-A7hLXuHZJl",
|
|
3209
|
-
"https://handbook.example.com/doc/campaign-detail-page-GWK1uA8w35#d-GWK1uA8w35",
|
|
3210
|
-
],
|
|
3211
|
-
strict: true,
|
|
3212
|
-
strictHost: true,
|
|
3213
|
-
strictThreshold: 0.85,
|
|
3214
|
-
view: "summary",
|
|
3215
|
-
concurrency: 2,
|
|
3216
|
-
})
|
|
3217
|
-
);
|
|
3218
|
-
|
|
3219
|
-
assert.doesNotThrow(() =>
|
|
3220
|
-
validateToolArgs("documents.canonicalize_candidates", {
|
|
3221
|
-
queries: ["campaign tracking", "event tracking"],
|
|
3222
|
-
ids: ["doc-1", "doc-2"],
|
|
3223
|
-
strict: true,
|
|
3224
|
-
strictThreshold: 0.8,
|
|
3225
|
-
titleSimilarityThreshold: 0.78,
|
|
3226
|
-
view: "summary",
|
|
3227
|
-
})
|
|
3228
|
-
);
|
|
3229
|
-
|
|
3230
|
-
assert.throws(
|
|
3231
|
-
() => validateToolArgs("documents.resolve_urls", {}),
|
|
3232
|
-
(err) => {
|
|
3233
|
-
assert.ok(err instanceof CliError);
|
|
3234
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.url"));
|
|
3235
|
-
return true;
|
|
3236
|
-
}
|
|
3237
|
-
);
|
|
3238
|
-
|
|
3239
|
-
assert.throws(
|
|
3240
|
-
() =>
|
|
3241
|
-
validateToolArgs("documents.canonicalize_candidates", {
|
|
3242
|
-
query: "tracking",
|
|
3243
|
-
titleSimilarityThreshold: 1.2,
|
|
3244
|
-
}),
|
|
3245
|
-
(err) => {
|
|
3246
|
-
assert.ok(err instanceof CliError);
|
|
3247
|
-
assert.ok(err.details?.issues?.some((issue) => issue.path === "args.titleSimilarityThreshold"));
|
|
3248
|
-
return true;
|
|
3249
|
-
}
|
|
3250
|
-
);
|
|
3251
|
-
});
|
|
3252
|
-
|
|
3253
|
-
test("documents.resolve_urls boosts urlId matches and keeps grouped deterministic output", async () => {
|
|
3254
|
-
const contract = NAVIGATION_TOOLS["documents.resolve_urls"];
|
|
3255
|
-
assert.ok(contract);
|
|
3256
|
-
|
|
3257
|
-
const calls = [];
|
|
3258
|
-
const ctx = {
|
|
3259
|
-
profile: { id: "profile-hardening", baseUrl: "https://handbook.example.com" },
|
|
3260
|
-
client: {
|
|
3261
|
-
async call(method, body, options) {
|
|
3262
|
-
calls.push({ method, body, options });
|
|
3263
|
-
if (method === "documents.search_titles") {
|
|
3264
|
-
return {
|
|
3265
|
-
body: {
|
|
3266
|
-
data: [
|
|
3267
|
-
{
|
|
3268
|
-
id: "doc-1",
|
|
3269
|
-
title: "Event Tracking Data",
|
|
3270
|
-
collectionId: "col-1",
|
|
3271
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3272
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3273
|
-
urlId: "A7hLXuHZJl",
|
|
3274
|
-
text: "tracking details",
|
|
3275
|
-
},
|
|
3276
|
-
{
|
|
3277
|
-
id: "doc-2",
|
|
3278
|
-
title: "Event Tracking Overview",
|
|
3279
|
-
collectionId: "col-1",
|
|
3280
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3281
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3282
|
-
urlId: "legacy-url",
|
|
3283
|
-
text: "legacy",
|
|
3284
|
-
},
|
|
3285
|
-
],
|
|
3286
|
-
},
|
|
3287
|
-
};
|
|
3288
|
-
}
|
|
3289
|
-
if (method === "documents.search") {
|
|
3290
|
-
return {
|
|
3291
|
-
body: {
|
|
3292
|
-
data: [
|
|
3293
|
-
{
|
|
3294
|
-
ranking: 0.88,
|
|
3295
|
-
context: "event tracking details",
|
|
3296
|
-
document: {
|
|
3297
|
-
id: "doc-1",
|
|
3298
|
-
title: "Event Tracking Data",
|
|
3299
|
-
collectionId: "col-1",
|
|
3300
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3301
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3302
|
-
urlId: "A7hLXuHZJl",
|
|
3303
|
-
text: "tracking details",
|
|
3304
|
-
},
|
|
3305
|
-
},
|
|
3306
|
-
],
|
|
3307
|
-
},
|
|
3308
|
-
};
|
|
3309
|
-
}
|
|
3310
|
-
if (method === "documents.info") {
|
|
3311
|
-
return {
|
|
3312
|
-
body: {
|
|
3313
|
-
data: {
|
|
3314
|
-
id: "doc-share",
|
|
3315
|
-
title: "Shared Handbook",
|
|
3316
|
-
collectionId: "col-share",
|
|
3317
|
-
updatedAt: "2026-03-01T00:00:00.000Z",
|
|
3318
|
-
publishedAt: "2026-03-01T00:00:00.000Z",
|
|
3319
|
-
urlId: "share-1",
|
|
3320
|
-
text: "shared",
|
|
3321
|
-
},
|
|
3322
|
-
},
|
|
3323
|
-
};
|
|
3324
|
-
}
|
|
3325
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
3326
|
-
},
|
|
3327
|
-
},
|
|
3328
|
-
};
|
|
3329
|
-
|
|
3330
|
-
const output = await contract.handler(ctx, {
|
|
3331
|
-
urls: [
|
|
3332
|
-
"https://handbook.example.com/doc/event-tracking-data-A7hLXuHZJl",
|
|
3333
|
-
"https://handbook.example.com/share/share-id-123",
|
|
3334
|
-
],
|
|
3335
|
-
limit: 3,
|
|
3336
|
-
view: "summary",
|
|
3337
|
-
strict: false,
|
|
3338
|
-
});
|
|
3339
|
-
|
|
3340
|
-
assert.equal(output.tool, "documents.resolve_urls");
|
|
3341
|
-
assert.equal(output.profile, "profile-hardening");
|
|
3342
|
-
assert.equal(output.urlCount, 2);
|
|
3343
|
-
assert.equal(output.result.perUrl.length, 2);
|
|
3344
|
-
|
|
3345
|
-
const docUrl = output.result.perUrl.find((item) => item.url.includes("/doc/"));
|
|
3346
|
-
assert.ok(docUrl);
|
|
3347
|
-
assert.equal(docUrl.bestMatch?.id, "doc-1");
|
|
3348
|
-
assert.ok(docUrl.bestMatch?.confidence >= 0.9);
|
|
3349
|
-
|
|
3350
|
-
const shareUrl = output.result.perUrl.find((item) => item.url.includes("/share/"));
|
|
3351
|
-
assert.ok(shareUrl);
|
|
3352
|
-
assert.equal(shareUrl.bestMatch?.id, "doc-share");
|
|
3353
|
-
assert.ok(Array.isArray(output.result.mergedBestMatches));
|
|
3354
|
-
assert.ok(calls.some((call) => call.method === "documents.info" && call.body.shareId));
|
|
3355
|
-
});
|
|
3356
|
-
|
|
3357
|
-
test("documents.canonicalize_candidates groups duplicates into canonical clusters", async () => {
|
|
3358
|
-
const contract = NAVIGATION_TOOLS["documents.canonicalize_candidates"];
|
|
3359
|
-
assert.ok(contract);
|
|
3360
|
-
|
|
3361
|
-
const ctx = {
|
|
3362
|
-
profile: { id: "profile-hardening" },
|
|
3363
|
-
client: {
|
|
3364
|
-
async call(method, body) {
|
|
3365
|
-
if (method === "documents.info") {
|
|
3366
|
-
const rows = {
|
|
3367
|
-
"doc-explicit": {
|
|
3368
|
-
id: "doc-explicit",
|
|
3369
|
-
title: "Campaign Detail Page",
|
|
3370
|
-
collectionId: "col-1",
|
|
3371
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3372
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3373
|
-
urlId: "GWK1uA8w35",
|
|
3374
|
-
text: "explicit doc",
|
|
3375
|
-
},
|
|
3376
|
-
};
|
|
3377
|
-
return { body: { data: rows[body.id] || null } };
|
|
3378
|
-
}
|
|
3379
|
-
|
|
3380
|
-
if (method === "documents.search_titles") {
|
|
3381
|
-
return {
|
|
3382
|
-
body: {
|
|
3383
|
-
data: [
|
|
3384
|
-
{
|
|
3385
|
-
id: "doc-explicit",
|
|
3386
|
-
title: "Campaign Detail Page",
|
|
3387
|
-
collectionId: "col-1",
|
|
3388
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3389
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3390
|
-
urlId: "GWK1uA8w35",
|
|
3391
|
-
text: "explicit doc",
|
|
3392
|
-
},
|
|
3393
|
-
{
|
|
3394
|
-
id: "doc-dup",
|
|
3395
|
-
title: "Campaign Detail Pages",
|
|
3396
|
-
collectionId: "col-1",
|
|
3397
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3398
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3399
|
-
urlId: "legacy-url",
|
|
3400
|
-
text: "duplicate title variant",
|
|
3401
|
-
},
|
|
3402
|
-
],
|
|
3403
|
-
},
|
|
3404
|
-
};
|
|
3405
|
-
}
|
|
3406
|
-
|
|
3407
|
-
if (method === "documents.search") {
|
|
3408
|
-
return {
|
|
3409
|
-
body: {
|
|
3410
|
-
data: [
|
|
3411
|
-
{
|
|
3412
|
-
ranking: 0.9,
|
|
3413
|
-
context: "campaign detail setup",
|
|
3414
|
-
document: {
|
|
3415
|
-
id: "doc-dup",
|
|
3416
|
-
title: "Campaign Detail Pages",
|
|
3417
|
-
collectionId: "col-1",
|
|
3418
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3419
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3420
|
-
urlId: "legacy-url",
|
|
3421
|
-
text: "duplicate title variant",
|
|
3422
|
-
},
|
|
3423
|
-
},
|
|
3424
|
-
],
|
|
3425
|
-
},
|
|
3426
|
-
};
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
3430
|
-
},
|
|
3431
|
-
},
|
|
3432
|
-
};
|
|
3433
|
-
|
|
3434
|
-
const output = await contract.handler(ctx, {
|
|
3435
|
-
ids: ["doc-explicit"],
|
|
3436
|
-
query: "campaign detail page",
|
|
3437
|
-
strict: true,
|
|
3438
|
-
strictThreshold: 0.7,
|
|
3439
|
-
titleSimilarityThreshold: 0.6,
|
|
3440
|
-
view: "summary",
|
|
3441
|
-
});
|
|
3442
|
-
|
|
3443
|
-
assert.equal(output.tool, "documents.canonicalize_candidates");
|
|
3444
|
-
assert.equal(output.profile, "profile-hardening");
|
|
3445
|
-
assert.equal(output.result.clusterCount, 1);
|
|
3446
|
-
assert.equal(output.result.duplicateClusterCount, 1);
|
|
3447
|
-
assert.equal(output.result.canonical.length, 1);
|
|
3448
|
-
assert.equal(output.result.canonical[0].id, "doc-explicit");
|
|
3449
|
-
assert.deepEqual(output.result.canonical[0].duplicateIds, ["doc-dup"]);
|
|
3450
|
-
});
|
|
3451
|
-
|
|
3452
|
-
test("search.expand reuses hydration cache for duplicate ids across queries", async () => {
|
|
3453
|
-
const contract = NAVIGATION_TOOLS["search.expand"];
|
|
3454
|
-
assert.ok(contract);
|
|
3455
|
-
|
|
3456
|
-
const calls = [];
|
|
3457
|
-
const ctx = {
|
|
3458
|
-
profile: { id: "profile-hardening" },
|
|
3459
|
-
client: {
|
|
3460
|
-
async call(method, body, options) {
|
|
3461
|
-
calls.push({ method, body, options });
|
|
3462
|
-
if (method === "documents.search_titles") {
|
|
3463
|
-
const base = [
|
|
3464
|
-
{
|
|
3465
|
-
id: "doc-a",
|
|
3466
|
-
title: "Incident Communication",
|
|
3467
|
-
collectionId: "col-1",
|
|
3468
|
-
updatedAt: "2026-03-01T00:00:00.000Z",
|
|
3469
|
-
publishedAt: "2026-03-01T00:00:00.000Z",
|
|
3470
|
-
urlId: "doc-a-url",
|
|
3471
|
-
text: "doc a",
|
|
3472
|
-
},
|
|
3473
|
-
{
|
|
3474
|
-
id: "doc-b",
|
|
3475
|
-
title: "Escalation Matrix",
|
|
3476
|
-
collectionId: "col-1",
|
|
3477
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3478
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3479
|
-
urlId: "doc-b-url",
|
|
3480
|
-
text: "doc b",
|
|
3481
|
-
},
|
|
3482
|
-
];
|
|
3483
|
-
return { body: { data: base } };
|
|
3484
|
-
}
|
|
3485
|
-
if (method === "documents.info") {
|
|
3486
|
-
return {
|
|
3487
|
-
body: {
|
|
3488
|
-
data: {
|
|
3489
|
-
id: body.id,
|
|
3490
|
-
title: body.id === "doc-a" ? "Incident Communication" : "Escalation Matrix",
|
|
3491
|
-
collectionId: "col-1",
|
|
3492
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3493
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3494
|
-
urlId: `${body.id}-url`,
|
|
3495
|
-
text: `hydrated ${body.id}`,
|
|
3496
|
-
},
|
|
3497
|
-
},
|
|
3498
|
-
};
|
|
3499
|
-
}
|
|
3500
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
3501
|
-
},
|
|
3502
|
-
},
|
|
3503
|
-
};
|
|
3504
|
-
|
|
3505
|
-
const output = await contract.handler(ctx, {
|
|
3506
|
-
queries: ["incident comms", "escalation matrix"],
|
|
3507
|
-
mode: "titles",
|
|
3508
|
-
limit: 5,
|
|
3509
|
-
expandLimit: 2,
|
|
3510
|
-
view: "summary",
|
|
3511
|
-
concurrency: 2,
|
|
3512
|
-
hydrateConcurrency: 2,
|
|
3513
|
-
});
|
|
3514
|
-
|
|
3515
|
-
assert.equal(output.tool, "search.expand");
|
|
3516
|
-
assert.equal(output.profile, "profile-hardening");
|
|
3517
|
-
assert.equal(output.queryCount, 2);
|
|
3518
|
-
assert.equal(output.result.perQuery.length, 2);
|
|
3519
|
-
|
|
3520
|
-
const infoCalls = calls.filter((call) => call.method === "documents.info");
|
|
3521
|
-
assert.equal(infoCalls.length, 2, "shared hydration cache should avoid duplicate documents.info calls");
|
|
3522
|
-
assert.deepEqual(
|
|
3523
|
-
infoCalls.map((call) => call.body.id).sort(),
|
|
3524
|
-
["doc-a", "doc-b"]
|
|
3525
|
-
);
|
|
3526
|
-
});
|
|
3527
|
-
|
|
3528
|
-
test("search.research supports precision shaping, hit limiting, and backlink enrichment", async () => {
|
|
3529
|
-
const contract = NAVIGATION_TOOLS["search.research"];
|
|
3530
|
-
assert.ok(contract);
|
|
3531
|
-
|
|
3532
|
-
const titleHitsByQuery = {
|
|
3533
|
-
"incident comms": [
|
|
3534
|
-
{
|
|
3535
|
-
id: "doc-1",
|
|
3536
|
-
title: "Incident Communication Playbook",
|
|
3537
|
-
collectionId: "col-1",
|
|
3538
|
-
parentDocumentId: null,
|
|
3539
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3540
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3541
|
-
urlId: "doc-1-url",
|
|
3542
|
-
text: "comms primary",
|
|
3543
|
-
},
|
|
3544
|
-
{
|
|
3545
|
-
id: "doc-2",
|
|
3546
|
-
title: "Escalation Matrix",
|
|
3547
|
-
collectionId: "col-1",
|
|
3548
|
-
parentDocumentId: null,
|
|
3549
|
-
updatedAt: "2026-02-25T00:00:00.000Z",
|
|
3550
|
-
publishedAt: "2026-02-25T00:00:00.000Z",
|
|
3551
|
-
urlId: "doc-2-url",
|
|
3552
|
-
text: "matrix",
|
|
3553
|
-
},
|
|
3554
|
-
],
|
|
3555
|
-
"escalation matrix": [
|
|
3556
|
-
{
|
|
3557
|
-
id: "doc-2",
|
|
3558
|
-
title: "Escalation Matrix",
|
|
3559
|
-
collectionId: "col-1",
|
|
3560
|
-
parentDocumentId: null,
|
|
3561
|
-
updatedAt: "2026-02-25T00:00:00.000Z",
|
|
3562
|
-
publishedAt: "2026-02-25T00:00:00.000Z",
|
|
3563
|
-
urlId: "doc-2-url",
|
|
3564
|
-
text: "matrix",
|
|
3565
|
-
},
|
|
3566
|
-
{
|
|
3567
|
-
id: "doc-3",
|
|
3568
|
-
title: "Pager Rotation Channels",
|
|
3569
|
-
collectionId: "col-1",
|
|
3570
|
-
parentDocumentId: null,
|
|
3571
|
-
updatedAt: "2026-02-20T00:00:00.000Z",
|
|
3572
|
-
publishedAt: "2026-02-20T00:00:00.000Z",
|
|
3573
|
-
urlId: "doc-3-url",
|
|
3574
|
-
text: "pager channels",
|
|
3575
|
-
},
|
|
3576
|
-
],
|
|
3577
|
-
};
|
|
3578
|
-
|
|
3579
|
-
const semanticHitsByQuery = {
|
|
3580
|
-
"incident comms": [
|
|
3581
|
-
{
|
|
3582
|
-
ranking: 0.93,
|
|
3583
|
-
context: "Communication path and escalation summary.",
|
|
3584
|
-
document: {
|
|
3585
|
-
id: "doc-1",
|
|
3586
|
-
title: "Incident Communication Playbook",
|
|
3587
|
-
collectionId: "col-1",
|
|
3588
|
-
parentDocumentId: null,
|
|
3589
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3590
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3591
|
-
urlId: "doc-1-url",
|
|
3592
|
-
text: "comms primary",
|
|
3593
|
-
},
|
|
3594
|
-
},
|
|
3595
|
-
{
|
|
3596
|
-
ranking: 0.55,
|
|
3597
|
-
context: "Channel fallback guidance.",
|
|
3598
|
-
document: {
|
|
3599
|
-
id: "doc-3",
|
|
3600
|
-
title: "Pager Rotation Channels",
|
|
3601
|
-
collectionId: "col-1",
|
|
3602
|
-
parentDocumentId: null,
|
|
3603
|
-
updatedAt: "2026-02-20T00:00:00.000Z",
|
|
3604
|
-
publishedAt: "2026-02-20T00:00:00.000Z",
|
|
3605
|
-
urlId: "doc-3-url",
|
|
3606
|
-
text: "pager channels",
|
|
3607
|
-
},
|
|
3608
|
-
},
|
|
3609
|
-
],
|
|
3610
|
-
"escalation matrix": [
|
|
3611
|
-
{
|
|
3612
|
-
ranking: 0.97,
|
|
3613
|
-
context: "Escalation matrix and approvals.",
|
|
3614
|
-
document: {
|
|
3615
|
-
id: "doc-2",
|
|
3616
|
-
title: "Escalation Matrix",
|
|
3617
|
-
collectionId: "col-1",
|
|
3618
|
-
parentDocumentId: null,
|
|
3619
|
-
updatedAt: "2026-02-25T00:00:00.000Z",
|
|
3620
|
-
publishedAt: "2026-02-25T00:00:00.000Z",
|
|
3621
|
-
urlId: "doc-2-url",
|
|
3622
|
-
text: "matrix",
|
|
3623
|
-
},
|
|
3624
|
-
},
|
|
3625
|
-
],
|
|
3626
|
-
};
|
|
3627
|
-
|
|
3628
|
-
const hydratedDocs = {
|
|
3629
|
-
"doc-1": {
|
|
3630
|
-
id: "doc-1",
|
|
3631
|
-
title: "Incident Communication Playbook",
|
|
3632
|
-
collectionId: "col-1",
|
|
3633
|
-
parentDocumentId: null,
|
|
3634
|
-
updatedAt: "2026-03-02T00:00:00.000Z",
|
|
3635
|
-
publishedAt: "2026-03-02T00:00:00.000Z",
|
|
3636
|
-
urlId: "doc-1-url",
|
|
3637
|
-
text: "Hydrated doc 1",
|
|
3638
|
-
},
|
|
3639
|
-
"doc-2": {
|
|
3640
|
-
id: "doc-2",
|
|
3641
|
-
title: "Escalation Matrix",
|
|
3642
|
-
collectionId: "col-1",
|
|
3643
|
-
parentDocumentId: null,
|
|
3644
|
-
updatedAt: "2026-02-25T00:00:00.000Z",
|
|
3645
|
-
publishedAt: "2026-02-25T00:00:00.000Z",
|
|
3646
|
-
urlId: "doc-2-url",
|
|
3647
|
-
text: "Hydrated doc 2",
|
|
3648
|
-
},
|
|
3649
|
-
"doc-3": {
|
|
3650
|
-
id: "doc-3",
|
|
3651
|
-
title: "Pager Rotation Channels",
|
|
3652
|
-
collectionId: "col-1",
|
|
3653
|
-
parentDocumentId: null,
|
|
3654
|
-
updatedAt: "2026-02-20T00:00:00.000Z",
|
|
3655
|
-
publishedAt: "2026-02-20T00:00:00.000Z",
|
|
3656
|
-
urlId: "doc-3-url",
|
|
3657
|
-
text: "Hydrated doc 3",
|
|
3658
|
-
},
|
|
3659
|
-
};
|
|
3660
|
-
|
|
3661
|
-
const backlinksByDoc = {
|
|
3662
|
-
"doc-1": [
|
|
3663
|
-
{
|
|
3664
|
-
id: "doc-10",
|
|
3665
|
-
title: "Incident Index",
|
|
3666
|
-
collectionId: "col-1",
|
|
3667
|
-
parentDocumentId: null,
|
|
3668
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3669
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3670
|
-
urlId: "doc-10-url",
|
|
3671
|
-
text: "index",
|
|
3672
|
-
},
|
|
3673
|
-
],
|
|
3674
|
-
"doc-2": [
|
|
3675
|
-
{
|
|
3676
|
-
id: "doc-11",
|
|
3677
|
-
title: "Escalation FAQ",
|
|
3678
|
-
collectionId: "col-1",
|
|
3679
|
-
parentDocumentId: null,
|
|
3680
|
-
updatedAt: "2026-03-03T00:00:00.000Z",
|
|
3681
|
-
publishedAt: "2026-03-03T00:00:00.000Z",
|
|
3682
|
-
urlId: "doc-11-url",
|
|
3683
|
-
text: "faq",
|
|
3684
|
-
},
|
|
3685
|
-
],
|
|
3686
|
-
};
|
|
3687
|
-
|
|
3688
|
-
const calls = [];
|
|
3689
|
-
const ctx = {
|
|
3690
|
-
profile: { id: "profile-hardening" },
|
|
3691
|
-
client: {
|
|
3692
|
-
async call(method, body, options) {
|
|
3693
|
-
calls.push({ method, body, options });
|
|
3694
|
-
if (method === "documents.search_titles") {
|
|
3695
|
-
return { body: { data: titleHitsByQuery[body.query] || [] } };
|
|
3696
|
-
}
|
|
3697
|
-
if (method === "documents.search") {
|
|
3698
|
-
return { body: { data: semanticHitsByQuery[body.query] || [] } };
|
|
3699
|
-
}
|
|
3700
|
-
if (method === "documents.info") {
|
|
3701
|
-
return { body: { data: hydratedDocs[body.id] || null } };
|
|
3702
|
-
}
|
|
3703
|
-
if (method === "documents.list") {
|
|
3704
|
-
return { body: { data: backlinksByDoc[body.backlinkDocumentId] || [] } };
|
|
3705
|
-
}
|
|
3706
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
3707
|
-
},
|
|
3708
|
-
},
|
|
3709
|
-
};
|
|
3710
|
-
|
|
3711
|
-
const output = await contract.handler(ctx, {
|
|
3712
|
-
queries: ["incident comms", "escalation matrix"],
|
|
3713
|
-
includeTitleSearch: true,
|
|
3714
|
-
includeSemanticSearch: true,
|
|
3715
|
-
precisionMode: "precision",
|
|
3716
|
-
limitPerQuery: 6,
|
|
3717
|
-
perQueryView: "ids",
|
|
3718
|
-
perQueryHitLimit: 1,
|
|
3719
|
-
evidencePerDocument: 2,
|
|
3720
|
-
maxDocuments: 2,
|
|
3721
|
-
expandLimit: 2,
|
|
3722
|
-
includeBacklinks: true,
|
|
3723
|
-
backlinksLimit: 2,
|
|
3724
|
-
view: "summary",
|
|
3725
|
-
});
|
|
3726
|
-
|
|
3727
|
-
assert.equal(output.tool, "search.research");
|
|
3728
|
-
assert.equal(output.profile, "profile-hardening");
|
|
3729
|
-
assert.equal(output.queryCount, 2);
|
|
3730
|
-
assert.equal(output.result.perQuery.length, 2);
|
|
3731
|
-
assert.ok(output.result.perQuery.every((row) => row.hits.length <= 1));
|
|
3732
|
-
assert.ok(output.result.merged.length <= 2);
|
|
3733
|
-
assert.ok(output.result.expanded.length <= 2);
|
|
3734
|
-
assert.ok(output.result.expanded.every((row) => Array.isArray(row.backlinks)));
|
|
3735
|
-
assert.equal(output.result.coverage.precisionMode, "precision");
|
|
3736
|
-
assert.equal(output.result.coverage.perQueryHitLimit, 1);
|
|
3737
|
-
assert.equal(output.result.coverage.evidencePerDocument, 2);
|
|
3738
|
-
assert.ok(output.result.coverage.backlinksRequested >= 1);
|
|
3739
|
-
|
|
3740
|
-
const backlinkCalls = calls.filter((call) => call.method === "documents.list");
|
|
3741
|
-
assert.ok(backlinkCalls.length >= 1, "includeBacklinks should issue documents.list backlink reads");
|
|
3742
|
-
});
|
|
3743
|
-
|
|
3744
|
-
test("ResultStore.emit offload envelope includes compact preview metadata", async () => {
|
|
3745
|
-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "outline-cli-hardening-preview-"));
|
|
3746
|
-
const store = new ResultStore({ tmpDir, mode: "auto", inlineMaxBytes: 64, pretty: false });
|
|
3747
|
-
const originalWrite = process.stdout.write;
|
|
3748
|
-
const chunks = [];
|
|
3749
|
-
process.stdout.write = (chunk, encoding, callback) => {
|
|
3750
|
-
chunks.push(typeof chunk === "string" ? chunk : String(chunk));
|
|
3751
|
-
if (typeof encoding === "function") {
|
|
3752
|
-
encoding();
|
|
3753
|
-
} else if (typeof callback === "function") {
|
|
3754
|
-
callback();
|
|
3755
|
-
}
|
|
3756
|
-
return true;
|
|
3757
|
-
};
|
|
3758
|
-
|
|
3759
|
-
try {
|
|
3760
|
-
await store.emit({
|
|
3761
|
-
ok: true,
|
|
3762
|
-
result: {
|
|
3763
|
-
items: [
|
|
3764
|
-
{ id: "doc-1", title: "A" },
|
|
3765
|
-
{ id: "doc-2", title: "B" },
|
|
3766
|
-
{ id: "doc-3", title: "C" },
|
|
3767
|
-
{ id: "doc-4", title: "D" },
|
|
3768
|
-
],
|
|
3769
|
-
},
|
|
3770
|
-
});
|
|
3771
|
-
|
|
3772
|
-
const line = chunks.join("").trim();
|
|
3773
|
-
const envelope = JSON.parse(line);
|
|
3774
|
-
assert.equal(envelope.stored, true);
|
|
3775
|
-
assert.equal(typeof envelope.file, "string");
|
|
3776
|
-
assert.ok(envelope.preview);
|
|
3777
|
-
assert.equal(envelope.preview.ok, true);
|
|
3778
|
-
assert.ok(envelope.preview.result);
|
|
3779
|
-
} finally {
|
|
3780
|
-
process.stdout.write = originalWrite;
|
|
3781
|
-
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
3782
|
-
}
|
|
3783
|
-
});
|
|
3784
|
-
|
|
3785
|
-
test("ResultStore.resolve restricts access to managed tmp dir", async () => {
|
|
3786
|
-
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "outline-cli-hardening-"));
|
|
3787
|
-
const store = new ResultStore({ tmpDir });
|
|
3788
|
-
|
|
3789
|
-
try {
|
|
3790
|
-
const insideRelative = store.resolve("result.json");
|
|
3791
|
-
assert.equal(insideRelative, path.resolve(tmpDir, "result.json"));
|
|
3792
|
-
|
|
3793
|
-
const insideAbsolute = path.join(tmpDir, "nested", "result.json");
|
|
3794
|
-
assert.equal(store.resolve(insideAbsolute), path.resolve(insideAbsolute));
|
|
3795
|
-
|
|
3796
|
-
const outsideAbsolute = path.resolve(tmpDir, "..", "outside.json");
|
|
3797
|
-
assert.throws(() => store.resolve(outsideAbsolute), /outside tmp dir/);
|
|
3798
|
-
|
|
3799
|
-
assert.throws(() => store.resolve("../outside.json"), /outside tmp dir/);
|
|
3800
|
-
} finally {
|
|
3801
|
-
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
3802
|
-
}
|
|
3803
|
-
});
|