TestBuildCustomScriptFilesStep verifies the generated step writes scripts to files
(t *testing.T)
| 249 | |
| 250 | // TestBuildCustomScriptFilesStep verifies the generated step writes scripts to files |
| 251 | func TestBuildCustomScriptFilesStep(t *testing.T) { |
| 252 | scripts := map[string]*SafeScriptConfig{ |
| 253 | "my-handler": { |
| 254 | // Users write only the handler body — no function wrapper or boilerplate needed |
| 255 | Script: "return { success: true };", |
| 256 | Inputs: map[string]*InputDefinition{ |
| 257 | "channel": {Type: "string"}, |
| 258 | }, |
| 259 | }, |
| 260 | } |
| 261 | |
| 262 | steps, err := buildCustomScriptFilesStep(scripts) |
| 263 | |
| 264 | require.NoError(t, err, "Should not return error for valid scripts") |
| 265 | require.NotEmpty(t, steps, "Should produce steps") |
| 266 | |
| 267 | fullYAML := strings.Join(steps, "") |
| 268 | |
| 269 | assert.Contains(t, fullYAML, "Configure Safe Outputs Custom Scripts", "Should have configure step name") |
| 270 | assert.Contains(t, fullYAML, "safe_output_script_my_handler.cjs", "Should reference the output filename") |
| 271 | // Verify heredoc delimiter follows the randomized GH_AW_SAFE_OUTPUT_SCRIPT_MY_HANDLER_<hex>_EOF format |
| 272 | delimRE := regexp.MustCompile(`GH_AW_SAFE_OUTPUT_SCRIPT_MY_HANDLER_[0-9a-f]{16}_EOF`) |
| 273 | assert.True(t, delimRE.MatchString(fullYAML), "Should use correct randomized heredoc delimiter") |
| 274 | // Verify the compiler generates the full outer wrapper |
| 275 | assert.Contains(t, fullYAML, "async function main(config = {}) {", "Should generate main function declaration") |
| 276 | assert.Contains(t, fullYAML, "const { channel } = config;", "Should generate config input destructuring") |
| 277 | assert.Contains(t, fullYAML, "return async function handleMyHandler(item, resolvedTemporaryIds, temporaryIdMap) {", "Should generate handler function") |
| 278 | assert.Contains(t, fullYAML, "module.exports = { main };", "Should include module.exports wrapper") |
| 279 | // User's handler body content should appear indented inside the handler |
| 280 | assert.Contains(t, fullYAML, "return { success: true };", "Should include user's handler body") |
| 281 | } |
| 282 | |
| 283 | // TestBuildCustomScriptFilesStepEmpty verifies nil return for empty scripts |
| 284 | func TestBuildCustomScriptFilesStepEmpty(t *testing.T) { |
nothing calls this directly
no test coverage detected