Capture native execution facts and complete scoped debug evidence
This commit is contained in:
@@ -2,13 +2,18 @@ package itemregistry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
itemcodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/itemregistry"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/items/identity"
|
||||
@@ -39,6 +44,43 @@ func itemNames(value dnd.ItemRegistry) []string {
|
||||
return names
|
||||
}
|
||||
|
||||
func TestNormalizationCaptureRetainsFixedMappingAndEveryProposal(t *testing.T) {
|
||||
recorder, err := frameworkdebug.Start(t.TempDir(), "normalization", time.Unix(1, 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
client := &recordingNormalizerClient{responses: []string{invalidItemProposal, safeFirstProposal}}
|
||||
request := normalizeRequestWithSource(mergedItems(), semanticDocument())
|
||||
request.Operation.Execution.Capture = recorder
|
||||
request.Operation.Controls.MaxAdditionalTurns = 1
|
||||
result, err := newNormalizer(t, client).Normalize(context.Background(), request)
|
||||
if err != nil || result.Outcome.Disposition != contracts.ProducerAccepted {
|
||||
t.Fatalf("normalization: %#v %v", result, err)
|
||||
}
|
||||
content, err := os.ReadFile(filepath.Join(recorder.Path(), "normalization", "originals.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var originals dnd.ItemRegistry
|
||||
if err := json.Unmarshal(content, &originals); err != nil || len(originals.Items) != 3 {
|
||||
t.Fatalf("fixed originals missing: %#v %v", originals, err)
|
||||
}
|
||||
content, err = os.ReadFile(filepath.Join(recorder.Path(), "normalization", "preparation.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var preparation struct {
|
||||
Mappings []any `json:"candidate_mappings"`
|
||||
}
|
||||
if err := json.Unmarshal(content, &preparation); err != nil || len(preparation.Mappings) != 3 {
|
||||
t.Fatalf("fixed handle mapping missing: %s %v", content, err)
|
||||
}
|
||||
proposals, err := os.ReadDir(filepath.Join(recorder.Path(), "normalization", "proposals"))
|
||||
if err != nil || len(proposals) != 2 {
|
||||
t.Fatalf("revised proposals lost: %v %v", proposals, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeNormalizationReassessesRevisionsAndUsesOnlyTheFinalProposal(t *testing.T) {
|
||||
finalPartial := `{"duplicate_groups":[{"candidate_numbers":[2,3],"canonical_candidate_number":3},{"candidate_numbers":[1,99],"canonical_candidate_number":1}]}`
|
||||
for _, test := range []struct {
|
||||
|
||||
Reference in New Issue
Block a user