Skip to content

The merge policy judges owner approval and reads required checks in Go #861

Description

@tbhb-agent

Problem

Two more pieces of merge-policy.py decide whether an unattended merge may go on: evaluate, which turns the inspection and a pull request's reviews into "owner required" and findings (about 55 lines), and required, which reads the applied branch rules and the ruleset files at the pinned base to name the required checks (about 95 lines, including branch pattern matching and rule parsing). Both are Python run through uv, on the golden list, and under the shell freeze in #588. An empty required set must stay a refusal.

Part of #324, within #588. Child 03 in #324's Children list. Replaces the evaluate and required parts of packages/agents/source/skills/merge-pr/shared/scripts/merge-policy.py.

Acceptance criteria

  1. AC1: Given an inspection result, a reviewer login, a head and a saved pull request snapshot, when agentrepo merge policy evaluate runs, then it prints JSON with owner_required, findings, owner_paths and owner_rule equal to the frozen helper's on the same fixtures.
  2. AC2: Given findings that are all golden-file changes, when the required reviewer's latest decisive review (APPROVED, CHANGES_REQUESTED or DISMISSED, latest by submission time) is an unedited APPROVED review by a Bot on the exact head, the snapshot's head is that head, and its body begins with the header-and-statement prefix Reviewed head: <40-hex SHA> (the SHA optionally in backticks and equal to the head), then an optional Model: line, then Loosens: no, with only the permitted characters and a single Loosens: statement, then owner review is waived with the rule text App review states Loosens: no; given any other finding, review state, author type, edit, missing or malformed prefix, SHA mismatch, or head, then owner review is required with the rule text owner approval. Text that follows the prefix after a blank line is permitted when the character and uniqueness constraints still hold.
  3. AC3: Given carriage-return line endings (normalized), tabs, backticks around the SHA, trailing blank lines after Loosens: no, additional body text after a blank line (the existing positive fixture in loosens.bats), or a body with a second Loosens: mention, when the waiver is judged, then each is accepted or rejected exactly as the frozen helper does; given two decisive reviews with the same submission time, then the waiver is not granted.
  4. AC4: Given applied branch rules and ruleset files at the pinned base, when agentrepo merge policy required runs, then it prints one required check name per line, sorted, the union of both, equal to the frozen helper's.
  5. AC5: Given a ruleset whose ref patterns include the base branch, the default branch token, or neither, or whose excludes match, or that is not an active branch ruleset, when rules are selected, then only matching rulesets contribute names.
  6. AC6: Given rules or ruleset files that cannot be parsed, or a ruleset directory outside the repository, when the command runs, then it exits 1 with merge policy unreadable: <reason>, and an unreadable file never yields a shorter list that passes.
  7. AC7: Given no required check is known for the base, or an empty check name, when the command runs, then it exits 1 with merge policy unreadable: No required checks are known for the base and prints nothing on stdout, so the caller refuses.
  8. AC8: Non-functional: ruleset files are read from the pinned base commit rather than the working tree, and the new commands run on macOS, Linux and Windows in CI.

Scope and non-goals

Scope: evaluate and required, their agentrepo merge policy subcommands, and tests ported from policy.bats, from the waiver cases in loosens.bats and from the required-ruleset cases in workflow.bats.

Non-goal: calling GitHub; the applied rules arrive on stdin exactly as today. Non-goal: the check verdict, which stays in agentrepo checks evaluate. Non-goal: editing the shell scripts before child 14.

Approach

Meet AC1 to AC8 with failing cases first: golden JSON and name lists from the frozen helper on fixtures taken from the Bats files named in Scope, then Go matching them. Mechanism is the implementer's choice.

Dependencies

Blocked by: #860, #333.

Prerequisites: #321 (configuration readers) and #333.

Size

S. One pull request.

Verify plan

  • AC1, AC2, AC3: golden comparison against the frozen helper on the waiver fixtures of loosens.bats, with a case per accepted and rejected body shape, including the trailing-text, tab and CRLF fixtures and the positive fixture at tests/skills/agent-merge-pr/loosens.bats:142.
  • AC4, AC5: table-driven rule and ruleset fixtures from workflow.bats and policy.bats.
  • AC6, AC7: malformed-input and empty-set table checking exit status, stdout and the stderr text.
  • AC8: a test that moves a ruleset file in the working tree only and sees it ignored; the CI matrix run.
  • Definition of done: D1 each AC is verified at the merged head, with the commands and results cited in the pull request's Verification. D2 an independent review approves the exact merged head, and every finding has a recorded disposition. D3 required checks pass with no gate loosened. D4 the leak scans the repository specifies are clean, and every post made for this work passes the per-post leak review before it is posted. D5 every commit is signed. D6 the documentation matches the change or the Verification says why there is no impact. D7 every commit has an Assisted-by trailer and the pull request has the provenance:agent-assisted label. D8 the pull request stays within the size limits. D9 follow-ups are filed as issues and listed under Related. D10 the merge closes the issue through a closing reference, the board shows Done, and the final Status: comment names the merge commit.

Risks

A shorter required list than the base enforces would let an unattended merge skip a check, and a looser waiver would let a golden change skip owner review. AC6 and AC7 hold the refusal, AC2 and AC3 hold the waiver boundary, and the parity fixtures include a missing ruleset. Undo: revert; no caller depends on it yet.

Operator authority

None. No owner-tier path is edited here.

Activity

  1. tbhb-agent commented on Oct 27, 2026

    @tbhb-agent
    ContributorAuthor

    Refinement: READY — The merge policy judges owner approval and reads required checks in Go
    Model: gpt-6-astra

    Child 03 The merge policy judges owner approval and reads required checks in Go

    Verdict: READY

    Checked: The accepted review prefix now permits qualifying trailing text, tabs and normalized CRLF, preserving tests/skills/agent-merge-pr/loosens.bats:142. Tied reviews, empty required sets and malformed rules have explicit outcomes and checks. The contracts match packages/agents/source/skills/merge-pr/shared/scripts/merge-policy.py:541 and packages/agents/source/skills/merge-pr/shared/scripts/merge-policy.py:667.

    Gaps: None.

    Split: None needed.

    Definition of done

    The definition of done for this issue (Feature). Tick each item and give its evidence.

    • D1 The author verified each AC on the merged head, and the Verification section of the pull request cites each AC ID with its evidence: the command and its result, or a link.
    • D2 An independent reviewer approved the exact merged head, and the author resolved each finding or filed it as a follow-up.
    • D3 The required checks pass on that head, and any loosened gate has the owner's approval of that exact head.
    • D4 The leak scans come back clean: gitleaks, devtools' check-leaks.sh with the repository's private-strings list, and the leak review of each post.
    • D5 The author signed each commit, the squash included.
    • D6 The docs match the change (README, docs/, CHANGELOG or help text), or the Verification section says "No doc impact" and why.
    • D7 The commits and the squash have Assisted-by trailers, and the pull request has the provenance:agent-assisted label.
    • D8 The pull request stays within the size limits, or the owner approved its exact head over the hard limit.
    • D9 The author files follow-ups and deferred findings as issues with at least a Problem and numbered AC and lists them under the Related section of the pull request. Any work left in the code links its issue.
    • D10 The merge closes the issue through a closing reference and the board shows Done. The final Status: comment names the merge commit.
    • devtools-1 mise run check is green, and so are the coverage floors mise run cover-go-check and mise run cover-py-check, which check doesn't run.
    • devtools-2 A change to skill sources under packages/agents/source/ commits what mise run generate-skills, then mise run skill-tokens, then apm install rewrite, in that order, and check-generated-skills (part of lint) passes.
    • devtools-3 A consumer-visible change (the vendored payload, a skill, a reusable workflow, a task or a pin) has its consumer steps in docs/agent-skills-migration.md or the adoption docs, or the PR's Verification says "No consumer impact" and why.

    Round: 3 of 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refinement:readyPassed the Definition of Ready; may be picked up

    Fields

    Priority

    None yet

    Work type

    None yet

    Projects

    • Status
      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions