fix(#3312): require static frontend evidence before ui-plan-gate blocks (#3451)

* fix(#3312): require static frontend evidence before ui-plan-gate blocks

* fix(#3312): fill changeset pr reference

* fix(#3312): align regression assertions with section heading and legacy artifact shape

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-08-14 09:27:48 -04:00
committed by GitHub
parent 43475a2e0f
commit 29c27e948b
11 changed files with 457 additions and 23 deletions

View File

@@ -16,7 +16,8 @@
* matched; "micro-frontend" and "micro frontend" ARE matched).
*
* Public API:
* checkUiPresence(text: string): { hasUI: boolean, tokens: string[] }
* checkUiPresence(text: string): { hasUI: boolean, tokens: string[],
* matchedToken: string|null, matchedLine: string|null }
*
* CLI usage — reads phase-section text from STDIN to avoid ARG_MAX limits:
* echo "$PHASE_SECTION" | node gsd-core/bin/lib/ui-safety-gate.cjs
@@ -32,6 +33,14 @@
export interface UiPresenceResult {
hasUI: boolean;
tokens: string[];
/**
* #3312: first token matched (lowercased) and the line it matched on, so gate
* consumers can surface WHAT tripped the sniffer without re-reading the source.
* Null when nothing matched (or when `**UI hint**: yes` short-circuits with no
* token match — the declaration, not vocabulary, is then the signal).
*/
matchedToken: string | null;
matchedLine: string | null;
}
export const UI_TOKENS: ReadonlyArray<string> = [
@@ -71,7 +80,7 @@ const UI_GATE_PATTERN_GLOBAL = new RegExp(UI_GATE_PATTERN.source, 'gi');
*/
export function checkUiPresence(text: string): UiPresenceResult {
if (typeof text !== 'string') {
return { hasUI: false, tokens: [] };
return { hasUI: false, tokens: [], matchedToken: null, matchedLine: null };
}
// Normalise CRLF so the pattern sees consistent line boundaries.
@@ -96,22 +105,30 @@ export function checkUiPresence(text: string): UiPresenceResult {
.join('\n');
const found = new Set<string>();
let matchedToken: string | null = null;
let matchedLine: string | null = null;
for (const line of sniffable.split('\n')) {
// Reset lastIndex before each line so the global pattern restarts from 0.
UI_GATE_PATTERN_GLOBAL.lastIndex = 0;
for (const m of line.matchAll(UI_GATE_PATTERN_GLOBAL)) {
if (matchedToken === null) {
// #3312: record the FIRST match so gate consumers can surface the
// triggering token/line for one-second operator triage.
matchedToken = m[2].toLowerCase();
matchedLine = line;
}
found.add(m[2].toLowerCase());
}
}
if (hint === 'no') {
return { hasUI: false, tokens: [] };
return { hasUI: false, tokens: [], matchedToken: null, matchedLine: null };
}
if (hint === 'yes') {
return { hasUI: true, tokens: [...found] };
return { hasUI: true, tokens: [...found], matchedToken, matchedLine };
}
return { hasUI: found.size > 0, tokens: [...found] };
return { hasUI: found.size > 0, tokens: [...found], matchedToken, matchedLine };
}
// ── CLI entry point ─────────────────────────────────────────────────────────