. */
@@ -33,6 +33,7 @@ export const APP_CODE_FIX: Record = {
STATE_MISMATCH: "make the URL load the state it names, or fix the state's expect selector",
WITHIN_NO_MATCH: "pass the custom element's tag or a selector inside the light DOM",
CLOSED_SHADOW: 'attach the shadow root with mode "open" in development, or pass a --within outside it',
+ TOO_MUCH_TEXT: 'pass a --within that holds only the crowded part of the screen, then rerun',
PROBE_ERROR: 'read the trace file; a page script that redefines DOM APIs breaks the probes',
ASSET_MISSING: 'fix the stylesheet path or wait for the server to serve it, then rerun',
};
@@ -104,7 +105,7 @@ async function reachable(url: string): Promise {
const codeOfRunError = (e: string): AppCode => (/^no browser available/i.test(e) ? 'NO_BROWSER' : /waitFor/.test(e) ? 'NOT_READY' : /timed? ?out|timeout/i.test(e) ? 'TIMEOUT' : 'UNREACHABLE');
-const INCOMPLETE_FROM_PROBE = new Set(['NOT_READY', 'STATE_MISMATCH', 'WITHIN_NO_MATCH', 'CLOSED_SHADOW']);
+const INCOMPLETE_FROM_PROBE = new Set(['NOT_READY', 'STATE_MISMATCH', 'WITHIN_NO_MATCH', 'CLOSED_SHADOW', 'TOO_MUCH_TEXT']);
type Parsed = { value: unknown } | { error: string; stack?: string };
diff --git a/lib/design-lint/render-probe-app.ts b/lib/design-lint/render-probe-app.ts
index a2b84519a..06e3c1fb5 100644
--- a/lib/design-lint/render-probe-app.ts
+++ b/lib/design-lint/render-probe-app.ts
@@ -21,7 +21,7 @@ export interface AppProbeFinding { rule: string; sentence: string; locator: stri
export interface AppProbeResult {
status: 'measured' | 'incomplete';
- /** Set when incomplete: NOT_READY, STATE_MISMATCH, WITHIN_NO_MATCH or CLOSED_SHADOW. */
+ /** Set when incomplete: NOT_READY, STATE_MISMATCH, WITHIN_NO_MATCH, CLOSED_SHADOW or TOO_MUCH_TEXT. */
code?: string;
detail?: string;
/** Elements the --within selector matched in the composed tree. */
@@ -358,11 +358,11 @@ export function glAppText(P: AppProbes, root: Element): Array<{ host: Element; t
return out;
}
-/** text-clipped (--full-house only): inside root, an element that clips horizontally (overflow-x hidden or clip) and paints part of its own text past its edge; a visually hidden box (under 4px, or a clip or clip-path) is screen-reader text, never a cut. The innermost 50, so waivers applied later can't hide an unwaived cut behind three waived ones. */
+/** text-clipped (--full-house only): inside root, an element that clips horizontally (overflow-x hidden or clip) and paints part of its own text past its edge; a visually hidden box (under 4px, or a clip or clip-path) is screen-reader text, never a cut. Text inside a box already reported as cutting counts only toward that box, so an outer box reports the rest of the text it cuts. The first 50, so waivers applied later can't hide an unwaived cut behind three waived ones. */
export function glAppClipped(P: AppProbes, root: Element): AppProbeFinding[] {
const { desc, vis, locOf, px, inside } = P.H;
const hits: Array<{ el: Element; sentence: string; m: number }> = [];
- for (const el of desc(root)) {
+ for (const el of desc(root).reverse()) {
if (!vis(el)) continue;
const cs = getComputedStyle(el);
if (!/hidden|clip/.test(cs.overflowX) || el.scrollWidth <= el.clientWidth + 1) continue;
@@ -372,6 +372,7 @@ export function glAppClipped(P: AppProbes, root: Element): AppProbeFinding[] {
let total = 0, hidden = 0;
const words: string[] = [];
for (const t of P.text(P, el)) {
+ if (hits.some((h) => inside(t.host, h.el))) continue;
words.push(t.text);
for (const q of t.rects) { total += q.width; hidden += Math.min(q.width, Math.max(0, q.right - right) + Math.max(0, left - q.left)); }
}
@@ -381,12 +382,11 @@ export function glAppClipped(P: AppProbes, root: Element): AppProbeFinding[] {
const shownPct = Math.max(0, Math.round(100 * (1 - cut / Math.max(total, el.scrollWidth))));
hits.push({ el, sentence: el.tagName.toLowerCase() + ' cuts off its text: ' + shownPct + '% of "' + words.join(' ').slice(0, 40) + '" shows, ' + px(cut) + 'px hidden', m: px(cut) });
}
- const inner = hits.filter((h) => !hits.some((o) => o !== h && inside(o.el, h.el)));
- return inner.slice(0, 50).map((h) => ({ rule: 'text-clipped', sentence: h.sentence + ' (over 1px)', locator: locOf(h.el), measured: h.m, threshold: 1 }));
+ return hits.reverse().slice(0, 50).map((h) => ({ rule: 'text-clipped', sentence: h.sentence + ' (over 1px)', locator: locOf(h.el), measured: h.m, threshold: 1 }));
}
-/** text-overlap (--full-house only): inside root, the line boxes (a glyph box trimmed to its line-height) of two elements, neither inside the other, intersecting by over 2px both ways, where no opaque surface between them hides one. Clipped-away text never counts. A positioned child painted over its parent's own text counts. First 50 pairs, so waivers applied later can't hide an unwaived one. */
-export function glAppOverlap(P: AppProbes, root: Element): AppProbeFinding[] {
+/** text-overlap (--full-house only): inside root, the line boxes (a glyph box trimmed to its line-height) of two elements, neither inside the other, intersecting by over 2px both ways, where no opaque surface between them hides one. Clipped-away text never counts. A positioned child painted over its parent's own text counts. A point below the fold is scrolled into view before the hit test. First 50 pairs, so waivers applied later can't hide an unwaived one. Null when the section holds over 2000 line boxes, too many to check. */
+export function glAppOverlap(P: AppProbes, root: Element): AppProbeFinding[] | null {
const { cparent, inside, locOf, px, rgb } = P.H;
const clipBox = (el: Element): { l: number; t: number; r: number; b: number } => {
let l = -Infinity, t = -Infinity, r = Infinity, b = Infinity;
@@ -409,7 +409,7 @@ export function glAppOverlap(P: AppProbes, root: Element): AppProbeFinding[] {
const box = { host: tb.host, text: tb.text, l: Math.max(q.left, c.l), t: Math.max(q.top + pad, c.t), r: Math.min(q.right, c.r), b: Math.min(q.bottom - pad, c.b) };
if (box.r - box.l > 1 && box.b - box.t > 1) boxes.push(box);
}
- if (boxes.length > 2000) break;
+ if (boxes.length > 2000) return null;
}
boxes.sort((a, b) => a.l - b.l);
const covers = (top: Element, stop: Element, o: { l: number; t: number; r: number; b: number }, x: number, y: number): boolean => {
@@ -423,11 +423,19 @@ export function glAppOverlap(P: AppProbes, root: Element): AppProbeFinding[] {
const whole = q.left <= o.l + 1 && q.right >= o.r - 1 && q.top <= o.t + 1 && q.bottom >= o.b - 1;
if (!whole && !overlay && cs.position !== 'sticky') continue;
if (!layered(e, stop)) continue;
- const hit = document.elementFromPoint(x, y);
- if (!hit || hit === e || inside(hit, e)) return true;
+ const hit = pointHit(x, y);
+ if (hit && (hit === e || inside(hit, e))) return true;
}
return false;
};
+ const pointHit = (x: number, y: number): Element | null => {
+ if (x >= 0 && x < innerWidth && y >= 0 && y < innerHeight) return document.elementFromPoint(x, y);
+ const sx = scrollX, sy = scrollY;
+ scrollTo({ left: sx + x - innerWidth / 2, top: sy + y - innerHeight / 2, behavior: 'instant' });
+ const hit = document.elementFromPoint(x - (scrollX - sx), y - (scrollY - sy));
+ scrollTo({ left: sx, top: sy, behavior: 'instant' });
+ return hit;
+ };
const fixedFrom = (e: Element, stop: Element): Element | null => {
for (let n: Element | null = e; n && n !== stop; n = cparent(n)) if (getComputedStyle(n).position === 'fixed') return n;
return null;
@@ -503,7 +511,13 @@ export async function glAppMeasure(P: AppProbes, a: AppMeasureArgs): Promise inside(l.container, m)) || l.container));
- for (const m of matches) findings.push(...P.overflow(P, m, vw), ...(a.fullHouse ? [...P.clipped(P, m), ...P.overlap(P, m)] : []));
+ for (const m of matches) {
+ findings.push(...P.overflow(P, m, vw));
+ if (!a.fullHouse) continue;
+ const overlap = P.overlap(P, m);
+ if (!overlap) return { ...base, status: 'incomplete', code: 'TOO_MUCH_TEXT', detail: a.within + ' holds over 2000 lines of text, more than text-overlap can check' };
+ findings.push(...P.clipped(P, m), ...overlap);
+ }
return { ...base, status: 'measured', findings };
}
diff --git a/lib/first-use-layout.ts b/lib/first-use-layout.ts
index 21c37fa87..48c0d0150 100644
--- a/lib/first-use-layout.ts
+++ b/lib/first-use-layout.ts
@@ -36,9 +36,14 @@ export async function runLayout(dir: string, deps: Pick s.status === 'incomplete').map(s => ({ state: s.name, viewport: s.viewport, code: s.code, detail: s.detail ?? '' })),
};
const file = path.join(dir, 'layout', `${at.toISOString().replace(/[-:]/g, '')}-${crypto.randomBytes(3).toString('hex')}.json`);
+ const tmp = `${file}.${process.pid}.tmp`;
try {
fs.mkdirSync(path.dirname(file), { recursive: true });
- fs.writeFileSync(file, JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
- } catch (e) { return { error: { code: 'FIRST_USE_RECORD_INVALID', detail: `cannot write ${file}: ${(e as Error).message}` } }; }
+ fs.writeFileSync(tmp, JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
+ fs.renameSync(tmp, file);
+ } catch (e) {
+ try { fs.rmSync(tmp, { force: true }); } catch { /* the layout directory itself is unusable */ }
+ return { error: { code: 'FIRST_USE_RECORD_INVALID', detail: `cannot write ${file}: ${(e as Error).message}` } };
+ }
return { receipt, file };
}
diff --git a/test/design-lint-full-house.test.ts b/test/design-lint-full-house.test.ts
index f10011c78..fc8a9498a 100644
--- a/test/design-lint-full-house.test.ts
+++ b/test/design-lint-full-house.test.ts
@@ -150,3 +150,43 @@ describe.skipIf(!hasBrowser)('--full-house: negative controls for text-overlap',
expect([open, r.app.verdict]).toEqual([[], 'clean']);
}, 60_000);
});
+
+describe.skipIf(!hasBrowser)('--full-house: gaps found in review (GST-4159)', () => {
+ const FOLD_CSS = 'main { padding: 24px } .spacer { height: 1500px } .near .spacer { height: 0 } .wrap { position: relative; width: 420px } .card { position: relative; z-index: 1; background: #222; height: 120px; padding: 10px; font: 20px/20px sans-serif } '
+ + '.tag { position: absolute; top: 10px; left: 30px; font: 20px/20px sans-serif } .over { z-index: 2 } .under { z-index: 0 }';
+ const fold = (where: string, layer: string): string => 'CARD TITLE TEXT HEREPAINTED ON TOP ';
+
+ test('a label painted over a solid card is an overlap below the fold as well as above it; the card painted over the label is clean in both places', async () => {
+ expect((await measure(page('fold-near-over.html', FOLD_CSS, fold('near', 'over')))).ids).toContain('text-overlap');
+ expect((await measure(page('fold-far-over.html', FOLD_CSS, fold('far', 'over')))).ids).toContain('text-overlap');
+ expect((await measure(page('fold-near-under.html', FOLD_CSS, fold('near', 'under')))).ids).not.toContain('text-overlap');
+ expect((await measure(page('fold-far-under.html', FOLD_CSS, fold('far', 'under')))).ids).not.toContain('text-overlap');
+ }, 60_000);
+
+ test('an outer box cutting its own text is reported even when an inner box inside it cuts its text too, and an inner cut alone is never blamed on the outer box', async () => {
+ const css = 'main { padding: 24px } .outer { width: 200px; margin: 0 0 8px; white-space: nowrap; overflow: hidden; font: 20px/20px sans-serif } .o-narrow { width: 150px } '
+ + '.inner { display: inline-block; width: 60px; overflow: hidden; vertical-align: top } .wide { display: inline-block; width: 400px; height: 4px } .o-inline { width: 80px } .truncate { overflow: hidden }';
+ const body = 'INNER LONG NAME OUTER TEXT THAT RUNS FAR PAST ITS EDGE'
+ + 'INNER LONG NAME'
+ + 'A VERY LONG PLAYER NAME HERE ';
+ const { open } = await measure(page('nested-cuts.html', css, body));
+ const locs = open.filter((f) => f.rule === 'text-clipped').map((f) => f.app!.locator);
+ expect(locs.filter((l) => /span\.inner/.test(l))).toHaveLength(2);
+ expect(locs.filter((l) => !/span\.inner/.test(l))).toEqual([expect.stringContaining('o-both'), expect.stringContaining('o-inline')]);
+ }, 60_000);
+
+ test('an outer box still reports its cut of a scaled child, and of a label that escapes a clipping wrapper', async () => {
+ const css = 'main { padding: 24px } .box { margin: 0 0 40px; white-space: nowrap; overflow: hidden; font: 20px/20px sans-serif } .b-scale { width: 100px } .b-escape { width: 200px; height: 40px; position: relative } '
+ + '.sc { display: inline-block; overflow: hidden; transform: scale(2); transform-origin: 0 0 } .mid { width: 100px; overflow: hidden } .esc { position: absolute; left: 150px; top: 0 }';
+ const body = 'SHORT NAMEESCAPING LONG LABEL TEXT ';
+ const { open } = await measure(page('outer-geometry.html', css, body));
+ const locs = open.filter((f) => f.rule === 'text-clipped').map((f) => f.app!.locator);
+ expect([locs.some((l) => l.includes('b-scale')), locs.some((l) => l.includes('b-escape'))]).toEqual([true, true]);
+ }, 60_000);
+
+ test('a section with more line boxes than text-overlap checks is incomplete, never measured clean', async () => {
+ const lines = Array.from({ length: 2100 }, (_, i) => 'line ' + i).join('\n');
+ const { r } = await measure(page('too-much-text.html', '.log { margin: 0; white-space: pre-line; font: 10px/10px sans-serif }', '' + lines + '
'));
+ expect([r.app.verdict, r.exitCode, r.app.states.map((s) => [s.status, s.code])]).toEqual(['incomplete', 4, [['incomplete', 'TOO_MUCH_TEXT']]]);
+ }, 60_000);
+});
diff --git a/test/first-use.test.ts b/test/first-use.test.ts
index 64e34556c..054f9cdf3 100644
--- a/test/first-use.test.ts
+++ b/test/first-use.test.ts
@@ -567,6 +567,25 @@ describe('the full-house layout gate (GSTA-908)', () => {
expect(fhReasons(none.r.dir)).toEqual([]);
expect(await runLayout(none.r.dir)).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('none: one static page') } });
});
+ test('an interrupted layout write leaves no half-written record behind', async () => {
+ const { r } = webRun();
+ if ('error' in r) throw new Error(r.error.detail);
+ const real = fs.writeFileSync;
+ const spy = spyOn(fs, 'writeFileSync').mockImplementation(((file: fs.PathOrFileDescriptor, data: string, ...rest: unknown[]) => {
+ if (!String(file).includes(`${path.sep}layout${path.sep}`)) return real(file, data, ...(rest as [fs.WriteFileOptions]));
+ real(file, data.slice(0, 20), ...(rest as [fs.WriteFileOptions]));
+ throw new Error('ENOSPC: no space left on device');
+ }) as typeof fs.writeFileSync);
+ let out: Awaited>;
+ try { out = await runLayout(r.dir, { engine: () => ({ engine: null, probe: { ok: false, reason: 'NEEDS_ASIDE', detail: 'test' }, error: 'no browser available (test)' }) as never }, () => T0); } finally { spy.mockRestore(); }
+ expect(out).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('ENOSPC') } });
+ expect(fs.readdirSync(path.join(r.dir, 'layout'))).toEqual([]);
+ expect(decide(r.dir, WEB, T0).reasons.filter(x => x.startsWith('record_unreadable'))).toEqual([]);
+ expect(fhReasons(r.dir)[0]).toStartWith('full_house_unchecked');
+ fs.rmSync(path.join(r.dir, 'layout'), { recursive: true });
+ fs.writeFileSync(path.join(r.dir, 'layout'), 'not a directory');
+ expect(await runLayout(r.dir, { engine: () => ({ engine: null, probe: { ok: false, reason: 'NEEDS_ASIDE', detail: 'test' }, error: 'no browser available (test)' }) as never }, () => T0)).toMatchObject({ error: { code: 'FIRST_USE_RECORD_INVALID', detail: expect.stringContaining('cannot write') } });
+ });
});
describe('gstack-first-use (CLI, temporary HOME and drive)', () => {