Skip to content

fix: correct array handling in Schema.resolve - #106

Open
ehennestad wants to merge 2 commits into
fix-meta-type-property-introspectionfrom
fix-schema-resolve-array-handling
Open

fix: correct array handling in Schema.resolve#106
ehennestad wants to merge 2 commits into
fix-meta-type-property-introspectionfrom
fix-schema-resolve-array-handling

Conversation

@ehennestad

@ehennestad ehennestad commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Three defects in the loop in Schema.resolve. All of them only appear when resolve is called on an array of instances, which is why the existing tests, which all resolve a scalar, did not catch them.

The loop stopped at the first already-resolved element

if ~obj(i).IsReference
    if options.NumLinksToResolve == 0
        fprintf('Instance is already resolved.\n')
        instance(i) = obj(i);
        return          % <- leaves the method, not the iteration

An element that is already resolved and has no link depth left needs no work, but returning ends the whole method. Every reference positioned after a resolved element in the array was silently left unresolved. [resolvedPerson, referencePerson].resolve() resolved neither.

Link depth leaked between array elements

options.NumLinksToResolve was decremented on the shared options struct inside the loop, so the budget spent following the links of one element was taken away from the next. Resolving a two-element array with a depth of 1 gave the first element a depth of 1 and the second a depth of 0. The depth is a budget per element, and each element now derives its own remaining depth from the original value rather than mutating it.

The already-resolved case printed to the command window

Resolving an instance that needs no work is not an event worth reporting, and a library function should not write to stdout regardless. The message appeared three times in a full test run.

Other changes

Resolver selection moves into a private selectLinkResolver method. That removes a level of nesting and lets the two branches of the loop read as the two cases they are: resolve this node, or follow its links.

Still outstanding

The recursive call discards the value returned by resolve:

linkedInstances{j}.resolve(nvPairs{:});

A resolver that populates a node in place therefore works, but one that has to build a new instance and return it has no effect. That is the normal case for a stub whose type is not known until it is probed — MixedTypeReference in this repository, and the referenceNode = [] branch of KGResolver in openminds-kg-sync. Fixing it needs the parent, property name and index at the point of resolution, which is the per-edge traversal protocol in #69. It is not addressed here.

Tests

Three cases added to ResolverTest, one per defect: that the loop continues past a resolved element, that the second array element gets the same depth budget as the first, and that resolving an already-resolved instance produces no command window output.

🤖 Generated with Claude Code

Three defects in the same loop, all of which only show up when resolve is
called on an array of instances.

An element that was already resolved and had no link depth left returned
from the method instead of moving to the next element, so every reference
after the first resolved element was silently left unresolved.

The link depth was decremented on the shared options struct inside the
loop, so depth spent on one element was taken away from the next. Each
element now derives its own remaining depth.

The already-resolved case wrote to the command window. Resolving an
instance that needs no work is not an event worth reporting, and the
message appeared three times in a full test run.

Resolver selection moves to a private method, which removes a level of
nesting from the loop.

Note that the recursive call still discards the instance returned by
resolve, so a resolver that replaces a node rather than populating it in
place has no effect. That needs the traversal rework in openMINDS-MATLAB
issue #69 and is not addressed here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Test Results (R2022a)

743 tests   726 ✅  2m 29s ⏱️
 19 suites   16 💤
  1 files      1 ❌

For more details on these failures, see this check.

Results for commit cf77ac2.

♻️ This comment has been updated with latest results.

@ehennestad
ehennestad force-pushed the fix-schema-resolve-array-handling branch from 2cd08b4 to cf77ac2 Compare August 27, 2026 23:40
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (fix-meta-type-property-introspection@7388b4c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
code/internal/+openminds/+abstract/Schema.m 85.71% 3 Missing ⚠️
Additional details and impacted files
@@                           Coverage Diff                           @@
##             fix-meta-type-property-introspection     #106   +/-   ##
=======================================================================
  Coverage                                        ?   78.91%           
=======================================================================
  Files                                           ?      417           
  Lines                                           ?     4031           
  Branches                                        ?        0           
=======================================================================
  Hits                                            ?     3181           
  Misses                                          ?      850           
  Partials                                        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ehennestad
ehennestad force-pushed the fix-schema-resolve-array-handling branch 7 times, most recently from 932c7e8 to cf77ac2 Compare August 28, 2026 12:59
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.

1 participant