Skip to content

fix(pr-shots): resolve the real base for before-images (#3733) - #4141

Closed
szsunyuan wants to merge 3 commits into
garrytan:mainfrom
szsunyuan:fix/3733-pr-shots-default-base
Closed

szsunyuan wants to merge 3 commits into
garrytan:mainfrom
szsunyuan:fix/3733-pr-shots-default-base

Conversation

@szsunyuan

@szsunyuan szsunyuan commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Why (in your own words)

A clone whose local origin/HEAD names the pushed feature branch makes gstack-pr-shots --path read that feature head as its own before-image. Committed PR changes then disappear from the comparison: with no extra uncommitted edit, both sides are identical and generation refuses with PR_SHOTS_IDENTICAL.

Use the real resolved base branch and its merge base with HEAD, so the comparison includes the committed PR changes.

Fixes #3733. The shared default-base work from #3718/#3795 landed earlier, but #3718 explicitly deferred this pr-shots consumer. This does not duplicate that completed resolver work.

Validation status: full free CI passed on the final head daa6a2400 (29 checks passed, 14 skipped; Free Tests run). 96 focused checks also pass locally, including the push-guard test that failed CI on the intermediate commit d883966ec (explained below). The selected paid lane remains pending: fork PRs skip the eval jobs, and skipped jobs are not passes. One local real-browser case was filtered out because of the host's sandbox restriction; it receives no pass credit.

Why this shape

The existing gate-diff/git helpers already implement the common default-base policy, remote-tracking precedence and merge-base calculation. Reusing them removes the separate raw origin/HEAD loop without introducing another resolver or a production test seam.

The shared selector deliberately keeps naming a stale remote HEAD (a missing branch, or history HEAD does not share), so the gates refuse instead of guessing a base; test/ship-release.test.ts pins that for the push guard. pr-shots only renders a before/after image, so when the shared default is unusable it falls back to main as its old loop did, then master. That fallback lives in lib/pr-shots.ts, not in the shared resolver.

CONTRIBUTING's wave process prefers the smaller change when two PRs solve the same thing. This is four files: one pr-shots production fix, existing-owner regressions, a CLI help correction and a changelog fragment. Fine to absorb into a wave.

What it does

  • Resolves the real base when local origin/HEAD incorrectly points at the feature branch, including a non-main default.
  • Keeps the branch fork point rather than using the base's latest tip.
  • Prefers the remote-tracking base over a stale local branch.
  • Falls back to main (as pr-shots did before), then master, when local origin/HEAD names a missing branch or unrelated history.
  • Preserves explicit --base, local-only repository behavior and structured missing-base refusal.
  • Adds nine Git-fixture cases to existing test/pr-shots.test.ts, not a new standalone test file.
  • Updates the CLI help to describe the resolved-base default.

What it deliberately does not do

  • No browser selection, rendering, layout, installation or sandbox changes. No captured file content is executed.
  • No new public exports, flags, dependencies or generated files.
  • No change to the shared lib/default-base.ts resolver, so the gates keep refusing a stale origin/HEAD. No new remote writes, fetch/merge policy or competing base resolver. The existing resolver's bounded PR-base/remote-HEAD metadata reads remain its own behavior.
  • No VERSION, package-version, released CHANGELOG.md, README or ETHOS edits. Release documentation is one entry-text-only branch fragment.
  • No /ship workflow changes or manual release stamp; the repository's merge/release process assigns the version.

Live evidence

Bun 1.4.2 on Linux. The reproductions use existing local Git-fixture helpers, a local bare origin and the real defaultBase, pathSides and buildPage functions. The remote's real default remains main; only the working clone's local origin/HEAD is changed. No browser, live model or GitHub service is needed by the fixtures.

Feature-branch origin/HEAD (the reported bug)

Before the production edit, the diagnostic fixture printed:

REMOTE DEFAULT ref: refs/heads/main HEAD
MISPOINTED LOCAL origin/HEAD:
  isFeatureHead=true
  isRealBase=false
  before="feature\n"
  after="feature\n"
  result=PR_SHOTS_IDENTICAL

CONTROL origin/HEAD=main:
  isFeatureHead=false
  isRealBase=true
  before="before\n"
  after="feature\n"
  result=comparison generated

Those fields are the recorded fixture result with ephemeral SHAs omitted. The original production module was unchanged between the initial base and refreshed 5f9b7ef20.

The new owner-test cases also failed before the production edit:

$ bun --no-env-file --no-load-bunfig test test/pr-shots.test.ts --test-name-pattern 'default base'
...
(fail) default base > a local origin/HEAD naming feature still compares against main [231.79ms]
...
(fail) default base > a local origin/HEAD naming feature still compares against develop [213.19ms]
...
(fail) default base > a moved remote base still compares from the branch fork point, not its tip [265.56ms]
...
(fail) default base > a self-referential remote HEAD with no resolvable base does not fall back to itself [267.19ms]

 3 pass
 11 filtered out
 4 fail
 16 expect() calls
Ran 7 tests across 1 file. [1445.00ms]

After the fix, the same mispointed-HEAD production-function scenario returned:

{
  "localRemoteHead": "origin/feature",
  "choseRealBase": true,
  "choseFeatureHead": false,
  "before": "before\n",
  "after": "feature\n",
  "result": "comparison generated"
}

The branch was then fast-forwarded to current main at 5f9b7ef20, with the patch verified byte-identical before and after the refresh.

Stale origin/HEAD (found in review)

Review of the first commit found a second case: when local origin/HEAD names a missing branch or unrelated history, the shared selector still names it, so pr-shots refused where its old loop fell back to origin/main. The two new cases failed before the fallback:

$ bun --no-env-file --no-load-bunfig test test/pr-shots.test.ts --test-name-pattern 'an unusable origin/HEAD' --timeout=30000
...
Received: {
  code: "PR_SHOTS_INPUT_NOT_FOUND",
  message: "no merge base with the resolved base branch; pass --base <ref>",
}
...
(fail) default base > an unusable origin/HEAD (dangling) falls back to main [239.65ms]
...
(fail) default base > an unusable origin/HEAD (unrelated) falls back to main [223.56ms]

 0 pass
 18 filtered out
 2 fail
 4 expect() calls
Ran 2 tests across 1 file. [553.00ms]

The first attempt at that fix, d883966ec, changed the shared resolver instead. CI caught that the push guard relies on the resolver to refuse a dangling origin/HEAD; the same failure reproduces locally:

$ bun --no-env-file --no-load-bunfig test test/ship-release.test.ts --timeout=30000 --test-name-pattern 'a base that exists on origin but is not fetched'
...
Expected substring or pattern: /^GUARDS: refused /
Received: "GUARDS: fail (regen no registry (origin/main@9565de98536f (no .gstack/generated.json)); guards 1 guard(s) failed: housekeeping)"
...
(fail) push: the pre-push housekeeping guards (GST-1138) > a base that exists on origin but is not fetched, a mistyped --base, a dangling origin/HEAD and an unreadable policy stop the push [2671.80ms]

daa6a2400 restores lib/default-base.ts byte-for-byte and keeps the fallback in pr-shots. The whole push-guard file passes again:

$ bun --no-env-file --no-load-bunfig test test/ship-release.test.ts --timeout=30000

 23 pass
 0 fail
 200 expect() calls
Ran 23 tests across 1 file. [70.03s]

Scope

  • Changed: four files, +142/-11 against main at 5f9b7ef20: lib/pr-shots.ts, test/pr-shots.test.ts, the existing CLI's help line, and changelog.d/fix-3733-pr-shots-default-base.md. No VERSION, released CHANGELOG or generated-file changes. Three commits: the second (d883966ec) fails the push-guard test on its own, and the third reverts its shared-resolver change, so the series is meant to be squashed.
  • Verified live by: the failed-before/working-after runs above; full free CI on daa6a2400 (29 passed, 14 skipped); 96 focused tests on the final head; strict product typecheck; test-type ratchet (812 known diagnostics, none new); CLI help; changelog prose lint; git diff --check; exact staged-diff redaction scans with zero findings.
  • Did NOT test: the full free suite locally (it passed in CI), the selected paid lane, native Windows/macOS execution, or a full /ship review/verification run. The one filtered real-browser capture case was not run locally. No browser sandbox override or global tool change was used.

Focused checks on the final head, under Bun 1.4.2 with umask 022, LC_ALL=C and isolated HOME, GSTACK_HOME and TMPDIR:

Check Pass Filtered Fail
pr-shots owner cases: base selection, comparison, browser-free CLI 19 1 0
test/ship-release.test.ts, including the dangling-origin/HEAD push-guard refusal 23 0 0
Shared resolver and gate-diff CLI: test/default-base.test.ts, test/gate-diff-cli.test.ts 38 0 0
Test-layout, subprocess-timeout and egress-wiring guards 16 0 0
Total 96 1 0

The commands were:

bun --no-env-file --no-load-bunfig test test/pr-shots.test.ts --timeout=30000 --test-name-pattern 'default base|diff and hunks|path mode|working-tree fingerprint|secret in a capture|outside the repository'
bun --no-env-file --no-load-bunfig test test/ship-release.test.ts --timeout=30000
bun --no-env-file --no-load-bunfig test test/default-base.test.ts test/gate-diff-cli.test.ts --timeout=30000
bun --no-env-file --no-load-bunfig test test/test-of-test-ratchet.test.ts test/spawnsync-timeout-tripwire.test.ts test/egress-receipt-wiring.test.ts --timeout=30000

The paid selector is intentionally reported, not reduced: the shared pr-shots references reach 252 registered cases. For this four-file diff, the PR profile selects 108 paid behaviors, no dedicated quality judges, and defers 144 broad behaviors to scheduled/release coverage. None of those unrun cases receives pass credit.

Liveness proof (required for external contributors)

image

Checklist

Test plan

  • Reproduce the wrong before-image and PR_SHOTS_IDENTICAL with a committed/pushed feature change.
  • Show the new cases fail before the fix, then pass after it.
  • Cover main/develop defaults, normal-head and explicit-base controls, a moved base, stale local base, local-only fallback and unresolved self-reference.
  • Cover a dangling or unrelated origin/HEAD falling back to main, with the shared resolver unchanged so the push guard still refuses that case.
  • Refresh to current main at 5f9b7ef20 while preserving the patch byte-for-byte.
  • Rerun focused checks on the final head: 96 pass, 1 filtered, 0 fail.
  • Run product typecheck and the test-type debt ratchet.
  • Check CLI help, changelog prose, whitespace and outgoing-diff redaction.
  • Complete full free acceptance on this PR's head (CI on daa6a2400: 29 passed, 14 skipped).
  • Complete required selected paid coverage or record maintainer-run fork-PR coverage.
  • Complete remaining shipping reviews/verification before merging.

Fork PRs do not receive upstream eval secrets. Skipped paid CI jobs are not passes; a maintainer must run the required paid coverage on an upstream branch before merge. Broad-profile deferrals remain scheduled/release coverage, not PR passes.

Fixes #3733.

A local origin/HEAD naming the pushed feature branch makes both sides
read from that head, hiding committed changes as PR_SHOTS_IDENTICAL.
Reuse the shared default-base, ref-resolution and merge-base helpers
instead of maintaining a separate origin/HEAD fallback loop.

Cover main and non-main defaults, moved bases, stale local branches,
local-only repositories and unresolved self-referential defaults in the
existing owner suite. Preserve explicit --base and update the CLI help.

Fixes: garrytan#3733

Co-Authored-By: Claude Code <[email protected]>
@trunk-io

trunk-io Bot commented Nov 7, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

szsunyuan and others added 2 commits November 7, 2026 22:51
Keep missing or unrelated remote HEAD targets from preventing the shared
default-base resolver from reaching a usable fallback. Cover both cases
with existing-owner pr-shots regressions.

Co-Authored-By: Claude Code <[email protected]>
d883966 made lib/default-base.ts skip a dangling or unrelated remote
HEAD. The push guard relies on the shared selector naming that ref so it
refuses, and test/ship-release.test.ts caught it guessing origin/main
instead. Restore the shared resolver and fall back to main, then master,
only in pr-shots' defaultBase.

Co-Authored-By: Claude Code <[email protected]>
@capy-ai

capy-ai Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for picking up #3733. This is on the crew's pick-up list: a crew lane will rebuild it on current main and credit you as co-author when it lands, then close this PR.

@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you for this. We're picking up the idea. A maintainer agent working through a batch of fixes (our tracking thread GSTA-802) will first reproduce the problem on current main. If it reproduces, the agent rebuilds the fix on main with you credited as co-author, because we don't merge outside branches directly, and we'll close this PR with a link when it lands. If it no longer reproduces, we'll close this and say what changed.

@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you, @szsunyuan. This was rebuilt on current main and landed in #4681 (merged as b3323f4), with credit in the changelog. gstack-pr-shots now uses the shared default-base resolver when origin/HEAD names the feature branch (#3733). We rebuild outside changes rather than merging the branch directly, so I'm closing this one.

@capy-ai capy-ai Bot closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deferred review finding: lib/pr-shots.ts:67 — pr-shots still takes origin/HEAD first, so in a GST-511 clone its before i

1 participant