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

Function TestBuildAWFConfigJSON

pkg/workflow/awf_config_test.go:20–933  ·  view source on GitHub ↗

TestBuildAWFConfigJSON verifies that BuildAWFConfigJSON produces a valid JSON config that contains the expected network, apiProxy, and container fields.

(t *testing.T)

Source from the content-addressed store, hash-verified

18// TestBuildAWFConfigJSON verifies that BuildAWFConfigJSON produces a valid JSON config
19// that contains the expected network, apiProxy, and container fields.
20func TestBuildAWFConfigJSON(t *testing.T) {
21 t.Run("basic config with allowed domains and API proxy enabled", func(t *testing.T) {
22 // Clear any ambient env override so the assertion below tests the built-in default.
23 t.Setenv(compilerenv.DefaultMaxTurnCacheMisses, "")
24 config := AWFCommandConfig{
25 EngineName: "copilot",
26 AllowedDomains: "github.com,api.github.com",
27 WorkflowData: &WorkflowData{
28 EngineConfig: &EngineConfig{ID: "copilot"},
29 NetworkPermissions: &NetworkPermissions{
30 Firewall: &FirewallConfig{Enabled: true},
31 },
32 },
33 }
34
35 jsonStr, err := BuildAWFConfigJSON(config)
36 require.NoError(t, err, "BuildAWFConfigJSON should not return an error")
37
38 // Must be valid JSON
39 var parsed map[string]any
40 require.NoError(t, json.Unmarshal([]byte(jsonStr), &parsed), "result must be valid JSON")
41
42 // Schema reference
43 assert.Contains(t, jsonStr, "$schema", "should include $schema reference")
44
45 // Network section with allowDomains
46 assert.Contains(t, jsonStr, `"allowDomains"`, "should include allowDomains")
47 assert.Contains(t, jsonStr, "github.com", "should include github.com in allowDomains")
48 assert.Contains(t, jsonStr, "api.github.com", "should include api.github.com in allowDomains")
49
50 // apiProxy section with enabled: true
51 assert.Contains(t, jsonStr, `"apiProxy"`, "should include apiProxy section")
52 assert.Contains(t, jsonStr, `"enabled":true`, "apiProxy should be enabled")
53 assert.Contains(t, jsonStr, fmt.Sprintf(`"maxRuns":%d`, constants.DefaultMaxRuns), "apiProxy should emit default maxRuns")
54 assert.Contains(t, jsonStr, fmt.Sprintf(`"maxCacheMisses":%d`, constants.DefaultMaxTurnCacheMisses), "apiProxy should emit default maxCacheMisses")
55 assert.NotContains(t, jsonStr, `"maxEffectiveTokens"`, "apiProxy should omit maxEffectiveTokens when unset")
56
57 // container.imageTag
58 assert.Contains(t, jsonStr, `"imageTag"`, "should include imageTag")
59
60 // logging section
61 assert.Contains(t, jsonStr, `"logging"`, "should include logging section")
62 assert.Contains(t, jsonStr, `"proxyLogsDir":"/tmp/gh-aw/sandbox/firewall/logs"`, "should include proxyLogsDir")
63 assert.Contains(t, jsonStr, `"auditDir":"/tmp/gh-aw/sandbox/firewall/audit"`, "should include auditDir")
64 })
65
66 t.Run("platform config is omitted when sandbox agent is disabled", func(t *testing.T) {
67 config := AWFCommandConfig{
68 EngineName: "copilot",
69 AllowedDomains: "github.com",
70 WorkflowData: &WorkflowData{
71 EngineConfig: &EngineConfig{ID: "copilot"},
72 NetworkPermissions: &NetworkPermissions{
73 Firewall: &FirewallConfig{Enabled: true},
74 },
75 SandboxConfig: &SandboxConfig{
76 Agent: &AgentSandboxConfig{
77 Type: SandboxTypeAWF,

Callers

nothing calls this directly

Calls 4

BuildAWFConfigJSONFunction · 0.85
TemplatableBoolTypeAlias · 0.85
SetenvMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected