@kya-os/mcp-i-runtime 1.3.1 → 1.3.3
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/.turbo/turbo-build.log +1 -1
- package/dist/auth/handshake.d.ts +23 -43
- package/dist/auth/handshake.d.ts.map +1 -1
- package/dist/auth/handshake.js +51 -82
- package/dist/auth/handshake.js.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/resume-token.d.ts +52 -0
- package/dist/auth/resume-token.d.ts.map +1 -0
- package/dist/auth/resume-token.js +89 -0
- package/dist/auth/resume-token.js.map +1 -0
- package/dist/auth/types.d.ts +15 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/dist/proof/companion.d.ts +25 -0
- package/dist/proof/companion.d.ts.map +1 -0
- package/dist/proof/companion.js +14 -0
- package/dist/proof/companion.js.map +1 -0
- package/dist/proof/generator.d.ts +22 -9
- package/dist/proof/generator.d.ts.map +1 -1
- package/dist/proof/generator.js +20 -27
- package/dist/proof/generator.js.map +1 -1
- package/dist/proof/index.d.ts +2 -1
- package/dist/proof/index.d.ts.map +1 -1
- package/dist/proof/index.js +3 -1
- package/dist/proof/index.js.map +1 -1
- package/dist/runtime/audit.d.ts.map +1 -1
- package/dist/runtime/audit.js +78 -18
- package/dist/runtime/audit.js.map +1 -1
- package/dist/runtime/base.d.ts +6 -1
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +65 -17
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/dif-core.d.ts +8 -0
- package/dist/runtime/dif-core.d.ts.map +1 -1
- package/dist/runtime/dif-core.js +10 -0
- package/dist/runtime/dif-core.js.map +1 -1
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +12 -5
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/claims-first-guard.d.ts +33 -0
- package/dist/services/claims-first-guard.d.ts.map +1 -0
- package/dist/services/claims-first-guard.js +77 -0
- package/dist/services/claims-first-guard.js.map +1 -0
- package/dist/services/holder-keys.d.ts +95 -0
- package/dist/services/holder-keys.d.ts.map +1 -0
- package/dist/services/holder-keys.js +281 -0
- package/dist/services/holder-keys.js.map +1 -0
- package/dist/services/holder-read-slots.d.ts +42 -0
- package/dist/services/holder-read-slots.d.ts.map +1 -0
- package/dist/services/holder-read-slots.js +82 -0
- package/dist/services/holder-read-slots.js.map +1 -0
- package/dist/services/proof-verifier.d.ts +13 -35
- package/dist/services/proof-verifier.d.ts.map +1 -1
- package/dist/services/proof-verifier.js +16 -74
- package/dist/services/proof-verifier.js.map +1 -1
- package/dist/services/request-holder.d.ts +78 -0
- package/dist/services/request-holder.d.ts.map +1 -0
- package/dist/services/request-holder.js +81 -0
- package/dist/services/request-holder.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -1
- package/dist/services/tool-context-builder.js +16 -4
- package/dist/services/tool-context-builder.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +7 -0
- package/dist/services/tool-protection.service.d.ts.map +1 -1
- package/dist/services/tool-protection.service.js +34 -15
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/tool-protection.d.ts +94 -0
- package/dist/types/tool-protection.d.ts.map +1 -1
- package/dist/types/tool-protection.js +113 -1
- package/dist/types/tool-protection.js.map +1 -1
- package/eslint.config.js +20 -0
- package/package.json +8 -2
- package/src/__tests__/runtime/amount-limit-enforcement.test.ts +269 -0
- package/src/__tests__/runtime/amount-limit-result.test.ts +61 -0
- package/src/__tests__/runtime/audit-contracts-compat.test.ts +20 -5
- package/src/__tests__/runtime/audit.test.ts +363 -53
- package/src/__tests__/runtime/process-tool-call-security.test.ts +97 -13
- package/src/__tests__/runtime/provider-selection.test.ts +4 -6
- package/src/__tests__/runtime/route-interception.test.ts +215 -214
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +89 -6
- package/src/__tests__/services/tool-protection-amount.test.ts +107 -0
- package/src/__tests__/services/tool-protection-failsafe.test.ts +71 -4
- package/src/__tests__/utils/tool-protection-runtime.ts +3 -0
- package/src/auth/__tests__/verify-or-hints-presented.test.ts +155 -0
- package/src/auth/handshake.ts +80 -125
- package/src/auth/index.ts +1 -0
- package/src/auth/resume-token.ts +134 -0
- package/src/auth/types.ts +20 -2
- package/src/index.ts +40 -1
- package/src/proof/__tests__/proof-generator.test.ts +80 -13
- package/src/proof/companion.ts +35 -0
- package/src/proof/generator.ts +51 -33
- package/src/proof/index.ts +3 -0
- package/src/runtime/__tests__/ext-apps-consent.test.ts +87 -2
- package/src/runtime/audit.ts +170 -65
- package/src/runtime/base.ts +95 -31
- package/src/runtime/dif-core.ts +16 -0
- package/src/services/__tests__/access-control.service.test.ts +44 -0
- package/src/services/__tests__/claims-first-guard.test.ts +93 -0
- package/src/services/__tests__/holder-fixtures.ts +135 -0
- package/src/services/__tests__/holder-keys.test.ts +257 -0
- package/src/services/__tests__/holder-read-slots.test.ts +117 -0
- package/src/services/__tests__/holder-reads.test.ts +284 -0
- package/src/services/__tests__/proof-verifier.test.ts +286 -195
- package/src/services/__tests__/request-holder.test.ts +210 -0
- package/src/services/__tests__/tool-context-builder-authtype.test.ts +79 -0
- package/src/services/__tests__/tool-context-builder.test.ts +4 -7
- package/src/services/__tests__/tool-protection-served-revision.test.ts +102 -0
- package/src/services/access-control.service.ts +11 -5
- package/src/services/claims-first-guard.ts +89 -0
- package/src/services/holder-keys.ts +379 -0
- package/src/services/holder-read-slots.ts +85 -0
- package/src/services/proof-verifier.ts +18 -79
- package/src/services/request-holder.ts +146 -0
- package/src/services/tool-context-builder.ts +19 -4
- package/src/services/tool-protection.service.ts +62 -19
- package/src/types/tool-protection.ts +161 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
import type { MCPIRuntimeBase } from "../../runtime/base";
|
|
3
|
+
import { createToolProtectionRuntime } from "../utils/tool-protection-runtime";
|
|
4
|
+
import {
|
|
5
|
+
AmountLimitError,
|
|
6
|
+
DelegationRequiredError,
|
|
7
|
+
isToolProtectionUnenforceableError,
|
|
8
|
+
type ToolProtectionUnenforceableError,
|
|
9
|
+
} from "../../types/tool-protection";
|
|
10
|
+
import { terminalForToolError } from "../../runtime/audit";
|
|
11
|
+
|
|
12
|
+
const SCOPE = "payments:send";
|
|
13
|
+
const LIMIT = { value: "50.00", currency: "USD" };
|
|
14
|
+
const AMOUNT_CONFIG = { argument: "amount", currency: "USD" };
|
|
15
|
+
|
|
16
|
+
const session = {
|
|
17
|
+
id: "session123",
|
|
18
|
+
audience: "https://client.example.com",
|
|
19
|
+
nonce: "test-nonce",
|
|
20
|
+
delegationToken: "delegation-token",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const verifyResponse = (constraints?: Record<string, unknown>) => ({
|
|
24
|
+
success: true,
|
|
25
|
+
data: {
|
|
26
|
+
valid: true,
|
|
27
|
+
credential: {
|
|
28
|
+
agent_did: "did:key:zmock123",
|
|
29
|
+
scopes: [SCOPE],
|
|
30
|
+
...(constraints === undefined ? {} : { constraints }),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const grantWithLimit = (maxAmount: unknown = LIMIT) =>
|
|
36
|
+
verifyResponse({
|
|
37
|
+
crisp: {
|
|
38
|
+
scopes: [{ resource: SCOPE, matcher: "exact", maxAmount }],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("amount limit enforcement", () => {
|
|
43
|
+
let runtime: MCPIRuntimeBase;
|
|
44
|
+
let protectionService: { checkToolProtection: ReturnType<typeof vi.fn> };
|
|
45
|
+
let accessControl: { verifyDelegation: ReturnType<typeof vi.fn> };
|
|
46
|
+
const handler = vi.fn().mockResolvedValue({ result: "success" });
|
|
47
|
+
|
|
48
|
+
const protect = (amount?: unknown) =>
|
|
49
|
+
protectionService.checkToolProtection.mockResolvedValue({
|
|
50
|
+
requiresDelegation: true,
|
|
51
|
+
requiredScopes: [SCOPE],
|
|
52
|
+
...(amount === undefined ? {} : { amount }),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const call = (args: unknown) =>
|
|
56
|
+
runtime.processToolCall("send_payment", args, handler, session);
|
|
57
|
+
|
|
58
|
+
const failure = async (args: unknown) =>
|
|
59
|
+
(await call(args).catch((error: unknown) => error)) as AmountLimitError;
|
|
60
|
+
|
|
61
|
+
beforeEach(async () => {
|
|
62
|
+
vi.clearAllMocks();
|
|
63
|
+
({
|
|
64
|
+
runtime,
|
|
65
|
+
mockToolProtectionService: protectionService,
|
|
66
|
+
mockAccessControlService: accessControl,
|
|
67
|
+
} = await createToolProtectionRuntime());
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("leaves a tool with no amount config untouched even when the grant carries a limit", async () => {
|
|
71
|
+
protect();
|
|
72
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
73
|
+
await expect(call({ amount: "1000000.00" })).resolves.toEqual({
|
|
74
|
+
result: "success",
|
|
75
|
+
});
|
|
76
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(handler.mock.calls[0][1]).toMatchObject({
|
|
78
|
+
constraints: { crisp: { scopes: [{ maxAmount: LIMIT }] } },
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it.each(["50.00", "50", "49.99", 50, "0"])(
|
|
83
|
+
"passes an amount of %j against a 50.00 USD limit",
|
|
84
|
+
async (amount) => {
|
|
85
|
+
protect(AMOUNT_CONFIG);
|
|
86
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
87
|
+
await expect(call({ amount })).resolves.toEqual({ result: "success" });
|
|
88
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
it.each(["50.01", 50.01])(
|
|
93
|
+
"refuses an amount of %j against a 50.00 USD limit and names the limit",
|
|
94
|
+
async (amount) => {
|
|
95
|
+
protect(AMOUNT_CONFIG);
|
|
96
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
97
|
+
const error = await failure({ amount });
|
|
98
|
+
expect(error).toBeInstanceOf(AmountLimitError);
|
|
99
|
+
expect(error).not.toBeInstanceOf(DelegationRequiredError);
|
|
100
|
+
expect(error.code).toBe("amount_limit_exceeded");
|
|
101
|
+
expect(error.toolName).toBe("send_payment");
|
|
102
|
+
expect(error.violation).toEqual({
|
|
103
|
+
code: "amount_limit_exceeded",
|
|
104
|
+
scope: SCOPE,
|
|
105
|
+
limit: LIMIT,
|
|
106
|
+
amount: "50.01",
|
|
107
|
+
});
|
|
108
|
+
expect(error.message).toBe(
|
|
109
|
+
'Tool "send_payment" refused under scope "payments:send": amount 50.01 USD exceeds the delegated limit of 50.00 USD. Nothing was executed.'
|
|
110
|
+
);
|
|
111
|
+
expect(error.toJSON()).toEqual({
|
|
112
|
+
error: "amount_limit_exceeded",
|
|
113
|
+
message: error.message,
|
|
114
|
+
toolName: "send_payment",
|
|
115
|
+
scope: SCOPE,
|
|
116
|
+
limit: LIMIT,
|
|
117
|
+
amount: "50.01",
|
|
118
|
+
});
|
|
119
|
+
expect(handler).not.toHaveBeenCalled();
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
it("reads the limit from the delegation record when the verifier returns no credential", async () => {
|
|
124
|
+
protect(AMOUNT_CONFIG);
|
|
125
|
+
accessControl.verifyDelegation.mockResolvedValue({
|
|
126
|
+
success: true,
|
|
127
|
+
data: {
|
|
128
|
+
valid: true,
|
|
129
|
+
delegation: {
|
|
130
|
+
constraints: {
|
|
131
|
+
crisp: {
|
|
132
|
+
scopes: [{ resource: SCOPE, matcher: "exact", maxAmount: LIMIT }],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
expect((await failure({ amount: "50.01" })).code).toBe(
|
|
139
|
+
"amount_limit_exceeded"
|
|
140
|
+
);
|
|
141
|
+
expect(handler).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("refuses a configured tool that requires no scope before any amount check", async () => {
|
|
145
|
+
protectionService.checkToolProtection.mockResolvedValue({
|
|
146
|
+
requiresDelegation: true,
|
|
147
|
+
requiredScopes: [],
|
|
148
|
+
amount: AMOUNT_CONFIG,
|
|
149
|
+
});
|
|
150
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
151
|
+
const error = await call({ amount: "1.00" }).catch((e: unknown) => e);
|
|
152
|
+
expect(isToolProtectionUnenforceableError(error)).toBe(true);
|
|
153
|
+
expect((error as ToolProtectionUnenforceableError).missing).toEqual([
|
|
154
|
+
"requiredScopes",
|
|
155
|
+
]);
|
|
156
|
+
expect(accessControl.verifyDelegation).not.toHaveBeenCalled();
|
|
157
|
+
expect(handler).not.toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("refuses a currency mismatch from the tool config", async () => {
|
|
161
|
+
protect({ argument: "amount", currency: "EUR" });
|
|
162
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
163
|
+
const error = await failure({ amount: "1.00" });
|
|
164
|
+
expect(error.code).toBe("amount_currency_mismatch");
|
|
165
|
+
expect(handler).not.toHaveBeenCalled();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("refuses a currency mismatch read from the call arguments", async () => {
|
|
169
|
+
protect({ argument: "amount", currency: { argument: "ccy" } });
|
|
170
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
171
|
+
await expect(call({ amount: "1.00", ccy: "USD" })).resolves.toEqual({
|
|
172
|
+
result: "success",
|
|
173
|
+
});
|
|
174
|
+
const error = await failure({ amount: "1.00", ccy: "EUR" });
|
|
175
|
+
expect(error.code).toBe("amount_currency_mismatch");
|
|
176
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it.each([
|
|
180
|
+
["abc", "amount_malformed"],
|
|
181
|
+
["-5", "amount_malformed"],
|
|
182
|
+
["1e3", "amount_malformed"],
|
|
183
|
+
[null, "amount_malformed"],
|
|
184
|
+
[undefined, "amount_missing"],
|
|
185
|
+
])("refuses an amount of %j when configured", async (amount, code) => {
|
|
186
|
+
protect(AMOUNT_CONFIG);
|
|
187
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
188
|
+
const error = await failure({ amount });
|
|
189
|
+
expect(error.code).toBe(code);
|
|
190
|
+
expect(handler).not.toHaveBeenCalled();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("refuses a call with no arguments at all when configured", async () => {
|
|
194
|
+
protect(AMOUNT_CONFIG);
|
|
195
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
196
|
+
const error = await failure(undefined);
|
|
197
|
+
expect(error.code).toBe("amount_missing");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it.each([
|
|
201
|
+
["no constraints on the credential", verifyResponse()],
|
|
202
|
+
["constraints without crisp", verifyResponse({ not_after: 1 })],
|
|
203
|
+
[
|
|
204
|
+
"a crisp scope without maxAmount",
|
|
205
|
+
verifyResponse({
|
|
206
|
+
crisp: { scopes: [{ resource: SCOPE, matcher: "exact" }] },
|
|
207
|
+
}),
|
|
208
|
+
],
|
|
209
|
+
[
|
|
210
|
+
"a maxAmount on a different scope",
|
|
211
|
+
verifyResponse({
|
|
212
|
+
crisp: {
|
|
213
|
+
scopes: [
|
|
214
|
+
{ resource: "other:scope", matcher: "exact", maxAmount: LIMIT },
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
}),
|
|
218
|
+
],
|
|
219
|
+
["no credential at all", { success: true, data: { valid: true } }],
|
|
220
|
+
])(
|
|
221
|
+
"passes a configured tool when the grant has %s",
|
|
222
|
+
async (_name, response) => {
|
|
223
|
+
protect(AMOUNT_CONFIG);
|
|
224
|
+
accessControl.verifyDelegation.mockResolvedValue(response);
|
|
225
|
+
await expect(call({ amount: "999999.00" })).resolves.toEqual({
|
|
226
|
+
result: "success",
|
|
227
|
+
});
|
|
228
|
+
await expect(call({})).resolves.toEqual({ result: "success" });
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
it("refuses when the delegated limit is malformed", async () => {
|
|
233
|
+
protect(AMOUNT_CONFIG);
|
|
234
|
+
accessControl.verifyDelegation.mockResolvedValue(
|
|
235
|
+
grantWithLimit({ value: "-5", currency: "USD" })
|
|
236
|
+
);
|
|
237
|
+
const error = await failure({ amount: "1.00" });
|
|
238
|
+
expect(error.code).toBe("amount_limit_malformed");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("refuses when the tool amount config is invalid and a limit applies", async () => {
|
|
242
|
+
protect({ argument: "", currency: "USD" });
|
|
243
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
244
|
+
const error = await failure({ amount: "1.00" });
|
|
245
|
+
expect(error.code).toBe("amount_config_invalid");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("does not consult the amount when the delegation itself is refused", async () => {
|
|
249
|
+
protect(AMOUNT_CONFIG);
|
|
250
|
+
accessControl.verifyDelegation.mockResolvedValue({
|
|
251
|
+
success: true,
|
|
252
|
+
data: { valid: false, error: { code: "delegation_revoked" } },
|
|
253
|
+
});
|
|
254
|
+
await expect(call({ amount: "1000.00" })).rejects.toBeInstanceOf(
|
|
255
|
+
DelegationRequiredError
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("records the refusal as a denied terminal event", async () => {
|
|
260
|
+
protect(AMOUNT_CONFIG);
|
|
261
|
+
accessControl.verifyDelegation.mockResolvedValue(grantWithLimit());
|
|
262
|
+
const error = await failure({ amount: "50.01" });
|
|
263
|
+
expect(terminalForToolError(error)).toEqual({
|
|
264
|
+
phase: "denied",
|
|
265
|
+
outcome: "denied",
|
|
266
|
+
reasonCode: "AMOUNT_LIMIT_EXCEEDED",
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { AMOUNT_LIMIT_CODES } from "@kya-os/contracts/delegation";
|
|
3
|
+
import { readToolRefusal } from "@kya-os/contracts/config";
|
|
4
|
+
import {
|
|
5
|
+
AmountLimitError,
|
|
6
|
+
amountLimitToolResult,
|
|
7
|
+
amountRefusalCode,
|
|
8
|
+
} from "../../types/tool-protection";
|
|
9
|
+
|
|
10
|
+
const exceeded = () =>
|
|
11
|
+
new AmountLimitError("send_payment", {
|
|
12
|
+
code: "amount_limit_exceeded",
|
|
13
|
+
scope: "payments:send",
|
|
14
|
+
limit: { value: "50.00", currency: "USD" },
|
|
15
|
+
amount: "50.01",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("amountLimitToolResult", () => {
|
|
19
|
+
it("is an isError result whose text is the error JSON, plus the refusal marker", () => {
|
|
20
|
+
expect(amountLimitToolResult(exceeded())).toEqual({
|
|
21
|
+
content: [
|
|
22
|
+
{
|
|
23
|
+
type: "text",
|
|
24
|
+
text: JSON.stringify({
|
|
25
|
+
error: "amount_limit_exceeded",
|
|
26
|
+
message:
|
|
27
|
+
'Tool "send_payment" refused under scope "payments:send": amount 50.01 USD exceeds the delegated limit of 50.00 USD. Nothing was executed.',
|
|
28
|
+
toolName: "send_payment",
|
|
29
|
+
scope: "payments:send",
|
|
30
|
+
limit: { value: "50.00", currency: "USD" },
|
|
31
|
+
amount: "50.01",
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
isError: true,
|
|
36
|
+
_meta: { "ai.kya-os/refusal": { code: "AMOUNT_LIMIT_EXCEEDED" } },
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("adds only a marker to the text and isError fields", () => {
|
|
41
|
+
expect(Object.keys(amountLimitToolResult(exceeded())).sort()).toEqual([
|
|
42
|
+
"_meta",
|
|
43
|
+
"content",
|
|
44
|
+
"isError",
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each(AMOUNT_LIMIT_CODES)("marks %s with its upper-case code", (code) => {
|
|
49
|
+
const error = new AmountLimitError("send_payment", {
|
|
50
|
+
code,
|
|
51
|
+
scope: "payments:send",
|
|
52
|
+
limit: { value: "50.00", currency: "USD" },
|
|
53
|
+
amount: "1.00",
|
|
54
|
+
} as never);
|
|
55
|
+
|
|
56
|
+
expect(amountRefusalCode(code)).toBe(code.toUpperCase());
|
|
57
|
+
expect(readToolRefusal(amountLimitToolResult(error))).toEqual({
|
|
58
|
+
code: code.toUpperCase(),
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -15,25 +15,40 @@ vi.mock("@kya-os/contracts/config", async (importOriginal) => {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
const { terminalForToolError } = await import("../../runtime/audit");
|
|
18
|
-
const { DelegationRequiredError } = await import(
|
|
19
|
-
"../../types/tool-protection"
|
|
20
|
-
);
|
|
18
|
+
const { DelegationRequiredError } = await import("../../types/tool-protection");
|
|
21
19
|
const { toDelegationDenial } = await import("../../runtime/delegation-denial");
|
|
22
20
|
|
|
23
21
|
describe("audit denial mapping against an older contracts release", () => {
|
|
24
|
-
it("still records a verifier denial as denied", () => {
|
|
22
|
+
it("still records a stateful verifier denial as denied", () => {
|
|
25
23
|
const error = new DelegationRequiredError(
|
|
26
24
|
"orders.place",
|
|
27
25
|
["orders:place"],
|
|
28
26
|
"https://example.com/consent",
|
|
29
27
|
undefined,
|
|
30
28
|
"resume_token",
|
|
31
|
-
toDelegationDenial("
|
|
29
|
+
toDelegationDenial("max_calls_exceeded")
|
|
32
30
|
);
|
|
33
31
|
|
|
34
32
|
expect(terminalForToolError(error)).toEqual({
|
|
35
33
|
phase: "denied",
|
|
36
34
|
outcome: "denied",
|
|
35
|
+
reasonCode: "BUDGET_EXCEEDED",
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("still records a refused grant a new grant could fix as challenged", () => {
|
|
40
|
+
const error = new DelegationRequiredError(
|
|
41
|
+
"orders.place",
|
|
42
|
+
["orders:place"],
|
|
43
|
+
"https://example.com/consent",
|
|
44
|
+
undefined,
|
|
45
|
+
"resume_token",
|
|
46
|
+
toDelegationDenial("delegation_revoked")
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(terminalForToolError(error)).toEqual({
|
|
50
|
+
phase: "challenged",
|
|
51
|
+
outcome: "challenged",
|
|
37
52
|
reasonCode: "DELEGATION_REVOKED",
|
|
38
53
|
});
|
|
39
54
|
});
|