Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
114
backend/internal/util/claude_schema_test.go
Normal file
114
backend/internal/util/claude_schema_test.go
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeClaudeToolInputSchema(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "root anyOf without type",
|
||||
input: `{
|
||||
"anyOf": [
|
||||
{"type":"object","properties":{"a":{"type":"string"}}},
|
||||
{"type":"object","properties":{"b":{"type":"integer"}}}
|
||||
]
|
||||
}`,
|
||||
expected: `{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"a":{"type":"string"},
|
||||
"b":{"type":"integer"}
|
||||
}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "root oneOf keeps nested union",
|
||||
input: `{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"nested":{"oneOf":[{"type":"string"},{"type":"number"}]}
|
||||
},
|
||||
"oneOf":[
|
||||
{"properties":{"a":{"type":"string"}},"required":["a"]},
|
||||
{"properties":{"b":{"type":"string"}},"required":["b"]}
|
||||
]
|
||||
}`,
|
||||
expected: `{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"nested":{"oneOf":[{"type":"string"},{"type":"number"}]},
|
||||
"a":{"type":"string"},
|
||||
"b":{"type":"string"}
|
||||
}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "root anyOf drops alternative required fields",
|
||||
input: `{
|
||||
"type":"object",
|
||||
"properties":{"a":{"type":"string"},"b":{"type":"string"}},
|
||||
"anyOf":[{"required":["a"]},{"required":["b"]}]
|
||||
}`,
|
||||
expected: `{
|
||||
"type":"object",
|
||||
"properties":{"a":{"type":"string"},"b":{"type":"string"}}
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "root allOf merges properties and required fields",
|
||||
input: `{
|
||||
"type":"object",
|
||||
"properties":{"base":{"type":"boolean"}},
|
||||
"required":["base"],
|
||||
"allOf":[
|
||||
{"type":"object","properties":{"a":{"type":"string"}},"required":["a"]},
|
||||
{"properties":{"b":{"type":"integer"}},"required":["a","b"]}
|
||||
]
|
||||
}`,
|
||||
expected: `{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"base":{"type":"boolean"},
|
||||
"a":{"type":"string"},
|
||||
"b":{"type":"integer"}
|
||||
},
|
||||
"required":["base","a","b"]
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "ordinary object schema",
|
||||
input: `{
|
||||
"type":"object",
|
||||
"properties":{"query":{"type":"string"}},
|
||||
"required":["query"],
|
||||
"additionalProperties":false
|
||||
}`,
|
||||
expected: `{
|
||||
"type":"object",
|
||||
"properties":{"query":{"type":"string"}},
|
||||
"required":["query"],
|
||||
"additionalProperties":false
|
||||
}`,
|
||||
},
|
||||
{
|
||||
name: "invalid schema",
|
||||
input: `{"type":`,
|
||||
expected: `{"type":"object","properties":{}}`,
|
||||
},
|
||||
{
|
||||
name: "boolean schema",
|
||||
input: `true`,
|
||||
expected: `{"type":"object","properties":{}}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
actual := NormalizeClaudeToolInputSchema([]byte(test.input))
|
||||
compareJSON(t, test.expected, string(actual))
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue