Keep source provenance out of prepare reuse decisions

This commit is contained in:
2026-11-20 13:40:55 +00:00
parent 32ff928786
commit 846f8470dc
4 changed files with 104 additions and 10 deletions

View File

@@ -0,0 +1,90 @@
package app
import (
"bytes"
"context"
"encoding/json"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
"go.maximumdirect.net/commandkit"
)
func TestEquivalentPartySelectionPreservesPreparedWork(t *testing.T) {
ctx := context.Background()
root := t.TempDir()
pipeline, campaign, session := writeValidConfigFiles(t, root)
selection := []string{"--stage", "prepare", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--format", "json"}
invoke := func(command []string, result any) {
t.Helper()
var out, diagnostic bytes.Buffer
outcome := Execute(ctx, command, commandkit.Streams{Out: &out, Err: &diagnostic})
if outcome.Status != 0 {
t.Fatalf("%v: status=%d diagnostics=%s", command, outcome.Status, &diagnostic)
}
if err := json.Unmarshal(out.Bytes(), result); err != nil {
t.Fatal(err)
}
}
var run runReport
invoke(append([]string{"run", "2026-05-03"}, selection...), &run)
path := artifacts.SessionManifestPathForCampaign(root, "sample-campaign", "2026-05-03")
store := &manifest.LocalStore{}
before, err := store.Load(ctx, path)
if err != nil {
t.Fatal(err)
}
before.MarkStageSucceeded("transcribe", time.Now().UTC(), nil)
if err := store.Save(ctx, path, before); err != nil {
t.Fatal(err)
}
checksums := func(m *manifest.Manifest) map[string]string {
result := map[string]string{}
for _, input := range m.Inputs {
result[input.Kind+"\x00"+input.Path] = input.Checksum
}
return result
}
partyPath := filepath.Join(filepath.Dir(campaign), "party.yml")
selection = append(selection, "--party-file", partyPath)
var plan sessionPlanReport
invoke(append([]string{"session", "plan", "2026-05-03"}, selection...), &plan)
if len(plan.Stages) != 1 || plan.Stages[0].Action != string(stageActionSkip) {
t.Fatalf("equivalent roster plan=%#v", plan)
}
invoke(append([]string{"run", "2026-05-03"}, selection...), &run)
after, err := store.Load(ctx, path)
if err != nil {
t.Fatal(err)
}
if len(run.Executed) != 0 || after.Stages["transcribe"].Status != manifest.StatusSucceeded || !reflect.DeepEqual(checksums(before), checksums(after)) {
t.Fatalf("equivalent selection reran work: report=%#v transcription=%v", run, after.Stages["transcribe"].Status)
}
party, err := os.ReadFile(partyPath)
if err != nil {
t.Fatal(err)
}
changed := strings.Replace(string(party), "Arannis", "Arannis Changed", 1)
if changed == string(party) {
t.Fatal("fixture did not contain the expected character")
}
mustWriteTestFile(t, partyPath, changed)
invoke(append([]string{"session", "plan", "2026-05-03"}, selection...), &plan)
if len(plan.Stages) != 1 || plan.Stages[0].Action != string(stageActionRun) {
t.Fatalf("changed roster plan=%#v", plan)
}
invoke(append([]string{"run", "2026-05-03"}, selection...), &run)
after, err = store.Load(ctx, path)
if err != nil {
t.Fatal(err)
}
if len(run.Executed) != 1 || after.Stages["transcribe"].Status != manifest.StatusStale || reflect.DeepEqual(checksums(before), checksums(after)) {
t.Fatalf("changed roster retained old work: report=%#v transcription=%v", run, after.Stages["transcribe"].Status)
}
}