Skip to content

Commit 3a4cf75

Browse files
committed
test(anthropic): lock the structured-output schema non-mutation invariant
The builder deep-clones before walking so it never deletes enum/const from the caller's schema object. Agent blocks inside a parallel or loop reuse the same responseFormat object across iterations, so losing that clone would strip the constraints from every iteration after the first. Verified the test fails when the clone is removed.
1 parent 1f6e843 commit 3a4cf75

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎apps/sim/providers/anthropic/core.request.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,23 @@ describe('executeAnthropicProviderRequest native structured outputs', () => {
506506
expect(wireSchema.properties.off.const).toBe(false)
507507
})
508508

509+
it("does not mutate the caller's schema, so parallel iterations reuse it safely", async () => {
510+
const shared = {
511+
type: 'object',
512+
additionalProperties: false,
513+
required: ['kind'],
514+
properties: { kind: { type: 'string', enum: ['a', 'b'], description: 'd' } },
515+
}
516+
const before = JSON.stringify(shared)
517+
518+
const first = await sendSchema(shared)
519+
const second = await sendSchema(shared)
520+
521+
expect(JSON.stringify(shared)).toBe(before)
522+
expect(first.properties.kind.enum).toEqual(['a', 'b'])
523+
expect(second.properties.kind.enum).toEqual(['a', 'b'])
524+
})
525+
509526
it('does not mistake a property literally named enum for a keyword', async () => {
510527
const wireSchema = await sendSchema({
511528
type: 'object',

0 commit comments

Comments
 (0)