Redirect matcher is exact-match only: parameterized legacy routes will hard-404 after Blazor deletion (Step 1 infeasible as written) #204

Closed
opened 2026-07-09 21:21:34 +02:00 by timothy · 3 comments
Owner

Severity: MUST-FIX (correctness gap in the removal plan — ersatztv#91 phase (b) Step 1)

What's wrong

LegacyUiRedirects.cs matches exact paths only — Map.TryGetValue(value, ...) against a static dictionary, with an explicit comment "EXACT paths only (no prefix matching)". Its 13 current entries are all parameterless.

The plan's Step 1 says: "add every SPA-READY route to LegacyUiRedirects.cs (including id-carrying detail/editor routes → their /app/... equivalents)." This is not expressible in the current mechanism. Routes like /media/movies/{MovieId:int}, /media/tv/shows/{ShowId:int}, /channels/{Id:int}, /blocks/{Id:int}, /playouts/block/{Id:int}, /media/collections/{Id:int}, etc. cannot be enumerated as static keys.

Blast radius

After Step 2 deletes Blazor, every parameterized legacy URL that Step 1 could not redirect returns a hard 404 (Blazor is gone; there's no fallback and no wildcard redirect). That breaks:

  • external bookmarks and shared deep links to a specific movie/show/channel,
  • any docs or muscle-memory URLs using the old /media/... / /channels/{id} scheme,
  • the phase-(a) promise that legacy routes 302 to their SPA counterpart.

This directly violates the "nothing of value dies" mandate for deep links.

Required before gate clears

Either:

  1. Extend the matcher to support pattern/prefix rules that rewrite id segments (e.g. /media/movies/{id} → /app/media/movies/{id}), then Step 1 becomes feasible; or
  2. Explicitly scope Step 1 to the parameterless routes it can handle and accept/document that parameterized deep links 404 post-deletion (and get sign-off that this loss is acceptable).

The plan currently promises (1) via a mechanism that only supports exact matches — that contradiction must be resolved before deletion.

[PLAN-MODE] — touches the redirect middleware design.

**Severity: MUST-FIX** (correctness gap in the removal plan — ersatztv#91 phase (b) Step 1) ## What's wrong `LegacyUiRedirects.cs` matches **exact paths only** — `Map.TryGetValue(value, ...)` against a static dictionary, with an explicit comment "EXACT paths only (no prefix matching)". Its 13 current entries are all parameterless. The plan's **Step 1** says: *"add every SPA-READY route to `LegacyUiRedirects.cs` (including id-carrying detail/editor routes → their `/app/...` equivalents)."* This is **not expressible** in the current mechanism. Routes like `/media/movies/{MovieId:int}`, `/media/tv/shows/{ShowId:int}`, `/channels/{Id:int}`, `/blocks/{Id:int}`, `/playouts/block/{Id:int}`, `/media/collections/{Id:int}`, etc. cannot be enumerated as static keys. ## Blast radius After Step 2 deletes Blazor, every parameterized legacy URL that Step 1 could not redirect returns a **hard 404** (Blazor is gone; there's no fallback and no wildcard redirect). That breaks: - external bookmarks and shared deep links to a specific movie/show/channel, - any docs or muscle-memory URLs using the old `/media/...` / `/channels/{id}` scheme, - the phase-(a) promise that legacy routes 302 to their SPA counterpart. This directly violates the "nothing of value dies" mandate for deep links. ## Required before gate clears Either: 1. Extend the matcher to support pattern/prefix rules that rewrite id segments (e.g. `/media/movies/{id}` → `/app/media/movies/{id}`), then Step 1 becomes feasible; **or** 2. Explicitly scope Step 1 to the parameterless routes it *can* handle and accept/document that parameterized deep links 404 post-deletion (and get sign-off that this loss is acceptable). The plan currently promises (1) via a mechanism that only supports exact matches — that contradiction must be resolved before deletion. `[PLAN-MODE]` — touches the redirect middleware design.
timothy added the priority: highreview labels 2026-07-09 21:21:34 +02:00
Author
Owner

Verified — LegacyUiRedirects.TryGetRedirect is a pure exact-match dictionary lookup, so the plan's "add every SPA-READY route incl. id-carrying ones" was infeasible as written.

Proposed resolution (to land in the removal PR, Step 1):

  1. Keep the exact-match map for static routes.
  2. Add an ordered pattern rule table for id-carrying routes — first-match-wins templates that capture the id and substitute it into the SPA target, e.g. /media/movies/{id} → /app/media/movies/{id}, /channels/{id} → /app/edit-channel/{id}, /blocks/{id} → /app/blocks/{id}, /media/tv/shows/{id} → /app/media/shows/{id}, etc. Routes whose Blazor detail pages merged into a list screen (e.g. /playouts/classic/{id}) redirect to the list (/app/playouts) — deep state is dropped deliberately, not 404'd.
  3. Add a catch-all fallback: any path reaching the end of the (former) Blazor branch that isn't API/OpenAPI/artwork 302s to /app — this replaces MapFallbackToPage("/_Host") so nothing hard-404s post-deletion.
  4. Unit tests per rule (extend the existing LegacyUiRedirects test suite from phase a) + a live-E2E redirect sweep in the removal PR gate.

Will implement with the removal PR; leaving open until then.

Verified — `LegacyUiRedirects.TryGetRedirect` is a pure exact-match dictionary lookup, so the plan's "add every SPA-READY route incl. id-carrying ones" was infeasible as written. **Proposed resolution (to land in the removal PR, Step 1):** 1. Keep the exact-match map for static routes. 2. Add an ordered **pattern rule table** for id-carrying routes — first-match-wins templates that capture the id and substitute it into the SPA target, e.g. `/media/movies/{id}` → `/app/media/movies/{id}`, `/channels/{id}` → `/app/edit-channel/{id}`, `/blocks/{id}` → `/app/blocks/{id}`, `/media/tv/shows/{id}` → `/app/media/shows/{id}`, etc. Routes whose Blazor detail pages merged into a list screen (e.g. `/playouts/classic/{id}`) redirect to the list (`/app/playouts`) — deep state is dropped deliberately, not 404'd. 3. Add a **catch-all fallback**: any path reaching the end of the (former) Blazor branch that isn't API/OpenAPI/artwork 302s to `/app` — this replaces `MapFallbackToPage("/_Host")` so nothing hard-404s post-deletion. 4. Unit tests per rule (extend the existing LegacyUiRedirects test suite from phase a) + a live-E2E redirect sweep in the removal PR gate. Will implement with the removal PR; leaving open until then.
timothy added this to the Blazor removal (#91 phase b) milestone 2026-07-11 01:14:28 +02:00
Author
Owner

claiming — session started 2026-07-11 (evening). Scope this session: extend LegacyUiRedirects to express id-carrying pattern rules and populate the SPA-ready ones (completes phase-(a) Step 1 for parameterized routes), gated per blazor-route-parity.md verdicts. The catch-all fallback that replaces MapFallbackToPage("/_Host") stays coupled to the removal PR (arc item 4) since Blazor still serves un-migrated routes. [PLAN-MODE] design pass escalated to Fable before implementing.

claiming — session started 2026-07-11 (evening). Scope this session: extend `LegacyUiRedirects` to express id-carrying pattern rules and populate the SPA-ready ones (completes phase-(a) Step 1 for parameterized routes), gated per `blazor-route-parity.md` verdicts. The catch-all fallback that replaces `MapFallbackToPage("/_Host")` stays coupled to the removal PR (arc item 4) since Blazor still serves un-migrated routes. `[PLAN-MODE]` design pass escalated to Fable before implementing.
timothy added the in-progress label 2026-07-11 16:21:30 +02:00
timothy removed the in-progress label 2026-07-11 17:00:25 +02:00
Author
Owner

Closed via PR #260 (merged to main 495e450e, fast-forward)

What was done: Extended LegacyUiRedirects from an exact-match dictionary to a two-tier matcher (signature unchanged), making the removal plan's Step 1 — "add every SPA-READY route incl. id-carrying detail/editor routes" — expressible for the first time.

  • Tier 1 — exact Map, now 52 entries (13 foundational + #204 (A)/(B) parameterless routes + (E-base) browse roots whose targets carry ?kind=…).
  • Tier 2 — 36 ordered PatternRule segment templates ((C) id-substituting, (C2) mid-path id, (D) id-dropping detail→list, (E-page) /…/page/{n} → ?kind=), first-match-wins, consulted only on a Tier-1 miss.
  • {id} = strict positive integer (NumberStyles.None, > 0) → non-int/0/neg/overflow falls through to Blazor (never a broken /app/edit-channel/abc). This strictness is also what makes the rule set collision-free by construction.
  • New AppendQueryString helper &-merges the incoming query into ?kind= targets — fixes the malformed double-? (/media/movies?page=2 → /app/media?kind=movies&page=2); plain targets keep byte-identical behavior. One-line Startup.cs change; redirect stays GET/HEAD-only 302 before UseRouting().
  • Guard invariant (code comment + a meta-test now covering both tiers): no rule may begin with /api|/artwork|/docs|/openapi|/iptv|/app|/media/sources — the matcher's specificity is load-bearing protection for those un-prefix-guarded surfaces.

Design: resolved via a [PLAN-MODE] design pass (mechanism, query-collision, id-validation, rule ordering) — recorded in docs/decisions.md (2026-07-11, #204).

Files changed: ErsatzTV/LegacyUiRedirects.cs, ErsatzTV/Startup.cs (one line), ErsatzTV.Tests/LegacyUiRedirectsTests.cs, docs/blazor-route-parity.md (§2 rows → §1), docs/decisions.md.

Verification: dotnet build 0 errors; 1132 tests green; live E2E 14/14 curl probes on the running host (7 correct 302→/app incl. the double-? fix verified live, HEAD-like-GET, all 302-not-301, correct fall-throughs for /channels/abc, /media/sources/plex, /system/health, /api/*); fork adversarial review = MERGEABLE (its one nit — Tier-2 not covered by the guard meta-test — fixed in follow-up 495e450e).

Deferred (deliberate, documented): the catch-all fallback replacing MapFallbackToPage("/_Host") stays with the removal PR (#91 phase b, arc item 4) — it can't land while Blazor still serves un-migrated routes. /media/sources/* (#202) and /system/health (escape hatch) remain un-redirected by design, encoded as negative tests. Two non-blocking review notes (double-trailing-slash on an id route falls through, matching existing //-hardening posture; /media/collections/{id} drops the id per the ratified in-screen-editor parity verdict) need no change.

Docs updated (same PR): docs/blazor-route-parity.md, docs/decisions.md.

Net effect: the #91b removal PR is de-risked — every PARITY-OK route now redirects; the removal PR only has to flip the deletion switch + add the catch-all fallback.

## Closed via PR #260 (merged to main `495e450e`, fast-forward) **What was done:** Extended `LegacyUiRedirects` from an exact-match dictionary to a **two-tier matcher** (signature unchanged), making the removal plan's Step 1 — "add every SPA-READY route incl. id-carrying detail/editor routes" — expressible for the first time. - **Tier 1** — exact `Map`, now **52 entries** (13 foundational + #204 (A)/(B) parameterless routes + (E-base) browse roots whose targets carry `?kind=…`). - **Tier 2** — **36 ordered `PatternRule` segment templates** ((C) id-substituting, (C2) mid-path id, (D) id-dropping detail→list, (E-page) `/…/page/{n}` → `?kind=`), first-match-wins, consulted only on a Tier-1 miss. - `{id}` = **strict positive integer** (`NumberStyles.None`, `> 0`) → non-int/`0`/neg/overflow falls through to Blazor (never a broken `/app/edit-channel/abc`). This strictness is also what makes the rule set **collision-free by construction**. - New `AppendQueryString` helper **`&`-merges** the incoming query into `?kind=` targets — fixes the malformed double-`?` (`/media/movies?page=2` → `/app/media?kind=movies&page=2`); plain targets keep byte-identical behavior. One-line `Startup.cs` change; redirect stays GET/HEAD-only **302** before `UseRouting()`. - **Guard invariant** (code comment + a meta-test now covering **both tiers**): no rule may begin with `/api|/artwork|/docs|/openapi|/iptv|/app|/media/sources` — the matcher's specificity is load-bearing protection for those un-prefix-guarded surfaces. **Design:** resolved via a `[PLAN-MODE]` design pass (mechanism, query-collision, id-validation, rule ordering) — recorded in `docs/decisions.md` (2026-07-11, #204). **Files changed:** `ErsatzTV/LegacyUiRedirects.cs`, `ErsatzTV/Startup.cs` (one line), `ErsatzTV.Tests/LegacyUiRedirectsTests.cs`, `docs/blazor-route-parity.md` (§2 rows → §1), `docs/decisions.md`. **Verification:** `dotnet build` 0 errors; **1132 tests green**; **live E2E 14/14 curl probes** on the running host (7 correct 302→`/app` incl. the double-`?` fix verified live, HEAD-like-GET, all 302-not-301, correct fall-throughs for `/channels/abc`, `/media/sources/plex`, `/system/health`, `/api/*`); fork adversarial review = **MERGEABLE** (its one nit — Tier-2 not covered by the guard meta-test — fixed in follow-up `495e450e`). **Deferred (deliberate, documented):** the catch-all fallback replacing `MapFallbackToPage("/_Host")` stays with the **removal PR (#91 phase b, arc item 4)** — it can't land while Blazor still serves un-migrated routes. `/media/sources/*` (#202) and `/system/health` (escape hatch) remain un-redirected by design, encoded as negative tests. Two non-blocking review notes (double-trailing-slash on an id route falls through, matching existing `//`-hardening posture; `/media/collections/{id}` drops the id per the ratified in-screen-editor parity verdict) need no change. **Docs updated (same PR):** `docs/blazor-route-parity.md`, `docs/decisions.md`. Net effect: the #91b removal PR is de-risked — every PARITY-OK route now redirects; the removal PR only has to flip the deletion switch + add the catch-all fallback.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#204