Skip to content

fix(cli): tests read opencv.js from a CI cache, never a CDN mid-test - #7968

Merged
miguel-heygen merged 4 commits into
mainfrom
fix/cli-opencv-from-cache
Nov 18, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
fix/cli-opencv-from-cache

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

The CLI tests no longer download opencv.js (10 MB, from a CDN) while they run. CI restores it and the face models from a cache keyed on opencv.ts's pins. On a cache miss it fetches them once in a step before the tests. A CLI test on CI that finds no cached copy now fails with a message naming the cache, instead of downloading.

Why

Test (cli 2/2) failed on an unrelated PR with could not download opencv.js (... bytes 8388608-10378214 dropped 4 times) from diff.test.ts > diffVideos. Every CI run downloaded the file inside the test's beforeAll, so any CDN hiccup turned a CLI shard red.

What changes

  • .github/actions/opencv-test-cache (new): actions/cache on ~/.cache/hyperframes/opencv, keyed on the OS and packages/cli/src/measure/opencv.ts, so a pin change starts a fresh cache. On a miss it runs packages/cli/scripts/prepare-test-opencv.mjs, which calls opencv.ts's own loadOpenCv. The size and sha256 pins stay in one place. This follows prepare-process-test-browser.mjs.
  • ci.yml test-cli and windows-render.yml's two engine-cli lanes use the action before their tests.
  • diff.test-helpers.ts:
    • seedOpenCvFromCache() is now the one place that copies a cached opencv.js into a test file's home.
    • It makes the folders private first. opencv.ts refuses a group-writable folder and downloads again, which is what happened under a 002 umask.
    • loadOpenCvFirst throws on CI when no cached copy exists.
  • scripts/test-reachability.json: the test-cli job's pinned hash is refreshed. The job runs the same vitest command over the same files, with one step added before it. check-test-reachability.mjs passes (zero orphan tests), and its tests pass 30/30.
  • face.test.ts uses seedOpenCvFromCache() in place of its own copy of that code. With the cache present on CI, its OpenCV tests now run there instead of skipping.

How it was checked

Every run below had fetch replaced by one that logs and throws, CI=1, a fresh TMPDIR and the default 002 umask.

  • fails without the fix: main's helper with no cached copy fails diff.test.ts with could not download opencv.js and tries one download.
  • With the fix and no cached copy, it fails with opencv.js is not in …: on CI the opencv-test-cache action puts it there and tries no download.
  • After prepare-test-opencv.mjs:
    • diff.test.ts, diff-offset, diff-people, diff-segments, diff.exit and face.test.ts made 0 download attempts in each of 3 runs.
    • 62 of 63 tests passed each time. The one failure, diff-offset's cut-matching test, is cut detection under the box's ffmpeg 7.0.2; CI pins ffmpeg 8.
  • Removing the private-folder step brings the download back under umask 002, so that step is needed.
  • tsc --noEmit reports no error in the changed files, and the commit hooks (typecheck, fallow, format) pass. fallow lists the new script as an entry, since only CI runs it.

Not checked

  • The Windows lanes and the first cache miss on CI. This PR's own runs exercise both.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 80 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-center-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Eddy's agent) Reviewed by Eddy's Claude agent at commit 97c54bc.

Verdict: not approved yet (comment only, no code blocker).

Summary. No SecOps finding is attached; this is a CI reliability change. CLI tests used to download opencv.js (executed code) from jsdelivr inside a test hook on every run; the PR adds a composite action that restores opencv.js and the face models from an Actions cache, fetches them once before the tests on a cache miss, and makes the test helper fail on CI instead of downloading when no cached copy exists. The size and sha256 pins in packages/cli/src/measure/opencv.ts are still checked on every load before opencv.js is required, so a restored cache entry is not trusted on its own. No trigger, permission, secret or dependency change; the one failing check (Test -> Test (support)) is an inspector test timeout in code this PR does not touch.

Why this is a comment and not an approval. The PR changes CI: a new composite action (.github/actions/opencv-test-cache/action.yml, an actions/cache step pinned by SHA and keyed on the hash of packages/cli/src/measure/opencv.ts, plus a fetch step on a cache miss) and one uses: step each in ci.yml and windows-render.yml. I read every added line: no change to triggers, permissions or secrets, and the restored or fetched opencv.js is still checked against the size and sha256 pins in opencv.ts before it is loaded, so a cache entry is not trusted on its own. I found no code blocker. During the incident I do not approve CI workflow changes without Eddy's word, so the approval waits on him.

The required Test check was red at this commit from Test (support): an inspector test timed out at 5 s in code this PR does not touch (the flake #7962 fixes); a rerun was in progress when I looked.

Blockers

None.

Non-blockers

  1. packages/cli/src/measure/diff.test-helpers.ts:54: CI guard checks only that opencv.js exists, so a partial or rejected cache still downloads mid-test. seedOpenCvFromCache returns true when OPENCV_DIR/opencv.js exists. If the restored cache lacks a cascade .xml, a file fails its sha256, or the copy is rejected as group-writable, the throw at line 61 is skipped and loadOpenCv (line 65) silently re-downloads from jsdelivr / raw.githubusercontent inside the hook. This is safe (the download is hash-verified) but is the CDN-in-test flake the PR says it removes. To resolve: Optional: have the CI branch assert all pinned files verify (or inject a throwing fetch on CI) so any mid-test download fails loudly.
  2. packages/cli/src/measure/face.test.ts:13: face.test.ts silently skips on CI when the cache is missing, unlike the diff tests. const opencv = media && seedOpenCvFromCache() feeds a skipIf; if the cache step is dropped from a lane or restores to a different home, the faceBoxes tests skip and the job stays green, while loadOpenCvFirst users throw in the same situation. To resolve: Optional: throw on CI when seedOpenCvFromCache() is false, as loadOpenCvFirst does.
  3. .github/actions/opencv-test-cache/action.yml:15: Cache-miss path makes the CDN fetch a prerequisite of the whole CLI job and saves the cache only if the job passes. On a miss (opencv.ts edited in any way, cache evicted, first run on a ref) node --import tsx packages/cli/scripts/prepare-test-opencv.mjs runs before any test; a CDN outage then fails both CLI shards and both Windows lanes outright, and because actions/cache saves in its post step only on job success, a PR with any failing CLI test re-downloads on every rerun. The script also instantiates the wasm (loadOpenCv) when only download+verify is needed. To resolve: Optional follow-up: key on the version/pins rather than the whole file, save with actions/cache/save right after the fetch, and call a download-and-verify-only export.

Fix criteria from the finding

  • none: (implied) Restored or fetched opencv.js is verified against a pinned hash before it is executed: met (packages/cli/src/measure/opencv.ts:128-131 ensureOpenCv re-checks size+sha256 (verifies, whisper/modelFile.ts:17-20) of every pinned file on each loadOpenCv call, and only then opencv.ts:164 requires opencv.js; a mismatching file is re-downloaded and re-verified (opencv.ts:138-144). The test helper (diff.test-helpers.ts:65) and the prepare script (prepare-test-opencv.mjs:5) both go through loadOpenCv; git grep shows opencv.ts:164 is the only place opencv.js is loaded.)
  • none: (implied) A pull request cannot plant a cache entry that main or a release job restores and executes: met (.github/actions/opencv-test-cache/action.yml:12 key is opencv-${{ runner.os }}-${{ hashFiles('packages/cli/src/measure/opencv.ts') }} with no restore-keys, so only exact-key hits; GitHub scopes caches written by pull_request and merge_group runs to their own ref, and even a bad entry fails the sha256 check before execution. Only ci.yml test-cli and windows-render engine-cli lanes use it; publish.yml does not.)
  • none: (implied) Pins live in reviewed code and cannot change unnoticed: met (Pins and URLs are in packages/cli/src/measure/opencv.ts:26-45 (unchanged by this PR); the cache key hashes that file, so any pin edit shows in the diff and starts a new cache.)
  • none: (implied) Actions pinned by SHA; no trigger, permission or secret widening: met (action.yml:9 actions/cache@0057852 (same SHA already used in install-ffmpeg-linux, preflight, publish.yml). ci.yml and windows-render.yml diffs add only the uses: ./.github/actions/opencv-test-cache step (ci.yml:614, windows-render.yml:507-508); permissions stay contents: read (+ pull-requests: read in ci.yml), no secrets or env passed to the step.)

Open outside this PR

  • Windows lanes (Tests on windows-latest: engine-cli-1 / engine-cli-2) had not finished when reviewed, so the action's behaviour on Windows (~ expansion to the profile dir, cache miss then fetch under bash, the 20 s per-test limit for the newly enabled faceBoxes tests) is not confirmed; the owner should wait for those two checks.
  • The second CI run on this SHA was still in progress; Test (support) needs to pass on rerun (first failure was an inspector httpContract 5 s timeout unrelated to this diff, worth tracking as a flake).
  • Pre-existing, untouched: the tests' shared fallback copy lives at a predictable path in the temp dir (tmpdir()/hf-test-opencv-, diff.test-helpers.ts:45,66-74). Content is hash-verified before execution, so it is not an execution risk, but it is a predictable shared-temp path on multi-user machines.
  • Pre-existing, untouched: opencv.js integrity rests on the sha256 pin in opencv.ts; any future PR changing that pin or URL needs a reviewer to check the new hash against the upstream package (not checkable from the repo).
  • Who can write Actions caches on the default branch and the repo's fork-PR workflow approval settings are GitHub settings outside the repository; not verified here.

CI: required Test was red from Test (support) (an inspector test timeout in untouched code); a rerun and several other jobs were pending when I looked.

How this was reviewed: a code-review pass and a security-review pass against the Mythos finding, by a reviewer agent in an isolated checkout of this commit; I then read the core of the fix and the cited lines myself. Nothing was built or run.

…ache

# Conflicts:
#	packages/cli/src/measure/face.test.ts

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 4e9fef0.

  • The merge of main keeps main's stall mock in face.test.ts (the vi.hoisted / node:child_process mock) and drops only the old hand-copied cache block. The diff against the merge base contains just this PR's eight files.
  • On CI, trustedCacheRoot() puts OPENCV_DIR at ~/.cache/hyperframes/opencv/4.10.0. The prepare step printed exactly that on Windows, so after the action runs, seedOpenCvFromCache() finds the file already in place and loadOpenCv makes no request.
  • This PR's own runs took the cache-miss path on all three lanes I read: Linux cli 1/2 and 2/2, and Windows engine-cli-1. Each printed Cache not found, then downloaded once in the prepare step, before any test ran.
  • face.test.ts ran its 11 tests on Linux instead of skipping, and diff.test.ts passed 25.
  • Keying the cache on opencv.ts is right, since the size and sha256 pins live there.
  • The mode: 0o700 on mkdirSync applies only to the folders it creates. That covers the fresh-TMPDIR / umask-002 case the body describes.
  • The CI throw is the right shape: a missing cache now fails with a message naming the action instead of hitting the CDN.

Non-blocking: a CDN failure on a cache miss now fails the prepare step rather than a test shard. That is one attempt per OS per pin change, which the job-level rerun covers.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit e6cee09 Nov 18, 2026
85 checks passed
@miguel-heygen
miguel-heygen deleted the fix/cli-opencv-from-cache branch November 18, 2026 02:27
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.

3 participants