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

Function TestSafeOutputStateFieldCoverage

pkg/workflow/safe_outputs_state_test.go:18–49  ·  view source on GitHub ↗

TestSafeOutputStateFieldCoverage verifies that hasAnySafeOutputEnabled and hasNonBuiltinSafeOutputsEnabled cover every descriptor-managed pointer field. This acts as a regression guard to ensure that when a new safe output descriptor is added, the developer is reminded (via a failing test) to also u

(t *testing.T)

Source from the content-addressed store, hash-verified

16// descriptor is added, the developer is reminded (via a failing test) to also
17// update the two direct-check functions.
18func TestSafeOutputStateFieldCoverage(t *testing.T) {
19 for _, handler := range safeOutputHandlers {
20 if handler.StructField == "ReportIncomplete" || handler.StructField == "ThreatDetection" {
21 // These are auto-defaulted policy controls, not action handlers. They are
22 // intentionally excluded from hasAnySafeOutputEnabled/hasNonBuiltinSafeOutputsEnabled
23 // so defaults don't count as explicit user-enabled safe outputs.
24 continue
25 }
26 t.Run(handler.StructField, func(t *testing.T) {
27 // Build a SafeOutputsConfig with only this one field set to a non-nil value.
28 cfg := &SafeOutputsConfig{}
29 val := reflect.ValueOf(cfg).Elem()
30 field := val.FieldByName(handler.StructField)
31 require.True(t, field.IsValid(),
32 "safeOutputHandlers references unknown struct field %q; update descriptors or struct", handler.StructField)
33 require.Equal(t, reflect.Pointer, field.Kind(),
34 "safeOutputHandlers field %q is expected to be a pointer type", handler.StructField)
35
36 field.Set(reflect.New(field.Type().Elem()))
37
38 // hasAnySafeOutputEnabled must return true for every descriptor field.
39 assert.True(t, hasAnySafeOutputEnabled(cfg),
40 "hasAnySafeOutputEnabled missing check for field %q; add it to the direct nil-check list", handler.StructField)
41
42 // hasNonBuiltinSafeOutputsEnabled must return true for every non-builtin field.
43 if !handler.Builtin {
44 assert.True(t, hasNonBuiltinSafeOutputsEnabled(cfg),
45 "hasNonBuiltinSafeOutputsEnabled missing check for non-builtin field %q; add it to the direct nil-check list", handler.StructField)
46 }
47 })
48 }
49}
50
51// TestSafeOutputStateCommentMemoryCoverage explicitly tests CommentMemory, which is
52// attached to SafeOutputs via tools.comment-memory (not listed in safeOutputFieldMapping)

Callers

nothing calls this directly

Calls 5

hasAnySafeOutputEnabledFunction · 0.85
RunMethod · 0.45
IsValidMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected