mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-03 23:37:53 +01:00
v1.94.3.0 fix(ship-preflight): stop when origin's default branch can't be read (#3718 follow-up) (#3913)
* fix(ship-preflight): stop when ls-remote origin HEAD fails instead of guessing the default branch Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(ship-preflight): a remote HEAD with no branch falls back to the default-base order; docs name the whole order Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: say when the default-base order still reads the local origin/HEAD 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>
This commit is contained in:
1 parent
7d475a4ea4
commit
ad51cef58a
8 files changed
+69
-8
No files matched your search
@@ -1,5 +1,15 @@
|
||||
# Changelog
|
||||
|
||||
## [1.94.3.0] - 2026-11-03
|
||||
|
||||
**`gstack-ship-preflight` no longer trusts a local `origin/HEAD` when origin can't say its default branch.** Preflight fell back to the local `origin/HEAD` whenever `git ls-remote --symref origin HEAD` failed or named no branch. With no local `origin/HEAD`, it went on from the default branch itself and merged the given base into it. When a PR-branch clone's `origin/HEAD` named the feature branch, it refused that branch as "on the base branch". Now a failed `ls-remote` stops with `git ls-remote origin HEAD failed: …; restore access first` before anything merges. A remote HEAD that names no branch (a detached HEAD, or a server that sends no symref) falls back to the shared default-base order in `lib/default-base.ts`, which uses the local `origin/HEAD` only when it doesn't name the checked-out branch, its upstream or HEAD's commit. The default-branch check now runs after the fetch, so a failed fetch still reports the fetch.
|
||||
|
||||
### Fixed
|
||||
- **`docs/eval-calls.md`, `docs/eval-models.md`**: the default `--base` now matches base resolution: origin/HEAD's branch unless it names the checked-out branch, its upstream or HEAD's commit, then the PR's base, the remote's live HEAD, `main` or `master`.
|
||||
|
||||
### Tests
|
||||
- `test/ship-preflight.test.ts`: with `ls-remote` failing and the fetch working, preflight stops before merging in two cases. One is the default branch with no local `origin/HEAD`, where main exited 0 and merged `release` into `main`. The other is a feature branch that the local `origin/HEAD` names, where main stopped as "on the base branch". When `ls-remote` prints only a sha, the default branch still stops as the base branch (main exited 0) and the feature branch goes on.
|
||||
|
||||
## [1.94.2.0] - 2026-11-03
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# gstack digest v1.94.2.0 — regenerate/re-copy after upgrading gstack
|
||||
# gstack digest v1.94.3.0 — regenerate/re-copy after upgrading gstack
|
||||
|
||||
Behavioral rules from gstack (https://github.com/garrytan/gstack), compressed
|
||||
for agent hosts without a full skill install. The full skills add workflows,
|
||||
|
||||
+3
-1
@@ -22,7 +22,9 @@ dropped), so a command with quotes or `$` never passes through a shell string;
|
||||
|
||||
1. `--plan-file <file>`: an operator-given file, read from disk.
|
||||
2. Otherwise `price_file` in `.gstack/pregate.json` as committed on
|
||||
`origin/<base>` (`--base`, default origin/HEAD's branch): a repo-relative
|
||||
`origin/<base>` (`--base`, default origin/HEAD's branch unless it names the
|
||||
checked-out branch, its upstream or HEAD's commit, then the PR's base, the
|
||||
remote's live HEAD, `main` or `master`): a repo-relative
|
||||
path whose bytes are read from the **HEAD commit** (`git show HEAD:<path>`),
|
||||
never from the working tree.
|
||||
|
||||
|
||||
+3
-1
@@ -66,7 +66,9 @@ unless the command says it is a smoke run.
|
||||
## Which copy is read
|
||||
|
||||
By default the reviewed copy is read: `git show origin/<base>:.gstack/eval-models.json`
|
||||
(`--base`, default origin/HEAD's branch). A branch cannot loosen the rules it
|
||||
(`--base`, default origin/HEAD's branch unless it names the checked-out branch,
|
||||
its upstream or HEAD's commit, then the PR's base, the remote's live HEAD, `main`
|
||||
or `master`). A branch cannot loosen the rules it
|
||||
is checked against. When the working-tree copy differs, an
|
||||
`EVAL_MODELS_NOTE:` line says so. `--models-from head` lints with the working-tree copy
|
||||
instead. Use it for the PR that adds or changes the file; the source label
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { defaultBaseBranch } from './default-base';
|
||||
import { classifyDiff } from './review-depth';
|
||||
import { audit } from './ship-audit';
|
||||
import { bin, carryNoneLine, firstLine, flagReader, gh, git, hostedOrigin, laneConcurrency, laneLine, lanes, Report, runLanes, shipPolicy, short } from './ship-bin-common';
|
||||
@@ -33,14 +34,16 @@ const DIST = /(^|\/)(cmd\/[^/]+\/main\.go|bin\/[^/]+|Cargo\.toml|setup\.py|packa
|
||||
|
||||
function integrate(cwd: string, base: string, r: Report): boolean {
|
||||
const branch = git(cwd, ['branch', '--show-current']).stdout.trim();
|
||||
const remote = /^ref: refs\/heads\/(\S+)\s+HEAD$/m.exec(git(cwd, ['ls-remote', '--symref', 'origin', 'HEAD'], 60_000).stdout)?.[1];
|
||||
const head = remote ?? git(cwd, ['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']).stdout.trim().replace(/^origin\//, '');
|
||||
r.add(`BRANCH: ${branch || '(detached)'} base=${base}`);
|
||||
if (!branch || branch === base || branch === head) { r.stop(`on the base branch (${branch || 'detached HEAD'}): ship from a feature branch`); return false; }
|
||||
if (!branch || branch === base) { r.stop(`on the base branch (${branch || 'detached HEAD'}): ship from a feature branch`); return false; }
|
||||
const status = git(cwd, ['status', '--porcelain']).stdout.split('\n').filter(Boolean);
|
||||
r.add(`STATUS: modified=${status.filter(l => !l.startsWith('??')).length} untracked=${status.filter(l => l.startsWith('??')).length} (uncommitted changes ship with this run)`);
|
||||
const fetch = git(cwd, ['fetch', 'origin', `+refs/heads/${base}:refs/remotes/origin/${base}`], 300_000);
|
||||
if (fetch.status !== 0) { r.stop(`git fetch origin ${base} failed: ${firstLine(fetch.stderr)}; restore access first`); return false; }
|
||||
const remoteHead = git(cwd, ['ls-remote', '--symref', 'origin', 'HEAD'], 60_000);
|
||||
if (remoteHead.status !== 0) { r.stop(`git ls-remote origin HEAD failed: ${firstLine(remoteHead.stderr)}; restore access first`); return false; }
|
||||
const head = /^ref: refs\/heads\/(\S+)\s+HEAD$/m.exec(remoteHead.stdout)?.[1] ?? defaultBaseBranch(cwd).branch;
|
||||
if (branch === head) { r.stop(`on the base branch (${branch}): ship from a feature branch`); return false; }
|
||||
const stat = git(cwd, ['diff', forkPoint(cwd, base), '--shortstat']).stdout.trim();
|
||||
const lines = [...stat.matchAll(/(\d+) (insertion|deletion)/g)].reduce((n, m) => n + Number(m[1]), 0);
|
||||
const commits = git(cwd, ['rev-list', '--count', `origin/${base}..HEAD`]).stdout.trim();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gstack",
|
||||
"version": "1.94.2",
|
||||
"version": "1.94.3",
|
||||
"description": "Garry's Stack — Claude Code skills + fast headless browser. One repo, one install, entire AI engineering workflow.",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
||||
@@ -57,6 +57,50 @@ describe('gstack-ship-preflight', () => {
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
|
||||
// Value: protects=a failed lookup of the remote's HEAD stops with "restore access first" instead of guessing the default branch from a local origin/HEAD;
|
||||
// fails_when=a failed ls-remote falls back to the local ref, so the default branch with no local origin/HEAD merges another base and goes on, and a feature
|
||||
// branch a Capy checkout's origin/HEAD names is refused as the base branch; why_new=GST-511 follow-up from #3718; seam=a git wrapper on PATH that fails
|
||||
// ls-remote only; no_claim=which access failure it was
|
||||
test('a failed remote HEAD lookup stops before merging, even when the fetch works', () => {
|
||||
const f = fx();
|
||||
fs.writeFileSync(path.join(f.root, 'stub', 'git'), `#!/bin/sh\n[ "$1" = ls-remote ] && { echo "ls-remote: unreachable" >&2; exit 128; }\nexec ${Bun.which('git')} "$@"\n`, { mode: 0o755 });
|
||||
f.git('push', '-q', 'origin', 'main:release');
|
||||
f.git('checkout', '-q', 'main');
|
||||
f.git('remote', 'set-head', 'origin', '-d');
|
||||
const onDefault = f.run(PREFLIGHT, ['--base', 'release']);
|
||||
f.git('checkout', '-q', 'feat');
|
||||
f.git('update-ref', 'refs/remotes/origin/feat', 'HEAD');
|
||||
f.git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/feat');
|
||||
const onFeature = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
for (const r of [onDefault, onFeature]) {
|
||||
expect(r.status).toBe(3);
|
||||
expect(r.stdout).toContain('STOP: git ls-remote origin HEAD failed: ls-remote: unreachable; restore access first');
|
||||
expect(r.stdout).not.toContain('MERGE:');
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=a remote whose HEAD names no branch (detached, or a server that sends no symref) falls back to the default-base ladder, not the local origin/HEAD;
|
||||
// fails_when=the fallback reads the local ref, so the default branch with no local origin/HEAD merges another base and goes on, and a feature branch a
|
||||
// Capy checkout's origin/HEAD names is refused as the base branch; why_new=pass-1 review of the ls-remote stop; seam=a git wrapper whose ls-remote prints
|
||||
// only a sha; no_claim=a repository whose default is neither main nor master
|
||||
test('with no symbolic remote HEAD, the default branch still stops and a feature branch named by a local origin/HEAD goes on', () => {
|
||||
const f = fx();
|
||||
fs.writeFileSync(path.join(f.root, 'stub', 'git'), `#!/bin/sh\n[ "$1" = ls-remote ] && { echo "0000000000000000000000000000000000000000\tHEAD"; exit 0; }\nexec ${Bun.which('git')} "$@"\n`, { mode: 0o755 });
|
||||
f.git('push', '-q', 'origin', 'main:release');
|
||||
f.git('checkout', '-q', 'main');
|
||||
f.git('remote', 'set-head', 'origin', '-d');
|
||||
const onDefault = f.run(PREFLIGHT, ['--base', 'release']);
|
||||
expect(onDefault.status).toBe(3);
|
||||
expect(onDefault.stdout).toContain('STOP: on the base branch (main)');
|
||||
expect(onDefault.stdout).not.toContain('MERGE:');
|
||||
f.git('checkout', '-q', 'feat');
|
||||
f.git('update-ref', 'refs/remotes/origin/feat', 'HEAD');
|
||||
f.git('symbolic-ref', 'refs/remotes/origin/HEAD', 'refs/remotes/origin/feat');
|
||||
const onFeature = f.run(PREFLIGHT, ['--base', 'main']);
|
||||
expect(onFeature.stdout).not.toContain('STOP: on the base branch');
|
||||
expect(onFeature.status).toBe(0);
|
||||
});
|
||||
|
||||
// Value: protects=Step 3 merges the base and a conflict stops with the files named, leaving the merge for the agent to resolve; fails_when=the bin resolves a conflict itself, aborts the merge, or continues to tests;
|
||||
// why_new=moved from the Step 3 prose; seam=git merge; no_claim=which side is right
|
||||
test('a merged base is reported; a conflict stops with the conflicted files and the merge left in place', () => {
|
||||
|
||||
Reference in new issue
Block a user