diff --git a/README.md b/README.md index 7f22026..8a51ffe 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ jobs: startsWith(github.event.comment.body, '/codeboarding') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) runs-on: ubuntu-latest - timeout-minutes: 60 + timeout-minutes: 180 permissions: contents: read actions: read # download the analysis an earlier run published @@ -60,7 +60,7 @@ jobs: sync: if: github.event_name == 'push' runs-on: ubuntu-latest - timeout-minutes: 60 + timeout-minutes: 180 permissions: contents: write actions: read # catch up from an analysis a review saved @@ -72,6 +72,8 @@ jobs: llm: hosted ``` +A first analysis of a large repository, around a million lines, can take over an hour, hence `timeout-minutes: 180`; GitHub bills the minutes used, not the limit. + Both jobs use the default `codeboarding_analysis_location`, so review always reads the analysis where sync saves it. If you set it, set it in both jobs. Keep both jobs in this one file: a repository running CodeBoarding from more than one workflow file is an [older setup](#moving-an-existing-setup), which the CodeBoarding dashboard flags and offers to fold into one. ## Review pull requests @@ -380,7 +382,7 @@ Off by default. With `problem_history: 'true'` on the sync job, every sync (a pu sync: if: github.event_name == 'push' runs-on: ubuntu-latest - timeout-minutes: 60 + timeout-minutes: 180 permissions: contents: write # also writes codeboarding/briefing actions: read # also reads merged pull requests' review artifacts diff --git a/action.yml b/action.yml index cbd9818..9a1db45 100644 --- a/action.yml +++ b/action.yml @@ -543,6 +543,7 @@ runs: ANALYSIS_DIR: ${{ steps.sync_analyze.outputs.analysis_dir }} CHECKOUT_DIR: ${{ github.workspace }}/.codeboarding-target SYNCED_BRANCH: ${{ steps.guard.outputs.synced_branch }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} BASELINE_BRANCH: ${{ steps.guard.outputs.analysis_branch }} ENGINE_VERSION: ${{ steps.state.outputs.engine_version }} # Recorded with each baseline-branch commit, so a reader can tell which configuration made it. @@ -553,15 +554,14 @@ runs: run: "$GITHUB_ACTION_PATH/scripts/action/deliver-sync.sh" # Named for the commit pull requests branch from, so a review that forks there - # finds this graph and skips analyzing the base entirely. Published under both - # the analyzed commit and the baseline commit written on top, because a pull - # request opened either side of that commit has a different merge base. - - name: Publish baseline analysis - if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_commit.outputs.baseline_sha != '' && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com' + # finds this graph and skips analyzing the base entirely. Published whatever the + # delivery did, so a refused push does not throw the analysis away. + - name: Publish baseline analysis for the analyzed commit + if: "!cancelled() && steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_analyze.outcome == 'success' && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com'" continue-on-error: true uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_commit.outputs.baseline_sha }} + name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_analyze.outputs.analyzed_sha }} path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base # Longer than a review's 14 days on purpose, and the margin is the whole # point: correctness comes from the renewal check, which republishes any @@ -572,12 +572,14 @@ runs: retention-days: 30 if-no-files-found: ignore - - name: Publish baseline analysis for the analyzed commit - if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_commit.outputs.analyzed_sha != '' && steps.sync_commit.outputs.analyzed_sha != steps.sync_commit.outputs.baseline_sha && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com' + # Also under the commit in_place writes on top of the analyzed one: a pull request + # opened either side of that commit has a different merge base. + - name: Publish baseline analysis for the baseline commit + if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'sync' && steps.sync_commit.outputs.baseline_sha != '' && steps.state.outputs.cfg_hash != '' && github.server_url == 'https://github.com' continue-on-error: true uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_commit.outputs.analyzed_sha }} + name: codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_commit.outputs.baseline_sha }} path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base # Longer than a review's 14 days on purpose, and the margin is the whole # point: correctness comes from the renewal check, which republishes any @@ -650,6 +652,28 @@ runs: KEEP_AUTH: 'true' run: '"$GITHUB_ACTION_PATH/scripts/action/with-auth.sh" "$GITHUB_ACTION_PATH/scripts/action/review-generate-baseline.sh"' + # Published before the head is analyzed, so a run that then fails or times out + # does not leave the next review to build the base again. + # Only a trusted run publishes a base graph: it is named for a commit, so + # every pull request forking there would read it, and a fork's analysis must + # never be what they read. + - name: Publish base analysis + id: publish_base + if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && steps.review_baseline.outputs.publish_base == 'true' && steps.guard.outputs.is_fork != 'true' && steps.state.outputs.base_name != '' && github.server_url == 'https://github.com' + continue-on-error: true + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: ${{ steps.state.outputs.base_name }} + path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base + # Longer than a review's 14 days on purpose, and the margin is the whole + # point: correctness comes from the renewal check, which republishes any + # base with less than a review's lifetime left, while this surplus + # decides how often that fires. Equal lifetimes renew on every run and + # publish a base per run rather than per merge base — more storage, not + # less. 30 leaves a 16-day reuse window. + retention-days: 30 + if-no-files-found: ignore + - name: Analyze pull request id: review_analyze if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' @@ -687,26 +711,6 @@ runs: retention-days: ${{ inputs.warmstart_retention_days }} if-no-files-found: ignore - # Only a trusted run publishes a base graph: it is named for a commit, so - # every pull request forking there would read it, and a fork's analysis must - # never be what they read. - - name: Publish base analysis - id: publish_base - if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && steps.review_baseline.outputs.publish_base == 'true' && steps.guard.outputs.is_fork != 'true' && steps.state.outputs.base_name != '' && github.server_url == 'https://github.com' - continue-on-error: true - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: ${{ steps.state.outputs.base_name }} - path: ${{ runner.temp }}/cb-state/${{ github.action }}/out/base - # Longer than a review's 14 days on purpose, and the margin is the whole - # point: correctness comes from the renewal check, which republishes any - # base with less than a review's lifetime left, while this surplus - # decides how often that fires. Equal lifetimes renew on every run and - # publish a base per run rather than per merge base — more storage, not - # less. 30 leaves a 16-day reuse window. - retention-days: 30 - if-no-files-found: ignore - - name: Render review diagram id: review_render if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' diff --git a/docs/COMMIT_STRATEGY.md b/docs/COMMIT_STRATEGY.md index 9e80f7e..bd52f89 100644 --- a/docs/COMMIT_STRATEGY.md +++ b/docs/COMMIT_STRATEGY.md @@ -38,10 +38,13 @@ pays for them. Health configuration stays, because a run seeded from a bundle reads it. The base graph is published only by the run that *computed* it, so it is written -about once per merge base rather than once per run — with two exceptions. A -review artifact references a base by id for its whole retention, so a base about -to expire inside that window is republished rather than left dangling under a -review that outlives it. And when no artifact holds the base at all, because the +about once per merge base rather than once per run. It is published as soon as it +exists, before the head is analyzed: building a base from scratch can take most of +a job's time limit, and a run that then fails or times out on the head still saves +it, so the next review starts from it instead of building it again. There are two +exceptions to "once per merge base". A review artifact references a base by id +for its whole retention, so a base about to expire inside that window is +republished rather than left dangling under a review that outlives it. And when no artifact holds the base at all, because the upload failed or because a fork review publishes nothing, the review artifact carries the graph inline and leaves `base_artifact` empty: a reader should prefer an inline `base_analysis.json` and fall back to the named artifact — ten runs on one pull request @@ -75,8 +78,10 @@ never fires. | `analysed_files_changed` | string | analysed files whose content hash differs between base and head; `unknown` when the analyses cannot say | | `pr_number`, `mode`, `seed_source`, `chain_depth` | string | provenance; nothing rendering a diagram needs them. `mode` is the head's engine mode | -**A sync run** publishes the base graph under both the commit it analyzed and the -baseline commit it writes on top, because a pull request opened either side of +**A sync run** publishes the base graph under the commit it analyzed whether or +not delivering it succeeds, so a push the remote refuses does not throw the +analysis away: the next sync or review catches up from the artifact. When delivery writes a baseline commit on top (`in_place`), it +is published under that commit too, because a pull request opened either side of that commit has a different merge base. ## Retention is what costs @@ -195,9 +200,11 @@ a code branch that happens to be named `codeboarding/baseline` fails, before any during the analysis, the result is still saved for the commit it analyzed: entries are keyed by commit, and a branch that merges faster than sync runs would otherwise never be saved. Only an analysis of an older commit than the tip's is -dropped, so the tip stays the latest diagram. If another sync moved the baseline branch, it builds on that tip once. A push the -remote refuses while the tip did not move is a branch rule, and the run fails -saying so. +dropped, so the tip stays the latest diagram. If another sync moved the baseline branch, it builds on that tip once. A push GitHub +refuses with a branch rule error (`GH006` for branch protection, `GH013` for a +ruleset) fails the run naming the bypass to add; any other refusal while the tip +did not move fails it asking to check the token. On github.com the analysis is +still published as an artifact. The tip is compared just before the push, not in the same transaction: if a sync of a newer commit lands in that window, the push is no longer a fast-forward and @@ -234,7 +241,7 @@ from a same-repository pull request branch, can still push to the branch and pla the pickle sync loads. Creation is covered too, so the bypass actor must be the identity sync pushes as -before the first sync, or that sync fails on the rule. Rulesets on a private repository need a paid GitHub plan +before the first sync, or that sync fails on the rule, saying which bypass to add. Rulesets on a private repository need a paid GitHub plan (Pro, Team or Enterprise); on Free they apply to public repositories only. ## Trust boundary diff --git a/scripts/action/codeboarding-baseline.sh b/scripts/action/codeboarding-baseline.sh index be19508..fdea894 100644 --- a/scripts/action/codeboarding-baseline.sh +++ b/scripts/action/codeboarding-baseline.sh @@ -16,6 +16,10 @@ baseline_fail() { exit 1 } +# True when git push output $1 is GitHub refusing a branch rule: GH006 is classic +# branch protection, GH013 a ruleset. +refused_by_rule() { grep -qiE 'protected branch|GH006|GH013|rule violation' <<< "$1"; } + # Returns 0 when branch $2 (BASELINE_BRANCH by default) exists in repository $1 and # 2 when it does not. Any other failure is retried once, so one network blip does # not fail the run. @@ -108,7 +112,7 @@ from_codeboarding_baseline() { # whose REMOTE, BASE_SHA and emit_result it uses; always exits. save_to_codeboarding_baseline() { local branch="$BASELINE_BRANCH" tree="$RUNNER_TEMP/codeboarding-baseline-tree" - local index="$RUNNER_TEMP/codeboarding-baseline-index" git_dir files new_tree tip tip_source parent commit now + local index="$RUNNER_TEMP/codeboarding-baseline-index" git_dir files new_tree tip tip_source parent commit push_output now git_dir="$(git rev-parse --absolute-git-dir)" rm -rf "$tree" "$index" mkdir -p "$tree" @@ -154,7 +158,7 @@ CodeBoarding-Config: $CFG_HASH") parent=(-p "$tip") if [ "$tip_source" = "$BASE_SHA" ] && git diff --quiet -I '"generated_at"' -I '"timestamp"' "$tip" "$new_tree"; then - emit_result "$files" false "$BASE_SHA" + emit_result "$files" false echo "::notice::$branch already holds this analysis of $SYNCED_BRANCH @${BASE_SHA:0:7}." exit 0 fi @@ -162,7 +166,7 @@ CodeBoarding-Config: $CFG_HASH") if [ "$tip_source" != "$BASE_SHA" ]; then git fetch -q --depth="$(( CATCHUP_BOUND + 1 ))" "$REMOTE" "$SYNCED_BRANCH" if git merge-base --is-ancestor "$BASE_SHA" "$tip_source" 2>/dev/null; then - emit_result "$files" false "$BASE_SHA" + emit_result "$files" false echo "::notice::$branch already holds the analysis of a newer commit, ${tip_source:0:7}; leaving it." exit 0 fi @@ -171,16 +175,20 @@ CodeBoarding-Config: $CFG_HASH") commit="$(git commit-tree "$new_tree" ${parent[@]+"${parent[@]}"} \ -m "chore(codeboarding): diagram of $SYNCED_BRANCH @${BASE_SHA:0:7}" "${trailers[@]}")" # Never forced: the parent is the tip just read, so this only ever fast-forwards. - if git push -q "$REMOTE" "$commit:refs/heads/$branch"; then - emit_result "$files" true "$BASE_SHA" + if push_output="$(git push -q "$REMOTE" "$commit:refs/heads/$branch" 2>&1)"; then + emit_result "$files" true exit 0 fi + echo "$push_output" >&2 + if refused_by_rule "$push_output"; then + baseline_fail "GitHub refused the push to $branch: a ruleset or branch protection covers it. Add GitHub Actions (or the CodeBoarding app, if github_token is its token) as a bypass actor: https://github.com/CodeBoarding/CodeBoarding-action/blob/main/docs/COMMIT_STRATEGY.md#the-baseline-branch" + fi now="$(git ls-remote "$REMOTE" "refs/heads/$branch" | awk '{print $1; exit}')" if [ "$now" = "$tip" ]; then - baseline_fail "GitHub refused the push to $branch, most likely because a branch rule protects it. Add the identity sync pushes with (the CodeBoarding app, or GitHub Actions for the default token) as a bypass actor for $branch in the repository's rulesets, and check that github_token may push to it." + baseline_fail "GitHub refused the push to $branch. Check that github_token may push to it and that no branch rule covers it." fi done - emit_result "$files" false "$BASE_SHA" + emit_result "$files" false echo "::notice::Another sync keeps updating $branch; leaving it to that run." exit 0 } diff --git a/scripts/action/deliver-sync.sh b/scripts/action/deliver-sync.sh index 98100a3..56e57e6 100755 --- a/scripts/action/deliver-sync.sh +++ b/scripts/action/deliver-sync.sh @@ -18,24 +18,29 @@ SH chmod 700 "$ASKPASS" export GIT_ASKPASS="$ASKPASS" GIT_TERMINAL_PROMPT=0 trap 'rm -f "$ASKPASS"' EXIT -# A pull request's merge base is whichever commit its author branched from, and -# this run's analysis is valid for two of them: the commit it analyzed, and the -# baseline commit it writes on top, which differs only in .codeboarding files -# that the fingerprint ignores. Publishing both means a pull request opened -# either side of a sync commit still gets an exact hit. +# baseline_sha is the commit written on top of the analyzed one, set only when +# in_place writes one. It differs only in .codeboarding files the fingerprint +# ignores, so the analysis is published under it too: a pull request opened +# either side of it still gets an exact hit. emit_result() { - printf 'files_written=%s\ncommitted=%s\nbaseline_sha=%s\nanalyzed_sha=%s\n' \ - "$1" "$2" "$3" "$BASE_SHA" >> "$GITHUB_OUTPUT" + printf 'files_written=%s\ncommitted=%s\nbaseline_sha=%s\n' "$1" "$2" "${3:-}" >> "$GITHUB_OUTPUT" } classify_push_failure() { - local expected="$1" branch="$2" current + local expected="$1" branch="$2" push_output="$3" current current="$(git ls-remote "$REMOTE" "refs/heads/$branch" | awk '{print $1; exit}')" [ "$current" != "$(git rev-parse HEAD)" ] || return 0 if [ "$current" != "$expected" ]; then - emit_result "$files_written" false "$BASE_SHA" + emit_result "$files_written" false echo "::notice::A newer run updated $branch; leaving it untouched." exit 0 fi + if refused_by_rule "$push_output"; then + # Only the default branch's analysis can live on codeboarding/baseline. + if [ "$branch" = "${DEFAULT_BRANCH:-}" ]; then + baseline_fail "GitHub refused the push to $branch: a ruleset or branch protection covers it. Remove \`codeboarding_analysis_location: in_place\` from both CodeBoarding jobs, and sync saves the analysis to \`codeboarding/baseline\`, a branch of its own: https://github.com/CodeBoarding/CodeBoarding-action#keep-the-baseline-current" + fi + baseline_fail "GitHub refused the push to $branch: a ruleset or branch protection covers it. Add GitHub Actions (or the CodeBoarding app, if github_token is its token) as a bypass actor: https://github.com/CodeBoarding/CodeBoarding-action#keep-the-analysis-on-the-code-branch" + fi baseline_fail "Could not push the CodeBoarding baseline to $branch." } @@ -67,7 +72,7 @@ files_written="$(find "$CHECKOUT_DIR/.codeboarding" -maxdepth 1 -type f \ git fetch "$REMOTE" "$SYNCED_BRANCH" remote_sha="$(git rev-parse FETCH_HEAD)" if [ "$remote_sha" != "$BASE_SHA" ]; then - emit_result "$files_written" false "$BASE_SHA" + emit_result "$files_written" false echo "::notice::$SYNCED_BRANCH advanced during analysis; a newer run should update its baseline." exit 0 fi @@ -77,14 +82,15 @@ fi # every run. Dropping either filter turns every sync into a commit. if git diff --cached --quiet || git diff --cached --quiet -I '"generated_at"' -I '"timestamp"'; then git reset -q - emit_result "$files_written" false "$BASE_SHA" + emit_result "$files_written" false echo "::notice::The CodeBoarding baseline is unchanged." exit 0 fi git commit -m 'chore(codeboarding): sync analysis baseline' >/dev/null -if ! git push "$REMOTE" "HEAD:refs/heads/$SYNCED_BRANCH"; then - classify_push_failure "$BASE_SHA" "$SYNCED_BRANCH" -fi +push_status=0 +push_output="$(git push "$REMOTE" "HEAD:refs/heads/$SYNCED_BRANCH" 2>&1)" || push_status=$? +echo "$push_output" >&2 +[ "$push_status" = 0 ] || classify_push_failure "$BASE_SHA" "$SYNCED_BRANCH" "$push_output" emit_result "$files_written" true "$(git rev-parse HEAD)" diff --git a/scripts/action/sync-generate-baseline.sh b/scripts/action/sync-generate-baseline.sh index 88daf72..58c1e8a 100755 --- a/scripts/action/sync-generate-baseline.sh +++ b/scripts/action/sync-generate-baseline.sh @@ -37,4 +37,6 @@ stage "$state" base { echo "$result" echo "analysis_dir=$state" + # The base is published under this commit whatever the delivery does. + echo "analyzed_sha=$head_sha" } >> "$GITHUB_OUTPUT" diff --git a/tests/test_action_state.py b/tests/test_action_state.py index 0a02ea4..4e53270 100644 --- a/tests/test_action_state.py +++ b/tests/test_action_state.py @@ -1040,6 +1040,30 @@ def test_the_renewal_threshold_matches_the_review_retention(self) -> None: review = next(s for s in self._uploads() if "review_artifact.outputs.artifact_dir" in s.get("path", "")) self.assertIn(f"'{review['retention-days']}'", renew) + def test_the_review_base_is_published_before_the_head_is_analyzed(self) -> None: + # A base built from scratch can take most of the job's time limit; a head + # analysis that then fails or times out must not take it down with it. + names = [s["name"] for s in self._steps()] + self.assertLess(names.index("Generate review baseline"), names.index("Publish base analysis")) + self.assertLess(names.index("Publish base analysis"), names.index("Analyze pull request")) + + def test_sync_publishes_its_analysis_whatever_the_delivery_did(self) -> None: + # A refused push used to throw away a finished analysis, so the next run + # analyzed everything again. + name = "Publish baseline analysis for the analyzed commit" + names = [s["name"] for s in self._steps()] + step = next(s for s in self._uploads() if s["name"] == name) + self.assertGreater(names.index(name), names.index("Deliver baseline")) + self.assertIn("!cancelled()", step["if"]) + self.assertIn("steps.sync_analyze.outcome == 'success'", step["if"]) + self.assertNotIn("sync_commit", step["if"]) + text = (ROOT / "action.yml").read_text(encoding="utf-8") + block = text[text.index(f"- name: {name}") :] + self.assertIn( + "codeboarding-base-${{ steps.state.outputs.cfg_hash }}-${{ steps.sync_analyze.outputs.analyzed_sha }}", + block[: block.index("\n\n")], + ) + def test_the_reusable_analysis_honours_the_configured_retention(self) -> None: warmstart = [s for s in self._uploads() if "warmstart" in s.get("path", "")] self.assertTrue(warmstart, "no warm-start publication step found") diff --git a/tests/test_action_sync.py b/tests/test_action_sync.py index 30ed246..ae99270 100644 --- a/tests/test_action_sync.py +++ b/tests/test_action_sync.py @@ -385,8 +385,9 @@ def tearDown(self) -> None: def _git(self, cwd: Path, *args: str) -> str: return subprocess.run(["git", *args], cwd=str(cwd), capture_output=True, text=True, check=True).stdout.strip() - def test_it_publishes_the_analysis_under_both_commits(self) -> None: + def _deliver(self, **env: str) -> tuple[subprocess.CompletedProcess, dict[str, str]]: output = self.root / "github-output" + output.write_text("", encoding="utf-8") result = subprocess.run( [str(ROOT / "scripts" / "action" / "deliver-sync.sh")], env={ @@ -401,19 +402,51 @@ def test_it_publishes_the_analysis_under_both_commits(self) -> None: "GITHUB_TOKEN": "unused", "REPOSITORY": "owner/repo", "SYNCED_BRANCH": "main", + **env, }, capture_output=True, text=True, check=False, ) - self.assertEqual(result.returncode, 0, result.stderr or result.stdout) - values = dict(line.split("=", 1) for line in output.read_text(encoding="utf-8").splitlines() if "=" in line) + return result, values + + def _protect_main(self) -> None: + hook = self.remote / "hooks" / "pre-receive" + hook.write_text( + '#!/bin/sh\necho "error: GH006: Protected branch update failed for refs/heads/main." >&2\nexit 1\n', + encoding="utf-8", + ) + hook.chmod(0o755) + + def test_it_publishes_the_analysis_under_both_commits(self) -> None: + result, values = self._deliver() + + self.assertEqual(result.returncode, 0, result.stderr or result.stdout) self.assertEqual(values["committed"], "true") - baseline_sha = self._git(self.checkout, "rev-parse", "HEAD") # The analysis describes the tree it ran on and the baseline commit # written on top, which differs only in files the fingerprint ignores. # A pull request branched either side of that commit must hit the cache. - self.assertEqual(values["baseline_sha"], baseline_sha) - self.assertEqual(values["analyzed_sha"], self.analyzed_sha) - self.assertNotEqual(values["baseline_sha"], values["analyzed_sha"]) + self.assertEqual(values["baseline_sha"], self._git(self.checkout, "rev-parse", "HEAD")) + self.assertNotEqual(values["baseline_sha"], self.analyzed_sha) + + def test_a_protected_default_branch_says_to_save_the_analysis_elsewhere(self) -> None: + self._protect_main() + + result, values = self._deliver(DEFAULT_BRANCH="main") + + self.assertNotEqual(result.returncode, 0) + reason = values["failure_reason"] + self.assertIn("Remove `codeboarding_analysis_location: in_place`", reason) + self.assertIn("#keep-the-baseline-current", reason) + self.assertIn(f"::error::{reason}", result.stdout) + + def test_a_protected_branch_other_than_the_default_names_the_bypass(self) -> None: + # codeboarding/baseline holds only the default branch's analysis, so moving there fails too. + self._protect_main() + + result, values = self._deliver(DEFAULT_BRANCH="trunk") + + self.assertNotEqual(result.returncode, 0) + self.assertIn("bypass actor", values["failure_reason"]) + self.assertNotIn("codeboarding_analysis_location", values["failure_reason"]) diff --git a/tests/test_baseline_branch.py b/tests/test_baseline_branch.py index eebc855..60f6b77 100644 --- a/tests/test_baseline_branch.py +++ b/tests/test_baseline_branch.py @@ -105,7 +105,7 @@ def test_the_first_sync_creates_an_orphan_branch_with_its_provenance(self) -> No (only,) = self._branch_log() self.assertEqual(only.split(), [git(self.remote, "rev-parse", BRANCH)], "the branch must have no parent") self.assertEqual(values["committed"], "true") - self.assertEqual(values["baseline_sha"], main_before, "artifacts are named for the analysed commit") + self.assertEqual(values["baseline_sha"], "", "nothing is written on main to publish under") files = set(git(self.remote, "ls-tree", "-r", "--name-only", BRANCH).splitlines()) self.assertEqual( files, @@ -165,11 +165,14 @@ def test_a_push_refused_by_a_branch_rule_says_how_to_fix_it(self) -> None: ) hook.chmod(0o755) - result, _values = self._deliver(expect_ok=False) + result, values = self._deliver(expect_ok=False) self.assertNotEqual(result.returncode, 0) self.assertIn(f"GitHub refused the push to {BRANCH}", result.stdout) self.assertIn("bypass actor", result.stdout) + # The sync summary repeats it, so it says why without opening the log. + self.assertIn("a ruleset or branch protection covers it", values["failure_reason"]) + self.assertIn("COMMIT_STRATEGY.md#the-baseline-branch", values["failure_reason"]) def _check(self, synced: str) -> subprocess.CompletedProcess: (self.root / "check-output").write_text("", encoding="utf-8") @@ -477,9 +480,11 @@ def test_the_branch_outranks_a_baseline_committed_at_the_merge_base(self) -> Non self.assertNotEqual(base["components"], ["stale"]) def test_sync_continues_from_the_branch_tip(self) -> None: - self._analyze(ANALYSIS_KIND="sync") + values = self._analyze(ANALYSIS_KIND="sync") self.assertEqual(self._modes(), ["incremental"]) + # Named before delivery, so the analysis is published even when delivery fails. + self.assertEqual(values["analyzed_sha"], git(self.checkout, "rev-parse", "HEAD")) def test_sync_replaces_the_committed_state_with_the_branch_tip(self) -> None: # Switching from push: the checkout still holds the old committed baseline.