Skip to content

Extract the edit-tool scaffold copied into ~36 tools #308

Closed

Description

@TMHSDigital

Summary

About 36 edit tools repeat the same scaffold: requireFfmpeg(), input-exists check (51 copies, 5 spellings), assertEditContainer, resolveOutput(... stamp()-rand() ...), runEditJob, okResponse/errorResponse. Copies have drifted (see the container-check regression filed separately).

Where

  • src/tools/trim.ts:46-77 and src/tools/crop.ts:112-138 (representative)
  • src/utils/media.ts:277-288 (assertEditContainer)

Impact

Every cross-cutting fix (#187 containers, #221 confinement, .partial cleanup) has to be applied N times; missed copies become latent bugs.

Suggested fix

  1. Add utils/editTool.ts with requireInput(path, label?) and editOutput(args, tag, ext, { container }) bundling the container check, resolveOutput and naming
  2. Migrate a few tools per commit
  3. Optionally add runEditTool(handler) to absorb try/requireFfmpeg/errorResponse
    Tests first: a table-driven tool-layer test calling every edit tool with a .webm output and a missing input.

Acceptance criteria

  • Shared helper used by all edit tools
  • Table-driven test in place

Getting started

  • Relevant files: src/tools/trim.ts, src/utils/media.ts
  • How to run tests: npm run build && npm test (also npm run typecheck and npm run lint)
  • Related docs: CONTRIBUTING.md, AGENTS.md

Filed by repo-audit/full-audit at f2fda28. Severity: medium. Effort: M. audit-key: tech-debt|src/tools|edit-tool-scaffold

Activity

  1. added
    help wanted
    tech-debt
    on Nov 9, 2026
  2. TMHSDigital commented on Nov 10, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 109197b.

    src/utils/editTool.ts adds two helpers:

    41 tool modules now use them. Container behaviour is unchanged. Tools that write other formats or stream copies pass anyContainer: extract_audio, export_gif, transcribe, convert, chapters, the callout/redact stills, save_replay, screenshot, and the trim and concat copies.

    editTool.test.ts tests both helpers. It also fails if any tool hand-writes the input check or builds a default edit name with resolveOutput(..., subdir("edits"), ...). The optional runEditTool wrapper is not included, because the handlers differ too much in what they return and clean up. The full suite passes (1115 tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedpriority: mediumtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions