Skip to content

fix: convert InputVar type to a discriminated union with slider and switch variants#820

Merged
chrispcampbell merged 7 commits intomainfrom
chris/819-input-var-fields
May 4, 2026
Merged

fix: convert InputVar type to a discriminated union with slider and switch variants#820
chrispcampbell merged 7 commits intomainfrom
chris/819-input-var-fields

Conversation

@chrispcampbell
Copy link
Copy Markdown
Contributor

Fixes #819

See issue for details. This only affects the model-check packages. I also made a small related change in the plugin-config package to correct the mapping for switch off/on values to follow the conventions we use elsewhere.

Drop the optional rendering metadata (step, reversed, units, format,
slidersActiveWhenOff/On) that check-core itself doesn't read.  These
fields are properly the concern of consumers like model-explorer and
will live in an extended bundle format defined elsewhere.

Also fix the template-bundle Input type to use SliderInputVar directly
(via intersection) since interfaces can't extend a union.
Two related cleanups for code that branches on `InputVar.kind`:

- For switch inputs, use the convention that `at-minimum` maps to the
  switch's `offValue` and `at-maximum` maps to its `onValue`, instead
  of erroring out (or sorting min/max with Math.min/max).  This matches
  the long-standing en-roads-check-bundle behavior.

- Prefer `switch (inputVar.kind)` over `if (inputVar.kind === 'slider')`
  / `if (inputVar.kind === 'switch')`, so that adding a new variant in
  the future surfaces all branches that need to handle it (and so
  searches for either kind name find every branch).

Touches the mocks (mock-check-scenario, mock-resolved-types,
mock-comparison-scenario), the position-resolution helpers in
check-scenario.ts and comparison-resolver.ts, the comparison matrix
filter in comparison-resolver.ts, and the per-input min/max scenario
filter in plugin-check's template-tests.
Now that the at-min/at-max position resolution maps switches to
off/on (instead of erroring), the matrix scenarios in check-core and
plugin-check no longer need to filter switches out.  This restores
behavior where every input — slider or switch — gets its own at-min
and at-max scenario.

In template-tests, the per-input min/max equality check is now
expressed via a small `valueAtPos` helper that returns minValue/maxValue
for sliders and offValue/onValue for switches, so switch inputs are
correctly skipped when their position value matches the default
(already covered by the all-inputs-at-default scenario).

Also includes the parallel cleanup in plugin-config/gen-inputs.ts:
the `addInputVariable` call for switches now passes `offValue`/`onValue`
directly as min/max, matching the convention used in sim-build.
@chrispcampbell chrispcampbell merged commit 9bd55cb into main May 4, 2026
6 checks passed
@chrispcampbell chrispcampbell deleted the chris/819-input-var-fields branch May 4, 2026 23:37
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.

Convert InputVar type in check-core to a discriminated union with slider and switch variants

1 participant