diff --git a/internal/domain/workflow/step_flow.go b/internal/domain/workflow/step_flow.go index d0bd2f838..28ff06f85 100644 --- a/internal/domain/workflow/step_flow.go +++ b/internal/domain/workflow/step_flow.go @@ -12,6 +12,7 @@ import ( "github.com/samcharles93/archie-core/internal/domain/agentrun" "github.com/samcharles93/archie-core/internal/domain/stableid" "github.com/samcharles93/archie-core/internal/domain/workflow/task" + "github.com/samcharles93/archie-core/internal/taskstate" ) const maxRetryAttempts = 10 @@ -272,9 +273,28 @@ func compileParallel(step StepRecord, registry StepRegistry) (Stage, error) { func runBranch(ctx context.Context, tc *TaskContext, stages []Stage) error { for _, stage := range stages { - if err := stage.Run(ctx, tc); err != nil && !stage.ContinueOnFailure { + parentID := tc.StepID + stepID, _, err := tc.startChildStep(ctx, task.StepKindStage, branchStepName(tc.workflowBranch, stage.Name)) + if err != nil { return err } + tc.StepID = stepID + runErr := stage.Run(ctx, tc) + tc.StepID = parentID + to, detail := taskstate.StepSucceeded, "" + switch { + case runErr == nil: + case ctx.Err() != nil: + to, detail = taskstate.StepInterrupted, runErr.Error() + default: + to, detail = taskstate.StepFailed, runErr.Error() + } + if err := tc.finishChildStep(ctx, stepID, to, detail, 0); err != nil { + return err + } + if runErr != nil && !stage.ContinueOnFailure { + return runErr + } if tc.Outcome.Status != "" { return nil } @@ -282,6 +302,17 @@ func runBranch(ctx context.Context, tc *TaskContext, stages []Stage) error { return nil } +// branchStepName qualifies a branch stage's recorded name with its branch, so +// two branches running the same step are distinct rows. It mirrors the name +// RunAgentChild gives a branch's agent steps; a branch step and the agent it +// runs may share a name, which is safe because they are different step kinds. +func branchStepName(branch, name string) string { + if branch == "" { + return name + } + return branch + "/" + name +} + // branch is a copy of the run's context for one parallel branch. The task is // copied too, with its usage counters zeroed, so join can add what the branch // spent without the branches racing on one task. diff --git a/internal/domain/workflow/step_flow_test.go b/internal/domain/workflow/step_flow_test.go new file mode 100644 index 000000000..bb19acbe6 --- /dev/null +++ b/internal/domain/workflow/step_flow_test.go @@ -0,0 +1,91 @@ +package workflow + +import ( + "context" + "errors" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/workflow/task" + "github.com/samcharles93/archie-core/internal/events" + "github.com/samcharles93/archie-core/internal/taskstate" +) + +// fakeStepStore records the step writes a branch makes. +type fakeStepStore struct { + started []task.StepStart + finished []task.StepFinish + nextID int64 +} + +func (f *fakeStepStore) Update(context.Context, *task.Task) error { return nil } + +func (f *fakeStepStore) Transition(context.Context, int64, string, string, string) error { + return nil +} + +func (f *fakeStepStore) InsertEvent(context.Context, events.Event) (int64, error) { return 0, nil } + +func (f *fakeStepStore) StartStep(_ context.Context, s task.StepStart) (int64, events.Event, error) { + f.nextID++ + f.started = append(f.started, s) + return f.nextID, events.Event{ID: f.nextID}, nil +} + +func (f *fakeStepStore) FinishStep(_ context.Context, s task.StepFinish) (events.Event, error) { + f.finished = append(f.finished, s) + return events.Event{ID: s.StepID}, nil +} + +// TestRunBranchRecordsChildSteps pins the step contract a branch owes the +// canvas: every branch step is a stage row parented to the parallel step and +// named for its branch, and its outcome is recorded. +func TestRunBranchRecordsChildSteps(t *testing.T) { + boom := errors.New("boom") + tests := []struct { + name string + stage Stage + wantErr error + wantStatus taskstate.StepStatus + wantDetail string + }{ + { + name: "a passing branch step", + stage: Stage{Name: "agent.run", Run: func(context.Context, *TaskContext) error { return nil }}, + wantStatus: taskstate.StepSucceeded, + }, + { + name: "a failing branch step", + stage: Stage{Name: "command.run", Run: func(context.Context, *TaskContext) error { return boom }}, + wantErr: boom, + wantStatus: taskstate.StepFailed, + wantDetail: "boom", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + store := &fakeStepStore{} + tc := &TaskContext{Task: &task.Task{ID: 1, Attempt: 1}, Store: store, StepID: 7, workflowBranch: "docs"} + err := runBranch(context.Background(), tc, []Stage{tt.stage}) + if !errors.Is(err, tt.wantErr) { + t.Fatalf("err = %v, want %v", err, tt.wantErr) + } + if len(store.started) != 1 { + t.Fatalf("started %d steps, want 1", len(store.started)) + } + start := store.started[0] + if start.Kind != task.StepKindStage || start.ParentID != 7 || start.Name != "docs/"+tt.stage.Name { + t.Fatalf("start = %#v, want a stage named %q under step 7", start, "docs/"+tt.stage.Name) + } + if len(store.finished) != 1 { + t.Fatalf("finished %d steps, want 1", len(store.finished)) + } + finish := store.finished[0] + if finish.To != tt.wantStatus || finish.Detail != tt.wantDetail { + t.Fatalf("finish = %#v, want %s %q", finish, tt.wantStatus, tt.wantDetail) + } + if tc.StepID != 7 { + t.Fatalf("branch step leaked its step id: %d", tc.StepID) + } + }) + } +} diff --git a/ui/dist/assets/index.js b/ui/dist/assets/index.js index 35184dc54..9367af5a7 100644 --- a/ui/dist/assets/index.js +++ b/ui/dist/assets/index.js @@ -3,7 +3,7 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en `&&(e.tagName===`PRE`||e.tagName===`TEXTAREA`)&&(n=n.slice(1));let{textContent:r}=e;r!==n&&r!==n.replace(/\r\n|\r/g,` `)&&(pi(e,0)||ri(),e.textContent=t.children)}if(d){if(_||b||!o||f&48){let t=e.tagName.includes(`-`),i=e.namespaceURI.includes(`svg`)?`svg`:e.namespaceURI.includes(`MathML`)?`mathml`:void 0;for(let a in d)if(_&&(a.endsWith(`value`)||a===`indeterminate`)||s(a)&&!O(a)||a[0]===`.`||t&&!O(a)||u&&u.includes(a)){if(ui(e,a,d[a]))continue;r(e,a,null,d[a],i,n)}}else if(d.onClick)r(e,`onClick`,null,d.onClick,void 0,n);else if(f&4&&Qt(d.style))for(let e in d.style)d.style[e]}let x;(x=d&&d.onVnodeBeforeMount)&&ms(x,n,t),h&&cr(t,null,n,`beforeMount`),((x=d&&d.onVnodeMounted)||h||l)&&Wo(()=>{x&&ms(x,n,t),l&&g.enter(e),h&&cr(t,null,n,`mounted`)},i)}return e.nextSibling},m=(e,t,r,o,s,c,u)=>{u||=!!t.dynamicChildren;let d=t.children,p=d.length,m=!1;for(let t=0;t
{let{slotScopeIds:c}=t;c&&(i=i?i.concat(c):c);let d=o(e),f=m(a(e),t,d,n,r,i,s);return f&&si(f)&&f.data===`]`?a(t.anchor=f):(ri(),l(t.anchor=u(`]`),d,f),f)},g=(e,t,r,i,s,l)=>{if(hi(e,t)||ri(),t.el=null,l){let t=_(e);for(;;){let n=a(e);if(n&&n!==t)c(n);else break}}let u=a(e),d=o(e);return c(e),n(null,t,d,u,r,i,oi(d),s),r&&(r.vnode.el=t.el,no(r,t.el)),u},_=(e,t=`[`,n=`]`)=>{let r=0;for(;e;)if(e=a(e),e&&si(e)&&(e.data===t&&r++,e.data===n)){if(r===0)return a(e);r--}return e},v=(e,t,n)=>{let r=t.parentNode;r&&r.replaceChild(e,t);let i=n;for(;i;)i.vnode.el===t&&(i.vnode.el=i.subTree.el=e),i=i.parent},y=e=>e.nodeType===1&&e.tagName===`TEMPLATE`;return[d,f]}var li=new Set([`src`,`srcset`,`href`,`poster`]);function ui(e,t,n){return li.has(t)?e.getAttribute(t)===(n==null?null:`${n}`):!1}var di=`data-allow-mismatch`,fi={0:`text`,1:`children`,2:`class`,3:`style`,4:`attribute`};function pi(e,t){if(t===0||t===1)for(;e&&!e.hasAttribute(di);)e=e.parentElement;return mi(e&&e.getAttribute(di),t)}function mi(e,t){if(e==null)return!1;if(e===``)return!0;{let n=e.split(`,`);return t===0&&n.includes(`children`)?!0:n.includes(fi[t])}}function hi(e,t){return pi(e.parentElement,1)||gi(e)||_i(t)}function gi(e){return e.nodeType===1&&mi(e.getAttribute(di),1)}function _i({props:e}){let t=e&&e[di];return typeof t==`string`&&mi(t,1)}var vi=de().requestIdleCallback||(e=>setTimeout(e,1)),yi=de().cancelIdleCallback||(e=>clearTimeout(e)),bi=(e=1e4)=>t=>{let n=vi(t,{timeout:e});return()=>yi(n)};function xi(e){let{top:t,left:n,bottom:r,right:i}=e.getBoundingClientRect(),{innerHeight:a,innerWidth:o}=window;return(t>0&&t0&&r0&&ne.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?sf+r:void 0})(),df=e=>{let{theme:t,classGroups:n}=e;return ff(n,t)},ff=(e,t)=>{let n=rf();for(let r in e){let i=e[r];pf(i,n,r,t)}return n},pf=(e,t,n,r)=>{let i=e.length;for(let a=0;a{if(typeof e==`string`){hf(e,t,n);return}if(typeof e==`function`){gf(e,t,n,r);return}_f(e,t,n,r)},hf=(e,t,n)=>{let r=e===``?t:vf(t,e);r.classGroupId=n},gf=(e,t,n,r)=>{if(yf(e)){pf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(nf(n,e))},_f=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e{let n=e,r=t.split(af),i=r.length;for(let e=0;e`isThemeGetter`in e&&e.isThemeGetter===!0,bf=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},xf=`!`,Sf=`:`,Cf=[],wf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Tf=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;se&&(e.type===`block-map`||e.type===`block-seq`);function DX({composeNode:e,composeEmptyNode:t},n,r,i,a){let o=r.start.source===`{`,s=o?`flow map`:`flow sequence`,c=new((a?.nodeClass)??(o?cY:uY))(n.schema);c.flow=!0;let l=n.atRoot;l&&(n.atRoot=!1),n.atKey&&=!1;let u=r.offset+r.start.source.length;for(let a=0;ae&&(e.type===`block-map`||e.type===`block-seq`);function EX({composeNode:e,composeEmptyNode:t},n,r,i,a){let o=r.start.source===`{`,s=o?`flow map`:`flow sequence`,c=new((a?.nodeClass)??(o?sY:lY))(n.schema);c.flow=!0;let l=n.atRoot;l&&(n.atRoot=!1),n.atKey&&=!1;let u=r.offset+r.start.source.length;for(let a=0;ac&&(c=r.length);else{r.length