Files
gstack/bin/gstack-lane-check
T
Garry Tanandcapy-ai[bot] 6417abf7a6 Move the tools only Capy crews use into a crew/ folder (GST-1833) (#4145)
* Load the Capy crew skills only on Capy machines (GST-1833)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Add changelog entry for Capy-only crew skills (GST-1833)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Move the Capy-only crew tooling into crew/ and run its tests only when needed (GST-1833)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Test that the Capy launch file puts crew/bin on PATH

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Count any ~/.capy as a Capy machine, so a Mac running Capy keeps /captain

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Fix the tests and fixtures that broke when crew tooling moved into crew/

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Plan every crew test when a pull request's merge-base can't be read

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Add a test that checks each crew-only module left the root tree for crew/

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Run crew tests on pull requests that change bin/ commands or workflows they drive

Review-Finding: p1/specialist-batched#1 reader=testing
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Keep running every crew test on every pull request; the skip comes in a later change

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Keep copied installs and older release bisects working after the crew/ move

Setup now copies crew/lib into every host's runtime root beside bin and lib, so Windows installs (which copy instead of linking) can still start gstack-ship-receipt, gstack-pregate and the other commands that import it. The release bisect runs the train-gate script from wherever the checked-out commit has it, so a bisect over commits from before the move still gets a verdict.

Review-Finding: p1/outside-voice#1 reader=outside-voice
Review-Finding: p1/outside-voice#2 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Say in the changelog that Windows installs keep working after the crew/ move

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Point the harness guide's merge-queue rows at crew/lib/ where those modules moved

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Point the plain-title test at the wave module's new home in crew/ (GST-1833)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-08 14:26:14 +00:00

63 lines
4.0 KiB
TypeScript
Executable File

#!/usr/bin/env -S bun --no-env-file --config=/dev/null
/**
* gstack-lane-check — planned files versus in-flight lanes (plan E2).
*
* gstack-lane-check --planned <path|glob>[,...] [--planned-file <file>] [--branch <name>]... [--pr <n>]... [--base <ref>] [--json]
*
* Diffs each in-flight branch or pull request against its merge base with the
* base branch and prints one `LANE_CONFLICT:` line per planned file it already
* changes (PR number, branch, hunk count), then `LANE_CHECK: clear | conflicts | unresolved`.
* Exit 0 clear, 1 conflicts, 3 when a lane could not be resolved and nothing conflicts.
* Logic: crew/lib/lane-ownership.ts. Codes: LANE_CONFLICT, LANE_REF_UNAVAILABLE (lib/result-codes.ts).
*/
import { spawnSync } from 'node:child_process';
import * as fs from 'node:fs';
import { EXIT, exitTableHelp } from '../lib/headless-artifacts';
import { laneCheck, renderLaneCheck } from '../crew/lib/lane-ownership';
import { resultLine } from '../lib/result-codes';
const HELP = `gstack-lane-check — one owner per file across in-flight lanes
--planned <p,p> files or globs this lane plans to touch (repeatable; \`lib/**\` and \`*.ts\` wildcards)
--planned-file <file> one planned path per line (# comments allowed)
--branch <name> an in-flight branch (fetched: origin/<name> or local)
--pr <n> an in-flight pull request; its head branch comes from \`gh pr view\`
--base <ref> the base to diff against (default origin/HEAD, else origin/main)
--json the whole check as one JSON object
${exitTableHelp()}`;
function main(argv: string[]): number {
if (argv.includes('--help') || argv.includes('-h')) { process.stdout.write(HELP + '\n'); return EXIT.ok; }
const planned: string[] = []; const branches: string[] = []; const prs: number[] = [];
let base: string | undefined;
for (let i = 0; i < argv.length; i++) {
const a = argv[i]!;
if (a === '--planned') planned.push(...(argv[++i] ?? '').split(','));
else if (a === '--planned-file') {
const file = argv[++i];
if (!file || !fs.existsSync(file)) { process.stderr.write(`gstack-lane-check: --planned-file ${file ?? ''} not found\n`); return EXIT.usage; }
planned.push(...fs.readFileSync(file, 'utf8').split('\n').map(l => l.replace(/#.*$/, '').trim()).filter(Boolean));
}
else if (a === '--branch') branches.push(argv[++i] ?? '');
else if (a === '--pr') { const n = Number(argv[++i]); if (!Number.isInteger(n) || n <= 0) { process.stderr.write('gstack-lane-check: --pr needs a positive number\n'); return EXIT.usage; } prs.push(n); }
else if (a === '--base') base = argv[++i];
else if (a !== '--json') { process.stderr.write(`gstack-lane-check: unknown argument ${a}\n${HELP}\n`); return EXIT.usage; }
}
if (planned.filter(Boolean).length === 0) { process.stderr.write(`gstack-lane-check: --planned or --planned-file is required\n${HELP}\n`); return EXIT.usage; }
if (branches.filter(Boolean).length === 0 && prs.length === 0) { process.stderr.write(`gstack-lane-check: name at least one --branch or --pr\n${HELP}\n`); return EXIT.usage; }
const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', timeout: 15_000 });
if (root.status !== 0) { process.stderr.write('gstack-lane-check: not inside a git repository\n'); return EXIT.usage; }
const check = laneCheck({ cwd: root.stdout.trim(), planned, branches: branches.filter(Boolean), prs, base });
if (argv.includes('--json')) process.stdout.write(JSON.stringify(check) + '\n');
else process.stdout.write(renderLaneCheck(check));
for (const lane of check.unresolved) process.stderr.write(resultLine('gstack-lane-check', 'LANE_REF_UNAVAILABLE', lane.pr !== null ? `PR #${lane.pr}` : lane.branch) + '\n');
if (check.intersections.length) {
process.stderr.write(resultLine('gstack-lane-check', 'LANE_CONFLICT', `${check.intersections.length} planned file(s) already in flight`) + '\n');
return EXIT.fail;
}
return check.unresolved.length ? EXIT.refused : EXIT.ok;
}
process.exitCode = main(process.argv.slice(2));