did.document + did.database: tolerant depends_on entry-key reads#137
Merged
Merged
Conversation
Companion to ndi-matlab#802 / #801. ndi.document doesn't inherit from did.document -- they're parallel classes in different packages -- but did.document carries the same dependency-accessor surface and the same V_alpha (.id) / intermediate-draft (.value) / V_delta (.document_id) entry-key compat concern. Without this DID-matlab change, ndi-matlab #802 CI fails on the V_alpha validator (`did.database/validate_doc_vs_schema` line 1292 reads `depends(idx2).value` directly). Changes: src/did/+did/document.m - Constructor: call new static helper i_normalizeDependsOn on the body so subsequent accessors can rely on the invariant "after construction, depends_on entries use document_id". - dependency_value, dependency_value_n: route reads through the new static helper i_readDependencyTarget (tolerant of all three spellings: document_id > value > id). - set_dependency_value: builds d_struct with `document_id`; matches-found branch writes `document_id` on the entry. Direct struct-array assignment now safe since the constructor invariant keeps the schema uniform. - add_dependency_value_n: routes through set_dependency_value without building a `value`-keyed intermediate. - Two new static-hidden helpers: * i_readDependencyTarget(entry) - tolerant single-entry reader. * i_normalizeDependsOn(body) - constructor-time canonicaliser. src/did/+did/database.m - validate_doc_vs_schema (line ~1292): the dependency-resolution loop read `depends(idx2).value` directly. Migrated to use did.document.i_readDependencyTarget so V_delta bodies (with `document_id`) pass through the validator without exploding. Direct depends_on field-access sweep in src/did: - src/did/+did/+fun/docs2graph.m - src/did/+did/+fun/finddocs_missing_dependencies.m both migrated to use i_readDependencyTarget. Test updates: - tests/+did/+unittest/TestInvalidModification.m: the immutable- fields list referenced 'depends_on.value'; updated to 'depends_on.document_id' to match the V_delta canonical. - tests/+did/+unittest/TestDbQueries.m: direct .value read migrated to use the helper. - tests/+did/+test/+helper/+documents/make_doc_tree_invalid.m: the invalid-document fabricator wrote depends_on(k).value; updated to depends_on(k).document_id so the fabricated fixtures match the canonical shape and the validator actually tests the field the post-rename code uses.
| if numel(matches)>0 | ||
| notfound = 0; | ||
| d{i} = getfield(did_document_obj.document_properties.depends_on(matches(1)),'value'); | ||
| d{i} = did.document.i_readDependencyTarget( ... |
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.
Companion to vh-lab/ndi-matlab#802 (issue #801). ndi.document and did.document are parallel classes in different packages (not an inheritance relationship), but both carry the same dependency-accessor surface and the same V_alpha (
.id) / intermediate-draft (.value) / V_delta (.document_id) entry-key compat concern. Without this PR, ndi-matlab #802 CI fails on the V_alpha validator atdid.database/validate_doc_vs_schemaline 1292, which readsdepends(idx2).valuedirectly.What changed
did.documenti_normalizeDependsOn(body)so subsequent accessors can rely on the invariant: after construction, depends_on entries usedocument_id.i_readDependencyTarget(entry)(new, static-hidden) — tolerant single-entry reader acceptingdocument_id/value/idwith that precedence.dependency_value,dependency_value_nroute reads throughi_readDependencyTarget.set_dependency_valuebuildsd_structwithdocument_idand writesdocument_idon update; direct struct-array assignment is now safe since the constructor invariant keeps the schema uniform.add_dependency_value_nroutes throughset_dependency_valuewithout building avalue-keyed intermediate.did.databasevalidate_doc_vs_schemaline ~1292: dependency-resolution loop migrated fromdepends(idx2).valuetodid.document.i_readDependencyTarget(depends(idx2)). V_delta bodies (withdocument_id) now pass through the V_alpha validator withoutMATLAB:nonExistentField.Sweep
src/did/+did/+fun/docs2graph.msrc/did/+did/+fun/finddocs_missing_dependencies.mboth migrated to use the helper.
Tests
TestInvalidModification.m: immutable-fields list'depends_on.value'→'depends_on.document_id'.TestDbQueries.m: direct.valueread migrated to use the helper.make_doc_tree_invalid.m: invalid-document fabricator wrotedepends_on(k).value; updated todepends_on(k).document_idso the fixtures match the canonical shape.Coordination
MATLAB:nonExistentFieldfailures.set_dependency_value/dependency_valueround-trip. Other DID-matlab tests exercise V_alpha bodies (with.id) through the validator — the tolerant helper ensures those keep working too.Generated by Claude Code