@@ -13,46 +13,28 @@ func TestGitHubLockdownAutodetection(t *testing.T) {
1313 workflow string
1414 expectedDetectStep bool
1515 expectedLockdown string // "auto" means use step output expression, "true" means hardcoded true, "false" means not present
16+ expectIfCondition bool // true if step should have if: condition
1617 description string
1718 }{
1819 {
19- name : "Auto-determination enabled when lockdown not specified and custom token defined " ,
20+ name : "Auto-determination enabled when lockdown not specified" ,
2021 workflow : `---
2122on: issues
2223engine: copilot
2324tools:
2425 github:
2526 mode: local
26- github-token: ${{ secrets.CUSTOM_TOKEN }}
2727 toolsets: [default]
2828---
2929
3030# Test Workflow
3131
32- Test automatic lockdown determination with custom token .
32+ Test automatic lockdown determination.
3333` ,
3434 expectedDetectStep : true ,
3535 expectedLockdown : "auto" ,
36- description : "When lockdown is not specified and custom token is defined, determination step should be added" ,
37- },
38- {
39- name : "No auto-determination when no custom token" ,
40- workflow : `---
41- on: issues
42- engine: copilot
43- tools:
44- github:
45- mode: local
46- toolsets: [default]
47- ---
48-
49- # Test Workflow
50-
51- Test without custom token - should not add determination step.
52- ` ,
53- expectedDetectStep : false ,
54- expectedLockdown : "false" ,
55- description : "When no custom token is defined, no determination step should be added" ,
36+ expectIfCondition : true ,
37+ description : "When lockdown is not specified, determination step should be added with if condition" ,
5638 },
5739 {
5840 name : "No auto-determination when lockdown explicitly set to true" ,
6345 github:
6446 mode: local
6547 lockdown: true
66- github-token: ${{ secrets.CUSTOM_TOKEN }}
6748 toolsets: [default]
6849---
6950
@@ -73,6 +54,7 @@ Test with explicit lockdown enabled.
7354` ,
7455 expectedDetectStep : false ,
7556 expectedLockdown : "true" ,
57+ expectIfCondition : false ,
7658 description : "When lockdown is explicitly true, no determination step and lockdown should be hardcoded" ,
7759 },
7860 {
8466 github:
8567 mode: local
8668 lockdown: false
87- github-token: ${{ secrets.CUSTOM_TOKEN }}
8869 toolsets: [default]
8970---
9071
@@ -94,27 +75,28 @@ Test with explicit lockdown disabled.
9475` ,
9576 expectedDetectStep : false ,
9677 expectedLockdown : "false" ,
78+ expectIfCondition : false ,
9779 description : "When lockdown is explicitly false, no determination step and no lockdown setting" ,
9880 },
9981 {
100- name : "Auto-determination with remote mode and custom token " ,
82+ name : "Auto-determination with remote mode" ,
10183 workflow : `---
10284on: issues
10385engine: copilot
10486tools:
10587 github:
10688 mode: remote
107- github-token: ${{ secrets.CUSTOM_TOKEN }}
10889 toolsets: [default]
10990---
11091
11192# Test Workflow
11293
113- Test auto-determination with remote GitHub MCP and custom token .
94+ Test auto-determination with remote GitHub MCP.
11495` ,
11596 expectedDetectStep : true ,
11697 expectedLockdown : "auto" ,
117- description : "Auto-determination should work with remote mode when custom token is defined" ,
98+ expectIfCondition : true ,
99+ description : "Auto-determination should work with remote mode" ,
118100 },
119101 }
120102
@@ -156,6 +138,13 @@ Test auto-determination with remote GitHub MCP and custom token.
156138 t .Errorf ("%s: Detection step presence = %v, want %v" , tt .description , detectStepPresent , tt .expectedDetectStep )
157139 }
158140
141+ // Check if the step has the if condition when expected
142+ if tt .expectIfCondition && detectStepPresent {
143+ if ! strings .Contains (yaml , "if: secrets.GH_AW_GITHUB_MCP_SERVER_TOKEN != ''" ) {
144+ t .Errorf ("%s: Expected if condition for GH_AW_GITHUB_MCP_SERVER_TOKEN" , tt .description )
145+ }
146+ }
147+
159148 // Check lockdown configuration based on expected value
160149 switch tt .expectedLockdown {
161150 case "auto" :
@@ -187,13 +176,12 @@ engine: claude
187176tools:
188177 github:
189178 mode: local
190- github-token: ${{ secrets.CUSTOM_TOKEN }}
191179 toolsets: [default]
192180---
193181
194182# Test Workflow
195183
196- Test automatic lockdown determination with Claude and custom token .
184+ Test automatic lockdown determination with Claude.
197185`
198186
199187 // Create temporary directory for test
@@ -228,7 +216,12 @@ Test automatic lockdown determination with Claude and custom token.
228216 strings .Contains (yaml , "determine-automatic-lockdown" )
229217
230218 if ! detectStepPresent {
231- t .Error ("Determination step should be present for Claude engine with custom token" )
219+ t .Error ("Determination step should be present for Claude engine" )
220+ }
221+
222+ // Check if the step has the if condition
223+ if ! strings .Contains (yaml , "if: secrets.GH_AW_GITHUB_MCP_SERVER_TOKEN != ''" ) {
224+ t .Error ("Expected if condition for GH_AW_GITHUB_MCP_SERVER_TOKEN in determination step" )
232225 }
233226
234227 // Check if lockdown uses step output expression
0 commit comments