Files
notarius/internal/framework/semanticreconcile/assets_test.go

70 lines
2.4 KiB
Go
Raw Normal View History

package semanticreconcile
import (
"context"
"reflect"
"strings"
"testing"
"go.maximumdirect.net/promptkit"
)
func TestNativeReconciliationPromptPairPreparesOffline(t *testing.T) {
client := &nativeReconciliationClient{}
engine := newReconciliationEngine(t, client)
preparation := proposalPreparation(t)
initial, err := InitialRequest(preparation, PromptID, "test-profile", "session-1")
if err != nil {
t.Fatal(err)
}
correction := CorrectionRequest(CorrectionPromptID, "test-profile", "session-1", []string{"Use only candidate numbers in the supplied range.", "Preserve distinct entities."})
if len(correction.Inputs) != 1 {
t.Fatal("correction regenerated fixed evidence")
}
var first promptkit.PreparedRun
for i, request := range []promptkit.RunRequest{initial, correction} {
handle, err := engine.PrepareExecution(context.Background(), request)
if err != nil {
t.Fatal(err)
}
prepared := handle.Details()
handle.Discard()
if prepared.SelectedProfileID != "test-profile" || prepared.SessionID != "session-1" {
t.Fatal("request selection lost")
}
if prepared.OutputContract.ValidationMode != promptkit.ValidationJSONSchema || prepared.StructuredOutput == nil {
t.Fatal("native response schema missing")
}
if i == 0 {
first = prepared
var system string
for _, message := range prepared.Messages {
if message.Role == "system" {
system += message.Content
}
}
for _, rule := range []string{"candidate_number_range", "not candidate numbers", "do not copy candidate names", "Preserve distinct entities"} {
if !strings.Contains(system, rule) {
t.Fatalf("missing enduring system principle %q", rule)
}
}
} else {
if !reflect.DeepEqual(first.OutputContract, prepared.OutputContract) || len(prepared.Messages) != 1 || prepared.Messages[0].Role != "user" {
t.Fatal("correction changed native contract or supplied more than a follow-up assignment")
}
text := prepared.Messages[0].Content
if !strings.Contains(text, "Use only candidate numbers") || !strings.Contains(text, "complete replacement proposal") {
t.Fatal("correction lost findings or assignment")
}
for _, material := range preparation.Materials() {
if strings.Contains(text, string(material)) {
t.Fatal("correction contains regenerated input material")
}
}
}
}
if len(client.requests) != 0 {
t.Fatal("offline preparation called a provider")
}
}