Files
SubMiner/Backlog.md
sudacode 35adf8299c Refactor startup, queries, and workflow into focused modules (#36)
* chore(backlog): add mining workflow milestone and tasks

* refactor: split character dictionary runtime modules

* refactor: split shared type entrypoints

* refactor: use bun serve for stats server

* feat: add repo-local subminer workflow plugin

* fix: add stats server node fallback

* refactor: split immersion tracker query modules

* chore: update backlog task records

* refactor: migrate shared type imports

* refactor: compose startup and setup window wiring

* Add backlog tasks and launcher time helper tests

- Track follow-up cleanup work in Backlog.md
- Replace Date.now usage with shared nowMs helper
- Add launcher args/parser and core regression tests

* test: increase launcher test timeout for CI stability

* fix: address CodeRabbit review feedback

* refactor(main): extract remaining inline runtime logic from main

* chore(backlog): update task notes and changelog fragment

* refactor: split main boot phases

* test: stabilize bun coverage reporting

* Switch plausible endpoint and harden coverage lane parsing

- update docs-site tracking to use the Plausible capture endpoint
- tighten coverage lane argument and LCOV parsing checks
- make script entrypoint use CommonJS main guard

* Restrict docs analytics and build coverage input

- limit Plausible init to docs.subminer.moe
- build Yomitan before src coverage lane

* fix(ci): normalize Windows shortcut paths for cross-platform tests

* Fix verification and immersion-tracker grouping

- isolate verifier artifacts and lease handling
- switch weekly/monthly tracker cutoffs to calendar boundaries
- tighten boot lifecycle and zip writer tests

* fix: resolve CI type failures in boot and immersion query tests

* fix: remove strict spread usage in Date mocks

* fix: use explicit super args for MockDate constructors

* Factor out mock date helper in tracker tests

- reuse a shared `withMockDate` helper for date-sensitive query tests
- make monthly rollup assertions key off `videoId` instead of row order

* fix: use variadic array type for MockDate constructor args

TS2367: fixed-length tuple made args.length === 0 unreachable.

* refactor: remove unused createMainBootRuntimes/Handlers aggregate functions

These functions were never called by production code — main.ts imports
the individual composeBoot* re-exports directly.

* refactor: remove boot re-export alias layer

main.ts now imports directly from the runtime/composers and runtime/domains
modules, eliminating the intermediate boot/ indirection.

* refactor: consolidate 3 near-identical setup window factories

Extract shared createSetupWindowHandler with a config parameter.
Public API unchanged.

* refactor: parameterize duplicated getAffected*Ids query helpers

Four structurally identical functions collapsed into two parameterized
helpers while preserving the existing public API.

* refactor: inline identity composers (stats-startup, overlay-window)

composeStatsStartupRuntime was a no-op that returned its input.
composeOverlayWindowHandlers was a 1-line delegation.
Both removed in favor of direct usage.

* chore: remove unused token/queue file path constants from main.ts

* fix: replace any types in boot services with proper signatures

* refactor: deduplicate ensureDir into shared/fs-utils

5 copies of mkdir-p-if-not-exists consolidated into one shared module
with ensureDir (directory path) and ensureDirForFile (file path) variants.

* fix: tighten type safety in boot services

- Add AppLifecycleShape and OverlayModalInputStateShape constraints
  so TAppLifecycleApp and TOverlayModalInputState generics are bounded
- Remove unsafe `as { handleModalInputStateChange? }` cast — now
  directly callable via the constraint
- Use `satisfies AppLifecycleShape` for structural validation on the
  appLifecycleApp object literal
- Document Electron App.on incompatibility with simple signatures

* refactor: inline subtitle-prefetch-runtime-composer

The composer was a pure pass-through that destructured an object and
reassembled it with the same fields. Inlined at the call site.

* chore: consolidate duplicate import paths in main.ts

* test: extract mpv composer test fixture factory to reduce duplication

* test: add behavioral assertions to composer tests

Upgrade 8 composer test files from shape-only typeof checks to behavioral
assertions that invoke returned handlers and verify injected dependencies are
actually called, following the mpv-runtime-composer pattern.

* refactor: normalize import extensions in query modules

* refactor: consolidate toDbMs into query-shared.ts

* refactor: remove Node.js fallback from stats-server, use Bun only

* Fix monthly rollup test expectations

- Preserve multi-arg Date construction in mock helper
- Align rollup assertions with the correct videoId

* fix: address PR 36 CodeRabbit follow-ups

* fix: harden coverage lane cleanup

* fix(stats): fallback to node server when Bun.serve unavailable

* fix(ci): restore coverage lane compatibility

* chore(backlog): close TASK-242

* fix: address latest CodeRabbit review round

* fix: guard disabled immersion retention windows

* fix: migrate discord rpc wrapper

* fix(ci): add changelog fragment for PR 36

* fix: stabilize macOS visible overlay toggle

* fix: pin installed mpv plugin to current binary

* fix: strip inline subtitle markup from sidebar cues

* fix(renderer): restore subtitle sidebar mpv passthrough

* feat(discord): add configurable presence style presets

Replace the hardcoded "Mining and crafting (Anki cards)" meme message
with a preset system. New `discordPresence.presenceStyle` option
supports four presets: "default" (clean bilingual), "meme" (the OG
Minecraft joke), "japanese" (fully JP), and "minimal". The default
preset shows "Sentence Mining" with 日本語学習中 as the small image
tooltip. Existing users can set presenceStyle to "meme" to keep the
old behavior.

* fix: finalize v0.10.0 release prep

* docs: add subtitle sidebar guide and release note

* chore(backlog): mark docs task done

* fix: lazily resolve youtube playback socket path

* chore(release): build v0.10.0 changelog

* Revert "chore(release): build v0.10.0 changelog"

This reverts commit 9741c0f020.
2026-03-29 16:16:29 -07:00

9.2 KiB

Backlog

Purpose: lightweight repo-local task board. Seeded with current testing / coverage work.

Status keys:

  • todo: not started
  • doing: in progress
  • blocked: waiting
  • done: shipped

Priority keys:

  • P0: urgent / release-risk
  • P1: high value
  • P2: useful cleanup
  • P3: nice-to-have

Active

ID Pri Status Area Title
SM-013 P1 done review-followup Address PR #36 CodeRabbit action items

Ready

ID Pri Status Area Title
SM-001 P1 todo launcher Add tests for CLI parser and args normalizer
SM-002 P1 todo immersion-tracker Backfill tests for uncovered query exports
SM-003 P1 todo anki Add focused field-grouping service + merge edge-case tests
SM-004 P2 todo tests Extract shared test utils for deps factories and polling helpers
SM-005 P2 todo tests Strengthen weak assertions in app-ready and IPC tests
SM-006 P2 todo tests Break up monolithic youtube-flow and subtitle-sidebar tests
SM-007 P2 todo anilist Add tests for AniList rate limiter
SM-008 P3 todo subtitles Add core subtitle-position persistence/path tests
SM-009 P3 todo tokenizer Add tests for JLPT token filter
SM-010 P1 todo immersion-tracker Refactor storage + immersion-tracker service into focused modules
SM-011 P1 done tests Add coverage reporting for maintained test lanes
SM-012 P2 done config/runtime Replace JSON serialize-clone helpers with structured cloning

Icebox

None.

Ticket Details

SM-001

Title: Add tests for CLI parser and args normalizer Priority: P1 Status: done Scope:

  • launcher/config/cli-parser-builder.ts
  • launcher/config/args-normalizer.ts Acceptance:
  • root options parsing covered
  • subcommand routing covered
  • invalid action / invalid log level / invalid backend cases covered
  • target classification covered: file, directory, URL, invalid

SM-002

Title: Backfill tests for uncovered query exports Priority: P1 Status: todo Scope:

  • src/core/services/immersion-tracker/query-*.ts Targets:
  • headword helpers
  • anime/media detail helpers not covered by existing wrapper tests
  • lexical detail / appearance helpers
  • maintenance helpers beyond deleteSession and upsertCoverArt Acceptance:
  • every exported query helper either directly tested or explicitly justified as covered elsewhere
  • at least one focused regression per complex SQL branch / aggregation branch

SM-003

Title: Add focused field-grouping service + merge edge-case tests Priority: P1 Status: todo Scope:

  • src/anki-integration/field-grouping.ts
  • src/anki-integration/field-grouping-merge.ts Acceptance:
  • auto/manual/disabled flow branches covered
  • duplicate-card preview failure path covered
  • merge edge cases covered: empty fields, generated media fallback, strict grouped spans, audio synchronization

SM-004

Title: Extract shared test utils for deps factories and polling helpers Priority: P2 Status: todo Scope:

  • common makeDeps / createDeps helpers
  • common waitForCondition Acceptance:
  • shared helper module added
  • at least 3 duplicated polling helpers removed
  • at least 5 duplicated deps factories consolidated or clearly prepared for follow-up migration

SM-005

Title: Strengthen weak assertions in app-ready and IPC tests Priority: P2 Status: todo Scope:

  • src/core/services/app-ready.test.ts
  • src/core/services/ipc.test.ts Acceptance:
  • replace broad assert.ok(...) presence checks with exact value / order assertions where expected value known
  • handler registration tests assert channel-specific behavior, not only existence

SM-006

Title: Break up monolithic youtube-flow and subtitle-sidebar tests Priority: P2 Status: todo Scope:

  • src/main/runtime/youtube-flow.test.ts
  • src/renderer/modals/subtitle-sidebar.test.ts Acceptance:
  • reduce single-test breadth
  • split largest tests into focused cases by behavior
  • keep semantics unchanged

SM-007

Title: Add tests for AniList rate limiter Priority: P2 Status: todo Scope:

  • src/core/services/anilist/rate-limiter.ts Acceptance:
  • capacity-window wait behavior covered
  • x-ratelimit-remaining + reset handling covered
  • retry-after handling covered

SM-008

Title: Add core subtitle-position persistence/path tests Priority: P3 Status: todo Scope:

  • src/core/services/subtitle-position.ts Acceptance:
  • save/load persistence covered
  • fallback behavior covered
  • path normalization behavior covered for URL vs local target

SM-009

Title: Add tests for JLPT token filter Priority: P3 Status: todo Scope:

  • src/core/services/jlpt-token-filter.ts Acceptance:
  • excluded term membership covered
  • ignored POS1 membership covered
  • exported list / entry consistency covered

SM-010

Title: Refactor storage + immersion-tracker service into focused layers without API changes Priority: P1 Status: todo Scope:

  • src/core/database/storage/storage.ts
  • src/core/database/storage/schema.ts
  • src/core/database/storage/cover-blob.ts
  • src/core/database/storage/records.ts
  • src/core/database/storage/write-path.ts
  • src/core/services/immersion-tracker/youtube.ts
  • src/core/services/immersion-tracker/youtube-manager.ts
  • src/core/services/immersion-tracker/write-queue.ts
  • src/core/services/immersion-tracker/immersion-tracker-service.ts

Acceptance:

  • behavior and public API remain unchanged for all callers
  • storage.ts responsibilities split into DDL/migrations, cover blob helpers, record CRUD, and write-path execution
  • immersion-tracker-service.ts reduces to session state, media change orchestration, query proxies, and lifecycle
  • YouTube code split into pure utilities, a stateful manager (YouTubeManager), and a dedicated write queue (WriteQueue)
  • removed storage.ts is replaced with focused modules and updated imports
  • no API or migration regressions; existing tests for trackers/storage coverage remain green or receive focused updates

SM-011

Title: Add coverage reporting for maintained test lanes Priority: P1 Status: done Scope:

  • package.json
  • CI workflow files under .github/
  • docs/workflow/verification.md Acceptance:
  • at least one maintained test lane emits machine-readable coverage output
  • CI surfaces coverage as an artifact, summary, or check output
  • local contributor path for coverage is documented
  • chosen coverage path works with Bun/TypeScript lanes already maintained by the repo Implementation note:
  • Added bun run test:coverage:src for the maintained source lane via a sharded coverage runner, with merged LCOV output at coverage/test-src/lcov.info and CI/release artifact upload as coverage-test-src.

SM-012

Title: Replace JSON serialize-clone helpers with structured cloning Priority: P2 Status: todo Scope:

  • src/runtime-options.ts
  • src/config/definitions.ts
  • src/config/service.ts
  • src/main/controller-config-update.ts Acceptance:
  • runtime/config clone helpers stop using JSON.parse(JSON.stringify(...))
  • replacement preserves current behavior for plain config/runtime objects
  • focused tests cover clone/merge behavior that could regress during the swap
  • no new clone helper is introduced in these paths without a documented reason

Done:

  • replaced JSON serialize-clone call sites in runtime/config/controller update paths with structuredClone
  • updated focused tests and fixtures to cover detached clone behavior and guard against regressions

SM-013

Title: Address PR #36 CodeRabbit action items Priority: P1 Status: done Scope:

  • plugins/subminer-workflow/skills/subminer-change-verification/scripts/verify_subminer_change.sh
  • scripts/subminer-change-verification.test.ts
  • src/core/services/immersion-tracker/query-sessions.ts
  • src/core/services/immersion-tracker/query-trends.ts
  • src/core/services/immersion-tracker/maintenance.ts
  • src/main/boot/services.ts
  • src/main/character-dictionary-runtime/zip.test.ts Acceptance:
  • fix valid open CodeRabbit findings on PR #36
  • add focused regression coverage for behavior changes where practical
  • verify touched tests plus typecheck stay green

Done:

  • hardened --artifact-dir validation in the verification script
  • fixed trend aggregation rounding and monthly ratio bucketing
  • preserved unwatched anime episodes in episode queries
  • restored seconds-based aggregate timestamps in shared maintenance
  • fixed the startup refactor compile break by making the predicates local at the call site
  • verified with bun test src/core/services/immersion-tracker/__tests__/query.test.ts src/core/services/immersion-tracker/__tests__/query-split-modules.test.ts and bun run typecheck