Validate schemas without relying on source filenames
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -11,10 +12,17 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/santhosh-tekuri/jsonschema/v6"
|
||||
"go.maximumdirect.net/configkit"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
type rejectWireSchemaLoad struct{}
|
||||
|
||||
func (rejectWireSchemaLoad) Load(uri string) (any, error) {
|
||||
return nil, fmt.Errorf("unexpected external resource %s", uri)
|
||||
}
|
||||
|
||||
func TestSchemaFilePreparationAndNativeSubmission(t *testing.T) {
|
||||
firstDir, secondDir := t.TempDir(), t.TempDir()
|
||||
first, second := filepath.Join(firstDir, "schema.json"), filepath.Join(secondDir, "schema.json")
|
||||
@@ -57,6 +65,16 @@ func TestSchemaFilePreparationAndNativeSubmission(t *testing.T) {
|
||||
if err != nil || !strings.Contains(string(encoded), `"$defs"`) || !strings.Contains(string(encoded), `#/$defs/value`) {
|
||||
t.Fatalf("wire schema = %s, %v", encoded, err)
|
||||
}
|
||||
compiler := jsonschema.NewCompiler()
|
||||
compiler.UseLoader(rejectWireSchemaLoad{})
|
||||
const submission = "https://provider.invalid/request-schema"
|
||||
document := payload["response_format"].(map[string]any)["json_schema"].(map[string]any)["schema"]
|
||||
if err := compiler.AddResource(submission, document); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := compiler.Compile(submission); err != nil {
|
||||
t.Fatalf("outbound schema needs local source context: %v", err)
|
||||
}
|
||||
if _, err := engine.PrepareExecution(context.Background(), promptkit.RunRequest{PromptID: "prompt"}); !errors.Is(err, promptkit.ErrValidation) {
|
||||
t.Fatalf("missing root error = %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user