MCPcopy Create free account
hub / github.com/github/gh-aw / TestCompilerNetworkPermissionsExtraction

Function TestCompilerNetworkPermissionsExtraction

pkg/workflow/network_test.go:12–266  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestCompilerNetworkPermissionsExtraction(t *testing.T) {
13 compiler := NewCompiler()
14
15 // Helper function to create a temporary workflow file for testing
16 createTempWorkflowFile := func(content string) (string, func()) {
17 tmpDir, err := os.MkdirTemp("", "test-workflow-")
18 if err != nil {
19 t.Fatalf("Failed to create temp dir: %v", err)
20 }
21
22 filePath := filepath.Join(tmpDir, "test.md")
23 err = os.WriteFile(filePath, []byte(content), 0644)
24 if err != nil {
25 t.Fatalf("Failed to write temp file: %v", err)
26 }
27
28 cleanup := func() {
29 os.RemoveAll(tmpDir)
30 }
31
32 return filePath, cleanup
33 }
34
35 t.Run("Extract top-level network permissions", func(t *testing.T) {
36 yamlContent := `---
37on: push
38engine:
39 id: claude
40 model: claude-3-5-sonnet-20241022
41network:
42 allowed:
43 - "github.com"
44 - "*.example.com"
45 - "api.trusted.com"
46strict: false
47---
48
49# Test Workflow
50This is a test workflow with network permissions.`
51
52 filePath, cleanup := createTempWorkflowFile(yamlContent)
53 defer cleanup()
54
55 workflowData, err := compiler.ParseWorkflowFile(filePath)
56 if err != nil {
57 t.Fatalf("Failed to parse workflow: %v", err)
58 }
59
60 if workflowData.NetworkPermissions == nil {
61 t.Fatal("Expected network permissions to be extracted")
62 }
63
64 expectedDomains := []string{"github.com", "*.example.com", "api.trusted.com"}
65 if len(workflowData.NetworkPermissions.Allowed) != len(expectedDomains) {
66 t.Fatalf("Expected %d allowed domains, got %d", len(expectedDomains), len(workflowData.NetworkPermissions.Allowed))
67 }
68
69 for i, expected := range expectedDomains {

Callers

nothing calls this directly

Calls 6

ParseWorkflowFileMethod · 0.95
NewCompilerFunction · 0.85
cleanupFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected