Verify durable reuse after session cleanup
This commit is contained in:
@@ -242,7 +242,7 @@ completion or reuse leaves no newly recreated `runs/` tree.
|
||||
|
||||
## Stage 5: Prove Durable Reuse And Downstream Development After Cleanup
|
||||
|
||||
Status: Pending.
|
||||
Status: Complete.
|
||||
|
||||
Read the existing reuse fixtures, stage semantic-resume tests,
|
||||
`internal/app/restore_workflow_test.go`, and the Stage 1 extraction tests. Build
|
||||
|
||||
104
internal/app/cleanup_reuse_test.go
Normal file
104
internal/app/cleanup_reuse_test.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/scriptorium"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
)
|
||||
|
||||
func TestCleanedSessionReusesProductsAndSupportsForcedAnalysis(t *testing.T) {
|
||||
cfg, env, notarius := extractionLifecycleFixture(t, true)
|
||||
cfg.Pipeline.Workspace.CleanupAfterPublish = true
|
||||
cfg.Pipeline.Storage.S3 = &config.StorageS3Config{Bucket: "archive", RootPrefix: "dnd"}
|
||||
cfg.Pipeline.Scriptorium = &config.ScriptoriumConfig{
|
||||
Binary: "scriptorium", Timeout: "1m",
|
||||
Artifacts: map[string]config.ScriptoriumArtifactConfig{
|
||||
"recap": {Enabled: true, PromptID: "test.recap", OutputPath: "artifacts/recap.md", Inputs: map[string]config.ScriptoriumInputConfig{
|
||||
"transcript": {Source: artifacts.ArtifactTranscriptFinalTrimmed, Required: true},
|
||||
"npcs": {Source: artifacts.ExtractionArtifactSourceID("npc_registry"), Required: true},
|
||||
}},
|
||||
},
|
||||
}
|
||||
var err error
|
||||
cfg.ArtifactCatalog, err = config.DeriveArtifactCatalog(cfg.Pipeline, cfg.Party)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
seed := loadLifecycleManifest(t, cfg)
|
||||
trim := seed.Stages["trim"]
|
||||
if err := os.WriteFile(filepath.Join(paths.AudioDir, "alice.flac"), []byte("synthetic audio"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seed.Inputs = append(seed.Inputs, manifest.InputRecord{Kind: "audio", Path: "audio/alice.flac"})
|
||||
seed.MarkStageSucceeded("prepare", time.Now().UTC(), nil)
|
||||
if err := (&manifest.LocalStore{}).Save(context.Background(), paths.ManifestPath, seed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
whisper := &whisperx.FakeClient{}
|
||||
env.WhisperX = whisper
|
||||
if _, err := executeStages(context.Background(), cfg, []stage.Stage{mustSelectStage(t, "transcribe")}, RunOptions{Env: env}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seed = loadLifecycleManifest(t, cfg)
|
||||
seed.Stages["trim"] = trim
|
||||
if err := (&manifest.LocalStore{}).Save(context.Background(), paths.ManifestPath, seed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
runner := &scriptorium.FakeRunner{}
|
||||
env.Scriptorium = runner
|
||||
publishRuns := 0
|
||||
plan := BoundedPlan{stages: []stage.Stage{mustSelectStage(t, "transcribe"), mustSelectStage(t, "extract"), mustSelectStage(t, "analyze"), cleanupPublishEvidenceStage{runs: &publishRuns}, resultStage{name: "notify"}, selectedCleanupStage(t)}}
|
||||
invoke := func(id string, selected BoundedPlan, force bool) *RunSummary {
|
||||
t.Helper()
|
||||
deps := cleanupOrchestrationDependencies()
|
||||
deps.newRunID = func() (string, error) { return id, nil }
|
||||
summary, err := executePlanWithDependencies(context.Background(), cfg, selected, RunOptions{Env: env, Force: force}, deps)
|
||||
if err != nil {
|
||||
t.Fatalf("invocation %s: %v", id, err)
|
||||
}
|
||||
return summary
|
||||
}
|
||||
invoke("processing-run", plan, false)
|
||||
if _, err := os.Lstat(paths.RunsDir); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("run history remains: %v", err)
|
||||
}
|
||||
loaded := loadLifecycleManifest(t, cfg)
|
||||
if !loaded.Stages["transcribe"].HasVersionedTranscribeState() || loaded.Stages["extract"].Status != manifest.StatusSucceeded || !loaded.Stages["analyze"].HasVersionedAnalyzeState() {
|
||||
t.Fatalf("durable records: %#v", loaded.Stages)
|
||||
}
|
||||
if len(notarius.requests) != 1 || len(runner.RunRequests) != 1 {
|
||||
t.Fatalf("initial calls: extraction=%d analysis=%d", len(notarius.requests), len(runner.RunRequests))
|
||||
}
|
||||
summary := invoke("reuse-run", plan, false)
|
||||
if len(summary.Executed) != 0 || len(notarius.requests) != 1 || len(runner.RunRequests) != 1 || len(whisper.RequestsSnapshot()) != 1 {
|
||||
t.Fatalf("reuse = %#v calls: extraction=%d analysis=%d", summary, len(notarius.requests), len(runner.RunRequests))
|
||||
}
|
||||
if _, err := os.Lstat(paths.RunsDir); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("reuse recreated runs: %v", err)
|
||||
}
|
||||
invoke("analysis-run", BoundedPlan{stages: []stage.Stage{mustSelectStage(t, "analyze")}}, true)
|
||||
if len(notarius.requests) != 1 || len(runner.RunRequests) != 2 || publishRuns != 1 {
|
||||
t.Fatalf("forced calls: extraction=%d analysis=%d publish=%d", len(notarius.requests), len(runner.RunRequests), publishRuns)
|
||||
}
|
||||
request := runner.RunRequests[1]
|
||||
if request.InputPaths["transcript"] != filepath.Join(paths.ArtifactsDir, "trimmed.from-manifest.json") || request.InputPaths["npcs"] != filepath.Join(paths.ArtifactsDir, "npc_registry.json") {
|
||||
t.Fatalf("analysis inputs = %#v", request.InputPaths)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(paths.RunsDir, "analysis-run")); err != nil {
|
||||
t.Fatalf("analysis diagnostics missing: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(paths.ArtifactsDir, "recap.md")); err != nil {
|
||||
t.Fatalf("canonical output missing: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user