did2: enforce superclasses-chain consistency in validateDocument#132
Merged
Conversation
V_gamma_SPEC (inherited unchanged by V_delta per conversions/from_did_v1/_universal_renames.md §4) requires that document_class.superclasses match the schema-derived chain class-name-by-class-name. validateDocument previously only checked that one property block existed per chain class; a hand-built or serialised doc could pass with a truncated or reordered superclasses array, which silently breaks transitive isa queries downstream (notably ndi-cloud-node's classLineage computation). - cache.validateDocument now compares dc.superclasses to obj.superclasses(className) and raises did2:validation:superclassesChainMismatch (or :missingSuperclasses / :badSuperclassEntry) on drift. - v1_to_v2.ensureClassBlocks rebuilds document_class.superclasses from the schema cache after per-class migrators run, so v1 inputs whose chain order/membership drifts from V_delta still produce spec-compliant output. - testSchemaCache covers truncated, reordered, missing-field, and malformed-entry cases, plus the base-class empty-chain accept.
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.
Summary
Closes the last gap between V_delta's spec and did2-matlab's validator:
document_class.superclassesmust equal the schema-derived chain class-name-by-class-name (V_gamma_SPEC.md §"Validation checklist", inherited unchanged by V_delta perconversions/from_did_v1/_universal_renames.md§4).validateDocumentpreviously only required one property block per chain class — a hand-built or partially-migrated doc could pass with a truncated or reorderedsuperclassesarray, which silently breaks transitiveisaqueries downstream. The clearest example is ndi-cloud-node'sclassLineagefield, which is computed fromdocument_class.superclasses[*].class_nameand never independently resolves the schema chain — so the writer must emit the full transitive closure.Changes
src/did/+did2/+schema/cache.m:validateDocumentnow comparesdc.superclassestoobj.superclasses(className)and raises one of three errors on drift:did2:validation:missingSuperclasses— the field is absent.did2:validation:badSuperclassEntry— an entry lacksclass_name.did2:validation:superclassesChainMismatch— wrong length, wrong order, or wrong names.Added a small
superclassClassNameshelper that normalises the[]/ scalar-struct / struct-array shapes the same way the existing BFS does.src/did/+did2/+convert/v1_to_v2.m:ensureClassBlocksnow also rebuildsdocument_class.superclassesfrom the schema cache after per-class migrators run. Necessary because the v1→v2 pipeline previously preserved the v1 chain verbatim — when V_delta has reordered or extended the chain (e.g.,oridirtuning_calcaddingtuning_fit), the migrated doc would now fail the new check. Migrators still see the v1-shaped chain when they dispatch; the rewrite happens after.tests/+did2/+unittest/testSchemaCache.m: five new tests covering truncated chain, reordered chain, missing-field, malformed-entry, andbase's legitimate empty-chain case.Why this matters for the NDI-matlab did2 migration
ndi-cloud-node's
classLineageis the index backingisaqueries. It's populated from the document'sdocument_class.superclassesarray verbatim — no schema traversal, no graph walk. The cloud trusts the writer. This change makes the writer trustworthy by failing loudly the moment a non-spec-compliant chain shows up, rather than letting it ship to Mongo and silently miss documents on every ancestor-class query.Test plan
did2.unittest.testSchemaCachepasses (new chain-consistency tests).did2.unittest.testConvertV1ToV2passes (verifies the migrator rebuild).Generated by Claude Code