Repository navigation
Description
Goal
Lock the screenmap.json base schema (FastLED ScreenMap) behind a unit-test contract so the upcoming groups/forks/data-strips work in #88 — or any other change — can't accidentally regress what FastLED-firmware devices read.
Background
#88 established that screenmap.json rides FastLED's ScreenMap::ParseJson contract: a top-level map object, per-segment { x[], y[], diameter? }, with unknown top-level keys silently ignored. Today the parser lives in src/common.ts:
parse_screenmap_data_json(jsonBlob)— single-strip path returning aPointArrayWithDiameter.parseScreenmapMultiStrip(text)— multi-strip path returning{ strips, allPoints, totalCount }.parse_screenmap_data(text)— auto-dispatches JSON vs CSV.
There's some coverage in tests/unit/multistrip-parsing.test.ts already but it doesn't pin the FastLED-equivalence contract per se.
What to test
A new (or extended) unit test that asserts the exact FastLED parser contract:
-
Round-trip fixtures. Check in a small set of
screenmap.jsonfixtures undertests/fixtures/screenmap-base-schema/. Each fixture'sexpected.jsonrecords the canonical parsed shape (segments + theirx,y,diameter). Parser output must equal it byte-for-byte (after stable serialization). At minimum:single-strip.json— one entry,diameterpresentsingle-strip-no-diameter.json— exercise the optional fieldmulti-strip.json— 3+ entries, varying lengthsfour-leds-canonical.json— the literal example from Design: forks + groups + data-strips — separating signal from physical placement #88 / FastLED docs
-
Required-key enforcement. Inputs missing the top-level
mapor missingx/yon a segment must surface as a clean parse failure (whatever today's behavior is — pin it). -
x.length === y.lengthinvariant. Mismatched lengths fail. -
Forward-compat invariants (the future-proofing payoff).
- Unknown top-level keys are ignored. A JSON with
{ "map": {...}, "dataStrips": [...], "groups": [...], "_arbitrary": 42 }must parse identically to one with just themapportion. This is the seam Design: forks + groups + data-strips — separating signal from physical placement #88 relies on for addingdataStrips+groupswithout breaking firmware compat. - Unknown per-segment keys are ignored. Same idea, nested.
- Unknown top-level keys are ignored. A JSON with
-
Reject hostile shapes.
mapas a non-object,x/yas non-arrays,diameteras a string — fail cleanly, don't crash. -
Stable iteration order. Multi-strip output preserves the JSON key declaration order. Today's UI depends on this (issue CI test infrastructure: move Playwright off default path, target <1 min for push/PR #80 / panel-ordering work touched it).
Suggested file
tests/unit/screenmap-schema-compat.test.ts — keeps the contract isolated from the existing parsing test (which covers internal shape) and the strips-model test (which covers mutations).
Fixtures live under tests/fixtures/screenmap-base-schema/ next to the spec, so each test reads its <name>.json + <name>.expected.json pair.
Acceptance
- New test file exists and passes.
- All 4 categories (round-trip, required keys, forward-compat, hostile inputs) have at least one assertion.
- Forward-compat case explicitly includes a fixture with
dataStripsandgroupstop-level keys (the proposed Design: forks + groups + data-strips — separating signal from physical placement #88 additions) and asserts the existing parser ignores them and produces identical output to the same JSON with onlymappresent. - Test runs under
npm test(currently the unit-test entry; finishes in <1 s).
Out of scope
- Adding the parser support for the new
dataStrips/groupskeys (separate work, dependent on Design: forks + groups + data-strips — separating signal from physical placement #88 resolution). - CSV path tests.
- Exporter / writer tests (covered separately by the round-trip tests in
screenmap-store.test.ts).
Blocks: any merge that touches parse_screenmap_data_json or parseScreenmapMultiStrip should require this test to be green.
Related: #88.
Activity
zackees commentedon Jun 14, 2026
Superseded by #92, which captures the final v2 schema and the parser/dispatch plan to implement. Closing.