mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-25 17:41:35 +01:00
Make /ship's preflight honor the repo's CI rerun time limit and name the install command in a fresh worktree (GST-3360) (#4608)
/ship's preflight now stops its rerun of CI-skipped test files at the repository's own `ci_record_timeout_s` limit instead of a fixed 600 s, and prints the limit it used. In a fresh worktree with no installed packages, preflight stops with the exact install command instead of failing later with missing tools. Why: several /ship runs on one machine hit both problems (one repository sets 900 s; each new worktree needed `bun install`). Nothing to do. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p3/outside-voice#1 reader=outside-voice Review-Finding: p3/outside-voice#2 reader=outside-voice
This commit is contained in:
1 parent
cbe37f2c0a
commit
df4d0bd0b1
8 files changed
+146
-11
No files matched your search
@@ -202,7 +202,7 @@ export function mappedLanes(cwd: string, base: string, list: { label: string; co
|
||||
* and records the CI-sourced ledger row; or, when the lane's inventory refuses this tree, the cleared remote gate for this exact
|
||||
* tree stands in (`remoteGate`, lib/remote-gate-stand-in.ts, GST-1688); or why neither held (`carryNone`), so the caller runs it.
|
||||
*/
|
||||
export function carryLane(cwd: string, base: string, l: { label: string; command: string }, timeoutS = DEFAULT_POLICY.ci_record_timeout_s): LaneResult {
|
||||
export function carryLane(cwd: string, base: string, l: { label: string; command: string }, timeoutS = recordCiTimeout(shipPolicy(cwd, base), base).seconds): LaneResult {
|
||||
const rec = bin(cwd, 'gstack-evidence', ['record-ci', '--label', l.label, '--base', base, '--remote-gate-stands-in', '--', l.command], timeoutS * 1000);
|
||||
const got = recordCiResult(rec.stderr);
|
||||
if (rec.status === 0 && got.remoteGate) return { label: l.label, exit: 0, testsRan: got.tests!, log: '-', remoteGate: got.remoteGate, standIn: got.standIn ?? 'not carried' };
|
||||
@@ -210,7 +210,7 @@ export function carryLane(cwd: string, base: string, l: { label: string; command
|
||||
return { label: l.label, exit: null, testsRan: 'unknown', log: '-', carryNone: got.none ?? `record_failed: ${firstLine(rec.stderr)}`, ...(got.diagnosis ? { diagnosis: got.diagnosis } : {}) };
|
||||
}
|
||||
|
||||
/** accept's bound on one record-ci (GST-1606): the base policy's `ci_record_timeout_s`, 600 s by default, clamped to 3600 s. */
|
||||
/** The bound on one record-ci, in accept, finish and preflight alike (GST-1606, GST-3360): the base policy's `ci_record_timeout_s`, 600 s by default, clamped to 3600 s. */
|
||||
export function recordCiTimeout(policy: Record<string, any> | null, base: string): { seconds: number; line: string } {
|
||||
const set = policy?.ci_record_timeout_s;
|
||||
if (typeof set !== 'number' || set === DEFAULT_POLICY.ci_record_timeout_s) return { seconds: DEFAULT_POLICY.ci_record_timeout_s, line: `CI_RECORD_TIMEOUT: ${DEFAULT_POLICY.ci_record_timeout_s}s (default)` };
|
||||
@@ -227,15 +227,16 @@ export function recordCiTimeout(policy: Record<string, any> | null, base: string
|
||||
* per_file remainder or exception preflight here; only the refused lanes go to record-ci, for a cleared remote gate. Every other
|
||||
* lane runs through gstack-evidence run --reuse (a pass at this tree, command and runtime is reused; `reuse: false` forces a run).
|
||||
*/
|
||||
export async function runLanes(cwd: string, list: { label: string; command: string }[], concurrency = Infinity, opts: { base?: string; reuse?: boolean; hold?: boolean } = {}): Promise<LaneResult[]> {
|
||||
export async function runLanes(cwd: string, list: { label: string; command: string }[], concurrency = Infinity, opts: { base?: string; reuse?: boolean; hold?: boolean; recordCiTimeoutS?: number } = {}): Promise<LaneResult[]> {
|
||||
const out: LaneResult[] = [];
|
||||
const mapped = opts.base ? mappedLanes(cwd, opts.base, list) : new Map<string, ShipLaneMapping>();
|
||||
const bound = mapped.size ? opts.recordCiTimeoutS ?? recordCiTimeout(shipPolicy(cwd, opts.base!), opts.base!).seconds : 0;
|
||||
const refused = list.map(l => !!opts.hold && mapped.has(l.label) && bin(cwd, 'gstack-ci-carry', ['find', '--base', opts.base!, '--command', l.command, '--allow-repo-commands']).status !== 0);
|
||||
const carries = list.map((l, i) => (refused[i] ? carryLane(cwd, opts.base!, l) : null));
|
||||
const carries = list.map((l, i) => (refused[i] ? carryLane(cwd, opts.base!, l, bound) : null));
|
||||
const done = (c: LaneResult | null) => !!(c?.carried || c?.remoteGate);
|
||||
const held = () => list.map((l, i) => { const c = carries[i]; return c && done(c) ? c : { ...(c ?? { label: l.label, exit: null, testsRan: 'unknown', log: '-' }), held: true as const }; });
|
||||
if (opts.hold && carries.some(c => c && !done(c))) return held();
|
||||
for (const [i, l] of list.entries()) if (!carries[i] && mapped.has(l.label)) carries[i] = carryLane(cwd, opts.base!, l);
|
||||
for (const [i, l] of list.entries()) if (!carries[i] && mapped.has(l.label)) carries[i] = carryLane(cwd, opts.base!, l, bound);
|
||||
if (opts.hold && carries.some(c => c && !done(c))) return held();
|
||||
let next = 0;
|
||||
const worker = async () => {
|
||||
|
||||
+1
-1
@@ -240,7 +240,7 @@ export const POLICY_EXPLANATIONS: Record<PolicyKey, string> = {
|
||||
bookkeeping: 'Root-anchored globs of bookkeeping tables, each ending in .tsv, .csv or .txt and never under .gstack/ or .github/, for example ["scripts/*-baseline.tsv"]. An edit of at most 20 lines to a matching file after review binds, first touched or not, takes /ship finish\'s scoped reader instead of Steps 5–11.5; the reader still reads every changed row. Read from the base branch only. Empty (default) declares none.',
|
||||
mechanical_retake: MECHANICAL_EXPLANATION,
|
||||
test_code: 'Root-anchored globs of test code the built-in test names miss, never under .gstack/ or .github/, for example ["tests/**/*.gd"] for GDScript checks. /ship finish routes a matching file changed after review as test code (one scoped reader of its test hunks) instead of behavior, beside the built-in globs; shared helpers and fixtures stay behavior. Read from the base branch only. Empty (default) declares none.',
|
||||
ci_record_timeout_s: 'Seconds `gstack-ship-release accept` lets one `gstack-evidence record-ci` run before it stops that lane, an integer of at least 60 (default 600). A value over 3600 is clamped to 3600, and accept prints the bound it used (`CI_RECORD_TIMEOUT:`). Raise it when record-ci runs long, for example a per_file remainder of CI-skipped files. Read from the base branch only.',
|
||||
ci_record_timeout_s: 'Seconds one `gstack-evidence record-ci` may run before it stops that lane (gstack-ship-release accept and finish, gstack-ship-preflight Step 5), an integer of at least 60 (default 600). A value over 3600 is clamped to 3600, and accept prints the bound it used (`CI_RECORD_TIMEOUT:`). Raise it when record-ci runs long, for example a per_file remainder of CI-skipped files. Read from the base branch only.',
|
||||
plan_record: 'off (default) | warn | require. Whether `gstack-ship-queue ready` and `land` check the PR body\'s `Plan:` line (approved: <run id or row id> | exempt: <reason>) against the approval store (docs/ship-policy.md#plan-record). warn prints the PLAN: line and continues; require refuses a missing, unresolved or agent-approved plan. This key is read from the base branch only; with it off, GSTACK_PLAN_RECORD, then plan_record in <state root>/config.yaml (gstack-config set plan_record warn, for a repo that commits no .gstack/), then warn in a Capy session decide. On a public repo render --plan writes Plan: approved (record r-<id>) instead of the run id.',
|
||||
docs_only: '{ allow, deny?, tests? } or null, read from the base revision only (docs/pregate.md#repo-docs-paths). allow (1 to 16) adds human-docs globs to the docs-only allowlist (README.md, docs/**.md, changelog.d/*.md): each ends in .md, starts with a literal directory or file name and passes through no hidden, code, test or agent directory ("wiki/board/**.md"). deny (up to 64 globs) removes paths, built-in ones included. tests (up to 16 test file paths) are the repository\'s checks for those directories: the docs lane runs them, and a non-docs file that names an allowed directory ("wiki/", \'wiki\') refuses the change unless it is one of them, names one, or one names it. The built-in deny list (agent instructions, templates, prompts, preferences, tool configuration, pinned results, preregistrations, generated outputs) always wins, a path a script or test names stays pinned, and a pull request that edits this file is never docs-only. An unknown key under docs_only is a warning, and the classifier then ignores allow. Needs min_gstack_version.',
|
||||
merge: 'train (default) | direct. direct: the Captain lands each READY PR at its own green head with `gstack-ship-queue land --pr <n> --pin <sha>` (no train, no stamp commit; the PR leaves VERSION, the manifest version and the CHANGELOG at the base and the release stamps them), and train build refuses. train: merge trains as before (docs/ship-policy.md#land-direct).',
|
||||
|
||||
+25
-3
@@ -17,7 +17,7 @@ import { classifyDiff } from './review-depth';
|
||||
import { wtreeFingerprint } from './script-invocation';
|
||||
import { audit } from './ship-audit';
|
||||
import { withGateLock } from './gate-dispositions';
|
||||
import { bin, carryNoneLines, firstLine, flagReader, gh, git, hostedOrigin, laneConcurrency, laneLine, lanes, mappedLanes, Report, runLanes, shipPolicy, shipRunMarker, short } from './ship-bin-common';
|
||||
import { bin, carryNoneLines, firstLine, flagReader, gh, git, hostedOrigin, laneConcurrency, laneLine, lanes, mappedLanes, recordCiTimeout, Report, runLanes, shipPolicy, shipRunMarker, short } from './ship-bin-common';
|
||||
|
||||
export const PREFLIGHT_HELP = `gstack-ship-preflight — /ship Steps 1-3 and Step 5's pregate and lanes in one call (ship/SKILL.md)
|
||||
|
||||
@@ -45,7 +45,7 @@ export const PREFLIGHT_HELP = `gstack-ship-preflight — /ship Steps 1-3 and Ste
|
||||
(CONTEXT, TODOS, COVERAGE_MAP, Coverage, PLAN_*, READER: coverage=needed|none plan=needed|none)
|
||||
|
||||
Prints at most 30 lines: BRANCH, STATUS, DIFF, PR/CARRY, APPLE, SCOPE, MERGE, DISTRIBUTION, POLICY,
|
||||
RUNTIME_LINES, PREGATE (with up to three PREGATE_DETAIL lines when it does not pass), LANES, one LANE line per lane
|
||||
RUNTIME_LINES, PREGATE (with up to three PREGATE_DETAIL lines when it does not pass), LANES, CI_RECORD_TIMEOUT (when a lane is mapped), one LANE line per lane
|
||||
(a lane the base maps in .gstack/pregate.json ship_lanes_from is carried from a verified CI run at this exact clean tree:
|
||||
LANE: <label> carried run=<id>/<attempt> tests_ran=<n>, else CI_CARRY: none (<reason>) and STOP: SHIP_LANE_NOT_CARRIED, or with
|
||||
--run-uncarried-here it runs here; any other lane that
|
||||
@@ -202,7 +202,27 @@ function merge(cwd: string, base: string, r: Report): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* GST-3360: Step 5's pregate and lanes run the repository's own tools, which a fresh worktree lacks until its packages are
|
||||
* installed (tsc exits 127, bun test cannot resolve imports). The install command for the checkout's lockfile, or null when
|
||||
* package.json declares no packages, node_modules exists, or Yarn Plug'n'Play's .pnp.cjs / .pnp.loader.mjs (Yarn Classic: .pnp.js)
|
||||
* marks an install that never creates node_modules. Preflight names the command and never runs it.
|
||||
*/
|
||||
function depsInstall(root: string): string | null {
|
||||
let pkg: { dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
||||
try { pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); } catch { return null; }
|
||||
const has = (f: string) => fs.existsSync(path.join(root, f));
|
||||
if (!Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }).length || has('node_modules') || has('.pnp.cjs') || has('.pnp.loader.mjs') || has('.pnp.js')) return null;
|
||||
return has('bun.lock') || has('bun.lockb') ? 'bun install --frozen-lockfile' : has('pnpm-lock.yaml') ? 'pnpm install --frozen-lockfile' : has('yarn.lock') ? 'yarn install --frozen-lockfile' : has('package-lock.json') || has('npm-shrinkwrap.json') ? 'npm ci' : 'bun install';
|
||||
}
|
||||
|
||||
async function tests(cwd: string, base: string, list: { label: string; command: string }[], policyFrom: string, timeout: string | undefined, step: { seconds: number; source: string }, run: { concurrency: number; line: string; hold: boolean; testsOnly: boolean }, r: Report): Promise<void> {
|
||||
const root = git(cwd, ['rev-parse', '--show-toplevel']).stdout.trim() || cwd;
|
||||
const install = depsInstall(root);
|
||||
if (install) {
|
||||
r.stop(`DEPS_MISSING: ${root}/package.json declares packages but there is no node_modules (a fresh worktree), so Step 5's pregate and lanes cannot run: cd '${root.replace(/'/g, `'\\''`)}' && ${install}, then ${run.testsOnly ? 'rerun this command' : `rerun with --tests-only --base ${base} and the same --lane flags`}`);
|
||||
return;
|
||||
}
|
||||
const pg = bin(cwd, 'gstack-pregate', ['--allow-repo-commands', '--base', base, '--policy-from', policyFrom, ...(timeout ? ['--timeout', timeout] : [])], step.seconds * 1000);
|
||||
if (pg.timedOut) {
|
||||
r.add(`PREGATE: time limit hit (Step 5's whole pregate ran past its ${step.seconds} s budget, ${step.source}, and was stopped with exit ${pg.status ?? 'none'}; no verdict)`);
|
||||
@@ -219,7 +239,9 @@ async function tests(cwd: string, base: string, list: { label: string; command:
|
||||
}
|
||||
if (/uncleared/.test(verdict)) r.next('pregate requires-remote: gstack-pregate clear, or --remote --spend-cap <usd> under a user cap, before Step 18');
|
||||
r.add(run.line);
|
||||
const ran = await runLanes(cwd, list, run.concurrency, { base, hold: run.hold });
|
||||
const recordCi = mappedLanes(cwd, base, list).size ? recordCiTimeout(shipPolicy(cwd, base), base) : undefined;
|
||||
if (recordCi) r.add(recordCi.line);
|
||||
const ran = await runLanes(cwd, list, run.concurrency, { base, hold: run.hold, recordCiTimeoutS: recordCi?.seconds });
|
||||
const results = ran.map(laneLine);
|
||||
for (const [i, l] of results.entries()) { for (const none of carryNoneLines(ran[i]!)) r.add(none); r.add(l.line); }
|
||||
const refused = ran.filter(l => l.held && l.carryNone);
|
||||
|
||||
Reference in new issue
Block a user