Skip to content

fix: decode controlled instance files through the shared JSON-LD path - #119

Open
ehennestad wants to merge 1 commit into
add-external-integration-testfrom
unify-controlled-instance-reading
Open

fix: decode controlled instance files through the shared JSON-LD path#119
ehennestad wants to merge 1 commit into
add-external-integration-testfrom
unify-controlled-instance-reading

Conversation

@ehennestad

@ehennestad ehennestad commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

The last manual read paths inside the repository, found during the external-integration verification two PRs down.

Two readers decoded with raw jsondecode

Three places load controlled instance files from the local library. getControlledInstance (used by ControlledTermBase) already decoded through the shared JSON-LD utility, but InstanceResolver.resolveNode and HasControlledInstance.fromName used raw jsondecode, which mangles "@id" into the field name x_id. Everything downstream of those two readers therefore leaned on x_id fallback branches instead of the at_-form keywords every other decoded document carries.

All three readers now decode through openminds.internal.utility.json.decode. No code inside this repository produces x_-form structs any more.

The offline reader corrupted apostrophes

jsonStr = strrep(jsonStr, '''', ''''''); %If character array contains ', need to replace with ''

Doubling apostrophes inside JSON text is quoting for an evaluation context that no longer exists; applied before jsondecode it simply corrupts values. A definition written in the file as 'associative array' came back as ''associative array'' — visible today on openminds.controlledterms.DataType("associativeArray"). The online reader did not do this, so the same instance decoded differently depending on whether the file came from disk or from GitHub. The line is removed.

Why the x_id fallback branches stay

I planned to remove them with this change, and that plan was wrong. They are not dead compatibility code: openminds-kg-sync's convertKgNode decodes Knowledge Graph payloads with raw jsondecode and hands x_-form structs into openMINDS types — the branches are the contract that integration currently relies on. They can be removed only after kg-sync normalizes its payloads to at_-form (or decodes through the shared utility), which belongs to the kg-sync migration alongside the resolver rename from #108, not to this stack.

Tests

Three cases in ControlledInstanceTest: apostrophes in definitions are not doubled; an instance resolved from an IRI keeps its identifier and carries the file's content; an instance built by name through the mixin gets its identifier from the library file.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Test Results (R2022a)

770 tests  +770   769 ✅ +769   2m 48s ⏱️ + 2m 48s
 21 suites + 21     1 💤 +  1 
  1 files   +  1     0 ❌ ±  0 

Results for commit 39b42fc. ± Comparison against base commit c43a2c8.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Test Results (R2026a)

770 tests  +770   769 ✅ +769   2m 0s ⏱️ + 2m 0s
 21 suites + 21     1 💤 +  1 
  1 files   +  1     0 ❌ ±  0 

Results for commit 39b42fc. ± Comparison against base commit c43a2c8.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (add-external-integration-test@c43a2c8). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../+openminds/+internal/+resolver/InstanceResolver.m 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##             add-external-integration-test     #119   +/-   ##
================================================================
  Coverage                                 ?   80.03%           
================================================================
  Files                                    ?      422           
  Lines                                    ?     4067           
  Branches                                 ?        0           
================================================================
  Hits                                     ?     3255           
  Misses                                   ?      812           
  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 unify-controlled-instance-reading branch from a4dfbb9 to 416ce9b Compare September 1, 2026 14:31
Three readers load controlled instance files from the local library. One
of them decoded through the shared JSON-LD utility; the other two,
InstanceResolver.resolveNode and HasControlledInstance.fromName, used raw
jsondecode, which mangles @id into x_id. Everything downstream of those
two readers therefore leaned on x_id fallback branches rather than the
at_-form keywords every other decoded document carries. All three now
decode through openminds.internal.utility.json.decode, so no code inside
this repository produces x_-form structs any more.

The offline reader also doubled every apostrophe inside the JSON text
before decoding, a leftover from quoting for some earlier evaluation
context. A definition written as 'associative array' came back as
''associative array'', and because the online reader did not do this, the
same instance decoded differently depending on where the file came from.
The replacement is removed.

The x_id fallback branches themselves are deliberately kept. They are not
dead compatibility code: openminds-kg-sync converts Knowledge Graph
payloads with raw jsondecode and hands x_-form structs into openMINDS
types, so the branches are the contract that integration relies on. They
can only be removed after kg-sync normalizes its payloads to at_-form,
which belongs to the kg-sync migration, not to this stack.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ehennestad
ehennestad force-pushed the unify-controlled-instance-reading branch from 416ce9b to 39b42fc Compare September 1, 2026 20:58
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