@hop-top/kit 0.5.0-alpha.0 → 0.5.0-alpha.2

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +237 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DgOEOsPB.d.ts +450 -0
  12. package/dist/cli.d.ts +5 -309
  13. package/dist/cli.js +250 -62
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/id/index.d.ts +2 -83
  19. package/dist/index--C7Mtsmm.d.ts +328 -0
  20. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  21. package/dist/index-MLrRDvEG.d.ts +1073 -0
  22. package/dist/index-QSffbLnj.d.ts +94 -0
  23. package/dist/index.d.ts +26 -0
  24. package/dist/index.js +5863 -0
  25. package/dist/llm-B5XUWH8T.d.ts +231 -0
  26. package/dist/llm.d.ts +1 -188
  27. package/dist/mcp/index.d.ts +2 -0
  28. package/dist/mcp/index.js +1453 -0
  29. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  30. package/dist/netpolicy.d.ts +1 -0
  31. package/dist/netpolicy.js +118 -0
  32. package/dist/output-VFFLqor9.d.ts +521 -0
  33. package/dist/output.d.ts +2 -213
  34. package/dist/output.js +554 -43
  35. package/dist/progress-CAzyxeWl.d.ts +38 -0
  36. package/dist/progress.d.ts +1 -30
  37. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  38. package/dist/provenance.d.ts +1 -24
  39. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  40. package/dist/routellm.d.ts +2 -64
  41. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  42. package/dist/rpc.d.ts +2 -25
  43. package/dist/safety-CUaYEjZc.d.ts +30 -0
  44. package/dist/safety.d.ts +1 -24
  45. package/dist/scope-BrhYB4ij.d.ts +141 -0
  46. package/dist/scope.d.ts +1 -121
  47. package/dist/stream-CrjeCp0M.d.ts +44 -0
  48. package/dist/stream.d.ts +1 -35
  49. package/dist/telemetry/index.d.ts +1 -315
  50. package/dist/telemetry/index.js +12 -1
  51. package/dist/tui/index.d.ts +4 -298
  52. package/dist/tui/index.js +61 -9
  53. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  54. package/dist/upgrade.d.ts +1 -95
  55. package/dist/xdg-DB7Shoib.d.ts +179 -0
  56. package/dist/xdg.d.ts +1 -169
  57. package/package.json +65 -25
  58. package/src/cli.offline.test.ts +93 -0
  59. package/src/cli.parity.test.ts +192 -0
  60. package/src/cli.ts +112 -12
  61. package/src/index.test.ts +58 -0
  62. package/src/index.ts +36 -0
  63. package/src/log.parity.test.ts +105 -0
  64. package/src/log.ts +64 -13
  65. package/src/mcp/bridge.test.ts +150 -0
  66. package/src/mcp/bridge.ts +246 -0
  67. package/src/mcp/conformance.test.ts +336 -0
  68. package/src/mcp/dispatch.ts +313 -0
  69. package/src/mcp/index.ts +138 -0
  70. package/src/mcp/legacy.ts +314 -0
  71. package/src/mcp/mcp.test.ts +697 -0
  72. package/src/mcp/modern-confirm.test.ts +520 -0
  73. package/src/mcp/modern-confirm.ts +452 -0
  74. package/src/mcp/modern.ts +723 -0
  75. package/src/mcp/tasks.ts +82 -0
  76. package/src/mcp/testtree.ts +250 -0
  77. package/src/mcp/types.ts +504 -0
  78. package/src/netpolicy.test.ts +202 -0
  79. package/src/netpolicy.ts +231 -0
  80. package/src/output/dispatch.ts +10 -2
  81. package/src/output/error.ts +293 -0
  82. package/src/output/formatter.ts +29 -5
  83. package/src/output/formatters/csv.ts +48 -12
  84. package/src/output/formatters/json.ts +4 -25
  85. package/src/output/formatters/project.ts +34 -0
  86. package/src/output/formatters/table.ts +8 -6
  87. package/src/output/formatters/text.ts +7 -3
  88. package/src/output/formatters/yaml.ts +5 -22
  89. package/src/output/projection.test.ts +298 -0
  90. package/src/output/projection.ts +33 -59
  91. package/src/output/template.ts +11 -21
  92. package/src/output.surface.test.ts +41 -0
  93. package/src/output.ts +39 -3
  94. package/src/telemetry/client.test.ts +31 -0
  95. package/src/telemetry/client.ts +7 -1
  96. package/src/telemetry/offline.test.ts +64 -0
  97. package/src/tui/parity.test.ts +142 -0
  98. package/src/tui/parity.ts +59 -13
  99. package/test/output/csv.test.ts +164 -0
  100. package/test/output/error.test.ts +241 -0
@@ -0,0 +1,520 @@
1
+ /**
2
+ * MRTR confirmation loop: the edge cases the wire fixture cannot
3
+ * express.
4
+ *
5
+ * The fixture pins one happy exchange. Everything else that makes the
6
+ * gate safe rather than merely functional — refusal on decline, the
7
+ * two distinct verification failures, the three binding components,
8
+ * and above all the two paths that must keep coexisting (header
9
+ * fallback for capability-less clients, header gate for key-less
10
+ * mounts) — is pinned here, mirroring the Go suite's coverage.
11
+ */
12
+
13
+ import { describe, expect, it } from 'vitest';
14
+
15
+ import { createMcpHandler } from './dispatch.js';
16
+ import {
17
+ ElicitationConfirmGate,
18
+ mcpConfirmArgsDigest,
19
+ mintMcpConfirmState,
20
+ MCP_CONFIRM_STATE_TTL_SECONDS,
21
+ verifyMcpConfirmState,
22
+ type McpConfirmBinding,
23
+ } from './modern-confirm.js';
24
+ import { modernLockBridge, mrtrLockBridge } from './testtree.js';
25
+ import { MCP_SPEC_2026_07_28 } from './types.js';
26
+
27
+ const KEY = 'mrtr-unit-suite-shared-secret-32b';
28
+
29
+ /** The reserved _meta bag, with the client's elicitation declaration. */
30
+ function meta(elicitation?: unknown): Record<string, unknown> {
31
+ const caps: Record<string, unknown> = {};
32
+ if (elicitation !== undefined) caps.elicitation = elicitation;
33
+ return {
34
+ 'io.modelcontextprotocol/clientCapabilities': caps,
35
+ 'io.modelcontextprotocol/protocolVersion': MCP_SPEC_2026_07_28,
36
+ };
37
+ }
38
+
39
+ interface CallOpts {
40
+ id?: number;
41
+ tool?: string;
42
+ args?: Record<string, unknown>;
43
+ meta?: Record<string, unknown>;
44
+ state?: string;
45
+ action?: string;
46
+ headers?: Record<string, string>;
47
+ }
48
+
49
+ /** Builds one modern tools/call request, with optional MRTR retry members. */
50
+ function call(o: CallOpts): { headers: Record<string, string>; body: string } {
51
+ const tool = o.tool ?? 'purge';
52
+ const params: Record<string, unknown> = {
53
+ name: tool,
54
+ _meta: o.meta ?? meta({}),
55
+ };
56
+ if (o.args !== undefined) params.arguments = o.args;
57
+ if (o.state !== undefined) params.requestState = o.state;
58
+ if (o.action !== undefined) {
59
+ params.inputResponses = { confirm: { action: o.action } };
60
+ }
61
+ return {
62
+ headers: {
63
+ 'Content-Type': 'application/json',
64
+ 'MCP-Protocol-Version': MCP_SPEC_2026_07_28,
65
+ 'Mcp-Method': 'tools/call',
66
+ 'Mcp-Name': tool,
67
+ ...(o.headers ?? {}),
68
+ },
69
+ body: JSON.stringify({
70
+ jsonrpc: '2.0',
71
+ id: o.id ?? 1,
72
+ method: 'tools/call',
73
+ params,
74
+ }),
75
+ };
76
+ }
77
+
78
+ /** A keyed MRTR mount plus its execution counter and gate. */
79
+ function mount(opts: { key?: string | undefined } = {}) {
80
+ const { bridge, executions } = mrtrLockBridge();
81
+ const handler = createMcpHandler(bridge, {
82
+ confirmationKey: 'key' in opts ? opts.key : KEY,
83
+ });
84
+ return { handler, executions };
85
+ }
86
+
87
+ /** Posts one request and decodes the JSON-RPC result. */
88
+ async function post(
89
+ handler: ReturnType<typeof createMcpHandler>,
90
+ o: CallOpts,
91
+ ): Promise<{ status: number; result: Record<string, unknown> }> {
92
+ const { headers, body } = call(o);
93
+ const res = await handler({ method: 'POST', headers, body });
94
+ const decoded = JSON.parse(res.body) as {
95
+ result?: Record<string, unknown>;
96
+ };
97
+ return { status: res.status, result: decoded.result ?? {} };
98
+ }
99
+
100
+ /** Asserts a result is an input_required prompt and returns its state. */
101
+ function promptState(result: Record<string, unknown>): string {
102
+ expect(result.resultType).toBe('input_required');
103
+ expect(typeof result.requestState).toBe('string');
104
+ return result.requestState as string;
105
+ }
106
+
107
+ describe('MRTR confirmation — full loop', () => {
108
+ it('round 1 prompts without executing, round 2 accepts and executes', async () => {
109
+ const { handler, executions } = mount();
110
+ const args = { target: 'data' };
111
+
112
+ const r1 = await post(handler, { id: 1, args });
113
+ expect(r1.status).toBe(200);
114
+ const state = promptState(r1.result);
115
+ expect(executions()).toBe(0);
116
+
117
+ // The prompt is one elicitation/create form request under the
118
+ // reserved key, and carries no execution members.
119
+ const requests = r1.result.inputRequests as Record<string, unknown>;
120
+ expect(Object.keys(requests)).toEqual(['confirm']);
121
+ const confirm = requests.confirm as Record<string, unknown>;
122
+ expect(confirm.method).toBe('elicitation/create');
123
+ const cp = confirm.params as Record<string, unknown>;
124
+ expect(cp.mode).toBe('form');
125
+ expect(String(cp.message)).toContain('purge');
126
+ expect(cp.requestedSchema).toEqual({ type: 'object', properties: {} });
127
+ expect('content' in r1.result).toBe(false);
128
+ expect('isError' in r1.result).toBe(false);
129
+
130
+ // The modern envelope is still stamped on the interim result.
131
+ const m = r1.result._meta as Record<string, unknown>;
132
+ expect(m['io.modelcontextprotocol/serverInfo']).toBeDefined();
133
+
134
+ const r2 = await post(handler, { id: 2, args, state, action: 'accept' });
135
+ expect(r2.status).toBe(200);
136
+ expect(r2.result.resultType).toBe('complete');
137
+ expect(r2.result.isError).toBe(false);
138
+ expect(executions()).toBe(1);
139
+ });
140
+
141
+ it('interim input_required results are never cacheable', async () => {
142
+ const { handler } = mount();
143
+ const { result } = await post(handler, {});
144
+ expect('ttlMs' in result).toBe(false);
145
+ expect('cacheScope' in result).toBe(false);
146
+ });
147
+ });
148
+
149
+ describe('MRTR confirmation — refusals and re-prompts', () => {
150
+ for (const action of ['decline', 'cancel']) {
151
+ it(`${action} refuses the call without executing`, async () => {
152
+ const { handler, executions } = mount();
153
+ const r1 = await post(handler, { id: 1 });
154
+ const state = promptState(r1.result);
155
+
156
+ const r2 = await post(handler, { id: 2, state, action });
157
+ expect(r2.status).toBe(200);
158
+ expect(r2.result.resultType).toBe('complete');
159
+ expect(r2.result.isError).toBe(true);
160
+ expect(JSON.stringify(r2.result.content)).toContain(
161
+ 'confirmation declined',
162
+ );
163
+ expect(executions()).toBe(0);
164
+ });
165
+ }
166
+
167
+ it('a valid state with a missing answer re-prompts rather than erroring', async () => {
168
+ const { handler, executions } = mount();
169
+ const r1 = await post(handler, { id: 1 });
170
+ const state = promptState(r1.result);
171
+
172
+ // Echoed state, no inputResponses at all.
173
+ const r2 = await post(handler, { id: 2, state });
174
+ expect(r2.status).toBe(200);
175
+ promptState(r2.result);
176
+ expect(executions()).toBe(0);
177
+ });
178
+
179
+ it('an unknown action re-prompts rather than accepting', async () => {
180
+ const { handler, executions } = mount();
181
+ const r1 = await post(handler, { id: 1 });
182
+ const state = promptState(r1.result);
183
+
184
+ const r2 = await post(handler, { id: 2, state, action: 'maybe' });
185
+ promptState(r2.result);
186
+ expect(executions()).toBe(0);
187
+ });
188
+
189
+ it('a tampered state is audited, never honored, and re-prompted', async () => {
190
+ const { bridge, executions } = mrtrLockBridge();
191
+ const handler = createMcpHandler(bridge, { confirmationKey: KEY });
192
+ const r1 = await post(handler, { id: 1 });
193
+ const state = promptState(r1.result);
194
+
195
+ // Flip the last MAC character: authentic framing, forged tag.
196
+ const forged =
197
+ state.slice(0, -1) + (state.endsWith('A') ? 'B' : 'A');
198
+ const r2 = await post(handler, {
199
+ id: 2,
200
+ state: forged,
201
+ action: 'accept',
202
+ });
203
+ // Re-prompted with FRESH state, not executed.
204
+ const reissued = promptState(r2.result);
205
+ expect(reissued).not.toBe(forged);
206
+ expect(executions()).toBe(0);
207
+ });
208
+
209
+ it('records the rejection as a security-relevant audit event', () => {
210
+ const gate = new ElicitationConfirmGate(new TextEncoder().encode(KEY));
211
+ const leaf = {
212
+ path: ['purge'],
213
+ description: 'Purge a target',
214
+ properties: {},
215
+ class: { requiresConfirmation: true },
216
+ };
217
+ const decision = gate.evaluate(
218
+ { method: 'POST', headers: {}, body: '' },
219
+ leaf,
220
+ { name: 'purge', _meta: meta({}), requestState: 'v1.99999999999.AAAA' },
221
+ );
222
+ expect(decision?.result.resultType).toBe('input_required');
223
+ expect(gate.rejections).toEqual([
224
+ {
225
+ path: 'purge',
226
+ mcpConfirmRejection: 'request_state_verification_failed',
227
+ },
228
+ ]);
229
+ });
230
+
231
+ it('an authentic but expired state re-prompts WITHOUT an audit event', () => {
232
+ const gate = new ElicitationConfirmGate(new TextEncoder().encode(KEY));
233
+ const leaf = {
234
+ path: ['purge'],
235
+ description: 'Purge a target',
236
+ properties: {},
237
+ class: { requiresConfirmation: true },
238
+ };
239
+ const params = { name: 'purge', _meta: meta({}), arguments: {} };
240
+ const binding: McpConfirmBinding = {
241
+ tool: 'purge',
242
+ argsDigest: mcpConfirmArgsDigest(params),
243
+ principal: '',
244
+ };
245
+ // Authentic, minted under this key, but an hour stale.
246
+ const stale = mintMcpConfirmState(
247
+ new TextEncoder().encode(KEY),
248
+ binding,
249
+ Math.floor(Date.now() / 1000) - 3600,
250
+ );
251
+ const decision = gate.evaluate(
252
+ { method: 'POST', headers: {}, body: '' },
253
+ leaf,
254
+ { ...params, requestState: stale, inputResponses: { confirm: { action: 'accept' } } },
255
+ );
256
+ expect(decision?.result.resultType).toBe('input_required');
257
+ // Expiry is routine, not suspicious: no audit event.
258
+ expect(gate.rejections).toEqual([]);
259
+ });
260
+ });
261
+
262
+ describe('MRTR confirmation — state binding', () => {
263
+ it('state minted for one argument set cannot authorize another', async () => {
264
+ const { handler, executions } = mount();
265
+ const r1 = await post(handler, { id: 1, args: { target: 'data' } });
266
+ const state = promptState(r1.result);
267
+
268
+ // Same tool, same principal, DIFFERENT arguments.
269
+ const r2 = await post(handler, {
270
+ id: 2,
271
+ args: { target: 'everything' },
272
+ state,
273
+ action: 'accept',
274
+ });
275
+ promptState(r2.result);
276
+ expect(executions()).toBe(0);
277
+ });
278
+
279
+ it('state minted for one tool cannot authorize another', () => {
280
+ const key = new TextEncoder().encode(KEY);
281
+ const args = mcpConfirmArgsDigest({ arguments: { target: 'data' } });
282
+ const exp = Math.floor(Date.now() / 1000) + MCP_CONFIRM_STATE_TTL_SECONDS;
283
+ const state = mintMcpConfirmState(
284
+ key,
285
+ { tool: 'purge', argsDigest: args, principal: '' },
286
+ exp,
287
+ );
288
+ expect(
289
+ verifyMcpConfirmState(
290
+ key,
291
+ state,
292
+ { tool: 'widget purge', argsDigest: args, principal: '' },
293
+ Math.floor(Date.now() / 1000),
294
+ ),
295
+ ).toBe('invalid');
296
+ });
297
+
298
+ it('state minted for one principal cannot authorize another', async () => {
299
+ const { handler, executions } = mount();
300
+ const r1 = await post(handler, {
301
+ id: 1,
302
+ headers: { Authorization: 'Bearer alice' },
303
+ });
304
+ const state = promptState(r1.result);
305
+
306
+ const r2 = await post(handler, {
307
+ id: 2,
308
+ state,
309
+ action: 'accept',
310
+ headers: { Authorization: 'Bearer mallory' },
311
+ });
312
+ promptState(r2.result);
313
+ expect(executions()).toBe(0);
314
+
315
+ // The rightful principal is still able to redeem it.
316
+ const r3 = await post(handler, {
317
+ id: 3,
318
+ state,
319
+ action: 'accept',
320
+ headers: { Authorization: 'Bearer alice' },
321
+ });
322
+ expect(r3.result.resultType).toBe('complete');
323
+ expect(executions()).toBe(1);
324
+ });
325
+
326
+ it('argument key order does not change the digest', () => {
327
+ const a = mcpConfirmArgsDigest({ arguments: { x: 1, y: { b: 2, a: 3 } } });
328
+ const b = mcpConfirmArgsDigest({ arguments: { y: { a: 3, b: 2 }, x: 1 } });
329
+ expect(a).toBe(b);
330
+ });
331
+
332
+ it('a state minted under a different key never verifies', () => {
333
+ const binding: McpConfirmBinding = {
334
+ tool: 'purge',
335
+ argsDigest: mcpConfirmArgsDigest({}),
336
+ principal: '',
337
+ };
338
+ const exp = Math.floor(Date.now() / 1000) + MCP_CONFIRM_STATE_TTL_SECONDS;
339
+ const state = mintMcpConfirmState(
340
+ new TextEncoder().encode('a-completely-different-shared-secret'),
341
+ binding,
342
+ exp,
343
+ );
344
+ expect(
345
+ verifyMcpConfirmState(
346
+ new TextEncoder().encode(KEY),
347
+ state,
348
+ binding,
349
+ Math.floor(Date.now() / 1000),
350
+ ),
351
+ ).toBe('invalid');
352
+ });
353
+
354
+ it('any instance holding the same key verifies another instance state', async () => {
355
+ const a = mount();
356
+ const b = mount();
357
+ const r1 = await post(a.handler, { id: 1, args: { target: 'data' } });
358
+ const state = promptState(r1.result);
359
+
360
+ // Redeemed against a DIFFERENT mount: statelessness, not a store.
361
+ const r2 = await post(b.handler, {
362
+ id: 2,
363
+ args: { target: 'data' },
364
+ state,
365
+ action: 'accept',
366
+ });
367
+ expect(r2.result.resultType).toBe('complete');
368
+ expect(b.executions()).toBe(1);
369
+ expect(a.executions()).toBe(0);
370
+ });
371
+ });
372
+
373
+ describe('verifyMcpConfirmState — structural defects', () => {
374
+ const key = new TextEncoder().encode(KEY);
375
+ const binding: McpConfirmBinding = {
376
+ tool: 'purge',
377
+ argsDigest: mcpConfirmArgsDigest({}),
378
+ principal: '',
379
+ };
380
+ const now = Math.floor(Date.now() / 1000);
381
+
382
+ for (const [label, state] of [
383
+ ['empty', ''],
384
+ ['two parts', 'v1.123'],
385
+ ['four parts', 'v1.123.abc.def'],
386
+ ['unknown version', 'v2.99999999999.AAAA'],
387
+ ['non-decimal expiry', 'v1.0x40.AAAA'],
388
+ ['exponent expiry', 'v1.1e10.AAAA'],
389
+ ['padded expiry', 'v1. 123.AAAA'],
390
+ ['undecodable tag', 'v1.99999999999.!!!!'],
391
+ ] as const) {
392
+ it(`${label} is invalid`, () => {
393
+ expect(verifyMcpConfirmState(key, state, binding, now)).toBe('invalid');
394
+ });
395
+ }
396
+
397
+ it('an authentic state past its expiry is expired, not invalid', () => {
398
+ const state = mintMcpConfirmState(key, binding, now - 1);
399
+ expect(verifyMcpConfirmState(key, state, binding, now)).toBe('expired');
400
+ });
401
+
402
+ it('a tampered expiry fails the MAC and is invalid, never expired', () => {
403
+ const state = mintMcpConfirmState(key, binding, now - 1);
404
+ const [, , mac] = state.split('.');
405
+ const bumped = `v1.${now + 3600}.${mac}`;
406
+ expect(verifyMcpConfirmState(key, bumped, binding, now)).toBe('invalid');
407
+ });
408
+ });
409
+
410
+ describe('MRTR confirmation — the header gate still stands', () => {
411
+ it('a client without elicitation capability falls back to the header gate', async () => {
412
+ const { handler, executions } = mount();
413
+
414
+ // No elicitation declared: refused at 428, NOT prompted.
415
+ const refused = await post(handler, { meta: meta() });
416
+ expect(refused.status).toBe(428);
417
+ expect(refused.result.isError).toBe(true);
418
+ expect(JSON.stringify(refused.result.content)).toContain(
419
+ 'confirmation required',
420
+ );
421
+ expect('inputRequests' in refused.result).toBe(false);
422
+ expect(executions()).toBe(0);
423
+
424
+ // With the header, the same client proceeds.
425
+ const ok = await post(handler, {
426
+ id: 2,
427
+ meta: meta(),
428
+ headers: { 'X-Confirm-Token': 'yes' },
429
+ });
430
+ expect(ok.status).toBe(200);
431
+ expect(ok.result.resultType).toBe('complete');
432
+ expect(executions()).toBe(1);
433
+ });
434
+
435
+ it('a url-only elicitation client cannot receive the form request', async () => {
436
+ const { handler } = mount();
437
+ const refused = await post(handler, { meta: meta({ url: {} }) });
438
+ expect(refused.status).toBe(428);
439
+ expect('inputRequests' in refused.result).toBe(false);
440
+ });
441
+
442
+ it('an elicitation object naming form is honored', async () => {
443
+ const { handler } = mount();
444
+ const { result } = await post(handler, { meta: meta({ form: {} }) });
445
+ promptState(result);
446
+ });
447
+
448
+ for (const [label, declared] of [
449
+ ['null', null],
450
+ ['non-object', 'form'],
451
+ ['array', []],
452
+ ] as const) {
453
+ it(`a ${label} elicitation declaration falls back to the header gate`, async () => {
454
+ const { handler } = mount();
455
+ const refused = await post(handler, { meta: meta(declared) });
456
+ expect(refused.status).toBe(428);
457
+ });
458
+ }
459
+
460
+ it('a mount with NO key keeps the header gate for everyone', async () => {
461
+ const { handler, executions } = mount({ key: undefined });
462
+
463
+ // Elicitation-capable, but there is no key to MAC state with.
464
+ const refused = await post(handler, { meta: meta({}) });
465
+ expect(refused.status).toBe(428);
466
+ expect('inputRequests' in refused.result).toBe(false);
467
+ expect('requestState' in refused.result).toBe(false);
468
+ expect(executions()).toBe(0);
469
+
470
+ const ok = await post(handler, {
471
+ id: 2,
472
+ meta: meta({}),
473
+ headers: { 'X-Confirm-Token': 'yes' },
474
+ });
475
+ expect(ok.result.resultType).toBe('complete');
476
+ expect(executions()).toBe(1);
477
+ });
478
+
479
+ it('rejects an empty confirmation key at mount time', () => {
480
+ expect(() =>
481
+ createMcpHandler(mrtrLockBridge().bridge, { confirmationKey: '' }),
482
+ ).toThrow(/empty key/);
483
+ });
484
+ });
485
+
486
+ describe('MRTR confirmation — leaves outside the gate', () => {
487
+ it('a leaf that does not require confirmation is never prompted', async () => {
488
+ const handler = createMcpHandler(modernLockBridge(), {
489
+ confirmationKey: KEY,
490
+ });
491
+ const { status, result } = await post(handler, {
492
+ tool: 'ping',
493
+ meta: meta({}),
494
+ });
495
+ expect(status).toBe(200);
496
+ expect(result.resultType).toBe('complete');
497
+ expect('inputRequests' in result).toBe(false);
498
+ });
499
+
500
+ it('MRTR never relaxes the destructive ceiling', async () => {
501
+ // `vault burn` is destructive AND requires confirmation, so it
502
+ // travels the WHOLE loop and still meets the policy gate behind
503
+ // it. Satisfying confirmation is not a way to bypass the ceiling.
504
+ const { handler, executions } = mount();
505
+ const r1 = await post(handler, { id: 1, tool: 'vault.burn' });
506
+ const state = promptState(r1.result);
507
+
508
+ const r2 = await post(handler, {
509
+ id: 2,
510
+ tool: 'vault.burn',
511
+ state,
512
+ action: 'accept',
513
+ });
514
+ expect(r2.status).toBe(200);
515
+ expect(r2.result.resultType).toBe('complete');
516
+ expect(r2.result.isError).toBe(true);
517
+ expect(JSON.stringify(r2.result.content)).toContain('destructive');
518
+ expect(executions()).toBe(0);
519
+ });
520
+ });