4.7 KiB
id, title, status, assignee, created_date, updated_date, labels, dependencies, priority, ordinal
| id | title | status | assignee | created_date | updated_date | labels | dependencies | priority | ordinal | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TASK-105 | Eliminate unsafe non-test runtime casts in main boundaries | Done |
|
2026-02-22 07:13 | 2026-02-23 02:06 |
|
|
medium | 102000 |
Description
Production runtime wiring still relies on many unsafe type escapes (as never, as unknown as) across src/main.ts and src/main/runtime/* non-test files.
Current scan shows repeated casts in dependency builders and runtime adapters, which hides contract drift and allowed current Jellyfin compile break to persist until full build.
Action Steps
- Build a baseline list of non-test unsafe casts in
src/main.tsandsrc/main/runtime. - Group casts by ownership domain (Jellyfin, overlay, startup, IPC, tokenization, tray).
- For each domain, introduce explicit interface types/adapters so casts are removed at boundary creation.
- Keep test-only casts allowed where practical, but remove production-path
as neverusage. - Add compile-time contract assertions for critical dependency builders to catch drift early.
- Validate with
bun run buildand affected source test suites.
Acceptance Criteria
- #1 Non-test
as neveroccurrences insrc/main.tsandsrc/main/runtimeare reduced to zero or documented narrow exceptions. - #2 Runtime dependency builders compile without unsafe production-path cast escapes.
- #3 Contract regressions are caught by compile/test checks rather than runtime behavior.
Implementation Plan
- Baseline cast inventory in non-test scope (
src/main.ts,src/main/runtime/*) usingrgand record before-count in notes. - Tighten runtime adapter contracts to remove
as neverescapes in*-main-depsmodules: MPV/Jellyfin defaults, startup config deps, overlay visibility/options deps, field-grouping deps, CLI context deps, subtitle tokenization deps, dictionary runtime deps, tray/app deps, and MPV event bindings. - Update
src/main.tsboundary wiring to match tightened contracts and remove cast escapes in config hot-reload setters, dictionary lookup setters, MPV defaults/OSD wiring, MPV client factory constructor typing, tray creation, and overlay bootstrap callbacks. - Re-run cast scan expecting zero non-test unsafe casts (or document narrow exceptions), run required gates (
bun run build,bun run test:core:src), then attach before/after cast report and finalize AC/DoD.
Implementation Notes
Executed TASK-105 implementation with runtime contract tightening across src/main.ts + src/main/runtime/* non-test files. Removed all unsafe as never / as unknown as casts in target scope by replacing unknown passthrough contracts with typed deps (MPV/Jellyfin runtime types, overlay/bootstrap deps, tokenizer/CLI deps, dictionary lookup function types, tray deps typing).
Cast reduction report: baseline scan count = 42 non-test matches (rg -n "as\\s+never|as\\s+unknown\\s+as" src/main.ts src/main/runtime --glob '!**/*.test.ts'), after changes = 0 matches with same command.
Verification: targeted runtime cast-refactor tests passed (bun test ... across 19 files, 35 pass / 0 fail). Required core lane passed: bun run test:core:src => 236 pass / 6 skip / 0 fail.
Blocker: bun run build currently fails on pre-existing unrelated typing issues in src/anki-integration/note-update-workflow.test.ts (6 TS errors). No remaining build errors from TASK-105 touched files.
Follow-up verification rerun after concurrent compile-fix pass: bun run build now succeeds on current HEAD (tsc + renderer build + packaging copy step). DoD build gate unblocked.
Final Summary
Eliminated unsafe non-test runtime cast escapes in src/main.ts and src/main/runtime/* by tightening runtime dependency-builder contracts (MPV/Jellyfin, overlay/bootstrap, CLI/tokenizer, dictionary/tray boundaries) and removing as never / as unknown as patterns in production paths. Captured cast reduction evidence (42 -> 0 matches in scoped scan), validated focused runtime suites (35 pass), and revalidated required gates (bun run test:core:src, bun run build) on current HEAD.
Definition of Done
- #1 Cast reduction report attached in task notes (before/after counts).
- #2
bun run buildandbun run test:core:srcpass. - #3 Any remaining exceptions have explicit rationale in code comments or task notes.