mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
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
50 lines
3.6 KiB
TypeScript
50 lines
3.6 KiB
TypeScript
/**
|
|
* first-use-layout — `gstack-first-use layout`: measures the play spec's crowded screens (its full_house state file, frozen
|
|
* at start) with gstack-design-lint's app profile under --full-house, so text-clipped and text-overlap run with no model,
|
|
* and writes one write-once receipt bound to the build and the frozen files (docs/first-use-check.md). Only those two
|
|
* rules decide the receipt's verdict; the app profile's spacing rules stay advice for the builder's own lint runs. decide() in
|
|
* first-use.ts only reads the receipts; this module is the only part of the first-use check that starts a browser.
|
|
*/
|
|
import * as crypto from 'node:crypto';
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import { parseViewport } from './design-lint/app-input';
|
|
import { lintApp, type AppOptions } from './design-lint/render-app';
|
|
import { readManifest, type FirstUseError, type LayoutReceipt } from './first-use';
|
|
|
|
const VERSION_FILE = path.resolve(import.meta.dir, '..', 'VERSION');
|
|
export const FULL_HOUSE_RULES = ['text-clipped', 'text-overlap'];
|
|
|
|
export async function runLayout(dir: string, deps: Pick<AppOptions, 'engine' | 'run' | 'reach'> = {}, now: () => Date = () => new Date()): Promise<{ receipt: LayoutReceipt; file: string } | { error: FirstUseError; nothing?: true }> {
|
|
const read = readManifest(dir);
|
|
if ('error' in read) return read;
|
|
const m = read.manifest, fh = m.full_house;
|
|
if (!fh) return { nothing: true, error: { code: 'FIRST_USE_RECORD_INVALID', detail: `this run's play spec has no crowded screens to measure (full_house: ${typeof m.play.full_house === 'string' ? m.play.full_house : 'none'})` } };
|
|
const viewports = fh.viewports?.map(parseViewport);
|
|
const r = await lintApp({ states: fh.states_parsed, within: fh.within, waitFor: fh.wait_for, viewports, waivers: fh.waivers_parsed, fullHouse: true, ...deps });
|
|
let version = 'unknown';
|
|
try { version = fs.readFileSync(VERSION_FILE, 'utf8').trim(); } catch { /* not a checkout */ }
|
|
const ours = r.findings.filter(f => f.app && FULL_HOUSE_RULES.includes(f.rule));
|
|
const open = ours.filter(f => !f.waiver).length;
|
|
const verdict = r.app.verdict === 'incomplete' ? 'incomplete' : open ? 'open' : 'clean';
|
|
const at = now();
|
|
const receipt: LayoutReceipt = {
|
|
schema_version: 1, kind: 'first-use-layout', at: at.toISOString(), build_fingerprint: m.build.fingerprint, states_sha256: fh.states_sha256, waivers_sha256: fh.waivers_sha256,
|
|
viewports: r.app.viewports, within: fh.within, origins: [...new Set(fh.states_parsed.map(s => { try { return new URL(s.url).origin; } catch { return s.url; } }))], gstack_version: version,
|
|
verdict, code: verdict === 'incomplete' ? r.app.code : open ? 'OPEN' : 'OK', open, waived: ours.length - open,
|
|
findings: ours.map(f => ({ rule: f.rule, evidence: f.evidence, ...(f.app ? { locator: f.app.locator } : {}), ...(f.waiver ? { waiver: f.waiver } : {}) })),
|
|
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(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 };
|
|
}
|