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

Function TestExtractEngineConfig

pkg/cli/audit_expanded_test.go:16–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestExtractEngineConfig(t *testing.T) {
17 tests := []struct {
18 name string
19 awInfoContent string
20 awInfoSubdir string // subdir under tmpDir to place aw_info.json
21 expectedEngine string
22 expectedModel string
23 expectNil bool
24 }{
25 {
26 name: "full engine config",
27 awInfoContent: `{"engine_id":"copilot","engine_name":"GitHub Copilot CLI","model":"gpt-4","version":"1.0.0","cli_version":"2.0.0","event_name":"issues","repository":"owner/repo"}`,
28 expectedEngine: "copilot",
29 expectedModel: "gpt-4",
30 },
31 {
32 name: "minimal engine config",
33 awInfoContent: `{"engine_id":"claude"}`,
34 expectedEngine: "claude",
35 },
36 {
37 name: "empty logs path",
38 expectNil: true,
39 },
40 {
41 name: "with firewall version",
42 awInfoContent: `{"engine_id":"copilot","awf_version":"1.2.3"}`,
43 expectedEngine: "copilot",
44 },
45 {
46 name: "aw_info.json in activation subdirectory",
47 awInfoContent: `{"engine_id":"claude","model":"claude-sonnet"}`,
48 awInfoSubdir: "activation",
49 expectedEngine: "claude",
50 expectedModel: "claude-sonnet",
51 },
52 }
53
54 for _, tt := range tests {
55 t.Run(tt.name, func(t *testing.T) {
56 if tt.expectNil && tt.awInfoContent == "" {
57 result := extractEngineConfigWithInferredEngine("", "")
58 assert.Nil(t, result, "Should return nil for empty logs path")
59 return
60 }
61
62 tmpDir := testutil.TempDir(t, "engine-config-*")
63 targetDir := tmpDir
64 if tt.awInfoSubdir != "" {
65 targetDir = filepath.Join(tmpDir, tt.awInfoSubdir)
66 err := os.MkdirAll(targetDir, 0755)
67 require.NoError(t, err, "Should create subdir")
68 }
69 err := os.WriteFile(filepath.Join(targetDir, "aw_info.json"), []byte(tt.awInfoContent), 0644)
70 require.NoError(t, err, "Should write aw_info.json")
71
72 result := extractEngineConfigWithInferredEngine(tmpDir, "")
73 if tt.expectNil {

Callers

nothing calls this directly

Calls 3

TempDirFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected