…jectui#8416)
`validateSchema(schema: any)` was a bare `any` on a published parameter. The
declaration moves by one token to `schema: unknown`, and every value is still
assignable, so no call site outside `@object-ui/core` had to move: the function
is not generic and returns the concrete `SchemaNodeValidationResult`, which
names no parameter type.
The half with teeth is the implementation. `validateSchema` calls four rules
unconditionally and only `validateBaseSchema` ever checked that it had an
object, so `validateFormSchema` (`schema.type`) and `validateChildren`
(`schema.children`) read straight through and `validateSchema(null)` threw a raw
`TypeError` instead of returning the `INVALID_SCHEMA` result its own contract
promises. The single guard now runs once, in `validateSchema`, before any rule
reads a key; the four rules take a narrowed `SchemaNodeUnderValidation` whose
keys are `unknown`. A `null` entry inside a form's `fields` array threw the same
way and is now reported as `MISSING_FIELD_NAME`.
No verdict that already existed changes: the guard's accept set is the one it
replaces, spelled the same way, and a 29-case matrix diffed before and after
shows every difference is a value that used to throw.
`scripts/check-doc-example-types.mjs`: the two `schema-validator.ts` ledger rows
are re-derived (490 -> 550, 515 -> 575) because their keys carry a line number
and this diff moved those JSDoc blocks. Verdicts unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH
Fixes #8416
validateSchemain@object-ui/coretookschema: any— a bareanyon a publishedparameter. This narrows it to
unknownand makes the implementation narrow the valuebefore it reads a key off it.
The card's premise, measured before relying on it
The card graded this cheap on one argument: for a parameter,
anytounknowniscaller-compatible, so the cost lands inside the implementation. It supplied its own
falsifier — if the return type or generics thread the parameter's
anyoutward, it stopsbeing caller-compatible. Measured, not inherited:
validateSchemaSchemaNodeValidationResult, which names no parameter typevalidateSchema(schema: any, path?: string)becomesvalidateSchema(schema: unknown, path?: string)SchemaNodeUnderValidationandisSchemaNodeShapeare module-private and appear in no published.d.ts(grepped across everypackages/*/dist)packages/corepackages/react/src/SchemaRenderer.tsx:84, which passes a value already typedany. It needed no change —@object-ui/reacttype-checkand its twoSchemaRenderersuites (49 tests) pass untouchedThe falsifier does not fire, and the re-grade trigger was not hit. No call site outside
this package moved.
The half that is not a type annotation
validateSchemacalls four rules unconditionally and only one of them ever checked ithad an object.
validateBaseSchemarefused a non-object and returned;validateRetiredNodeTypeused optional chaining; but
validateFormSchemareadschema.typeandvalidateChildrenread
schema.childrenstraight through. So, measured on256c709e2before the change:SchemaRendererwraps its call in atry/catchcommented "Validator itself failed —surface but don't crash render". That catch is where the crash was landing in the one
shipped consumer.
The guard now runs once, in
validateSchema, before any rule reads a key; the fourrules take a narrowed node type whose keys are all
unknown. The same defect one leveldown goes with it: a
nullentry inside a form'sfieldsarray threw the same way.Accept-set delta — 29 cases, diffed before and after
Both matrices were produced from a real build: the pre-change one by restoring the base
file, rebuilding
@object-ui/core, confirming the mutation reacheddist/(distdeclaredvalidateSchema(schema: any), then probing.25 of 29 identical. The four that moved:
nullTypeErrorINVALID_SCHEMAatschemaundefinedTypeErrorINVALID_SCHEMAatschema{ type: 'form', fields: [null] }TypeErrorMISSING_FIELD_NAMEatschema.fields[0]{ type: 'form', fields: [namedFunction] }valid: trueMISSING_FIELD_NAMEatschema.fields[0]The first three are a crash becoming the documented refusal. The fourth is a genuine
refusal-set widening and it is why this is declared
Clause-②: yesbelow: a namedfunction satisfied
field.namethroughFunction.prototype.name. It is a corner JSONcannot express, and function values on this family's mirrors are already refused
(objectui#6124) — but that changeset names
@object-ui/types' zodvalidateSchema, notthis structural one, so there is no published contract text that already covers it.
Everything else holds: an array node keeps
MISSING_REQUIRED(typeof []is'object',and the replaced guard let it through too), primitives keep their single
INVALID_SCHEMA,nullholes insidechildrenare still skipped, thebodydialect still resolves, nestedretired types are still refused by path, and no new error
codeis emitted.Verification
Every command was run from the repo root. Readings are quoted from each tool's own verdict
line, and the union below was run at
f5cb148f5, the final commit.Ablation — from the committed tree, mutation proved on disk first. The mutation is
git checkout 256c709e2 -- packages/core/src/validation/schema-validator.ts, i.e. revertingthe narrowing wholesale.
isSchemaNodeShape7 to 0,schema: unknown1 to 0; blob hash3802177toe27f547, equal to the base blob and different from the head blob.../schema-validator.jsto package source, notdist— nobuild sits between the mutation and the run.
takes every value UNCAST, which is what makes the narrowing caller-compatible`validateSchema(null)` returns INVALID_SCHEMA instead of throwing a raw TypeError`validateSchema(undefined)` returns INVALID_SCHEMA instead of throwing a raw TypeError`isValidSchema(null)` answers `false`, which is the boolean its docblock promises`assertValidSchema(null)` throws the validator's OWN refusal, not a TypeErrora `null` entry inside `fields` is REPORTED, not thrown onschema-validator.test.ts,predicate-valued-gate-rules.test.tsandform-field-widget-namespace.test.ts, plus this file's own five behaviour-preservationcases. The mutation is surgical; the harness is live.
git diff HEADempty and the blob back at3802177.The type-level half fires under
tsc, not vitest, and is shown doing it. The pin is acompile-time refusal (the mechanism objectui#3181 established for this package), and
tsc -p tsconfig.test.json --listFilesconfirms the file is in that program (1 hit of 234).Under the same mutation:
Gate enumeration, on both axes. Asked which tests read this file or path, and
separately what lines did my change move.
scripts/__tests__/body-dialect-census.test.ts:198asserts this file stillcontains the literal
schema.children || schema.body. It does — the narrowing kept thatexpression byte-identical. Green.
scripts/check-doc-example-types.mjskeys its ledger bypath:line symbol,and two rows point into this file. My diff moved both JSDoc blocks down, so the rows were
re-derived from the file:
490to550(assertValidSchema) and515to575(
isValidSchema). Verdicts and codes unchanged. Same precedent as the objectui#8738 rowalready in that file.
Control that moves when the change is wrong: reverting just the
550row back to490makes
check:doc-examplesexit 1 withSTALE LEDGER ROW ...:490 assertValidSchemaandUNDECLARED FAILURE ...:550 assertValidSchema. The row edit is load-bearing, not cosmetic.Runs.
turbo run build $(node scripts/check-doc-snippet-types.mjs --build-filter) --concurrency=235 successful, 35 totalpnpm --filter @object-ui/core run type-checktsc --noEmit && tsc -p tsconfig.test.json)pnpm --filter @object-ui/react run type-checkpnpm exec vitest run packages/core/src/validation/Test Files 8 passed · Tests 144 passedpnpm exec vitest runon the twoSchemaRenderergate-diagnostic suitesTests 49 passedpnpm exec vitest run scripts/__tests__/body-dialect-census.test.ts scripts/__tests__/check-doc-example-types.test.ts scripts/__tests__/check-doc-example-shared-reader.test.tsTest Files 3 passed · Tests 87 passednode scripts/check-doc-example-types.mjs@examplecompiles, or fails exactly as its ledger row declares."node scripts/check-control-bytes.mjsscanned 7072 tracked text file(s)Lint — the complete units, not a narrowing. CI's lint job runs
pnpm lint(turbo, perpackage) plus
lint:root. My diff lives in exactly two of those units and both were runwhole:
@object-ui/core(234 files, 0 errors) and the root scope (305 files, 0errors, and
scripts/check-doc-example-types.mjsconfirmed present in the population).File counts are read from eslint's own
--format jsonoutput. Type-aware linting is notenabled anywhere in
eslint.config.js(zero occurrences ofproject), so this diff cannotmove the verdict of any file it does not itself contain — the other package units are
provably unaffected rather than merely unrun. The five surviving
@typescript-eslint/no-explicit-anywarnings in this file are all pre-existing and on linesthis diff does not touch; the file's bare
: anycount drops 13 to 5.Ratchets: none moved, measured.
KNOWN_BARE_ANY_EXAMPLESinscripts/check-skill-examples.mjsis an empty set whoseSCAN_ROOTSareskillsand.claude/skills— it cannot seepackages/**. A repo-wide grep forBARE_ANY/bare-anyfinds that script and its own test and nothing else, so there is no other bare-
anyratchetto move. No baseline was edited.
Governed surface: none touched.
node scripts/check-governed-queue-guard.mjs --testonall four changed paths answers
NOT GOVERNED — 4 path(s) checked against 5 governed surface(s); none matched.Clause-②: yes
Judged here, not inherited. The mechanical floor is clear: no new exported symbol and
no new key on a published payload (both grepped, above). What tips it is the fourth row
of the accept-set matrix — one input that validated before and is refused now. A
nowouldhave to cite published contract text that already declares that refusal; objectui#6124 is
the closest and it names a different symbol in a different package. Genuinely unsure, so:
yes. Theneeds:contract-reviewlabel is on this PR and on the card.Clause-②:line could not be added to the claim comment — the dispatching seat hasno comment-edit tool (objectstack#17213) — so this section and the report are where the
declaration lives. A second claim comment was deliberately not posted.
node scripts/pm/check-widening-tells.mjswas not used as evidence. Its bare CLI hasno repo flag and always judges as objectstack (objectstack#17217), and using the exported
judge with
reposet correctly does not rescue it here: the control fires as expected(
packages/types/src/zod/form.zod.tsis covered as objectui, not covered as objectstack),and under that same correct repo none of this diff's four files is covered by any
surface row. The tool has nothing to say about these paths in either direction.
验收备注
Observations found while reading the file. None is filed, and none is in this PR.
assertValidSchema(schema: any)andisValidSchema(value: any)sit directly belowvalidateSchemain the same file and are the same class — published parameters typedbare
any. They were left alone deliberately: the card scopes tovalidateSchema, andnarrowing two more published parameters is a second published-surface change on a card
graded p3.
assertValidSchema's ledger row already declares TS18046 (is of type 'unknown'), so touching it would also move a declared diagnostic. Successor: [finding]ComponentInput.defaultValue?: any(packages/types/src/base.ts:550) is why the marked plugin example inskills/objectuimust carry a bareany— tighten the contract tounknownand the baseline row retires with the guide #7493,the parent bare-
anycensus. noted, not filed.BASE_SCHEMA_RULESvalidators still readvalidate: (value: any), whilepredicateGateRulenext to them already reads(value: unknown). They consumeschema[key], which this change madeunknown, and each narrows withtypeofon itsfirst line, so nothing is unsound — it is an inconsistency the file's own
AuthoredFormFielddocblock already notes ("The rest of this file predates thatdiscipline"). Successor: [finding]
ComponentInput.defaultValue?: any(packages/types/src/base.ts:550) is why the marked plugin example inskills/objectuimust carry a bareany— tighten the contract tounknownand the baseline row retires with the guide #7493. noted, not filed.validateSchema([])reportsMISSING_REQUIREDrather than "schema must be an object",because
typeof []is'object'. Preserved exactly, and pinned by a test in this PR soit cannot drift silently. Whether an array node deserves its own refusal is a product
question, not a defect. noted, not filed.
with their subject — the class objectui#8875 was filed for this shift. No cross-file
path:lineaddress was written into any comment added here; the ledger comment names themoves in the file that owns them. noted, not filed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01611D6ZaRaMmwTNQmSbk8MH
Generated by Claude Code