Files
archie/internal/domain/binding/inputs_test.go
T
sam d320a1a01a feat(eda): workflow inputs, optional repository and agent profiles
Workflow definitions declare inputs, repository (none, optional or
required; default required) and profile. A binding assigns each input
from a mapped parameter or a constant and may take its repository from a
parameter, which must name a configured repo; both are checked when the
binding is saved and again at dispatch. Inputs travel as structured task
data (tasks.inputs, the task brief, and a JSON block in the agent's
mission), never as body text.

A task with no repository runs in a per-task scratch workspace with no
clone and no publication grant. The agent.run step runs one mission
without a repository and finishes the task in the new completed status.

Agent profiles live under [containers.profiles.<name>]: an image and an
allowlist over the tools archie adds (MCP, scripts, plugins).
[containers].image is the default profile; an unconfigured profile parks
the task. The workflow is now pinned before the container starts so the
profile can choose its image.

Also stop two archied tests writing embedded NATS state into the package
directory, refuse an empty state_dir for embedded NATS, and drop the NATS
store files an earlier lane commit tracked.
2026-09-24 20:29:33 +10:00

102 lines
4.3 KiB
Go

package binding
import (
"encoding/json"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/domain/mapping"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
)
func TestCheckWorkflow(t *testing.T) {
fields := []mapping.Field{
{Name: "ip", Type: mapping.TypeString},
{Name: "count", Type: mapping.TypeNumber},
{Name: "repo", Type: mapping.TypeString},
{Name: "blob", Type: mapping.TypeAny},
}
investigate := task.WorkflowInterface{
Repository: task.RepositoryNone,
Inputs: map[string]task.InputSpec{
"src_ip": {Type: "string", Required: true},
"severity": {Type: "number"},
},
}
review := task.WorkflowInterface{Repository: task.RepositoryRequired}
tests := []struct {
name string
b Binding
w task.WorkflowInterface
wantErr string
}{
{name: "param and constant", w: investigate, b: Binding{Inputs: map[string]InputSource{
"src_ip": {Param: "ip"}, "severity": {Value: 3.0},
}}},
{name: "any parameter feeds a typed input", w: investigate, b: Binding{Inputs: map[string]InputSource{"src_ip": {Param: "blob"}}}},
{name: "required input unassigned", w: investigate, b: Binding{}, wantErr: `requires input "src_ip"`},
{name: "undeclared input", w: investigate, b: Binding{Inputs: map[string]InputSource{
"src_ip": {Param: "ip"}, "port": {Value: 22.0},
}}, wantErr: `"port" is not declared`},
{name: "unknown parameter", w: investigate, b: Binding{Inputs: map[string]InputSource{"src_ip": {Param: "addr"}}}, wantErr: `parameter "addr", which the mapping does not have`},
{name: "parameter of the wrong type", w: investigate, b: Binding{Inputs: map[string]InputSource{"src_ip": {Param: "count"}}}, wantErr: `"src_ip" is string, but parameter "count" is number`},
{name: "constant of the wrong type", w: investigate, b: Binding{Inputs: map[string]InputSource{"src_ip": {Value: 4.0}}}, wantErr: "its constant is number"},
{name: "no-repository workflow with a pin", w: investigate, b: Binding{Owner: "acme", Repo: "api", Inputs: map[string]InputSource{"src_ip": {Param: "ip"}}}, wantErr: "runs without a repository"},
{name: "repository from a string parameter", w: review, b: Binding{RepoParam: "repo"}},
{name: "repository parameter missing", w: review, b: Binding{RepoParam: "full_name"}, wantErr: `"full_name" is not in the mapping`},
{name: "repository parameter not a string", w: review, b: Binding{RepoParam: "count"}, wantErr: "is number, want string"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.b.CheckWorkflow(tt.w, fields)
if tt.wantErr == "" {
if err != nil {
t.Fatalf("CheckWorkflow() = %v", err)
}
return
}
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
t.Fatalf("CheckWorkflow() = %v, want containing %q", err, tt.wantErr)
}
})
}
}
func TestValidateInputsAndRepository(t *testing.T) {
base := Binding{Name: "n", Matcher: Matcher{Source: "s"}, MappingID: "m", Workflow: "w"}
both := base
both.Inputs = map[string]InputSource{"a": {Param: "p", Value: "x"}}
neither := base
neither.Inputs = map[string]InputSource{"a": {}}
pinned := base
pinned.Owner, pinned.Repo, pinned.RepoParam = "acme", "api", "repo"
for name, b := range map[string]Binding{"both": both, "neither": neither, "pin and parameter": pinned} {
if err := b.Validate(); err == nil {
t.Errorf("%s: Validate() = nil, want an error", name)
}
}
}
func TestResolveInputsAndRepository(t *testing.T) {
b := Binding{RepoParam: "full", Inputs: map[string]InputSource{
"src_ip": {Param: "ip"}, "severity": {Value: "high"}, "missing": {Param: "absent"},
}}
values := map[string]any{"ip": "10.0.0.1", "full": "acme/api", "n": json.Number("1")}
got := b.ResolveInputs(values)
if got["src_ip"] != "10.0.0.1" || got["severity"] != "high" {
t.Errorf("ResolveInputs() = %v", got)
}
if _, ok := got["missing"]; ok {
t.Error("an unresolved parameter was passed as an input")
}
owner, repo, ok, err := b.RepositoryFrom(values)
if err != nil || !ok || owner != "acme" || repo != "api" {
t.Errorf("RepositoryFrom() = %q, %q, %v, %v", owner, repo, ok, err)
}
for _, bad := range []string{"acme", "acme/", "/api", "a/b/c"} {
if _, _, _, err := b.RepositoryFrom(map[string]any{"full": bad}); err == nil {
t.Errorf("RepositoryFrom(%q) accepted a value that is not owner/name", bad)
}
}
}