fix(cli): check flags caption words hidden behind a cut-out and ignores a mostly transparent cover (#6770)

* fix(cli): check flags caption words hidden behind a cut-out and ignores a mostly transparent cover

* fix(cli): a caption word's lifetime is shifted only by its composition hosts
This commit is contained in:
Miguel Ángel
2026-10-30 01:47:19 +00:00
committed by GitHub
parent 6874cc2890
commit f523ee2fca
7 changed files with 134 additions and 10 deletions
+4
View File
@@ -2006,6 +2006,10 @@ function assignOptionalLayoutFields(issue: LayoutIssue, value: Record<string, un
if (overflow) issue.overflow = overflow;
const coveredFraction = numberValue(value, "coveredFraction");
if (coveredFraction !== null) issue.coveredFraction = coveredFraction;
const lifetime = recordField(value, "lifetime");
const start = lifetime ? numberValue(lifetime, "start") : null;
const end = lifetime ? numberValue(lifetime, "end") : null;
if (start !== null && end !== null) issue.lifetime = { start, end };
}
function recordField(value: unknown, key: string): Record<string, unknown> | null {
+3 -3
View File
@@ -2124,7 +2124,7 @@ function shapeLayoutSection(
browser: CheckBrowserResult,
options: CheckOptions,
): CheckReport["layout"] {
const shaped = shapeLayoutFindings(issues, options, browser.layoutSamples.length);
const shaped = shapeLayoutFindings(issues, options, browser.layoutSamples);
return {
...section(shaped.findings),
duration: browser.duration,
@@ -2140,11 +2140,11 @@ function shapeLayoutSection(
function shapeLayoutFindings(
issues: AnchoredLayoutIssue[],
options: CheckOptions,
totalSampleCount?: number,
sampleTimes?: readonly number[],
): { findings: AnchoredLayoutIssue[]; totalIssueCount: number; truncated: boolean } {
const deduped = dedupeLayoutIssues(issues);
const all = options.collapseStatic
? collapseStaticLayoutIssues(deduped, totalSampleCount)
? collapseStaticLayoutIssues(deduped, sampleTimes?.length, sampleTimes)
: deduped;
const anchored = all.map(ensureAnchoredLayoutIssue);
let grouped = anchored;
@@ -285,6 +285,38 @@ describe("persistence-tiered severity (#U10)", () => {
expect(collapsed[0]).toMatchObject({ severity: "error", occurrences: 2 });
});
it("keeps a text_occluded at error when the word lives one sample and is hidden at it", () => {
const grid = [0.167, 0.5, 0.833, 1.167];
const word = (time: number, lifetime: { start: number; end: number }) => ({
...issue("text_occluded", "error"),
time,
lifetime,
});
const collapsed = collapseStaticLayoutIssues(
[word(0.167, { start: 0, end: 0.4 }), word(0.5, { start: 0.4, end: 0.8 })].map((entry) => ({
...entry,
selector: `#w${entry.time}`,
})),
grid.length,
grid,
);
expect(collapsed.map((entry) => entry.severity)).toEqual(["error", "error"]);
});
it("still demotes a text_occluded seen at one of several samples its clip spans", () => {
const grid = [0.1, 0.3, 0.5, 0.7];
const collapsed = collapseStaticLayoutIssues(
[{ ...issue("text_occluded", "error"), time: 0.3, lifetime: { start: 0, end: 1 } }],
grid.length,
grid,
);
expect(collapsed[0]).toMatchObject({ severity: "info", occurrences: 1 });
});
it("keeps a text_occluded over changing text at error, not demoted per sample", () => {
const collapsed = collapseStaticLayoutIssues(
[
+25 -4
View File
@@ -67,6 +67,8 @@ export interface LayoutIssue {
/** `text_occluded` only (0-1): probe-grid share hit by an opaque occluder, or behind a
* transparent video the most covered word's share under its alpha (layout-audit.browser.js). */
coveredFraction?: number;
/** `text_occluded` only: the global window the element's own clip is on screen. */
lifetime?: { start: number; end: number };
fixHint?: string;
}
@@ -225,6 +227,7 @@ const TEXT_AGNOSTIC_KEY_CODES: ReadonlySet<LayoutIssueCode> = new Set([
export function collapseStaticLayoutIssues(
issues: LayoutIssue[],
totalSampleCount?: number,
sampleTimes?: readonly number[],
): LayoutIssue[] {
const groups = new Map<
string,
@@ -275,6 +278,7 @@ export function collapseStaticLayoutIssues(
},
multiSampleRun,
sampleCount,
sampleTimes,
),
);
}
@@ -305,9 +309,22 @@ function coverTier(issue: LayoutIssue, sampleCount: number): LayoutIssue {
return (issue.occurrences ?? 1) * 2 >= sampleCount ? issue : { ...issue, severity: "info" };
}
function tierIssue(issue: LayoutIssue, multiSampleRun: boolean, sampleCount: number): LayoutIssue {
function tierIssue(
issue: LayoutIssue,
multiSampleRun: boolean,
sampleCount: number,
sampleTimes?: readonly number[],
): LayoutIssue {
if (multiSampleRun && issue.code === "canvas_covered") return coverTier(issue, sampleCount);
return applyPersistenceTier(issue, multiSampleRun);
return applyPersistenceTier(issue, multiSampleRun, sampleTimes);
}
/** An element whose clip spans no more samples than it was caught at was caught for its whole life. */
function caughtForWholeLifetime(issue: LayoutIssue, sampleTimes?: readonly number[]): boolean {
if (!issue.lifetime || !sampleTimes) return false;
const { start, end } = issue.lifetime;
const sampled = sampleTimes.filter((time) => time >= start && time < end).length;
return (issue.occurrences ?? 1) >= sampled;
}
/**
@@ -322,7 +339,11 @@ function tierIssue(issue: LayoutIssue, multiSampleRun: boolean, sampleCount: num
* is a parked entrance, not drift. Codes without a promotion rule are left
* untouched when held — persistence, not the code, decides their tier.
*/
function applyPersistenceTier(issue: LayoutIssue, multiSampleRun: boolean): LayoutIssue {
function applyPersistenceTier(
issue: LayoutIssue,
multiSampleRun: boolean,
sampleTimes?: readonly number[],
): LayoutIssue {
if (!multiSampleRun) return issue;
if (!PERSISTENCE_TIERED_CODES.has(issue.code)) return issue;
@@ -331,7 +352,7 @@ function applyPersistenceTier(issue: LayoutIssue, multiSampleRun: boolean): Layo
// lastSeen) — always under the ignore floor, so occurrences <= 1 is a
// complete (not approximate) test for "held under 250ms".
if (occurrences <= 1) {
return { ...issue, severity: "info" };
return caughtForWholeLifetime(issue, sampleTimes) ? issue : { ...issue, severity: "info" };
}
if (issue.code === "content_overlap" && isContentOverlapHeldLongEnough(issue, occurrences)) {
return { ...issue, severity: "error" };