Use derived artifact catalogs throughout planning and execution
This commit is contained in:
128
internal/app/catalog_execution_test.go
Normal file
128
internal/app/catalog_execution_test.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
func TestSelectedPartyCatalogDrivesBoundedAnalysis(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
||||
mustWriteTestFile(t, pipelinePath, `workspace:
|
||||
root: `+filepath.Join(dir, "work")+`
|
||||
scriptorium:
|
||||
artifact_families:
|
||||
character_meta:
|
||||
enabled: false
|
||||
for_each: party.characters
|
||||
prompt_id: meta
|
||||
output_path_pattern: artifacts/{character_id}/meta.md
|
||||
inputs:
|
||||
players: {source: narratio.input.players, required: true}
|
||||
character_note:
|
||||
enabled: false
|
||||
for_each: party.characters
|
||||
prompt_id: note
|
||||
output_path_pattern: artifacts/{character_id}/note.md
|
||||
inputs:
|
||||
meta: {source: narratio.member_artifact.character_meta, required: true}
|
||||
member_vars:
|
||||
character_name: character.name
|
||||
`)
|
||||
campaignPath := filepath.Join(dir, "campaign.yml")
|
||||
mustWriteTestFile(t, campaignPath, "campaign_id: campaign\ninputs: {speakers_file: speakers.yml, autocorrect_file: autocorrect.yml, glossary_file: glossary.yml, party_file: default-party.yml}\n")
|
||||
partyPath := filepath.Join(dir, "selected-party.yml")
|
||||
mustWriteTestFile(t, partyPath, "schema_version: narratio.party.v1\ncharacters:\n ivy:\n player: {name: Selected Player}\n character: {name: Ivy, classes: [{name: ranger}]}\n")
|
||||
sessionPath := filepath.Join(dir, "session.yml")
|
||||
mustWriteTestFile(t, sessionPath, "session_id: session\ninputs: {audio_dir: audio}\n")
|
||||
pipeline, err := config.LoadPipeline(pipelinePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
campaign, err := config.LoadCampaign(campaignPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := config.LoadPipelineCampaignWithPartyFile(pipelinePath, pipeline, campaignPath, campaign, &partyPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg, err := config.LoadSessionWithPipelineCampaignOptions(loaded, sessionPath, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, err := json.Marshal(cfg.Pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plan, err := BuildBoundedPlan("analyze", "analyze")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor("campaign", "session")
|
||||
now := time.Now().UTC()
|
||||
seed := manifest.New("session", now)
|
||||
seed.Campaign = "campaign"
|
||||
for _, name := range plan.PrefixNames() {
|
||||
seed.MarkStageSucceeded(name, now, nil)
|
||||
}
|
||||
playersPath := filepath.Join(paths.InputsDir, "players.yml")
|
||||
mustWriteTestFile(t, playersPath, string(cfg.Party.Players))
|
||||
checksum, err := artifacts.SHA256File(playersPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
descriptor, ok := artifactpolicy.DescribePreparedInputSource("narratio.input.players")
|
||||
if !ok {
|
||||
t.Fatal("players source is unavailable")
|
||||
}
|
||||
seed.Inputs = append(seed.Inputs, manifest.InputRecord{Kind: descriptor.ManifestKind, Path: playersPath, Checksum: checksum})
|
||||
saveBoundedManifest(t, cfg, seed)
|
||||
runner := &scriptorium.FakeRunner{}
|
||||
summary, err := executePlan(context.Background(), cfg, plan, RunOptions{
|
||||
SelectedArtifacts: []string{"character_note"},
|
||||
Env: &Env{Scriptorium: runner, Logger: slog.New(slog.NewTextHandler(io.Discard, nil))},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(summary.Executed, []string{"analyze"}) || len(runner.RunRequests) != 2 || runner.RunRequests[0].PromptID != "meta" || runner.RunRequests[1].PromptID != "note" {
|
||||
t.Fatalf("bounded family execution: summary=%+v requests=%+v", summary, runner.RunRequests)
|
||||
}
|
||||
players, err := os.ReadFile(runner.RunRequests[0].InputPaths["players"])
|
||||
if err != nil || !strings.Contains(string(players), "Selected Player") || runner.RunRequests[1].Vars["character_name"] != "Ivy" {
|
||||
t.Fatalf("selected roster did not reach both domain consumers: %v", err)
|
||||
}
|
||||
current, err := (&manifest.LocalStore{}).Load(context.Background(), manifestPathFor(cfg))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, key := range []string{"character_meta_ivy", "character_note_ivy"} {
|
||||
record := current.Stages["analyze"].AnalyzeArtifacts[key]
|
||||
if record.Status != manifest.AnalyzeArtifactCurrent || record.CharacterID != "ivy" || record.Family == "" {
|
||||
t.Fatalf("family output identity: %+v", record)
|
||||
}
|
||||
}
|
||||
after, err := json.Marshal(cfg.Pipeline)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(before, after) || len(cfg.Pipeline.Scriptorium.Artifacts) != 0 {
|
||||
t.Fatal("execution changed completed pipeline configuration")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user