2026-08-09 16:08:53 +00:00
package semanticreconcile
import (
"context"
"reflect"
"strings"
"testing"
2026-11-22 00:07:05 +00:00
"go.maximumdirect.net/promptkit"
2026-08-09 16:08:53 +00:00
)
2026-11-22 00:07:05 +00:00
func TestNativeReconciliationPromptPairPreparesOffline ( t * testing . T ) {
client := & nativeReconciliationClient { }
engine := newReconciliationEngine ( t , client )
preparation := proposalPreparation ( t )
initial , err := InitialRequest ( preparation , PromptID , "test-profile" , "session-1" )
2026-08-09 16:08:53 +00:00
if err != nil {
2026-11-22 00:07:05 +00:00
t . Fatal ( err )
2026-08-09 16:08:53 +00:00
}
2026-11-22 00:07:05 +00:00
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" )
2026-08-09 16:08:53 +00:00
}
2026-11-22 00:07:05 +00:00
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 )
2026-08-09 16:08:53 +00:00
}
2026-11-22 00:07:05 +00:00
prepared := handle . Details ( )
handle . Discard ( )
if prepared . SelectedProfileID != "test-profile" || prepared . SessionID != "session-1" {
t . Fatal ( "request selection lost" )
2026-08-09 16:08:53 +00:00
}
2026-11-22 00:07:05 +00:00
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" )
}
}
2026-08-09 16:08:53 +00:00
}
}
2026-11-22 00:07:05 +00:00
if len ( client . requests ) != 0 {
t . Fatal ( "offline preparation called a provider" )
2026-08-09 16:08:53 +00:00
}
}