TestCleanJSONSchemaErrorMessage tests the full cleanup pipeline for jsonschema errors
(t *testing.T)
| 278 | |
| 279 | // TestCleanJSONSchemaErrorMessage tests the full cleanup pipeline for jsonschema errors |
| 280 | func TestCleanJSONSchemaErrorMessage(t *testing.T) { |
| 281 | tests := []struct { |
| 282 | name string |
| 283 | input string |
| 284 | wantNot []string |
| 285 | wantAny []string |
| 286 | }{ |
| 287 | { |
| 288 | name: "removes jsonschema validation failed header", |
| 289 | input: "jsonschema validation failed with 'http://contoso.com/schema.json#'\n" + |
| 290 | "- at '/engine': 'oneOf' failed, none matched\n" + |
| 291 | "- at '/engine': value must be one of 'claude', 'codex'\n" + |
| 292 | "- at '/engine': got string, want object", |
| 293 | wantNot: []string{"jsonschema validation failed", "contoso.com", "got string, want object", "oneOf"}, |
| 294 | wantAny: []string{"value must be one of 'claude', 'codex'"}, |
| 295 | }, |
| 296 | { |
| 297 | name: "removes at-root prefix", |
| 298 | input: "jsonschema validation failed with '...'\n" + |
| 299 | "- at '': additional property 'foo' not allowed", |
| 300 | wantNot: []string{"jsonschema validation failed", "at '': "}, |
| 301 | wantAny: []string{"additional property 'foo' not allowed"}, |
| 302 | }, |
| 303 | { |
| 304 | name: "empty result falls back to generic message", |
| 305 | input: "jsonschema validation failed with '...'", |
| 306 | wantAny: []string{"schema validation failed"}, |
| 307 | }, |
| 308 | } |
| 309 | |
| 310 | for _, tt := range tests { |
| 311 | t.Run(tt.name, func(t *testing.T) { |
| 312 | result := cleanJSONSchemaErrorMessage(tt.input) |
| 313 | |
| 314 | for _, unwanted := range tt.wantNot { |
| 315 | assert.NotContains(t, result, unwanted, |
| 316 | "Result should not contain %q\nResult: %s", unwanted, result) |
| 317 | } |
| 318 | |
| 319 | if len(tt.wantAny) > 0 { |
| 320 | found := false |
| 321 | for _, wanted := range tt.wantAny { |
| 322 | if strings.Contains(result, wanted) { |
| 323 | found = true |
| 324 | break |
| 325 | } |
| 326 | } |
| 327 | assert.True(t, found, |
| 328 | "Result should contain at least one of %v\nResult: %s", tt.wantAny, result) |
| 329 | } |
| 330 | }) |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // TestTranslateSchemaConstraintMessage tests that minimum/maximum messages are translated to plain English |
| 335 | func TestTranslateSchemaConstraintMessage(t *testing.T) { |
nothing calls this directly
no test coverage detected