build(frontend): close the lint gaps the E32 audit measured

eslint now also enforces:
- the React Compiler diagnostics that `recommended` leaves out (todo,
  memo-dependencies and ten zero-hit tripwires);
- a description on every suppression, and no blanket disables;
- no focused or skipped tests (vitest and playwright);
- the typed pair no-floating-promises and no-deprecated.

Lint also covers e2e/ and the TypeScript build configs, which `eslint .`
had been skipping in silence.

Every hit is fixed or suppressed inline with a named reason:
- The 31 try statements the compiler cannot lower yet carry a suppression
  until S3 rewrites them. Five other compiler skips were plain fixes:
  a module counter bumped inside a hook, a ref read in a default
  parameter, and a local named like the <section> it renders.
- The real defects behind floating promises are fixed. ChatDock threw at
  nobody when the device key store could not be opened. VideoEditor's
  play() rejection went unhandled. loadYouTubeApi never rejected, so a
  blocked IFrame API left the player on an empty stage forever; it now
  fails on a script error or after 15 s, shows its own error with the
  way out, and lets the next open try again.
- MutableRefObject, FormEvent and lucide's deprecated brand icon are
  replaced. The YouTube glyph now lives in lib/brandIcons.
- The lint-probe harness lets its virtual file names into TypeScript's
  default project, so the contract tests still run the real config.
This commit is contained in:
2026-10-03 16:34:20 +02:00
parent 3c16012524
commit 471846d784
72 changed files with 938 additions and 216 deletions
@@ -0,0 +1,84 @@
// @vitest-environment jsdom
//
// The YouTube IFrame API script failing to load must END in an error state. `loadYouTubeApi` used to
// return a promise that only ever resolved: a blocked or failed script (a content blocker, no
// network) left the modal on an empty stage forever, with no error and no way to retry short of a
// reload — the promise was memoised, so every later open waited on the same dead one (E32 audit).
//
// Its own file on purpose: `loadYouTubeApi` memoises the API promise in a module-level singleton,
// and these tests need a module instance that has never seen `window.YT`.
import { describe, it, expect, vi, afterEach } from "vitest";
import { renderHook } from "@testing-library/react";
import { QueryClient } from "@tanstack/react-query";
import { createRef, type RefObject } from "react";
import { useYtProgress, YT_API_LOAD_FAILED, YT_API_TIMEOUT_MS } from "./playerModalHooks";
import type { YTPlayer } from "./youtube";
const VID = "EC5oFYy9z9g";
const apiScripts = () =>
[...document.head.querySelectorAll("script")].filter((s) => s.src.includes("iframe_api"));
const settle = async () => {
for (let i = 0; i < 6; i++) await Promise.resolve();
};
function mountPlayer(setPlayerError: (code: number | null) => void) {
const mount = document.createElement("div");
document.body.appendChild(mount);
return renderHook(() =>
useYtProgress({
activeId: VID,
resumeAt: 0,
mountRef: { current: mount },
playerRef: createRef<YTPlayer>() as RefObject<YTPlayer | null>,
currentIdRef: { current: VID },
navRef: { current: { queue: undefined, index: 0 } },
modeRef: { current: { autoMode: "off", loopMode: "off" } },
setWatched: () => {},
setPlayerError,
setLiveData: () => {},
reapplyStored: () => {},
focusModal: () => {},
advanceOnEnd: () => {},
sessionPosRef: { current: new Map() },
qc: new QueryClient(),
}),
);
}
describe("useYtProgress — the IFrame API failing to load", () => {
// Fail any load still in flight, so the module's memoised promise is cleared for the next test
// (a pending one would carry a timer from before that test's fake clock).
afterEach(async () => {
for (const s of apiScripts()) s.dispatchEvent(new Event("error"));
await settle();
vi.useRealTimers();
});
it("shows the load-failed state when the script errors, and a later open tries again", async () => {
const setPlayerError = vi.fn();
const first = mountPlayer(setPlayerError);
const [tag] = apiScripts();
expect(tag).toBeDefined();
tag!.dispatchEvent(new Event("error"));
await settle();
expect(setPlayerError).toHaveBeenCalledWith(YT_API_LOAD_FAILED);
first.unmount();
// Not memoised as a failure: the next open loads the script again rather than waiting on the
// dead promise.
const again = mountPlayer(vi.fn());
expect(apiScripts()).toHaveLength(1);
again.unmount();
});
it("gives up after the timeout when the script never answers", async () => {
vi.useFakeTimers();
const setPlayerError = vi.fn();
const { unmount } = mountPlayer(setPlayerError);
await vi.advanceTimersByTimeAsync(YT_API_TIMEOUT_MS + 1);
expect(setPlayerError).toHaveBeenCalledWith(YT_API_LOAD_FAILED);
unmount();
});
});