From f27704f0542b492422752abada3dd1a78efeb9e9 Mon Sep 17 00:00:00 2001 From: Matteo Cherubini Date: Wed, 1 Jul 2026 19:56:42 +0200 Subject: [PATCH] test(open-pr): add test for rolling PR branch updates --- tests/open-pr-rolling.bats | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/open-pr-rolling.bats diff --git a/tests/open-pr-rolling.bats b/tests/open-pr-rolling.bats new file mode 100644 index 0000000..3a1d887 --- /dev/null +++ b/tests/open-pr-rolling.bats @@ -0,0 +1,48 @@ +#!/usr/bin/env bats +# open-pr-rolling.bats — a re-ingest of the same slug updates the OPEN PR's branch +# (force-with-lease) instead of failing. Uses the local bare remote from make_fixture_genome. +load helpers +setup_file() { :; } + +@test "open-pr: re-ingest of the same slug rolls the branch forward (force-with-lease)" { + command -v jq >/dev/null 2>&1 || skip "jq not installed" + G="$(make_fixture_genome)"; cd "$G" + export FORGEJO_URL="http://forgejo.local" FORGEJO_USER=u FORGEJO_TOKEN=t DRY_RUN=1 + body="$(mktemp)"; echo body > "$body" + + # first ingest of slug x (v1) + mkdir -p wiki/sources; printf 'v1\n' > wiki/sources/x.md + run bash "$SKILL_SCRIPTS/open-pr.sh" --slug x --title "feat: ingest x" --body-file "$body" --base main + [ "$status" -eq 0 ] + git rev-parse --verify feat/ai-ingest-x + first="$(git rev-parse feat/ai-ingest-x)" + + # simulate clean_start back to base, then an edited re-ingest (v2) + git switch -q main; git reset -q --hard origin/main; git clean -q -fd + printf 'v2-edited\n' > wiki/sources/x.md + run bash "$SKILL_SCRIPTS/open-pr.sh" --slug x --title "feat: ingest x" --body-file "$body" --base main + [ "$status" -eq 0 ] + second="$(git rev-parse feat/ai-ingest-x)" + + # the branch was REBUILT from base (diverged), not appended: second is not a descendant of first + run git merge-base --is-ancestor "$first" "$second" + [ "$status" -ne 0 ] + + # origin received the v2 content (force-with-lease pushed the rebuilt branch) + git fetch -q origin + run git show "origin/feat/ai-ingest-x:wiki/sources/x.md" + [ "$status" -eq 0 ] + [[ "$output" == *"v2-edited"* ]] +} + +@test "open-pr: prune branch override still works after the rolling change" { + command -v jq >/dev/null 2>&1 || skip "jq not installed" + G="$(make_fixture_genome)"; cd "$G" + export FORGEJO_URL="http://forgejo.local" FORGEJO_USER=u FORGEJO_TOKEN=t DRY_RUN=1 + body="$(mktemp)"; echo body > "$body" + mkdir -p wiki/sources; printf 'p\n' > wiki/sources/p.md + run bash "$SKILL_SCRIPTS/open-pr.sh" --branch "chore/prune-orphans-2026-06-30" \ + --title "chore: prune 1 orphaned source(s)" --body-file "$body" --base main + [ "$status" -eq 0 ] + git rev-parse --verify "chore/prune-orphans-2026-06-30" +}