Files
SubMiner/docs/workflow/testing.md
T
sudacode 90fc7cf940 refactor(main): fold remaining main-deps builders into their handlers (#308)
* refactor(main): drop remaining pass-through main-deps builders

Jellyfin client-info/setup-window/remote, overlay shortcuts/visibility/
layout/window-factory, config hot-reload, and startup bootstrap factory
builders only forwarded deps. Callers now pass deps to the handlers
directly; createWatchConfigPathHandler moves into config-hot-reload-handlers.

* refactor(main): fold small-logic main-deps builders into their handlers

Tray click, mpv client factory, startup bootstrap exit callbacks, overlay
runtime options, and dictionary roots/runtime builders move their logic
into the owning handler or call site. The two duplicated dictionary-root
builders become one createBuildDictionaryRootsHandler(vendorDirName).

* refactor(main): fold cli command context builders into the factory

createCliCommandContextFactory now adapts appState and main services to
the CLI command context deps directly (socket-path change notification,
texthooker port/websocket URL, browser-open default). The pass-through
cli-command-context-main-deps and cli-command-context-deps layers are
removed; their behavioural tests now run against the factory's context.

* refactor(main): fold subtitle tokenization builder into the mpv composer

The tokenizer deps builder's logic (known-word lookup recording and the
character-dictionary gate on name matching) becomes
buildTokenizerRuntimeOptions in mpv-runtime-composer, tested through the
composer. The MeCab check and dictionary prewarm handlers move to
subtitle-tokenization-warmup.ts, and the unused BuiltMainDeps type is
removed from composer contracts.

* refactor(main): drop redundant tokenizer deps keys and cast

* refactor(main): end the main-deps builder pattern

mpv-main-event-main-deps becomes mpv-main-event-binding-deps
(createMpvMainEventBindingDeps), returning the binding deps directly
instead of a thunk; it owns the subtitle-recording state. The will-quit
cleanup adapter likewise returns its deps directly, and the pass-through
app-lifecycle activate builders are removed.

* docs: drop references to main-deps builders
2026-10-31 14:07:07 -07:00

2.2 KiB

Testing Guidelines

Status: active
Last verified: 2026-10-04
Owner: Kyle Yasuda
Read when: adding or changing tests

Which lanes to run lives in Verification. This page covers what a good test looks like here.

Test Behavior, Not Wiring

  • Exercise a module through its public interface and assert outcomes: return values, resulting state, files written, rows in sqlite, messages sent to a fake process.
  • Prefer real collaborators that are cheap: tmp dirs, in-memory or tmp sqlite, fake executables, pure parsers. Fake only the edges (Electron, mpv socket, network).
  • Assert call order only when order is the behavior (startup sequencing, ABA races), and then assert relative order, not the whole call log.

Do Not Write

  • Pass-through tests: a handler or adapter that only forwards deps (*-runtime-handlers.ts) needs no test. TypeScript already checks the shape.
  • Source-text tests: reading .ts, .css, .html, .lua, .swift, or workflow YAML and asserting with regexes. If the invariant matters, extract the logic and run it (see src/preload-ipc-listeners.ts). Policy lints over workflow YAML are the exception and belong in one parsed-YAML check.
  • "Stays deleted" tests for removed modules, flags, or selectors. tsc and review catch reintroduction.
  • Tests that restate constants, defaults, labels, or window options.
  • The same rule at several layers. Test a rule once where it lives; keep one end-to-end case (for the tokenizer, the golden corpus) for integration.

Keep Tests Small

  • Shared setup goes in a makeDeps(overrides) helper or a *-test-harness.ts file, not pasted into every test.
  • Near-identical cases become a table: for (const c of cases) test(c.name, ...).
  • Inject timers, clocks, and loggers instead of patching globals or private members.
  • A bug fix gets a regression test for the behavior that broke, named after the behavior, not the ticket.

Known Debt

  • src/main/main-wiring.test.ts and src/renderer/renderer-init-order.test.ts still regex main.ts / renderer.ts to guard startup ordering. Replace each test with a behavioral one as the logic moves out of main.ts closures.