Selection-id boundary: ScheduleItemInspector is unguarded, and list-backed pickers drop malformed options silently #677

Open
opened 2026-07-27 04:23:26 +02:00 by timothy · 1 comment
Owner

Split out of the #651 final review. Two items, both extensions of the boundary rule that branch established (docs/spa-conventions.md §3b → "Put a validity predicate at the BOUNDARY the class crosses"). Neither is data loss; both are the same class arriving somewhere #651 did not reach.

1. ScheduleItemInspector stores and submits raw wire ids

web/src/schedules/ScheduleItemInspector.tsx:403-428,490-501 reads collectionId / mediaItemId / multiCollectionId / smartCollectionId / playlistId / playlistGroupId straight out of the API response into editor state and submits them unchanged. That is exactly the class web/src/api/selectionId.ts exists for: the API binds each as a 32-bit int, so a malformed successful response carrying 1.5 or 2147483648 renders as a normal selection and then fails on write.

#651 centralized the predicate and applied it to every ingress on RerunCollectionsScreen, PlaylistsScreen and FillerPresetsScreen. This screen was outside its scope and is unchanged by that branch — but "the boundary, not the site" is the whole point of the rule, so it should be tracked rather than left silent.

Fix: route every id through selectionIdOrNull on the way in, and isSelectionId when building options. Treat an unbindable id as absent (never coerce — rounding 1.5 to 1 submits a different record), clear any label alongside a dropped id, and make sure the screen's save gate actually refuses to write without a selection. #651's round-9 finding was that the analogous gate did not exist on PlaylistsScreen, so check rather than assume.

2. List-backed pickers drop malformed options silently

RerunCollectionsScreen.toPickerOptions, PlaylistsScreen.toPickerOptions and FillerPresetsScreen's collection-family option mapping all flatMap away any element whose id fails isSelectionId. Dropping one bad option among good ones is right. But a wholly malformed page yields an empty picker with no explanation, which contradicts the convention rounds 6/7 established for SearchPicker:

a malformed payload is a failed attempt with a visible message, precisely because a malformed page reading as an authoritative empty answer was a shipped bug on this branch

So the same defect now exists in the other direction: "there is nothing to pick" and "we threw your options away" look identical. SearchPicker already distinguishes these (resultsFor.ok → a "Search failed" alert instead of "No matches"); the list-backed path has no equivalent.

Related, same area: FillerPresetsScreen.tsx:688 computes its truncation hint (Showing the first N of M) from the unfiltered page length, so after filtering, N can exceed the number of options actually rendered.

Fix: surface a distinct "some options could not be loaded" / "failed to load options" state when the filter drops elements (or when it drops all of them), and derive the truncation hint from the filtered list.

Not in scope

The #651 screens' own ingresses are closed and covered by regressions; this is the surface beyond them.

Done-when

  • Every id ingress in ScheduleItemInspector passes through the shared selectionId predicate, with unbindable ids treated as absent and their labels cleared
  • That screen's save path cannot submit an unbindable or missing id — verified by a test that attempts the write and asserts zero writes are reachable (a write-count assertion on a path that never attempts one is trivially true)
  • A wholly-malformed list-backed page surfaces as a failure, visibly distinct from an authoritative empty result, on all three #651 screens
  • FillerPresetsScreen's truncation hint counts the options actually rendered
  • Each new test verified to fail without its fix, naming the load-bearing assertion
  • docs/spa-conventions.md §3b updated in the same PR if the convention moves
  • npm run lint, npm run typecheck (not tsc --noEmit — the root tsconfig is solution-style and checks nothing), npx vitest run green
  • adversarial review passed
Split out of the #651 final review. Two items, both extensions of the boundary rule that branch established (`docs/spa-conventions.md` §3b → "Put a validity predicate at the BOUNDARY the class crosses"). Neither is data loss; both are the same class arriving somewhere #651 did not reach. ## 1. `ScheduleItemInspector` stores and submits raw wire ids `web/src/schedules/ScheduleItemInspector.tsx:403-428,490-501` reads `collectionId` / `mediaItemId` / `multiCollectionId` / `smartCollectionId` / `playlistId` / `playlistGroupId` straight out of the API response into editor state and submits them unchanged. That is exactly the class `web/src/api/selectionId.ts` exists for: the API binds each as a 32-bit `int`, so a malformed successful response carrying `1.5` or `2147483648` renders as a normal selection and then fails on write. #651 centralized the predicate and applied it to every ingress on `RerunCollectionsScreen`, `PlaylistsScreen` and `FillerPresetsScreen`. This screen was outside its scope and is unchanged by that branch — but "the boundary, not the site" is the whole point of the rule, so it should be tracked rather than left silent. **Fix**: route every id through `selectionIdOrNull` on the way in, and `isSelectionId` when building options. Treat an unbindable id as absent (never coerce — rounding `1.5` to `1` submits a *different* record), clear any label alongside a dropped id, and make sure the screen's save gate actually refuses to write without a selection. #651's round-9 finding was that the analogous gate did **not** exist on `PlaylistsScreen`, so check rather than assume. ## 2. List-backed pickers drop malformed options silently `RerunCollectionsScreen.toPickerOptions`, `PlaylistsScreen.toPickerOptions` and `FillerPresetsScreen`'s collection-family option mapping all `flatMap` away any element whose id fails `isSelectionId`. Dropping one bad option among good ones is right. But a **wholly** malformed page yields an empty picker with no explanation, which contradicts the convention rounds 6/7 established for `SearchPicker`: > a malformed payload is a *failed attempt* with a visible message, precisely because a malformed page reading as an authoritative empty answer was a shipped bug on this branch So the same defect now exists in the other direction: "there is nothing to pick" and "we threw your options away" look identical. `SearchPicker` already distinguishes these (`resultsFor.ok` → a "Search failed" alert instead of "No matches"); the list-backed path has no equivalent. Related, same area: `FillerPresetsScreen.tsx:688` computes its truncation hint (`Showing the first N of M`) from the **unfiltered** page length, so after filtering, N can exceed the number of options actually rendered. **Fix**: surface a distinct "some options could not be loaded" / "failed to load options" state when the filter drops elements (or when it drops all of them), and derive the truncation hint from the filtered list. ## Not in scope The #651 screens' *own* ingresses are closed and covered by regressions; this is the surface beyond them. ## Done-when - [ ] Every id ingress in `ScheduleItemInspector` passes through the shared `selectionId` predicate, with unbindable ids treated as absent and their labels cleared - [ ] That screen's save path cannot submit an unbindable or missing id — verified by a test that **attempts the write** and asserts zero writes are reachable (a write-count assertion on a path that never attempts one is trivially true) - [ ] A wholly-malformed list-backed page surfaces as a failure, visibly distinct from an authoritative empty result, on all three #651 screens - [ ] `FillerPresetsScreen`'s truncation hint counts the options actually rendered - [ ] Each new test verified to fail without its fix, naming the load-bearing assertion - [ ] `docs/spa-conventions.md` §3b updated in the same PR if the convention moves - [ ] `npm run lint`, `npm run typecheck` (**not** `tsc --noEmit` — the root tsconfig is solution-style and checks nothing), `npx vitest run` green - [ ] adversarial review passed
timothy added the bugpriority: lowfrontend labels 2026-07-27 04:23:26 +02:00
Author
Owner

Two more items from the final cold review of #651, both on PlaylistsScreen and both left unfixed there deliberately (one pre-existing, one unreachable today). Same class as the rest of this issue: an id and its label disagreeing, or a disabled control with no stated reason.

3. The item row says "(no X selected)" for a valid id with a null name

web/src/screens/PlaylistsScreen.tsx:750:

{item.selectedName || `(no ${typeLabel(item.collectionType).toLowerCase()} selected)`}

The fallback is keyed on selectedName alone, regardless of selectedId. The generated types make the name null | string, so a response carrying a valid id with a null/empty name renders "(no movie selected)" while Save is enabled and no validation badge appears.

That is the mirror image of the bug #651 round 9 fixed (there the name survived a dropped id; here the id survives a missing name), and it violates the same rule that branch wrote into docs/spa-conventions.md §3b — a row must not make two contradictory statements about the same item. The picker already gets this right (selectedName || \#${selectedId}``); the row does not.

Fix: fall back to #${item.selectedId} when an id is present, and reserve "(no X selected)" for selectedId == null — matching SearchPicker.

4. An all-unbindable group list disables Create with no reason

web/src/screens/PlaylistsScreen.tsx:367-371,398: if every group id failed isSelectionId, bindableGroups is empty, the Select renders no options and no placeholder, and Create is disabled with nothing explaining why. Contrast the groups.length === 0 path, which disables "Add playlist" up front so the dialog is never reachable in that state.

Unreachable with identity PKs — filed for completeness, because "always explain a disabled state" is exactly the property #651 round 9 established for this screen's Save button, and this is the one place it does not hold.

Fix: when the group list is non-empty but nothing in it is bindable, say so (or disable the entry point, as the empty case does).


Both are additions to the existing ## Done-when; suggested extra boxes:

  • A valid selectedId with a null/empty name renders #<id>, not "(no X selected)"
  • A group list with no bindable entries explains why Create is unavailable, rather than silently disabling it
Two more items from the final cold review of #651, both on `PlaylistsScreen` and both left unfixed there deliberately (one pre-existing, one unreachable today). Same class as the rest of this issue: an id and its label disagreeing, or a disabled control with no stated reason. ### 3. The item row says "(no X selected)" for a valid id with a null name `web/src/screens/PlaylistsScreen.tsx:750`: ```tsx {item.selectedName || `(no ${typeLabel(item.collectionType).toLowerCase()} selected)`} ``` The fallback is keyed on `selectedName` alone, **regardless of `selectedId`**. The generated types make the name `null | string`, so a response carrying a valid id with a null/empty name renders "(no movie selected)" while Save is enabled and no validation badge appears. That is the **mirror image** of the bug #651 round 9 fixed (there the name survived a dropped id; here the id survives a missing name), and it violates the same rule that branch wrote into `docs/spa-conventions.md` §3b — a row must not make two contradictory statements about the same item. The picker already gets this right (`selectedName || \`#${selectedId}\``); the row does not. **Fix**: fall back to `#${item.selectedId}` when an id is present, and reserve "(no X selected)" for `selectedId == null` — matching `SearchPicker`. ### 4. An all-unbindable group list disables Create with no reason `web/src/screens/PlaylistsScreen.tsx:367-371,398`: if *every* group id failed `isSelectionId`, `bindableGroups` is empty, the `Select` renders no options and no placeholder, and Create is disabled **with nothing explaining why**. Contrast the `groups.length === 0` path, which disables "Add playlist" up front so the dialog is never reachable in that state. Unreachable with identity PKs — filed for completeness, because "always explain a disabled state" is exactly the property #651 round 9 established for this screen's Save button, and this is the one place it does not hold. **Fix**: when the group list is non-empty but nothing in it is bindable, say so (or disable the entry point, as the empty case does). --- Both are additions to the existing `## Done-when`; suggested extra boxes: - [ ] A valid `selectedId` with a null/empty name renders `#<id>`, not "(no X selected)" - [ ] A group list with no bindable entries explains why Create is unavailable, rather than silently disabling it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#677