From 17d555a1c7232a727f98278ee768add29b5a6141 Mon Sep 17 00:00:00 2001 From: Kay Robbins Date: Tue, 10 Nov 2026 11:56:06 -0600 Subject: [PATCH] Report a HED key nested beside a valid one in a sidecar entry Move the hed-tests pin to babc444, which adds the case sidecar-invalid-hed-key-nested-beside-valid, and add unit tests. Co-Authored-By: Claude Opus 5.5 --- spec_tests/hed-tests | 2 +- src/bids/types/json.js | 6 ++++++ tests/otherTests/issueParameters.spec.js | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spec_tests/hed-tests b/spec_tests/hed-tests index c49d5556..babc4440 160000 --- a/spec_tests/hed-tests +++ b/spec_tests/hed-tests @@ -1 +1 @@ -Subproject commit c49d5556e5bafb4985db8180a203448740e5b08b +Subproject commit babc44406dfede6590de63bba5bb48792f97c817 diff --git a/src/bids/types/json.js b/src/bids/types/json.js index 77ae603c..b81a53f8 100644 --- a/src/bids/types/json.js +++ b/src/bids/types/json.js @@ -200,6 +200,12 @@ export class BidsSidecar extends BidsJsonFile { } if (BidsSidecar._sidecarValueHasHed(value)) { + // The second-level HED key is valid, but a HED key deeper in the same entry is not. + for (const [subkey, subvalue] of Object.entries(value)) { + if (subkey !== 'HED') { + this._verifyKeyHasNoDeepHed(subkey, subvalue, key) + } + } return [key, new BidsSidecarKey(key, value.HED, this)] } diff --git a/tests/otherTests/issueParameters.spec.js b/tests/otherTests/issueParameters.spec.js index 54f4cd52..c70bbbf8 100644 --- a/tests/otherTests/issueParameters.spec.js +++ b/tests/otherTests/issueParameters.spec.js @@ -98,6 +98,29 @@ describe('Issue Parameters Tests', () => { expect(thrownError.issue.parameters.key).toBe('event_code') }) + test.each([ + ['in a sibling object', { trial: { HED: 'Red', metadata: { HED: 'Blue' } } }], + ['deep in a sibling object', { trial: { HED: { face: 'Red' }, extra: { inner: { HED: 'Blue' } } } }], + ])('should throw error for a deep HED key %s beside a valid second-level HED', (_, invalidData) => { + const thrownError = captureError(invalidData) + + expectError(thrownError, 'illegalSidecarHedDeepKey', 'SIDECAR_INVALID') + expect(thrownError.issue.parameters.key).toBe('trial') + expect(thrownError.issue.parameters.sidecarKey).toBe('trial') + }) + + test('should not throw error for sibling metadata without HED beside a valid second-level HED', () => { + const sidecar = new BidsSidecar( + 'test.json', + { path: 'test.json' }, + { + trial: { HED: { face: 'Red' }, Levels: { face: 'A face' }, Description: 'Trial type' }, + }, + ) + expect(sidecar).toBeInstanceOf(BidsSidecar) + expect(sidecar.sidecarKeys.has('trial')).toBe(true) + }) + test('should validate complete error structure and message', () => { const invalidData = createInvalidData(3) const thrownError = captureError(invalidData)