Skip to content

Refactor: deepen internal modules and table-driven flag parsing - #152

Merged
renezander030 merged 7 commits into
masterfrom
refactor/deepen-internal-modules
Oct 14, 2026
Merged

renezander030 merged 7 commits into
masterfrom
refactor/deepen-internal-modules

Conversation

@renezander030

Copy link
Copy Markdown
Owner

Internal refactor with no behaviour change. Duplicated logic moves behind small internal modules, and the CLI flag parser becomes table-driven.

Changes

  • Atomic writes: a new src/atomic-write.ts holds the temp + fsync + rename staging. The user-enums catalogue and the app-version tracker now use the same random-name, exclusive-create temp file as draft saves. draft.writeAtomic keeps its signature.
  • JSON metadata reads: readJsonObjectFile / parseJsonObject (in bom.ts) replace seven hand-rolled read-and-parse copies in register, rename, media registration and the CLI. An absent file and a corrupt one remain distinct outcomes.
  • register / rename: one guard now handles the "changed on disk after it was planned" refusal for both commands.
  • Segment lookup: requireSegment (src/segment-lookup.ts) replaces 17 find-or-throw copies and saveTemplate's own search loop. The error message is unchanged.
  • detect-scenes / detect-silence: both run their ffmpeg pass through runFfmpegAnalysis (src/ffmpeg-pass.ts). Each keeps its own error labels and hints.
  • Flag parsing: 165 single-field flags (boolean, text, float, integer, Number) move from parseFlags branches into typed tables. A table entry that doesn't match its Flags field fails type-checking. Flags with validation, multiple values or command scoping keep their branches.
  • Dead code: removes the unused detectStoreAppVersion and mattingState.

src/ goes from 23,330 to 23,119 code lines, not counting blanks and comments.

Verification

  • npm run build, npm test (1228 tests, 0 failures; 10 new), npm run lint, npm run wasm:verify, Python client unit tests, npm pack + npm run smoke:package, all on Node 20.
  • New tests pin current behaviour, and each passes on master as well as on this branch:
    • the changed-on-disk refusal and --force-write for rename and register
    • exact ffmpeg failure messages for both detectors (unavailable, timeout, buffer overflow, non-zero exit)
    • absent / BOM / non-object JSON reads
    • atomic state-file writes
  • Old and new parseFlags return identical results on 107,996 argument vectors: every flag, in every command context, with the value present, missing, flag-like and repeated.
  • Public surface is unchanged:
    • --help and every <command> --help
    • describe output
    • lib.js exports
    • all shipped .d.ts files (byte-identical)

Review notes

The user-enums catalogue and the app-version tracker now stage writes
through the same random-name, exclusive-create temp file as draft saves.
readJsonObjectFile tells an absent file (raw null) from a corrupt one
(obj null); register, rename and media registration use it.
Adds tests for the refusal and for --force-write.
…silence

Error messages are unchanged and now pinned by tests.
Boolean, text and numeric flags that only set one field move into typed
tables; flags with validation or command scoping keep their branches.
@renezander030
renezander030 merged commit 30e2b1d into master Oct 14, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant