Skip to content

Fix TestDataHandler's DataType.ANY and PAIR/ARRAY handling - #859

Merged
martin-henz merged 1 commit into
conductor-migrationfrom
fix/testplugin-any-datatype
Jul 28, 2026
Merged

Fix TestDataHandler's DataType.ANY and PAIR/ARRAY handling#859
martin-henz merged 1 commit into
conductor-migrationfrom
fix/testplugin-any-datatype

Conversation

@martin-henz

Copy link
Copy Markdown
Member

Summary

Fixes the failing `binary_tree Bundle` CI job — same failure reported earlier and confirmed pre-existing, unrelated to the `@sourceacademy/conductor` version bump (#858). Root cause was two bugs in `lib/testplugin`'s shared test double, both invisible until #813's regression test built a tree entirely out of `array_make`/`array_set` (simulating a tree round-tripped back in through Python) instead of `pair_make`.

Bug 1 — `matchesType()` didn't special-case `DataType.ANY`. It already special-cases `DataType.LIST` (matching `PAIR` or `EMPTY_LIST`), but for `ANY` it fell through to `value.type === expected` — requiring a value's own type tag to literally be `ANY`. That's backwards: per conductor's own `isSameType()` (`t1 === DataType.ANY || t2 === DataType.ANY` → `true`) and `isReferenceType()`'s doc comment ("never a value's own type tag; only ever a declared parameter type"), `ANY` as a declared type must match any value. This produced:
```
Error: Array element expected ANY, got EMPTY_LIST.
```

Bug 2 — `getPair()` (the single choke point every `pair_*` method uses) only ever looked up `pairMap`. Per `binary_tree`'s own comment ("a pair is just an array of length 2 - no distinct pair representation"), `pair_head`/`pair_tail` are expected to transparently accept a value tagged `DataType.ARRAY`, matching the real evaluator. `getPair` had no fallback to `arrayMap`, producing:
```
Error: Unknown pair identifier 3.
```

Verification

  • `binary_tree`: all 19/19 tests pass (previously 1 failing), `tsc` passes
  • `testplugin`'s own test suite (6/6) passes
  • Ran the full test suite for every other package that depends on `modules-testplugin` — `csg`, `curve` (bundle + tab), `midi`, `plotly`, `repeat`, `scrabble` — all pass, confirming the fix doesn't regress anything relying on the previous (buggy) behavior
  • `yarn constraints` clean
  • `yarn lint:all` — no new errors/warnings

🤖 Generated with Claude Code

Two bugs in the shared testplugin test double surfaced by binary_tree's
regression test for #813 (accepting DataType.ARRAY as equally valid to
PAIR for tree nodes):

1. matchesType() special-cases DataType.LIST (PAIR or EMPTY_LIST) but
   not DataType.ANY - it fell through to `value.type === expected`,
   requiring a value's own type tag to literally be ANY, which per
   conductor's own isSameType() (`t1 === DataType.ANY || t2 === DataType.ANY`
   => true) and isReferenceType()'s doc comment ("never a value's own
   type tag; only ever a declared parameter type") is backwards: ANY as
   a declared/expected type must match any value. array_set(arr, i, v)
   on an array_make(DataType.ANY, ...) array threw "Array element
   expected ANY, got EMPTY_LIST" for exactly this reason.

2. getPair() (the single choke point pair_head/pair_tail/pair_sethead/
   pair_settail/pair_assert all use) only ever looked up pairMap, so a
   value tagged DataType.ARRAY - which per binary_tree's own comment
   ("a pair is just an array of length 2 - no distinct pair
   representation") pair_head/pair_tail are expected to accept
   transparently, matching the real evaluator - threw "Unknown pair
   identifier N" instead of falling back to arrayMap.

Both were invisible until a test actually built a tree entirely out of
array_make/array_set (simulating a tree round-tripped back in through
Python) rather than pair_make, which is exactly what #813's regression
test does.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@martin-henz
martin-henz merged commit 9dda178 into conductor-migration Jul 28, 2026
@martin-henz
martin-henz deleted the fix/testplugin-any-datatype branch July 28, 2026 05:28
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