Repository navigation
fix(environments): stop mutating the shared config when expanding branch policies - #1082
Conversation
…nch policies
The Environments constructor rewrote custom_branch_policies on the config
objects it was given. Suborg config is shared by every repo in the suborg,
so the first repo turned ['main'] into [{ name: 'main', type: 'branch' }]
and every later repo saw objects that match neither expansion branch,
ending up with custom branch policies enabled and an empty allowlist.
Clone the entries before normalising them.
Fixes github-community-projects#876
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The fix is covered by targeted regression tests and resolves the shared-config mutation.
Review effort: Lite
Findings: None
What changed in this PR
Prevents environment policy expansion from mutating shared configuration across repositories.
Changes:
- Clones entries before normalizing branch policies.
- Adds regression tests for config immutability and repeated plugin construction.
| File | Description |
|---|---|
test/unit/lib/plugins/environments.test.js |
Tests shared-config behavior. |
lib/plugins/environments.js |
Clones entries before normalization. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Thanks for this. We hit the same bug on 3.0.0 and are rolling this patch out as a patched image while it waits for review. Three things we found along the way may help it land. 1. The empty allowlist fails open, not closed. Here says the result "blocks every deployment with no error". We tested it, and it's the other way round. An environment with custom branch policies enabled ( 2. environments:
- name: a
deployment_branch_policy: &main_only
protected_branches: false
custom_branch_policies:
- type: branch
names: ["main"]
- name: b
deployment_branch_policy: *main_only
- name: c
deployment_branch_policy: *main_only
Making the normalisation idempotent fixes both the cross-repo case this PR targets and the anchor case. That means accepting an entry that's already } else if (typeof policy === 'object' && typeof policy.name === 'string' && !policy.names) {
policies.push({ name: policy.name, type: policy.type || 'branch' })
} else if (typeof policy === 'object' && Array.isArray(policy.names)) {Keeping the 3. Where to look in the wild. We ran 3.0.0's own Happy to open a follow-up PR with the idempotent version and a test for the anchor case if that's useful. |
The
Environmentsconstructor rewritescustom_branch_policieson the config objects it is given. Suborg config is one object shared by every repo in the suborg, so the first repo turns['main']into[{ name: 'main', type: 'branch' }]and every later repo sees objects that match neither expansion branch. Those repos end up with custom branch policies switched on and an empty allowlist, which blocks every deployment with no error.This clones the entries before normalising them. Two tests cover it: the caller's config is left untouched, and a second plugin built from the same config gets the same expanded policies as the first.
The same two tests against
main-enterprise(left) and this branch (right):Fixes #876. The symptom there (custom policies enabled, no rules created, at org and suborg level) matches what we saw on an org with four suborgs declaring the policy.