mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* feat(cli): skipContrastInMotion moves to HF_TOOL_CONTEXT check-review
The --skip-contrast-in-motion flag and HYPERFRAMES_CHECK_SKIP_CONTRAST_IN_MOTION
env give way to a check-review capability in HF_TOOL_CONTEXT, so only a harness
turns it on. The skill text and manifest go back to main.
* feat(cli): check-review findingFrames saves one plain frame per finding time
With HF_TOOL_CONTEXT check-review.findingFrames, every error/warning finding in
layout or contrast with a real bbox gets frameTime (the middle sample of its
longest held run, by the heldMs gap rule) and frame (the absolute path of an
unannotated full frame shared by every finding at that time). One seek and
screenshot per distinct time, capped at 60 times with errors first, into the
run's snapshot folder; not listed in snapshots, history or events. Without the
capability, output is unchanged.
* docs(cli): finding-frame comments name the check-review capability, not a flag
* fix(cli): validate finding frame times and preserve cancellation
* fix(cli): count finding frame progress toward the check deadline
* feat(cli): check-review inspect attaches the inspector's report to each framed finding
With findingFrames on, the finding-frames page is served with the
inspector's GSAP hooks. After each frame is captured, every finding framed
at that time is inspected by its data-hf-id, else its selector, and the
inspector's own report is attached as the finding's inspect field. A failed
inspection becomes that finding's { error } and never fails the check.
Without the capability nothing changes.
Drops the unused @types/mime-types devDependency that the dependency audit
flags once packages/cli/package.json is touched.
* fix(cli): stop finding inspections after cancellation
* fix(cli): reject ambiguous finding inspection targets
* fix(ci): build inspector before Windows CLI smoke
* fix(cli): parse viewport HTML with explicit server parser
87 lines
3.2 KiB
TypeScript
87 lines
3.2 KiB
TypeScript
import { realpathSync } from "node:fs";
|
|
import type { Page } from "puppeteer-core";
|
|
import type { BundleOptions, BundleScriptProvenance } from "@hyperframes/core/compiler";
|
|
import type { LiveInspection, PageRunner } from "@hyperframes/inspector/live";
|
|
import type { CheckFindingInspect, CheckInspectTarget } from "./checkTypes.js";
|
|
import { normalizeErrorMessage } from "./errorMessage.js";
|
|
import type { StaticProjectServer } from "./staticProjectServer.js";
|
|
|
|
export interface FindingInspector {
|
|
/** The HTML to serve in place of the plain check page; undefined when preparing failed. */
|
|
readonly html?: string;
|
|
ready(server: StaticProjectServer): Promise<void>;
|
|
inspect(page: Page, target: CheckInspectTarget): Promise<CheckFindingInspect>;
|
|
}
|
|
|
|
const runnerFor = (page: Page): PageRunner => ({
|
|
run: <A, R>(fn: (arg: A) => R, arg: A) =>
|
|
page.evaluate(fn as (arg: unknown) => R, arg) as Promise<R>,
|
|
});
|
|
|
|
/** Never throws: a failure to prepare becomes every target's `{ error }`. */
|
|
export async function prepareFindingInspector(
|
|
projectDir: string,
|
|
bundle: (options: BundleOptions) => Promise<string>,
|
|
): Promise<FindingInspector> {
|
|
let live: LiveInspection;
|
|
try {
|
|
const { fingerprint, prepareLiveInspection } = await import("@hyperframes/inspector/live");
|
|
const project = realpathSync(projectDir);
|
|
const sourceVersion = fingerprint(project);
|
|
const provenance: BundleScriptProvenance[] = [];
|
|
const reads = new Set<string>();
|
|
const html = await bundle({
|
|
scriptProvenance: (script) => provenance.push(script),
|
|
onRead: (path) => reads.add(path),
|
|
});
|
|
live = prepareLiveInspection(project, html, provenance, sourceVersion, [...reads]);
|
|
} catch (error) {
|
|
return failedInspector(error);
|
|
}
|
|
let failure: unknown;
|
|
return {
|
|
html: live.html,
|
|
async ready(server) {
|
|
try {
|
|
live.finalizeDocument(await servedIndexHtml(server));
|
|
} catch (error) {
|
|
failure = error;
|
|
}
|
|
},
|
|
async inspect(page, target) {
|
|
if (failure !== undefined) return { error: normalizeErrorMessage(failure) };
|
|
try {
|
|
const report = await live.inspect(runnerFor(page), {
|
|
targets: [target],
|
|
descendants: false,
|
|
});
|
|
if (
|
|
"selector" in target &&
|
|
report.results.some((result) => result.candidates.length + result.candidatesOmitted > 1)
|
|
) {
|
|
return { error: `ambiguous_selector: ${target.selector} matches multiple elements` };
|
|
}
|
|
return report;
|
|
} catch (error) {
|
|
return { error: normalizeErrorMessage(error) };
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
function failedInspector(error: unknown): FindingInspector {
|
|
const inspect = { error: normalizeErrorMessage(error) };
|
|
return { ready: async () => {}, inspect: async () => inspect };
|
|
}
|
|
|
|
/** The HTML the server answers for `/`, which differs from what it was given (codec map). */
|
|
async function servedIndexHtml(server: StaticProjectServer): Promise<string> {
|
|
if (server.answer) {
|
|
const response = await server.answer({ method: "GET", path: "/", headers: {} });
|
|
return response.body.toString("utf8");
|
|
}
|
|
const response = await fetch(server.url);
|
|
if (!response.ok) throw new Error(`check server answered ${response.status} for its page`);
|
|
return response.text();
|
|
}
|