Repository navigation
Description
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
- AC1: Given an inspection result, a reviewer login, a head and a saved pull request snapshot, when
agentrepo merge policy evaluateruns, then it prints JSON withowner_required,findings,owner_pathsandowner_ruleequal to the frozen helper's on the same fixtures. - 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 optionalModel:line, thenLoosens: no, with only the permitted characters and a singleLoosens:statement, then owner review is waived with the rule textApp 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 textowner approval. Text that follows the prefix after a blank line is permitted when the character and uniqueness constraints still hold. - 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 inloosens.bats), or a body with a secondLoosens: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. - AC4: Given applied branch rules and ruleset files at the pinned base, when
agentrepo merge policy requiredruns, then it prints one required check name per line, sorted, the union of both, equal to the frozen helper's. - 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.
- 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. - 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 baseand prints nothing on stdout, so the caller refuses. - 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
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 attests/skills/agent-merge-pr/loosens.bats:142. - AC4, AC5: table-driven rule and ruleset fixtures from
workflow.batsandpolicy.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-bytrailer and the pull request has theprovenance:agent-assistedlabel. 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 finalStatus: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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Work type
Projects
- StatusShow more project fieldsBacklog
Activity
tbhb-agent commentedon Oct 27, 2026
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 matchpackages/agents/source/skills/merge-pr/shared/scripts/merge-policy.py:541andpackages/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.
check-leaks.shwith the repository's private-strings list, and the leak review of each post.docs/, CHANGELOG or help text), or the Verification section says "No doc impact" and why.provenance:agent-assistedlabel.Status:comment names the merge commit.mise run checkis green, and so are the coverage floorsmise run cover-go-checkandmise run cover-py-check, whichcheckdoesn't run.packages/agents/source/commits whatmise run generate-skills, thenmise run skill-tokens, thenapm installrewrite, in that order, andcheck-generated-skills(part oflint) passes.docs/agent-skills-migration.mdor the adoption docs, or the PR's Verification says "No consumer impact" and why.Round: 3 of 3