Share read-only planning and analysis closure
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
@@ -56,3 +59,84 @@ func plannedSelfSkipReason(stageName string, cfg *config.Config) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type workProjection struct {
|
||||
Stages []projectedStage
|
||||
Model *manifest.Manifest
|
||||
}
|
||||
|
||||
type projectedStage struct {
|
||||
Name string
|
||||
Decision preExecutionDecision
|
||||
Reason string
|
||||
Analysis *stage.AnalyzeResumeSummary
|
||||
}
|
||||
|
||||
func projectSelectedWork(ctx context.Context, cfg *config.Config, plan BoundedPlan, force bool, selectedArtifacts []string, effective artifacts.EffectiveArtifactSet, store artifacts.Store, snapshot *manifest.Manifest) (*workProjection, error) {
|
||||
model, err := cloneManifestForPlan(snapshot, cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plan: clone session state: %w", err)
|
||||
}
|
||||
|
||||
stages := plan.Stages()
|
||||
stageEnv := &stage.Env{
|
||||
Config: cfg, SelectedArtifactKeys: append([]string(nil), selectedArtifacts...),
|
||||
EffectiveArtifacts: effective, ArtifactStore: store, Force: force,
|
||||
}
|
||||
|
||||
projection := &workProjection{Model: model}
|
||||
for _, selectedStage := range stages {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return projection, err
|
||||
}
|
||||
semanticConfig, err := currentStageSemanticConfig(selectedStage, stageEnv)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plan: fingerprint semantic configuration for stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
decision := decideStageExecution(recordedStageStatus(model, selectedStage.Name()), force, nil)
|
||||
var validation *stage.ResumeValidation
|
||||
if decision.action == stageActionSkip {
|
||||
checked, validationErr := evaluateStageResume(ctx, selectedStage, stageEnv, model, semanticConfig)
|
||||
if validationErr != nil {
|
||||
return nil, fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||
}
|
||||
validation = checked
|
||||
decision = decideStageExecution(recordedStageStatus(model, selectedStage.Name()), force, checked)
|
||||
}
|
||||
if _, err := applyPreExecutionDecision(model, selectedStage.Name(), decision, time.Now().UTC()); err != nil {
|
||||
return nil, fmt.Errorf("plan: model resume invalidation for stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
if decision.action == stageActionRun && selectedStage.Name() == "analyze" {
|
||||
if validator, ok := selectedStage.(stage.ResumeValidator); ok {
|
||||
checked, validationErr := validator.ValidateResume(ctx, stageEnv, model)
|
||||
if validationErr != nil {
|
||||
return nil, fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||
}
|
||||
checked = checked.Normalized()
|
||||
validation = &checked
|
||||
}
|
||||
}
|
||||
reason := decision.selectedStaleReason
|
||||
if reason == "" {
|
||||
switch {
|
||||
case force:
|
||||
reason = "forced"
|
||||
case decision.action == stageActionSkip:
|
||||
reason = "recorded result is reusable"
|
||||
default:
|
||||
reason = "no reusable successful result"
|
||||
}
|
||||
}
|
||||
entry := projectedStage{Name: selectedStage.Name(), Decision: decision, Reason: reason}
|
||||
if validation != nil {
|
||||
entry.Analysis = validation.Analyze
|
||||
}
|
||||
projection.Stages = append(projection.Stages, entry)
|
||||
if decision.action == stageActionRun {
|
||||
if err := modelPlannedStageRun(model, selectedStage, cfg, decision, semanticConfig); err != nil {
|
||||
return nil, fmt.Errorf("plan: model stage %q: %w", selectedStage.Name(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return projection, ctx.Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user