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

Function TestAddCommentFooterConfiguration

pkg/workflow/safe_outputs_footer_test.go:29–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestAddCommentFooterConfiguration(t *testing.T) {
30 t.Run("footer: false on add-comment", func(t *testing.T) {
31 compiler := NewCompiler()
32 frontmatter := map[string]any{
33 "name": "Test",
34 "safe-outputs": map[string]any{
35 "add-comment": map[string]any{"footer": false},
36 },
37 }
38 config := compiler.extractSafeOutputsConfig(frontmatter)
39 require.NotNil(t, config)
40 require.NotNil(t, config.AddComments)
41 require.NotNil(t, config.AddComments.Footer)
42 assert.Equal(t, "false", *config.AddComments.Footer, "add-comment footer should be false")
43 })
44
45 t.Run("global footer: false propagates to add-comment", func(t *testing.T) {
46 compiler := NewCompiler()
47 frontmatter := map[string]any{
48 "name": "Test",
49 "safe-outputs": map[string]any{
50 "footer": false,
51 "add-comment": map[string]any{},
52 },
53 }
54 config := compiler.extractSafeOutputsConfig(frontmatter)
55 require.NotNil(t, config)
56 require.NotNil(t, config.Footer)
57 assert.False(t, *config.Footer, "Global footer should be false")
58
59 workflowData := &WorkflowData{
60 Name: "Test",
61 SafeOutputs: config,
62 }
63 var steps []string
64 compiler.addHandlerManagerConfigEnvVar(&steps, workflowData)
65
66 for _, step := range steps {
67 if strings.Contains(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG") {
68 parts := strings.Split(step, "GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG: ")
69 if len(parts) == 2 {
70 jsonStr := strings.TrimSpace(parts[1])
71 jsonStr = strings.Trim(jsonStr, "\"")
72 jsonStr = strings.ReplaceAll(jsonStr, "\\\"", "\"")
73 var handlerConfig map[string]any
74 err := json.Unmarshal([]byte(jsonStr), &handlerConfig)
75 require.NoError(t, err)
76
77 addCommentConfig, ok := handlerConfig["add_comment"].(map[string]any)
78 require.True(t, ok, "add_comment handler config should exist")
79 assert.Equal(t, false, addCommentConfig["footer"], "add_comment should inherit global footer: false")
80 }
81 }
82 }
83 })
84}
85
86func TestGlobalFooterConfiguration(t *testing.T) {

Callers

nothing calls this directly

Calls 4

NewCompilerFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected