diff --git a/.github/pr-shape-check.sh b/.github/pr-shape-check.sh new file mode 100755 index 000000000000..b36cf7b85093 --- /dev/null +++ b/.github/pr-shape-check.sh @@ -0,0 +1,163 @@ +#!/bin/bash +set -euo pipefail + +# A pull request into this fork is a sync onto quattro, a topic onto quattro, +# or a layer of a stack whose trunk is quattro. Every topic and layer is held +# to the file cap against its own base and may not carry upstream commits; +# those arrive only through a sync. + +FILE_CAP=40 + +fail() { + printf '%s\n' "$1" >&2 + exit 1 +} + +: "${PR_HEAD_REF:?PR_HEAD_REF is required}" +: "${PR_BASE_REF:?PR_BASE_REF is required}" +: "${PR_NUMBER:?PR_NUMBER is required}" + +is_sync_ref() { + local ref=$1 + [[ $ref == cursor/upstream-changes-pr-* || $ref == cursor/fork-upstream-updates-* || $ref == "i18n-sync" ]] +} + +ensure_commit() { + local sha=$1 + local ref=$2 + if ! git cat-file -e "${sha}^{commit}" 2>/dev/null; then + git fetch --no-tags origin "$ref" || + fail "Could not fetch ${ref}. The shape check needs it to compare this pull request." + fi +} + +if [[ -n ${PR_OPEN_JSON_FILE:-} ]]; then + open_json=$(cat "$PR_OPEN_JSON_FILE") +else + : "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}" + open_json=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --limit 200 --json number,headRefName,baseRefName) || + fail "Could not list open pull requests. The shape check needs that list." +fi + +open_count=$(jq 'length' <<<"$open_json") +if (( open_count == 200 )); then + fail "The open pull request list stopped at 200, so a second sync or a stack layer could be missing. Wait, then rerun the check." +fi + +# The trunk of the stack this pull request belongs to, from GitHub's native +# stack metadata. Empty when it is not in a native stack. +native_stack_trunk() { + local owner name + if [[ -n ${PR_STACK_JSON_FILE:-} ]]; then + jq -r '.baseRefName // empty' "$PR_STACK_JSON_FILE" + return + fi + owner=${GITHUB_REPOSITORY%%/*} + name=${GITHUB_REPOSITORY#*/} + # The $ names are GraphQL variables, not shell expansions. + # shellcheck disable=SC2016 + gh api graphql \ + -f query='query($owner: String!, $name: String!, $number: Int!) { + repository(owner: $owner, name: $name) { + pullRequest(number: $number) { stack { baseRefName } } + } + }' \ + -f owner="$owner" -f name="$name" -F number="$PR_NUMBER" \ + --jq '.data.repository.pullRequest.stack.baseRefName // empty' 2>/dev/null || true +} + +# Walk a hand-built stack down through open pull requests to its trunk. +walked_stack_trunk() { + local base=$1 + local depth layers + for (( depth = 0; depth < 50; depth++ )); do + layers=$(jq -c --arg base "$base" '[.[] | select(.headRefName == $base)]' <<<"$open_json") + case $(jq 'length' <<<"$layers") in + 0) + printf '%s\n' "$base" + return + ;; + 1) + base=$(jq -r '.[0].baseRefName' <<<"$layers") + ;; + *) + fail "More than one open pull request has head ${base}. A stack layer has exactly one pull request." + ;; + esac + done + fail "The stack under ${PR_BASE_REF} is more than 50 layers deep or loops back on itself." +} + +if is_sync_ref "$PR_HEAD_REF"; then + if [[ $PR_BASE_REF != "quattro" ]]; then + fail "A sync targets quattro. Retarget this pull request to quattro." + fi + # The translation branch is its own job. An upstream import does not block + # it, and it does not block an upstream import. + if [[ $PR_HEAD_REF != "i18n-sync" ]]; then + sync_heads=$(jq -r --arg n "$PR_NUMBER" ' + .[] + | select((.number | tostring) != $n) + | select( + (.headRefName | startswith("cursor/upstream-changes-pr-")) + or (.headRefName | startswith("cursor/fork-upstream-updates-")) + ) + | "#\(.number) \(.headRefName) -> \(.baseRefName)" + ' <<<"$open_json") + if [[ -n $sync_heads ]]; then + fail "Another sync is already open: +${sync_heads} +Push onto that branch, or wait until it merges." + fi + fi + printf 'ok - sync %s into %s\n' "$PR_HEAD_REF" "$PR_BASE_REF" + exit 0 +fi + +if [[ $PR_BASE_REF != "quattro" ]]; then + trunk=$(native_stack_trunk) + if [[ -z $trunk ]]; then + trunk=$(walked_stack_trunk "$PR_BASE_REF") + fi + if [[ $trunk != "quattro" ]]; then + fail "This pull request targets ${PR_BASE_REF}, and the stack under it ends at ${trunk}, not quattro. Build the stack with gh stack so its bottom pull request targets quattro, or retarget this pull request to quattro." + fi +fi + +: "${HEAD_SHA:?HEAD_SHA is required}" +: "${BASE_SHA:?BASE_SHA is required}" +ensure_commit "$BASE_SHA" "$PR_BASE_REF" +ensure_commit "$HEAD_SHA" "$HEAD_SHA" + +# Each layer is measured against the branch it targets, so a stack splits a +# large change instead of hiding it above the bottom layer. +file_count=$(git diff --name-only "${BASE_SHA}...${HEAD_SHA}" | grep -c . || true) +if (( file_count > FILE_CAP )); then + fail "This pull request changes ${file_count} files against ${PR_BASE_REF}. The cap is ${FILE_CAP} per pull request. Split it into a stack with gh stack, each layer under the cap, with the bottom layer targeting quattro." +fi + +# Upstream commits that this branch carries and its base does not have mean +# an import is riding in a topic. Stacking on an open sync is fine: the sync +# branch is then the base and already has them. +if [[ -n ${UPSTREAM_REF:-} ]]; then + upstream_ref=$UPSTREAM_REF +else + : "${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is required}" + parent=$(gh api "repos/${GITHUB_REPOSITORY}" --jq '.parent.full_name // empty') || + fail "Could not look up the upstream repository of ${GITHUB_REPOSITORY}." + [[ -n $parent ]] || fail "${GITHUB_REPOSITORY} has no upstream repository to compare against." + git fetch --no-tags "https://github.com/${parent}.git" "+refs/heads/quattro:refs/remotes/upstream/quattro" || + fail "Could not fetch quattro from ${parent}. The shape check needs it to find upstream commits." + upstream_ref=refs/remotes/upstream/quattro +fi + +mapfile -t shared < <(git merge-base --all "$HEAD_SHA" "$upstream_ref" || true) +upstream_count=0 +if (( ${#shared[@]} > 0 )); then + upstream_count=$(git rev-list --count "${shared[@]}" "^${BASE_SHA}") +fi +if (( upstream_count > 0 )); then + fail "This pull request carries ${upstream_count} upstream commits that ${PR_BASE_REF} does not have. Upstream changes arrive only through a sync branch (cursor/upstream-changes-pr-*). Rebase onto ${PR_BASE_REF} without them, or stack this pull request on the open sync." +fi + +printf 'ok - %s into %s (%s files)\n' "$PR_HEAD_REF" "$PR_BASE_REF" "$file_count" diff --git a/.github/workflows/pr-shape.yml b/.github/workflows/pr-shape.yml new file mode 100644 index 000000000000..b34ab513aff1 --- /dev/null +++ b/.github/workflows/pr-shape.yml @@ -0,0 +1,47 @@ +name: Check pull request shape + +# Syncs, topics on quattro, and stacks of any depth whose trunk is quattro are +# the shapes an agent can open. Every topic and stack layer is capped against +# its own base and may not carry upstream commits. i18n-sync is a sync. This +# job runs the shape tests plus the layout and polkit checks. +on: + pull_request: + types: [opened, synchronize, reopened, edited] + +permissions: + contents: read + pull-requests: read + +jobs: + pr-shape: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + - name: Check the pull request shape + env: + PR_HEAD_REF: ${{ github.head_ref }} + PR_BASE_REF: ${{ github.base_ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + GH_TOKEN: ${{ github.token }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: bash .github/pr-shape-check.sh + - name: Install test commands + run: | + sudo apt-get update + sudo apt-get install -y jq lua5.4 + if ! command -v lua >/dev/null; then + sudo ln -sf "$(command -v lua5.4)" /usr/bin/lua + fi + - uses: actions/setup-node@v7 + with: + node-version: 24 + - name: Shape, layout, and polkit tests + run: | + bash test/shell.d/pr-shape-check-test.sh + bash test/shell.d/hyprland-floating-workspaces-test.sh + bash test/shell.d/polkit-face-test.sh diff --git a/AGENTS.md b/AGENTS.md index d3984f4c8d0d..8b7312a438e1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -101,6 +101,16 @@ The experience should be the same on every platform. When a package or feature i - Commits should be atomic: include only one coherent change or fix, and do not mix unrelated work. - Commit messages should be succinct and describe the change being made. +# Pull Requests + +Pull requests go to this fork (`mark-groves/omarchy`), never upstream. `.github/pr-shape-check.sh` enforces the shapes below on every pull request. + +- Prefer a stack of small pull requests over one large one. Build it with GitHub's native stacks through `gh stack` (`gh extension install github/gh-stack`): `gh stack init`, `gh stack add ` for each layer, `gh stack submit` to open the linked pull requests, `gh stack view` to check them. Each layer should be reviewable on its own, the way an atomic commit is. +- The bottom of every stack targets `quattro`. Each layer targets the layer below it. +- Every pull request, each stack layer included, changes at most 40 files against the branch it targets. Over that, split it into more layers. +- Merge a stack from GitHub's stack merge, bottom up. Never merge a layer into `quattro` by hand. +- Upstream changes arrive only through a sync branch (`cursor/upstream-changes-pr-*`), one open at a time, targeting `quattro`. A topic or layer must not carry upstream commits; stack it on the open sync when it needs them. + # Helper Commands Use these instead of raw shell commands: diff --git a/test/shell.d/pr-shape-check-test.sh b/test/shell.d/pr-shape-check-test.sh new file mode 100755 index 000000000000..0e6357937c9f --- /dev/null +++ b/test/shell.d/pr-shape-check-test.sh @@ -0,0 +1,205 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT + +printf '[]\n' >"$scratch/no-prs.json" +printf 'null\n' >"$scratch/no-stack.json" +printf '{"baseRefName":"quattro"}\n' >"$scratch/stack-quattro.json" +printf '{"baseRefName":"dev"}\n' >"$scratch/stack-dev.json" + +# One repository holds the fork and a stand-in for upstream quattro, so every +# commit the check needs is already local and nothing is fetched. +repo=$scratch/repo +git init -q -b quattro "$repo" +git -C "$repo" config user.email test@example.com +git -C "$repo" config user.name Test +git -C "$repo" config commit.gpgsign false + +commit_files() { + local count=$1 + local prefix=${2//\//-} + local i + for (( i = 1; i <= count; i++ )); do + printf '%s\n' "$prefix $i" >"$repo/$prefix-$i" + done + git -C "$repo" add -A + git -C "$repo" commit -q -m "$2" +} + +commit_files 1 base +git -C "$repo" checkout -q -b upstream +commit_files 2 upstream-change +git -C "$repo" checkout -q -b cursor/upstream-changes-pr-aaaa +git -C "$repo" checkout -q quattro + +reset_env() { + PR_NUMBER=1 + PR_OPEN_JSON_FILE=$scratch/no-prs.json + PR_STACK_JSON_FILE=$scratch/no-stack.json + HEAD_SHA= + BASE_SHA= +} + +run_shape() { + shape_status=0 + shape_output=$( + cd "$repo" && + PR_HEAD_REF=$PR_HEAD_REF \ + PR_BASE_REF=$PR_BASE_REF \ + PR_NUMBER=$PR_NUMBER \ + PR_OPEN_JSON_FILE=$PR_OPEN_JSON_FILE \ + PR_STACK_JSON_FILE=$PR_STACK_JSON_FILE \ + HEAD_SHA=$HEAD_SHA \ + BASE_SHA=$BASE_SHA \ + UPSTREAM_REF=upstream \ + bash "$ROOT/.github/pr-shape-check.sh" 2>&1 + ) || shape_status=$? +} + +# A branch off $1 named $2 with $3 changed files; sets HEAD_SHA and BASE_SHA. +topic() { + git -C "$repo" checkout -q -b "$2" "$1" + commit_files "$3" "$2" + BASE_SHA=$(git -C "$repo" rev-parse "$1") + HEAD_SHA=$(git -C "$repo" rev-parse "$2") + git -C "$repo" checkout -q quattro +} + +expect_pass() { + (( shape_status == 0 )) || fail "$1" "$shape_output" + pass "$1" +} + +expect_fail() { + (( shape_status == 1 )) && [[ $shape_output == *"$2"* ]] || fail "$1" "$shape_output" + pass "$1" +} + +reset_env +PR_HEAD_REF=i18n-sync +PR_BASE_REF=quattro +run_shape +expect_pass "the translation sync is exempt from the file cap" + +PR_BASE_REF=dev +run_shape +expect_fail "the translation sync still has to target quattro" "A sync targets quattro. Retarget this pull request to quattro." + +printf '%s\n' '[{"number":9,"headRefName":"cursor/upstream-changes-pr-aaaa","baseRefName":"quattro"}]' >"$scratch/open-sync.json" +PR_BASE_REF=quattro +PR_OPEN_JSON_FILE=$scratch/open-sync.json +run_shape +expect_pass "an open upstream sync does not block the translation sync" + +PR_HEAD_REF=cursor/upstream-changes-pr-bbbb +run_shape +expect_fail "a second upstream sync names the open one" "#9 cursor/upstream-changes-pr-aaaa -> quattro" + +printf '%s\n' '[{"number":9,"headRefName":"i18n-sync","baseRefName":"quattro"}]' >"$scratch/open-i18n.json" +PR_OPEN_JSON_FILE=$scratch/open-i18n.json +run_shape +expect_pass "an open translation sync does not block an upstream sync" + +reset_env +topic quattro cursor/fits-the-cap 40 +PR_HEAD_REF=cursor/fits-the-cap +PR_BASE_REF=quattro +run_shape +expect_pass "a topic of 40 files passes" + +reset_env +topic quattro cursor/oversized-topic 41 +PR_HEAD_REF=cursor/oversized-topic +PR_BASE_REF=quattro +run_shape +expect_fail "a topic over 40 files fails with the stack message" "This pull request changes 41 files against quattro. The cap is 40 per pull request. Split it into a stack with gh stack" + +reset_env +topic quattro i18n-sync-extra 41 +PR_HEAD_REF=i18n-sync-extra +PR_BASE_REF=quattro +run_shape +expect_fail "only the i18n-sync branch is the translation sync" "changes 41 files" + +# A native stack three layers deep: quattro <- layer-1 <- layer-2 <- layer-3. +reset_env +topic quattro layer-1 30 +topic layer-1 layer-2 30 +topic layer-2 layer-3 30 +PR_STACK_JSON_FILE=$scratch/stack-quattro.json +PR_HEAD_REF=layer-3 +PR_BASE_REF=layer-2 +run_shape +expect_pass "a native stack layer is capped against its own base, not quattro" + +topic layer-2 layer-3-oversized 41 +PR_HEAD_REF=layer-3-oversized +run_shape +expect_fail "an oversized layer above the bottom of a stack fails" "changes 41 files against layer-2" + +topic layer-2 layer-3-dev 1 +PR_STACK_JSON_FILE=$scratch/stack-dev.json +PR_HEAD_REF=layer-3-dev +run_shape +expect_fail "a native stack whose trunk is not quattro fails" "the stack under it ends at dev, not quattro" + +# Without native metadata the check walks open pull requests to the trunk. +printf '%s\n' '[ + {"number":11,"headRefName":"layer-1","baseRefName":"quattro"}, + {"number":12,"headRefName":"layer-2","baseRefName":"layer-1"} +]' >"$scratch/walked.json" +reset_env +PR_OPEN_JSON_FILE=$scratch/walked.json +PR_HEAD_REF=layer-3 +PR_BASE_REF=layer-2 +HEAD_SHA=$(git -C "$repo" rev-parse layer-3) +BASE_SHA=$(git -C "$repo" rev-parse layer-2) +run_shape +expect_pass "a hand-built stack of any depth walks down to quattro" + +printf '%s\n' '[ + {"number":11,"headRefName":"layer-1","baseRefName":"dev"}, + {"number":12,"headRefName":"layer-2","baseRefName":"layer-1"} +]' >"$scratch/walked-dev.json" +PR_OPEN_JSON_FILE=$scratch/walked-dev.json +run_shape +expect_fail "a hand-built stack that ends off quattro fails" "the stack under it ends at dev, not quattro" + +PR_OPEN_JSON_FILE=$scratch/no-prs.json +run_shape +expect_fail "a base branch with no pull request under it fails" "the stack under it ends at layer-2, not quattro" + +# Upstream commits only arrive through a sync. +reset_env +git -C "$repo" checkout -q -b cursor/import-in-topic quattro +git -C "$repo" merge -q --no-ff upstream -m "Take upstream" +commit_files 1 import-in-topic +git -C "$repo" checkout -q quattro +PR_HEAD_REF=cursor/import-in-topic +PR_BASE_REF=quattro +HEAD_SHA=$(git -C "$repo" rev-parse cursor/import-in-topic) +BASE_SHA=$(git -C "$repo" rev-parse quattro) +run_shape +expect_fail "a topic carrying upstream commits fails" "carries 1 upstream commits that quattro does not have" + +reset_env +topic cursor/upstream-changes-pr-aaaa cursor/on-the-sync 1 +printf '%s\n' '[{"number":9,"headRefName":"cursor/upstream-changes-pr-aaaa","baseRefName":"quattro"}]' >"$scratch/open-sync.json" +PR_OPEN_JSON_FILE=$scratch/open-sync.json +PR_HEAD_REF=cursor/on-the-sync +PR_BASE_REF=cursor/upstream-changes-pr-aaaa +run_shape +expect_pass "a layer stacked on the open sync passes the upstream check" + +git -C "$repo" merge -q --no-ff upstream -m "Merge sync" +reset_env +topic quattro cursor/after-the-sync 1 +PR_HEAD_REF=cursor/after-the-sync +PR_BASE_REF=quattro +run_shape +expect_pass "a topic after the sync merged does not count upstream commits" diff --git a/test/shell.d/unowned-system-paths-test.sh b/test/shell.d/unowned-system-paths-test.sh index b683a4220089..45f99e3edd5d 100755 --- a/test/shell.d/unowned-system-paths-test.sh +++ b/test/shell.d/unowned-system-paths-test.sh @@ -45,11 +45,6 @@ allowed = { # upgrade carrying the handler is the one that would hit the conflict, and the # handler only helps once it is on disk. Package it the release after. "/usr/lib/chromium/initial_preferences", - # USB and Thunderbolt approval copy their polkit actions from default/polkit - # when that feature is set up. The action exists only for that setup; the - # two files are the whole exception. - "/usr/share/polkit-1/actions/org.omarchy.usb.policy", - "/usr/share/polkit-1/actions/org.omarchy.thunderbolt.policy", } # One-time 3.x upgrade. It runs before this rule existed and cannot be made to