Skip to content

fix(harness): judge the whole content on a first push in the review, comments and contract gates - #183

Open
cljiahao wants to merge 16 commits into
mainfrom
claude/no-base-first-push-gates-b46940
Open

cljiahao wants to merge 16 commits into
mainfrom
claude/no-base-first-push-gates-b46940

Conversation

@cljiahao

@cljiahao cljiahao commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Summary

On the first push of a scaffolded project to a new empty remote there is no origin/main. Three seeded gates then failed or judged nothing:

  • record-review.sh --prepare exited 1 with "no base ref found" and "cannot compute the diff hash". The fix text did not name TC_REVIEW_BASE.
  • check-comments.sh reported "nothing checked" and exited 0.
  • check-contract.sh skipped its changed-generator rule and exited 0.

The fix reuses the ratchet's first-push decision. check-review-record.sh gains a first_push() test, exposed as the mode --first-push (exit 0 first push, 1 a base exists, 2 a base may exist but is not here). On a genuine first push:

  • the review gate diffs the empty tree to HEAD and records base=empty-tree;
  • check-comments.sh uses the empty tree as the merge base, so every tracked and untracked source file is judged as new;
  • check-contract.sh prints a first-push note instead of silently skipping.

A second push, which has a base, behaves as before and needs a new review. One seeded-doc paragraph in harness.md describes the route. Changelog fragment: changelog.d/no-base-review-diff-gates.fixed.md. gate-ratchet.sh and check-change-size.sh are not touched.

Threat model

  • Asset: the review, comments and contract gates must judge real content, never nothing.
  • Bypass 1, hand-set base: an attacker or a careless user sets a base (TC_REVIEW_BASE, BASE_REF) that empties the diff so a first push passes unchecked.
  • Bypass 2, forged first push: a base exists, but the gate is made to believe it does not (deleted remote-tracking ref, shallow clone, upstream still configured), so the gate falls into the lenient first-push route.
  • Bypass 3, lingering override: an override or the empty-tree token set once lets a later push skip the check.
  • Bypass 4, CI route: CI takes the lenient local route.
  • Out of scope: a forged first commit that cannot be told from a pristine scaffold, which the ratchet already documents as a human-read push.

The gates fail closed: whenever a base may exist and cannot be read, they exit 2.

Allow-list design

The first-push route is allowed only when all of these hold; anything else keeps the old behaviour (exit 2 or the existing message):

  • no @{upstream}, origin/HEAD, origin/main or origin/master candidate resolves;
  • there are no remote-tracking refs at all;
  • the repository is not shallow;
  • no upstream is configured for the branch;
  • the run is not CI.

The same conditions the ratchet uses, kept in one function. The token empty-tree is reserved: an explicit TC_REVIEW_BASE=empty-tree is refused, and write_diff accepts that base only while first_push still holds. BASE_REF from the environment is refused on a first push in check-comments.sh. With no base named and not a first push, check-contract.sh exits 2. An explicit base argument or GATE_BASE keeps the documented local skip.

Probe list

Per gate (review, comments, contract):

  • control with a base present: the old behaviour is unchanged;
  • first push, clean content: passes and says it judged the whole content;
  • first push, refused content: refused;
  • remote-tracking ref deleted after a first push, upstream still configured: not a first push, exit 2;
  • a remote-tracking ref that is not the base, or a shallow clone: not a first push;
  • override at HEAD: the review owes nothing for that push and leaves no passing record;
  • hand-set empty-tree and BASE_REF on a first push: refused;
  • CI never takes the empty-tree route (review gate, CI mode).

Revert proof: with the three seeded scripts restored to HEAD and the new tests kept, the new probes fail (review gate 7, contract 3, comments 6 failures).

Tests run

  • scripts/seeded-review-gate.test.sh: 456 passed, 0 failed.
  • scripts/seeded-comments.test.sh: 1033 passed, 0 failed.
  • scripts/seeded-contract.test.sh: 95 passed, 0 failed.
  • bash scripts/lint-skills.sh skills/: all checks passed.
  • shellcheck on scripts/*.sh and the three seeded scripts: clean.
  • scripts/run-gates.sh --check: map matches (92 commands).
  • scripts/check-template-comments.sh: ok (327 files).
  • python3 scripts/check-fences.py --root .: 571 fences OK.
  • scripts/regen-golden.sh --write, then scripts/check-golden.sh: 8/8 combos OK, also after merging origin/main.

Not verified

  • The Python-stack repro: step 1 was reproduced on a TypeScript scaffold only. The test fixtures cover both languages, but no Python scaffold was run end to end.
  • The timing of whole-content check-comments.sh on a real scaffold: not measured against the pre-push budget.

🤖 Generated with Claude Code

Kelerence and others added 16 commits December 1, 2026 21:19
…comments and contract gates

With no origin/main, record-review --prepare exited 1/2 on a missing base, and check-comments and
check-contract judged nothing or failed. On a genuine first push (same conditions as the ratchet's
first-push route) they now diff against the empty tree. A base that may exist but cannot be read
still exits 2; the fix text names TC_REVIEW_BASE. Overrides cannot skip a later push.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ing by exact path and hash, and resolve bases by refs/remotes

On a first push the review, comments and contract gates judged every file,
so a FastAPI scaffold failed on the seeded .mjs helpers and the review diff
was the whole tree. A file is now left out only when its exact path and
sha256 equal a row of a generated per-stack table held in the hash-pinned
gate-ratchet.sh. Every other file is judged. All gates resolve origin/main
and origin/master as refs/remotes/..., so a local branch of that name is
not a base. No-base messages name the supported way to set the base.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…push-gates-b46940

# Conflicts:
#	tests/golden/fastapi-azure.sha256
#	tests/golden/fastapi-github.sha256
#	tests/golden/nestjs-azure.sha256
#	tests/golden/nestjs-github.sha256
#	tests/golden/nextjs-azure.sha256
#	tests/golden/nextjs-github.sha256
#	tests/golden/vite-react-azure.sha256
#	tests/golden/vite-react-github.sha256
…tchet, baseline and comments gates and probe tag bases

A tag named origin/main on HEAD won over the remote-tracking ref, so the
change-size budget measured zero lines. The default and argument bases now map
origin/main and origin/master to refs/remotes/... in change-size, ratchet,
baseline growth and comments. Tag-base probes cover the review, comments,
contract, mutation-diff and change-size gates, plus symlink-at-seeded-path
cases and a four-stack real-scaffold first-push loop. The harness doc states
the residual that the table rests on the manifest hash.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…push-gates-b46940

# Conflicts:
#	tests/golden/fastapi-azure.sha256
#	tests/golden/fastapi-github.sha256
#	tests/golden/nestjs-azure.sha256
#	tests/golden/nestjs-github.sha256
#	tests/golden/nextjs-azure.sha256
#	tests/golden/nextjs-github.sha256
#	tests/golden/vite-react-azure.sha256
#	tests/golden/vite-react-github.sha256
…ts and CI gates

check-workarounds no longer takes a local main or master as its base and maps an explicit origin/main argument to refs/remotes; check-comments drops its local fallback; check-shared-gates, ci-gates.sh and the seeded CI files qualify the base as refs/remotes. check-review-record --seeded-paths reads the stack from harness.json at HEAD. The seeded file table stores paths with a bar for the slash so the guard scan does not take a seeded rules file for a gate file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…push-gates-b46940

# Conflicts:
#	skills/scaffold/shared/template/scripts/gate-ratchet.sh
#	tests/golden/fastapi-azure.sha256
#	tests/golden/fastapi-github.sha256
#	tests/golden/nestjs-azure.sha256
#	tests/golden/nestjs-github.sha256
#	tests/golden/nextjs-azure.sha256
#	tests/golden/nextjs-github.sha256
#	tests/golden/vite-react-azure.sha256
#	tests/golden/vite-react-github.sha256
…he workarounds, comments and review gates

A base now counts only when it resolves as a fully qualified refs/remotes/origin/<branch> ref. Every origin/<branch> input maps to that ref, so a tag or local branch of the same name cannot stand in for it. check-comments.sh no longer trusts BASE_REF outside CI and refuses an argument base that is a local branch, tag, HEAD or sha. check-workarounds.sh takes @{upstream} only when it is a remote-tracking ref. check-comments.sh skips a remote-tracking candidate that stands at HEAD and judges the whole content when all do. ci-gates.sh passes the full ref. Tests cover each case with a clean control.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…push-gates-b46940

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… the pushed commit, and take a bare sha only from the pre-push route

Outside CI, check-comments.sh now judges the whole content when a base given by argument or BASE_REF stands at HEAD, so a remote-tracking ref written at HEAD cannot empty the diff. check-workarounds.sh does the same for an explicit origin/<branch> base at the pushed commit, and takes a bare sha base only from its own --pre-push child call (marked with the parent process id). Tests cover each case with a clean control, and the changelog states what is still not caught.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…emote base, and the awk-count check uses check

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… ref

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

2 participants