The dashboard could not name a workflow's declared inputs, so POST /api/work-requests admitted a pr-review task with no pr_number, which then failed at the workflow's intake stage (archie-core-06nq). The handler now takes `inputs`, checks it against the workflow's declared interface before admitting the task, and carries it through SpawnRequest.Inputs -> EnqueueChatTaskRequest; the form renders one field per declared input, sends a declared number as a number, and keeps Start disabled while a required input is empty. Item 2 of the lane brief -- archie-core-afbk.12, review.precision_gate / review.approve_before_post in the dashboard Config tab -- is deliberately NOT in this commit. The surface it describes no longer exists in this tree; the supervisor's decision was to stop it and re-scope it as its own lane, and the facts it must start from belong in the branch's record: * The Config-tab components were deleted bybecb0b5e(2026-09-25, "the legacy config catalog stops advertising fields the control plane owns"): ConfigSections.vue, ConfigRow.vue, ConfigControl.vue, ConfigList.vue, ConfigNotices.vue, ConfigUnavailable.vue, config-field.ts and sections.ts all went, because no page used them. Descriptor entries in internal/webui/config_schema.go would therefore change nothing a person can see: the only consumer of GET /api/config is SystemModelsPage reading `catalog`; the per-field `schema` has no renderer. * The config write seams went earlier, in31622ec5(2026-09-21, "delete the runtime config overlay"): UpdateConfig, ResetConfig and UpdateRepoField are gone and internal/webui/server.go serves only GET /api/config. Configuration is written through the control plane. * No control-plane resource carries review settings. executionSettingsDocument (internal/app/controlplane/workflow_settings.go) and workflow.ExecutionSettings carry only the four budget fields, and runtimeConfigFrom never layers cfg.Review. That is exactly why the budget descriptors survive in the catalog and review.* cannot: budgets are saved through workflow-execution-settings, edited on the Task-execution page, so those entries match a real write path. * The brief's precedent name is wrong: TestToolSettingsProjectionCarriesEveryMCPServerField does not exist. The precedent is TestToolSettingsProjectionCarriesEveryMirroredField (internal/app/controlplane/runtime_config_test.go:349). Making review.* genuinely editable needs a carrying control-plane resource (extend workflow-execution-settings or add a review-settings kind), a layering step in internal/app/archied/control_plane.go, and the round-trip test that precedent sets -- an unsettled design decision spanning packages this lane does not own.
181 lines
7.5 KiB
Go
181 lines
7.5 KiB
Go
package webui
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
)
|
|
|
|
func workflowControlPlane(t *testing.T, definitions workflow.WorkflowDefinitionCollection) *controlPlaneClientStub {
|
|
t.Helper()
|
|
value, err := json.Marshal(definitions)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return &controlPlaneClientStub{query: &controlpb.Resource{Kind: "workflow-definitions", Version: 1, ValueJson: value}}
|
|
}
|
|
|
|
type recordingWorkRequestCreator struct{ request gateway.SpawnRequest }
|
|
|
|
func (c *recordingWorkRequestCreator) CreateTask(_ context.Context, request gateway.SpawnRequest) (int64, error) {
|
|
c.request = request
|
|
return 42, nil
|
|
}
|
|
|
|
func TestWorkflowsIncludeInstalledZeroRunDefinitions(t *testing.T) {
|
|
srv := newTestServer(t)
|
|
srv.ControlPlane = workflowControlPlane(t, workflow.WorkflowDefinitionCollection{Definitions: []workflow.WorkflowDefinitionEntry{{ID: "custom", YAML: "id: custom\nsteps:\n - type: implement.prepare\n - type: implement.plan\n"}}})
|
|
|
|
w := httptest.NewRecorder()
|
|
srv.Handler().ServeHTTP(w, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/workflows", nil))
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
|
}
|
|
var response struct {
|
|
Definitions []workflow.Definition `json:"definitions"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(response.Definitions) != 1 || response.Definitions[0].ID != "custom" || response.Definitions[0].Origin != "database" {
|
|
t.Fatalf("definitions = %#v", response.Definitions)
|
|
}
|
|
}
|
|
|
|
// 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."}`
|
|
w := postWorkRequest(t, srv, body)
|
|
|
|
if w.Code != http.StatusCreated {
|
|
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
|
}
|
|
if got := creator.request; got.Identity != "archie" || got.Repo != "acme/widget" || got.Workflow != "implement" || got.Title != "Fix login" || got.Body != "Reproduce and fix it." {
|
|
t.Fatalf("request = %#v", got)
|
|
}
|
|
}
|
|
|
|
func TestWorkRequestRejectsDisabledWorkflow(t *testing.T) {
|
|
srv := newTestServer(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"}}})
|
|
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)
|
|
}
|
|
if got := creator.request; got.Title != "" || got.Body != "" || got.Repo != "" || got.Workflow != "" || got.Identity != "" || len(got.Inputs) != 0 {
|
|
t.Fatalf("creator called with %#v", got)
|
|
}
|
|
}
|