Reuse supplied analysis products without rebuilding their history
This commit is contained in:
@@ -63,10 +63,6 @@ func planAnalyzeWork(
|
||||
}
|
||||
targets := effective.Keys()
|
||||
targetSet := stringSet(targets)
|
||||
order, err := artifacts.AnalyzeTargetClosure(configured, targets)
|
||||
if err != nil {
|
||||
return analyzeWorkPlan{}, err
|
||||
}
|
||||
|
||||
reconciled := make(map[string]analyzeArtifactReconciliation, len(reconciliation.Ordered))
|
||||
removed := make([]analyzePlanItem, 0)
|
||||
@@ -79,6 +75,21 @@ func planAnalyzeWork(
|
||||
}
|
||||
sort.Slice(removed, func(i, j int) bool { return removed[i].Key < removed[j].Key })
|
||||
|
||||
// A supplied product is an input to this invocation. Its historical
|
||||
// prerequisites become work only when the product is explicitly regenerated.
|
||||
workGraph := make(map[string]config.ScriptoriumArtifactConfig, len(configured))
|
||||
for key, definition := range configured {
|
||||
_, target := targetSet[key]
|
||||
if reconciled[key].Reason == analyzeReconciliationSupplied && !(force && target) {
|
||||
definition.DependsOn = nil
|
||||
}
|
||||
workGraph[key] = definition
|
||||
}
|
||||
order, err := artifacts.AnalyzeTargetClosure(workGraph, targets)
|
||||
if err != nil {
|
||||
return analyzeWorkPlan{}, err
|
||||
}
|
||||
|
||||
plan := analyzeWorkPlan{
|
||||
ExplicitTargets: append([]string(nil), targets...),
|
||||
Removed: removed,
|
||||
|
||||
@@ -3,6 +3,7 @@ package stage
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
|
||||
@@ -54,6 +55,60 @@ func TestAnalyzeSuppliedPrerequisiteAndNewTarget(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnalyzeSuppliedProductsStopHistoricalDependencyWork(t *testing.T) {
|
||||
for _, child := range []bool{false, true} {
|
||||
name := "supplied target"
|
||||
if child {
|
||||
name = "new child of supplied prerequisite"
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
env, m := suppliedAnalyzeFixture(t)
|
||||
parent := env.Config.ArtifactCatalog.Artifacts["session_recap"]
|
||||
parent.DependsOn = []string{"historical"}
|
||||
env.Config.ArtifactCatalog.Artifacts["session_recap"] = parent
|
||||
env.Config.ArtifactCatalog.Artifacts["historical"] = config.ScriptoriumArtifactConfig{
|
||||
PromptID: "historical", OutputPath: "artifacts/historical.md",
|
||||
Inputs: map[string]config.ScriptoriumInputConfig{
|
||||
"transcript": {Source: artifacts.ArtifactTranscriptBase, Required: true},
|
||||
},
|
||||
}
|
||||
env.SelectedArtifactKeys = []string{"session_recap"}
|
||||
runner := &orderedScriptoriumRunner{RunBody: "new handout\n"}
|
||||
env.Scriptorium = runner
|
||||
if child {
|
||||
addAnalyzeDependentArtifact(env)
|
||||
env.SelectedArtifactKeys = []string{"player_handout"}
|
||||
}
|
||||
preview, err := (analyzeStage{}).ValidateResume(context.Background(), env, m)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantWork := 0
|
||||
if child {
|
||||
wantWork = 1
|
||||
}
|
||||
if len(preview.Analyze.ExecutionOrder) != wantWork || len(preview.Analyze.PrerequisiteWork) != 0 {
|
||||
t.Fatalf("historical work in preview: %+v", preview.Analyze)
|
||||
}
|
||||
if _, err := (analyzeStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(runner.Calls) != wantWork {
|
||||
t.Fatalf("calls %v, want %d generations", runner.Calls, wantWork)
|
||||
}
|
||||
if _, ok := m.SuppliedProducts.Products[artifacts.ConfiguredArtifactSourceID("session_recap")]; !ok {
|
||||
t.Fatal("lost accepted supplied product")
|
||||
}
|
||||
// Force reopens the supplied target's generation requirements.
|
||||
env.SelectedArtifactKeys = []string{"session_recap"}
|
||||
env.Force = true
|
||||
if _, err := (analyzeStage{}).Run(context.Background(), env, m); err == nil || !strings.Contains(err.Error(), "historical") {
|
||||
t.Fatalf("forced replacement should require historical input: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnalyzeForcedSuppliedTargetBecomesLocalCheckpoint(t *testing.T) {
|
||||
env, m := suppliedAnalyzeFixture(t)
|
||||
env.SelectedArtifactKeys = []string{"session_recap"}
|
||||
|
||||
Reference in New Issue
Block a user