Skip to content

Pin screenmap.json base schema via a backward-compat unit test #89

Closed

Description

@zackees

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 a PointArrayWithDiameter.
  • 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:

  1. Round-trip fixtures. Check in a small set of screenmap.json fixtures under tests/fixtures/screenmap-base-schema/. Each fixture's expected.json records the canonical parsed shape (segments + their x, y, diameter). Parser output must equal it byte-for-byte (after stable serialization). At minimum:

  2. Required-key enforcement. Inputs missing the top-level map or missing x/y on a segment must surface as a clean parse failure (whatever today's behavior is — pin it).

  3. x.length === y.length invariant. Mismatched lengths fail.

  4. Forward-compat invariants (the future-proofing payoff).

  5. Reject hostile shapes. map as a non-object, x/y as non-arrays, diameter as a string — fail cleanly, don't crash.

  6. 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 dataStrips and groups top-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 only map present.
  • Test runs under npm test (currently the unit-test entry; finishes in <1 s).

Out of scope

Blocks: any merge that touches parse_screenmap_data_json or parseScreenmapMultiStrip should require this test to be green.

Related: #88.

Activity

  1. zackees commented on Jun 14, 2026

    @zackees
    OwnerAuthor

    Superseded by #92, which captures the final v2 schema and the parser/dispatch plan to implement. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions