diff --git a/docs/internal/stage-analyze.md b/docs/internal/stage-analyze.md index 0f5b303..f13eebf 100644 --- a/docs/internal/stage-analyze.md +++ b/docs/internal/stage-analyze.md @@ -92,9 +92,10 @@ Supported source families: generation inputs or fingerprint. - owns a read-only typed work planner. Its explicit targets are enabled artifacts by default or the exact normalized `--artifacts` selection when - supplied. It closes targets over configured prerequisites, orders the closure - topologically, reuses current members, and schedules every non-current member - before its dependents. + supplied. It closes targets over configured prerequisites, stopping at valid + supplied products unless they are explicit forced targets. It orders the work + topologically, reuses current or supplied members, and schedules non-current + members before their dependents. - force applies only to explicit targets. A current prerequisite is reused unless it is itself an explicit forced target; disabled prerequisites may be rebuilt when required, while unrelated disabled artifacts are excluded. diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 633022e..c3646d2 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -11,7 +11,13 @@ product requirements or an implementation plan. ## 1. P2: Stop dependency work at accepted supplied analysis products -Status: Open +Status: Complete + +Resolution: the analysis planner closes the active work graph at accepted +supplied products, except explicit forced targets. Behavioral regressions cover +preview and execution for a supplied target and a new child, with absent +historical inputs, plus forced replacement. Verified with +`go test ./internal/stage ./internal/artifacts ./internal/manifest`. Affected stages: 4, 5, and 12. diff --git a/internal/stage/analyze_plan.go b/internal/stage/analyze_plan.go index ba31058..e091e06 100644 --- a/internal/stage/analyze_plan.go +++ b/internal/stage/analyze_plan.go @@ -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, diff --git a/internal/stage/analyze_supplied_test.go b/internal/stage/analyze_supplied_test.go index 6c846f9..252c5cf 100644 --- a/internal/stage/analyze_supplied_test.go +++ b/internal/stage/analyze_supplied_test.go @@ -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"}