fix: propagate top-level environment: to the detection job#38918
Conversation
…tion test - The `buildDetectionJob` function in `threat_detection.go` already inherits `data.Environment` so the detection job receives the same `environment:` field as `agent`, `conclusion`, `pre_activation`, and `safe_outputs` jobs. - Add `TestDetectionJobEnvironmentPropagation` integration test to `environment_test.go` that compiles a full workflow and asserts the detection job section contains (or omits) the expected `environment:` value. - Refactor `TestSafeOutputsEnvironmentPropagation` to use the pre-existing `extractJobSection` helper from `compiler_test_helpers_test.go`, removing duplicated section-extraction logic. Closes #38900 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
environment: to the detection job
There was a problem hiding this comment.
Pull request overview
Adds an end-to-end integration test to ensure the compiled workflow YAML propagates a top-level environment: to the detection job (and respects the safe-outputs.threat-detection.environment override), and refactors an existing environment propagation test to reuse the shared job-section extraction helper.
Changes:
- Refactor
TestSafeOutputsEnvironmentPropagationto useextractJobSection, removing duplicated YAML slicing logic. - Add
TestDetectionJobEnvironmentPropagationcovering environment propagation and precedence for thedetectionjob across three scenarios.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/environment_test.go | Refactors safe_outputs env assertions to use extractJobSection and adds an integration test verifying detection job environment propagation + override precedence. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
|
@copilot add integration workflow test for this scenario |
…tion Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Added an integration workflow fixture test for this scenario in It now compiles |
When a workflow declares a top-level
environment:, it was propagated toagent,conclusion,pre_activation, andsafe_outputs— but silently skipped fordetection. Thedetectionjob was consumingCOPILOT_GITHUB_TOKENoutside the environment gate, bypassing protection rules on every compile.Changes
pkg/workflow/threat_detection.go—buildDetectionJobalready had the fix in the current tree (environment := data.Environment), matching the same propagation pattern used by other secret-consuming jobs.pkg/workflow/environment_test.go— AddedTestDetectionJobEnvironmentPropagationintegration coverage that compiles workflows end-to-end and asserts:detectioninherits itdetectionhas noenvironment:fieldpkg/workflow/threat_detection_job_combinations_integration_test.go+pkg/cli/workflows/test-copilot-threat-detection-environment.md— Added an integration workflow fixture test that compiles a real workflow file and verifies the generateddetectionjob containsenvironment: production.pkg/workflow/environment_test.go— RefactoredTestSafeOutputsEnvironmentPropagationto use the pre-existingextractJobSectionhelper fromcompiler_test_helpers_test.go, removing duplicated section-extraction logic.