R5: a mover left unfinished by another's failure is put in a pipeline again
A pipeline ending failed or cancelled keeps each mover whose own required steps passed or never ran in the runner's state unfinished and names it in pipeline-ended's unfinished; the branch's next kept catalog revision carries it, or starts a pipeline for it alone. runner_unfinished reads the state, runner_unfinished_drop drops one key, runner_unfinished_place asks the new seat verb place-unfinished (contracts regenerated), both hand acts. Builds: design 47 H2 §786, §820 (unfinished), H-A-398
This commit is contained in:
@@ -20,26 +20,27 @@ const Form = 2
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "2"
|
||||
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=75717fd670a7 LogEntry=b5c78894cc5b Member=8a103baec01f Mover=5659e54b6dd0 MoverEnded=4b35095f6829 Pipeline=2663792125bf PipelineEnded=523f8fc0fe41 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineStarted=a3d000f095db PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=5beff763f531 StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepOutputsByPipelineStepArtifactValue=a2f06147f4b6 StepResult=94c2bea6ddcd StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
|
||||
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=75717fd670a7 LogEntry=b5c78894cc5b Member=8a103baec01f Mover=5659e54b6dd0 MoverEnded=4b35095f6829 Pipeline=2663792125bf PipelineEnded=523f8fc0fe41 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineStarted=a3d000f095db PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=5beff763f531 StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepOutputsByPipelineStepArtifactValue=a2f06147f4b6 StepResult=94c2bea6ddcd StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
|
||||
)
|
||||
|
||||
const (
|
||||
VerbRun = "run"
|
||||
VerbStart = "start"
|
||||
VerbShow = "show"
|
||||
VerbList = "list"
|
||||
VerbStands = "stands"
|
||||
VerbWhyCarried = "why-carried"
|
||||
VerbKept = "kept"
|
||||
VerbReview = "review"
|
||||
VerbRerun = "rerun"
|
||||
VerbAccept = "accept"
|
||||
VerbCancel = "cancel"
|
||||
VerbEndAgain = "end-again"
|
||||
VerbPlace = "place"
|
||||
VerbAskAgain = "ask-again"
|
||||
VerbTestRuns = "test-runs"
|
||||
VerbTestRunsDrop = "test-runs-drop"
|
||||
VerbRun = "run"
|
||||
VerbStart = "start"
|
||||
VerbShow = "show"
|
||||
VerbList = "list"
|
||||
VerbStands = "stands"
|
||||
VerbWhyCarried = "why-carried"
|
||||
VerbKept = "kept"
|
||||
VerbReview = "review"
|
||||
VerbRerun = "rerun"
|
||||
VerbAccept = "accept"
|
||||
VerbCancel = "cancel"
|
||||
VerbEndAgain = "end-again"
|
||||
VerbPlace = "place"
|
||||
VerbPlaceUnfinished = "place-unfinished"
|
||||
VerbAskAgain = "ask-again"
|
||||
VerbTestRuns = "test-runs"
|
||||
VerbTestRunsDrop = "test-runs-drop"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -58,7 +59,7 @@ const (
|
||||
|
||||
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
|
||||
func Verbs() []string {
|
||||
return []string{VerbRun, VerbStart, VerbShow, VerbList, VerbStands, VerbWhyCarried, VerbKept, VerbReview, VerbRerun, VerbAccept, VerbCancel, VerbEndAgain, VerbPlace, VerbAskAgain, VerbTestRuns, VerbTestRunsDrop}
|
||||
return []string{VerbRun, VerbStart, VerbShow, VerbList, VerbStands, VerbWhyCarried, VerbKept, VerbReview, VerbRerun, VerbAccept, VerbCancel, VerbEndAgain, VerbPlace, VerbPlaceUnfinished, VerbAskAgain, VerbTestRuns, VerbTestRunsDrop}
|
||||
}
|
||||
|
||||
// Events is every event published on the seat's subject: a new copy each call.
|
||||
@@ -274,6 +275,44 @@ func DecodePipelinesByBranchRunRunValue(raw []byte) (PipelinesByBranchRunRunValu
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// PipelinesByBranchRevisionUnfinishedModuleKey is the key of one value of the state pipelines under the form "<branch>.<revision>.unfinished.<module>".
|
||||
func PipelinesByBranchRevisionUnfinishedModuleKey(branch, revision, module string) string {
|
||||
return branch + "." + revision + ".unfinished." + module
|
||||
}
|
||||
|
||||
// ParsePipelinesByBranchRevisionUnfinishedModuleKey reads the parts of a key of the form "<branch>.<revision>.unfinished.<module>", in the order of the form; the last result is false for a key of another form.
|
||||
func ParsePipelinesByBranchRevisionUnfinishedModuleKey(key string) (string, string, string, bool) {
|
||||
rest := key
|
||||
v0, after0, found0 := strings.Cut(rest, ".")
|
||||
if !found0 || v0 == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
rest = after0
|
||||
v2, after2, found2 := strings.Cut(rest, ".unfinished.")
|
||||
if !found2 || v2 == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
rest = after2
|
||||
if rest == "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
v4 := rest
|
||||
rest = ""
|
||||
if rest != "" {
|
||||
return "", "", "", false
|
||||
}
|
||||
return v0, v2, v4, true
|
||||
}
|
||||
|
||||
// DecodePipelinesByBranchRevisionUnfinishedModuleValue reads one value of the state pipelines under the form "<branch>.<revision>.unfinished.<module>" as another part wrote it: a field PipelinesByBranchRevisionUnfinishedModuleValue does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodePipelinesByBranchRevisionUnfinishedModuleValue(raw []byte) (PipelinesByBranchRevisionUnfinishedModuleValue, int, error) {
|
||||
var v PipelinesByBranchRevisionUnfinishedModuleValue
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// PipelinesByStepsPipelineMoverKey is the key of one value of the state pipelines under the form "steps.<pipeline>.<mover>".
|
||||
func PipelinesByStepsPipelineMoverKey(pipeline, mover string) string {
|
||||
return "steps." + pipeline + "." + mover
|
||||
@@ -1383,6 +1422,22 @@ type PlaceAnswer struct {
|
||||
Pipeline Pipeline `json:"pipeline"`
|
||||
}
|
||||
|
||||
// PlaceUnfinishedInput is what place-unfinished takes.
|
||||
type PlaceUnfinishedInput struct {
|
||||
// the unfinished entry's key, <branch>.<module>
|
||||
Key string `json:"key"`
|
||||
// why, written with the caller the runtime proves in the hand-act log
|
||||
Why string `json:"why"`
|
||||
}
|
||||
|
||||
// PlaceUnfinishedAnswer is what place-unfinished answers.
|
||||
type PlaceUnfinishedAnswer struct {
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
// the key of the pipeline the mover is put in
|
||||
Pipeline string `json:"pipeline"`
|
||||
}
|
||||
|
||||
// AskAgainInput is what ask-again takes.
|
||||
type AskAgainInput struct {
|
||||
// the mover's module, so a pipeline of several movers is never ambiguous; a call naming none on a pipeline of one mover is taken as that mover (design 47 H-A-101)
|
||||
@@ -1493,6 +1548,9 @@ type PipelinesByBranchSourcePublishedPackageVersionValue = Pipeline
|
||||
// PipelinesByBranchRunRunValue is one value of the state pipelines under the key <branch>.run.<run>.
|
||||
type PipelinesByBranchRunRunValue = Pipeline
|
||||
|
||||
// PipelinesByBranchRevisionUnfinishedModuleValue is one value of the state pipelines under the key <branch>.<revision>.unfinished.<module>.
|
||||
type PipelinesByBranchRevisionUnfinishedModuleValue = Pipeline
|
||||
|
||||
// PipelinesByStepsPipelineMoverValue is one value of the state pipelines under the key steps.<pipeline>.<mover>.
|
||||
type PipelinesByStepsPipelineMoverValue struct {
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
@@ -1643,6 +1701,15 @@ func DecodePlaceAnswer(raw []byte) (PlaceAnswer, int, error) {
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// DecodePlaceUnfinishedAnswer reads a PlaceUnfinishedAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodePlaceUnfinishedAnswer(raw []byte) (PlaceUnfinishedAnswer, int, error) {
|
||||
var v PlaceUnfinishedAnswer
|
||||
if err := json.Unmarshal(raw, &v); err != nil {
|
||||
return v, 0, err
|
||||
}
|
||||
return v, formRead(raw), nil
|
||||
}
|
||||
|
||||
// DecodeAskAgainAnswer reads a AskAgainAnswer as another part wrote it: a field this reader does not know is left unread, never refused; the form read is answered, 1 when absent (design 47 H2 §780).
|
||||
func DecodeAskAgainAnswer(raw []byte) (AskAgainAnswer, int, error) {
|
||||
var v AskAgainAnswer
|
||||
|
||||
@@ -578,6 +578,40 @@
|
||||
},
|
||||
"class": "act"
|
||||
},
|
||||
{
|
||||
"name": "place-unfinished",
|
||||
"description": "A mover kept in the state unfinished put in a pipeline of its own at once, keyed <branch>.<revision>.unfinished.<module>; written in the hand-act log (design 47 H2 §786, H-A-398).",
|
||||
"input": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string",
|
||||
"description": "the unfinished entry's key, <branch>.<module>"
|
||||
},
|
||||
"why": {
|
||||
"type": "string",
|
||||
"description": "why, written with the caller the runtime proves in the hand-act log"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"key",
|
||||
"why"
|
||||
]
|
||||
},
|
||||
"answer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"pipeline": {
|
||||
"type": "string",
|
||||
"description": "the key of the pipeline the mover is put in"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"pipeline"
|
||||
]
|
||||
},
|
||||
"class": "act"
|
||||
},
|
||||
{
|
||||
"name": "ask-again",
|
||||
"description": "A declined approval step asked again (ADR 0666 section 10). Written in the hand-act log.",
|
||||
@@ -858,6 +892,13 @@
|
||||
},
|
||||
"description": "a run on request's pipeline, one per run, its movers the named commits' modules; it delivers nothing (H-A-83)"
|
||||
},
|
||||
{
|
||||
"key": "<branch>.<revision>.unfinished.<module>",
|
||||
"value": {
|
||||
"$ref": "#/defs/Pipeline"
|
||||
},
|
||||
"description": "a pipeline of its own of one mover kept in the runner's state unfinished, put in it by place-unfinished; the revision the unfinished entry names (design 47 H2 §86, H-A-398)"
|
||||
},
|
||||
{
|
||||
"key": "steps.<pipeline>.<mover>",
|
||||
"value": {
|
||||
|
||||
@@ -18,6 +18,7 @@ export declare const verbs: {
|
||||
readonly cancel: "cancel";
|
||||
readonly endAgain: "end-again";
|
||||
readonly place: "place";
|
||||
readonly placeUnfinished: "place-unfinished";
|
||||
readonly askAgain: "ask-again";
|
||||
readonly testRuns: "test-runs";
|
||||
readonly testRunsDrop: "test-runs-drop";
|
||||
@@ -115,6 +116,12 @@ export declare function pipelinesByBranchRunRunKey(branch: string, run: string):
|
||||
/** The parts of a key of the form "<branch>.run.<run>", or undefined for a key of another form. */
|
||||
export declare function parsePipelinesByBranchRunRunKey(_key: string): { branch: string; run: string } | undefined;
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<revision>.unfinished.<module>". */
|
||||
export declare function pipelinesByBranchRevisionUnfinishedModuleKey(branch: string, revision: string, module: string): string;
|
||||
|
||||
/** The parts of a key of the form "<branch>.<revision>.unfinished.<module>", or undefined for a key of another form. */
|
||||
export declare function parsePipelinesByBranchRevisionUnfinishedModuleKey(_key: string): { branch: string; revision: string; module: string } | undefined;
|
||||
|
||||
/** The key of one value of the state pipelines under the form "steps.<pipeline>.<mover>". */
|
||||
export declare function pipelinesByStepsPipelineMoverKey(pipeline: string, mover: string): string;
|
||||
|
||||
@@ -863,6 +870,22 @@ export interface PlaceAnswer {
|
||||
"pipeline": Pipeline;
|
||||
}
|
||||
|
||||
/** is what place-unfinished takes. */
|
||||
export interface PlaceUnfinishedInput {
|
||||
/** the unfinished entry's key, <branch>.<module> */
|
||||
"key": string;
|
||||
/** why, written with the caller the runtime proves in the hand-act log */
|
||||
"why": string;
|
||||
}
|
||||
|
||||
/** is what place-unfinished answers. */
|
||||
export interface PlaceUnfinishedAnswer {
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
"form"?: number;
|
||||
/** the key of the pipeline the mover is put in */
|
||||
"pipeline": string;
|
||||
}
|
||||
|
||||
/** is what ask-again takes. */
|
||||
export interface AskAgainInput {
|
||||
/** the mover's module, so a pipeline of several movers is never ambiguous; a call naming none on a pipeline of one mover is taken as that mover (design 47 H-A-101) */
|
||||
@@ -966,6 +989,9 @@ export type PipelinesByBranchSourcePublishedPackageVersionValue = Pipeline;
|
||||
/** is one value of the state pipelines under the key <branch>.run.<run>. */
|
||||
export type PipelinesByBranchRunRunValue = Pipeline;
|
||||
|
||||
/** is one value of the state pipelines under the key <branch>.<revision>.unfinished.<module>. */
|
||||
export type PipelinesByBranchRevisionUnfinishedModuleValue = Pipeline;
|
||||
|
||||
/** is one value of the state pipelines under the key steps.<pipeline>.<mover>. */
|
||||
export interface PipelinesByStepsPipelineMoverValue {
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
|
||||
@@ -18,6 +18,7 @@ export const verbs = {
|
||||
cancel: "cancel",
|
||||
endAgain: "end-again",
|
||||
place: "place",
|
||||
placeUnfinished: "place-unfinished",
|
||||
askAgain: "ask-again",
|
||||
testRuns: "test-runs",
|
||||
testRunsDrop: "test-runs-drop",
|
||||
@@ -176,6 +177,29 @@ export function parsePipelinesByBranchRunRunKey(_key) {
|
||||
return { branch, run };
|
||||
}
|
||||
|
||||
/** The key of one value of the state pipelines under the form "<branch>.<revision>.unfinished.<module>". */
|
||||
export function pipelinesByBranchRevisionUnfinishedModuleKey(branch, revision, module) {
|
||||
return branch + "." + revision + ".unfinished." + module;
|
||||
}
|
||||
|
||||
/** The parts of a key of the form "<branch>.<revision>.unfinished.<module>", or undefined for a key of another form. */
|
||||
export function parsePipelinesByBranchRevisionUnfinishedModuleKey(_key) {
|
||||
let _rest = _key;
|
||||
const _at0 = _rest.indexOf(".");
|
||||
if (_at0 <= 0) return undefined;
|
||||
const branch = _rest.slice(0, _at0);
|
||||
_rest = _rest.slice(_at0 + 1);
|
||||
const _at2 = _rest.indexOf(".unfinished.");
|
||||
if (_at2 <= 0) return undefined;
|
||||
const revision = _rest.slice(0, _at2);
|
||||
_rest = _rest.slice(_at2 + 12);
|
||||
if (_rest === "") return undefined;
|
||||
const module = _rest;
|
||||
_rest = "";
|
||||
if (_rest !== "") return undefined;
|
||||
return { branch, revision, module };
|
||||
}
|
||||
|
||||
/** The key of one value of the state pipelines under the form "steps.<pipeline>.<mover>". */
|
||||
export function pipelinesByStepsPipelineMoverKey(pipeline, mover) {
|
||||
return "steps." + pipeline + "." + mover;
|
||||
|
||||
@@ -174,6 +174,7 @@ func main() {
|
||||
tools = append(tools, HealthTool(r.Pipelines, kept{stdio.State(pipeline.StateConsumers)}, time.Now,
|
||||
func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[mesh-delivery-pipeline-tools] "+f+"\n", a...) }))
|
||||
tools = append(tools, WaitingTool(kept{stdio.State(seat.StateQueue)}))
|
||||
tools = append(tools, UnfinishedTools(keptDelete{kept{stdio.State(pipeline.StateUnfinished)}}, meshhandactsclient.Recorder{Ask: stdio.Ask})...)
|
||||
if err := stdio.Serve("", tools); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[mesh-delivery-pipeline-tools] %v\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -43,7 +43,13 @@ func TestTools(t *testing.T) {
|
||||
for _, tl := range UnloggedTools(stdio.State("pipelines"), stdio.Log("step-log"), nil, nil) {
|
||||
names = append(names, tl.Name)
|
||||
}
|
||||
want := "mesh-pipeline-runner.show mesh-pipeline-runner.list mesh-pipeline-runner.stands mesh-pipeline-runner.why-carried mesh-pipeline-runner.kept runner_first_views runner_first_view_again runner_cancel runner_rerun runner_start runner_run runner_accept runner_place runner_end_again runner_ask_again runner_health runner_waiting runner_unlogged runner_unlogged_append"
|
||||
// design 47 H2 §786: the unfinished movers are read and dropped by hand.
|
||||
unfinished := unfinishedOfMem{"main.app": `{"fingerprint":"src2:aa","revision":4,"pipeline":"main.4","outcome":"failed"}`}
|
||||
tools := UnfinishedTools(unfinished, nil)
|
||||
for _, tl := range tools {
|
||||
names = append(names, tl.Name)
|
||||
}
|
||||
want := "mesh-pipeline-runner.show mesh-pipeline-runner.list mesh-pipeline-runner.stands mesh-pipeline-runner.why-carried mesh-pipeline-runner.kept runner_first_views runner_first_view_again runner_cancel runner_rerun runner_start runner_run runner_accept runner_place runner_end_again runner_unfinished_place runner_ask_again runner_health runner_waiting runner_unlogged runner_unlogged_append runner_unfinished runner_unfinished_drop"
|
||||
if got := strings.Join(names, " "); got != want {
|
||||
t.Errorf("tools %q, want %q", got, want)
|
||||
}
|
||||
@@ -70,8 +76,51 @@ func TestTools(t *testing.T) {
|
||||
if len(journal) != 1 || !strings.Contains(journal[0], "main.137") {
|
||||
t.Errorf("the journal said %q, want main.137 said once", journal)
|
||||
}
|
||||
// design 47 H2 §786: runner_unfinished reads each key and its entry; runner_unfinished_drop names why, drops nothing when
|
||||
// its hand act is not recorded, and drops the key once it is.
|
||||
if got, err := tools[0].Run(nil); err != nil || fmt.Sprint(got) != "[{main.app {src2:aa 4 main.4 failed}}]" {
|
||||
t.Errorf("runner_unfinished = %v (%v)", got, err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
acts views.HandActs
|
||||
args map[string]any
|
||||
refusal string
|
||||
}{
|
||||
{"no why", recordingActs{}, map[string]any{"key": "main.app"}, "why"},
|
||||
{"no such key", recordingActs{}, map[string]any{"key": "main.lib", "why": "x"}, "holds no main.lib"},
|
||||
{"not recorded", refusingActs{}, map[string]any{"key": "main.app", "why": "x"}, "not recorded"},
|
||||
{"dropped", recordingActs{}, map[string]any{"key": "main.app", "why": "the change is reverted"}, ""},
|
||||
} {
|
||||
_, err := UnfinishedTools(unfinished, c.acts)[1].Run(c.args)
|
||||
_, held := unfinished["main.app"]
|
||||
if c.refusal != "" && (err == nil || !strings.Contains(err.Error(), c.refusal) || !held) {
|
||||
t.Errorf("runner_unfinished_drop %s: %v, the key held %t", c.name, err, held)
|
||||
}
|
||||
if c.refusal == "" && (err != nil || held) {
|
||||
t.Errorf("runner_unfinished_drop %s: %v, the key held %t", c.name, err, held)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unfinishedOfMem is a state unfinished in memory.
|
||||
type unfinishedOfMem map[string]string
|
||||
|
||||
func (u unfinishedOfMem) Keys() ([]string, error) { return queueOf(u).Keys() }
|
||||
|
||||
func (u unfinishedOfMem) Value(k string) (json.RawMessage, error) {
|
||||
if v, ok := u[k]; ok {
|
||||
return json.RawMessage(v), nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (u unfinishedOfMem) Delete(k string) error { delete(u, k); return nil }
|
||||
|
||||
type recordingActs struct{}
|
||||
|
||||
func (recordingActs) RecordHandAct(views.HandAct) error { return nil }
|
||||
|
||||
// queueOf is a state queue in memory, its keys in no order.
|
||||
type queueOf map[string]string
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-delivery-pipeline/internal/pipeline"
|
||||
)
|
||||
|
||||
// UnfinishedState is the runner's state unfinished as the tools read and drop it.
|
||||
type UnfinishedState interface {
|
||||
pipeline.Kept
|
||||
Delete(key string) error
|
||||
}
|
||||
|
||||
// keptDelete is a state of the runner read and deleted through the runtime.
|
||||
type keptDelete struct{ kept }
|
||||
|
||||
func (k keptDelete) Delete(key string) error { return k.s.Delete(key) }
|
||||
|
||||
// Unfinished is one mover kept in the state unfinished, as runner_unfinished lists it.
|
||||
type Unfinished struct {
|
||||
Key string `json:"key"`
|
||||
pipeline.UnfinishedEntry
|
||||
}
|
||||
|
||||
// UnfinishedTools are runner_unfinished and runner_unfinished_drop over the runner's state unfinished (design 47 H2 §786):
|
||||
// every mover a pipeline's end left unfinished, and one key dropped by hand, with why, written in the hand-act log first.
|
||||
// runner_unfinished_place, which puts one in a pipeline of its own, asks the seat verb place-unfinished (VerbTools).
|
||||
func UnfinishedTools(st UnfinishedState, acts views.HandActs) []stdio.Tool {
|
||||
str := map[string]any{"type": "string"}
|
||||
return []stdio.Tool{
|
||||
{Name: Prefix + "_unfinished",
|
||||
Description: "The movers a pipeline's end left unfinished (design 47 H2 §786): each key <branch>.<module> with its fingerprint, the catalog revision and the pipeline it was left in, and that pipeline's outcome. Each is put in the pipeline of its branch's next catalog revision; runner_unfinished_place puts one in a pipeline of its own now, runner_unfinished_drop drops one.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) { return unfinishedOf(st) }},
|
||||
{Name: Prefix + "_unfinished_drop",
|
||||
Description: "Drop one mover from the state unfinished by hand (design 47 H2 §786): its key <branch>.<module> and why, written in the hand-act log first; the mover is then put in no pipeline again until its fingerprint moves.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{"key": str, "why": str}, "required": []string{"key", "why"}},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
in, err := as[struct {
|
||||
Key string `json:"key"`
|
||||
Why string `json:"why"`
|
||||
}](args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dropUnfinished(st, acts, in.Key, in.Why)
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
func unfinishedOf(st pipeline.Kept) ([]Unfinished, error) {
|
||||
keys, err := st.Keys()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the state unfinished is not read: %w", err)
|
||||
}
|
||||
slices.Sort(keys)
|
||||
out := []Unfinished{}
|
||||
for _, k := range keys {
|
||||
raw, err := st.Value(k)
|
||||
if err != nil || raw == nil {
|
||||
continue
|
||||
}
|
||||
u := Unfinished{Key: k}
|
||||
if err := json.Unmarshal(raw, &u.UnfinishedEntry); err != nil {
|
||||
return nil, fmt.Errorf("the unfinished entry %s is not read: %w", k, err)
|
||||
}
|
||||
out = append(out, u)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func dropUnfinished(st UnfinishedState, acts views.HandActs, key, why string) (any, error) {
|
||||
if strings.TrimSpace(key) == "" {
|
||||
return nil, errors.New("runner_unfinished_drop names the unfinished entry's key")
|
||||
}
|
||||
if msg := whyOf(why); msg != "" {
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
raw, err := st.Value(key)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the unfinished entry %s is not read: %w", key, err)
|
||||
}
|
||||
if raw == nil {
|
||||
return nil, fmt.Errorf("the state unfinished holds no %s: nothing was dropped", key)
|
||||
}
|
||||
if acts == nil {
|
||||
return nil, errors.New("no way to record a hand act is given: nothing was dropped")
|
||||
}
|
||||
if err := acts.RecordHandAct(views.HandAct{What: "dropped the unfinished mover " + key + " by hand", Why: strings.TrimSpace(why),
|
||||
Cause: "unfinished-drop", Verb: Prefix + "_unfinished_drop"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act is not recorded, so nothing was dropped: %w", err)
|
||||
}
|
||||
if err := st.Delete(key); err != nil {
|
||||
return nil, fmt.Errorf("the unfinished entry %s is not deleted: %w", key, err)
|
||||
}
|
||||
return map[string]any{"dropped": key}, nil
|
||||
}
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// VerbTools are runner_start, runner_run, runner_accept, runner_place and runner_ask_again: the runner's seat verbs start,
|
||||
// run, accept, place (§748) and ask-again, reachable as tools (design 47 G §83, §482), as runner_rerun reaches rerun. Each asks its verb over the bus with
|
||||
// VerbTools are runner_start, runner_run, runner_accept, runner_place, runner_unfinished_place and runner_ask_again: the
|
||||
// runner's seat verbs start, run, accept, place (§748), place-unfinished (H2 §786) and ask-again, reachable as tools (design 47 G §83, §482), as runner_rerun reaches rerun. Each asks its verb over the bus with
|
||||
// the arguments it was given and answers the verb's answer; the verb records the hand act and refuses what it refuses.
|
||||
func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.Tool {
|
||||
str := map[string]any{"type": "string"}
|
||||
@@ -63,6 +63,15 @@ func VerbTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.
|
||||
}
|
||||
return whyOf(in.Why)
|
||||
}),
|
||||
verbTool[seat.PlaceUnfinishedInput](ask, "unfinished_place", seat.VerbPlaceUnfinished,
|
||||
"Put a mover kept in the state unfinished in a pipeline of its own at once, by the seat verb place-unfinished (design 47 H2 §786): the entry's key <branch>.<module> (runner_unfinished lists them) and why; written in the hand-act log. The answer names the pipeline, keyed <branch>.<revision>.unfinished.<module>.",
|
||||
obj([]string{"key", "why"}, map[string]any{"key": str, "why": str}),
|
||||
func(in seat.PlaceUnfinishedInput) string {
|
||||
if in.Key == "" {
|
||||
return "place-unfinished names the unfinished entry's key"
|
||||
}
|
||||
return whyOf(in.Why)
|
||||
}),
|
||||
verbTool[seat.AskAgainInput](ask, "ask_again", seat.VerbAskAgain,
|
||||
"Ask a declined approval step of a pipeline once more by the seat verb ask-again: the pipeline's key, the mover's module (needed when the pipeline moves several) and why.",
|
||||
obj([]string{"pipeline", "why"}, map[string]any{"pipeline": str, "module": str, "why": str}),
|
||||
|
||||
@@ -36,6 +36,10 @@ func TestVerbTools(t *testing.T) {
|
||||
{"end-again", "runner_end_again", "seat:mesh-pipeline-runner.end-again", "", map[string]any{"pipeline": "main.20", "why": "left running"},
|
||||
seat.EndAgainInput{Pipeline: "main.20", Why: "left running"}},
|
||||
{"end-again no why", "runner_end_again", "", "names why", map[string]any{"pipeline": "main.20"}, nil},
|
||||
// design 47 H2 §786, H-A-398: runner_unfinished_place asks the verb place-unfinished with the entry's key and why.
|
||||
{"unfinished place", "runner_unfinished_place", "seat:mesh-pipeline-runner.place-unfinished", "", map[string]any{"key": "main.app", "why": "now"},
|
||||
seat.PlaceUnfinishedInput{Key: "main.app", Why: "now"}},
|
||||
{"unfinished place no key", "runner_unfinished_place", "", "entry's key", map[string]any{"why": "now"}, nil},
|
||||
{"ask-again no why", "runner_ask_again", "", "names why", map[string]any{"pipeline": "p"}, nil},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
|
||||
@@ -73,6 +73,12 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// The movers a pipeline's end left unfinished, put in a pipeline again at their branch's next revision (design 47 H2 §786).
|
||||
unfinishedKV, err := process.EssentialBucket(ctx, js, "pipeline runner", ownBucket(cred.Module, pipeline.StateUnfinished), "put a mover left unfinished in a pipeline again")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
unfinished := &pipeline.Unfinished{Store: kvUnfinished{ctx, unfinishedKV}, Logf: logger.Printf}
|
||||
// The toolchain of each language as heard agreed, for the steps' asks (§416, A-104).
|
||||
toolchains, err := process.EssentialBucket(ctx, js, "pipeline runner", ownBucket(cred.Module, "toolchains"), "name a step's toolchain")
|
||||
if err != nil {
|
||||
@@ -166,7 +172,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, publish: js.PublishMsg, cred: cred, bound: askBound, logf: logger.Printf}, Name: cred.Module,
|
||||
Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains),
|
||||
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing,
|
||||
Findings: rv.Findings, Observer: cred.Module} // a mover waiting on its registration is registration-missing (H-A-262)
|
||||
Findings: rv.Findings, Observer: cred.Module, // a mover waiting on its registration is registration-missing (H-A-262)
|
||||
Unfinished: unfinished}
|
||||
hearer.Unfinished = unfinished
|
||||
hearer.AskSteps = starter.AskSteps
|
||||
hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4))
|
||||
logger.Printf("asks: an ask's bound %s, counted from its put until its holder's ask-taken, then from the take and each step-progress; past it the step ends could not run and its ask is dropped", askBound)
|
||||
|
||||
+11
-1
@@ -54,7 +54,7 @@ func TestTheQueueRunsPipelinesInTurn(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
const module = "mesh-delivery-pipeline"
|
||||
for _, state := range []string{"pipelines", "kept", "toolchains", "findings", "first-views", "consumers", "aged", "recoveries", seat.StateQueue} {
|
||||
for _, state := range []string{"pipelines", "kept", "toolchains", "findings", "first-views", "consumers", "aged", "recoveries", seat.StateQueue, pipeline.StateUnfinished} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -304,6 +304,16 @@ func TestTheQueueRunsPipelinesInTurn(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outcome("main.4", seat.PipelineOutcomeCancelled)
|
||||
// design 47 H2 §786: the cancel leaves main.4's lib unfinished; dropped here, as runner_unfinished_drop does, so the
|
||||
// next take-ins move only what they name.
|
||||
unfinished, err := js.KeyValue(ctx, module+"_"+pipeline.StateUnfinished)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waitFor(t, ctx, logs, func() bool { _, err := unfinished.Get(ctx, "main.lib"); return err == nil })
|
||||
if err := unfinished.Delete(ctx, "main.lib"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
outcome("main.6", seat.PipelineOutcomeRunning)
|
||||
waitFor(t, ctx, logs, func() bool { _, ok := finding(pipeline.QueueFullKind); return !ok })
|
||||
if p := get("main.7"); p.Outcome != seat.PipelineOutcomeWaiting {
|
||||
|
||||
+127
-109
@@ -47,124 +47,21 @@ func (s *syncBuffer) String() string { s.mu.Lock(); defer s.mu.Unlock(); return
|
||||
// of the build, and ends the placed review step when a session calls `review`, answered by the process with the caller the
|
||||
// bus proved; the pipeline then ends passed.
|
||||
func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *testing.T) {
|
||||
url := testbus.URL(t)
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
js, err := jetstream.New(nc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
const module = "mesh-delivery-pipeline"
|
||||
for _, state := range []string{"pipelines", "kept", "toolchains", "findings", "first-views", "consumers", "aged", "recoveries", "queue"} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// bounds and test-runs keep keys with their own time to live (§725), as the bus makes them from the manifest's key-ttl.
|
||||
for _, state := range []string{"bounds", TestRunsState} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1, LimitMarkerTTL: time.Minute}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Kept pipelines in the old form, their steps inline in the record, as the runner's start finds them on a live bus
|
||||
// (main.41-46, one of 437 steps): each start path reads them at once from its own goroutine (H-A-187, H §774).
|
||||
keptPipelines(t, ctx, js, module)
|
||||
// The step log, the runner's old logs section (§470): the stream the bus makes for it.
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: buscompose.LogStreamName(module, seat.StateStepLog), Subjects: []string{buscompose.LogSubject(module, seat.StateStepLog) + ".>"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
findingsStream(t, ctx, js, module)
|
||||
events, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := events.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{Durable: "n1_" + module, AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
asks, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "ASKS", Subjects: []string{"mesh.seat.*.accept.>"}, Retention: jetstream.WorkQueuePolicy})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The seats the runner calls, answered as their holders do.
|
||||
reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Review: "optional", Validate: "bypass", Composition: "bypass", Approval: "bypass"}}}
|
||||
answer := func(subject string, body any) {
|
||||
if _, err := nc.Subscribe(subject, func(m *nats.Msg) {
|
||||
raw, _ := json.Marshal(map[string]any{"result": body})
|
||||
_ = m.Respond(raw)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
answer("mesh.seat.mesh-catalog.call.registrations.*", catalog.RegistrationsAnswer{Registrations: []catalog.Registration{reg}})
|
||||
// The branch main has no revision yet at the runner's start (none-yet), then revision 1 holding app (A-336).
|
||||
var revised atomic.Bool
|
||||
if _, err := nc.Subscribe("mesh.seat.mesh-catalog.call.revision.*", func(m *nats.Msg) {
|
||||
var a catalog.RevisionAnswer
|
||||
w := startWhole(t, ctx, []catalog.Registration{reg}, func([]byte) catalog.RevisionAnswer {
|
||||
if revised.Load() {
|
||||
a = catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 1, Kind: "trunk", Branch: "main", Source: 3},
|
||||
return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 1, Kind: "trunk", Branch: "main", Source: 3},
|
||||
Entries: []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:aa"}}}
|
||||
} else {
|
||||
a.NoneYet = true
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"result": a})
|
||||
_ = m.Respond(raw)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
answer("mesh.seat.mesh-hand-acts.call.hand-act.*", map[string]any{})
|
||||
// The seat list (A-186): the seat mesh-catalog's seat-definitions names the runner's seat, whose definition its write
|
||||
// verbs' callers are checked against, as the contracts' file holds it.
|
||||
def, err := os.ReadFile("../../../mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := nc.Subscribe("mesh.seat.mesh-catalog.call."+seatlist.Verb+".*", func(m *nats.Msg) {
|
||||
var in struct {
|
||||
Seat string `json:"seat"`
|
||||
}
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
entry := seatlist.Entry{Seat: seat.Seat, Source: seatlist.SourceTrunk, Digest: "sha256:runner"}
|
||||
var result any = seatlist.Listing{Revision: 1, Seats: []seatlist.Entry{entry}}
|
||||
if in.Seat != "" {
|
||||
entry.Definition = def
|
||||
result = seatlist.Answer{Seat: in.Seat, Found: in.Seat == seat.Seat, Entry: &entry, Revision: 1}
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"result": result})
|
||||
_ = m.Respond(raw)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return catalog.RevisionAnswer{NoneYet: true}
|
||||
})
|
||||
const module = "mesh-delivery-pipeline"
|
||||
nc, js, asks, pipelines, logs := w.nc, w.js, w.asks, w.pipelines, w.logs
|
||||
|
||||
dir := t.TempDir()
|
||||
broker := filepath.Join(dir, "broker")
|
||||
raw, _ := json.Marshal(process.Account{URL: url, Node: "n1", Module: module, User: "runner", Password: "x"})
|
||||
if err := os.WriteFile(broker, raw, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logs := &syncBuffer{}
|
||||
runCtx, stop := context.WithCancel(ctx)
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- run(runCtx, func(k string) string {
|
||||
if k == process.BrokerFileEnv {
|
||||
return broker
|
||||
}
|
||||
return ""
|
||||
}, logs)
|
||||
}()
|
||||
defer func() { stop(); <-done }()
|
||||
|
||||
pipelines, err := js.KeyValue(ctx, module+"_pipelines")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A take-in.taken names one entry of the source revision; the runner places the pipeline of the registered module.
|
||||
taken, _ := json.Marshal(catalog.TakeInTaken{Branch: "main", Source: 3, Call: "0123456789abcdef",
|
||||
Entries: []catalog.TakeInEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}})
|
||||
@@ -275,6 +172,127 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes
|
||||
}
|
||||
}
|
||||
|
||||
// whole is the runner started whole as its process is, against this test's bus (design 47 G §22, §54): its states, streams
|
||||
// and seat list made as the bus makes them from its manifest, the catalog's registrations and revisions answered by regs and
|
||||
// revision, its journal in logs.
|
||||
type whole struct {
|
||||
nc *nats.Conn
|
||||
js jetstream.JetStream
|
||||
asks jetstream.Stream
|
||||
pipelines jetstream.KeyValue
|
||||
logs *syncBuffer
|
||||
}
|
||||
|
||||
func startWhole(t *testing.T, ctx context.Context, regs []catalog.Registration, revision func(in []byte) catalog.RevisionAnswer) whole {
|
||||
t.Helper()
|
||||
url := testbus.URL(t)
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(nc.Close)
|
||||
js, err := jetstream.New(nc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
const module = "mesh-delivery-pipeline"
|
||||
for _, state := range []string{"pipelines", "kept", "toolchains", "findings", "first-views", "consumers", "aged", "recoveries", "queue", pipeline.StateUnfinished} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// bounds and test-runs keep keys with their own time to live (§725), as the bus makes them from the manifest's key-ttl.
|
||||
for _, state := range []string{"bounds", TestRunsState} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1, LimitMarkerTTL: time.Minute}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Kept pipelines in the old form, their steps inline in the record, as the runner's start finds them on a live bus
|
||||
// (main.41-46, one of 437 steps): each start path reads them at once from its own goroutine (H-A-187, H §774).
|
||||
keptPipelines(t, ctx, js, module)
|
||||
// The step log, the runner's old logs section (§470): the stream the bus makes for it.
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: buscompose.LogStreamName(module, seat.StateStepLog), Subjects: []string{buscompose.LogSubject(module, seat.StateStepLog) + ".>"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
findingsStream(t, ctx, js, module)
|
||||
events, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := events.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{Durable: "n1_" + module, AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
asks, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "ASKS", Subjects: []string{"mesh.seat.*.accept.>"}, Retention: jetstream.WorkQueuePolicy})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// The seats the runner calls, answered as their holders do.
|
||||
answer := func(subject string, body any) {
|
||||
if _, err := nc.Subscribe(subject, func(m *nats.Msg) {
|
||||
raw, _ := json.Marshal(map[string]any{"result": body})
|
||||
_ = m.Respond(raw)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
answer("mesh.seat.mesh-catalog.call.registrations.*", catalog.RegistrationsAnswer{Registrations: regs})
|
||||
if _, err := nc.Subscribe("mesh.seat.mesh-catalog.call.revision.*", func(m *nats.Msg) {
|
||||
raw, _ := json.Marshal(map[string]any{"result": revision(m.Data)})
|
||||
_ = m.Respond(raw)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
answer("mesh.seat.mesh-hand-acts.call.hand-act.*", map[string]any{})
|
||||
// The seat list (A-186): the seat mesh-catalog's seat-definitions names the runner's seat, whose definition its write
|
||||
// verbs' callers are checked against, as the contracts' file holds it.
|
||||
def, err := os.ReadFile("../../../mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := nc.Subscribe("mesh.seat.mesh-catalog.call."+seatlist.Verb+".*", func(m *nats.Msg) {
|
||||
var in struct {
|
||||
Seat string `json:"seat"`
|
||||
}
|
||||
_ = json.Unmarshal(m.Data, &in)
|
||||
entry := seatlist.Entry{Seat: seat.Seat, Source: seatlist.SourceTrunk, Digest: "sha256:runner"}
|
||||
var result any = seatlist.Listing{Revision: 1, Seats: []seatlist.Entry{entry}}
|
||||
if in.Seat != "" {
|
||||
entry.Definition = def
|
||||
result = seatlist.Answer{Seat: in.Seat, Found: in.Seat == seat.Seat, Entry: &entry, Revision: 1}
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"result": result})
|
||||
_ = m.Respond(raw)
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
broker := filepath.Join(dir, "broker")
|
||||
raw, _ := json.Marshal(process.Account{URL: url, Node: "n1", Module: module, User: "runner", Password: "x"})
|
||||
if err := os.WriteFile(broker, raw, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logs := &syncBuffer{}
|
||||
runCtx, stop := context.WithCancel(ctx)
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- run(runCtx, func(k string) string {
|
||||
if k == process.BrokerFileEnv {
|
||||
return broker
|
||||
}
|
||||
return ""
|
||||
}, logs)
|
||||
}()
|
||||
t.Cleanup(func() { stop(); <-done })
|
||||
pipelines, err := js.KeyValue(ctx, module+"_pipelines")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return whole{nc: nc, js: js, asks: asks, pipelines: pipelines, logs: logs}
|
||||
}
|
||||
|
||||
// kvKept reads a bucket as the tools bundle's states do.
|
||||
type kvKept struct {
|
||||
ctx context.Context
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
const module = "mesh-delivery-pipeline"
|
||||
for _, state := range []string{"pipelines", "kept", "toolchains", "findings", "first-views", "consumers", "aged", "recoveries", "queue"} {
|
||||
for _, state := range []string{"pipelines", "kept", "toolchains", "findings", "first-views", "consumers", "aged", "recoveries", "queue", pipeline.StateUnfinished} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
)
|
||||
|
||||
// kvUnfinished is the runner's state unfinished on the bus (design 47 H2 §786), as pipeline.UnfinishedStore reads it: a key
|
||||
// it does not hold is nil.
|
||||
type kvUnfinished struct {
|
||||
ctx context.Context
|
||||
kv jetstream.KeyValue
|
||||
}
|
||||
|
||||
func (u kvUnfinished) Get(key string) ([]byte, error) {
|
||||
e, err := u.kv.Get(u.ctx, key)
|
||||
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.Value(), nil
|
||||
}
|
||||
|
||||
func (u kvUnfinished) Put(key string, value []byte) error {
|
||||
_, err := u.kv.Put(u.ctx, key, value)
|
||||
return err
|
||||
}
|
||||
|
||||
func (u kvUnfinished) Delete(key string) error { return u.kv.Delete(u.ctx, key) }
|
||||
|
||||
// Keys are the keys matching filter, `*` one key part.
|
||||
func (u kvUnfinished) Keys(filter string) ([]string, error) {
|
||||
lister, err := u.kv.ListKeysFiltered(u.ctx, filter)
|
||||
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []string
|
||||
for k := range lister.Keys() {
|
||||
out = append(out, k)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
//go:build integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
|
||||
"mesh-delivery-pipeline/internal/pipeline"
|
||||
)
|
||||
|
||||
// design 47 H2 §786, whole: of a pipeline of two movers one fails its unit step; pipeline-ended names the other in
|
||||
// unfinished and the runner keeps it in its state unfinished; the next take-in's pipeline carries it, its composition is
|
||||
// asked and passes (it is wanted), and its key goes once that pipeline ends passed.
|
||||
func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
steps := catalog.StepStatuses{Lint: "bypass", Unit: "required", Integration: "bypass", Validate: "required", Composition: "required",
|
||||
Review: "bypass", Approval: "bypass"}
|
||||
regs := []catalog.Registration{{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: steps}},
|
||||
{Module: "lib", Branches: []string{"main"}, Origin: "o/lib", Policy: catalog.Policy{Steps: steps}}}
|
||||
var newest atomic.Int64
|
||||
newest.Store(1)
|
||||
w := startWhole(t, ctx, regs, func(in []byte) catalog.RevisionAnswer {
|
||||
var q catalog.RevisionInput
|
||||
_ = json.Unmarshal(in, &q)
|
||||
n := q.Revision
|
||||
if n == 0 {
|
||||
n = newest.Load()
|
||||
}
|
||||
lib := "l1"
|
||||
if n == 2 {
|
||||
lib = "l2"
|
||||
}
|
||||
return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: n, Kind: "trunk", Branch: "main", Source: n + 2},
|
||||
Entries: []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:aa"},
|
||||
{Module: "lib", Commit: lib, Fp: "src2:" + lib, Artifacts: []catalog.Artifact{{Ref: "lib:lib", Language: "go", Kind: "program"}}},
|
||||
{Module: "mesh-build-go", Commit: "c0", Fp: "src2:go", Acts: []catalog.ActingRule{{Step: "build", On: "go", Seat: nodebuildgo.Seat}}}}}
|
||||
})
|
||||
ended := make(chan seat.PipelineEnded, 4)
|
||||
if _, err := w.nc.Subscribe("mesh.seat.mesh-pipeline-runner.event.pipeline-ended.>", func(m *nats.Msg) {
|
||||
var pe seat.PipelineEnded
|
||||
if json.Unmarshal(m.Data, &pe) == nil {
|
||||
ended <- pe
|
||||
}
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
unfinished, err := w.js.KeyValue(ctx, "mesh-delivery-pipeline_"+pipeline.StateUnfinished)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
takeIn := func(source, revision int64, entries ...catalog.TakeInEntry) {
|
||||
raw, _ := json.Marshal(catalog.TakeInTaken{Branch: "main", Source: source, Revision: revision, Call: "0123456789abcdef", Entries: entries})
|
||||
if _, err := w.js.Publish(ctx, "mesh.mod.mesh-delivery-indexer.event.take-in.taken", raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// answer ends every running step of key once, as its seat's holder says it: lib's unit fails when fail says so.
|
||||
answered := map[string]bool{}
|
||||
answer := func(key string, fail bool) func() bool {
|
||||
return func() bool {
|
||||
var p seat.Pipeline
|
||||
if !readPipeline(ctx, w.pipelines, key, &p) {
|
||||
return false
|
||||
}
|
||||
for _, s := range p.Steps {
|
||||
open := s.Outcome == seat.StepResultOutcomeRunning || s.Outcome == seat.StepResultOutcomeWaitingForABuildNode
|
||||
if !open || s.Ask == "" || answered[s.Ask+s.Module] {
|
||||
continue
|
||||
}
|
||||
answered[s.Ask+s.Module] = true
|
||||
m, _ := pipeline.MoverOf(p, s.Module)
|
||||
outcome := "passed"
|
||||
if fail && s.Module == "lib" && s.Step == seat.StepResultStepUnit {
|
||||
outcome = "failed"
|
||||
}
|
||||
body := map[string]any{"v": 1, "id": s.Ask, "pipeline": key, "step": s.Step, "module": s.Module, "commit": m.Commit,
|
||||
"fingerprint": m.Fingerprint, "node": "n1", "outcome": outcome, "artifact": s.Artifact}
|
||||
if s.Seat == builds.Seat {
|
||||
body["entries"] = []builds.BuildEntry{{Module: s.Module, Commit: m.Commit, Fingerprint: m.Fingerprint}}
|
||||
}
|
||||
raw, _ := json.Marshal(body)
|
||||
if _, err := w.js.Publish(ctx, "mesh.seat."+s.Seat+".event.step-ended.n1", raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return p.Outcome != seat.PipelineOutcomeRunning
|
||||
}
|
||||
}
|
||||
endOf := func() seat.PipelineEnded {
|
||||
select {
|
||||
case pe := <-ended:
|
||||
return pe
|
||||
case <-ctx.Done():
|
||||
t.Fatalf("no pipeline-ended was said; the runner said:\n%s", w.logs.String())
|
||||
}
|
||||
return seat.PipelineEnded{}
|
||||
}
|
||||
|
||||
takeIn(3, 1, catalog.TakeInEntry{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}, catalog.TakeInEntry{Module: "lib", Commit: "l1", Fingerprint: "src2:l1"})
|
||||
waitFor(t, ctx, w.logs, answer("main.1", true))
|
||||
if pe := endOf(); pe.Pipeline != "main.1" || pe.Outcome != seat.PipelineEndedOutcomeFailed || !slices.Equal(pe.Unfinished, []string{"app"}) {
|
||||
t.Fatalf("pipeline-ended = %s %s unfinished %v, want main.1 failed leaving app unfinished\n%s", pe.Pipeline, pe.Outcome, pe.Unfinished, w.logs.String())
|
||||
}
|
||||
if e, err := unfinished.Get(ctx, "main.app"); err != nil || !json.Valid(e.Value()) {
|
||||
t.Fatalf("the state unfinished holds no main.app: %v", err)
|
||||
}
|
||||
|
||||
// The next take-in moves lib alone, at a new fingerprint: its pipeline carries app, whose composition is asked and passes.
|
||||
newest.Store(2)
|
||||
rev, _ := json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: 2, Kind: "trunk", Branch: "main", Source: 4, CallKind: catalog.CatalogRevisionEventCallKindTakeIn})
|
||||
if _, err := w.js.Publish(ctx, catalog.SubjectCatalogRevision("main"), rev); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
takeIn(4, 2, catalog.TakeInEntry{Module: "lib", Commit: "l2", Fingerprint: "src2:l2"})
|
||||
waitFor(t, ctx, w.logs, answer("main.2", false))
|
||||
var p seat.Pipeline
|
||||
if !readPipeline(ctx, w.pipelines, "main.2", &p) || !pipeline.Moves(p, "app") {
|
||||
t.Fatalf("main.2 moves %+v, want app carried", p.Movers)
|
||||
}
|
||||
composed := false
|
||||
for _, s := range p.Steps {
|
||||
composed = composed || (s.Module == "app" && s.Step == seat.StepResultStepComposition && s.Outcome == seat.StepResultOutcomePassed && s.Ask != "")
|
||||
}
|
||||
if pe := endOf(); pe.Pipeline != "main.2" || pe.Outcome != seat.PipelineEndedOutcomePassed || !composed || len(pe.Unfinished) != 0 {
|
||||
t.Fatalf("main.2 ended %s, app composed %t, unfinished %v\n%s", pe.Outcome, composed, pe.Unfinished, w.logs.String())
|
||||
}
|
||||
if _, err := unfinished.Get(ctx, "main.app"); err == nil {
|
||||
t.Error("main.app is still unfinished after main.2 passed")
|
||||
}
|
||||
}
|
||||
@@ -38,19 +38,21 @@ func answerVerbs(conn *process.Conn, seats *seatlist.Part, v pipeline.Verbs) (fu
|
||||
return conn.AnswerSeat(seat.Seat, seatlist.Definition(seats.Reader, seat.Seat), writeHandlers(v))
|
||||
}
|
||||
|
||||
// writeHandlers are the seat's write verbs the process answers: run, review, rerun, accept, cancel, end-again, start, and ask-again; and
|
||||
// writeHandlers are the seat's write verbs the process answers: run, review, rerun, accept, cancel, end-again, place,
|
||||
// place-unfinished (design 47 H2 §786), start, and ask-again; and
|
||||
// the test runs' verbs test-runs and test-runs-drop (A-469g, A-470i).
|
||||
func writeHandlers(v pipeline.Verbs) map[string]process.SeatHandler {
|
||||
return map[string]process.SeatHandler{
|
||||
seat.VerbRun: verbOf(func(c string, in seat.RunInput) (any, error) { return v.Run(c, in) }),
|
||||
seat.VerbReview: verbOf(func(c string, in seat.ReviewInput) (any, error) { return v.Review(c, in) }),
|
||||
seat.VerbRerun: verbOf(func(c string, in seat.RerunInput) (any, error) { return v.Rerun(c, in) }),
|
||||
seat.VerbAccept: verbOf(func(c string, in seat.AcceptInput) (any, error) { return v.Accept(c, in) }),
|
||||
seat.VerbCancel: verbOf(func(c string, in seat.CancelInput) (any, error) { return v.Cancel(c, in) }),
|
||||
seat.VerbEndAgain: verbOf(func(c string, in seat.EndAgainInput) (any, error) { return v.EndAgain(c, in) }),
|
||||
seat.VerbPlace: verbOf(func(c string, in seat.PlaceInput) (any, error) { return v.Place(c, in) }),
|
||||
seat.VerbStart: verbOf(func(c string, in seat.StartInput) (any, error) { return v.Start(c, in) }),
|
||||
seat.VerbAskAgain: verbOf(func(c string, in seat.AskAgainInput) (any, error) { return v.AskAgain(c, in) }),
|
||||
seat.VerbRun: verbOf(func(c string, in seat.RunInput) (any, error) { return v.Run(c, in) }),
|
||||
seat.VerbReview: verbOf(func(c string, in seat.ReviewInput) (any, error) { return v.Review(c, in) }),
|
||||
seat.VerbRerun: verbOf(func(c string, in seat.RerunInput) (any, error) { return v.Rerun(c, in) }),
|
||||
seat.VerbAccept: verbOf(func(c string, in seat.AcceptInput) (any, error) { return v.Accept(c, in) }),
|
||||
seat.VerbCancel: verbOf(func(c string, in seat.CancelInput) (any, error) { return v.Cancel(c, in) }),
|
||||
seat.VerbEndAgain: verbOf(func(c string, in seat.EndAgainInput) (any, error) { return v.EndAgain(c, in) }),
|
||||
seat.VerbPlace: verbOf(func(c string, in seat.PlaceInput) (any, error) { return v.Place(c, in) }),
|
||||
seat.VerbPlaceUnfinished: verbOf(func(c string, in seat.PlaceUnfinishedInput) (any, error) { return v.PlaceUnfinished(c, in) }),
|
||||
seat.VerbStart: verbOf(func(c string, in seat.StartInput) (any, error) { return v.Start(c, in) }),
|
||||
seat.VerbAskAgain: verbOf(func(c string, in seat.AskAgainInput) (any, error) { return v.AskAgain(c, in) }),
|
||||
// §728, A-469g: a test run's drop is answered by the process, the only writer of pipelines and test-runs.
|
||||
seat.VerbTestRunsDrop: verbOf(func(c string, in seat.TestRunsDropInput) (any, error) { return v.TestRunsDrop(c, in) }),
|
||||
// A-470i: test-runs too, since the process holds test-runs-cap-mib, the cap its fill is said against.
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestEveryWriteVerbIsServed(t *testing.T) {
|
||||
got = append(got, v)
|
||||
}
|
||||
slices.Sort(got)
|
||||
want := []string{seat.VerbAccept, seat.VerbAskAgain, seat.VerbCancel, seat.VerbEndAgain, seat.VerbPlace, seat.VerbRerun, seat.VerbReview, seat.VerbStart, seat.VerbRun, seat.VerbTestRuns, seat.VerbTestRunsDrop}
|
||||
want := []string{seat.VerbAccept, seat.VerbAskAgain, seat.VerbCancel, seat.VerbEndAgain, seat.VerbPlace, seat.VerbPlaceUnfinished, seat.VerbRerun, seat.VerbReview, seat.VerbStart, seat.VerbRun, seat.VerbTestRuns, seat.VerbTestRunsDrop}
|
||||
slices.Sort(want)
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("the process answers %v, want %v", got, want)
|
||||
|
||||
@@ -2,6 +2,8 @@ package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -87,14 +89,23 @@ func TestOnePipelineEndedNamesEveryMoverWithItsTier(t *testing.T) {
|
||||
|
||||
// R6/AC1 and AC2 (design 47 H §746; ADR 0682 §8, H-A-3): a mover's required step that ends `nothing to run` counts as
|
||||
// passed, so the pipeline passes; one mover's required step failed fails the pipeline, naming that mover's step.
|
||||
//
|
||||
// design 47 H2 §786: the failed end names the other mover in pipeline-ended's unfinished and keeps it in the state
|
||||
// unfinished; the failing mover's own key goes (it waits for its fingerprint to move), and a passed end deletes its movers'
|
||||
// keys.
|
||||
func TestThePipelinePassesOnNothingToRunAndFailsOnOneMover(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, lib, want string
|
||||
unfinished []string
|
||||
keys string
|
||||
}{
|
||||
{"nothing to run", seat.StepResultOutcomeNothingToRun, seat.PipelineOutcomePassed},
|
||||
{"one mover failed", seat.StepResultOutcomeFailed, seat.PipelineOutcomeFailed},
|
||||
{"nothing to run", seat.StepResultOutcomeNothingToRun, seat.PipelineOutcomePassed, nil, ""},
|
||||
{"one mover failed", seat.StepResultOutcomeFailed, seat.PipelineOutcomeFailed, []string{"app"},
|
||||
`main.app={"fingerprint":"src2:aa","revision":0,"pipeline":"main.5","outcome":"failed"}`},
|
||||
} {
|
||||
h, store, _, _ := twoMovers(t)
|
||||
h, store, bodies, _ := twoMovers(t)
|
||||
u := memUnfinished{"main.lib": `{"fingerprint":"src2:bb"}`, "main.app": `{"fingerprint":"src2:aa"}`}
|
||||
h.Unfinished = &Unfinished{Store: u}
|
||||
for _, ev := range []StepEnded{ended("a1", "lint", "passed"), libEnded(c.lib)} {
|
||||
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ev); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -104,9 +115,44 @@ func TestThePipelinePassesOnNothingToRunAndFailsOnOneMover(t *testing.T) {
|
||||
if p.Outcome != c.want || (c.want == seat.PipelineOutcomeFailed && !strings.Contains(p.Why, "lib lib:lib unit failed")) {
|
||||
t.Errorf("%s: the pipeline ended %s (%s), want %s", c.name, p.Outcome, p.Why, c.want)
|
||||
}
|
||||
pe, _ := bodies["pipeline-ended.main.5"].(seat.PipelineEnded)
|
||||
if !slices.Equal(pe.Unfinished, c.unfinished) || u.String() != c.keys {
|
||||
t.Errorf("%s: pipeline-ended's unfinished %v and the state %q, want %v and %q", c.name, pe.Unfinished, u.String(), c.unfinished, c.keys)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// memUnfinished is a state unfinished in memory.
|
||||
type memUnfinished map[string]string
|
||||
|
||||
func (m memUnfinished) Get(k string) ([]byte, error) {
|
||||
if v, ok := m[k]; ok {
|
||||
return []byte(v), nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
func (m memUnfinished) Put(k string, v []byte) error { m[k] = string(v); return nil }
|
||||
func (m memUnfinished) Delete(k string) error { delete(m, k); return nil }
|
||||
func (m memUnfinished) Keys(filter string) ([]string, error) {
|
||||
prefix := strings.TrimSuffix(filter, "*")
|
||||
var out []string
|
||||
for k := range m {
|
||||
if strings.HasPrefix(k, prefix) {
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// String is the state's keys and values in key order.
|
||||
func (m memUnfinished) String() string {
|
||||
var out []string
|
||||
for _, k := range slices.Sorted(maps.Keys(m)) {
|
||||
out = append(out, k+"="+m[k])
|
||||
}
|
||||
return strings.Join(out, " ")
|
||||
}
|
||||
|
||||
// R8 (design 47 H §746, H-A-52, H-A-62): a version-released writes its version into the mover of that module in the pipeline
|
||||
// of the source revision built, on the branch it was released for, so pipeline-ended names it; another branch's pipeline,
|
||||
// and a version heard again, write nothing.
|
||||
|
||||
@@ -29,7 +29,8 @@ func StepsKey(pipeline, mover string) string {
|
||||
func stepsPrefix(pipeline string) string { return StepsKey(pipeline, "") }
|
||||
|
||||
// IsStepsKey says whether a key of the state pipelines is a mover's steps rather than a pipeline's record: `steps.` and a
|
||||
// pipeline key of a take-in's (4 parts), a run's (5 parts, its third `run`) or a publish's (7 parts) and one mover.
|
||||
// pipeline key of a take-in's (4 parts), a run's (5 parts, its third `run`), an unfinished mover's own (6 parts, its fourth
|
||||
// `unfinished`, H-A-398) or a publish's (7 parts) and one mover.
|
||||
func IsStepsKey(key string) bool {
|
||||
parts := strings.Split(key, ".")
|
||||
if parts[0] != "steps" {
|
||||
@@ -40,6 +41,8 @@ func IsStepsKey(key string) bool {
|
||||
return true
|
||||
case 5:
|
||||
return parts[2] == runToken
|
||||
case 6:
|
||||
return parts[3] == unfinishedToken
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
// A pipeline is keyed by its revision (H-A-213 (4)), so the pipelines of a source are those naming it, of either key
|
||||
// form a source's pipelines were kept under.
|
||||
var pkeys []string
|
||||
for _, f := range []string{b + ".*", b + ".*.published.*.*"} {
|
||||
for _, f := range []string{b + ".*", b + ".*.published.*.*", b + ".*." + unfinishedToken + ".*"} {
|
||||
k, err := h.Store.Keys(f)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("the pipelines of source %d are not listed: %w", ev.Source, err)
|
||||
|
||||
@@ -67,9 +67,9 @@ func keyRevision(b Begin) int64 {
|
||||
return b.Source
|
||||
}
|
||||
|
||||
// keyForms are the filters of every key form of the state pipelines: a revision's, a run's, and a publish's kept from before
|
||||
// a release revision started one pipeline (H-A-213 (2)).
|
||||
var keyForms = []string{"*.*", "*." + runToken + ".*", "*.*.published.*.*"}
|
||||
// keyForms are the filters of every key form of the state pipelines: a revision's, a run's, a publish's kept from before
|
||||
// a release revision started one pipeline (H-A-213 (2)), and an unfinished mover's pipeline of its own (H-A-398).
|
||||
var keyForms = []string{"*.*", "*." + runToken + ".*", "*.*.published.*.*", "*.*." + unfinishedToken + ".*"}
|
||||
|
||||
// AllKeys are every pipeline's key, of each key form (§746, §747; H-A-83).
|
||||
func AllKeys(store interface {
|
||||
@@ -220,6 +220,9 @@ type Starter struct {
|
||||
// (1), H-A-328): read when a mover's wait on it is written, so a publish made before the wait places the mover without
|
||||
// any event; nil reads nothing, the publish event alone placing it.
|
||||
AskPublished func(in builds.PublishedInput) (builds.PublishedAnswer, error)
|
||||
// Unfinished puts the movers an earlier pipeline left unfinished in the pipeline of the branch's next catalog revision
|
||||
// (design 47 H2 §786); nil puts none.
|
||||
Unfinished *Unfinished
|
||||
|
||||
publishedMu sync.Mutex
|
||||
publishedRead map[string]builds.PublishedAnswer
|
||||
@@ -992,11 +995,11 @@ func DecodeTakenIn(raw []byte) (catalog.TakeInTaken, error) {
|
||||
// skip, starts nothing; a second hearing writes nothing. view is the catalog half of the event's branch, read for the
|
||||
// entries the steps and the tiers are made from.
|
||||
func (s *Starter) TakenIn(ev catalog.TakeInTaken, view func(branch string) (Half, bool)) (int, error) {
|
||||
if len(ev.Entries) == 0 {
|
||||
s.logf("the take-in of %s source %d names no entries: it starts no pipeline", ev.Branch, ev.Source)
|
||||
return 0, nil
|
||||
}
|
||||
if ev.Branch == "" || ev.Source <= 0 {
|
||||
if len(ev.Entries) == 0 {
|
||||
s.logf("the take-in of %s source %d names no entries: it starts no pipeline", ev.Branch, ev.Source)
|
||||
return 0, nil
|
||||
}
|
||||
return 0, fmt.Errorf("a take-in.taken names its watched branch and source revision: branch %q source %d", ev.Branch, ev.Source)
|
||||
}
|
||||
// A take-in heard before its branch's half is held starts its pipeline with no steps, never placed from empty entries
|
||||
@@ -1011,6 +1014,15 @@ func (s *Starter) TakenIn(ev catalog.TakeInTaken, view func(branch string) (Half
|
||||
for _, e := range ev.Entries {
|
||||
movers = append(movers, seat.Mover{Module: e.Module, Commit: e.Commit, Fingerprint: e.Fingerprint, Repository: e.Repository})
|
||||
}
|
||||
// The revision the take-in kept carries the movers an earlier pipeline left unfinished (design 47 H2 §786), judged
|
||||
// against that revision's own entries.
|
||||
if !ev.Skipped && ev.Revision > 0 {
|
||||
movers = s.carryUnfinished(ev.Branch, ev.Revision, half, held, movers)
|
||||
}
|
||||
if len(movers) == 0 {
|
||||
s.logf("the take-in of %s source %d names no entries: it starts no pipeline", ev.Branch, ev.Source)
|
||||
return 0, nil
|
||||
}
|
||||
movers = Tiers(movers, half.Entries, s.logf)
|
||||
ok, err := s.Start(Begin{Branch: ev.Branch, Source: ev.Source, Call: ev.Call, Revision: ev.Revision, Movers: movers,
|
||||
Entries: half.Entries, unheld: !held})
|
||||
@@ -1030,6 +1042,27 @@ func (s *Starter) TakenIn(ev catalog.TakeInTaken, view func(branch string) (Half
|
||||
return started, err
|
||||
}
|
||||
|
||||
// carryUnfinished adds to the movers of revision of branch the unfinished movers whose fingerprint is still their entry's
|
||||
// there (§786): half when it is that revision, else the revision read by its number; an unread revision carries none, said.
|
||||
func (s *Starter) carryUnfinished(branch string, revision int64, half Half, held bool, movers []seat.Mover) []seat.Mover {
|
||||
if s.Unfinished == nil {
|
||||
return movers
|
||||
}
|
||||
if !held || half.Revision != revision {
|
||||
if s.Revision == nil {
|
||||
s.logf("revision %d of %s is not read, so it carries no unfinished mover: the runner holds no revision reader", revision, branch)
|
||||
return movers
|
||||
}
|
||||
read, err := s.Revision(branch, revision)
|
||||
if err != nil {
|
||||
s.logf("revision %d of %s is not read, so it carries no unfinished mover: %v", revision, branch, err)
|
||||
return movers
|
||||
}
|
||||
half = read
|
||||
}
|
||||
return s.Unfinished.Carry(branch, revision, half.Entries, movers)
|
||||
}
|
||||
|
||||
// Release places the movers of pipeline key whose awaited publishes are all heard now (design 47 H §746, H-A-84). It says
|
||||
// how many pipelines it placed in.
|
||||
func (s *Starter) Release(store Updater, key string, view func(branch string) (Half, bool)) (int, error) {
|
||||
@@ -1147,18 +1180,21 @@ func (s *Starter) Revised(ev catalog.CatalogRevisionEvent, read func(branch stri
|
||||
if half.Revision != ev.Revision {
|
||||
return 0, fmt.Errorf("the revision verb answered revision %d of %s for %d", half.Revision, branch, ev.Revision)
|
||||
}
|
||||
if len(half.Movers) == 0 {
|
||||
s.logf("the revision %d of %s (%s) names no mover: it starts no pipeline", ev.Revision, branch, ev.Call)
|
||||
return 0, nil
|
||||
}
|
||||
movers := make([]seat.Mover, 0, len(half.Movers))
|
||||
for _, e := range half.Movers {
|
||||
movers = append(movers, seat.Mover{Module: e.Module, Commit: e.Commit, Fingerprint: e.Fingerprint, Repository: e.Repository})
|
||||
}
|
||||
// A revision of the same source moves no mover out of the open pipeline of that source holding it: that pipeline keeps
|
||||
// it, and this revision starts no pipeline of its own for it (H-A-283); only a revision of a new source moves movers.
|
||||
if movers = s.keepSameSource(branch, half, movers); len(movers) == 0 {
|
||||
s.logf("the revision %d of %s (%s) moves only movers the open pipelines of its source %d keep: it starts no pipeline (H-A-283)", ev.Revision, branch, ev.Call, half.Source)
|
||||
if len(movers) > 0 {
|
||||
if movers = s.keepSameSource(branch, half, movers); len(movers) == 0 {
|
||||
s.logf("the revision %d of %s (%s) moves only movers the open pipelines of its source %d keep (H-A-283)", ev.Revision, branch, ev.Call, half.Source)
|
||||
}
|
||||
}
|
||||
// It carries the movers an earlier pipeline left unfinished, or starts a pipeline for them alone (design 47 H2 §786).
|
||||
movers = s.carryUnfinished(branch, half.Revision, half, true, movers)
|
||||
if len(movers) == 0 {
|
||||
s.logf("the revision %d of %s (%s) moves no mover: it starts no pipeline", ev.Revision, branch, ev.Call)
|
||||
return 0, nil
|
||||
}
|
||||
movers = Tiers(movers, half.Entries, s.logf)
|
||||
|
||||
@@ -392,6 +392,50 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) {
|
||||
if p, _, err := mem.Get("main.12"); err != nil || len(p.Movers) != 1 || !Moves(p, "moved") {
|
||||
t.Errorf("main.12 = %+v (%v), want the one mover moved: batched is not named by the take-in", p, err)
|
||||
}
|
||||
|
||||
// design 47 H2 §786: the next kept revision carries each unfinished mover still at its entry's fingerprint, one journal
|
||||
// line each; a key the revision moves or holds at another fingerprint, or not at all, goes; a revision that moves
|
||||
// nothing starts a pipeline for the unfinished alone; place-unfinished puts one in a pipeline of its own, a hand act.
|
||||
var journal []string
|
||||
s.Logf = func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }
|
||||
u := memUnfinished{"main.batched": `{"fingerprint":"src2:bb","revision":11}`, "main.moved": `{"fingerprint":"src2:00"}`,
|
||||
"main.gone": `{"fingerprint":"src2:cc"}`, "dev.batched": `{"fingerprint":"src2:bb"}`}
|
||||
s.Unfinished = &Unfinished{Store: u, Logf: s.Logf}
|
||||
half.Revision = 13
|
||||
ev.Revision, ev.Source = 13, 10
|
||||
if n, err := s.TakenIn(ev, view); err != nil || n != 1 {
|
||||
t.Fatalf("the take-in of revision 13 started %d (%v)", n, err)
|
||||
}
|
||||
if p, _, _ := mem.Get("main.13"); len(p.Movers) != 2 || !Moves(p, "moved") || !Moves(p, "batched") {
|
||||
t.Errorf("main.13 moves %+v, want moved and the unfinished batched", p.Movers)
|
||||
}
|
||||
if u.String() != `dev.batched={"fingerprint":"src2:bb"} main.batched={"fingerprint":"src2:bb","revision":11}` {
|
||||
t.Errorf("the state unfinished = %s, want main.moved (moved at src2:aa) and main.gone (no entry) gone", u.String())
|
||||
}
|
||||
if !strings.Contains(strings.Join(journal, "\n"), "revision 13 of main puts batched in a pipeline again") {
|
||||
t.Errorf("the journal says %q, want batched put in a pipeline again", journal)
|
||||
}
|
||||
half.Revision = 14
|
||||
if n, err := s.TakenIn(catalog.TakeInTaken{Branch: "main", Source: 11, Revision: 14}, view); err != nil || n != 1 {
|
||||
t.Fatalf("a take-in moving nothing started %d (%v), want one pipeline for the unfinished", n, err)
|
||||
}
|
||||
if p, _, _ := mem.Get("main.14"); len(p.Movers) != 1 || !Moves(p, "batched") {
|
||||
t.Errorf("main.14 moves %+v, want batched alone", p.Movers)
|
||||
}
|
||||
half.Revision = 11
|
||||
acts := &actLog{}
|
||||
v := Verbs{Starter: s, View: view, Acts: acts}
|
||||
if a, err := v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "now"}); err != nil || a.Pipeline != "main.11.unfinished.batched" || len(*acts) != 1 {
|
||||
t.Errorf("place-unfinished = %+v (%v), %d hand acts", a, err, len(*acts))
|
||||
}
|
||||
if p, _, _ := mem.Get("main.11.unfinished.batched"); len(p.Movers) != 1 || !Moves(p, "batched") {
|
||||
t.Errorf("main.11.unfinished.batched moves %+v, want batched", p.Movers)
|
||||
}
|
||||
for _, in := range []seat.PlaceUnfinishedInput{{Key: "main.batched", Why: "again"}, {Key: "main.none", Why: "x"}, {Key: "dev.batched"}} {
|
||||
if _, err := v.PlaceUnfinished("agent.dev", in); err == nil {
|
||||
t.Errorf("place-unfinished %+v is refused", in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// R16/AC1 (design 47 H §765, H-A-58, H-A-98): a take-in.taken of the old form, with no call (or no branch or source), is
|
||||
|
||||
@@ -186,6 +186,9 @@ type Hearer struct {
|
||||
// Rejoin keys a pipeline running again once its approval is answered and it still runs (H-A-106 (b); Starter.Rejoin);
|
||||
// nil keys none.
|
||||
Rejoin func(key string)
|
||||
// Unfinished keeps, at every end, the movers it leaves unfinished in the state unfinished (design 47 H2 §786); nil keeps
|
||||
// none.
|
||||
Unfinished *Unfinished
|
||||
}
|
||||
|
||||
// EndReaders ends each of readers' steps of run with r's result (§725, §726): a step that read an ended run, or the steps
|
||||
@@ -488,6 +491,7 @@ func (h *Hearer) said(p seat.Pipeline, asked []int, ended bool) error {
|
||||
h.logf("%s ended %s", p.Pipeline, p.Outcome)
|
||||
}
|
||||
h.Failures.Ended(p)
|
||||
h.Unfinished.Ended(p)
|
||||
if h.RegistrationWaits != nil {
|
||||
h.RegistrationWaits()
|
||||
}
|
||||
@@ -666,7 +670,7 @@ func stepsOf(p seat.Pipeline, module string) []seat.StepResult {
|
||||
|
||||
// pipelineEnded is p's pipeline-ended (design 47 H §746): its key, branch, source, call, revision and outcome, and per
|
||||
// mover, in the delivery order of its tiers, its module, fingerprint, commit, widens (H-A-119), released version, step results
|
||||
// and tier.
|
||||
// and tier; and the movers its end left unfinished (design 47 H2 §786).
|
||||
func pipelineEnded(p seat.Pipeline) seat.PipelineEnded {
|
||||
movers := make([]seat.MoverEnded, 0, len(p.Movers))
|
||||
for _, m := range p.Movers {
|
||||
@@ -676,7 +680,7 @@ func pipelineEnded(p seat.Pipeline) seat.PipelineEnded {
|
||||
sort.SliceStable(movers, func(i, j int) bool { return movers[i].Tier < movers[j].Tier })
|
||||
return seat.PipelineEnded{V: 1, Pipeline: p.Pipeline, Branch: p.Branch, Source: p.Source, Call: p.Call, Revision: p.Revision,
|
||||
Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers,
|
||||
Phases: phasesOf(p)}
|
||||
Phases: phasesOf(p), Unfinished: unfinishedOf(p)}
|
||||
}
|
||||
|
||||
// phasesOf is p's phases (design 47 H2 §785): taken, when the runner wrote the pipeline at its take-in; placed, the
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// StateUnfinished is the runner's state of the movers left unfinished by another mover's failure (design 47 H2 §786, §820):
|
||||
// one key `<branch>.<module>` per such mover, deleted by the runner or by runner_unfinished_drop.
|
||||
const StateUnfinished = "unfinished"
|
||||
|
||||
// unfinishedToken is the third part of the key of a pipeline of its own of an unfinished mover,
|
||||
// `<branch>.<revision>.unfinished.<module>` (H-A-398).
|
||||
const unfinishedToken = "unfinished"
|
||||
|
||||
// UnfinishedEntry is one value of the state unfinished (§786): the mover's fingerprint, the catalog revision and the pipeline
|
||||
// it was left unfinished in, and that pipeline's outcome.
|
||||
type UnfinishedEntry struct {
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
Revision int64 `json:"revision"`
|
||||
Pipeline string `json:"pipeline"`
|
||||
Outcome string `json:"outcome"`
|
||||
}
|
||||
|
||||
// UnfinishedStore is the state unfinished: a key's value (nil when it has none), a put, a delete and the keys matching a
|
||||
// filter, `*` one key part.
|
||||
type UnfinishedStore interface {
|
||||
Get(key string) ([]byte, error)
|
||||
Put(key string, value []byte) error
|
||||
Delete(key string) error
|
||||
Keys(filter string) ([]string, error)
|
||||
}
|
||||
|
||||
// UnfinishedKey is a mover's key in the state unfinished, `<branch>.<module>`, each escaped as a key's name is (§786).
|
||||
func UnfinishedKey(branch, module string) string {
|
||||
return keys.EscapeName(branch) + "." + keys.EscapeName(module)
|
||||
}
|
||||
|
||||
// UnfinishedPipelineKey is the key of an unfinished mover's pipeline of its own, `<branch>.<revision>.unfinished.<module>`
|
||||
// (H-A-398).
|
||||
func UnfinishedPipelineKey(branch string, revision int64, module string) string {
|
||||
return seat.PipelinesByBranchRevisionUnfinishedModuleKey(keys.EscapeName(branch), strconv.FormatInt(revision, 10), keys.EscapeName(module))
|
||||
}
|
||||
|
||||
// neverRan are the outcomes of a step that never ran: still waiting, not asked, cancelled, held by a dependency that did not
|
||||
// build, or waiting for a build node (§786).
|
||||
var neverRan = []string{seat.StepResultOutcomeWaiting, seat.StepResultOutcomeNotAsked, seat.StepResultOutcomeCancelled,
|
||||
seat.StepResultOutcomeDidNotBuild, seat.StepResultOutcomeWaitingForABuildNode}
|
||||
|
||||
// leftUnfinished says whether a pipeline's end leaves movers unfinished: a delivering pipeline (no run on request) that ended
|
||||
// failed or cancelled (§786; a could-not-run step ends a pipeline failed, H-A-398).
|
||||
func leftUnfinished(p seat.Pipeline) bool {
|
||||
return p.Run == "" && (p.Outcome == seat.PipelineOutcomeFailed || p.Outcome == seat.PipelineOutcomeCancelled)
|
||||
}
|
||||
|
||||
// unfinishedOf are the movers p's end leaves unfinished (§786): in a pipeline ended failed or cancelled, each mover no newer
|
||||
// revision moved out of it whose own required steps all passed or never ran.
|
||||
func unfinishedOf(p seat.Pipeline) []string {
|
||||
if !leftUnfinished(p) {
|
||||
return nil
|
||||
}
|
||||
var out []string
|
||||
for _, m := range p.Movers {
|
||||
if slices.Contains(p.Superseded, m.Module) {
|
||||
continue
|
||||
}
|
||||
if ownStepsHeld(p, m.Module) {
|
||||
out = append(out, m.Module)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ownStepsHeld says whether every required step of module in p passed or never ran.
|
||||
func ownStepsHeld(p seat.Pipeline, module string) bool {
|
||||
for _, s := range p.Steps {
|
||||
if s.Module != module || s.Status != seat.StepResultStatusRequired {
|
||||
continue
|
||||
}
|
||||
if !stepPassed(s) && !slices.Contains(neverRan, s.Outcome) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Unfinished keeps the movers left unfinished in the state unfinished and puts them in a pipeline again (§786).
|
||||
type Unfinished struct {
|
||||
Store UnfinishedStore
|
||||
Logf func(string, ...any)
|
||||
}
|
||||
|
||||
func (u *Unfinished) logf(format string, args ...any) {
|
||||
if u.Logf != nil {
|
||||
u.Logf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// read is one key's entry, and whether it is held.
|
||||
func (u *Unfinished) read(key string) (UnfinishedEntry, bool, error) {
|
||||
raw, err := u.Store.Get(key)
|
||||
if err != nil || raw == nil {
|
||||
return UnfinishedEntry{}, false, err
|
||||
}
|
||||
var e UnfinishedEntry
|
||||
if err := json.Unmarshal(raw, &e); err != nil {
|
||||
return UnfinishedEntry{}, false, fmt.Errorf("the unfinished entry %s is not read: %w", key, err)
|
||||
}
|
||||
return e, true, nil
|
||||
}
|
||||
|
||||
// Ended takes a pipeline's end into the state unfinished (§786): a mover p leaves unfinished is kept under its key; a mover
|
||||
// whose pipeline ended passed, or whose own required step did not pass (it waits for its fingerprint to move), has its key
|
||||
// deleted when the key names its fingerprint. A run on request's pipeline, and one every mover left, change nothing.
|
||||
func (u *Unfinished) Ended(p seat.Pipeline) {
|
||||
if u == nil || p.Run != "" {
|
||||
return
|
||||
}
|
||||
switch p.Outcome {
|
||||
case seat.PipelineOutcomePassed, seat.PipelineOutcomeFailed, seat.PipelineOutcomeCancelled:
|
||||
default:
|
||||
return
|
||||
}
|
||||
left := unfinishedOf(p)
|
||||
for _, m := range p.Movers {
|
||||
if slices.Contains(p.Superseded, m.Module) {
|
||||
continue
|
||||
}
|
||||
key := UnfinishedKey(p.Branch, m.Module)
|
||||
if slices.Contains(left, m.Module) {
|
||||
raw, _ := json.Marshal(UnfinishedEntry{Fingerprint: m.Fingerprint, Revision: p.Revision, Pipeline: p.Pipeline, Outcome: p.Outcome})
|
||||
if err := u.Store.Put(key, raw); err != nil {
|
||||
u.logf("%s ended %s and leaves %s unfinished, but it is not kept in the state unfinished: %v", p.Pipeline, p.Outcome, m.Module, err)
|
||||
continue
|
||||
}
|
||||
u.logf("%s ended %s and leaves %s unfinished: it is put in a pipeline again at %s's next catalog revision (§786)", p.Pipeline, p.Outcome, m.Module, p.Branch)
|
||||
continue
|
||||
}
|
||||
e, held, err := u.read(key)
|
||||
if err != nil {
|
||||
u.logf("%s: the unfinished entry of %s is not read: %v", p.Pipeline, m.Module, err)
|
||||
continue
|
||||
}
|
||||
if !held || e.Fingerprint != m.Fingerprint {
|
||||
continue
|
||||
}
|
||||
if err := u.Store.Delete(key); err != nil {
|
||||
u.logf("%s: the unfinished entry of %s is not deleted: %v", p.Pipeline, m.Module, err)
|
||||
continue
|
||||
}
|
||||
u.logf("%s ended %s: %s is no longer unfinished", p.Pipeline, p.Outcome, m.Module)
|
||||
}
|
||||
}
|
||||
|
||||
// Carry adds to the movers of a catalog revision of branch each unfinished mover whose fingerprint is still its entry's in
|
||||
// entries, the revision's entries, with one journal line per mover added again (§786). An unfinished mover the revision
|
||||
// moves at a newer fingerprint, or whose entry holds another fingerprint or none, has its key deleted; one it moves at its
|
||||
// own fingerprint is carried by the revision already. It answers movers with the added ones after them.
|
||||
func (u *Unfinished) Carry(branch string, revision int64, entries map[string]catalog.CatalogEntry, movers []seat.Mover) []seat.Mover {
|
||||
if u == nil {
|
||||
return movers
|
||||
}
|
||||
ukeys, err := u.Store.Keys(keys.EscapeName(branch) + ".*")
|
||||
if err != nil {
|
||||
u.logf("the unfinished movers of %s are not listed, so revision %d carries none: %v", branch, revision, err)
|
||||
return movers
|
||||
}
|
||||
slices.Sort(ukeys)
|
||||
for _, key := range ukeys {
|
||||
_, name, _ := strings.Cut(key, ".")
|
||||
module, err := keys.UnescapeName(name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
e, held, err := u.read(key)
|
||||
if err != nil || !held {
|
||||
if err != nil {
|
||||
u.logf("revision %d of %s: %v", revision, branch, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if i := slices.IndexFunc(movers, func(m seat.Mover) bool { return m.Module == module }); i >= 0 {
|
||||
if movers[i].Fingerprint != e.Fingerprint {
|
||||
u.dropMoved(key, module, fmt.Sprintf("revision %d of %s moves it at %s", revision, branch, movers[i].Fingerprint))
|
||||
}
|
||||
continue
|
||||
}
|
||||
entry, ok := entries[module]
|
||||
if !ok || entry.Fp != e.Fingerprint {
|
||||
u.dropMoved(key, module, fmt.Sprintf("revision %d of %s holds it at %q", revision, branch, entry.Fp))
|
||||
continue
|
||||
}
|
||||
movers = append(movers, seat.Mover{Module: module, Commit: entry.Commit, Fingerprint: entry.Fp, Repository: entry.Repository})
|
||||
u.logf("revision %d of %s puts %s in a pipeline again: %s left it unfinished (%s) at fingerprint %s (§786)", revision, branch, module, e.Pipeline, e.Outcome, e.Fingerprint)
|
||||
}
|
||||
return movers
|
||||
}
|
||||
|
||||
// dropMoved deletes the key of an unfinished mover a newer fingerprint moves (§786).
|
||||
func (u *Unfinished) dropMoved(key, module, why string) {
|
||||
if err := u.Store.Delete(key); err != nil {
|
||||
u.logf("the unfinished entry of %s is not deleted: %v", module, err)
|
||||
return
|
||||
}
|
||||
u.logf("%s is no longer unfinished: %s", module, why)
|
||||
}
|
||||
|
||||
// Entry is one key's entry; false when the state holds none.
|
||||
func (u *Unfinished) Entry(key string) (UnfinishedEntry, bool, error) {
|
||||
if u == nil {
|
||||
return UnfinishedEntry{}, false, errors.New("the runner keeps no state unfinished")
|
||||
}
|
||||
return u.read(key)
|
||||
}
|
||||
@@ -726,3 +726,63 @@ func (v Verbs) Place(caller string, in seat.PlaceInput) (seat.PlaceAnswer, error
|
||||
p, _, err = s.Store.Get(in.Pipeline)
|
||||
return seat.PlaceAnswer{Pipeline: p}, err
|
||||
}
|
||||
|
||||
// PlaceUnfinished puts a mover kept in the state unfinished in a pipeline of its own at once, recorded in the hand-act log
|
||||
// first (design 47 H2 §786, H-A-398): keyed `<branch>.<revision>.unfinished.<module>`, its steps placed from the entries of
|
||||
// the catalog revision the entry names, the mover at the entry's fingerprint. The key stays until that pipeline ends passed.
|
||||
// A key the state does not hold, a revision whose entry holds another fingerprint, or a pipeline written already is refused,
|
||||
// nothing done.
|
||||
func (v Verbs) PlaceUnfinished(_ string, in seat.PlaceUnfinishedInput) (seat.PlaceUnfinishedAnswer, error) {
|
||||
s := v.Starter
|
||||
if strings.TrimSpace(in.Key) == "" {
|
||||
return seat.PlaceUnfinishedAnswer{}, errors.New("place-unfinished names the unfinished entry's key")
|
||||
}
|
||||
if s == nil || s.Unfinished == nil {
|
||||
return seat.PlaceUnfinishedAnswer{}, errors.New("the runner keeps no state unfinished: nothing was placed")
|
||||
}
|
||||
e, held, err := s.Unfinished.Entry(in.Key)
|
||||
if err != nil {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the unfinished entry %s is not read: %w", in.Key, err)
|
||||
}
|
||||
if !held {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the state unfinished holds no %s: nothing was placed", in.Key)
|
||||
}
|
||||
b, m, _ := strings.Cut(in.Key, ".")
|
||||
branch, berr := keys.UnescapeName(b)
|
||||
module, merr := keys.UnescapeName(m)
|
||||
if berr != nil || merr != nil || branch == "" || module == "" {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("%s is no key <branch>.<module>: nothing was placed", in.Key)
|
||||
}
|
||||
var half Half
|
||||
switch {
|
||||
case s.Revision != nil:
|
||||
if half, err = s.Revision(branch, e.Revision); err != nil {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the revision %d of %s is not read: nothing was placed: %w", e.Revision, branch, err)
|
||||
}
|
||||
case v.View != nil:
|
||||
var ok bool
|
||||
if half, ok = v.View(branch); !ok || half.Revision != e.Revision {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the revision %d of %s is not held: nothing was placed", e.Revision, branch)
|
||||
}
|
||||
default:
|
||||
return seat.PlaceUnfinishedAnswer{}, errors.New("the runner reads no catalog revision: nothing was placed")
|
||||
}
|
||||
entry, ok := half.Entries[module]
|
||||
if !ok || entry.Fp != e.Fingerprint || half.Source <= 0 {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the revision %d of %s holds %s at %q, not its unfinished fingerprint %s: nothing was placed", e.Revision, branch, module, entry.Fp, e.Fingerprint)
|
||||
}
|
||||
key := UnfinishedPipelineKey(branch, e.Revision, module)
|
||||
if err := v.record(seat.VerbPlaceUnfinished, "put the unfinished mover "+module+" of "+branch+" in the pipeline "+key+" by hand", in.Why); err != nil {
|
||||
return seat.PlaceUnfinishedAnswer{}, err
|
||||
}
|
||||
started, err := s.Start(Begin{Branch: branch, Source: half.Source, Revision: e.Revision, Entries: half.Entries, Key: key,
|
||||
Movers: []seat.Mover{{Module: module, Commit: entry.Commit, Fingerprint: entry.Fp, Repository: entry.Repository, Tier: 1}}})
|
||||
if err != nil {
|
||||
return seat.PlaceUnfinishedAnswer{}, err
|
||||
}
|
||||
if !started {
|
||||
return seat.PlaceUnfinishedAnswer{}, fmt.Errorf("the pipeline %s is started already: nothing was placed", key)
|
||||
}
|
||||
s.logf("%s puts the unfinished mover %s in a pipeline of its own by hand (§786)", key, module)
|
||||
return seat.PlaceUnfinishedAnswer{Pipeline: key}, nil
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ func TestManifest(t *testing.T) {
|
||||
{"claims the seat serving every verb of its definition", len(m.Claims) == 1 && m.Claims[0].Name == seat.Seat &&
|
||||
equalSets(m.Claims[0].Serves, seat.Verbs())},
|
||||
// §27, §85, §330, §355, §77: the old state sections.
|
||||
{"old state sections", equalSets(states, []string{seat.StatePipelines, seat.StateKept, "aged", "recoveries", "bounds", "test-runs", "toolchains", "findings", "first-views", "consumers", seat.StateQueue})},
|
||||
{"old state sections", equalSets(states, []string{seat.StatePipelines, seat.StateKept, "aged", "recoveries", "bounds", "test-runs", "toolchains", "findings", "first-views", "consumers", seat.StateQueue, "unfinished"})},
|
||||
// design 47 H2 §786, §820: unfinished is a state of 8 MiB.
|
||||
{"unfinished 8 MiB", stateMiB["unfinished"] == 8},
|
||||
// §535, §647, A-77, A-104: an ask no holder takes is bound by a key with its own time to live.
|
||||
{"bounds is key-ttl", keyTTL["bounds"]},
|
||||
// §725, A-469w, A-470: test-runs holds its runs' bound keys, each with its own time to live; 64 MiB its ceiling.
|
||||
@@ -117,7 +119,7 @@ func TestManifest(t *testing.T) {
|
||||
// RN25 (§539): the runner's tools carry the prefix runner_.
|
||||
{"first-view tools", equalSets(m.Tools, []string{"runner_first_views", "runner_first_view_again", "runner_health", "runner_unlogged", "runner_unlogged_append",
|
||||
"runner_start", "runner_run", "runner_accept", "runner_ask_again", "runner_place", "runner_end_again", "runner_waiting",
|
||||
"runner_test_runs", "runner_test_runs_drop"})},
|
||||
"runner_test_runs", "runner_test_runs_drop", "runner_unfinished", "runner_unfinished_drop", "runner_unfinished_place"})},
|
||||
// A-305 (ADR 0227 rule 8, ADR 0240 rule 2): the process is judged by its unit, as every process of mesh-delivery,
|
||||
// never by a tool of its own; runner_health stays a tool.
|
||||
{"health is the unit", healthTool(raw) == "unit"},
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"cancel",
|
||||
"end-again",
|
||||
"place",
|
||||
"place-unfinished",
|
||||
"ask-again",
|
||||
"test-runs",
|
||||
"test-runs-drop"
|
||||
@@ -40,7 +41,10 @@
|
||||
"runner_end_again",
|
||||
"runner_waiting",
|
||||
"runner_test_runs",
|
||||
"runner_test_runs_drop"
|
||||
"runner_test_runs_drop",
|
||||
"runner_unfinished",
|
||||
"runner_unfinished_drop",
|
||||
"runner_unfinished_place"
|
||||
],
|
||||
"consumes": [
|
||||
"mesh-delivery-indexer.take-in.taken",
|
||||
@@ -217,6 +221,11 @@
|
||||
{
|
||||
"name": "consumers",
|
||||
"history": 1
|
||||
},
|
||||
{
|
||||
"name": "unfinished",
|
||||
"history": 1,
|
||||
"max-mib": 8
|
||||
}
|
||||
],
|
||||
"streams": [
|
||||
|
||||
Reference in New Issue
Block a user