diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 7753f658..159b5c69 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -84,7 +84,7 @@ type Have struct { Run string // Pipeline is the pipeline of the want the module was applied from, its key ., kept beside Run // (H-A-429 (1), H-A-458 (1); nodeengine.HaveByNodeModuleValue.Pipeline): a want's run is compared with Run only when - // the want names the same pipeline. Kept and replaced together with Run. + // the want's pipeline is of the same branch (pipelineBranch). Kept and replaced together with Run. Pipeline string } @@ -1536,8 +1536,9 @@ func (a *Agent) settleOne(ctx context.Context, module string) { } // Design 47 H2 ยง813 (1), H-A-384 (2): the run the module was applied from is its have's, never this engine's memory, so // a restarted engine applies no older run again. Read only for a want that carries one, and compared only within the - // want's pipeline: a want of another pipeline is a placement the assigner made on purpose and replaces whatever stands - // (H-A-429 (1), H-A-458 (1)). + // want's branch: a want of another branch is a placement the assigner made on purpose and replaces whatever stands + // (H-A-429 (1), H-A-458 (1)). A pipeline's key is ., so every pipeline of a branch has its own key and + // the branch is the key without its last part. appliedRun := "" if w.Want.Run != "" { h, found, unread := a.readHave(ctx, module) @@ -1548,7 +1549,7 @@ func (a *Agent) settleOne(ctx context.Context, module string) { a.mu.Unlock() return } - if found && h.Pipeline == w.Want.Pipeline { + if found && pipelineBranch(h.Pipeline) == pipelineBranch(w.Want.Pipeline) { appliedRun = h.Run } } @@ -1903,6 +1904,15 @@ func (a *Agent) takenAtStart(module string, runs compositions.Composed) { // pipeline (settleOne compares no runs of two, H-A-458 (1)): each is // the composition run's pipeline sequence in decimal. A want or an apply without one is not ordered by run, nor is a run // that is no decimal number. +// pipelineBranch is the branch of a pipeline's key . (design 47 H1, the runner's key; H-A-458 (1)): the +// key without its last part. A key with no source part is its own branch. +func pipelineBranch(key string) string { + if i := strings.LastIndexByte(key, '.'); i >= 0 { + return key[:i] + } + return key +} + func runIsNewer(want, applied string) bool { if want == "" || applied == "" { return true diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index d1c96b92..a8327a46 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -394,12 +394,13 @@ func testAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) { if got := len(b.appliedList()) - before; got != 0 { t.Errorf("a want of run 10 after a have of run 20: applied %d times, want none", got) } - // H-A-429 (1), H-A-458 (1): a want's run is compared with the have's only within one pipeline: a lower run of another - // pipeline replaces what stands, and the have keeps that pipeline beside its run; a lower run of the same is refused. + // H-A-429 (1), H-A-458 (1): a want's run is compared with the have's only within one branch, a pipeline's key being + // .: a lower run of another branch replaces what stands, and the have keeps its pipeline beside its + // run; a lower run of an older pipeline of the same branch is refused. for _, row := range []struct { fp, run, pipeline string applied int - }{{"7", "10", "feat.mesh-host", 1}, {"8", "9", "feat.mesh-host", 0}} { + }{{"7", "10", "feat.10", 1}, {"8", "9", "feat.9", 0}, {"b", "5", "main.5", 1}} { before := len(b.appliedList()) fpr := fpOf(row.fp) ckr, crawr, digr := composition(t, "web", fpr, false, archive("a", d2)) @@ -412,8 +413,8 @@ func testAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) { t.Errorf("a want of run %s of pipeline %s: applied %d times, want %d", row.run, row.pipeline, got, row.applied) } } - if h := b.haves.last("web"); h.Run != "10" || h.Pipeline != "feat.mesh-host" { - t.Errorf("the have names run %q of pipeline %q, want run 10 of feat.mesh-host", h.Run, h.Pipeline) + if h := b.haves.last("web"); h.Run != "5" || h.Pipeline != "main.5" { + t.Errorf("the have names run %q of pipeline %q, want run 5 of main.5", h.Run, h.Pipeline) } b.mu.Lock() said := strings.Join(b.said, "\n") diff --git a/internal/link/have_test.go b/internal/link/have_test.go index d1fdc7c0..4ed84058 100644 --- a/internal/link/have_test.go +++ b/internal/link/have_test.go @@ -772,10 +772,10 @@ func testAnAppliedModulesHaveNamesTheFingerprintAndTheDigestAndFollowsItsHealth( fp := "src2:" + strings.Repeat("a", 64) dig := "sha256:" + strings.Repeat("b", 64) // H-A-458 (1): the run it was applied from is kept with the pipeline of its want. - q.NoteModule(context.Background(), ModuleFact{Module: "web", FP: fp, Composed: dig, Run: "12", Pipeline: "main.mesh-host"}) + q.NoteModule(context.Background(), ModuleFact{Module: "web", FP: fp, Composed: dig, Run: "12", Pipeline: "main.12"}) h := l.have(t, "n1.web") if h.Fp != fp || h.Composed != dig || h.Phase != nodeengineclient.PhaseRunning || h.Health != nodeengineclient.HealthUnknown || - h.Run != "12" || h.Pipeline != "main.mesh-host" { + h.Run != "12" || h.Pipeline != "main.12" { t.Fatalf("the have after the apply: %+v", h) } // Design 47, *What each step says*: running is said once, when the build is healthy and its manifest is known, on