Skip to content

Commit ab6684f

Browse files
fix(contracts): anchor the predicate double-cast annotation to the cast
`check:api-validation:strict` counted 9 unannotated double-casts against a baseline of 8, failing CI. The predicate leaf schema was annotated, but the annotation sat above the declaration while the checker anchors on the line carrying the cast — five lines below, at the close of the object literal. The scanner walks back at most three lines and stops at the first non-comment one, so it hit `value: z.unknown().optional(),` and never saw the reason. Splitting the object schema from the cast puts them adjacent, so the existing reason binds. No behavior change — the cast, the schema, and the reasoning are unchanged. Also lowers the rawJsonReads ratchet 6 -> 5 to match the current count, which had drifted down; leaving it high lets a removed raw read silently come back. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5fea5f7 commit ab6684f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

apps/sim/lib/api/contracts/tables.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,16 @@ function predicateTreeTooLarge(root: unknown): string | null {
477477
* before it ran. Strict on BOTH branches is required: strict on the group alone
478478
* would just fall through to the leaf branch, which is the more dangerous reading.
479479
*/
480-
// double-cast-allowed: `z.unknown()` keeps the runtime permissive (a leaf value
481-
// is arbitrary JSON), but infers `unknown`, which is wider than
482-
// `Predicate['value']`. The narrowing is type-level only — nothing is coerced.
483-
const predicateLeafSchema = z.strictObject({
480+
const predicateLeafObjectSchema = z.strictObject({
484481
field: z.string().min(1, 'field is required').max(128),
485482
op: z.enum(FILTER_OPS),
486483
value: z.unknown().optional(),
487-
}) as unknown as z.ZodType<Predicate>
484+
})
485+
486+
// double-cast-allowed: `z.unknown()` keeps the runtime permissive (a leaf value
487+
// is arbitrary JSON), but infers `unknown`, which is wider than
488+
// `Predicate['value']`. The narrowing is type-level only — nothing is coerced.
489+
const predicateLeafSchema = predicateLeafObjectSchema as unknown as z.ZodType<Predicate>
488490

489491
const predicateNodeSchema: z.ZodType<PredicateNode> = z.lazy(() =>
490492
z.union([predicateGroupSchema, predicateLeafSchema])

scripts/check-api-validation-contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const BOUNDARY_POLICY_BASELINE = {
2525
clientHookRawFetches: 0,
2626
clientSameOriginApiFetches: 0,
2727
doubleCasts: 8,
28-
rawJsonReads: 6,
28+
rawJsonReads: 5,
2929
untypedResponses: 0,
3030
annotationsMissingReason: 0,
3131
} as const

0 commit comments

Comments
 (0)