MCPcopy Create free account
hub / github.com/github/gh-aw / TestGenerateSchemaBasedSuggestions

Function TestGenerateSchemaBasedSuggestions

pkg/parser/schema_suggestions_test.go:13–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestGenerateSchemaBasedSuggestions(t *testing.T) {
14 // Sample schema JSON for testing
15 schemaJSON := `{
16 "type": "object",
17 "properties": {
18 "name": {"type": "string"},
19 "age": {"type": "integer"},
20 "email": {"type": "string"},
21 "permissions": {
22 "type": "object",
23 "properties": {
24 "contents": {"type": "string"},
25 "issues": {"type": "string"},
26 "pull-requests": {"type": "string"}
27 },
28 "additionalProperties": false
29 }
30 },
31 "additionalProperties": false
32 }`
33
34 tests := []struct {
35 name string
36 errorMessage string
37 jsonPath string
38 frontmatterContent string
39 wantContains []string
40 wantEmpty bool
41 }{
42 {
43 name: "additional property error at root level",
44 errorMessage: "additional property 'naem' not allowed", // Typo for "name" (distance 2)
45 jsonPath: "",
46 wantContains: []string{"Did you mean", "name"}, // Close match found
47 },
48 {
49 name: "additional property error in nested object",
50 errorMessage: "additional property 'contnt' not allowed", // Typo for "contents" (distance 1)
51 jsonPath: "/permissions",
52 wantContains: []string{"Did you mean", "contents"}, // Close match found
53 },
54 {
55 name: "type error with integer expected",
56 errorMessage: "got string, want integer",
57 jsonPath: "/age",
58 wantContains: []string{"Expected format:", "42"},
59 },
60 {
61 name: "multiple additional properties",
62 errorMessage: "additional properties 'prop1', 'prop2' not allowed", // Far from any valid field
63 jsonPath: "",
64 wantContains: []string{"Valid fields are:", "name", "age"}, // No close matches, show valid fields
65 },
66 {
67 name: "non-validation error",
68 errorMessage: "some other error",
69 jsonPath: "",
70 wantEmpty: true,

Callers

nothing calls this directly

Calls 2

RunMethod · 0.45

Tested by

no test coverage detected