test(examples): assert generated inferred types contain no unknown recursively - #395
Conversation
…cursively Adds a compile-time DeepHasUnknown<T> assertion over the inferred z.infer<> types and model interfaces of committed generated output (canada_holidays cycles for #383, resend nullable arrays/objects for #390 and the object-null fix, plus a large example for breadth). The existing property test only checked generated source text for the "unknown" substring, which a z.infer collapse to unknown (the #383 shape) can bypass; this checks the inferred type itself, recursively, and self-tests that the detector actually fires. Claude-Session: https://claude.ai/code/session_01JdgDU9EqCzmdNFm3gb2gFj
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds ChangesCompile-time unknown leak assertion harness
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. Comment |
Fallow audit reportFound 3 findings. Dead code (1)
Dependencies (2)
Generated by fallow. |
| @@ -0,0 +1,183 @@ | |||
| // Compile-time assertions: generated inferred types must contain no unknown in named fields. | |||
There was a problem hiding this comment.
warn fallow/unused-file: File is not reachable from any entry point
Run
fallow fix --filesor delete this file.
Summary
The prior schema-shape property test only checked generated SOURCE TEXT for the "unknown" substring. This can be bypassed by a
z.infercollapse to unknown: the #383 shape where source text saysz.ZodTypewith no literal "unknown" substring, but the inferred type resolves tounknown. This adds a TYPE-LEVEL recursiveDeepHasUnknown<T>assertion over inferred types (model interfaces + z.infer), providing compile-time proof that INFERRED types contain no unknown in any named field recursively.Changes
DeepHasUnknown<T>detector for model interfaces andz.inferresultsunknownwhen input_schema is enabled (z.lazy + bare: z.ZodType) #383 cyclic cases (canada_holidays), bug(openapi-gen): nullable array (type: ["array","null"]) with items emits z.unknown() instead of z.array(...) #390 nullable arrays + object-null (resend), and large breadth example (spotify).passthrough()catchall index signatureexamples/type-assertions.tswired intoexamples/tsconfig.jsonincludeTesting
pnpm --filter @codewithagents/examples run typecheckpasses locallypnpm fallow:auditexits 0 (fallow "unused file" warning is warn-level only, expected for type-only assertion)Notes
test:change. Release Please will NOT create a version bump.Summary by CodeRabbit