merge: name a workflow's declared inputs on the work-request form (06nq)
# Conflicts: # ui/dist/assets/index.js
This commit is contained in:
commit
173c0dacba
7 files changed
+333
-22
No files matched your search
@@ -50,6 +50,12 @@ type workRequest struct {
|
||||
Workflow string `json:"workflow"`
|
||||
Title string `json:"title"`
|
||||
Instructions string `json:"instructions"`
|
||||
// Inputs assigns the inputs the named workflow declares -- pr-review's
|
||||
// pr_number, for instance. The handler checks the assignment against the
|
||||
// declaration before the task is admitted, so a request that could only
|
||||
// fail at the workflow's first stage is refused here instead
|
||||
// (archie-core-06nq).
|
||||
Inputs map[string]any `json:"inputs"`
|
||||
}
|
||||
|
||||
func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -85,18 +91,22 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "identity, repository, workflow, title, and instructions are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
available, err := s.hasWorkflow(r.Context(), request.Workflow)
|
||||
iface, enabled, err := s.enabledWorkflowInterface(r.Context(), request.Workflow)
|
||||
if err != nil {
|
||||
http.Error(w, "workflow definitions unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
if !available {
|
||||
if !enabled {
|
||||
http.Error(w, "workflow is not enabled", http.StatusConflict)
|
||||
return
|
||||
}
|
||||
if err := iface.CheckInputs(request.Inputs); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
taskID, err := s.WorkRequests.CreateTask(r.Context(), messaging.SpawnRequest{
|
||||
Identity: request.Identity, Repo: request.Repository, Workflow: request.Workflow,
|
||||
Title: request.Title, Body: request.Instructions,
|
||||
Title: request.Title, Body: request.Instructions, Inputs: request.Inputs,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, "work request rejected", http.StatusBadRequest)
|
||||
@@ -107,16 +117,26 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, map[string]any{"ok": true, "task_id": taskID})
|
||||
}
|
||||
|
||||
// hasWorkflow reports whether workflow id is defined and enabled for the
|
||||
// default org, the org every dashboard caller acts in until access resolves
|
||||
// a caller's own.
|
||||
func (s *Server) hasWorkflow(ctx context.Context, id string) (bool, error) {
|
||||
found, err := s.hasWorkflowDefinition(ctx, id)
|
||||
// enabledWorkflowInterface returns the interface workflow id declares, and
|
||||
// whether it is defined and enabled for the default org -- the org every
|
||||
// dashboard caller acts in until access resolves a caller's own. The interface
|
||||
// is what the work-request handler checks a request's inputs against, so a task
|
||||
// whose workflow declaration the request cannot satisfy is refused before it is
|
||||
// admitted.
|
||||
func (s *Server) enabledWorkflowInterface(ctx context.Context, id string) (task.WorkflowInterface, bool, error) {
|
||||
entry, found, err := s.workflowEntry(ctx, id)
|
||||
if err != nil || !found {
|
||||
return false, err
|
||||
return task.WorkflowInterface{}, false, err
|
||||
}
|
||||
enablement, _, err := s.workflowEnablement(ctx)
|
||||
return enablement.Enabled(org.DefaultOrgID, id), err
|
||||
if err != nil || !enablement.Enabled(org.DefaultOrgID, id) {
|
||||
return task.WorkflowInterface{}, false, err
|
||||
}
|
||||
iface, err := task.ParseWorkflowInterface(entry.YAML)
|
||||
if err != nil {
|
||||
return task.WorkflowInterface{}, false, err
|
||||
}
|
||||
return iface, true, nil
|
||||
}
|
||||
|
||||
func (s *Server) hasWorkflowDefinition(ctx context.Context, id string) (bool, error) {
|
||||
|
||||
@@ -49,18 +49,113 @@ func TestWorkflowsIncludeInstalledZeroRunDefinitions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// declaredInputsDefinition is a pr-review-shaped definition: it declares the
|
||||
// inputs the handler checks a work request against, one of them required, so a
|
||||
// request that does not name a pull request number cannot be admitted.
|
||||
const declaredInputsDefinition = `id: pr-review
|
||||
inputs:
|
||||
pr_number:
|
||||
type: number
|
||||
required: true
|
||||
depth:
|
||||
type: string
|
||||
steps:
|
||||
- type: implement.prepare
|
||||
`
|
||||
|
||||
func postWorkRequest(t *testing.T, srv *Server, body string) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/work-requests", strings.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Archie-CSRF", "1")
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
return w
|
||||
}
|
||||
|
||||
// TestWorkRequestCarriesDeclaredInputs: a dashboard request names the workflow's
|
||||
// declared inputs and the admitted task carries them, so a pr-review request
|
||||
// reaches its workflow with the pull request number stagePRIntake reads
|
||||
// (archie-core-06nq).
|
||||
func TestWorkRequestCarriesDeclaredInputs(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
creator := &recordingWorkRequestCreator{}
|
||||
srv.WorkRequests = creator
|
||||
srv.ControlPlane = workflowControlPlane(t, workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{{ID: "pr-review", YAML: declaredInputsDefinition}}})
|
||||
|
||||
w := postWorkRequest(t, srv, `{"identity":"archie","repository":"acme/widget","workflow":"pr-review","title":"Review 77","instructions":"Review it.","inputs":{"pr_number":77,"depth":"deep"}}`)
|
||||
if w.Code != http.StatusCreated {
|
||||
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
||||
}
|
||||
if got := creator.request.Inputs["pr_number"]; got != float64(77) {
|
||||
t.Errorf("pr_number input = %#v, want the number the request sent", got)
|
||||
}
|
||||
if got := creator.request.Inputs["depth"]; got != "deep" {
|
||||
t.Errorf("depth input = %#v, want \"deep\"", got)
|
||||
}
|
||||
// EffectivePRNumber is how the daemon and stagePRIntake read the input, so
|
||||
// the assignment is proven against the consumer rather than against the
|
||||
// map's shape alone.
|
||||
if got := (workflow.Task{Inputs: creator.request.Inputs}).EffectivePRNumber(); got != 77 {
|
||||
t.Errorf("EffectivePRNumber() = %d, want 77", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWorkRequestRejectsUnmetDeclaredInputs: the request is refused at the
|
||||
// producer, naming the input, instead of being admitted and then parked or
|
||||
// failed at the workflow's first stage.
|
||||
func TestWorkRequestRejectsUnmetDeclaredInputs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
body string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "missing a required input",
|
||||
body: `{"identity":"archie","repository":"acme/widget","workflow":"pr-review","title":"Review","instructions":"Review it."}`,
|
||||
want: `input "pr_number" is required`,
|
||||
},
|
||||
{
|
||||
name: "naming an input the workflow does not declare",
|
||||
body: `{"identity":"archie","repository":"acme/widget","workflow":"pr-review","title":"Review","instructions":"Review it.","inputs":{"pr_number":77,"pull_request":77}}`,
|
||||
want: `input "pull_request" is not declared by the workflow`,
|
||||
},
|
||||
{
|
||||
name: "a value of the wrong type",
|
||||
body: `{"identity":"archie","repository":"acme/widget","workflow":"pr-review","title":"Review","instructions":"Review it.","inputs":{"pr_number":"seventy-seven"}}`,
|
||||
want: `input "pr_number" is string, want number`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
creator := &recordingWorkRequestCreator{}
|
||||
srv.WorkRequests = creator
|
||||
srv.ControlPlane = workflowControlPlane(t, workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{{ID: "pr-review", YAML: declaredInputsDefinition}}})
|
||||
|
||||
w := postWorkRequest(t, srv, tt.body)
|
||||
if w.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
||||
}
|
||||
if !strings.Contains(w.Body.String(), tt.want) {
|
||||
t.Errorf("body = %q, want it to name the failure %q", w.Body, tt.want)
|
||||
}
|
||||
if got := creator.request; got.Title != "" || got.Body != "" || len(got.Inputs) != 0 {
|
||||
t.Errorf("creator called with %#v", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkRequestUsesNormalTaskAdmission(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
creator := &recordingWorkRequestCreator{}
|
||||
srv.WorkRequests = creator
|
||||
srv.ControlPlane = workflowControlPlane(t, workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{{ID: "implement", YAML: "id: implement\nsteps:\n - type: implement.prepare\n"}}})
|
||||
|
||||
// An inputless workflow keeps taking an inputless request.
|
||||
body := `{"identity":"archie","repository":"acme/widget","workflow":"implement","title":"Fix login","instructions":"Reproduce and fix it."}`
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/work-requests", strings.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Archie-CSRF", "1")
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
w := postWorkRequest(t, srv, body)
|
||||
|
||||
if w.Code != http.StatusCreated {
|
||||
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
||||
@@ -75,11 +170,7 @@ func TestWorkRequestRejectsDisabledWorkflow(t *testing.T) {
|
||||
creator := &recordingWorkRequestCreator{}
|
||||
srv.WorkRequests = creator
|
||||
srv.ControlPlane = workflowControlPlane(t, workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{{ID: "custom", YAML: "id: custom\nsteps:\n - type: implement.prepare\n"}}})
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/work-requests", strings.NewReader(`{"identity":"archie","repository":"acme/widget","workflow":"implement","title":"Fix","instructions":"Do it"}`))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Archie-CSRF", "1")
|
||||
w := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(w, req)
|
||||
w := postWorkRequest(t, srv, `{"identity":"archie","repository":"acme/widget","workflow":"implement","title":"Fix","instructions":"Do it"}`)
|
||||
if w.Code != http.StatusConflict {
|
||||
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -17,4 +17,4 @@ Defaulting to \`null\`.`),null)}function VS(e){return zS(e)&&!Number.isNaN(e)&&e
|
||||
`)}),a=null):a=[];continue}if(a){a.push(c);continue}let l=YE(c),u=e+1<n.length?YE(n[e+1]):null;if(l&&u&&XE(u)&&l.length===u.length){o(),s();let r=[];for(e+=2;e<n.length;e++){let t=YE(n[e]);if(!t||t.length!==l.length){e--;break}r.push(t)}t.push({kind:`table`,head:l.map(e=>qE(e)),rows:r.map(e=>e.map(e=>qE(e)))});continue}if(!c.trim()){o(),s();continue}let d=c.match(/^(#{1,3})\s+(.+)$/);if(d){o(),s(),t.push({kind:`h${d[1].length}`,inline:qE(d[2])});continue}let f=c.match(/^\s*[-*]\s+(.+)$/),p=c.match(/^\s*\d+[.)]\s+(.+)$/);if(f||p){o();let e=p?`ol`:`ul`;(!i||i.tag!==e)&&(s(),i={tag:e,items:[]}),i.items.push((f||p)[1]);continue}if(c.startsWith(`>`)){o(),s(),t.push({kind:`blockquote`,inline:qE(c.replace(/^>\s?/,``))});continue}r.push(c)}return o(),s(),a&&t.push({kind:`pre`,code:a.join(`
|
||||
`)}),t}function YE(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function XE(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var ZE={class:`[overflow-wrap:anywhere]`},QE={key:0,class:`my-2 overflow-auto rounded-md border border-border bg-background/60 p-3`},$E={class:`font-mono text-[0.85em]`},eD={key:1,class:`my-3 w-full border-collapse text-[0.92em]`},tD={key:2,class:`my-2 border-l-[3px] border-primary pl-3 text-fg-muted`},nD={key:3,class:`mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]`},rD={key:4,class:`mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]`},iD={key:5,class:`mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]`},aD={key:6,class:`my-2.5 flex list-disc flex-col gap-1 pl-5`},oD={key:7,class:`my-2.5 flex list-decimal flex-col gap-1 pl-5`},sD={key:8,class:`mb-2.5 last:mb-0`},cD=j({__name:`ChatMarkdown`,props:{text:{}},setup(e){let t=e,n=U(()=>JE(t.text));return(e,t)=>(F(),I(`div`,ZE,[(F(!0),I(P,null,M(n.value,(e,t)=>(F(),I(P,{key:t},[e.kind===`pre`?(F(),I(`pre`,QE,[R(`code`,$E,E(e.code),1)])):e.kind===`table`?(F(),I(`table`,eD,[R(`thead`,null,[R(`tr`,null,[(F(!0),I(P,null,M(e.head,(e,t)=>(F(),I(`th`,{key:t,class:`border border-border bg-muted px-2 py-1.5 text-left font-semibold`},[z(GE,{inline:e},null,8,[`inline`])]))),128))])]),R(`tbody`,null,[(F(!0),I(P,null,M(e.rows,(e,t)=>(F(),I(`tr`,{key:t},[(F(!0),I(P,null,M(e,(e,t)=>(F(),I(`td`,{key:t,class:`border border-border px-2 py-1.5 text-left`},[z(GE,{inline:e},null,8,[`inline`])]))),128))]))),128))])])):e.kind===`blockquote`?(F(),I(`blockquote`,tD,[z(GE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h1`?(F(),I(`h1`,nD,[z(GE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h2`?(F(),I(`h2`,rD,[z(GE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h3`?(F(),I(`h3`,iD,[z(GE,{inline:e.inline},null,8,[`inline`])])):e.kind===`ul`?(F(),I(`ul`,aD,[(F(!0),I(P,null,M(e.items,(e,t)=>(F(),I(`li`,{key:t},[z(GE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`ol`?(F(),I(`ol`,oD,[(F(!0),I(P,null,M(e.items,(e,t)=>(F(),I(`li`,{key:t},[z(GE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`p`?(F(),I(`p`,sD,[z(GE,{inline:e.inline},null,8,[`inline`])])):V(``,!0)],64))),128))]))}}),lD={class:`truncate`},uD=j({__name:`ChatNavChip`,props:{path:{},label:{}},setup(e){return(t,n)=>{let r=ha(`RouterLink`);return F(),L(r,{to:e.path,title:`Go to ${e.label||e.path}`,class:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-primary/45 bg-primary-soft px-2.5 py-1 text-xs font-semibold text-link transition-colors hover:border-primary hover:bg-primary/15 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`},{default:k(()=>[z(O(xd),{"aria-hidden":`true`,class:`size-3.5 shrink-0`}),R(`span`,lD,E(e.label||e.path),1)]),_:1},8,[`to`,`title`])}}}),dD={key:1,class:`flex items-baseline gap-1.5 [overflow-wrap:anywhere]`},fD={class:`font-semibold text-foreground`},pD={key:0,class:`font-mono text-[0.95em] text-fg-subtle`},mD=j({__name:`ChatToolCall`,props:{tool:{},streaming:{type:Boolean}},setup(e){let t=e,n=U(()=>t.tool.name||t.tool.Name||t.tool.tool||`tool`),r=U(()=>t.tool.parameters||t.tool.Parameters||``),i=U(()=>!!(t.tool.err||t.tool.Err||t.tool.failed)),a=U(()=>t.tool.summary||t.tool.Summary||t.tool.text||t.tool.err||t.tool.Err||(t.streaming?i.value?`failed`:`running…`:`done`));return(t,o)=>e.tool.path?(F(),L(uD,{key:0,path:e.tool.path,label:e.tool.label},null,8,[`path`,`label`])):(F(),I(`div`,dD,[z(O(uf),{"aria-hidden":`true`,class:`size-3.5 shrink-0 self-center text-fg-subtle`}),R(`span`,fD,E(n.value),1),r.value?(F(),I(`code`,pD,E(r.value),1)):V(``,!0),R(`span`,{class:T(O(K)(`text-fg-muted`,i.value&&`text-danger`))},E(a.value),3)]))}}),hD={key:0,class:`mb-2 grid gap-0.5 text-xs`},gD={key:1,class:`mb-2 flex flex-wrap gap-1.5`},_D={key:3,class:`whitespace-pre-wrap`},vD=j({__name:`ChatBubble`,props:{text:{},tools:{default:()=>[]},media:{default:()=>[]},assistant:{type:Boolean,default:!1},streaming:{type:Boolean,default:!1}},setup(e){return(t,n)=>(F(),I(`div`,{class:T([`flex`,e.assistant?`justify-start`:`justify-end`])},[R(`div`,{class:T(O(K)(`max-w-[min(78ch,86%)] rounded-[0.85rem] px-4 py-3 leading-normal [overflow-wrap:anywhere]`,e.assistant?`bg-muted`:`bg-primary/15`))},[e.assistant&&e.tools.length?(F(),I(`div`,hD,[(F(!0),I(P,null,M(e.tools,(t,n)=>(F(),L(mD,{key:n,tool:t,streaming:e.streaming},null,8,[`tool`,`streaming`]))),128))])):V(``,!0),e.media.length?(F(),I(`div`,gD,[(F(!0),I(P,null,M(e.media,(e,t)=>(F(),L(RE,{key:t,attachment:e},null,8,[`attachment`]))),128))])):V(``,!0),e.assistant?(F(),L(cD,{key:2,text:e.text},null,8,[`text`])):(F(),I(`div`,_D,E(e.text),1)),N(t.$slots,`default`)],2)],2))}}),yD={class:`w-full self-center justify-self-center py-6 text-center`},bD={class:`grid gap-2`},xD=[`onClick`],SD=j({__name:`ChatEmptyState`,emits:[`proLine truncated
|
||||
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>NM?`${n.slice(0,NM).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var FM=[`title`],IM=j({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=U(()=>dM(n.event)),a=U(()=>PM(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=U(()=>n.event.at?xj(n.event.at):`—`);return(e,t)=>(F(),L(O(AM),{class:T(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[fu(uu(o,[`prevent`]),[`enter`]),fu(uu(o,[`prevent`]),[`space`])]},{default:k(()=>[z(O($),{class:`font-medium`},{default:k(()=>[B(E(n.event.kind||n.event.type||`event`),1)]),_:1}),z(O($),{class:`font-mono`},{default:k(()=>[B(E(i.value>0?`#${i.value}`:`—`),1)]),_:1}),z(O($),{class:`w-[55%] max-w-0`},{default:k(()=>[R(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},E(a.value.text),9,FM)]),_:1}),z(O($),null,{default:k(()=>[B(E(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}});function LM(e,t){return`${e}:${t??0}`}function RM(e){let t=[];for(let n of e){let e=n.kind||n.type||`event`,r=Number(n.task_id)||0,i=LM(PM(n).text,r),a=t[t.length-1];if(a&&a.key===i){a.count+=1,a.events.push(n);continue}t.push({key:i,label:e,taskID:r,count:1,representative:n,events:[n]})}return t}var zM={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},BM={class:`max-h-[28rem] overflow-y-auto`},VM=[`aria-expanded`,`aria-label`,`onClick`],HM=[`title`],UM=j({__name:`LiveActivityCard`,setup(e){let t=GD(),{activity:n,streamKind:r,streamState:i}=od(kA()),a=rn(new Set),o=U(()=>RM(n.value));function s(e){a.has(e)?a.delete(e):a.add(e)}function c(e){return a.has(e.key)}function l(e){return PM(e.representative)}function u(e){return e.representative.at?xj(e.representative.at):`—`}function d(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(F(),L(O(mj),null,{default:k(()=>[z(O(yj),null,{default:k(()=>[z(O(bj),null,{default:k(()=>[...t[0]||=[B(`Live activity`,-1)]]),_:1}),z(O(hj),null,{default:k(()=>[z(O(dj),{variant:O(r)},{default:k(()=>[B(E(O(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),z(O(gj),null,{default:k(()=>[R(`div`,zM,[R(`div`,BM,[z(O(OM),null,{default:k(()=>[z(O(MM),{class:`sticky top-0 z-10 bg-card`},{default:k(()=>[z(O(AM),null,{default:k(()=>[z(O(jM),null,{default:k(()=>[...t[1]||=[B(`Event`,-1)]]),_:1}),z(O(jM),null,{default:k(()=>[...t[2]||=[B(`Task`,-1)]]),_:1}),z(O(jM),null,{default:k(()=>[...t[3]||=[B(`Detail`,-1)]]),_:1}),z(O(jM),null,{default:k(()=>[...t[4]||=[B(`When`,-1)]]),_:1})]),_:1})]),_:1}),z(O(kM),null,{default:k(()=>[O(n).length?V(``,!0):(F(),L(O(AM),{key:0},{default:k(()=>[z(O($),{colspan:`4`},{default:k(()=>[z(O(rj),null,{default:k(()=>[z(O(oj),null,{default:k(()=>[z(O(lj),null,{default:k(()=>[...t[5]||=[B(`Waiting for activity`,-1)]]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})),O(n).length?(F(!0),I(P,{key:1},M(o.value,e=>(F(),I(P,{key:e.key},[e.count===1?(F(),L(IM,{key:0,event:e.representative,onOpen:d},null,8,[`event`])):(F(),I(P,{key:1},[z(O(AM),{class:T(e.taskID>0?`cursor-pointer`:``),role:e.taskID>0?`link`:void 0,tabindex:e.taskID>0?0:void 0,title:e.taskID>0?`Open task details`:void 0,onClick:t=>e.taskID>0&&d(e.taskID),onKeydown:[fu(uu(t=>e.taskID>0&&d(e.taskID),[`prevent`]),[`enter`]),fu(uu(t=>e.taskID>0&&d(e.taskID),[`prevent`]),[`space`])]},{default:k(()=>[z(O($),{class:`font-medium`},{default:k(()=>[R(`button`,{type:`button`,class:`inline-flex items-center gap-1 rounded hover:opacity-80`,"aria-expanded":c(e),"aria-label":`${c(e)?`Hide`:`Show`} ${e.count} ${e.label} events`,onClick:uu(t=>s(e.key),[`stop`])},[c(e)?(F(),L(O(Td),{key:0,class:`size-3.5 shrink-0 text-fg-subtle`})):(F(),L(O(Ed),{key:1,class:`size-3.5 shrink-0 text-fg-subtle`})),B(` `+E(e.label)+` `,1),z(O(dj),{variant:`idle`},{default:k(()=>[B(`×`+E(e.count),1)]),_:2},1024)],8,VM)]),_:2},1024),z(O($),{class:`font-mono`},{default:k(()=>[B(E(e.taskID>0?`#${e.taskID}`:`—`),1)]),_:2},1024),z(O($),{class:`w-[55%] max-w-0`},{default:k(()=>[R(`span`,{class:`block truncate`,title:l(e).truncated?l(e).full:void 0},E(l(e).text),9,HM)]),_:2},1024),z(O($),null,{default:k(()=>[B(E(u(e)),1)]),_:2},1024)]),_:2},1032,[`class`,`role`,`tabindex`,`title`,`onClick`,`onKeydown`]),c(e)?(F(!0),I(P,{key:0},M(e.events,(t,n)=>(F(),L(IM,{key:`${e.key}:${n}`,event:t,onOpen:d},null,8,[`event`]))),128)):V(``,!0)],64))],64))),128)):V(``,!0)]),_:1})]),_:1})])])]),_:1})]),_:1}))}}),WM=j({__name:`Alert`,props:{class:{type:[Boolean,null,String,Object,Array]},variant:{}},setup(e){let t=e;return(n,r)=>(F(),I(`div`,{"data-slot":`alert`,class:T(O(K)(O(JM)({variant:e.variant}),t.class)),role:`alert`},[N(n.$slots,`default`)],2))}}),GM=j({__name:`AlertAction`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e;return(e,n)=>(F(),I(`div`,{"data-slot":`alert-action`,class:T(O(K)(`absolute top-2 right-2`,t.class))},[N(e.$slots,`default`)],2))}}),KM=j(
Line truncated
|
||||
`)){let e=n.indexOf(`:`);if(e<=0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function GN(e,t){if(!e.event_type)return{label:`Unidentified`,identified:!1};let n=t.find(t=>t.id===e.event_type);return{label:n?n.name:`Deleted type`,identified:!0}}function KN(e,t){if(!e)return`No event type`;let n=t.find(t=>t.id===e);return n?`${n.source} / ${n.name}`:`Deleted type`}function qN(e){let t=[...(e.headers||[]).map(e=>`${e.name} = ${e.value}`),...(e.payload||[]).map(e=>e.op===`present`?`${e.path} present`:`${e.path} = ${e.value??``}`)];return t.length?t.join(` · `):`any event`}function JN(e){return{headers:(e.headers||[]).filter(e=>e.name.trim()!==``).map(e=>({name:e.name.trim(),value:e.value})),payload:(e.payload||[]).filter(e=>e.path.trim()!==``).map(e=>e.op===`present`?{path:e.path.trim(),op:e.op}:{path:e.path.trim(),op:e.op,value:e.value??``})}}var YN=D([]),XN=D([]),ZN=D(!0),QN=D(null),$N=D(null),eP=D(!1),tP=D(null);async function nP(){try{let e=await q.eventTypes();ZN.value=e.enabled!==!1,YN.value=e.event_types||[],XN.value=e.proposals||[],QN.value=null}catch(e){QN.value=e.message||String(e)}}function rP(e){return{headers:(e.headers||[]).map(e=>({...e})),payload:(e.payload||[]).map(e=>({...e}))}}function iP(e){tP.value=null,$N.value=e}function aP(e){let t=pP.value.find(t=>String(t.id)===e.sample_id);iP({mode:`proposal`,id:null,source:e.source,name:``,rule:rP(e.rule),headersText:``,body:t?.body||``,exampleHeaders:e.headers||{}})}function oP(e=``){iP({mode:`paste`,id:null,source:e,name:``,rule:{headers:[],payload:[]},headersText:``,body:``,exampleHeaders:{}})}function sP(e){iP({mode:`edit`,id:e.id,source:e.source,name:e.name,rule:rP(e.rule),headersText:``,body:``,exampleHeaders:{}})}function cP(){$N.value=null}async function lP(){let e=$N.value;if(e){eP.value=!0;try{if(e.mode===`edit`&&e.id)await q.eventTypeUpdate(e.id,{name:e.name,rule:JN(e.rule)});else{let t=e.mode===`paste`?WN(e.headersText):e.exampleHeaders;await q.eventTypeCreate({source:e.source,name:e.name,rule:e.mode===`paste`?void 0:JN(e.rule),example:{headers:t,body:e.body}})}$N.value=null,await nP()}catch(e){tP.value=e.message||String(e)}finally{eP.value=!1}}}var uP=D(null);async function dP(){let e=uP.value;if(uP.value=null,e)try{await q.eventTypeDelete(e.id),await nP()}catch(e){QN.value=e.message||String(e)}}var fP=100,pP=D([]),mP=D(!0),hP=D(null),gP=D(!0),_P=D(null);async function vP(){try{let e=await q.captures(fP);mP.value=e.enabled!==!1,pP.value=e.captures||[],hP.value=null}catch(e){hP.value=e.message||String(e)}finally{gP.value=!1}}function yP(e){let t=pP.value.find(t=>t.id===e);return t&&(_P.value=t),!!t}function bP(){pP.value.length&&(_P.value=pP.value[0])}function xP(){AA(`captures`,()=>{vP(),nP()})}var SP=j({__name:`Tabs`,props:{defaultValue:{},orientation:{},dir:{},activationMode:{},modelValue:{},unmountOnHide:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},emits:[`update:modelValue`],setup(e,{emit:t}){let n=e,r=t,i=xg(Fw(n,`class`),r);return(e,t)=>(F(),L(O(HC),H({"data-slot":`tabs`,"data-orientation":O(i).orientation||`horizontal`},O(i),{class:O(K)(`gap-2 group/tabs flex data-horizontal:flex-col`,n.class)}),{default:k(t=>[N(e.$slots,`default`,we(Os(t)))]),_:3},16,[`data-orientation`,`class`]))}}),CP=j({__name:`TabsContent`,props:{value:{},forceMount:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=Fw(t,`class`);return(e,r)=>(F(),L(O(GC),H({"data-slot":`tabs-content`,class:O(K)(`text-sm flex-1 outline-none`,t.class)},O(n)),{default:k(()=>[N(e.$slots,`default`)]),_:3},16,[`class`]))}}),wP=j({__name:`TabsList`,props:{loop:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]},variant:{default:`default`}},setup(e){let t=e,n=Fw(t,`class`,`variant`);return(r,i)=>(F(),L(O(KC),H({"data-slot":`tabs-list`,"data-variant":e.variant},O(n),{class:O(K)(O(EP)({variant:e.variant}),t.class)}),{default:k(()=>[N(r.$slots,`default`)]),_:3},16,[`data-variant`,`class`]))}}),TP=j({__name:`TabsTrigger`,props:{value:{},disabled:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=bg(Fw(t,`class`));return(e,r)=>(F(),L(O(qC),H({"data-slot":`tabs-trigger`,class:O(K)(`gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*=size-])]:size-4 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabledLine truncated
|
||||
`)){let e=n.indexOf(`:`);if(e<=0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function GN(e,t){if(!e.event_type)return{label:`Unidentified`,identified:!1};let n=t.find(t=>t.id===e.event_type);return{label:n?n.name:`Deleted type`,identified:!0}}function KN(e,t){if(!e)return`No event type`;let n=t.find(t=>t.id===e);return n?`${n.source} / ${n.name}`:`Deleted type`}function qN(e){let t=[...(e.headers||[]).map(e=>`${e.name} = ${e.value}`),...(e.payload||[]).map(e=>e.op===`present`?`${e.path} present`:`${e.path} = ${e.value??``}`)];return t.length?t.join(` · `):`any event`}function JN(e){return{headers:(e.headers||[]).filter(e=>e.name.trim()!==``).map(e=>({name:e.name.trim(),value:e.value})),payload:(e.payload||[]).filter(e=>e.path.trim()!==``).map(e=>e.op===`present`?{path:e.path.trim(),op:e.op}:{path:e.path.trim(),op:e.op,value:e.value??``})}}var YN=D([]),XN=D([]),ZN=D(!0),QN=D(null),$N=D(null),eP=D(!1),tP=D(null);async function nP(){try{let e=await q.eventTypes();ZN.value=e.enabled!==!1,YN.value=e.event_types||[],XN.value=e.proposals||[],QN.value=null}catch(e){QN.value=e.message||String(e)}}function rP(e){return{headers:(e.headers||[]).map(e=>({...e})),payload:(e.payload||[]).map(e=>({...e}))}}function iP(e){tP.value=null,$N.value=e}function aP(e){let t=pP.value.find(t=>String(t.id)===e.sample_id);iP({mode:`proposal`,id:null,source:e.source,name:``,rule:rP(e.rule),headersText:``,body:t?.body||``,exampleHeaders:e.headers||{}})}function oP(e=``){iP({mode:`paste`,id:null,source:e,name:``,rule:{headers:[],payload:[]},headersText:``,body:``,exampleHeaders:{}})}function sP(e){iP({mode:`edit`,id:e.id,source:e.source,name:e.name,rule:rP(e.rule),headersText:``,body:``,exampleHeaders:{}})}function cP(){$N.value=null}async function lP(){let e=$N.value;if(e){eP.value=!0;try{if(e.mode===`edit`&&e.id)await q.eventTypeUpdate(e.id,{name:e.name,rule:JN(e.rule)});else{let t=e.mode===`paste`?WN(e.headersText):e.exampleHeaders;await q.eventTypeCreate({source:e.source,name:e.name,rule:e.mode===`paste`?void 0:JN(e.rule),example:{headers:t,body:e.body}})}$N.value=null,await nP()}catch(e){tP.value=e.message||String(e)}finally{eP.value=!1}}}var uP=D(null);async function dP(){let e=uP.value;if(uP.value=null,e)try{await q.eventTypeDelete(e.id),await nP()}catch(e){QN.value=e.message||String(e)}}var fP=100,pP=D([]),mP=D(!0),hP=D(null),gP=D(!0),_P=D(null);async function vP(){try{let e=await q.captures(fP);mP.value=e.enabled!==!1,pP.value=e.captures||[],hP.value=null}catch(e){hP.value=e.message||String(e)}finally{gP.value=!1}}function yP(e){let t=pP.value.find(t=>t.id===e);return t&&(_P.value=t),!!t}function bP(){pP.value.length&&(_P.value=pP.value[0])}function xP(){AA(`captures`,()=>{vP(),nP()})}var SP=j({__name:`Tabs`,props:{defaultValue:{},orientation:{},dir:{},activationMode:{},modelValue:{},unmountOnHide:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},emits:[`update:modelValue`],setup(e,{emit:t}){let n=e,r=t,i=xg(Fw(n,`class`),r);return(e,t)=>(F(),L(O(HC),H({"data-slot":`tabs`,"data-orientation":O(i).orientation||`horizontal`},O(i),{class:O(K)(`gap-2 group/tabs flex data-horizontal:flex-col`,n.class)}),{default:k(t=>[N(e.$slots,`default`,we(Os(t)))]),_:3},16,[`data-orientation`,`class`]))}}),CP=j({__name:`TabsContent`,props:{value:{},forceMount:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=Fw(t,`class`);return(e,r)=>(F(),L(O(GC),H({"data-slot":`tabs-content`,class:O(K)(`text-sm flex-1 outline-none`,t.class)},O(n)),{default:k(()=>[N(e.$slots,`default`)]),_:3},16,[`class`]))}}),wP=j({__name:`TabsList`,props:{loop:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]},variant:{default:`default`}},setup(e){let t=e,n=Fw(t,`class`,`variant`);return(r,i)=>(F(),L(O(KC),H({"data-slot":`tabs-list`,"data-variant":e.variant},O(n),{class:O(K)(O(EP)({variant:e.variant}),t.class)}),{default:k(()=>[N(r.$slots,`default`)]),_:3},16,[`data-variant`,`class`]))}}),TP=j({__name:`TabsTrigger`,props:{value:{},disabled:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=bg(Fw(t,`class`));return(e,r)=>(F(),L(O(qC),H({"data-slot":`tabs-trigger`,class:O(K)(`gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*=size-])]:size-4 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabledLine truncated
|
||||
@@ -20,6 +20,11 @@ import { api } from "@/lib/api";
|
||||
import { delivered } from "@/lib/delivered";
|
||||
import { useIdentitiesStore } from "@/stores/identities";
|
||||
import type { WorkflowDefinition, WorkflowStats } from "@/workflows/workflow-rows";
|
||||
import {
|
||||
declaredInputs,
|
||||
inputValues,
|
||||
missingRequiredInputs,
|
||||
} from "@/workflows/work-request";
|
||||
|
||||
/** Starting work enters Archie's normal admitted task queue, not a side door. */
|
||||
const emit = defineEmits<{ started: [taskId: number]; cancel: [] }>();
|
||||
@@ -52,18 +57,27 @@ const workflow = ref("");
|
||||
const title = ref("");
|
||||
const instructions = ref("");
|
||||
const identity = ref("");
|
||||
// One text field per declared input, by input name: the chosen workflow's
|
||||
// declaration decides what is rendered and what the request carries.
|
||||
const inputText = ref<Record<string, string>>({});
|
||||
watchEffect(() => {
|
||||
if (!workflow.value && definitions.value[0]) workflow.value = definitions.value[0].id;
|
||||
if (!identity.value && actors.value[0]) identity.value = actors.value[0].id;
|
||||
});
|
||||
|
||||
const selected = computed(() => definitions.value.find((d) => d.id === workflow.value));
|
||||
const declared = computed(() => declaredInputs(selected.value));
|
||||
const missing = computed(() => missingRequiredInputs(declared.value, inputText.value));
|
||||
|
||||
const statFor = (id: string) => stats.value.find((s) => s.workflow === id);
|
||||
const identityName = computed(() => actors.value.find((a) => a.id === identity.value)?.display_name ?? "nobody");
|
||||
|
||||
const submitting = ref(false);
|
||||
const error = ref("");
|
||||
const ready = computed(
|
||||
() => !!(repository.value.trim() && workflow.value && title.value.trim() && instructions.value.trim() && identity.value),
|
||||
() =>
|
||||
!!(repository.value.trim() && workflow.value && title.value.trim() && instructions.value.trim() && identity.value) &&
|
||||
missing.value.length === 0,
|
||||
);
|
||||
async function submit() {
|
||||
if (!ready.value || submitting.value) return;
|
||||
@@ -76,6 +90,7 @@ async function submit() {
|
||||
workflow: workflow.value,
|
||||
title: title.value.trim(),
|
||||
instructions: instructions.value,
|
||||
inputs: inputValues(declared.value, inputText.value),
|
||||
});
|
||||
emit("started", result.task_id);
|
||||
} catch (err) {
|
||||
@@ -128,6 +143,27 @@ async function submit() {
|
||||
<p v-if="!definitions.length && !loadError" class="text-xs text-fg-subtle">No enabled workflows.</p>
|
||||
</div>
|
||||
|
||||
<!-- One field per input the chosen workflow declares: pr-review cannot run
|
||||
without its pr_number, and the server refuses a request that does not
|
||||
set what the workflow declares. The declared type is the hint, so the
|
||||
value is typed the way the workflow reads it. -->
|
||||
<div v-if="declared.length" class="grid gap-3">
|
||||
<div v-for="field in declared" :key="field.name" class="grid gap-1.5">
|
||||
<label :for="`${uid}-input-${field.name}`" class="text-[13px] font-medium">
|
||||
<span class="font-mono">{{ field.name }}</span>
|
||||
<span v-if="field.required" class="text-fg-subtle"> · required</span>
|
||||
</label>
|
||||
<Input
|
||||
:id="`${uid}-input-${field.name}`"
|
||||
v-model="inputText[field.name]"
|
||||
:type="field.type === 'number' ? 'number' : 'text'"
|
||||
class="font-mono"
|
||||
:required="field.required"
|
||||
/>
|
||||
<p class="text-xs text-fg-subtle">{{ field.type }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-1.5">
|
||||
<label :for="`${uid}-title`" class="text-[13px] font-medium">Title</label>
|
||||
<Input :id="`${uid}-title`" v-model="title" required />
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* The work-request form's input vocabulary: what the chosen workflow declares,
|
||||
* and how one field's text becomes the typed value the daemon checks.
|
||||
*
|
||||
* A workflow is startable only by naming what it declares. pr-review requires
|
||||
* pr_number, so a request that does not set it is refused by the handler
|
||||
* (archie-core-06nq) rather than admitted and then parked at dispatch. The
|
||||
* declaration comes from the definitions endpoint, so a workflow that starts
|
||||
* declaring inputs needs no change here.
|
||||
*/
|
||||
|
||||
import type { WorkflowDefinition } from "./workflow-rows";
|
||||
|
||||
/** One input a workflow declares, as the form renders it. */
|
||||
export interface DeclaredInput {
|
||||
name: string;
|
||||
/** The declared type: string, number, bool, object, array or any. */
|
||||
type: string;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* declaredInputs lists the inputs a workflow declares, by name. Sorted, so the
|
||||
* fields keep their places while the operator types and across re-renders.
|
||||
*/
|
||||
export function declaredInputs(
|
||||
definition?: WorkflowDefinition,
|
||||
): DeclaredInput[] {
|
||||
return Object.entries(definition?.inputs ?? {})
|
||||
.map(([name, spec]) => ({
|
||||
name,
|
||||
type: spec.type,
|
||||
required: spec.required === true,
|
||||
}))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
/**
|
||||
* missingRequiredInputs names the declared inputs that are required and still
|
||||
* empty, so the form disables Start instead of earning the server's refusal.
|
||||
*/
|
||||
export function missingRequiredInputs(
|
||||
declared: DeclaredInput[],
|
||||
text: Record<string, string>,
|
||||
): string[] {
|
||||
return declared
|
||||
.filter((input) => input.required && !(text[input.name] ?? "").trim())
|
||||
.map((input) => input.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* inputValue is the typed value one field's text stands for. Text that does not
|
||||
* read as the declared type travels as it was typed, so the server's check
|
||||
* names the mismatch rather than this guessing at a value nobody typed.
|
||||
*/
|
||||
export function inputValue(text: string, type: string): unknown {
|
||||
switch (type) {
|
||||
case "number": {
|
||||
const trimmed = text.trim();
|
||||
return trimmed !== "" && !Number.isNaN(Number(trimmed))
|
||||
? Number(trimmed)
|
||||
: text;
|
||||
}
|
||||
case "bool":
|
||||
return text === "true" ? true : text === "false" ? false : text;
|
||||
case "string":
|
||||
return text;
|
||||
default:
|
||||
// object, array and any: the field's text is JSON.
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* inputValues builds the `inputs` object the request carries: the declared
|
||||
* inputs the operator filled in. An input left empty is absent rather than an
|
||||
* empty string, so an optional input is simply unset and a required one is
|
||||
* caught by missingRequiredInputs before the request is sent.
|
||||
*/
|
||||
export function inputValues(
|
||||
declared: DeclaredInput[],
|
||||
text: Record<string, string>,
|
||||
): Record<string, unknown> {
|
||||
const inputs: Record<string, unknown> = {};
|
||||
for (const input of declared) {
|
||||
const value = text[input.name];
|
||||
if (value === undefined || value === "") continue;
|
||||
inputs[input.name] = inputValue(value, input.type);
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
@@ -26,6 +26,11 @@ export interface WorkflowDefinition {
|
||||
name?: string;
|
||||
origin?: string;
|
||||
enabled?: boolean;
|
||||
/** The inputs the workflow declares, by name. A workflow that declares none
|
||||
* is started without any, which is every workflow but pr-review today. */
|
||||
inputs?: Record<string, { type: string; required?: boolean }>;
|
||||
/** none, optional or required; a workflow that declares none needs a repository. */
|
||||
repository?: string;
|
||||
}
|
||||
|
||||
/** One table row: a definition, its statistics, or both. */
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
declaredInputs,
|
||||
inputValues,
|
||||
missingRequiredInputs,
|
||||
type DeclaredInput,
|
||||
} from "../src/workflows/work-request.ts";
|
||||
|
||||
// The shape GET /api/workflows reports for a definition, as far as the
|
||||
// work-request form reads it.
|
||||
const prReview = {
|
||||
id: "pr-review",
|
||||
name: "pr-review",
|
||||
enabled: true,
|
||||
inputs: {
|
||||
pr_number: { type: "number", required: true },
|
||||
depth: { type: "string" },
|
||||
},
|
||||
};
|
||||
|
||||
test("the form renders one field per declared input, in a stable order", () => {
|
||||
assert.deepEqual(declaredInputs(prReview), [
|
||||
{ name: "depth", type: "string", required: false },
|
||||
{ name: "pr_number", type: "number", required: true },
|
||||
]);
|
||||
});
|
||||
|
||||
test("a workflow that declares no inputs renders no fields", () => {
|
||||
assert.deepEqual(declaredInputs({ id: "implement" }), []);
|
||||
assert.deepEqual(declaredInputs(undefined), []);
|
||||
});
|
||||
|
||||
test("a declared number is sent as a number, not as the typed text", () => {
|
||||
assert.deepEqual(
|
||||
inputValues(declaredInputs(prReview), { pr_number: "77", depth: "deep" }),
|
||||
{ pr_number: 77, depth: "deep" },
|
||||
);
|
||||
});
|
||||
|
||||
test("an input left empty is absent rather than an empty string", () => {
|
||||
assert.deepEqual(inputValues(declaredInputs(prReview), { pr_number: "77" }), {
|
||||
pr_number: 77,
|
||||
});
|
||||
});
|
||||
|
||||
test("text that is not the declared type is sent as typed, for the server to name", () => {
|
||||
assert.deepEqual(inputValues(declaredInputs(prReview), { pr_number: "seventy-seven" }), {
|
||||
pr_number: "seventy-seven",
|
||||
});
|
||||
});
|
||||
|
||||
test("required inputs that are still empty are named", () => {
|
||||
const declared = declaredInputs(prReview);
|
||||
assert.deepEqual(missingRequiredInputs(declared, {}), ["pr_number"]);
|
||||
assert.deepEqual(missingRequiredInputs(declared, { pr_number: " " }), ["pr_number"]);
|
||||
assert.deepEqual(missingRequiredInputs(declared, { pr_number: "77" }), []);
|
||||
});
|
||||
|
||||
test("an optional input does not hold the form back", () => {
|
||||
const declared: DeclaredInput[] = declaredInputs(prReview);
|
||||
assert.deepEqual(missingRequiredInputs(declared, { pr_number: "1" }), []);
|
||||
});
|
||||
Reference in new issue
Block a user