@devries-cameron20 / composio Mirror · read-only / commits / c151daa2f
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 08:30 UTC

test(json-schema-to-zod): skip subnormal `multipleOf` cases the Ajv oracle underflows on (#4985)

This PR: - fixes a flaky failure in `property-semantics.test.ts`, seen on https://github.com/ComposioHQ/composio/actions/runs/39299841251/job/118221829145 (PR #4976, unrelated to its change) - skips generated cases where `multipleOf` is set and the value is subnormal, with `fc.pre`, and lists the exclusion with the other oracle limits in the file header - adds `does not treat a subnormal as an integer multiple` to `semantic-regressions.test.ts`, pinning that every builder rejects `-5e-324` for `multipleOf: 5` while Ajv accepts it ## Context fast-check generated `{ multipleOf: 5 }` with `-5e-324`, the smallest subnormal double. Ajv checks `(value / 5) % 1 === 0` in floating point, and `-5e-324 / 5` underflows to `-0`, so Ajv accepts. The converter's exact decimal check (`isJsonMultipleOf`) correctly rejects it: `-5e-324` is not a multiple of 5. The converter is right, and the oracle can't express this case. Verified: replaying the CI seed (`seed: -2109801589, path: "97"`) fails all builders on `next` and passes on this branch. `pnpm --filter @composio/json-schema-to-zod test` (2301 passed), `typecheck`, oxlint and prettier pass.

Alberto Schiabel committed Oct 20, 2026 at 17:50 UTC c151daa2f0aa711389952f0c0877dbb1a57f1e5b
2 files changed +22
ts/packages/json-schema-to-zod/test/property-semantics.test.ts
+12
@@ -13,6 +13,11 @@
13 * - `multipleOf` is always an integer: the converter checks decimal
14 * multiples through decimal scaling (see the `primitive-float-multiple-of`
15 * corpus case) while the oracle uses raw float modulo
16 + * - subnormal numbers are skipped under `multipleOf`: the oracle divides in
17 + * floating point, and `-5e-324 / 5` underflows to `-0`, so Ajv calls a
18 + * subnormal a multiple of any small integer. The converter's exact check
19 + * rejects it (see "does not treat a subnormal as an integer multiple" in
20 + * semantic-regressions.test.ts)
21 * - draft-4 boolean `exclusiveMinimum`/`exclusiveMaximum` are never
22 * generated: they are not part of Draft 7, so the oracle cannot express
23 * them (the `primitive-draft4-boolean-exclusive-bounds` corpus case covers
@@ -117,10 +122,17 @@ const schemaAndInstance: fc.Arbitrary<{ schema: SchemaRecord; value: Serializabl
122
123 const ajv = new Ajv({ strict: false });
124
125 +/** Smallest positive normal double; anything nonzero below it is subnormal. */
126 +const MIN_NORMAL = 2 ** -1022;
127 +const isSubnormal = (value: Serializable): boolean =>
128 + typeof value === 'number' && value !== 0 && Math.abs(value) < MIN_NORMAL;
129 +
130 describe.each(builders)('scalar conversion matches the Draft 7 oracle ($name)', builder => {
131 it('accepts exactly what Ajv accepts, standalone and object-wrapped', () => {
132 fc.assert(
133 fc.property(schemaAndInstance, ({ schema, value }) => {
134 + fc.pre(!(schema.multipleOf !== undefined && isSubnormal(value)));
135 +
136 const objectSchema = {
137 type: 'object',
138 properties: { value: schema },
ts/packages/json-schema-to-zod/test/semantic-regressions.test.ts
+10
@@ -327,6 +327,16 @@ describe.each(builders)('whole-schema semantic regressions ($name)', builder =>
327 expect(builder.convert(schema).safeParse(value).success).toBe(false);
328 });
329
330 + it('does not treat a subnormal as an integer multiple', () => {
331 + const schema: JsonSchema = { type: 'number', multipleOf: 5 };
332 + const value = -5e-324;
333 +
334 + // Ajv divides in floating point and `-5e-324 / 5` underflows to `-0`, so the
335 + // oracle accepts; the property suite skips this case for that reason.
336 + expect(ajv.compile(schema)(value), 'the oracle underflows on this fixture').toBe(true);
337 + expect(builder.convert(schema).safeParse(value).success).toBe(false);
338 + });
339 +
340 it('keeps a guarded object root a ZodObject with its shape', () => {
341 const schema: JsonSchema = {
342 type: 'object',