Commit 9791fd8
committed
refactor(media): reuse shared execution limits and give each rule one home
Quality pass over the ffmpeg hardening, from a four-angle review.
Reuse:
- Replace the hand-rolled OperationBudget with createTimeoutAbortController
from @/lib/core/execution-limits, which already models "one deadline plus a
parent signal, and tell me which fired". This also removes the per-command
setTimeout: the controller's single deadline covers the whole operation, so
probeFile now takes its cap from getRemainingExecutionMs.
- Combine the tool's cancellation signals with combineExecutionAbortSignals,
and move that helper to base-tool.ts next to assertServerToolNotAborted,
where the shared "how does a tool consume cancellation" concern lives.
Altitude:
- Delete assertOptionsWithinBounds. Every rule in it also lived in the
operation that consumes it, and the two copies had already diverged:
extract_audio's allowlist existed only in the preflight, and the end >= start
check only there. Each rule now has exactly one home, at its point of use.
- Stop resolving the ffmpeg binary in withTempDir, so a validation failure no
longer surfaces as "FFmpeg not found" on a host without it. runCommand and
probeFile resolve it, being the only things that need it.
- Add tempPath(), which resolves a name inside the temp dir and refuses
anything that escapes. All 14 path sites go through it, so the containment
invariant is structural rather than dependent on remembering to sanitize
every filename source.
- Declare OUTPUT_EXTS explicitly instead of deriving the allowlist from
EXT_TO_MIME, so widening a content-type map cannot widen what may be written.
Also: a supplied width/height of 0 now reaches the bounds check rather than
being treated as absent, memoize the resolved ffprobe path, and settle() on a
synchronous throw from .save() so no listener outlives the command.
Tests: replace two assertions that could not fail (`rejects.not.toThrow` passes
on any rejection, including "FFmpeg not found") with deterministic ones, which
also removes every real ffmpeg spawn from the suite — 293ms of test time to
21ms. Verified hermetic with ffmpeg off PATH, and verified against real ffmpeg
out-of-band that probe, convert, scale_pad, budget expiry, and external abort
all still behave.1 parent 260abe8 commit 9791fd8
4 files changed
Lines changed: 249 additions & 242 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
31 | 44 | | |
32 | 45 | | |
33 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | 80 | | |
93 | 81 | | |
94 | 82 | | |
| |||
180 | 168 | | |
181 | 169 | | |
182 | 170 | | |
183 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
184 | 174 | | |
185 | 175 | | |
186 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | | - | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
81 | 86 | | |
82 | | - | |
83 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
84 | 91 | | |
85 | 92 | | |
86 | 93 | | |
| |||
0 commit comments