Collect previous history for artifact prerequisites
This commit is contained in:
@@ -100,7 +100,7 @@ remain behaviorally unchanged.
|
||||
|
||||
## Stage 2: Collect and consume prerequisite-inclusive history requirements
|
||||
|
||||
Status: Pending
|
||||
Status: Complete
|
||||
|
||||
Read `internal/artifacts/previous_requirements.go`, `effective_set.go`,
|
||||
`internal/stage/prepare.go`, `semantic_contracts_initial.go`, and the callers
|
||||
|
||||
@@ -378,7 +378,10 @@ func buildPreviousCacheRestoreActions(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
requirements := artifacts.CollectPreviousArtifactRequirements(cfg.ConcreteArtifacts(), effective)
|
||||
requirements, err := artifacts.CollectPreviousArtifactRequirements(cfg.ConcreteArtifacts(), effective)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(requirements) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -510,9 +510,9 @@ func manifestPathFor(cfg *config.Config) string {
|
||||
)
|
||||
}
|
||||
|
||||
func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveSets ...artifacts.EffectiveArtifactSet) bool {
|
||||
func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveSets ...artifacts.EffectiveArtifactSet) (bool, error) {
|
||||
if cfg == nil || cfg.Pipeline == nil || cfg.Session == nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
effective := artifacts.EffectiveArtifactSet{}
|
||||
if len(effectiveSets) > 0 {
|
||||
@@ -525,7 +525,7 @@ func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveS
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
stageRequested := func(name string) bool {
|
||||
@@ -538,27 +538,30 @@ func needsObjectStoreForRun(cfg *config.Config, stages []stage.Stage, effectiveS
|
||||
}
|
||||
|
||||
if cfg.Session.Inputs.AudioS3 != nil && stageRequested("prepare") {
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
if stageRequested("prepare") {
|
||||
requirements := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
||||
requirements, err := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(requirements) > 0 && strings.TrimSpace(cfg.Session.PreviousSessionID) != "" {
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
if !stageRequested("publish") {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if cfg.Pipeline.Publish == nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if cfg.Pipeline.Publish.Enabled != nil && !*cfg.Pipeline.Publish.Enabled {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if cfg.Pipeline.Publish.UploadRun != nil && !*cfg.Pipeline.Publish.UploadRun {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func needsNotariusForRun(cfg *config.Config, stages []stage.Stage) bool {
|
||||
|
||||
@@ -56,7 +56,11 @@ func composeInvocation(runtime *invocationRuntime, stages []stage.Stage) error {
|
||||
if err := runtime.ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if env.ObjectStore == nil && needsObjectStoreForRun(env.Config, stages, runtime.effectiveArtifacts) {
|
||||
needStore, err := needsObjectStoreForRun(env.Config, stages, runtime.effectiveArtifacts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if env.ObjectStore == nil && needStore {
|
||||
objectStore, err := dependencies.newObjectStore(runtime.ctx, env.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -455,7 +455,6 @@ func TestNeedsObjectStoreForRunPrepareWithPreviousRequirements(t *testing.T) {
|
||||
Scriptorium: &config.ScriptoriumConfig{
|
||||
Artifacts: map[string]config.ScriptoriumArtifactConfig{
|
||||
"session_recap": {
|
||||
Enabled: true,
|
||||
Inputs: map[string]config.ScriptoriumInputConfig{
|
||||
"previous_recap": {
|
||||
Source: "narratio.previous_session.artifact.session_recap",
|
||||
@@ -471,8 +470,12 @@ func TestNeedsObjectStoreForRunPrepareWithPreviousRequirements(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
cfg.Pipeline.Scriptorium.Artifacts["child"] = config.ScriptoriumArtifactConfig{Enabled: true, DependsOn: []string{"session_recap"}}
|
||||
cfg.ArtifactCatalog = &config.ArtifactCatalog{Artifacts: cfg.Pipeline.Scriptorium.Artifacts}
|
||||
got := needsObjectStoreForRun(cfg, []stage.Stage{countingStage{name: "prepare", runs: new(int)}})
|
||||
got, err := needsObjectStoreForRun(cfg, []stage.Stage{countingStage{name: "prepare", runs: new(int)}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Fatalf("needsObjectStoreForRun() = %v, want %v", got, tt.want)
|
||||
}
|
||||
@@ -1553,3 +1556,27 @@ func projectedTestPlayers(t *testing.T, party *config.CanonicalParty) []byte {
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func TestNeedsObjectStoreRespectsSelectedPrerequisites(t *testing.T) {
|
||||
definitions := map[string]config.ScriptoriumArtifactConfig{
|
||||
"child": {Enabled: true, DependsOn: []string{"parent"}},
|
||||
"parent": {Inputs: map[string]config.ScriptoriumInputConfig{"history": {Source: "narratio.previous_session.artifact.history", Required: true}}},
|
||||
"other": {Enabled: true},
|
||||
}
|
||||
cfg := &config.Config{Pipeline: &config.PipelineConfig{Scriptorium: &config.ScriptoriumConfig{Artifacts: definitions}}, Session: &config.SessionConfig{PreviousSessionID: "previous"}, ArtifactCatalog: &config.ArtifactCatalog{Artifacts: definitions}}
|
||||
for _, tc := range []struct {
|
||||
selected string
|
||||
want bool
|
||||
}{{"child", true}, {"other", false}} {
|
||||
t.Run(tc.selected, func(t *testing.T) {
|
||||
effective, err := artifacts.ResolveEffectiveArtifactSet(artifacts.ConfiguredArtifactDefinitions(definitions), []string{tc.selected})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := needsObjectStoreForRun(cfg, []stage.Stage{countingStage{name: "prepare", runs: new(int)}}, effective)
|
||||
if err != nil || got != tc.want {
|
||||
t.Fatalf("store needed = %v, error = %v", got, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,12 @@ func inspectSessionState(ctx context.Context, cfg *config.Config, status, remote
|
||||
effective, err := resolveEffectiveArtifacts(cfg, nil)
|
||||
fail("artifacts", err)
|
||||
if err == nil {
|
||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective))
|
||||
requirements, collectErr := artifacts.CollectPreviousArtifactRequirements(configuredScriptoriumArtifacts(cfg), effective)
|
||||
fail("artifacts", collectErr)
|
||||
if collectErr != nil {
|
||||
return report, resultErr
|
||||
}
|
||||
previous := inspectPreviousArtifactReadiness(ctx, cfg, store, requirements)
|
||||
fail("previous", previous.Err)
|
||||
for _, requirement := range previous.Requirements {
|
||||
state := "ready"
|
||||
|
||||
@@ -79,7 +79,10 @@ func TestCollectPreviousArtifactRequirementsUsesExactEffectiveSet(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatalf("ResolveEffectiveArtifactSet() error = %v", err)
|
||||
}
|
||||
requirements := CollectPreviousArtifactRequirements(configured, effective)
|
||||
requirements, err := CollectPreviousArtifactRequirements(configured, effective)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(requirements) != 1 || requirements[0].Name != "explicit_artifact" || !requirements[0].Required {
|
||||
t.Fatalf("requirements = %#v, want only the explicit artifact prerequisite", requirements)
|
||||
}
|
||||
|
||||
@@ -16,24 +16,25 @@ type PreviousArtifactRequirement struct {
|
||||
Sources []string
|
||||
}
|
||||
|
||||
// CollectPreviousArtifactRequirements scans the effective Scriptorium artifact
|
||||
// set and returns deduplicated previous-session requirements in deterministic order.
|
||||
// CollectPreviousArtifactRequirements scans targets and their prerequisites for
|
||||
// deduplicated previous-session requirements in deterministic order.
|
||||
func CollectPreviousArtifactRequirements(
|
||||
artifactsCfg map[string]config.ScriptoriumArtifactConfig,
|
||||
effective EffectiveArtifactSet,
|
||||
) []PreviousArtifactRequirement {
|
||||
if len(artifactsCfg) == 0 {
|
||||
return nil
|
||||
) ([]PreviousArtifactRequirement, error) {
|
||||
if len(effective.Keys()) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
artifactNames := sortedScriptoriumArtifactNames(artifactsCfg)
|
||||
artifactNames, err := AnalyzeTargetClosure(artifactsCfg, effective.Keys())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort.Strings(artifactNames)
|
||||
byName := map[string]PreviousArtifactRequirement{}
|
||||
|
||||
for _, artifactName := range artifactNames {
|
||||
artifactCfg := artifactsCfg[artifactName]
|
||||
if !effective.Includes(artifactName) {
|
||||
continue
|
||||
}
|
||||
|
||||
inputNames := sortedScriptoriumInputKeys(artifactCfg.Inputs)
|
||||
for _, inputName := range inputNames {
|
||||
@@ -58,7 +59,7 @@ func CollectPreviousArtifactRequirements(
|
||||
}
|
||||
|
||||
if len(byName) == 0 {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
requirements := make([]PreviousArtifactRequirement, 0, len(byName))
|
||||
@@ -69,16 +70,7 @@ func CollectPreviousArtifactRequirements(
|
||||
sort.Slice(requirements, func(i, j int) bool {
|
||||
return requirements[i].Name < requirements[j].Name
|
||||
})
|
||||
return requirements
|
||||
}
|
||||
|
||||
func sortedScriptoriumArtifactNames(artifactsCfg map[string]config.ScriptoriumArtifactConfig) []string {
|
||||
names := make([]string, 0, len(artifactsCfg))
|
||||
for name := range artifactsCfg {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
return requirements, nil
|
||||
}
|
||||
|
||||
func sortedScriptoriumInputKeys(inputs map[string]config.ScriptoriumInputConfig) []string {
|
||||
|
||||
@@ -185,10 +185,43 @@ func TestCollectPreviousArtifactRequirements(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("ResolveEffectiveArtifactSet() error = %v", err)
|
||||
}
|
||||
got := CollectPreviousArtifactRequirements(tt.artifactsCfg, effective)
|
||||
got, err := CollectPreviousArtifactRequirements(tt.artifactsCfg, effective)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Fatalf("CollectPreviousArtifactRequirements() = %#v, want %#v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreviousRequirementsFollowSelectedPrerequisites(t *testing.T) {
|
||||
configured := map[string]config.ScriptoriumArtifactConfig{
|
||||
"child": {Enabled: true, DependsOn: []string{"parent"}},
|
||||
"parent": {DependsOn: []string{"base"}, Inputs: map[string]config.ScriptoriumInputConfig{"optional": {Source: "narratio.previous_session.artifact.history"}}},
|
||||
"base": {Inputs: map[string]config.ScriptoriumInputConfig{"required": {Source: "narratio.previous_session.artifact.history", Required: true}}},
|
||||
"other": {Enabled: true, Inputs: map[string]config.ScriptoriumInputConfig{"other": {Source: "narratio.previous_session.artifact.other", Required: true}}},
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
selected []string
|
||||
want int
|
||||
}{
|
||||
{"default", nil, 2}, {"explicit", []string{"child"}, 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
effective, err := ResolveEffectiveArtifactSet(ConfiguredArtifactDefinitions(configured), tc.selected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := CollectPreviousArtifactRequirements(configured, effective)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != tc.want || got[0].Name != "history" || !got[0].Required || len(got[0].Sources) != 2 {
|
||||
t.Fatalf("requirements = %#v", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ func collectPreparePreviousRequirements(cfg *config.Config, effective artifacts.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return artifacts.CollectPreviousArtifactRequirements(cfg.ConcreteArtifacts(), effective), nil
|
||||
return artifacts.CollectPreviousArtifactRequirements(cfg.ConcreteArtifacts(), effective)
|
||||
}
|
||||
|
||||
func clearManagedPreviousState(paths artifacts.SessionPaths) error {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
@@ -46,6 +47,40 @@ func TestPrepareSemanticConfigSensitivity(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrepareSemanticConfigIncludesPrerequisiteHistory(t *testing.T) {
|
||||
env := initialSemanticEnv()
|
||||
definitions := map[string]config.ScriptoriumArtifactConfig{
|
||||
"child": {Enabled: true, DependsOn: []string{"parent"}},
|
||||
"parent": {}, "other": {},
|
||||
}
|
||||
env.Config.Pipeline.Scriptorium = &config.ScriptoriumConfig{Artifacts: definitions}
|
||||
env.Config.ArtifactCatalog = &config.ArtifactCatalog{Artifacts: definitions}
|
||||
before, err := buildPrepareSemanticConfig(env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parent := definitions["parent"]
|
||||
parent.Inputs = map[string]config.ScriptoriumInputConfig{"history": {Source: "narratio.previous_session.artifact.history", Required: true}}
|
||||
definitions["parent"] = parent
|
||||
after, err := buildPrepareSemanticConfig(env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reflect.DeepEqual(before, after) {
|
||||
t.Fatal("reachable history did not change preparation evidence")
|
||||
}
|
||||
other := definitions["other"]
|
||||
other.Inputs = map[string]config.ScriptoriumInputConfig{"history": {Source: "narratio.previous_session.artifact.other", Required: true}}
|
||||
definitions["other"] = other
|
||||
unrelated, err := buildPrepareSemanticConfig(env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(after, unrelated) {
|
||||
t.Fatal("unrelated history changed preparation evidence")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareSemanticConfigRecordsCanonicalProjectionVersion(t *testing.T) {
|
||||
env := initialSemanticEnv()
|
||||
payload, err := buildPrepareSemanticConfig(env)
|
||||
|
||||
Reference in New Issue
Block a user