Watched-repos needs no bespoke webhook-parsing code: the existing generic capture+binding system (internal/infrastructure/captureintake, internal/domain/binding.Binding) already turns any inbound webhook into a task on any workflow, via a dashboard-editable matcher, CEL filter and payload-to-input mapping. pr-review just needed to become a binding-targetable workflow. - Workflow gains an Interface field (task.WorkflowInterface) so a Go-literal builtin can declare inputs the same way a YAML-defined one does; ShippedDefinitions emits an inputs: block only when non-empty, so every other builtin's generated YAML is byte-identical to before. - PRReview() declares pr_number as a required number input. - Task gains EffectivePRNumber(): PRNumber when a producer set it directly (archie's own PRs), else the pr_number input a binding assigned generically through Task.Inputs. Handles json.Number (the store's round-trip encoding), float64 and int. - The daemon resolves it once in acquireTaskContainer, before the task brief is written and before the pr-review prefetch runs, so everything downstream agrees. stagePRIntake falls back to the same resolution for any dispatch path that bypasses container acquisition, and fails loudly if neither PRNumber nor the input is set. An operator wires up watched-repos entirely through the dashboard: a Binding matching the webhook's source, a CEL filter for pull_request events, workflow: pr-review, and an Inputs mapping pr_number from the payload. No code change needed for a new repo or a new source. Operator/chat trigger remains open, left as a precise continuation: EnqueueChatTask is part of the State Store's protobuf-generated gRPC contract (proto/state/v1/state.proto), not just a Go interface -- extending it for a generic inputs parameter needs a proto field addition + regen, a new SQL query (StampTaskBinding cannot be reused, since it unconditionally stamps binding_id/version, which a plain chat task must never carry), and updates across staterpc's client/server and ~20 call sites. Real plumbing, not a quick tool rewrite -- scoped correctly as its own pass rather than rushed here.
30 lines
1.0 KiB
Go
30 lines
1.0 KiB
Go
package task
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestEffectivePRNumber(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
task Task
|
|
want int
|
|
}{
|
|
{"PRNumber set directly wins", Task{PRNumber: 7, Inputs: map[string]any{"pr_number": json.Number("99")}}, 7},
|
|
{"json.Number from a store round trip", Task{Inputs: map[string]any{"pr_number": json.Number("42")}}, 42},
|
|
{"float64 from a hand-built map", Task{Inputs: map[string]any{"pr_number": float64(13)}}, 13},
|
|
{"int from a hand-built map", Task{Inputs: map[string]any{"pr_number": 5}}, 5},
|
|
{"missing input", Task{Inputs: map[string]any{}}, 0},
|
|
{"nil Inputs", Task{}, 0},
|
|
{"wrong type", Task{Inputs: map[string]any{"pr_number": "not a number"}}, 0},
|
|
{"malformed json.Number", Task{Inputs: map[string]any{"pr_number": json.Number("not-a-number")}}, 0},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
if got := test.task.EffectivePRNumber(); got != test.want {
|
|
t.Errorf("EffectivePRNumber() = %d, want %d", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|