mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 17:41:35 +01:00
Review and shipping tools: seven small fixes to exclusions, issue links, PR description checks, build outputs, known-red tests and telemetry (GST-3464) (#4672)
Fixes seven small bugs in the review and shipping tools: bad exclusion keys now refuse, `Review-Finding:` lines are no longer issue references, older commits' issue mentions name their commit, and wording checks skip the PR's short opening lines. A native binary the checkout builds at a path its committed `.gitignore` names is no longer flagged as a download; the grouped-merge test gate can read the list of tests already failing on main from a file; and telemetry no longer logs a duplicate onboarding event when a run crosses midnight. Nothing to do; each fix has a test that fails on main. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Co-authored-by: Davmunrey <108531295+Davmunrey@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#2 reader=outside-voice
This commit is contained in:
19 files changed
+263
-22
No files matched your search
@@ -48,6 +48,8 @@ export interface ClosingPr { number: number; state?: string; headRefName?: strin
|
||||
const CLOSURE = /^\s*(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?)\s*:?\s+(?:([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#|#|GH-)(\d+)\s*$/i;
|
||||
const PARTIAL = /\b(?:partial(?:ly)?|part of|defer(?:red)?|follow-?up|related|refs?|see|context)\b/i;
|
||||
const CROSS = /\b([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#(\d+)\b/g;
|
||||
/** /ship's `Review-Finding: <ledger id or fingerprint> reader=<reader>` trailer names a review ledger entry (`p1/red-team#3`), never an issue (#4371). */
|
||||
const REVIEW_FINDING = /^\s*review-finding:\s/i;
|
||||
const BARE = /(?<![A-Za-z0-9_./-])#(\d+)\b/g;
|
||||
/** One `name #N[, #M]…`, `name PR #N` or `name issue #N`: the name, then every number. */
|
||||
const NAMED_PART = /([A-Za-z][\w.-]*(?:\/[\w.-]+)?)\s+(?:(?:PR|issue)\s+)?(#\d+(?:,\s*#\d+)*)/gi;
|
||||
@@ -63,6 +65,7 @@ export function mentionsIn(message: string, source = 'commit'): IssueMention[] {
|
||||
const add = (m: IssueMention) => { const k = `${m.repo ?? ''}#${m.issue}:${m.intent}`; if (!seen.has(k)) { seen.add(k); out.push(m); } };
|
||||
for (const raw of message.split('\n')) {
|
||||
const line = raw.replace(/\s+$/, '');
|
||||
if (REVIEW_FINDING.test(line)) continue;
|
||||
const trailer = CLOSURE.exec(line);
|
||||
if (trailer && !PARTIAL.test(line)) { add({ issue: Number(trailer[2]), intent: 'fixes', ...(trailer[1] ? { repo: trailer[1] } : {}), source: `${source}: ${line.trim()}` }); continue; }
|
||||
const rest = line.replace(NAMED, whole => whole.replace(NAMED_PART, (part, name: string, numbers: string) => {
|
||||
|
||||
+24
-4
@@ -34,7 +34,7 @@ const SCP = /^(?:[\w.-]+@)?[\w.-]+:(?!\/\/)[\w./-]+$/;
|
||||
export interface Inventory { at: number; roots: string[]; repos: Record<string, string[]>; big: Record<string, number>; ignored?: Record<string, Omit<Ignored, 'path'>>; partial?: string }
|
||||
export interface Found { path: string; kind: 'repo' | 'download'; remote?: string; bytes: number | null }
|
||||
/** A new directory the sweep saw and did not count: a marked test fixture root, or a repository whose remote resolves locally. */
|
||||
export interface Ignored { path: string; reason: 'fixture-marker' | 'local-remote'; remote?: string }
|
||||
export interface Ignored { path: string; reason: 'fixture-marker' | 'local-remote' | 'build-output'; remote?: string }
|
||||
export type SweepVerdict = 'clean' | 'violation' | 'partial';
|
||||
export interface StageSweep {
|
||||
attempt: number;
|
||||
@@ -139,7 +139,7 @@ export function inventory(roots: readonly string[], checkout: string, skip: read
|
||||
}
|
||||
for (const d of list) {
|
||||
const p = path.join(dir, d.name);
|
||||
if (d.isFile()) { if (ENGINE_DB.test(d.name) && dir.startsWith(engine)) continue; try { const s = fs.statSync(p); if (s.size >= BIG_BYTES) inv.big[p] = s.size; } catch { /* gone */ } continue; }
|
||||
if (d.isFile()) { if (ENGINE_DB.test(d.name) && dir.startsWith(engine)) continue; try { const s = fs.statSync(p); if (s.size >= BIG_BYTES) { if (buildOutput(home, p)) inv.ignored![p] = { reason: 'build-output' }; else inv.big[p] = s.size; } } catch { /* gone */ } continue; }
|
||||
if (d.isDirectory() && !SKIP.has(d.name) && depth < SWEEP_DEPTH) walk(p, depth + 1);
|
||||
}
|
||||
};
|
||||
@@ -148,6 +148,26 @@ export function inventory(roots: readonly string[], checkout: string, skip: read
|
||||
}
|
||||
|
||||
function realOr(p: string): string { try { return fs.realpathSync(p); } catch { return path.resolve(p); } }
|
||||
|
||||
/** ELF, Mach-O (32, 64 and universal, either byte order) and PE headers: what a compiler or `bun build --compile` writes. */
|
||||
const NATIVE_MAGIC = [[0x7f, 0x45, 0x4c, 0x46], [0xfe, 0xed, 0xfa, 0xce], [0xfe, 0xed, 0xfa, 0xcf], [0xce, 0xfa, 0xed, 0xfe], [0xcf, 0xfa, 0xed, 0xfe], [0xca, 0xfe, 0xba, 0xbe], [0x4d, 0x5a]];
|
||||
|
||||
/**
|
||||
* A big file the checkout's own build writes, not a fetch (GSTA-745: `bin/gstack-cso-core`, 110 MB, built while a stage ran):
|
||||
* a native executable inside the checkout at a path its committed, unmodified root `.gitignore` names exactly, with no glob.
|
||||
* Anything else, a download into an ignored directory or under a glob included, stays a fetch.
|
||||
*/
|
||||
function buildOutput(checkout: string, file: string): boolean {
|
||||
const rel = path.relative(checkout, file);
|
||||
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return false;
|
||||
const git = (args: string[]) => spawnSync('git', ['-C', checkout, ...args], { encoding: 'utf8', timeout: 10_000 });
|
||||
if (git(['ls-files', '--error-unmatch', '--', '.gitignore']).status !== 0 || git(['diff', '--quiet', 'HEAD', '--', '.gitignore']).status !== 0) return false;
|
||||
const hit = /^\.gitignore:\d+:(.*)\t/.exec(git(['check-ignore', '--no-index', '-v', '--', rel.split(path.sep).join('/')]).stdout ?? '');
|
||||
if (!hit || hit[1]!.replace(/^\//, '') !== rel.split(path.sep).join('/')) return false;
|
||||
const head = Buffer.alloc(4);
|
||||
try { const fd = fs.openSync(file, 'r'); try { fs.readSync(fd, head, 0, 4, 0); } finally { fs.closeSync(fd); } } catch { return false; }
|
||||
return NATIVE_MAGIC.some(m => m.every((b, i) => head[i] === b));
|
||||
}
|
||||
function du(p: string): number | null {
|
||||
const r = spawnSync('du', ['-sk', p], { encoding: 'utf8', timeout: 10_000 });
|
||||
const kb = Number(/^(\d+)/.exec(r.stdout ?? '')?.[1]);
|
||||
@@ -163,7 +183,7 @@ export function sweepDiff(start: Inventory, end: Inventory): Found[] {
|
||||
found.push({ path: p, kind: 'repo', remote, bytes: du(p) });
|
||||
}
|
||||
for (const [p, bytes] of Object.entries(end.big)) {
|
||||
if (p in start.big || found.some(f => p.startsWith(f.path + path.sep))) continue;
|
||||
if (p in start.big || start.ignored?.[p]?.reason === 'build-output' || found.some(f => p.startsWith(f.path + path.sep))) continue;
|
||||
found.push({ path: p, kind: 'download', bytes });
|
||||
}
|
||||
return found;
|
||||
@@ -206,7 +226,7 @@ export function foundLines(stage: Stage, attempt: number, found: readonly Found[
|
||||
export function ignoredLines(stage: Stage, attempt: number, ignored: readonly Ignored[]): string[] {
|
||||
return ignored.map(i => {
|
||||
const remote = i.remote ? ` remote=${control(i.remote) ? JSON.stringify(i.remote) : i.remote}` : '';
|
||||
const why = i.reason === 'fixture-marker' ? `a test fixture root carrying ${FIXTURE_MARKER}` : 'its remote resolves to a local path through url.<base>.insteadOf';
|
||||
const why = i.reason === 'fixture-marker' ? `a test fixture root carrying ${FIXTURE_MARKER}` : i.reason === 'build-output' ? 'a native executable the checkout\'s committed .gitignore names exactly, which its own build writes' : 'its remote resolves to a local path through url.<base>.insteadOf';
|
||||
return `FETCH_IGNORED: stage=${stage} attempt=${attempt} path=${shownPath(i.path)} reason=${i.reason}${remote} (${why}, so not a fetch; docs/review-policy.md#what-readers-may-fetch)`;
|
||||
});
|
||||
}
|
||||
|
||||
+2
-2
@@ -683,8 +683,8 @@ export function finish(rawText: string | null, source: PolicySource): LoadedPoli
|
||||
let raw: unknown;
|
||||
try { raw = JSON.parse(rawText); }
|
||||
catch (e: any) { return { policy: JSON.parse(JSON.stringify(DEFAULT_POLICY)), present: true, source, errors: [{ code: 'POLICY_INVALID', path: SHIP_POLICY_PATH, message: `not valid JSON: ${e.message}` }], warnings: [], values: {} }; }
|
||||
const all = validatePolicy(raw), exclusion = /^review_(exclude_paths|content_patterns)(\[|$)/;
|
||||
const rest = source.kind === 'base' && all.length && all.every(e => exclusion.test(e.path)) ? Object.fromEntries(Object.entries(raw as Record<string, unknown>).filter(([k]) => !exclusion.test(k))) : null;
|
||||
const all = validatePolicy(raw), exclusion = /^review_(exclude_paths|content_patterns)(\[|$)/, exclusionKey = /^review_(exclude_paths|content_patterns)$/;
|
||||
const rest = source.kind === 'base' && all.length && all.every(e => exclusion.test(e.path)) ? Object.fromEntries(Object.entries(raw as Record<string, unknown>).filter(([k]) => !exclusionKey.test(k))) : null;
|
||||
const errors = rest && !validatePolicy(rest).length ? [] : all, read = errors.length ? null : (rest ?? raw) as Record<string, unknown>, merged = mergePolicy(read, source.label);
|
||||
const warnings = raw && typeof raw === 'object' && !Array.isArray(raw) ? policyWarnings(raw as Record<string, unknown>) : [];
|
||||
return { policy: merged.policy, present: true, source, errors, warnings, values: merged.values, ...(rest && !errors.length ? { setAside: all } : {}) };
|
||||
|
||||
@@ -12,6 +12,7 @@ import { docsExceptionLine, parseReceiptDocs } from './ship-receipt-docs';
|
||||
import { ruledNoteText, type RuledNote } from './ruled-notes';
|
||||
import { gateDispositionText, type GateDisposition } from './gate-dispositions';
|
||||
import { laneExceptionBodyLines } from './test-lane-exception';
|
||||
import { VISIBLE_CHARS, VISIBLE_LINES, visibleOpening } from './pr-body-shape';
|
||||
|
||||
export interface ProseClaim { field: string; prose: number; receipt: number }
|
||||
export interface ProseCheck { checked: number; mismatches: ProseClaim[] }
|
||||
@@ -60,6 +61,20 @@ function withoutFences(body: string): string {
|
||||
return out.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* The body without its opening, the lines above its first `<details>` fold (after closed fences are gone): R76 keeps that
|
||||
* part to what changed for a user, why and what to do, so a number there is the subject of the PR (`58 fixed with gstack`,
|
||||
* a published result), never one of its receipt counters. A body with no fold, or an opening longer than R76 allows
|
||||
* (VISIBLE_LINES lines, VISIBLE_CHARS characters, measured on the body before its fences collapse, as the PR body shape check measures it), is checked whole.
|
||||
*/
|
||||
function withoutOpening(body: string, unfenced: string): string {
|
||||
const lines = body.split(/(?<=\n)/);
|
||||
const fold = lines.findIndex(l => /^ {0,3}<details\b/i.test(l));
|
||||
if (fold <= 0) return body;
|
||||
const opening = visibleOpening(unfenced);
|
||||
return opening.length > VISIBLE_LINES || [...opening.join('\n')].length > VISIBLE_CHARS ? body : '(opening)\n' + lines.slice(fold).join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* The body without the `## Approvals` blocks gstack-approvals renders (lib/approval-record.ts renderRecord): the
|
||||
* heading, the Date | Asked | Exact words table and its `Source: gstack-approvals record for …` footer. Those rows
|
||||
@@ -120,7 +135,7 @@ function withoutExceptionLines(body: string, receipt: Record<string, unknown>):
|
||||
|
||||
/**
|
||||
* Every `<name>=<n>`, `<name>: <n>` and `<n> <name>` in the prose (the body
|
||||
* without its receipt block, its code fences, its rendered Approvals block and its exception lines), where `<name>` is a counter's leaf key with `_`
|
||||
* without its receipt block, its opening above the first fold, its code fences, its rendered Approvals block and its exception lines), where `<name>` is a counter's leaf key with `_`
|
||||
* matched as `_`, space or `-` and not part of a longer word (`3 pass-through`
|
||||
* is not a `pass` claim), compared with the receipt. A leaf key shared by
|
||||
* several counters (`pass` under every gate lane, `passed` under gate and ci)
|
||||
@@ -130,7 +145,8 @@ function withoutExceptionLines(body: string, receipt: Record<string, unknown>):
|
||||
* `<n> <name>` claim about the next key (#3513).
|
||||
*/
|
||||
export function checkReceiptProse(receipt: Record<string, unknown>, body: string): ProseCheck {
|
||||
const prose = withoutExceptionLines(withoutApprovalsBlocks(withoutFences(body.replace(BLOCK_RE, ''))), receipt);
|
||||
const raw = body.replace(BLOCK_RE, '');
|
||||
const prose = withoutExceptionLines(withoutApprovalsBlocks(withoutOpening(withoutFences(raw), raw)), receipt);
|
||||
const byLeaf = new Map<string, Array<{ field: string; value: number }>>();
|
||||
for (const [field, value] of receiptCounters(receipt)) {
|
||||
const leaf = field.split('.').at(-1)!;
|
||||
|
||||
Reference in new issue
Block a user