135
expect(sent(systemOne).state).toMatchObject({ context: { thread: 't1' } });
136
});
137
138
+ it('sends no context key when getContext returns null', async () => {
139
+ const { gate, systemOne } = gateWith(0.9, { getContext: () => null });
140
+ await gate(context);
141
+ expect(sent(systemOne).state).not.toHaveProperty('context');
142
+ });
143
+
144
it('hands redactArguments a copy, so redacting in place leaves the executed call alone', async () => {
145
const before = structuredClone(params.arguments);
146
const { gate, systemOne } = gateWith(0.9, {
177
});
178
});
179
180
+ it('lets a redactor mask a null leaf to null and keeps the executed call original', async () => {
181
+ const callArguments = { ...params.arguments, flag: null };
182
+ const executedParams = { ...params, arguments: callArguments };
183
+ const { gate, systemOne } = gateWith(0.9, {
184
+ redactArguments: (_slug, args) => ({ ...args, flag: null }),
185
+ });
186
+ const executed = await gate({ ...context, params: executedParams });
187
+ expect(executed).toBe(executedParams);
188
+ const call = sent(systemOne).state as {
189
+ proposed_call: { arguments: Record<string, unknown> };
190
+ };
191
+ expect(call.proposed_call.arguments).toEqual(callArguments);
192
+ });
193
+
194
it.each<[string, Partial<TypesafeGateOptions>, Record<string, unknown>]>([
195
['a redactor that returns no object', { redactArguments: () => 'secret' as never }, {}],
196
[
206
{ redactArguments: (_slug, args) => ({ ...args, password: 42 }) },
207
{},
208
],
209
+ [
210
+ 'a redactor that replaces a null leaf with an object',
211
+ { redactArguments: (_slug, args) => ({ ...args, flag: { controlled: 'data' } }) },
212
+ { flag: null },
213
+ ],
214
[
215
'a redactor that shortens an array',
216
{ redactArguments: (_slug, args) => ({ ...args, to: (args.to as string[]).slice(1) }) },
255
}
256
);
257
258
+ it.each<[string, unknown]>([
259
+ ['an empty string', ''],
260
+ ['a numeric string', '0.9'],
261
+ ['a boolean', true],
262
+ ['NaN', Number.NaN],
263
+ ])('rejects a threshold of %s when the gate is built, not at check time', (_label, value) => {
264
+ expect(() =>
265
+ new TypesafeProvider({ client: mockClient(() => undefined).client }).confidenceGate({
266
+ tools,
267
+ getRequest: () => 'email ada',
268
+ threshold: value as never,
269
+ })
270
+ ).toThrow(TypesafeInvalidOptionsError);
271
+ });
272
+
273
const unavailable = Object.assign(new Error('down'), {
274
name: 'InternalServerError',
275
status: 503,