Skip to content

did.document + did.database: tolerant depends_on entry-key reads#137

Merged
stevevanhooser merged 1 commit into
V2from
claude/801-did-document-dependency-accessors
May 21, 2026
Merged

did.document + did.database: tolerant depends_on entry-key reads#137
stevevanhooser merged 1 commit into
V2from
claude/801-did-document-dependency-accessors

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

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 at did.database/validate_doc_vs_schema line 1292, which reads depends(idx2).value directly.

What changed

did.document

  • Constructor calls a new static helper i_normalizeDependsOn(body) so subsequent accessors can rely on the invariant: after construction, depends_on entries use document_id.
  • i_readDependencyTarget(entry) (new, static-hidden) — tolerant single-entry reader accepting document_id / value / id with that precedence.
  • dependency_value, dependency_value_n route reads through i_readDependencyTarget.
  • set_dependency_value builds d_struct with document_id and writes document_id on update; direct struct-array assignment is 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.

did.database

  • validate_doc_vs_schema line ~1292: dependency-resolution loop migrated from depends(idx2).value to did.document.i_readDependencyTarget(depends(idx2)). V_delta bodies (with document_id) now pass through the V_alpha validator without MATLAB:nonExistentField.

Sweep

  • src/did/+did/+fun/docs2graph.m
  • src/did/+did/+fun/finddocs_missing_dependencies.m

both migrated to use the helper.

Tests

  • TestInvalidModification.m: immutable-fields list 'depends_on.value''depends_on.document_id'.
  • TestDbQueries.m: direct .value read migrated to use the helper.
  • make_doc_tree_invalid.m: invalid-document fabricator wrote depends_on(k).value; updated to depends_on(k).document_id so the fixtures match the canonical shape.

Coordination

  • This PR is independent of did-schema and merges into V2 freely.
  • Once merged, ndi-matlab #802 CI re-runs against fresh did-matlab/V2 and should clear the MATLAB:nonExistentField failures.
  • Test plan: did-matlab's existing test_document.m exercises the set_dependency_value / dependency_value round-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

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.
Comment thread src/did/+did/document.m
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( ...
@stevevanhooser stevevanhooser merged commit 943118c into V2 May 21, 2026
3 checks passed
@stevevanhooser stevevanhooser deleted the claude/801-did-document-dependency-accessors branch May 21, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants