Skip to content

Commit caea386

Browse files
fix(cli): check's dense overlap pass takes at most 240 samples, at clip windows first (#5764)
* fix(cli): check's dense overlap pass takes at most 240 samples, at clip windows first * fix(cli): a held overlap on a long film is still an error under the 240-sample bound
1 parent cc9e1bb commit caea386

5 files changed

Lines changed: 95 additions & 12 deletions

File tree

‎packages/cli/src/commands/check.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ function fakeDriver(overrides: Partial<CheckAuditDriver> = {}): CheckAuditDriver
163163
getDuration: vi.fn(async () => 9),
164164
hasNoTimelineDeclaration: vi.fn(async () => false),
165165
getTransitionBoundaries: vi.fn(async () => []),
166+
getClipEdges: vi.fn(async () => []),
166167
getCanvas: vi.fn(async () => ({ width: 1920, height: 1080 })),
167168
findAmbiguousSelectors: vi.fn(async (_selectors: string[]) => []),
168169
seek: vi.fn(async (_time: number) => undefined),
@@ -2312,6 +2313,46 @@ describe("dense motion-overlap re-sampling", () => {
23122313
expect(driver.collectOverlap).toHaveBeenCalled();
23132314
expect(report.layout.findings.some((f) => f.code === "content_overlap")).toBe(true);
23142315
});
2316+
2317+
it("keeps a long film's dense pass to a fixed number of seeks", async () => {
2318+
const clipEdges = Array.from({ length: 433 }, (_, i) => [i * 1.2, i * 1.2 + 1.1]).flat();
2319+
const driver = fakeDriver({
2320+
getDuration: vi.fn(async () => 540),
2321+
getClipEdges: async () => clipEdges,
2322+
});
2323+
await runScenario(driver);
2324+
expect(vi.mocked(driver.seekGeometry).mock.calls.length).toBeLessThanOrEqual(240);
2325+
});
2326+
2327+
it("still promotes an overlap held on a long film", async () => {
2328+
const held = (time: number): boolean => time >= 200 && time <= 260;
2329+
const driver = fakeDriver({
2330+
getDuration: vi.fn(async () => 540),
2331+
collectLayout: vi.fn(async (_time: number) => []),
2332+
collectOverlap: vi.fn(async (time: number) =>
2333+
held(time) ? [layoutIssue("warning", { time, code: "content_overlap" })] : [],
2334+
),
2335+
});
2336+
const { report } = await runScenario(driver);
2337+
expect(report.layout.findings).toContainEqual(
2338+
expect.objectContaining({ code: "content_overlap", severity: "error" }),
2339+
);
2340+
expect(vi.mocked(driver.seekGeometry).mock.calls.length).toBeLessThanOrEqual(240);
2341+
});
2342+
2343+
it("samples a short clip the uniform grid steps over", async () => {
2344+
const inShortClip = (time: number): boolean => time > 100.1 && time < 100.4;
2345+
const driver = fakeDriver({
2346+
getDuration: vi.fn(async () => 540),
2347+
getClipEdges: async () => [100.1, 100.4],
2348+
collectLayout: vi.fn(async (_time: number) => []),
2349+
collectOverlap: vi.fn(async (time: number) =>
2350+
inShortClip(time) ? [layoutIssue("warning", { time, code: "content_overlap" })] : [],
2351+
),
2352+
});
2353+
const { report } = await runScenario(driver);
2354+
expect(report.layout.findings.some((f) => f.code === "content_overlap")).toBe(true);
2355+
});
23152356
});
23162357

23172358
describe("scoped check", () => {

‎packages/cli/src/utils/checkBrowser.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ function createPageDriver(page: Page, setTime: (time: number) => void): CheckAud
570570
getDuration: () => getCompositionDuration(page),
571571
hasNoTimelineDeclaration: () => hasNoTimelineDeclaration(page),
572572
getTransitionBoundaries: () => collectTweenBoundaries(page),
573+
getClipEdges: () => collectClipEdges(page),
573574
getCanvas: () =>
574575
page.evaluate(() => ({ width: window.innerWidth, height: window.innerHeight })),
575576
findAmbiguousSelectors: (selectors) => findAmbiguousSelectors(page, selectors),
@@ -644,6 +645,16 @@ async function getCompositionDuration(page: Page): Promise<number> {
644645
});
645646
}
646647

648+
async function collectClipEdges(page: Page): Promise<number[]> {
649+
return page.evaluate(() => {
650+
type Clip = { kind: string; start: number; duration: number };
651+
const manifest = Reflect.get(window, "__clipManifest") as { clips?: Clip[] } | undefined;
652+
return (manifest?.clips ?? [])
653+
.filter((clip) => clip.kind !== "audio")
654+
.flatMap((clip) => [clip.start, clip.start + clip.duration]);
655+
});
656+
}
657+
647658
async function collectTweenBoundaries(page: Page): Promise<number[]> {
648659
// GSAP getter binding and parent-time conversion form one serialized algorithm.
649660
// fallow-ignore-next-line complexity

‎packages/cli/src/utils/checkPipeline.ts‎

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
buildLayoutSampleTimes,
1818
buildTransitionSampleTimes,
1919
collapseStaticLayoutIssues,
20+
CONTENT_OVERLAP_HELD_ERROR_MS,
2021
longestContiguousRunMs,
2122
dedupeLayoutIssues,
2223
limitLayoutIssues,
@@ -489,19 +490,35 @@ async function collectGridSamples(
489490

490491
// Dense grid catches mid-motion text collisions the sparse layout grid seeks past; text-only overlap collection is cheap enough to afford it.
491492
const OVERLAP_SAMPLE_FPS = 8;
492-
// Ceiling that bounds dense seeks; past ~75s the grid degrades below 8fps rather than growing the seek budget without limit.
493-
const OVERLAP_MAX_SAMPLES = 600;
493+
// A fixed ceiling, so check's work does not grow with film length: clip windows first, then a uniform fill.
494+
const OVERLAP_MAX_SAMPLES = 240;
495+
// Part of it re-looks at an overlap half a second on where the grid is too sparse to show it held.
496+
const OVERLAP_HOLD_PROBES = 60;
497+
498+
function evenlyPicked(times: number[], count: number): number[] {
499+
if (times.length <= count) return times;
500+
const last = Math.max(1, count - 1);
501+
return Array.from(
502+
{ length: count },
503+
(_, i) => times[Math.floor((i * (times.length - 1)) / last)] ?? 0,
504+
);
505+
}
494506

495-
function buildOverlapSampleTimes(duration: number): number[] {
507+
function buildOverlapSampleTimes(duration: number, clipEdges: number[]): number[] {
496508
if (!Number.isFinite(duration) || duration <= 0) return [];
497509
const count = Math.min(
498-
OVERLAP_MAX_SAMPLES,
510+
OVERLAP_MAX_SAMPLES - OVERLAP_HOLD_PROBES,
499511
Math.max(2, Math.ceil(duration * OVERLAP_SAMPLE_FPS) + 1),
500512
);
501-
const step = duration / (count - 1);
502-
return mergeSampleTimes(
503-
Array.from({ length: count }, (_, index) => Math.round(index * step * 1000) / 1000),
504-
);
513+
const inner = clipEdges.filter((t) => t > 0 && t < duration);
514+
const cuts = inner.length > 0 ? mergeSampleTimes([0, duration], inner) : [];
515+
// One sample inside every stretch where the visible clips stay the same, so a short overlap is never stepped over.
516+
const windows = cuts.slice(1).map((end, i) => ((cuts[i] ?? 0) + end) / 2);
517+
const picked = evenlyPicked(windows, count);
518+
const fill = count - picked.length;
519+
const step = duration / Math.max(1, fill - 1);
520+
const uniform = Array.from({ length: fill }, (_, i) => i * step);
521+
return mergeSampleTimes([...picked, ...uniform].map((t) => Math.round(t * 1000) / 1000));
505522
}
506523

507524
/** Reruns content_overlap on a fine grid, unconditionally rather than gated on fingerprint change, since an animation aliased to the sparse grid collides between identical-fingerprint samples. */
@@ -512,15 +529,28 @@ async function collectMotionOverlapSamples(
512529
range?: [number, number],
513530
): Promise<void> {
514531
const baseTimes = new Set(grid.layoutSamples);
515-
const overlapTimes = buildOverlapSampleTimes(range ? range[1] - range[0] : grid.duration);
532+
const offset = range?.[0] ?? 0;
533+
const edges = (await driver.getClipEdges()).map((time) => time - offset);
534+
const overlapTimes = buildOverlapSampleTimes(range ? range[1] - range[0] : grid.duration, edges);
516535
const shiftedTimes = range
517536
? mergeSampleTimes(overlapTimes.map((time) => time + range[0]))
518537
: overlapTimes;
519-
for (const time of shiftedTimes) {
538+
const holdS = CONTENT_OVERLAP_HELD_ERROR_MS / 1000;
539+
const end = range ? range[1] : grid.duration;
540+
let probes = 0;
541+
for (const [index, time] of shiftedTimes.entries()) {
520542
if (baseTimes.has(time)) continue;
521543
// Settle-free seek: collectOverlap reads getBoundingClientRect geometry, valid synchronously after setTime, so the dense pass skips the per-seek paint settle.
522544
await driver.seekGeometry(time);
523-
collected.layoutIssues.push(...(await driver.collectOverlap(time)));
545+
const issues = await driver.collectOverlap(time);
546+
collected.layoutIssues.push(...issues);
547+
const next = shiftedTimes[index + 1] ?? Number.POSITIVE_INFINITY;
548+
const probe = Math.round((time + holdS) * 1000) / 1000;
549+
if (!issues.length || next - time <= 2 * holdS || probe > end || probes >= OVERLAP_HOLD_PROBES)
550+
continue;
551+
probes += 1;
552+
await driver.seekGeometry(probe);
553+
collected.layoutIssues.push(...(await driver.collectOverlap(probe)));
524554
}
525555
}
526556

‎packages/cli/src/utils/checkTypes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export interface CheckAuditDriver {
195195
/** True when the root composition explicitly declares that it is intentionally timeline-free. */
196196
hasNoTimelineDeclaration(): Promise<boolean>;
197197
getTransitionBoundaries(): Promise<number[]>;
198+
getClipEdges(): Promise<number[]>;
198199
getCanvas(): Promise<Canvas>;
199200
findAmbiguousSelectors(selectors: string[]): Promise<AnchoredLayoutIssue[]>;
200201
seek(time: number): Promise<void>;

‎packages/cli/src/utils/layoutAudit.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function dedupeLayoutIssues(issues: LayoutIssue[]): LayoutIssue[] {
189189
}
190190

191191
// Persistence-tier thresholds (#U10): occurrences>=2 alone can't imply the 500ms floor under dense 8fps sampling, so content_overlap promotion requires a literal firstSeen..lastSeen span >= 500ms — stricter for sparse callers too.
192-
const CONTENT_OVERLAP_HELD_ERROR_MS = 500;
192+
export const CONTENT_OVERLAP_HELD_ERROR_MS = 500;
193193
const HELD_ACROSS_SAMPLES_MIN_OCCURRENCES = 2;
194194

195195
// Tiering only applies to layout-audit.browser.js's own per-sample seek-grid

0 commit comments

Comments
 (0)