TestParseSafeScriptsConfig verifies parsing of safe-scripts configuration
(t *testing.T)
| 14 | |
| 15 | // TestParseSafeScriptsConfig verifies parsing of safe-scripts configuration |
| 16 | func TestParseSafeScriptsConfig(t *testing.T) { |
| 17 | scriptsMap := map[string]any{ |
| 18 | "slack-post-message": map[string]any{ |
| 19 | "name": "Post Slack Message", |
| 20 | "description": "Post a message to a Slack channel", |
| 21 | "inputs": map[string]any{ |
| 22 | "channel": map[string]any{ |
| 23 | "description": "Slack channel name", |
| 24 | "required": true, |
| 25 | "type": "string", |
| 26 | }, |
| 27 | "message": map[string]any{ |
| 28 | "description": "Message content", |
| 29 | "required": true, |
| 30 | "type": "string", |
| 31 | }, |
| 32 | }, |
| 33 | // Users write only the body of main — the compiler wraps it |
| 34 | "script": `return async function handleSlackPostMessage(message, resolvedTemporaryIds) { |
| 35 | return { success: true }; |
| 36 | };`, |
| 37 | }, |
| 38 | } |
| 39 | |
| 40 | result := parseSafeScriptsConfig(scriptsMap) |
| 41 | |
| 42 | require.NotNil(t, result, "Should return non-nil result") |
| 43 | require.Len(t, result, 1, "Should have one script") |
| 44 | |
| 45 | script, exists := result["slack-post-message"] |
| 46 | require.True(t, exists, "Should have slack-post-message script") |
| 47 | assert.Equal(t, "Post Slack Message", script.Name, "Name should match") |
| 48 | assert.Equal(t, "Post a message to a Slack channel", script.Description, "Description should match") |
| 49 | assert.Contains(t, script.Script, "return async function", "Script body should contain handler return") |
| 50 | |
| 51 | require.Len(t, script.Inputs, 2, "Should have 2 inputs") |
| 52 | |
| 53 | channelInput, ok := script.Inputs["channel"] |
| 54 | require.True(t, ok, "Should have channel input") |
| 55 | assert.Equal(t, "string", channelInput.Type, "Channel type should be string") |
| 56 | assert.True(t, channelInput.Required, "Channel should be required") |
| 57 | |
| 58 | messageInput, ok := script.Inputs["message"] |
| 59 | require.True(t, ok, "Should have message input") |
| 60 | assert.Equal(t, "string", messageInput.Type, "Message type should be string") |
| 61 | assert.True(t, messageInput.Required, "Message should be required") |
| 62 | } |
| 63 | |
| 64 | // TestParseSafeScriptsConfigNilMap verifies nil input handling |
| 65 | func TestParseSafeScriptsConfigNilMap(t *testing.T) { |
nothing calls this directly
no test coverage detected