Repository navigation
🤖 feat: Add PR Automation Config and Record #16809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
berry-13
wants to merge
14
commits into
dev
Choose a base branch
from
feat/pr-automation-record
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8155da3
feat: Add PR Automation Config and Record
berry-13 3778aa1
fix: Address Review Findings on PR Automation Record
berry-13 574eb69
fix: Fence PR Automation Rebinding and Deletion
berry-13 a69ffb9
fix: Bind PR Automation Claims to the Pull Request
berry-13 d7f62b8
fix: Keep PR Automation Fences Through Restart, Rebind and Retention
berry-13 861c213
fix: Fence PR Automation Stops, Removals and Time Window
berry-13 ae01737
fix: Give PR Automation Deletion Fences a Way Out and Cover First-Tim…
berry-13 b27446a
refactor: Check PR Automation Liveness at Claim Instead of Fencing De…
berry-13 7c93db0
fix: Undo Rejected PR Automation Claims and Fence Event Stops by Run
berry-13 fe93799
fix: Walk the Full Subagent Lineage and Fence PR Automation Enables a…
berry-13 74ba57b
fix: Fence PR Automation Claims and Bot Removals by Epoch and Read Li…
berry-13 629bcf7
fix: Read PR Automation Lineage Without graphLookup and Restore the T…
berry-13 df456e4
fix: Keep Rejected PR Automation Enables Unclaimable and Scope Lineag…
berry-13 e1fb0ef
fix: Clamp PR Automation Trust to the Admin Ceiling and Commit Enable…
berry-13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import type { PRAutomationTrustLevel } from './types/prAutomation'; | ||
| import { clampPRAutomationTrust } from './types/prAutomation'; | ||
| import { configSchema } from './config'; | ||
|
|
||
| describe('clampPRAutomationTrust', () => { | ||
| it('defaults to the narrowest level when the user chose nothing', () => { | ||
| expect(clampPRAutomationTrust(undefined, 'anyone')).toBe('approvedBots'); | ||
| }); | ||
|
|
||
| it.each<[PRAutomationTrustLevel, PRAutomationTrustLevel, PRAutomationTrustLevel]>([ | ||
| ['anyone', 'approvedBots', 'approvedBots'], | ||
| ['collaborators', 'approvedBots', 'approvedBots'], | ||
| ['anyone', 'collaborators', 'collaborators'], | ||
| ['approvedBots', 'anyone', 'approvedBots'], | ||
| ['collaborators', 'anyone', 'collaborators'], | ||
| ['anyone', 'anyone', 'anyone'], | ||
| ])('requested %s under a %s ceiling gives %s', (requested, ceiling, expected) => { | ||
| expect(clampPRAutomationTrust(requested, ceiling)).toBe(expected); | ||
| }); | ||
|
|
||
| it('falls back to the narrowest level for a value it does not know', () => { | ||
| expect(clampPRAutomationTrust('everyone' as unknown as PRAutomationTrustLevel, 'anyone')).toBe( | ||
| 'approvedBots', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('agent PR automation config', () => { | ||
| const parse = (prAutomation?: unknown) => | ||
| configSchema.safeParse({ version: '1.0', endpoints: { agents: { prAutomation } } }); | ||
|
|
||
| it('is absent when not configured, which leaves it off', () => { | ||
| const absent = configSchema.parse({ version: '1.0', endpoints: { agents: {} } }); | ||
| expect(absent.endpoints?.agents?.prAutomation).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('defaults to disabled with the narrowest ceiling', () => { | ||
| const empty = configSchema.parse({ | ||
| version: '1.0', | ||
| endpoints: { agents: { prAutomation: {} } }, | ||
| }); | ||
| expect(empty.endpoints?.agents?.prAutomation).toEqual({ | ||
| enabled: false, | ||
| maxRounds: 5, | ||
| maxMinutes: 120, | ||
| maxBots: 20, | ||
| maxTrust: 'approvedBots', | ||
| }); | ||
| }); | ||
|
|
||
| it('accepts an administrator raising the limits and the ceiling', () => { | ||
| const result = parse({ | ||
| enabled: true, | ||
| maxRounds: 10, | ||
| maxMinutes: 240, | ||
| maxTrust: 'collaborators', | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it.each([0, 21, 1.5])('rejects %s fix rounds', (maxRounds) => { | ||
| expect(parse({ maxRounds }).success).toBe(false); | ||
| }); | ||
|
|
||
| it.each([4, 1441, 1.5])('rejects a %s minute window', (maxMinutes) => { | ||
| expect(parse({ maxMinutes }).success).toBe(false); | ||
| }); | ||
|
|
||
| it.each([0, 101, 1.5])('rejects %s approved bots per repository', (maxBots) => { | ||
| expect(parse({ maxBots }).success).toBe(false); | ||
| }); | ||
|
|
||
| it('accepts the largest approved bot limit', () => { | ||
| expect(parse({ maxBots: 100 }).success).toBe(true); | ||
| }); | ||
|
|
||
| it.each(['everyone', 'bots', ''])('rejects %s as a trust ceiling', (maxTrust) => { | ||
| expect(parse({ maxTrust }).success).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| export const PR_AUTOMATION_STATES = ['idle', 'waiting', 'fixing', 'needs_user', 'stopped'] as const; | ||
|
|
||
| /** | ||
| * Stable, machine-readable reasons an automation stopped. The client maps each | ||
| * code to localized copy; none of them carries provider text or a comment body. | ||
| */ | ||
| export const PR_AUTOMATION_STOP_CODES = [ | ||
| 'user_stopped', | ||
| 'round_cap', | ||
| 'time_cap', | ||
| 'fork_pull_request', | ||
| 'untrusted_head_commit', | ||
| 'approval_expired', | ||
| 'pull_request_closed', | ||
| 'disabled_by_admin', | ||
| ] as const; | ||
|
|
||
| /** Largest per-repository bot allowlist a deployment can configure. */ | ||
| export const MAX_PR_AUTOMATION_BOTS = 100; | ||
| export const DEFAULT_PR_AUTOMATION_BOTS = 20; | ||
|
|
||
| /** Ordered from narrowest to widest: who may be acted on. */ | ||
| export const PR_AUTOMATION_TRUST_LEVELS = ['approvedBots', 'collaborators', 'anyone'] as const; | ||
|
|
||
| export type PRAutomationState = (typeof PR_AUTOMATION_STATES)[number]; | ||
| export type PRAutomationStopCode = (typeof PR_AUTOMATION_STOP_CODES)[number]; | ||
| export type PRAutomationTrustLevel = (typeof PR_AUTOMATION_TRUST_LEVELS)[number]; | ||
|
|
||
| /** | ||
| * An administrator's ceiling bounds what a user may choose. A user can only | ||
| * narrow it, so the result is whichever level is narrower. | ||
| */ | ||
| export function clampPRAutomationTrust( | ||
| requested: PRAutomationTrustLevel | undefined, | ||
| ceiling: PRAutomationTrustLevel, | ||
| ): PRAutomationTrustLevel { | ||
| if (requested == null) { | ||
| return PR_AUTOMATION_TRUST_LEVELS[0]; | ||
| } | ||
| const requestedRank = PR_AUTOMATION_TRUST_LEVELS.indexOf(requested); | ||
| const ceilingRank = PR_AUTOMATION_TRUST_LEVELS.indexOf(ceiling); | ||
| if (requestedRank < 0) { | ||
| return PR_AUTOMATION_TRUST_LEVELS[0]; | ||
| } | ||
| return PR_AUTOMATION_TRUST_LEVELS[Math.min(requestedRank, ceilingRank)]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this commit, setting
endpoints.agents.prAutomation.enabledtotruehas no observable effect: a repo-wide search finds the new enable/claim operations only in their definitions and tests, while production consumers call only stop/delete during cleanup. There is no route, webhook orchestration, or frontend entry point that enables a record or starts a round, so administrators can opt into a capability that no user can invoke. Add the owning backend flow and frontend controls, or defer exposing this configuration until they ship.AGENTS.md reference: AGENTS.md:L49-L52
Useful? React with 👍 / 👎.