aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
GitHub aien-dev/aien-architecture-mv#201 (code only)
Apply it
git checkout -b patch-3b056bdcd0178639 b2400fec3fd360ed11fda775e4018c22167e0c2f curl -fsSL https://interplane.io/drakestapleton/aien-architecture-mv/patches/3b056bdcd0178639.patch | git am
Provenance
github-import 1
aien-dev/aien-architecture-mv
201
2d206cbd3769b48e01005391414deaa05462ef41
{"kind":"github-import","owner":"aien-dev","repo":"aien-architecture-mv","number":201,"url":"https://github.com/aien-dev/aien-architecture-mv/pull/201","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:55Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index d854ce8..fafbbfb 100644 --- a/.crumb +++ b/.crumb @@ -21,8 +21,8 @@ "generated": { "children": [ { - "digest": "40d778cb00ec60253084751365e4660cd147804daf36fda8ac23d4363f5fa05e", - "last_commit": "0d4c608", + "digest": "bccfc765e0a32a2e4a31cc84d1b5fad1047ac129def178f543c208afb9e7b3a9", + "last_commit": "cfe1c22", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -33,8 +33,8 @@ "purpose": "Directory doctrine. Purpose not yet described by a human." }, { - "digest": "c34f88bb1ba323a3712efd9fd12cbefa5d0b8d92b3ea66375c5b0b916cfdebd7", - "last_commit": "4478c1a", + "digest": "8bb604d86df1aa3f433600354b036dab1734d921530cf48147886a6ebeeabca9", + "last_commit": "78a7014", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." }, @@ -45,15 +45,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:d5b710c190d0e1e5376811ce19509ec003fffb3a1855ae2d68c0b6b784df8b13", - "compiled_at": "2026-10-10T14:28:20Z", + "children_root": "sha256:770180f54121cb55bfbc154efd4eb2cc2fca53dd7dd8fc43911a64c930f384b3", + "compiled_at": "2026-10-10T15:59:58Z", "compiler": "crumb-compile/1", - "digest": "sha256:ef7a691b54e9143c64bc8b762a5edd42fe7d806290fb828dbc9f015b7342ad8f", + "digest": "sha256:1c66ac3d3cce9f995c4eb047efa11f56f126d9eb4fb48b0735b1ff5b29e1ec6f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 255, - "generated_at_commit": "0d4c60879e1694595020d13678f804e30cd316d8", - "source_tree": "sha256:3cd181f0e99b5b2a267e2ecdaa6ec356358938d2470c116fe1e4c74a45bba43f" + "files": 260, + "generated_at_commit": "78a7014095431bb50d5e718ab0035a2891e89513", + "source_tree": "sha256:31728b54e286db11569f4cc953d87ede8b3fef5e70827dac790150ff08c99177" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 241cf05..0a230cd 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -38,7 +38,7 @@ "children": [ { "digest": "0f5f051b567320ca492dc91af59fd67460e76e96d0a56efbdf33c093d84e96d6", - "last_commit": "0d4c608", + "last_commit": "b2400fe", "name": "adr", "purpose": "Directory docs/adr. Purpose not yet described by a human." }, @@ -56,7 +56,7 @@ }, { "digest": "476ca8e3cf8257376bcf010981a621b3c129f0724014ce4a443ed0d27efc8f27", - "last_commit": "0d4c608", + "last_commit": "b2400fe", "name": "plans", "purpose": "Directory docs/plans. Purpose not yet described by a human." }, @@ -74,14 +74,14 @@ } ], "children_root": "sha256:7c342e6d7fe441f2ac93916c1a65c61a275d8ebc576d614364cc6c4fa05b03a7", - "compiled_at": "2026-10-10T14:28:20Z", + "compiled_at": "2026-10-10T15:59:58Z", "compiler": "crumb-compile/1", - "digest": "sha256:40d778cb00ec60253084751365e4660cd147804daf36fda8ac23d4363f5fa05e", + "digest": "sha256:bccfc765e0a32a2e4a31cc84d1b5fad1047ac129def178f543c208afb9e7b3a9", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 147, - "generated_at_commit": "0d4c60879e1694595020d13678f804e30cd316d8", - "source_tree": "sha256:c34cc507b049d0284a619d9472e5445f5d99c9d290c71e23813f32bc3bde7dc6" + "files": 148, + "generated_at_commit": "78a7014095431bb50d5e718ab0035a2891e89513", + "source_tree": "sha256:68b8a49fc6c1846bdc726e3b8d56c4c4ff75d4abb5153ed3f351ca3fccad9c0d" }, "owner_lane": "", "provenance": { diff --git a/docs/REPOSITORY_EXECUTION_RULES.md b/docs/REPOSITORY_EXECUTION_RULES.md new file mode 100644 index 0000000..a9736fe --- /dev/null +++ b/docs/REPOSITORY_EXECUTION_RULES.md @@ -0,0 +1,197 @@ +# AIEN Repository Execution Rules + +## Adoption + +Adopted 2026-10-10 from Drake's revised rules for the six-issue campaign (interplane#97 and #98, aien-sovereign-core#397 and #398, aegis-runtime#38 and #39). Tooling: `scripts/pr-gate.sh` and `scripts/rebase-crumb.sh`. + +## Recorded facts (2026-10-10) + +- (a) Branch protection read from GitHub: interplane requires the checks schemas-and-fixtures, rust, python, cross-language, adapter-aien and adapter-odysseus, in strict mode, with no review count. aien-sovereign-core requires the check "Workspace Verification & Invariant Audit", 0 reviews, enforce_admins on. aegis-runtime requires the check "Test & Invariant Verification", 0 reviews, enforce_admins on. Therefore `--admin` is never needed for a green PR. +- (b) interplane has no .crumb files, so the crumb step is skipped there with a notice. aegis-runtime and aien-sovereign-core use crumbs. +- (c) INTERPLANE carries a Python SDK by Drake's 2026-10-04 direction (approved exception). The Motus adapter for interplane#97 lives only under interplane adapters/motus. No Python enters any AIEN-owned repository. + + +These rules apply to Claude Code, all delegated workers, and all repositories involved in this implementation campaign. + +The objective is to ship verified code without corrupting shared branches, bypassing security requirements, or creating unnecessary integration conflicts. + +## 1. Source of Truth + +GitHub main is authoritative. Inspect current code, tests, active PRs, and repository instructions before editing. + +Never implement an issue solely from its description. Check whether the functionality already exists or has been superseded. + +Use separate branches and worktrees for concurrent development. + +One worker owns each writable worktree. Never allow two workers to modify the same worktree concurrently. + +## 2. Crumb Compilation + +Every applicable PR must have `.crumb` compilation and verification completed after its final source change. + +Required commands: `crumb compile .` then `crumb verify .` + +Commit generated `.crumb` changes separately as the final commit. + +Do not modify source files after that commit without rerunning compilation and verification. + +If a repository does not support these commands, report the discrepancy and follow its explicit repository policy. Never silently skip a required check. + +## 3. Rebase and Crumb Conflicts + +Every sovereign-core merge to main can invalidate `.crumb` files in other open PRs. + +After each sovereign-core merge, evaluate remaining PRs for drift. + +Approved recovery script: `scripts/rebase-crumb.sh <worktree> <branch>` (this repository). + +Before running it: + +- Confirm the worktree has no uncommitted changes. +- Confirm the intended branch and remote. +- Inspect the script before first use. +- Preserve the expected remote head for force-with-lease protection. +- Ensure no other worker is writing to that branch. + +The script takes main's `.crumb`, recompiles crumbs as the last commit, and pushes with lease. + +If it reports CODE CONFLICT, stop automated rebasing for that branch. Resolve the source conflict before recompiling. + +Never discard source changes to manufacture a clean rebase. + +Do not rewrite another worker's branch without coordination. + +## 4. Definition of CLEAN + +A PR may merge only when all of the following hold: + +- Working tree is clean. +- Changes are based on the intended current main. +- No unresolved merge conflicts. +- Required compilation and crumb verification pass. +- Required tests and CI checks pass. +- Required approvals are present and valid. +- GitHub reports a mergeable state. +- No outstanding blocking security findings. +- The final diff contains no unintended changes. +- The implementation satisfies the linked issue's acceptance criteria. + +Do not equate GitHub's CLEAN merge-state label with complete verification. + +## 5. Merge Procedure + +Serialize merges into each repository's main branch. + +Default command: `gh pr merge N -R aien-dev/<repo> --squash --delete-branch` + +Only use `--admin` when explicitly authorized for that specific PR and when the required project governance permits it. + +Never use administrative privileges to hide failing tests, missing approvals, security findings, or unresolved conflicts. + +After every merge, refresh main and revalidate dependent or competing PRs. + +## 6. GitHub PR Editing + +The normal `gh pr edit` workflow is currently unreliable in this environment. + +Use the API fallback: `gh api -X PATCH repos/aien-dev/<repo>/pulls/N -F body=@file` + +Verify the returned response and fetch the PR afterward to confirm the update. + +Do not assume an API operation succeeded merely because the command exited. + +## 7. Language and Runtime Constraints + +No Python or systemd may be introduced as part of this campaign. + +Use Rust for AIEN-owned runtime, orchestration, adapters, and execution control. + +Motus may run externally using its own dependencies, but the AIEN integration must communicate over an explicitly verified protocol boundary. + +If a task requires Python inside an AIEN-owned repository, treat it as an architectural conflict. Redesign it or report the blocker before proceeding. + +Existing Python files do not authorize adding more Python. Flag any conflict with the strict repository policy rather than silently ignoring it. + +## 8. Command Hooks + +A local Bash hook rejects certain command text containing accelerator or kernel-module related terms. + +Do not embed source-file contents containing these terms into Bash commands or heredocs. Use the approved Write tool for file creation and editing. + +Do not attempt to bypass restrictions on executing prohibited operations. + +If an approved development command is incorrectly blocked, report the exact failure and use an authorized alternative. + +## 9. Commits and Attribution + +Use small, logically isolated commits. + +Required commit trailers, when attribution accurately reflects the contributors: + +`Co-authored-by: Drake Stapleton <drake@aienos.com>` +`Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>` + +Do not invent contributors or misrepresent authorship. + +Required PR footer: 🤖 Generated with [Claude Code](https://claude.com/claude-code) + +Every PR must reference its issue, describe its implementation, identify verification performed, and disclose limitations. + +## 10. Worker Models and Verification + +Use Sonnet for delegated implementation workers unless instructed otherwise. + +Workers may inspect, implement, test, and propose solutions within their assigned ownership boundaries. + +A worker's claim of completion is not verification. + +The coordinating agent must independently inspect every worker's changes and verify relevant tests, security invariants, and actual GitHub state. + +Do not accept unsupported claims about test passes, hardware performance, successful merges, or completed integrations. + +Use an independent reviewer for security-sensitive changes. + +## 11. Failure Handling + +Do not repeatedly retry the same failing operation without identifying the cause. + +On failure: + +1. Capture the exact failure and affected commit. +2. Determine whether it is source-related, environmental, or caused by concurrent changes. +3. Apply the smallest justified correction. +4. Rerun the affected verification. +5. Escalate or isolate persistent blockers without destroying valid work. + +Never force-push another worker's changes away. + +Never turn off tests, security checks, or authorization rules merely to make a PR merge. + +## 12. Communication + +Use plain English when reporting to Drake. Do not use em dashes or en dashes. + +Provide concise updates that identify completed work, active work, blockers, and next actions. + +Do not confuse attempted operations with completed operations. + +## 13. Final Delivery + +Before declaring the campaign complete: + +- Verify every merged PR against its issue. +- Check relevant cross-repository interfaces. +- Run integration tests. +- Confirm no unintended dependency or architecture changes. +- Report remaining failed, skipped, or unavailable verification. +- Confirm final GitHub issue and PR status. + +A task is complete only when the implementation, verification, and required integration are finished. + +## 14. Worker Instructions + +Worker briefs live with each campaign; this document wins when they conflict. + +Stable rules and validated scripts live in aien-architecture (`docs/REPOSITORY_EXECUTION_RULES.md`, `scripts/pr-gate.sh`, `scripts/rebase-crumb.sh`). + +**Operating principle: Ship correct, verified code. Preserve other workers' changes. Protect main. Never trade correctness for apparent progress.** diff --git a/scripts/.crumb b/scripts/.crumb index 2ee4a9c..082d16d 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-06T20:50:34Z", + "compiled_at": "2026-10-10T15:59:58Z", "compiler": "crumb-compile/1", - "digest": "sha256:c34f88bb1ba323a3712efd9fd12cbefa5d0b8d92b3ea66375c5b0b916cfdebd7", + "digest": "sha256:8bb604d86df1aa3f433600354b036dab1734d921530cf48147886a6ebeeabca9", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 7, - "generated_at_commit": "abda85392f829daeefd57b126eac299df8397325", - "source_tree": "sha256:ad70f421e2dca07f97cdf023e1b747fd0c3871f861f7ed206556222e4c1183b5" + "files": 11, + "generated_at_commit": "78a7014095431bb50d5e718ab0035a2891e89513", + "source_tree": "sha256:fc28f00940d1199ab2b6a930b0a59905bf4e9729b636d1ec11c1e333ceb858a2" }, "owner_lane": "", "provenance": { diff --git a/scripts/pr-gate.sh b/scripts/pr-gate.sh new file mode 100755 index 0000000..db43afe --- /dev/null +++ b/scripts/pr-gate.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env bash +# PR merge gate for aien-dev repositories. Reads GitHub state at the moment of the call, checks +# docs/REPOSITORY_EXECUTION_RULES.md rules 2, 4 and 5, then (unless --dry-run) squash-merges. +# It does not replace a human read of the diff, and it never rebases anything by itself. +# +# Usage: pr-gate.sh <repo> <pr-number> [--worktree DIR] [--dry-run] [--admin-authorized-by "<who, date, reason>"] +# Env: GH (default gh), GIT (default git), CRUMB (default crumb), SLEEP_SECS (default 10, UNKNOWN retry). +# Output: one line per step, "GATE <step>: PASS|FAIL|SKIP <reason>". Exit 1 at the first FAIL. +set -u +GH=${GH:-gh} +GIT=${GIT:-git} +CRUMB=${CRUMB:-crumb} +SLEEP_SECS=${SLEEP_SECS:-10} + +usage() { echo 'usage: pr-gate.sh <repo> <pr-number> [--worktree DIR] [--dry-run] [--admin-authorized-by "<who, date, reason>"]' >&2; exit 2; } +[ $# -ge 2 ] || usage +REPO=$1; N=$2; shift 2 +WT=""; DRY=0; ADMIN="" +while [ $# -gt 0 ]; do + case "$1" in + --worktree) [ $# -ge 2 ] || usage; WT=$2; shift 2 ;; + --dry-run) DRY=1; shift ;; + --admin-authorized-by) [ $# -ge 2 ] || usage; ADMIN=$2; shift 2 ;; + *) usage ;; + esac +done +case "$N" in ''|*[!0-9]*) usage ;; esac +FULL="aien-dev/$REPO" + +pass() { echo "GATE $1: PASS $2"; } +skip() { echo "GATE $1: SKIP $2"; } +fail() { echo "GATE $1: FAIL $2"; exit 1; } + +FIELDS=number,state,isDraft,baseRefName,headRefName,headRefOid,mergeable,mergeStateStatus,reviewDecision,statusCheckRollup +view() { $GH pr view "$N" -R "$FULL" --json "$FIELDS" 2>&1; } + +# 1. pr +PR=$(view) || fail pr "could not read PR: $(echo "$PR" | head -1)" +echo "$PR" | jq -e . >/dev/null 2>&1 || fail pr "gh did not return JSON" +f() { echo "$PR" | jq -r "$1"; } +STATE=$(f .state); DRAFT=$(f .isDraft); BASE=$(f .baseRefName); HEADREF=$(f .headRefName); HEADOID=$(f .headRefOid) +[ "$STATE" = OPEN ] || fail pr "state is $STATE, not OPEN" +[ "$DRAFT" = false ] || fail pr "PR is a draft" +[ "$BASE" = main ] || fail pr "base is $BASE, not main" +pass pr "#$N $HEADREF at ${HEADOID:0:8}, open, not draft, base main" + +# 2. local +if [ -z "$WT" ]; then + skip local "no worktree given" +else + G="$GIT -C $WT" + $G rev-parse --is-inside-work-tree >/dev/null 2>&1 || fail local "$WT is not a git checkout" + $G fetch -q origin 2>/dev/null || fail local "fetch failed in $WT" + [ -z "$($G status --porcelain)" ] || fail local "worktree is dirty" + CUR=$($G rev-parse --abbrev-ref HEAD) + [ "$CUR" = "$HEADREF" ] || fail local "worktree is on $CUR, PR branch is $HEADREF" + [ "$($G rev-parse HEAD)" = "$HEADOID" ] || fail local "local HEAD $($G rev-parse --short HEAD) differs from GitHub head ${HEADOID:0:7}" + [ "$($G merge-base origin/main HEAD)" = "$($G rev-parse origin/main)" ] || fail local "stale base, branch is not on current origin/main; run scripts/rebase-crumb.sh" + pass local "clean, on $CUR, HEAD matches GitHub, based on current origin/main" +fi + +# 3. crumb +if [ -z "$WT" ]; then + skip crumb "no worktree given" +elif ! $G ls-files '*.crumb' '**/.crumb' | grep -q .; then + skip crumb "no crumbs in repo (rule 2 notice)" +else + VOUT=$(cd "$WT" && $CRUMB verify . 2>&1); VRC=$? + VLAST=$(echo "$VOUT" | tail -1) + { [ "$VRC" -eq 0 ] && echo "$VLAST" | grep -q 'OK' && ! echo "$VLAST" | grep -q 'FAIL'; } || fail crumb "crumb verify did not print OK: $VLAST" + if $G diff --name-only origin/main...HEAD | grep -q '\.crumb$'; then + NONCRUMB=$($G diff-tree --no-commit-id --name-only -r HEAD | grep -v '\.crumb$' || true) + [ -z "$NONCRUMB" ] || fail crumb "crumbs changed but the HEAD commit also changes source ($(echo "$NONCRUMB" | head -3 | tr '\n' ' ')); the crumb commit must be separate and last (rule 2)" + fi + pass crumb "verify OK, crumb commit is separate and last" +fi + +# 4. base +TRIES=0 +while :; do + MSS=$(f .mergeStateStatus); MRG=$(f .mergeable) + [ "$MSS" = UNKNOWN ] || break + TRIES=$((TRIES+1)) + [ "$TRIES" -le 5 ] || fail base "GitHub has not computed mergeability" + sleep "$SLEEP_SECS" + PR=$(view) || fail base "could not re-read PR" +done +[ "$MRG" != CONFLICTING ] || fail base "mergeable is CONFLICTING (merge conflicts)" +case "$MSS" in + CLEAN) pass base "mergeStateStatus CLEAN" ;; + BEHIND) fail base "stale, rebase first" ;; + DIRTY) fail base "merge conflicts" ;; + BLOCKED) fail base "required checks or reviews missing" ;; + UNSTABLE) fail base "a check is failing" ;; + HAS_HOOKS) + if [ "$DRY" = 1 ]; then pass base "HAS_HOOKS (accepted in dry run only)" + else fail base "merge queue or hooks present, check by hand"; fi ;; + *) fail base "unexpected mergeStateStatus $MSS" ;; +esac + +# 5. checks +RD=$(f '.reviewDecision // ""') +case "$RD" in + CHANGES_REQUESTED) fail checks "reviewDecision is CHANGES_REQUESTED" ;; + REVIEW_REQUIRED) fail checks "reviewDecision is REVIEW_REQUIRED" ;; +esac +PROT=$($GH api "repos/$FULL/branches/main/protection/required_status_checks" --jq .contexts 2>&1); PRC=$? +if [ "$PRC" -ne 0 ]; then + if echo "$PROT" | grep -qE '404|Not Found'; then + echo "WARNING: $FULL main has no branch protection; no required contexts to verify" >&2 + skip checks "no branch protection" + else + fail checks "could not read required checks: $(echo "$PROT" | head -1)" + fi +else + echo "$PROT" | jq -e 'type=="array"' >/dev/null 2>&1 || fail checks "required checks response is not a list" + MISSING=$(echo "$PR" | jq -r --argjson req "$PROT" ' + (.statusCheckRollup // []) as $r + | $req[] as $c + | select(([$r[] | select((.name == $c or .context == $c) and (.conclusion == "SUCCESS" or .state == "SUCCESS"))] | length) == 0) + | $c') + [ -z "$MISSING" ] || fail checks "required check not green: $(echo "$MISSING" | tr '\n' ',' | sed 's/,$//')" + pass checks "$(echo "$PROT" | jq 'length') required contexts green, reviewDecision ${RD:-none}" +fi + +# 6. merge +if [ "$DRY" = 1 ]; then + skip merge "dry run" +else + ARGS=(pr merge "$N" -R "$FULL" --squash --delete-branch) + NOTE="squash" + if [ -n "$ADMIN" ]; then ARGS+=(--admin); NOTE="squash with --admin, authorized by: $ADMIN"; fi + MOUT=$($GH "${ARGS[@]}" 2>&1) || fail merge "gh pr merge failed: $(echo "$MOUT" | head -1)" + POST=$($GH pr view "$N" -R "$FULL" --json state,mergedAt,mergeCommit 2>&1) || fail merge "merge ran but state could not be re-read" + [ "$(echo "$POST" | jq -r .state)" = MERGED ] || fail merge "after merge, state is $(echo "$POST" | jq -r .state), not MERGED" + pass merge "$NOTE; merge commit $(echo "$POST" | jq -r '.mergeCommit.oid // "unknown"')" +fi + +# 7. queue +LIST=$($GH pr list -R "$FULL" --json number,headRefName,mergeStateStatus 2>&1) || fail queue "could not list open PRs: $(echo "$LIST" | head -1)" +echo "$LIST" | jq -r --argjson me "$N" '.[] | select(.number != $me) + | "QUEUE #\(.number) \(.headRefName) \(.mergeStateStatus)" + (if (.mergeStateStatus == "BEHIND" or .mergeStateStatus == "DIRTY") then " needs scripts/rebase-crumb.sh" else "" end)' +pass queue "$(echo "$LIST" | jq --argjson me "$N" '[.[] | select(.number != $me)] | length') other open PRs listed, none rebased" +exit 0 diff --git a/scripts/rebase-crumb.sh b/scripts/rebase-crumb.sh new file mode 100755 index 0000000..4918785 --- /dev/null +++ b/scripts/rebase-crumb.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# Rebase a PR branch onto origin/main, resolve conflicts that are only in .crumb files by taking +# main's copy, recompile crumbs as a fresh last commit, and push with a lease on the old head. +# +# Usage: rebase-crumb.sh <worktree> <branch> +# Env: GIT (default git), CRUMB (default crumb), so tests can stub the tools. +# Exit: 0 done, 2 precondition refused, 3 CODE CONFLICT (rebase aborted), 4 crumb or rebase failure +# (nothing pushed). +set -u +GIT=${GIT:-git} +CRUMB=${CRUMB:-crumb} +TRAILERS='Co-authored-by: Drake Stapleton <drake@aienos.com> +Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>' + +refuse() { echo "REFUSED: $1" >&2; exit 2; } + +[ $# -eq 2 ] || { echo "usage: rebase-crumb.sh <worktree> <branch>" >&2; exit 2; } +W=$1; B=$2 +cd "$W" 2>/dev/null || refuse "worktree $W does not exist" +$GIT rev-parse --is-inside-work-tree >/dev/null 2>&1 || refuse "$W is not a git checkout" +[ -z "$($GIT status --porcelain)" ] || refuse "working tree is not clean" +[ "$B" != "main" ] || refuse "branch is main" +URL=$($GIT config --get remote.origin.url 2>/dev/null) || refuse "no origin remote" +case "$URL" in + *github.com/aien-dev/*|*git@github.com:aien-dev/*) ;; + *) refuse "origin URL is not under aien-dev: $URL" ;; +esac +$GIT fetch -q origin || refuse "fetch failed" +$GIT rev-parse -q --verify "refs/remotes/origin/$B" >/dev/null || refuse "origin/$B does not exist" + +GD=$($GIT rev-parse --git-dir) +LOCK="$GD/rebase-crumb.lock" +if [ -e "$LOCK" ] && [ -z "$(find "$LOCK" -mmin +120 2>/dev/null)" ]; then + refuse "lock $LOCK is fresh (another run, or younger than 2 hours)" +fi +echo $$ > "$LOCK" || refuse "cannot create lock" +trap 'rm -f "$LOCK"' EXIT + +LEASE=$($GIT rev-parse "origin/$B") +$GIT checkout -q -B "$B" "origin/$B" || { echo "checkout failed" >&2; exit 4; } + +rebasing() { [ -d "$($GIT rev-parse --git-path rebase-merge)" ] || [ -d "$($GIT rev-parse --git-path rebase-apply)" ]; } + +$GIT rebase -q origin/main >/dev/null 2>&1 +while rebasing; do + C=$($GIT diff --name-only --diff-filter=U) + if [ -z "$C" ]; then + GIT_EDITOR=true $GIT rebase --continue >/dev/null 2>&1 && continue + # A resolved commit that became empty cannot be continued; skip it. + if [ -z "$($GIT diff --cached --name-only)" ]; then + $GIT rebase --skip >/dev/null 2>&1 && continue + fi + echo "rebase continue failed" >&2; $GIT status --short | head; $GIT rebase --abort; exit 4 + fi + NONCRUMB=$(echo "$C" | grep -v '\.crumb$' || true) + if [ -n "$NONCRUMB" ]; then + echo "CODE CONFLICT: $(echo "$NONCRUMB" | tr '\n' ' ')" + $GIT rebase --abort + exit 3 + fi + # During a rebase "ours" is the branch being rebased onto, which is main. + echo "$C" | while IFS= read -r f; do + if $GIT cat-file -e "origin/main:$f" 2>/dev/null; then + $GIT checkout -q --ours -- "$f" && $GIT add -- "$f" + else + $GIT rm -q -f -- "$f" + fi + done + GIT_EDITOR=true $GIT rebase --continue >/dev/null 2>&1 || { + if [ -z "$($GIT diff --cached --name-only)" ] && $GIT rebase --skip >/dev/null 2>&1; then continue; fi + echo "rebase continue failed" >&2; $GIT status --short | head; $GIT rebase --abort; exit 4 + } +done + +if $GIT ls-files '*.crumb' '**/.crumb' | grep -q .; then + $CRUMB compile . >/dev/null 2>&1 + VOUT=$($CRUMB verify . 2>&1); VRC=$? + if [ "$VRC" -ne 0 ] || ! echo "$VOUT" | tail -1 | grep -q 'OK' || echo "$VOUT" | tail -1 | grep -q 'FAIL'; then + echo "crumb verify did not print OK; nothing pushed: $(echo "$VOUT" | tail -1)" >&2 + exit 4 + fi + echo "crumb: $(echo "$VOUT" | tail -1)" + if [ -n "$($GIT status --porcelain)" ]; then + $GIT add -A && $GIT commit -q -m "crumb compile (after rebase onto main) + +$TRAILERS" || { echo "crumb commit failed" >&2; exit 4; } + fi +else + echo "crumb: no crumbs in repo, step skipped (rule 2 notice)" +fi + +$GIT push -q --force-with-lease="refs/heads/$B:$LEASE" origin "$B" || { echo "push failed (lease or network)" >&2; exit 4; } +echo "rebased $B onto $($GIT rev-parse --short origin/main): $($GIT log --oneline -1 | cut -c1-70)" diff --git a/scripts/test_pr_gate.sh b/scripts/test_pr_gate.sh new file mode 100755 index 0000000..9c7bf44 --- /dev/null +++ b/scripts/test_pr_gate.sh @@ -0,0 +1,168 @@ +#!/usr/bin/env bash +# Offline test for pr-gate.sh. A fake `gh` on PATH answers from fixture JSON chosen by $CASE and +# records any merge command line. Local and crumb steps use real temporary git repos (bare origin +# plus worktree) and a fake `crumb`. No network, no auth. +set -u +here="$(cd "$(dirname "$0")" && pwd)" +gate="$here/pr-gate.sh" +tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT +export GIT_AUTHOR_NAME=T GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=T GIT_COMMITTER_EMAIL=t@example.invalid +export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null +export SLEEP_SECS=0 +FX="$tmp/fx"; mkdir -p "$FX" "$tmp/bin"; export FX + +cat > "$tmp/bin/gh" <<'S' +#!/usr/bin/env bash +d="$FX/$CASE" +case "$1 $2" in + "pr view") + if echo "$*" | grep -q mergeCommit && [ -e "$d/merged-flag" ]; then cat "$d/merged.json" + else + # UNKNOWN case: the first N answers can be counted + cat "$d/pr.json" + fi ;; + "pr list") cat "$d/list.json" ;; + "pr merge") echo "$*" > "$d/merge.cmd"; touch "$d/merged-flag" ;; + api\ repos/*) + if [ -e "$d/prot404" ]; then echo "gh: Not Found (HTTP 404)" >&2; exit 1; fi + cat "$d/prot.json" ;; + *) echo "fake gh: unhandled: $*" >&2; exit 2 ;; +esac +S +cat > "$tmp/bin/crumb" <<'S' +#!/usr/bin/env bash +[ "$1" = verify ] || exit 0 +if [ "${CRUMB_FAIL:-0}" = 1 ]; then echo "crumb verify: FAIL: stale"; exit 1; fi +echo "crumb verify: OK" +S +chmod +x "$tmp/bin/gh" "$tmp/bin/crumb" +export PATH="$tmp/bin:$PATH" + +pass=0; bad=0 +ok() { pass=$((pass+1)); } +no() { bad=$((bad+1)); echo "TEST FAIL: $1"; } +run() { OUT=$("$gate" "$@" 2>&1); rc=$?; } +expect() { # expect <rc> <label> <gate args...> + w=$1; l=$2; shift 2; run "$@" + if [ "$rc" = "$w" ]; then ok; else no "$l (rc=$rc, want $w): $OUT"; fi +} +has() { # has <label> <pattern> against $OUT + if echo "$OUT" | grep -qE -- "$2"; then ok; else no "$1 (missing /$2/): $OUT"; fi +} +hasnot() { if echo "$OUT" | grep -qE -- "$2"; then no "$1 (unexpected /$2/): $OUT"; else ok; fi; } + +# fixture builder: fx <case> [jq filter applied to the clean PR] +CLEANPR='{"number":7,"state":"OPEN","isDraft":false,"baseRefName":"main","headRefName":"feat","headRefOid":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","mergeable":"MERGEABLE","mergeStateStatus":"CLEAN","reviewDecision":"","statusCheckRollup":[{"__typename":"CheckRun","name":"rust","status":"COMPLETED","conclusion":"SUCCESS"},{"__typename":"StatusContext","context":"legacy-ci","state":"SUCCESS"}]}' +fx() { + mkdir -p "$FX/$1" + echo "$CLEANPR" | jq "${2:-.}" > "$FX/$1/pr.json" + echo '["rust","legacy-ci"]' > "$FX/$1/prot.json" + echo '[{"number":7,"headRefName":"feat","mergeStateStatus":"CLEAN"},{"number":9,"headRefName":"other","mergeStateStatus":"BEHIND"},{"number":10,"headRefName":"third","mergeStateStatus":"CLEAN"}]' > "$FX/$1/list.json" + echo '{"state":"MERGED","mergedAt":"2026-10-10T00:00:00Z","mergeCommit":{"oid":"cafebabecafebabecafebabecafebabecafebabe"}}' > "$FX/$1/merged.json" +} + +# ---- GitHub-side cases (no worktree) +fx clean; export CASE=clean; expect 0 "clean PR passes dry run" repo1 7 --dry-run +has "dry run prints pr PASS" 'GATE pr: PASS' +has "local skipped without worktree" 'GATE local: SKIP no worktree given' +has "merge skipped in dry run" 'GATE merge: SKIP dry run' +has "queue marks BEHIND PR as needing rebase" 'QUEUE #9 other BEHIND needs scripts/rebase-crumb.sh' +has "queue shows clean PR plainly" 'QUEUE #10 third CLEAN$' +hasnot "queue omits the PR itself" 'QUEUE #7 ' +check_nomerge() { if [ ! -e "$FX/$1/merge.cmd" ]; then ok; else no "$2"; fi; } +check_nomerge clean "dry run must not call gh pr merge" + +fx behind '.mergeStateStatus="BEHIND"'; CASE=behind expect 1 "BEHIND refuses" repo1 7 --dry-run +has "BEHIND reason" 'stale, rebase first' +fx dirty '.mergeStateStatus="DIRTY"'; CASE=dirty expect 1 "DIRTY refuses" repo1 7 --dry-run +fx blocked '.mergeStateStatus="BLOCKED"'; CASE=blocked expect 1 "BLOCKED refuses" repo1 7 --dry-run +fx unstable '.mergeStateStatus="UNSTABLE"'; CASE=unstable expect 1 "UNSTABLE refuses" repo1 7 --dry-run +fx conflicting '.mergeable="CONFLICTING"'; CASE=conflicting expect 1 "mergeable CONFLICTING refuses" repo1 7 --dry-run +fx unknown '.mergeStateStatus="UNKNOWN"'; CASE=unknown expect 1 "UNKNOWN retries then refuses" repo1 7 --dry-run +has "UNKNOWN reason" 'has not computed mergeability' +fx hooks '.mergeStateStatus="HAS_HOOKS"'; CASE=hooks expect 0 "HAS_HOOKS passes in dry run" repo1 7 --dry-run +CASE=hooks expect 1 "HAS_HOOKS refuses on a real merge" repo1 7 +check_nomerge hooks "HAS_HOOKS real run must not merge" +fx draft '.isDraft=true'; CASE=draft expect 1 "draft refuses" repo1 7 --dry-run +fx closed '.state="CLOSED"'; CASE=closed expect 1 "closed refuses" repo1 7 --dry-run +fx wrongbase '.baseRefName="release"'; CASE=wrongbase expect 1 "non-main base refuses" repo1 7 --dry-run +fx missing '.statusCheckRollup=[{"__typename":"CheckRun","name":"rust","conclusion":"SUCCESS"}]' +CASE=missing expect 1 "required check absent from rollup refuses" repo1 7 --dry-run +has "names the missing check" 'legacy-ci' +fx failing '.statusCheckRollup[0].conclusion="FAILURE"' +CASE=failing expect 1 "required check present but FAILURE refuses" repo1 7 --dry-run +fx changes '.reviewDecision="CHANGES_REQUESTED"'; CASE=changes expect 1 "CHANGES_REQUESTED refuses" repo1 7 --dry-run +fx reqrev '.reviewDecision="REVIEW_REQUIRED"'; CASE=reqrev expect 1 "REVIEW_REQUIRED refuses" repo1 7 --dry-run +fx approved '.reviewDecision="APPROVED"'; CASE=approved expect 0 "APPROVED passes" repo1 7 --dry-run +fx noprot; touch "$FX/noprot/prot404"; CASE=noprot expect 0 "404 on protection gives SKIP and passes" repo1 7 --dry-run +has "no protection SKIP line" 'GATE checks: SKIP no branch protection' +has "no protection warning" 'WARNING' +fx noprotb '.mergeStateStatus="BEHIND"'; touch "$FX/noprotb/prot404" +CASE=noprotb expect 1 "404 protection does not rescue a BEHIND PR" repo1 7 --dry-run + +# ---- merge cases +fx merge; CASE=merge expect 0 "clean PR merges (non-dry-run)" repo1 7 +has "merge PASS with sha" 'GATE merge: PASS squash; merge commit cafebabe' +if grep -q -- '--squash --delete-branch' "$FX/merge/merge.cmd" && ! grep -q -- '--admin' "$FX/merge/merge.cmd"; then ok; else no "merge command has squash+delete-branch and no --admin: $(cat "$FX/merge/merge.cmd" 2>&1)"; fi +fx adm; CASE=adm expect 0 "authorized admin merge" repo1 7 --admin-authorized-by "Drake, 2026-10-10, test" +if grep -q -- '--admin' "$FX/adm/merge.cmd"; then ok; else no "--admin recorded when authorized"; fi +has "authorization text printed" 'authorized by: Drake, 2026-10-10, test' +fx admfail '.mergeStateStatus="BLOCKED"'; CASE=admfail expect 1 "--admin never overrides a BLOCKED PR" repo1 7 --admin-authorized-by "Drake, 2026-10-10, test" +check_nomerge admfail "no merge call for BLOCKED even with authorization" +fx notmerged; echo '{"state":"OPEN","mergedAt":null,"mergeCommit":null}' > "$FX/notmerged/merged.json" +CASE=notmerged expect 1 "merge not confirmed is a FAIL" repo1 7 +has "reports not MERGED" 'not MERGED' +CASE=clean expect 2 "bad usage exits 2" repo1 +CASE=clean expect 2 "non-numeric PR exits 2" repo1 abc + +# ---- local and crumb cases with real git repos +# mkrepo <name> [nocrumb]: main has src.txt (+ .crumb); branch feat = commit "feat", then (crumbs) commit "crumb compile". +mkrepo() { + d="$tmp/$1"; mkdir -p "$d"; git init -q --bare -b main "$d/origin.git"; git init -q -b main "$d/seed" + ( cd "$d/seed" && echo base > src.txt && { [ "${2:-}" = nocrumb ] || echo c0 > .crumb; } && git add -A && git commit -q -m base \ + && git remote add origin "$d/origin.git" && git push -q origin main ) + git clone -q "$d/origin.git" "$d/w" + ( cd "$d/w" && git checkout -q -b feat && echo feat > feat.txt && git add -A && git commit -q -m feat + if [ "${2:-}" != nocrumb ]; then echo c1 > .crumb && git add -A && git commit -q -m "crumb compile"; fi + git push -q origin feat ) + W="$d/w" +} +lfx() { # lfx <case> : fixture whose headRefOid is the worktree HEAD + fx "$1" ".headRefOid=\"$(git -C "$W" rev-parse HEAD)\"" +} +mkrepo l1; lfx l1; CASE=l1 expect 0 "local+crumb clean passes" repo1 7 --dry-run --worktree "$W" +has "local PASS" 'GATE local: PASS' +has "crumb PASS" 'GATE crumb: PASS' + +mkrepo l2; echo dirt >> "$W/feat.txt"; lfx l2; CASE=l2 expect 1 "dirty worktree refuses" repo1 7 --dry-run --worktree "$W" +has "dirty reason" 'worktree is dirty' + +mkrepo l3; git -C "$W" checkout -q -b other; lfx l3; CASE=l3 expect 1 "wrong branch refuses" repo1 7 --dry-run --worktree "$W" +has "wrong branch reason" 'worktree is on other' + +mkrepo l4 +fx l4 '.headRefOid="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"'; CASE=l4 expect 1 "local HEAD differs from GitHub head refuses" repo1 7 --dry-run --worktree "$W" +has "oid mismatch reason" 'differs from GitHub head' + +mkrepo l5 +( cd "$tmp/l5/seed" && echo more > more.txt && git add -A && git commit -q -m "main moves" && git push -q origin main ) +lfx l5; CASE=l5 expect 1 "stale base refuses" repo1 7 --dry-run --worktree "$W" +has "stale base points at rebase script" 'run scripts/rebase-crumb.sh' + +mkrepo l6; ( cd "$W" && echo src2 > src2.txt && git add -A && git commit -q --amend -m "mixed" ) +lfx l6; CASE=l6 expect 1 "HEAD commit mixing source and .crumb refuses" repo1 7 --dry-run --worktree "$W" +has "mixed commit reason" 'must be separate and last' + +mkrepo l7; lfx l7; CRUMB_FAIL=1 CASE=l7 expect 1 "crumb verify failure refuses" repo1 7 --dry-run --worktree "$W" +has "verify reason" 'did not print OK' + +mkrepo l8 nocrumb; lfx l8; CASE=l8 expect 0 "repo without crumbs passes" repo1 7 --dry-run --worktree "$W" +has "no crumbs gives SKIP notice" 'GATE crumb: SKIP no crumbs in repo \(rule 2 notice\)' + +# crumbs exist but this PR does not touch them: HEAD may be a source commit +mkrepo l9 +( cd "$W" && git reset -q --hard HEAD~1 && git push -q -f origin feat ) +lfx l9; CASE=l9 expect 0 "PR that does not touch crumbs may end on a source commit" repo1 7 --dry-run --worktree "$W" + +echo "PASS $pass FAIL $bad" +[ "$bad" -eq 0 ] diff --git a/scripts/test_rebase_crumb.sh b/scripts/test_rebase_crumb.sh new file mode 100755 index 0000000..900ca55 --- /dev/null +++ b/scripts/test_rebase_crumb.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +# Offline test for rebase-crumb.sh. Real temporary git repos (a bare "origin" plus a worktree whose +# origin URL looks like an aien-dev URL, redirected to the bare repo with insteadOf) and a fake +# `crumb` on PATH. No network, no auth. +set -u +here="$(cd "$(dirname "$0")" && pwd)" +script="$here/rebase-crumb.sh" +tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT +export GIT_AUTHOR_NAME=T GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=T GIT_COMMITTER_EMAIL=t@example.invalid +export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null +FAKEURL="https://github.com/aien-dev/fake-repo" + +mkdir -p "$tmp/bin" +cat > "$tmp/bin/crumb" <<'S' +#!/usr/bin/env bash +case "$1" in + compile) echo compiled >> .crumb ;; + verify) if [ "${CRUMB_FAIL:-0}" = 1 ]; then echo "crumb verify: FAIL: stale"; exit 1; else echo "crumb verify: OK"; fi ;; +esac +S +chmod +x "$tmp/bin/crumb" +export PATH="$tmp/bin:$PATH" + +pass=0; bad=0 +ok() { pass=$((pass+1)); } +no() { bad=$((bad+1)); echo "TEST FAIL: $1"; } +expect() { # expect <rc> <label> <worktree> <branch> (output in $OUT) + OUT=$("$script" "$3" "$4" 2>&1); rc=$? + if [ "$rc" = "$1" ]; then ok; else no "$2 (rc=$rc, want $1): $OUT"; fi +} +check() { # check <label> <command...> + l=$1; shift; if "$@" >/dev/null 2>&1; then ok; else no "$l"; fi +} + +# mk <name> [nocrumb] : origin (bare) + worktree w on branch feat (pushed). main has src.txt and .crumb. +mk() { + d="$tmp/$1"; mkdir -p "$d"; git init -q --bare -b main "$d/origin.git" + git init -q -b main "$d/seed" + ( cd "$d/seed" && echo base > src.txt && { [ "${2:-}" = nocrumb ] || echo c0 > .crumb; } \ + && git add -A && git commit -q -m base && git remote add origin "$d/origin.git" && git push -q origin main ) + git clone -q "$d/origin.git" "$d/w" + ( cd "$d/w" && git checkout -q -b feat && echo feat > feat.txt && git add -A && git commit -q -m feat && git push -q origin feat \ + && git remote set-url origin "$FAKEURL" && git config "url.$d/origin.git.insteadOf" "$FAKEURL" ) + W="$d/w"; O="$d/origin.git" +} +advance_main() { # advance_main <seed-dir> <file> <content> + ( cd "$1" && git checkout -q main && echo "$3" > "$2" && git add -A && git commit -q -m "main $2" && git push -q origin main ) +} +ohead() { git -C "$O" rev-parse "refs/heads/feat"; } + +# 1 dirty tree +mk t1; echo x >> "$W/feat.txt" +expect 2 "dirty tree refused" "$W" feat +# 2 branch main +mk t2 +expect 2 "branch main refused" "$W" main +# 3 wrong remote +mk t3; git -C "$W" remote set-url origin https://github.com/other-org/x +expect 2 "wrong remote refused" "$W" feat +# 4 lock present (fresh) +mk t4; touch "$W/.git/rebase-crumb.lock" +expect 2 "fresh lock refused" "$W" feat +check "fresh lock left in place" test -e "$W/.git/rebase-crumb.lock" +# 5 not a git checkout +mkdir -p "$tmp/plain" +expect 2 "non-git directory refused" "$tmp/plain" feat +# 6 origin branch missing +mk t6 +expect 2 "missing origin branch refused" "$W" nosuchbranch +# 7 clean rebase, crumb commit, push +mk t7; advance_main "$tmp/t7/seed" main-only.txt m +before=$(ohead) +expect 0 "clean rebase succeeds" "$W" feat +check "push reached origin" test "$(ohead)" = "$(git -C "$W" rev-parse HEAD)" +check "origin head moved" test "$(ohead)" != "$before" +check "last commit is crumb compile" test "$(git -C "$W" log -1 --format=%s)" = "crumb compile (after rebase onto main)" +check "crumb commit has both trailers" bash -c "git -C '$W' log -1 --format=%B | grep -q 'Co-authored-by: Drake Stapleton <drake@aienos.com>' && git -C '$W' log -1 --format=%B | grep -q 'Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>'" +check "main commit is an ancestor" git -C "$W" merge-base --is-ancestor origin/main HEAD +check "lock removed on exit" test ! -e "$W/.git/rebase-crumb.lock" +check "final line format" bash -c "echo '$OUT' | tail -1 | grep -q '^rebased feat onto '" +# 8 stale lock (older than 2h) does not block +mk t8; touch -d '3 hours ago' "$W/.git/rebase-crumb.lock"; advance_main "$tmp/t8/seed" main-only.txt m +expect 0 "stale lock ignored" "$W" feat +# 9 CODE CONFLICT +mk t9 +( cd "$tmp/t9/w" && git checkout -q feat && echo featside > src.txt && git add -A && git commit -q -m "feat src" && git push -q origin feat ) +advance_main "$tmp/t9/seed" src.txt mainside +before=$(ohead) +expect 3 "code conflict exits 3" "$W" feat +check "CODE CONFLICT message names file" bash -c "echo '$OUT' | grep -q 'CODE CONFLICT: src.txt'" +check "no rebase left in progress" test ! -d "$W/.git/rebase-merge" +check "code conflict pushed nothing" test "$(ohead)" = "$before" +check "lock removed after conflict" test ! -e "$W/.git/rebase-crumb.lock" +# 10 crumb-only conflict resolved with main's copy +mk t10 +( cd "$tmp/t10/w" && echo featcrumb > .crumb && git add -A && git commit -q -m "feat crumb" && git push -q origin feat ) +advance_main "$tmp/t10/seed" .crumb maincrumb +expect 0 "crumb-only conflict resolved" "$W" feat +check "main's crumb copy kept, then compiled" test "$(cat "$W/.crumb")" = "$(printf 'maincrumb\ncompiled')" +check "feat source change kept" test -f "$W/feat.txt" +# 11 verify fails: exit 4, no push +mk t11; advance_main "$tmp/t11/seed" main-only.txt m; before=$(ohead) +OUT=$(CRUMB_FAIL=1 "$script" "$W" feat 2>&1); rc=$? +if [ "$rc" = 4 ]; then ok; else no "verify failure exits 4 (rc=$rc): $OUT"; fi +check "verify failure pushed nothing" test "$(ohead)" = "$before" +# 12 repo with no crumbs: step skipped +mk t12 nocrumb; advance_main "$tmp/t12/seed" main-only.txt m +expect 0 "no-crumb repo passes" "$W" feat +check "skip notice printed" bash -c "echo '$OUT' | grep -q 'crumb: no crumbs in repo, step skipped (rule 2 notice)'" +check "no crumb commit made" test "$(git -C "$W" log -1 --format=%s)" = "feat" +# 13 lease protects against someone else's push between fetch and push +mk t13; advance_main "$tmp/t13/seed" main-only.txt m +cat > "$tmp/bin/racegit" <<S +#!/usr/bin/env bash +# real git, but just before the push another writer moves origin/feat +if [ "\$1" = push ]; then + git clone -q "$tmp/t13/origin.git" "$tmp/t13/racer" && ( cd "$tmp/t13/racer" && git checkout -q feat && echo other > other.txt && git add -A && git commit -q -m other && git push -q origin feat ) +fi +exec git "\$@" +S +chmod +x "$tmp/bin/racegit" +OUT=$(GIT="$tmp/bin/racegit" "$script" "$W" feat 2>&1); rc=$? +if [ "$rc" = 4 ]; then ok; else no "lease violation exits 4 (rc=$rc): $OUT"; fi +check "racer commit not overwritten" test "$(git -C "$O" log -1 --format=%s feat)" = "other" + +echo "PASS $pass FAIL $bad" +[ "$bad" -eq 0 ]