mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
Crowded-screen layout check catches cut-off and overlapping text it used to miss (GST-4159) (#4894)
The first-use layout check now catches overlapping text below the bottom of the window and cut-off text inside nested boxes, reports a screen with too much text as not measured instead of passing it, and saves its result in one step. Why: four gaps found in the final review of #4893 could let a crowded screen pass the first-use check with text that's cut off or painted over. Nothing to do: the play spec and commands are unchanged. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=red-team Review-Finding: p2/adversarial-native#1 reader=adversarial-native Review-Finding: p3/outside-voice#1 reader=outside-voice
This commit is contained in:
1 parent
b2e9522b2f
commit
e4a69b0b52
8 files changed
+98
-17
No files matched your search
@@ -0,0 +1 @@
|
||||
**The crowded-screen layout check no longer misses cut-off or overlapping text in four cases.** Text painted over a solid card below the bottom edge of the window now counts as overlapping; before, it was taken as hidden and skipped. A box that cuts off its own text is now reported even when a smaller box inside it cuts off text too. A screen with more than 2,000 lines of text is now reported as not measured (`TOO_MUCH_TEXT`) instead of passing with the extra text unchecked. And `gstack-first-use layout` now saves its result in one step, so an interrupted run can't leave a half-written result behind.
|
||||
+2
-1
@@ -379,7 +379,7 @@ finding a waiver did not answer makes the section open.
|
||||
| `note-in-row-weight` | ask | in a list of rows, a note with no icon and no surface of its own, OKLCH lightness within 0.15 of the name's and size 0.9 or more of it; or, at 1200px and wider, a note of three lines or more | mute the note, or give it an icon or a callout |
|
||||
| `small-hit-area` | ask | at 480px and narrower, a control inside a list row under 32px in either dimension (an input's label counts toward its box; a link inside a run of text is exempt) | a 32px target that keeps the glyph its size |
|
||||
| `section-overflow` | ask | an element inside the section whose right edge passes the viewport (outside any scroller), or a non-scrolling element whose content is wider than its box | wrap or shrink it, or give it a scroller |
|
||||
| `text-clipped` | ask | `--full-house` only: an element that hides its horizontal overflow (`overflow-x` hidden or clip, ellipsis included) holds text wider than its box by more than 1px; boxes under 4px and visually hidden text (`clip` or `clip-path`, the screen-reader-only pattern) are skipped, and only the innermost of nested clippers reports. The evidence says how much of the text shows | let the text wrap, shrink it to fit, or give the box room for the longest value |
|
||||
| `text-clipped` | ask | `--full-house` only: an element that hides its horizontal overflow (`overflow-x` hidden or clip, ellipsis included) holds text wider than its box by more than 1px; boxes under 4px and visually hidden text (`clip` or `clip-path`, the screen-reader-only pattern) are skipped, and text inside a nested clipper that already reports counts only toward that box, so an outer box reports only the rest of the text it cuts. The evidence says how much of the text shows | let the text wrap, shrink it to fit, or give the box room for the longest value |
|
||||
| `text-overlap` | ask | `--full-house` only: two text runs from different elements (an absolutely or fixed positioned child counts against its parent's own text), whose line boxes (glyph rows trimmed to the line height and cut to any clipping ancestor) overlap by more than 2px in both directions. The pair is skipped only when an opaque surface on one side, at least four times the other run's area and painted above it (positioned, or on its own layer, and topmost at the overlap), hides that run's whole line (a dialog over the page), sits in a fixed overlay (a toast or callout floating over the page), or is a sticky bar. A badge with its own background over part of a score, and text spilling into the next row's background, still report. Up to 50 findings per rule and screen, so waivers can't hide an unwaived one | put the badge or label in the flow beside the text, or reserve space for it |
|
||||
|
||||
How it reads the page, with no test hooks (no `data-testid`, no attribute at
|
||||
@@ -439,6 +439,7 @@ them all:
|
||||
| <a id="app-code-state_mismatch"></a>`STATE_MISMATCH` | the state's `expect` selector matched nothing | make the URL load the state it names, or fix `expect` |
|
||||
| <a id="app-code-within_no_match"></a>`WITHIN_NO_MATCH` | `--within` matched nothing in the document or any open shadow root | pass the custom element's tag or a selector inside the light DOM |
|
||||
| <a id="app-code-closed_shadow"></a>`CLOSED_SHADOW` | a custom element in the section (or, when nothing matched, on the page) renders a closed shadow root: no shadow root, no light DOM, 40px or taller | attach the shadow root with mode "open" in development, or pass a `--within` outside it |
|
||||
| <a id="app-code-too_much_text"></a>`TOO_MUCH_TEXT` | with `--full-house`, the section holds over 2000 lines of text, more than `text-overlap` can check | pass a `--within` that holds only the crowded part of the screen, then rerun |
|
||||
| <a id="app-code-probe_error"></a>`PROBE_ERROR` | a probe threw or answered in a shape the lint does not know | read the trace file; a page script that redefines DOM APIs breaks the probes |
|
||||
| <a id="app-code-asset_missing"></a>`ASSET_MISSING` | a linked stylesheet did not load (a font that did not load is only a `LINT_APP_NOTE`) | fix the stylesheet path or wait for the server, then rerun |
|
||||
|
||||
|
||||
@@ -129,5 +129,5 @@ With a handful of builds, this is a case series, not an eval. For each first ver
|
||||
- It doesn't dispatch the checker by itself; the thread that owns the build starts it with the brief.
|
||||
- It doesn't check the wording of other messages sent to the owner.
|
||||
- The crowded-screen check measures only horizontal cuts and overlapping text on web pages. It doesn't catch text cut off vertically, a `line-clamp` that hides lines, a number that wraps onto a second line, a screen the fixture doesn't seed, or native iOS, Android and Mac screens.
|
||||
- The crowded-screen measurement trusts the fixture URL: it doesn't check that the server there runs the build being sent (the record lists the origins it opened). It measures only text that paints on screen, so text marked `aria-hidden` still counts when it is visible. It waits for `wait_for` once before measuring each viewport rather than at each one, and compares at most 2000 line boxes per screen.
|
||||
- The crowded-screen measurement trusts the fixture URL: it doesn't check that the server there runs the build being sent (the record lists the origins it opened). It measures only text that paints on screen, so text marked `aria-hidden` still counts when it is visible. It waits for `wait_for` once before measuring each viewport rather than at each one, and checks at most 2000 line boxes per screen; a screen with more is reported as not measured (`TOO_MUCH_TEXT`).
|
||||
- It doesn't push a build through rough play (idling past a timer, a wrong answer, a dropped player). A pilot of that check caught the bug it was aimed at in 1 of 3 tries, so it was left out.
|
||||
@@ -21,7 +21,7 @@ import type { Runner } from './render';
|
||||
import { finalize, oneLine, summarize, type Finding, type Summary } from './report';
|
||||
import { ruleMeta } from './rules/ids';
|
||||
|
||||
export const APP_CODES = ['NO_BROWSER', 'UNREACHABLE', 'TIMEOUT', 'NOT_READY', 'STATE_MISMATCH', 'WITHIN_NO_MATCH', 'CLOSED_SHADOW', 'PROBE_ERROR', 'ASSET_MISSING'] as const;
|
||||
export const APP_CODES = ['NO_BROWSER', 'UNREACHABLE', 'TIMEOUT', 'NOT_READY', 'STATE_MISMATCH', 'WITHIN_NO_MATCH', 'CLOSED_SHADOW', 'TOO_MUCH_TEXT', 'PROBE_ERROR', 'ASSET_MISSING'] as const;
|
||||
export type AppCode = typeof APP_CODES[number];
|
||||
|
||||
/** One line each: what to do about a state that was not measured. Anchors: docs/design-lint.md#app-code-<code in lower case>. */
|
||||
@@ -33,6 +33,7 @@ export const APP_CODE_FIX: Record<AppCode, string> = {
|
||||
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<string | null> {
|
||||
|
||||
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<string>(['NOT_READY', 'STATE_MISMATCH', 'WITHIN_NO_MATCH', 'CLOSED_SHADOW']);
|
||||
const INCOMPLETE_FROM_PROBE = new Set<string>(['NOT_READY', 'STATE_MISMATCH', 'WITHIN_NO_MATCH', 'CLOSED_SHADOW', 'TOO_MUCH_TEXT']);
|
||||
|
||||
type Parsed = { value: unknown } | { error: string; stack?: string };
|
||||
|
||||
|
||||
@@ -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<App
|
||||
const vw = innerWidth;
|
||||
const findings: AppProbeFinding[] = [];
|
||||
for (const l of lists) findings.push(...P.rows(P, l, vw), ...P.after(P, l, matches.find((m) => 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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,14 @@ export async function runLayout(dir: string, deps: Pick<AppOptions, 'engine' | '
|
||||
incomplete: r.app.states.filter(s => 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 };
|
||||
}
|
||||
@@ -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 => '<main class="' + where + '"><div class="spacer"></div><div class="wrap"><div class="card"><span class="t">CARD TITLE TEXT HERE</span></div><span class="tag ' + layer + '">PAINTED ON TOP</span></div></main>';
|
||||
|
||||
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 = '<main><div class="outer o-both"><span class="inner">INNER LONG NAME</span> OUTER TEXT THAT RUNS FAR PAST ITS EDGE</div>'
|
||||
+ '<div class="outer o-narrow"><span class="inner">INNER LONG NAME</span><i class="wide"></i></div>'
|
||||
+ '<div class="outer o-inline"><span class="truncate">A VERY LONG PLAYER NAME HERE</span></div></main>';
|
||||
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 = '<main><div class="box b-scale"><span class="sc">SHORT NAME</span></div><div class="box b-escape"><div class="mid"><span class="esc">ESCAPING LONG LABEL TEXT</span></div></div></main>';
|
||||
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 }', '<main><p class="log">' + lines + '</p></main>'));
|
||||
expect([r.app.verdict, r.exitCode, r.app.states.map((s) => [s.status, s.code])]).toEqual(['incomplete', 4, [['incomplete', 'TOO_MUCH_TEXT']]]);
|
||||
}, 60_000);
|
||||
});
|
||||
@@ -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<ReturnType<typeof runLayout>>;
|
||||
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)', () => {
|
||||
|
||||
Reference in new issue
Block a user