fix(e24): review round 3 — the holes round 2's own fixes left

Round 3 reviewed the round-2 commit across six dimensions. Fifteen findings, five survived
three adversarial refuters each; three died on 2+ refutations (a keyboard-focus claim that
is a property of `ui/Button` at all six of its `loading` call sites, a contract-test
false-pass that needs a deliberate revert plus a self-incriminating comment, and a
MAX_EXCLUDE coupling whose slice is unreachable from the real client).

- `rerolling` was still wrong for a FAILED press. `data === undefined` is true forever for a
  key whose request failed (`retry: false`), so the next unrelated mutation re-disabled the
  reroll button — the same defect round 2 reported, one branch over. `!isFetched` is the
  flag that remembers a key settled; `!isError` would not have worked, because query-core
  resets a data-less query to "pending" for the duration of a refetch, hiding the error
  exactly when it matters.
- The hero fallback used `??`, which cannot tell "this budget's last pick resolved to NO
  hero" from "nothing remembered". So a press that failed after an empty one resurrected the
  card the page had already excluded as seen and just said it had nothing beyond. The tagged
  slot is now authoritative for its own budget.
- `setPage`'s boolean — the input the whole burial rule reads — was asserted by nothing.
  The type fences the SHAPE, so deleting a `return` fails tsc, but swapping the two values
  passed typecheck and all 822 tests. NavigationProvider gets its first render test, on the
  value AND on the effects the early return skips.
- `closeThenNavigate`'s door into `buryUnder` was equally unpinned: reverting that one call
  site to the old unconditional burial left the suite green. It has the mirror case now.
- The comment claiming one rule serves both entry points was overstated. `buryUnder` fails
  OPEN, and `CommandItem.run` is typed `() => void`, so only the palette's bare
  `() => setPage(page)` rows forward the boolean at all. Nothing regressed — that path buried
  unconditionally before — but the prose said more than the code does, so it now says what is
  true and points at the deferred fix. Same for a "the only assertion in the suite" claim
  that the file it cites as precedent also makes.

Every new test mutation-checked red for the right reason, both edges where there are two.
Gate: ruff, ruff format, 3x tsc, eslint (0 errors), prettier, knip, vitest 828, pytest 1005.
This commit is contained in:
2026-09-09 00:39:37 +02:00
parent e4ffd59ca7
commit 59efc8f2e8
6 changed files with 241 additions and 12 deletions
+5 -5
View File
@@ -1,10 +1,10 @@
// @vitest-environment jsdom
//
// ONE test, ONE file, for the same reason CommandPalette.ordering.dom.test.tsx has its own: this is
// the only assertion in the suite that lets a reconcile issue a REAL programmatic history.back(),
// and history.ts's overlay bookkeeping is module-global. history.dom.test.ts states its own
// invariant — every layer there is closed by a genuine Back, so no programmatic back() runs and the
// shared state stays clean between its tests — and this test would break it.
// ONE test, ONE file, for the same reason CommandPalette.ordering.dom.test.tsx has its own — it is
// the other assertion in the suite that lets a reconcile issue a REAL programmatic history.back()
// (unstubbed), and history.ts's overlay bookkeeping is module-global. history.dom.test.ts states its
// own invariant — every layer there is closed by a genuine Back or a stubbed back(), so nothing real
// fires and the shared state stays clean between its tests — and this test would break it.
import { describe, it, expect, vi } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { navigateOverOverlays, useBackToClose } from "./history";
+31
View File
@@ -152,6 +152,37 @@ describe("closeThenNavigate", () => {
}
});
// The mirror of the case above, and the OTHER door into `buryUnder` — round 3 found that only
// `navigateOverOverlays` was pinned, so this call site could be reverted to the old unconditional
// burial with the whole suite green. Reachable through the palette: `run: () => setPage(page)` is
// a bare arrow, so `setPage`'s `false` really does arrive here when the chosen module is the one
// already on screen. Nothing was pushed, so the layer underneath is still ours to reclaim.
it("leaves the layer below reclaimable when the command navigated nowhere", async () => {
const back = vi.spyOn(window.history, "back").mockImplementation(() => {
window.dispatchEvent(new PopStateEvent("popstate", { state: window.history.state }));
});
try {
const player = renderHook(() => useBackToClose(() => {}));
await settle();
const palette = renderHook(() => useBackToClose(() => {}));
await settle();
const navigate = vi.fn(() => false); // setPage's early return: already on that page
await act(async () => {
closeThenNavigate(() => palette.unmount(), navigate);
await Promise.resolve();
});
expect(navigate).toHaveBeenCalledTimes(1);
expect(back).toHaveBeenCalledTimes(1); // the palette's own entry
player.unmount();
await settle();
expect(back).toHaveBeenCalledTimes(2); // and the player's, because nothing was pushed over it
} finally {
back.mockRestore();
}
});
// Without this the command is not late, it never happens: an overlay closed in the same tick it
// opened never pushed an entry, so no reclaim popstate is ever coming.
it("navigates anyway when no reclaim popstate ever arrives", () => {
+13 -2
View File
@@ -173,6 +173,16 @@ let listenerInstalled = false;
* popped onto an identical `sfPage` with an empty overlay stack, i.e. a press that did nothing
* (round 2). One rule for both entry points below, because both take the same no-op navigation.
*
* It fails OPEN, and that is a deliberate limit rather than an oversight: only a literal `false`
* skips the mark, so a `navigate` that reports nothing is assumed to have pushed — which is what
* the code did unconditionally before, so nothing regressed by adding this. The gap it leaves is
* `closeThenNavigate`'s palette callers: `CommandItem.run` is typed `() => void`, so only the rows
* written as a bare `() => setPage(page)` forward the boolean at all, while the block-bodied and
* non-navigating rows (surprise, playlists, theme, the cheat sheet) still mark a live sibling
* overlay's entry buried under a push that never happened. Closing that overlay by its own control
* then costs one dead browser-Back press. Deferred, with the fix (widen `CommandItem.run` and have
* each row report) on ROADMAP.md — this rule is complete only for `navigateOverOverlays`.
*
* Marking AFTER the call is safe: `navigate()` is synchronous and only `reconcileHistory` (a
* microtask) and the popstate listener ever move `historyDepth`. */
function buryUnder(navigate: () => boolean | void): void {
@@ -255,8 +265,9 @@ export function closeThenNavigate(close: () => void, navigate: () => boolean | v
// reconcile ate the new page entry). MARK them rather than zeroing the depth: round 1 set
// `historyDepth = 0` outright, which also desynced the counter from overlays the navigation does
// NOT unmount — About/ReleaseNotes live outside the page column — so one Back both navigated and
// closed them (round 2). `buryUnder` is what skips the mark when the command navigated nowhere
// — a palette entry for the page you are already on.
// closed them (round 2). `buryUnder` skips the mark when the command reports it navigated
// nowhere — which here is only the palette's bare `() => setPage(page)` module rows; see the
// fail-open limit documented on `buryUnder` for the rows that cannot report.
buryUnder(navigate);
};
const onPop = () => {