feat(validate): extract @hyperframes/validate importable runtime validate#2013
Draft
xuanruli wants to merge 1 commit into
Draft
feat(validate): extract @hyperframes/validate importable runtime validate#2013xuanruli wants to merge 1 commit into
xuanruli wants to merge 1 commit into
Conversation
6778d89 to
88596f0
Compare
validateHtmlInBrowser (+ onPage hook)97da76f to
5cd79b1
Compare
…date The browser-based `validate` (console/network/HTTP + contrast/clip audits, remote-asset localization, viewport-from-comp) only existed inline in the `validate` CLI command, so external consumers couldn't reuse it — they reimplement a parallel headless harness that drifts from render (missing localize → false CORS; hardcoded viewport → false out-of-frame; hand-maintained runtime parity). Lint doesn't have this problem: it's an importable `@hyperframes/lint` package. This lifts the browser core into a new `@hyperframes/validate` package, exporting `validateHtmlInBrowser(html, opts)`. The CLI `validate` command is behavior-unchanged: it lints + bundles, resolves Chrome via its own `ensureBrowser()`, and delegates. The package takes `opts.browserExecutablePath` so the caller owns browser discovery — the package stays launch-agnostic (no browser/manager), like lint owns rules but not I/O. New `opts.onPage(page)` runs extra checks on the SAME loaded page before teardown (findings merged), so a consumer can layer its own gates (e.g. caption-zone / out-of-frame) without a second browser load. - contrast-audit.browser.js moves to the package (its only consumer); the CLI build copies it into dist and the bundled runtime loads it via the same page.addScriptTag path. - The small low-level helpers validate needs (static file server, comp-viewport parse, linkedom shim, error normalizer) are vendored into the package so it doesn't import from @hyperframes/cli (which depends on it); folding both onto a shared low-level package is a follow-up. Marked in .fallowrc duplicates.ignore, matching the repo's moved-code convention. - Pure-function + contrast-script tests move to the package with the code they cover; the CLI keeps only extractCompositionErrorsFromLint (a CLI-side lint→error shaping concern). Verified: package build + typecheck clean, package tests 13/13, CLI tests 1270/1270 (103 files), fallow audit clean on 20 changed files, and an e2e `hyperframes validate` on a real composition through the package (Chrome launch + contrast audit) returns ok:true. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
5cd79b1 to
a108ffa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extracts the browser-based
validateinto a new@hyperframes/validatepackage that exportsvalidateHtmlInBrowser(html, opts)— mirroring how@hyperframes/lintexposeslintHyperframeHtml. ThevalidateCLI command is behavior-unchanged; it now delegates to the package.Why
The full validate harness (console/network/HTTP error capture, contrast + clip-duration audits, remote-asset localization, viewport-from-comp) only lived inline in the CLI command, so external consumers (e.g. the astral video-agent's
validate_hyperframesbridge) can't reuse it. They reimplement a parallel headless harness that drifts from render:net::ERR_FAILEDon the crossorigin<img>S3 fetches the real render localizes firstout_of_frameon portrait compsLint doesn't have this problem because it's an importable package. This gives validate the same shape, so there's one implementation everyone shares.
Design (mirrors the lint pattern)
validateHtmlInBrowsertakesopts.browserExecutablePath— the CLI resolves Chrome via its ownensureBrowser()and passes it in. The package has nobrowser/manager, staying launch-agnostic (lint owns rules, not file I/O; validate owns the audit, not browser discovery).opts.onPage(page)runs caller checks on the same loaded page before teardown (findings merged into errors/warnings). This is the hook a downstream consumer uses to layer its own gates — e.g. the caption-zone / out-of-frame geometry checks — without a second browser load or a forked harness.contrast-audit.browser.jsmoves to the package (its only consumer). The CLI build copies it intodist/commandsand the bundled runtime loads it via the samepage.addScriptTagpath.@hyperframes/cli(which depends on it). Folding cli + validate onto a shared low-level package is a sensible follow-up — flagged in.fallowrcduplicates.ignorewith the repo's existing moved-code convention. (Maintainer call — happy to do it either way.)extractCompositionErrorsFromLint, a CLI-side lint→error shaping concern.Verification
@hyperframes/validate: build + typecheck clean, tests 13/13@hyperframes/cli: build clean, tests 1270/1270 (103 files)fallow audit --base origin/main: clean on 20 changed fileshyperframes validateon a real composition through the package (Chrome launch + contrast audit) →ok: trueFollow-ups (not in this PR)
validate_hyperframesbridge atvalidateHtmlInBrowser+ passonPage= caption-zone / out-of-frame gates, replacing its standalonebridge.mjs.🤖 Generated with Claude Code