TestErrorFormattingDoesNotMangle verifies formatting doesn't corrupt messages
(t *testing.T)
| 252 | |
| 253 | // TestErrorFormattingDoesNotMangle verifies formatting doesn't corrupt messages |
| 254 | func TestErrorFormattingDoesNotMangle(t *testing.T) { |
| 255 | tests := []struct { |
| 256 | name string |
| 257 | message string |
| 258 | }{ |
| 259 | { |
| 260 | name: "message with special characters", |
| 261 | message: "Error: failed to compile workflow 'test.md' at line 42", |
| 262 | }, |
| 263 | { |
| 264 | name: "message with multiple sentences", |
| 265 | message: "Compilation failed. Check your workflow syntax. See docs for help.", |
| 266 | }, |
| 267 | { |
| 268 | name: "message with newlines", |
| 269 | message: "Error on line 1:\n invalid field 'unknown'", |
| 270 | }, |
| 271 | { |
| 272 | name: "message with path", |
| 273 | message: "Failed to read /path/to/workflow.md", |
| 274 | }, |
| 275 | } |
| 276 | |
| 277 | for _, tt := range tests { |
| 278 | t.Run(tt.name, func(t *testing.T) { |
| 279 | formatted := console.FormatErrorMessage(tt.message) |
| 280 | |
| 281 | // All essential parts of the message should be preserved |
| 282 | // (formatting may add prefixes/styling but shouldn't lose content) |
| 283 | essentialParts := strings.FieldsSeq(tt.message) |
| 284 | for part := range essentialParts { |
| 285 | // Skip very short parts like ":", "at", etc. |
| 286 | if len(part) > 2 { |
| 287 | assert.Contains(t, formatted, part, |
| 288 | "Formatted message should preserve essential part: %s", part) |
| 289 | } |
| 290 | } |
| 291 | }) |
| 292 | } |
| 293 | } |
nothing calls this directly
no test coverage detected