TestGetSandboxDisableJustification tests the full justification validation logic, including all the rejection cases required by the acceptance criteria: - boolean true fails (no longer a legacy shorthand) - expressions fail - too-short strings fail - whitespace-padded strings fail - a 20+ character
(t *testing.T)
| 87 | // - whitespace-padded strings fail |
| 88 | // - a 20+ character literal reason passes |
| 89 | func TestGetSandboxDisableJustification(t *testing.T) { |
| 90 | makeData := func(value any) *WorkflowData { |
| 91 | return &WorkflowData{ |
| 92 | Features: map[string]any{ |
| 93 | "dangerously-disable-sandbox-agent": value, |
| 94 | }, |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | t.Run("boolean true is rejected", func(t *testing.T) { |
| 99 | _, err := getSandboxDisableJustification(makeData(true)) |
| 100 | require.Error(t, err) |
| 101 | assert.Contains(t, err.Error(), "string", "should explain that a string is required") |
| 102 | }) |
| 103 | |
| 104 | t.Run("boolean false is rejected", func(t *testing.T) { |
| 105 | _, err := getSandboxDisableJustification(makeData(false)) |
| 106 | require.Error(t, err) |
| 107 | assert.Contains(t, err.Error(), "string", "should explain that a string is required") |
| 108 | }) |
| 109 | |
| 110 | t.Run("empty string is rejected", func(t *testing.T) { |
| 111 | _, err := getSandboxDisableJustification(makeData("")) |
| 112 | require.Error(t, err) |
| 113 | assert.Contains(t, err.Error(), "20", "should mention minimum length") |
| 114 | }) |
| 115 | |
| 116 | t.Run("short string is rejected", func(t *testing.T) { |
| 117 | _, err := getSandboxDisableJustification(makeData("too short")) |
| 118 | require.Error(t, err) |
| 119 | assert.Contains(t, err.Error(), "20", "should mention minimum length") |
| 120 | }) |
| 121 | |
| 122 | t.Run("whitespace-padded short string is rejected", func(t *testing.T) { |
| 123 | // 22 spaces - long enough on paper but collapses to empty after TrimSpace |
| 124 | _, err := getSandboxDisableJustification(makeData(" ")) |
| 125 | require.Error(t, err) |
| 126 | assert.Contains(t, err.Error(), "20", "should mention minimum length") |
| 127 | }) |
| 128 | |
| 129 | t.Run("whitespace-padded string where trimmed is below minimum is rejected", func(t *testing.T) { |
| 130 | // "short" padded with whitespace to 25 total chars still fails (trimmed is 5) |
| 131 | _, err := getSandboxDisableJustification(makeData(" short ")) |
| 132 | require.Error(t, err) |
| 133 | assert.Contains(t, err.Error(), "20", "should mention minimum length") |
| 134 | }) |
| 135 | |
| 136 | t.Run("GitHub Actions expression is rejected", func(t *testing.T) { |
| 137 | _, err := getSandboxDisableJustification(makeData("${{ inputs.reason }}")) |
| 138 | require.Error(t, err) |
| 139 | assert.Contains(t, err.Error(), "expressions") |
| 140 | }) |
| 141 | |
| 142 | t.Run("longer expression with surrounding text is rejected", func(t *testing.T) { |
| 143 | _, err := getSandboxDisableJustification(makeData("reason: ${{ inputs.reason }} end")) |
| 144 | require.Error(t, err) |
| 145 | assert.Contains(t, err.Error(), "expressions") |
| 146 | }) |
nothing calls this directly
no test coverage detected