did.query: fix shape-strict eqlen check on struct input#134
Merged
Conversation
did.query's one-arg struct-input branch validates that the input
struct carries exactly {field, operation, param1, param2}. The
check used a shape-strict comparison:
eqlen(sort(fieldnames(field)), sort({'field','operation','param1','param2'}))
sort(fieldnames(...)) returns a 4x1 cell; the literal is a 1x4
cell. eqlen routes through sizeeq, which requires identical
sizes, so the validator rejected every well-formed struct input
regardless of field membership.
Surfaced by VH-Lab/NDI-matlab PR #799 (the did2 #6 read-time
augmentation work): an acceptance test that constructed
ndi.query from a pre-built searchstructure tripped the check.
NDI-matlab side worked around it by swapping the test to the
cell-input form, but the underlying did.query bug remained.
Fix: build the literal as a column ({'field';'operation';...})
so sort() returns 4x1 on both sides. Field-set semantics are
unchanged (membership and count still strict).
Tests:
- test_struct_input_accepted: a well-formed searchstructure now
round-trips through did.query(struct) as documented.
- test_struct_input_rejects_unknown_fields: an extra field still
errors (regression guard so the shape fix doesn't accidentally
loosen the validator).
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.
Summary
did.query's one-arg struct-input branch validates that the input struct carries exactly{field, operation, param1, param2}. The check used a shape-strict comparison:sort(fieldnames(...))returns a4x1cell; the literal is1x4.eqlenroutes throughsizeeq, which requires identical sizes, so the validator rejected every well-formed struct input regardless of field membership. The struct-input form has been latent-broken since this code was written.Surfaced by VH-Lab/NDI-matlab#799 (the
[did2 #6]read-time augmentation work): an acceptance test that constructedndi.queryfrom a pre-built searchstructure tripped the check. NDI-matlab side worked around it by swapping the test to the cell-input form, but the underlyingdid.querybug remained.Fix
Build the expected-fields literal as a column (
{'field';'operation';...}) sosort()returns4x1on both sides. Field-set semantics are unchanged — membership and count are still strict.Test plan
test_struct_input_accepted— a well-formed searchstructure now round-trips throughdid.query(struct)as documented in the header comment of the constructor.test_struct_input_rejects_unknown_fields— an extra field still errors (regression guard so the shape fix doesn't accidentally loosen the validator).The existing 4 tests in
test_query.mcontinue to pass.Generated by Claude Code