-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathconstants_test.go
More file actions
637 lines (544 loc) · 18.9 KB
/
constants_test.go
File metadata and controls
637 lines (544 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
//go:build !integration
package constants
import (
"path/filepath"
"testing"
"time"
)
func TestGetWorkflowDir(t *testing.T) {
expected := filepath.Join(".github", "workflows")
result := GetWorkflowDir()
if result != expected {
t.Errorf("GetWorkflowDir() = %q, want %q", result, expected)
}
}
func TestDefaultAllowedDomains(t *testing.T) {
if len(DefaultAllowedDomains) == 0 {
t.Error("DefaultAllowedDomains should not be empty")
}
expectedDomains := []string{"localhost", "localhost:*", "127.0.0.1", "127.0.0.1:*"}
if len(DefaultAllowedDomains) != len(expectedDomains) {
t.Errorf("DefaultAllowedDomains length = %d, want %d", len(DefaultAllowedDomains), len(expectedDomains))
}
for i, domain := range expectedDomains {
if DefaultAllowedDomains[i] != domain {
t.Errorf("DefaultAllowedDomains[%d] = %q, want %q", i, DefaultAllowedDomains[i], domain)
}
}
}
func TestSafeWorkflowEvents(t *testing.T) {
if len(SafeWorkflowEvents) == 0 {
t.Error("SafeWorkflowEvents should not be empty")
}
// workflow_run is intentionally excluded due to HIGH security risks
expectedEvents := []string{"workflow_dispatch", "schedule"}
if len(SafeWorkflowEvents) != len(expectedEvents) {
t.Errorf("SafeWorkflowEvents length = %d, want %d", len(SafeWorkflowEvents), len(expectedEvents))
}
for i, event := range expectedEvents {
if SafeWorkflowEvents[i] != event {
t.Errorf("SafeWorkflowEvents[%d] = %q, want %q", i, SafeWorkflowEvents[i], event)
}
}
}
func TestAllowedExpressions(t *testing.T) {
if len(AllowedExpressions) == 0 {
t.Error("AllowedExpressions should not be empty")
}
// Test a few key expressions are present
requiredExpressions := []string{
"github.event.issue.number",
"github.event.pull_request.number",
"github.repository",
"github.run_id",
"github.workspace",
}
expressionsMap := make(map[string]bool)
for _, expr := range AllowedExpressions {
expressionsMap[expr] = true
}
for _, required := range requiredExpressions {
if !expressionsMap[required] {
t.Errorf("AllowedExpressions missing required expression: %q", required)
}
}
}
func TestAgenticEngines(t *testing.T) {
if len(AgenticEngines) == 0 {
t.Error("AgenticEngines should not be empty")
}
expectedEngines := []string{"claude", "codex", "copilot", "gemini", "opencode"}
if len(AgenticEngines) != len(expectedEngines) {
t.Errorf("AgenticEngines length = %d, want %d", len(AgenticEngines), len(expectedEngines))
}
for i, engine := range expectedEngines {
if AgenticEngines[i] != engine {
t.Errorf("AgenticEngines[%d] = %q, want %q", i, AgenticEngines[i], engine)
}
}
// Verify that engine constants can be converted to strings for AgenticEngines
if string(ClaudeEngine) != "claude" {
t.Errorf("ClaudeEngine constant = %q, want %q", ClaudeEngine, "claude")
}
if string(CodexEngine) != "codex" {
t.Errorf("CodexEngine constant = %q, want %q", CodexEngine, "codex")
}
if string(CopilotEngine) != "copilot" {
t.Errorf("CopilotEngine constant = %q, want %q", CopilotEngine, "copilot")
}
if string(GeminiEngine) != "gemini" {
t.Errorf("GeminiEngine constant = %q, want %q", GeminiEngine, "gemini")
}
if DefaultEngine != CopilotEngine {
t.Errorf("DefaultEngine = %q, want CopilotEngine (%q)", DefaultEngine, CopilotEngine)
}
}
func TestDefaultGitHubTools(t *testing.T) {
if len(DefaultGitHubToolsLocal) == 0 {
t.Error("DefaultGitHubToolsLocal should not be empty")
}
if len(DefaultGitHubToolsRemote) == 0 {
t.Error("DefaultGitHubToolsRemote should not be empty")
}
if len(DefaultReadOnlyGitHubTools) == 0 {
t.Error("DefaultReadOnlyGitHubTools should not be empty")
}
// Test that DefaultGitHubTools defaults to local mode
if len(DefaultGitHubTools) != len(DefaultGitHubToolsLocal) {
t.Errorf("DefaultGitHubTools should default to DefaultGitHubToolsLocal")
}
// Test that Local and Remote tools reference the same shared list
if len(DefaultGitHubToolsLocal) != len(DefaultReadOnlyGitHubTools) {
t.Errorf("DefaultGitHubToolsLocal should have same length as DefaultReadOnlyGitHubTools, got %d vs %d",
len(DefaultGitHubToolsLocal), len(DefaultReadOnlyGitHubTools))
}
if len(DefaultGitHubToolsRemote) != len(DefaultReadOnlyGitHubTools) {
t.Errorf("DefaultGitHubToolsRemote should have same length as DefaultReadOnlyGitHubTools, got %d vs %d",
len(DefaultGitHubToolsRemote), len(DefaultReadOnlyGitHubTools))
}
// Test a few key tools are present in all lists
requiredTools := []string{
"get_me",
"list_issues",
"pull_request_read",
"get_file_contents",
"search_code",
}
for name, tools := range map[string][]string{
"DefaultGitHubToolsLocal": DefaultGitHubToolsLocal,
"DefaultGitHubToolsRemote": DefaultGitHubToolsRemote,
"DefaultReadOnlyGitHubTools": DefaultReadOnlyGitHubTools,
} {
toolsMap := make(map[string]bool)
for _, tool := range tools {
toolsMap[tool] = true
}
for _, required := range requiredTools {
if !toolsMap[required] {
t.Errorf("%s missing required tool: %q", name, required)
}
}
}
}
func TestDefaultBashTools(t *testing.T) {
if len(DefaultBashTools) == 0 {
t.Error("DefaultBashTools should not be empty")
}
// Test a few key bash tools are present
requiredTools := []string{
"echo",
"ls",
"cat",
"grep",
}
toolsMap := make(map[string]bool)
for _, tool := range DefaultBashTools {
toolsMap[tool] = true
}
for _, required := range requiredTools {
if !toolsMap[required] {
t.Errorf("DefaultBashTools missing required tool: %q", required)
}
}
}
func TestPriorityFields(t *testing.T) {
if len(PriorityStepFields) == 0 {
t.Error("PriorityStepFields should not be empty")
}
if len(PriorityJobFields) == 0 {
t.Error("PriorityJobFields should not be empty")
}
if len(PriorityWorkflowFields) == 0 {
t.Error("PriorityWorkflowFields should not be empty")
}
// Test that "name" is first in step fields
if PriorityStepFields[0] != "name" {
t.Errorf("PriorityStepFields[0] = %q, want %q", PriorityStepFields[0], "name")
}
// Test that "name" is first in job fields
if PriorityJobFields[0] != "name" {
t.Errorf("PriorityJobFields[0] = %q, want %q", PriorityJobFields[0], "name")
}
// Test that "on" is first in workflow fields
if PriorityWorkflowFields[0] != "on" {
t.Errorf("PriorityWorkflowFields[0] = %q, want %q", PriorityWorkflowFields[0], "on")
}
}
func TestConstantValues(t *testing.T) {
tests := []struct {
name string
value string
expected string
}{
{"CLIExtensionPrefix", string(CLIExtensionPrefix), "gh aw"},
{"DefaultMCPRegistryURL", string(DefaultMCPRegistryURL), "https://api.mcp.github.com/v0.1"},
{"AgentJobName", string(AgentJobName), "agent"},
{"ActivationJobName", string(ActivationJobName), "activation"},
{"PreActivationJobName", string(PreActivationJobName), "pre_activation"},
{"DetectionJobName", string(DetectionJobName), "detection"},
{"SafeOutputArtifactName", SafeOutputArtifactName, "safe-output"},
{"AgentOutputArtifactName", AgentOutputArtifactName, "agent-output"},
{"SafeOutputItemsArtifactName", SafeOutputItemsArtifactName, "safe-outputs-items"},
{"SafeOutputsMCPServerID", string(SafeOutputsMCPServerID), "safeoutputs"},
{"CheckMembershipStepID", string(CheckMembershipStepID), "check_membership"},
{"CheckStopTimeStepID", string(CheckStopTimeStepID), "check_stop_time"},
{"CheckSkipIfMatchStepID", string(CheckSkipIfMatchStepID), "check_skip_if_match"},
{"CheckSkipIfNoMatchStepID", string(CheckSkipIfNoMatchStepID), "check_skip_if_no_match"},
{"CheckCommandPositionStepID", string(CheckCommandPositionStepID), "check_command_position"},
{"IsTeamMemberOutput", IsTeamMemberOutput, "is_team_member"},
{"StopTimeOkOutput", StopTimeOkOutput, "stop_time_ok"},
{"SkipCheckOkOutput", SkipCheckOkOutput, "skip_check_ok"},
{"SkipNoMatchCheckOkOutput", SkipNoMatchCheckOkOutput, "skip_no_match_check_ok"},
{"CommandPositionOkOutput", CommandPositionOkOutput, "command_position_ok"},
{"ActivatedOutput", ActivatedOutput, "activated"},
{"DefaultActivationJobRunnerImage", DefaultActivationJobRunnerImage, "ubuntu-slim"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.value != tt.expected {
t.Errorf("%s = %q, want %q", tt.name, tt.value, tt.expected)
}
})
}
}
func TestModelNameConstants(t *testing.T) {
// Test that ModelName type works correctly
tests := []struct {
name string
value ModelName
expected string
}{
{"ModelName basic", ModelName("test-model"), "test-model"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if string(tt.value) != tt.expected {
t.Errorf("%s = %q, want %q", tt.name, tt.value, tt.expected)
}
})
}
}
func TestNumericConstants(t *testing.T) {
tests := []struct {
name string
value LineLength
minValue LineLength
}{
{"MaxExpressionLineLength", MaxExpressionLineLength, 1},
{"ExpressionBreakThreshold", ExpressionBreakThreshold, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.value < tt.minValue {
t.Errorf("%s = %d, should be >= %d", tt.name, tt.value, tt.minValue)
}
})
}
}
func TestTimeoutConstants(t *testing.T) {
// Test new time.Duration-based constants
tests := []struct {
name string
value time.Duration
minValue time.Duration
}{
{"DefaultAgenticWorkflowTimeout", DefaultAgenticWorkflowTimeout, 1 * time.Minute},
{"DefaultToolTimeout", DefaultToolTimeout, 1 * time.Second},
{"DefaultMCPStartupTimeout", DefaultMCPStartupTimeout, 1 * time.Second},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.value < tt.minValue {
t.Errorf("%s = %v, should be >= %v", tt.name, tt.value, tt.minValue)
}
})
}
}
func TestFeatureFlagConstants(t *testing.T) {
// Test that feature flag constants have the correct type and values
tests := []struct {
name string
value FeatureFlag
expected string
}{
{"MCPScriptsFeatureFlag", MCPScriptsFeatureFlag, "mcp-scripts"},
{"MCPGatewayFeatureFlag", MCPGatewayFeatureFlag, "mcp-gateway"},
{"DisableXPIAPromptFeatureFlag", DisableXPIAPromptFeatureFlag, "disable-xpia-prompt"},
{"DIFCProxyFeatureFlag", DIFCProxyFeatureFlag, "difc-proxy"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if string(tt.value) != tt.expected {
t.Errorf("%s = %q, want %q", tt.name, tt.value, tt.expected)
}
})
}
}
func TestFeatureFlagType(t *testing.T) {
// Test that FeatureFlag type can be used as expected
var flag FeatureFlag = "test-flag"
if string(flag) != "test-flag" {
t.Errorf("FeatureFlag conversion failed: got %q, want %q", flag, "test-flag")
}
// Test that constants can be assigned to FeatureFlag variables
mcpScriptsFlag := MCPScriptsFeatureFlag
if mcpScriptsFlag != "mcp-scripts" {
t.Errorf("MCPScriptsFeatureFlag assignment failed: got %q, want %q", mcpScriptsFlag, "mcp-scripts")
}
}
func TestSemanticTypeAliases(t *testing.T) {
// Test URL type
t.Run("URL type", func(t *testing.T) {
var testURL URL = "https://example.com"
if string(testURL) != "https://example.com" {
t.Errorf("URL conversion failed: got %q, want %q", testURL, "https://example.com")
}
// Test DefaultMCPRegistryURL has the correct type
registryURL := DefaultMCPRegistryURL
if string(registryURL) != "https://api.mcp.github.com/v0.1" {
t.Errorf("DefaultMCPRegistryURL = %q, want %q", registryURL, "https://api.mcp.github.com/v0.1")
}
})
// Test ModelName type
t.Run("ModelName type", func(t *testing.T) {
var testModel ModelName = "test-model"
if string(testModel) != "test-model" {
t.Errorf("ModelName conversion failed: got %q, want %q", testModel, "test-model")
}
})
// Test JobName type
t.Run("JobName type", func(t *testing.T) {
var testJob JobName = "test-job"
if string(testJob) != "test-job" {
t.Errorf("JobName conversion failed: got %q, want %q", testJob, "test-job")
}
// Test job name constants have the correct type
agentJob := AgentJobName
if string(agentJob) != "agent" {
t.Errorf("AgentJobName = %q, want %q", agentJob, "agent")
}
activationJob := ActivationJobName
if string(activationJob) != "activation" {
t.Errorf("ActivationJobName = %q, want %q", activationJob, "activation")
}
preActivationJob := PreActivationJobName
if string(preActivationJob) != "pre_activation" {
t.Errorf("PreActivationJobName = %q, want %q", preActivationJob, "pre_activation")
}
detectionJob := DetectionJobName
if string(detectionJob) != "detection" {
t.Errorf("DetectionJobName = %q, want %q", detectionJob, "detection")
}
})
// Test StepID type
t.Run("StepID type", func(t *testing.T) {
var testStep StepID = "test-step"
if string(testStep) != "test-step" {
t.Errorf("StepID conversion failed: got %q, want %q", testStep, "test-step")
}
// Test step ID constants have the correct type
membershipStep := CheckMembershipStepID
if string(membershipStep) != "check_membership" {
t.Errorf("CheckMembershipStepID = %q, want %q", membershipStep, "check_membership")
}
stopTimeStep := CheckStopTimeStepID
if string(stopTimeStep) != "check_stop_time" {
t.Errorf("CheckStopTimeStepID = %q, want %q", stopTimeStep, "check_stop_time")
}
skipMatchStep := CheckSkipIfMatchStepID
if string(skipMatchStep) != "check_skip_if_match" {
t.Errorf("CheckSkipIfMatchStepID = %q, want %q", skipMatchStep, "check_skip_if_match")
}
commandPosStep := CheckCommandPositionStepID
if string(commandPosStep) != "check_command_position" {
t.Errorf("CheckCommandPositionStepID = %q, want %q", commandPosStep, "check_command_position")
}
})
// Test CommandPrefix type
t.Run("CommandPrefix type", func(t *testing.T) {
var testPrefix CommandPrefix = "test-prefix"
if string(testPrefix) != "test-prefix" {
t.Errorf("CommandPrefix conversion failed: got %q, want %q", testPrefix, "test-prefix")
}
// Test CLIExtensionPrefix has the correct type
cliPrefix := CLIExtensionPrefix
if string(cliPrefix) != "gh aw" {
t.Errorf("CLIExtensionPrefix = %q, want %q", cliPrefix, "gh aw")
}
})
// Test WorkflowID type
t.Run("WorkflowID type", func(t *testing.T) {
var testWorkflow WorkflowID = "ci-doctor"
if string(testWorkflow) != "ci-doctor" {
t.Errorf("WorkflowID conversion failed: got %q, want %q", testWorkflow, "ci-doctor")
}
})
// Test EngineName type
t.Run("EngineName type", func(t *testing.T) {
var testEngine EngineName = "copilot"
if string(testEngine) != "copilot" {
t.Errorf("EngineName conversion failed: got %q, want %q", testEngine, "copilot")
}
// Test engine constants have the correct type
copilot := CopilotEngine
if string(copilot) != "copilot" {
t.Errorf("CopilotEngine = %q, want %q", copilot, "copilot")
}
claude := ClaudeEngine
if string(claude) != "claude" {
t.Errorf("ClaudeEngine = %q, want %q", claude, "claude")
}
codex := CodexEngine
if string(codex) != "codex" {
t.Errorf("CodexEngine = %q, want %q", codex, "codex")
}
})
}
func TestTypeSafetyBetweenSemanticTypes(t *testing.T) {
// This test demonstrates that semantic types provide type safety
// by preventing accidental mixing of different string types
// These assignments should work (same types)
job1 := AgentJobName
job2 := ActivationJobName
if job1 == job2 {
t.Error("AgentJobName should not equal ActivationJobName")
}
step1 := CheckMembershipStepID
step2 := CheckStopTimeStepID
if step1 == step2 {
t.Error("CheckMembershipStepID should not equal CheckStopTimeStepID")
}
// Verify that we can still convert to string when needed
if string(job1) != "agent" {
t.Errorf("JobName string conversion failed: got %q, want %q", job1, "agent")
}
if string(step1) != "check_membership" {
t.Errorf("StepID string conversion failed: got %q, want %q", step1, "check_membership")
}
// Verify that different semantic types have different underlying types
// (this is a compile-time check, but we verify the values are correct)
jobStr := string(AgentJobName)
stepStr := string(CheckMembershipStepID)
_ = jobStr // Used for demonstration
_ = stepStr // Used for demonstration
// Different semantic types prevent accidental mixing even if string values match
}
// TestHelperMethods tests the helper methods on semantic types
func TestHelperMethods(t *testing.T) {
t.Run("Version", func(t *testing.T) {
version := Version("1.0.0")
if version.String() != "1.0.0" {
t.Errorf("Version.String() = %q, want %q", version.String(), "1.0.0")
}
if !version.IsValid() {
t.Error("Version.IsValid() = false, want true for non-empty value")
}
emptyVersion := Version("")
if emptyVersion.IsValid() {
t.Error("Version.IsValid() = true, want false for empty value")
}
})
t.Run("JobName", func(t *testing.T) {
job := JobName("agent")
if job.String() != "agent" {
t.Errorf("JobName.String() = %q, want %q", job.String(), "agent")
}
if !job.IsValid() {
t.Error("JobName.IsValid() = false, want true for non-empty value")
}
emptyJob := JobName("")
if emptyJob.IsValid() {
t.Error("JobName.IsValid() = true, want false for empty value")
}
})
t.Run("StepID", func(t *testing.T) {
step := StepID("check_membership")
if step.String() != "check_membership" {
t.Errorf("StepID.String() = %q, want %q", step.String(), "check_membership")
}
if !step.IsValid() {
t.Error("StepID.IsValid() = false, want true for non-empty value")
}
emptyStep := StepID("")
if emptyStep.IsValid() {
t.Error("StepID.IsValid() = true, want false for empty value")
}
})
t.Run("CommandPrefix", func(t *testing.T) {
prefix := CommandPrefix("gh aw")
if prefix.String() != "gh aw" {
t.Errorf("CommandPrefix.String() = %q, want %q", prefix.String(), "gh aw")
}
if !prefix.IsValid() {
t.Error("CommandPrefix.IsValid() = false, want true for non-empty value")
}
emptyPrefix := CommandPrefix("")
if emptyPrefix.IsValid() {
t.Error("CommandPrefix.IsValid() = true, want false for empty value")
}
})
}
func TestGetAllEngineSecretNames(t *testing.T) {
secrets := GetAllEngineSecretNames()
// Should not be empty
if len(secrets) == 0 {
t.Error("GetAllEngineSecretNames() should not return empty slice")
}
// Build a set for easy lookup
secretSet := make(map[string]bool)
for _, s := range secrets {
secretSet[s] = true
}
// Verify primary engine secrets are included
expectedSecrets := []string{
"COPILOT_GITHUB_TOKEN",
"ANTHROPIC_API_KEY",
"OPENAI_API_KEY",
}
for _, expected := range expectedSecrets {
if !secretSet[expected] {
t.Errorf("GetAllEngineSecretNames() missing expected secret: %q", expected)
}
}
// Verify alternative secrets are included
alternativeSecrets := []string{
"CODEX_API_KEY",
}
for _, alt := range alternativeSecrets {
if !secretSet[alt] {
t.Errorf("GetAllEngineSecretNames() missing expected alternative secret: %q", alt)
}
}
// Verify system-level secret is included
if !secretSet["GH_AW_GITHUB_TOKEN"] {
t.Error("GetAllEngineSecretNames() missing GH_AW_GITHUB_TOKEN")
}
// Verify no duplicates
seen := make(map[string]bool)
for _, s := range secrets {
if seen[s] {
t.Errorf("GetAllEngineSecretNames() returned duplicate secret: %q", s)
}
seen[s] = true
}
}