Repository navigation
fix(profile): pick employment fields from an unrefined schema - #912
Merged
Merged
Conversation
zod 4.6 refuses `.pick()` on an object that carries a refinement:
Error: .pick() cannot be used on object schemas containing refinements
zod 4.1 allowed it and quietly dropped the refinement, which is the only
reason the five employment cards worked. Each one picks a single field out
of `profileEmploymentInputSchema` inside its save handler, and that schema
ends in `.superRefine(...)`. On 4.6 the `.pick()` throws before `safeParse`
is reached, inside an event handler — so ticking a licence class, a
military status, an availability window, a work location or typing an
hourly rate would save nothing, and say nothing.
That is what made #870 (the backend Dependabot group, zod 4.1.13 -> 4.6.5)
red: 9 failures in profile-employment-left.test.tsx, every one an
array-valued field. Latent on main today, since main is still on 4.1.13.
## Changes
`profileEmploymentBaseSchema` is the `z.object({...}).partial()`, exported
on its own. `profileEmploymentInputSchema` is now that base plus the
cross-field travel rule. Routers and whole-payload validation keep using
the refined one and are unchanged; the cards pick from the base.
The five cards each swapped to the base schema. They also each had:
if (!result.success) return
which discards something the user just chose without a toast, a log or a
console warning. That is what turned a library guard into invisible data
loss — the throw and the silent-discard path lead to the same place. Each
now logs a warning with the zod issues before returning.
`employment-schema-pick.test.ts` asserts that every field the cards pick is
pickable without throwing, that a picked field still enforces its own rules
(3-location max), and that the refined schema still rejects `open_to_travel`
with no distance. It fails the moment a refinement is attached to the schema
the cards import.
## Verification
Ran both suites against zod 4.6.5 by temporarily moving the catalog pin,
then reverted it — the bump itself belongs to #870, not here:
zod 4.1.13, before -> 40 passed, 0 failed (the pin hid the bug)
zod 4.6.5, before -> 31 passed, 9 failed
zod 4.6.5, after -> 49 passed, 0 failed
scf-core full suite 1267 passed / 0 failed on 4.1.13; scf-core and
scaffald-app typecheck and lint clean.
Note: `packages/supabase/functions/_shared/schemas/consolidated.ts` is a
near-duplicate of the scf-trpc copy that nothing imports — the cards resolve
through `@scf/supabase/client-types` to `@scf/trpc/schemas`. Changed in
lockstep so the two do not drift further apart; the duplication itself is
left alone.
Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #910.
zod 4.6 refuses
.pick()on an object that carries a refinement:zod 4.1 allowed it and quietly dropped the refinement, which is the only reason the five employment cards worked. Each picks a single field out of
profileEmploymentInputSchemainside its save handler, and that schema ends in.superRefine(...). On 4.6 the.pick()throws beforesafeParseis reached, inside an event handler — so ticking a licence class, a military status, an availability window, a work location, or typing an hourly rate would save nothing and say nothing.That is what made #870 red. Latent on
maintoday, which is still on zod 4.1.13.Changes
profileEmploymentBaseSchemais thez.object({…}).partial(), exported on its own.profileEmploymentInputSchemais now that base plus the cross-field travel rule — routers and whole-payload validation are unchanged. The five cards pick from the base.They also each had this:
A validation failure discards something the user just chose, with no toast, no log, nothing. That is what turned a library guard into invisible data loss: the throw and the silent-discard path lead to the same place, and neither is observable. Each now logs the zod issues before returning. I'd argue that half matters more than the schema split — the split fixes this bug, the logging is why the next one won't be silent.
employment-schema-pick.test.tsasserts every field the cards pick is pickable without throwing, that a picked field still enforces its own rules (the 3-location max), and that the refined schema still rejectsopen_to_travelwith no distance. It fails the moment a refinement is attached to the schema the cards import — which is the only way to catch this before a browser does.Verification
Ran both suites against zod 4.6.5 by temporarily moving the catalog pin, then reverted it — the bump belongs to #870, not here:
Plus on 4.1.13:
scf-corefull suite 1267 passed / 0 failed,scf-coreandscaffald-apptypecheck and lint clean,pnpm prepushgreen.One thing I found and did not fix
packages/supabase/functions/_shared/schemas/consolidated.tsis a near-duplicate ofpackages/scf-trpc/src/schemas/consolidated.ts— they differ by an import path and one line whereProfileEmploymentOutputis inferred from the input schema in the scf-trpc copy. Nothing imports the_sharedone: the cards resolve through@scf/supabase/client-types→@scf/trpc/schemas→ scf-trpc. I changed both in lockstep so they do not drift further, but a dead 700-line duplicate of the schema that everything actually depends on is worth deleting in its own PR.🤖 Generated with Claude Code