Share read-only planning and analysis closure

This commit is contained in:
2026-11-26 04:19:33 +00:00
parent f1fb77baa0
commit 3e7200ef28
5 changed files with 172 additions and 73 deletions

View File

@@ -50,6 +50,64 @@ func TestPlanDoesNotCreateWorkdir(t *testing.T) {
}
type observingArtifactStore struct {
artifacts.Store
pathLookups int
}
func (s *observingArtifactStore) SessionPathsFor(campaign, sessionID string) artifacts.SessionPaths {
s.pathLookups++
return s.Store.SessionPathsFor(campaign, sessionID)
}
func TestProjectionUsesInjectedSnapshotAndSchedulesPrerequisites(t *testing.T) {
pipeline, campaign, session := writeValidConfigFilesWithScriptoriumArtifacts(t, t.TempDir())
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
if err != nil {
t.Fatal(err)
}
cfg.ArtifactCatalog.Artifacts = map[string]config.ScriptoriumArtifactConfig{
"prerequisite": {Enabled: false, PromptID: "parent", OutputPath: "artifacts/parent.md"},
"target": {Enabled: true, PromptID: "child", OutputPath: "artifacts/child.md", DependsOn: []string{"prerequisite"}},
}
selection := []string{"target"}
effective, err := resolveEffectiveArtifacts(cfg, selection)
if err != nil {
t.Fatal(err)
}
plan, err := BuildBoundedPlan("analyze", "analyze")
if err != nil {
t.Fatal(err)
}
snapshot := manifest.New(cfg.Session.SessionID, time.Now().UTC())
snapshot.Campaign = cfg.Session.Campaign
snapshot.MarkStageSucceeded("analyze", time.Now().UTC(), nil)
snapshot.Stages["analyze"].AnalyzeStateVersion = manifest.AnalyzeStateContractVersion
snapshot.Stages["analyze"].AnalyzeArtifacts = map[string]manifest.AnalyzeArtifactRecord{"target": {Key: "target", Status: manifest.AnalyzeArtifactMissing, ProducerRunID: "prior", UpdatedAt: time.Now().UTC()}}
before, err := cloneManifestForPlan(snapshot, cfg)
if err != nil {
t.Fatal(err)
}
store := &observingArtifactStore{Store: artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)}
projection, err := projectSelectedWork(context.Background(), cfg, plan, false, selection, effective, store, snapshot)
if err != nil {
t.Fatal(err)
}
if store.pathLookups == 0 {
t.Fatal("projection did not use injected store")
}
if !reflect.DeepEqual(snapshot, before) {
t.Fatal("projection mutated authoritative manifest")
}
if len(projection.Stages) != 1 || projection.Stages[0].Analysis == nil {
t.Fatalf("projection = %+v", projection)
}
work := projection.Stages[0].Analysis.ExecutionOrder
if len(work) != 2 || work[0].Key != "prerequisite" || work[1].Key != "target" {
t.Fatalf("scheduled work = %+v", work)
}
}
func TestPlanShowsRunAndSkipFromManifest(t *testing.T) {
workspaceRoot := t.TempDir()
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)