Move cross-family runner contracts into module integration tests
This commit is contained in:
@@ -1,123 +0,0 @@
|
||||
package combatturns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
combatcodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/combatturns"
|
||||
scenecodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/scenedescriptions"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/combatturns/shape"
|
||||
sourcerefs "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/combatturns/source_refs"
|
||||
relatedness "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/combatturns/source_relatedness"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/merge/appendorder"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/normalize/noop"
|
||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/seriatim/input/transcript"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestNativeCombatPipelineHonorsSceneEligibilityWithoutSyntheticRequests(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
kind dnd.SceneKind
|
||||
mismatched bool
|
||||
wantCalls int
|
||||
}{
|
||||
{"combat", dnd.SceneKindCombat, false, 1},
|
||||
{"narrative", dnd.SceneKindNarrative, false, 0},
|
||||
{"recap", dnd.SceneKindRecap, false, 0},
|
||||
{"meta", dnd.SceneKindMeta, false, 0},
|
||||
{"mismatched combat", dnd.SceneKindCombat, true, 0},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client := &fakeCombatTurnsLLMClient{raw: `{"combat_turns":[{"actor":"Aria","turn_kind":"turn","source_refs":[{"start_unit_id":1,"end_unit_id":1}]}]}`}
|
||||
engine := newExtractor(t, client).engine
|
||||
registries := pipeline.Registries{
|
||||
Inputs: pipeline.NewInputAdapterRegistry(), Chunkers: pipeline.NewChunkerRegistry(),
|
||||
ArtifactCodecs: pipeline.NewArtifactCodecRegistry(), Extractors: pipeline.NewExtractorRegistry(),
|
||||
Mergers: pipeline.NewMergerRegistry(), Normalizers: pipeline.NewNormalizerRegistry(),
|
||||
Validators: pipeline.NewValidatorRegistry(), ValidatorChains: pipeline.NewValidatorChainRegistry(),
|
||||
Outputs: pipeline.NewOutputEncoderRegistry(),
|
||||
}
|
||||
check := func(err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
check(transcript.Register(registries.Inputs))
|
||||
check(units.Register(registries.Chunkers))
|
||||
check(pipeline.RegisterArtifactCodec(registries.ArtifactCodecs, combatcodec.New()))
|
||||
check(Register(registries.Extractors))
|
||||
check(appendorder.RegisterTyped(registries.Mergers, dnd.CombatTurnListKind, func(values []dnd.CombatTurnList) (dnd.CombatTurnList, error) {
|
||||
result := dnd.CombatTurnList{CombatTurns: []dnd.CombatTurn{}}
|
||||
for _, value := range values {
|
||||
result.CombatTurns = append(result.CombatTurns, value.CombatTurns...)
|
||||
}
|
||||
return result, nil
|
||||
}))
|
||||
check(noop.RegisterTyped[dnd.CombatTurnList](registries.Normalizers, dnd.CombatTurnListKind))
|
||||
check(jsonoutput.Register(registries.Outputs))
|
||||
check(shape.Register(registries.Validators))
|
||||
check(sourcerefs.Register(registries.Validators))
|
||||
check(relatedness.Register(registries.Validators))
|
||||
scene := dnd.SceneDescription{
|
||||
ID: "chunk-000001", SourceRef: source.SourceRef{SourceID: "combat-session", StartUnitID: 1, EndUnitID: 1},
|
||||
Kind: test.kind, Title: "Eligibility only", Summary: "This prose must not become combat evidence.",
|
||||
}
|
||||
if test.mismatched {
|
||||
scene.SourceRef.EndUnitID = 2
|
||||
}
|
||||
content, err := scenecodec.New().Encode(dnd.SceneDescriptionList{Scenes: []dnd.SceneDescription{scene}})
|
||||
check(err)
|
||||
path := filepath.Join(t.TempDir(), "scenes.json")
|
||||
check(os.WriteFile(path, content, 0600))
|
||||
profile := pipeline.PipelineProfile{
|
||||
ID: "native-combat", Input: pipeline.Binding(transcript.Key), Chunk: pipeline.Binding(units.Key), Output: pipeline.Binding(jsonoutput.Key),
|
||||
LLMProfile: "profile-combat",
|
||||
Artifacts: map[string]pipeline.ArtifactLaneProfile{"combat": {
|
||||
Extract: pipeline.ModuleBinding{Module: Key, Validators: pipeline.ValidatorOverride{Set: true, Validators: []pipeline.ModuleBinding{
|
||||
pipeline.Binding(shape.Key), pipeline.Binding(sourcerefs.Key), pipeline.Binding(relatedness.Key),
|
||||
}}, References: map[string]pipeline.ReferenceSource{SceneDescriptionReferenceSlot: pipeline.ExternalReference(path)}},
|
||||
Merge: pipeline.Binding(appendorder.Key), Normalize: pipeline.Binding(noop.Key),
|
||||
}},
|
||||
}
|
||||
catalog := pipeline.ModuleCatalog{
|
||||
Inputs: registries.Inputs, Chunkers: registries.Chunkers, ArtifactCodecs: registries.ArtifactCodecs,
|
||||
Extractors: registries.Extractors, Mergers: registries.Mergers, Normalizers: registries.Normalizers,
|
||||
Validators: registries.Validators, ValidatorChains: registries.ValidatorChains, Outputs: registries.Outputs,
|
||||
}
|
||||
resolved, err := pipeline.ResolvePipeline(profile, pipeline.ResolveOptions{}, catalog)
|
||||
check(err)
|
||||
resolved, _, err = pipeline.MaterializeReferences(resolved, catalog, pipeline.ReferenceMaterializationOptions{})
|
||||
check(err)
|
||||
prepared, err := pipeline.Prepare(resolved, registries, pipeline.ModuleDependencies{Engine: engine})
|
||||
check(err)
|
||||
preparations := 0
|
||||
result, err := pipeline.New().Run(context.Background(), pipeline.RunInput{
|
||||
Prepared: prepared, SourceID: "combat-session", Workers: 1,
|
||||
RawInput: []byte(`{"metadata":{},"segments":[{"id":1,"speaker":"Alice","start":0,"end":1,"text":"Aria strikes the ogre."}]}`),
|
||||
Execution: contracts.ExecutionOptions{OnPrepared: func(context.Context, promptkit.PreparedRun) { preparations++ }},
|
||||
})
|
||||
check(err)
|
||||
if len(client.requests) != test.wantCalls || preparations != test.wantCalls || result.FallbackCount != 0 || len(result.OutputFiles) != 1 {
|
||||
t.Fatalf("pipeline=%#v native=%d/%d, want %d", result, len(client.requests), preparations, test.wantCalls)
|
||||
}
|
||||
value, err := combatcodec.New().Decode(result.OutputFiles[0].Bytes)
|
||||
check(err)
|
||||
if value.CombatTurns == nil || len(value.CombatTurns) != test.wantCalls {
|
||||
t.Fatalf("combat artifact=%#v", value)
|
||||
}
|
||||
if test.wantCalls > 0 && (value.CombatTurns[0].Actor != "Aria" || value.CombatTurns[0].SourceRefs[0].SourceID != "combat-session") {
|
||||
t.Fatalf("combat evidence=%#v", value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package enemyevents
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
eventcodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/enemyevents"
|
||||
scenecodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/scenedescriptions"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/merge/appendorder"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/normalize/noop"
|
||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/seriatim/input/transcript"
|
||||
)
|
||||
|
||||
func TestNativeEnemyPipelineRetainsIntrinsicCodecBoundaryWithEmptyValidators(t *testing.T) {
|
||||
for _, name := range []string{"Ashfang", " "} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
client := &fakeEnemyEventsLLMClient{response: extractionResponse{Events: []enemyEventResponse{
|
||||
{Name: name, Kind: "engaged", SourceRefs: []enemySourceRefResponse{{StartUnitID: 1, EndUnitID: 1}}},
|
||||
}}}
|
||||
engine := newEnemyExtractor(t, client).engine
|
||||
registries := pipeline.Registries{
|
||||
Inputs: pipeline.NewInputAdapterRegistry(), Chunkers: pipeline.NewChunkerRegistry(),
|
||||
ArtifactCodecs: pipeline.NewArtifactCodecRegistry(), Extractors: pipeline.NewExtractorRegistry(),
|
||||
Mergers: pipeline.NewMergerRegistry(), Normalizers: pipeline.NewNormalizerRegistry(),
|
||||
Validators: pipeline.NewValidatorRegistry(), ValidatorChains: pipeline.NewValidatorChainRegistry(),
|
||||
Outputs: pipeline.NewOutputEncoderRegistry(),
|
||||
}
|
||||
check := func(err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
check(transcript.Register(registries.Inputs))
|
||||
check(units.Register(registries.Chunkers))
|
||||
check(pipeline.RegisterArtifactCodec(registries.ArtifactCodecs, eventcodec.New()))
|
||||
check(Register(registries.Extractors))
|
||||
check(appendorder.RegisterTyped(registries.Mergers, dnd.EnemyEventListKind, func(values []dnd.EnemyEventList) (dnd.EnemyEventList, error) {
|
||||
result := dnd.EnemyEventList{Events: []dnd.EnemyEvent{}}
|
||||
for _, value := range values {
|
||||
result.Events = append(result.Events, value.Events...)
|
||||
}
|
||||
return result, nil
|
||||
}))
|
||||
check(noop.RegisterTyped[dnd.EnemyEventList](registries.Normalizers, dnd.EnemyEventListKind))
|
||||
check(jsonoutput.Register(registries.Outputs))
|
||||
references := groundingReferences(t, "Ashfang", dnd.SceneKindCombat)
|
||||
content, err := scenecodec.New().Encode(dnd.SceneDescriptionList{Scenes: []dnd.SceneDescription{{
|
||||
ID: "chunk-000001", SourceRef: source.SourceRef{SourceID: "combat-session", StartUnitID: 1, EndUnitID: 1},
|
||||
Kind: dnd.SceneKindCombat, Title: "Combat", Summary: "Ashfang opposes the party.",
|
||||
}}})
|
||||
check(err)
|
||||
references = replaceItem(references, SceneDescriptionReferenceSlot, newReferenceItem(SceneDescriptionReferenceSlot, content))
|
||||
referenceSources := make(map[string]pipeline.ReferenceSource)
|
||||
root := t.TempDir()
|
||||
for name, slot := range references.Slots {
|
||||
path := filepath.Join(root, name+".json")
|
||||
check(os.WriteFile(path, slot.Items[0].Content, 0600))
|
||||
referenceSources[name] = pipeline.ExternalReference(path)
|
||||
}
|
||||
profile := pipeline.PipelineProfile{
|
||||
ID: "native-enemies", Input: pipeline.Binding(transcript.Key), Chunk: pipeline.Binding(units.Key), Output: pipeline.Binding(jsonoutput.Key),
|
||||
LLMProfile: "enemy-profile",
|
||||
Artifacts: map[string]pipeline.ArtifactLaneProfile{"enemies": {
|
||||
Extract: pipeline.ModuleBinding{Module: Key, References: referenceSources, Validators: pipeline.ValidatorOverride{Set: true, Validators: []pipeline.ModuleBinding{}}},
|
||||
Merge: pipeline.Binding(appendorder.Key), Normalize: pipeline.Binding(noop.Key),
|
||||
}},
|
||||
}
|
||||
catalog := pipeline.ModuleCatalog{
|
||||
Inputs: registries.Inputs, Chunkers: registries.Chunkers, ArtifactCodecs: registries.ArtifactCodecs,
|
||||
Extractors: registries.Extractors, Mergers: registries.Mergers, Normalizers: registries.Normalizers,
|
||||
Validators: registries.Validators, ValidatorChains: registries.ValidatorChains, Outputs: registries.Outputs,
|
||||
}
|
||||
resolved, err := pipeline.ResolvePipeline(profile, pipeline.ResolveOptions{}, catalog)
|
||||
check(err)
|
||||
resolved, _, err = pipeline.MaterializeReferences(resolved, catalog, pipeline.ReferenceMaterializationOptions{})
|
||||
check(err)
|
||||
prepared, err := pipeline.Prepare(resolved, registries, pipeline.ModuleDependencies{Engine: engine})
|
||||
check(err)
|
||||
result, err := pipeline.New().Run(context.Background(), pipeline.RunInput{
|
||||
Prepared: prepared, SourceID: "combat-session", Workers: 1,
|
||||
RawInput: []byte(`{"metadata":{},"segments":[{"id":1,"speaker":"GM","start":0,"end":1,"text":"Ashfang attacks the party."}]}`),
|
||||
})
|
||||
if len(client.requests) != 1 {
|
||||
t.Fatalf("native calls=%d", len(client.requests))
|
||||
}
|
||||
if strings.TrimSpace(name) == "" {
|
||||
if err == nil || !strings.Contains(err.Error(), "encode extract lane") || !strings.Contains(err.Error(), "name must not be empty") {
|
||||
t.Fatalf("intrinsic codec error=%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
check(err)
|
||||
if result.FallbackCount != 0 || len(result.OutputFiles) != 1 {
|
||||
t.Fatalf("assembled outcome=%#v", result)
|
||||
}
|
||||
value, err := eventcodec.New().Decode(result.OutputFiles[0].Bytes)
|
||||
check(err)
|
||||
if len(value.Events) != 1 || value.Events[0].Name != name || value.Events[0].SourceRefs[0].SourceID != "combat-session" {
|
||||
t.Fatalf("durable events=%#v", value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package spells
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
spellcodec "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/codec/spells"
|
||||
spellcatalogvalidator "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/spells/catalog"
|
||||
spellshape "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/spells/shape"
|
||||
spellsourcerefs "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/spells/source_refs"
|
||||
spellsourcerelatedness "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/spells/source_relatedness"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/merge/appendorder"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/generic/normalize/noop"
|
||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/seriatim/input/transcript"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// Count the real validator boundary, not a second implementation of its rules.
|
||||
type observedSpellValidator struct {
|
||||
contracts.TypedValidator[dnd.SpellList]
|
||||
record func(string)
|
||||
}
|
||||
|
||||
func (v observedSpellValidator) Validate(ctx context.Context, req contracts.TypedValidationRequest[dnd.SpellList]) (contracts.ValidationResult, error) {
|
||||
v.record(v.Name())
|
||||
return v.TypedValidator.Validate(ctx, req)
|
||||
}
|
||||
|
||||
func TestNativeSpellPipelineAssessesEveryCandidateOnce(t *testing.T) {
|
||||
response := func(name string) string {
|
||||
return fmt.Sprintf(`{"spell_casts":[{"caster":"Aria","spell":%q,"source_refs":[{"start_unit_id":1,"end_unit_id":1}]}]}`, name)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
mode contracts.ExecutionMode
|
||||
responses []string
|
||||
wantError bool
|
||||
fallbacks int
|
||||
}{
|
||||
{"initial acceptance", contracts.ModeStrict, []string{response("Cure Wounds")}, false, 0},
|
||||
{"final correction accepted", contracts.ModeStrict, []string{response("Unknown Spell"), response("Unknown Spell"), response("Cure Wounds")}, false, 0},
|
||||
{"strict exhaustion", contracts.ModeStrict, []string{response("Unknown Spell"), response("Unknown Spell"), response("Unknown Spell")}, true, 0},
|
||||
{"permissive empty fallback", contracts.ModePermissive, []string{response("Unknown Spell"), response("Unknown Spell"), response("Unknown Spell")}, false, 1},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client := &fakeSpellsLLMClient{outputs: append([]string(nil), test.responses...)}
|
||||
engine := newSpellEngine(t, client)
|
||||
registries := pipeline.Registries{
|
||||
Inputs: pipeline.NewInputAdapterRegistry(), Chunkers: pipeline.NewChunkerRegistry(),
|
||||
ArtifactCodecs: pipeline.NewArtifactCodecRegistry(), Extractors: pipeline.NewExtractorRegistry(),
|
||||
Mergers: pipeline.NewMergerRegistry(), Normalizers: pipeline.NewNormalizerRegistry(),
|
||||
Validators: pipeline.NewValidatorRegistry(), ValidatorChains: pipeline.NewValidatorChainRegistry(),
|
||||
Outputs: pipeline.NewOutputEncoderRegistry(),
|
||||
}
|
||||
check := func(err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
check(transcript.Register(registries.Inputs))
|
||||
check(units.Register(registries.Chunkers))
|
||||
check(pipeline.RegisterArtifactCodec(registries.ArtifactCodecs, spellcodec.New()))
|
||||
check(Register(registries.Extractors))
|
||||
check(appendorder.RegisterTyped(registries.Mergers, dnd.SpellListKind, func(values []dnd.SpellList) (dnd.SpellList, error) {
|
||||
result := dnd.SpellList{SpellCasts: []dnd.SpellCast{}}
|
||||
for _, value := range values {
|
||||
result.SpellCasts = append(result.SpellCasts, value.SpellCasts...)
|
||||
}
|
||||
return result, nil
|
||||
}))
|
||||
check(noop.RegisterTyped[dnd.SpellList](registries.Normalizers, dnd.SpellListKind))
|
||||
check(jsonoutput.Register(registries.Outputs))
|
||||
catalogValidator, err := spellcatalogvalidator.New(spellcatalogvalidator.Options{})
|
||||
check(err)
|
||||
validators := []contracts.TypedValidator[dnd.SpellList]{
|
||||
spellshape.New(spellshape.Options{}), spellsourcerefs.New(spellsourcerefs.Options{}),
|
||||
catalogValidator, spellsourcerelatedness.New(spellsourcerelatedness.Options{}),
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var calls []string
|
||||
record := func(name string) { mu.Lock(); defer mu.Unlock(); calls = append(calls, name) }
|
||||
var bindings []pipeline.ModuleBinding
|
||||
var names []string
|
||||
for _, validator := range validators {
|
||||
check(pipeline.RegisterTypedValidator(registries.Validators, dnd.SpellListKind,
|
||||
pipeline.ValidatorSpec{Key: validator.Name(), ExecutionClass: contracts.ExecutionClassDeterministic},
|
||||
func() (contracts.TypedValidator[dnd.SpellList], error) {
|
||||
return observedSpellValidator{validator, record}, nil
|
||||
}))
|
||||
bindings = append(bindings, pipeline.Binding(validator.Name()))
|
||||
names = append(names, validator.Name())
|
||||
}
|
||||
partyFile := filepath.Join(t.TempDir(), "party.txt")
|
||||
check(os.WriteFile(partyFile, []byte("party-grounding-sentinel: Aria"), 0600))
|
||||
turns := 2
|
||||
profile := pipeline.PipelineProfile{
|
||||
ID: "native-spells", Input: pipeline.Binding(transcript.Key),
|
||||
Chunk: pipeline.Binding(units.Key), Output: pipeline.Binding(jsonoutput.Key),
|
||||
LLMProfile: "profile-spells",
|
||||
Artifacts: map[string]pipeline.ArtifactLaneProfile{"spells": {
|
||||
Extract: pipeline.ModuleBinding{Module: Key, Mode: &test.mode, MaxAdditionalTurns: &turns,
|
||||
Validators: pipeline.ValidatorOverride{Set: true, Validators: bindings},
|
||||
References: map[string]pipeline.ReferenceSource{"party": pipeline.ExternalReference(partyFile)}},
|
||||
Merge: pipeline.Binding(appendorder.Key), Normalize: pipeline.Binding(noop.Key),
|
||||
}},
|
||||
}
|
||||
catalog := pipeline.ModuleCatalog{
|
||||
Inputs: registries.Inputs, Chunkers: registries.Chunkers, ArtifactCodecs: registries.ArtifactCodecs,
|
||||
Extractors: registries.Extractors, Mergers: registries.Mergers, Normalizers: registries.Normalizers,
|
||||
Validators: registries.Validators, ValidatorChains: registries.ValidatorChains, Outputs: registries.Outputs,
|
||||
}
|
||||
resolved, err := pipeline.ResolvePipeline(profile, pipeline.ResolveOptions{}, catalog)
|
||||
check(err)
|
||||
resolved, _, err = pipeline.MaterializeReferences(resolved, catalog, pipeline.ReferenceMaterializationOptions{})
|
||||
check(err)
|
||||
prepared, err := pipeline.Prepare(resolved, registries, pipeline.ModuleDependencies{Engine: engine})
|
||||
check(err)
|
||||
model := "run-wide-spell-model"
|
||||
var preparations []promptkit.PreparedRun
|
||||
output, err := pipeline.New().Run(context.Background(), pipeline.RunInput{
|
||||
Prepared: prepared, SourceID: "spell-session", SessionID: "spell-session-override", Workers: 1,
|
||||
RawInput: []byte(`{"metadata":{},"segments":[{"id":1,"speaker":"Alice","start":0,"end":1,"text":"I cast Cure Wounds."}]}`),
|
||||
Execution: contracts.ExecutionOptions{Execution: &promptkit.ExecutionTargetOverride{Model: model},
|
||||
OnPrepared: func(_ context.Context, value promptkit.PreparedRun) { preparations = append(preparations, value) }},
|
||||
})
|
||||
if (err != nil) != test.wantError {
|
||||
t.Fatalf("pipeline error = %v, want error %t", err, test.wantError)
|
||||
}
|
||||
wantCalls := len(test.responses)
|
||||
if len(client.requests) != wantCalls || len(preparations) != wantCalls {
|
||||
t.Fatalf("provider/preparation calls = %d/%d, want %d", len(client.requests), len(preparations), wantCalls)
|
||||
}
|
||||
var expected []string
|
||||
for range wantCalls {
|
||||
expected = append(expected, names...)
|
||||
}
|
||||
if !reflect.DeepEqual(calls, expected) {
|
||||
t.Fatalf("ordered assessments = %v, want %v (no outer assessment)", calls, expected)
|
||||
}
|
||||
for i, request := range client.requests {
|
||||
if request.Target.Model != model || request.Prompt.SessionID != "spell-session-override" || preparations[i].SelectedProfileID != "profile-spells" {
|
||||
t.Fatal("native profile/session/execution override lost")
|
||||
}
|
||||
wantID := PromptID
|
||||
if i > 0 {
|
||||
wantID = CorrectionPromptID
|
||||
}
|
||||
if preparations[i].PromptID != wantID {
|
||||
t.Fatalf("prompt = %q, want %q", preparations[i].PromptID, wantID)
|
||||
}
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
previous := client.requests[i-1].Prompt.Messages
|
||||
current := request.Prompt.Messages
|
||||
if len(current) != len(previous)+2 || !reflect.DeepEqual(current[:len(previous)], previous) {
|
||||
t.Fatal("native continuation did not retain exact ordered history")
|
||||
}
|
||||
if current[len(previous)].Role != "assistant" || current[len(previous)].Content != test.responses[i-1] ||
|
||||
!strings.Contains(current[len(previous)+1].Content, "recognized D&D spell") {
|
||||
t.Fatal("correction lost the actual candidate or catalog guidance")
|
||||
}
|
||||
if strings.Count(promptText(request), "party-grounding-sentinel") != 1 {
|
||||
t.Fatal("reference bytes were regenerated in correction")
|
||||
}
|
||||
}
|
||||
if test.wantError {
|
||||
return
|
||||
}
|
||||
if output.FallbackCount != test.fallbacks || len(output.OutputFiles) != 1 {
|
||||
t.Fatalf("outcome = %#v", output)
|
||||
}
|
||||
value, err := spellcodec.New().Decode(output.OutputFiles[0].Bytes)
|
||||
check(err)
|
||||
if test.fallbacks > 0 {
|
||||
if value.SpellCasts == nil || len(value.SpellCasts) != 0 {
|
||||
t.Fatalf("invalid empty fallback: %#v", value)
|
||||
}
|
||||
} else if len(value.SpellCasts) != 1 || value.SpellCasts[0].Spell != "Cure Wounds" || value.SpellCasts[0].SourceRefs[0].SourceID != "spell-session" {
|
||||
t.Fatalf("durable spell artifact = %#v", value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user