Skip to content

Commit dbb1a79

Browse files
Copilotpelikhan
andauthored
test: add workflow fixture coverage for detection environment propagation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 48f0b7a commit dbb1a79

3 files changed

Lines changed: 41 additions & 21 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description: Test workflow for top-level environment propagation to threat detection
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
task:
7+
description: 'Task summary'
8+
required: true
9+
default: 'Check environment propagation'
10+
11+
environment: production
12+
permissions: read-all
13+
14+
engine: copilot
15+
16+
safe-outputs:
17+
create-issue:
18+
title-prefix: "[bot] "
19+
labels: [automated]
20+
max: 1
21+
threat-detection: true
22+
23+
timeout-minutes: 10
24+
---
25+
26+
# Test Threat Detection Environment Propagation
27+
28+
This workflow verifies that when a top-level `environment` is configured,
29+
the compiled `detection` job inherits it.
30+
31+
Create an issue summarizing the provided task input.

pkg/workflow/environment_test.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ This is a test.`,
342342
}
343343

344344
// TestDetectionJobEnvironmentPropagation verifies that the top-level environment: field is
345-
// propagated to the detection job during full workflow compilation, matching the same
346-
// unconditional fallback used by agent / conclusion / safe_outputs jobs.
345+
// propagated to the detection job during full workflow compilation.
347346
func TestDetectionJobEnvironmentPropagation(t *testing.T) {
348347
tests := []struct {
349348
name string
@@ -384,25 +383,6 @@ This is a test.`,
384383
expectEnvInDet: false,
385384
expectedEnvValue: "",
386385
},
387-
{
388-
name: "threat-detection environment override takes precedence over top-level",
389-
frontmatter: `---
390-
on:
391-
issues:
392-
types: [opened]
393-
environment: production
394-
safe-outputs:
395-
add-comment: {}
396-
threat-detection:
397-
environment: aoai-model
398-
---
399-
400-
# Test Workflow
401-
402-
This is a test.`,
403-
expectEnvInDet: true,
404-
expectedEnvValue: "environment: aoai-model",
405-
},
406386
}
407387

408388
for _, tt := range tests {

pkg/workflow/threat_detection_job_combinations_integration_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ func TestWorkflowFilesCompile(t *testing.T) {
365365

366366
threatFiles := []string{
367367
"test-copilot-threat-detection-expression.md",
368+
"test-copilot-threat-detection-environment.md",
368369
"test-copilot-repo-memory-threat-detection.md",
369370
"test-copilot-repo-memory-threat-detection-expression.md",
370371
"test-copilot-cache-memory-threat-detection.md",
@@ -410,6 +411,14 @@ func TestWorkflowFilesCompile(t *testing.T) {
410411
"file %s should produce a detection job", filename)
411412
}
412413

414+
// Environment fixture must propagate top-level environment to detection.
415+
if filename == "test-copilot-threat-detection-environment.md" {
416+
detectionSection := extractJobSection(yaml, string(constants.DetectionJobName))
417+
require.NotEmpty(t, detectionSection, "detection job section should be present")
418+
assert.Contains(t, detectionSection, "environment: production",
419+
"detection job in %s should inherit top-level environment", filename)
420+
}
421+
413422
// Repo-memory files should produce push_repo_memory job
414423
if strings.Contains(filename, "repo-memory") {
415424
assert.Contains(t, yaml, " push_repo_memory:",

0 commit comments

Comments
 (0)