feat(pr-review): operator/chat trigger queues a pr-review task
review_pr self-omitted since d73e0748 deleted the synchronous reviewer it
called. It is rebuilt on the task enqueue path everything else uses: the
tool resolves the identity's configured repo, then queues a pr-review task
naming the pull request through the workflow's declared pr_number input,
which is the same generic input mechanism a watched-repos binding uses.
That input has to reach the store with the task, so
EnqueueChatTaskRequest gains inputs_json and the tasks insert writes the
inputs column directly. StampTaskBinding no longer writes it: the insert is
now the column's only writer, and a chat task must not acquire binding
provenance just to carry an input.
ChatPRReviewer, its result shape and the reviewer wiring are deleted with
the path they served.
This commit is contained in:
39 files changed
+227
-192
No files matched your search
@@ -355,7 +355,7 @@ func TestStateStoreRealProcessSmoke(t *testing.T) {
|
||||
// Combined task/event/capture view: a task, an event on that task, and an
|
||||
// unrelated capture written through one consumer, read back across all
|
||||
// three surfaces in a single pass (the dashboard/observability read path).
|
||||
task, err := cl.EnqueueChatTask(ctx, "acme", "widget", "verify state store", "body", "implement", "")
|
||||
task, err := cl.EnqueueChatTask(ctx, "acme", "widget", "verify state store", "body", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("EnqueueChatTask = %+v, %v", task, err)
|
||||
}
|
||||
@@ -485,7 +485,7 @@ func TestStateStoreRealProcessRestartRecovery(t *testing.T) {
|
||||
|
||||
first := startStateStoreProcess(t, bin, cfg)
|
||||
s1 := dial(t, first.addr)
|
||||
task, err := s1.EnqueueChatTask(t.Context(), "acme", "widget", "survive restart", "body", "implement", "")
|
||||
task, err := s1.EnqueueChatTask(t.Context(), "acme", "widget", "survive restart", "body", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("first EnqueueChatTask = %+v, %v", task, err)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func recoveryFixture(t *testing.T) (string, *pgstore.TaskDB) {
|
||||
// seedTask writes one task so the database holds more than its settings.
|
||||
func seedTask(t *testing.T, st *pgstore.TaskDB, title string) {
|
||||
t.Helper()
|
||||
if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", ""); err != nil {
|
||||
if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", "", nil); err != nil {
|
||||
t.Fatalf("seed task %q: %v", title, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestExecuteTaskRequestStartsWorkflowCallCallee(t *testing.T) {
|
||||
const callerYAML = "id: caller\nrepository: none\ninputs:\n src_ip: {type: string}\nsteps:\n - type: workflow.call\n settings:\n workflow: callee\n inputs: {src_ip: \"inputs.src_ip\"}\n wait: false\n - type: agent.run\n settings:\n mission: report\n"
|
||||
// A real caller row, claimed and running, so the store's enqueue reads
|
||||
// the same row shape production does.
|
||||
task, err := st.EnqueueChatTask(ctx, "", "", "workflow.call integration", "", "caller", "")
|
||||
task, err := st.EnqueueChatTask(ctx, "", "", "workflow.call integration", "", "caller", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("seed caller task: %v", err)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ type chatSetup struct {
|
||||
ChatTaskLister gateway.ChatTaskLister
|
||||
ChatTaskLogs gateway.ChatTaskLogReader
|
||||
ChatTaskActor gateway.ChatTaskActor
|
||||
ChatPRReviewer gateway.ChatPRReviewer
|
||||
DefaultChatIdentity string
|
||||
// Bus carries primary-input events (archie-core-035): a completed
|
||||
// chat turn is published here so input-driven curators can wake. Nil
|
||||
@@ -182,7 +181,6 @@ func newChatTurnRunner(
|
||||
TaskLogs: s.ChatTaskLogs,
|
||||
TaskActor: s.ChatTaskActor,
|
||||
TaskIdentity: s.DefaultChatIdentity,
|
||||
PRReviewer: s.ChatPRReviewer,
|
||||
Bus: s.Bus,
|
||||
BotUser: cfg.BotUser,
|
||||
Channel: channel,
|
||||
|
||||
@@ -126,16 +126,9 @@ func (b *boot) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskActor
|
||||
setup := chatSetup{
|
||||
Cfg: config.NewHolder(cfg), LLM: b.chatLLM, ChatModels: b.chatModels, ToolReg: b.toolReg,
|
||||
Personas: b.personas, ChatTasks: b.chatTasks,
|
||||
ChatTaskLister: chatTaskListerAdapter{tasks: b.stateStore.Tasks},
|
||||
ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.taskLogs},
|
||||
// ChatPRReviewer is nil for now: the synchronous operator-review
|
||||
// implementation (prReviewer) was removed with the adversarial
|
||||
// self-review system it depended on (archie-core-afbk.7). The
|
||||
// review_pr chat tool self-omits when its reviewer is nil, so the
|
||||
// dashboard/chat simply stops advertising the capability until the
|
||||
// operator trigger is rebuilt to enqueue an async pr-review task
|
||||
// instead (tracked in that bead's continuation).
|
||||
ChatTaskActor: actor, ChatPRReviewer: nil,
|
||||
ChatTaskLister: chatTaskListerAdapter{tasks: b.stateStore.Tasks},
|
||||
ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.taskLogs},
|
||||
ChatTaskActor: actor,
|
||||
DefaultChatIdentity: b.defaultChatIdentity,
|
||||
Bus: b.bus, Log: b.log,
|
||||
MemoryEngine: b.memoryStore(),
|
||||
|
||||
@@ -539,14 +539,16 @@ type chatTaskWriterAdapter struct {
|
||||
enqueue func(
|
||||
ctx context.Context,
|
||||
owner, repo, title, body, workflow, identity string,
|
||||
inputs map[string]any,
|
||||
) (*workflow.Task, error)
|
||||
}
|
||||
|
||||
func (a chatTaskWriterAdapter) EnqueueChatTask(
|
||||
ctx context.Context,
|
||||
owner, repo, title, body, workflow, identity string,
|
||||
inputs map[string]any,
|
||||
) (int64, error) {
|
||||
task, err := a.enqueue(ctx, owner, repo, title, body, workflow, identity)
|
||||
task, err := a.enqueue(ctx, owner, repo, title, body, workflow, identity, inputs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ func TestManualRequeueTaskRejectsOtherStatuses(t *testing.T) {
|
||||
func TestChatTaskListerAdapterReadsSQLiteIdentity(t *testing.T) {
|
||||
st := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
want, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "identity task", "", "tdd", "reviewer")
|
||||
want, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "identity task", "", "tdd", "reviewer", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -610,13 +610,14 @@ func TestChatTaskWriterAdapter(t *testing.T) {
|
||||
enqueue: func(
|
||||
context.Context,
|
||||
string, string, string, string, string, string,
|
||||
map[string]any,
|
||||
) (*workflow.Task, error) {
|
||||
return tt.result, tt.err
|
||||
},
|
||||
}
|
||||
id, err := adapter.EnqueueChatTask(
|
||||
context.Background(),
|
||||
"owner", "repo", "title", "body", "workflow", "identity",
|
||||
"owner", "repo", "title", "body", "workflow", "identity", nil,
|
||||
)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("EnqueueChatTask() error = %v, wantErr %t", err, tt.wantErr)
|
||||
|
||||
@@ -175,7 +175,7 @@ func TestStateStoreDataSurvivesRestart(t *testing.T) {
|
||||
if err := first.openStateStore(t.Context()); err != nil {
|
||||
t.Fatalf("first openStateStore: %v", err)
|
||||
}
|
||||
task, err := first.st.EnqueueChatTask(t.Context(), "acme", "widget", "restart check", "body", "implement", "")
|
||||
task, err := first.st.EnqueueChatTask(t.Context(), "acme", "widget", "restart check", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("EnqueueChatTask: %v", err)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestChatTaskActorAdapterCrossIdentityRefused(t *testing.T) {
|
||||
st := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "parked job", "", "", "identity-owner")
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "parked job", "", "", "identity-owner", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func TestChatTaskActorAdapterRefusesDisallowedStateAction(t *testing.T) {
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "test task", "", "", "archie")
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "test task", "", "", "archie", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -251,7 +251,7 @@ func TestChatTaskActorAdapterAppliesActionsToStore(t *testing.T) {
|
||||
|
||||
adapter := newChatTaskActorForTest(t, st, config.Config{MaxRetries: 3})
|
||||
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "actionable task", "", "", "archie")
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "actionable task", "", "", "archie", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestDashboardAndChatAgreeOnTerminalStates(t *testing.T) {
|
||||
st := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "decide on me", "", "", "reviewer")
|
||||
task, err := st.EnqueueChatTask(ctx, "acme", "widget", "decide on me", "", "", "reviewer", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func composeUIProcess(t *testing.T) (*webui.Server, int64) {
|
||||
}
|
||||
t.Cleanup(closeClient)
|
||||
|
||||
task, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "a task", "body", "implement", "")
|
||||
task, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "a task", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("seed task: %v", err)
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func serveGRPC(t *testing.T, register func(grpc.ServiceRegistrar)) (target strin
|
||||
func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
||||
st := pgstore.Open(t)
|
||||
defer st.Close()
|
||||
if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", ""); err != nil {
|
||||
if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", "", nil); err != nil {
|
||||
t.Fatalf("seed task: %v", err)
|
||||
}
|
||||
// Claimed (not just enqueued): StartStep guards on the execution's own
|
||||
|
||||
@@ -156,7 +156,7 @@ func composeUIProcessWithLog(t *testing.T) (*webui.Server, int64, int) {
|
||||
st := pgstore.Open(t)
|
||||
t.Cleanup(func() { _ = st.Close() })
|
||||
|
||||
task, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "a task", "body", "implement", "")
|
||||
task, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "a task", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("seed task: %v", err)
|
||||
}
|
||||
|
||||
@@ -2957,13 +2957,17 @@ func (x *EnqueueIssueResponse) GetInserted() bool {
|
||||
}
|
||||
|
||||
type EnqueueChatTaskRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
|
||||
Repo string `protobuf:"bytes,2,opt,name=repo,proto3" json:"repo,omitempty"`
|
||||
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
|
||||
Body string `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
|
||||
Workflow string `protobuf:"bytes,5,opt,name=workflow,proto3" json:"workflow,omitempty"`
|
||||
Identity string `protobuf:"bytes,6,opt,name=identity,proto3" json:"identity,omitempty"`
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
|
||||
Repo string `protobuf:"bytes,2,opt,name=repo,proto3" json:"repo,omitempty"`
|
||||
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
|
||||
Body string `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
|
||||
Workflow string `protobuf:"bytes,5,opt,name=workflow,proto3" json:"workflow,omitempty"`
|
||||
Identity string `protobuf:"bytes,6,opt,name=identity,proto3" json:"identity,omitempty"`
|
||||
// inputs_json assigns workflow inputs, a JSON object of the same form
|
||||
// EnqueueBindingTaskRequest carries. A chat task sets them at insert
|
||||
// time: it has no binding provenance to stamp afterwards.
|
||||
InputsJson string `protobuf:"bytes,7,opt,name=inputs_json,json=inputsJson,proto3" json:"inputs_json,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -3040,6 +3044,13 @@ func (x *EnqueueChatTaskRequest) GetIdentity() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *EnqueueChatTaskRequest) GetInputsJson() string {
|
||||
if x != nil {
|
||||
return x.InputsJson
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type EnqueueChatTaskResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Task *Task `protobuf:"bytes,1,opt,name=task,proto3" json:"task,omitempty"`
|
||||
@@ -11902,14 +11913,16 @@ const file_state_v1_state_proto_rawDesc = "" +
|
||||
"\x06labels\x18\x06 \x01(\tR\x06labels\x12\x1a\n" +
|
||||
"\bidentity\x18\a \x01(\tR\bidentity\"2\n" +
|
||||
"\x14EnqueueIssueResponse\x12\x1a\n" +
|
||||
"\binserted\x18\x01 \x01(\bR\binserted\"\xa4\x01\n" +
|
||||
"\binserted\x18\x01 \x01(\bR\binserted\"\xc5\x01\n" +
|
||||
"\x16EnqueueChatTaskRequest\x12\x14\n" +
|
||||
"\x05owner\x18\x01 \x01(\tR\x05owner\x12\x12\n" +
|
||||
"\x04repo\x18\x02 \x01(\tR\x04repo\x12\x14\n" +
|
||||
"\x05title\x18\x03 \x01(\tR\x05title\x12\x12\n" +
|
||||
"\x04body\x18\x04 \x01(\tR\x04body\x12\x1a\n" +
|
||||
"\bworkflow\x18\x05 \x01(\tR\bworkflow\x12\x1a\n" +
|
||||
"\bidentity\x18\x06 \x01(\tR\bidentity\"=\n" +
|
||||
"\bidentity\x18\x06 \x01(\tR\bidentity\x12\x1f\n" +
|
||||
"\vinputs_json\x18\a \x01(\tR\n" +
|
||||
"inputsJson\"=\n" +
|
||||
"\x17EnqueueChatTaskResponse\x12\"\n" +
|
||||
"\x04task\x18\x01 \x01(\v2\x0e.state.v1.TaskR\x04task\"\x12\n" +
|
||||
"\x10ClaimNextRequest\"M\n" +
|
||||
|
||||
@@ -1911,7 +1911,7 @@ func TestReconcilePRsSkipsChatTasks(t *testing.T) {
|
||||
d, s, fg := testDaemon(t, 3, 0)
|
||||
ctx := context.Background()
|
||||
|
||||
task, err := s.EnqueueChatTask(ctx, "acme", "widget", "chat task", "", "", "")
|
||||
task, err := s.EnqueueChatTask(ctx, "acme", "widget", "chat task", "", "", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func (s *workflowDefinitionsStub) WorkflowDefinitions(context.Context) (workflow
|
||||
func TestWorkflowDefinitionPinSurvivesActiveOverride(t *testing.T) {
|
||||
resources := pgstore.Open(t)
|
||||
defer resources.Close()
|
||||
task, err := resources.EnqueueChatTask(t.Context(), "acme", "widget", "custom", "", "custom", "operator")
|
||||
task, err := resources.EnqueueChatTask(t.Context(), "acme", "widget", "custom", "", "custom", "operator", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -52,10 +52,14 @@ type Inbound struct {
|
||||
// Workflow are optional -- empty means "the daemon's configured
|
||||
// default for this identity".
|
||||
type SpawnRequest struct {
|
||||
Title string
|
||||
Body string // operator instructions carried into the admitted task
|
||||
Repo string // "owner/name"; empty = identity's default repo
|
||||
Title string
|
||||
Body string // operator instructions carried into the admitted task
|
||||
Repo string // "owner/name"; empty = identity's default repo
|
||||
// Workflow may name a workflow whose interface declares inputs
|
||||
// (pr-review's pr_number, for instance). Inputs assigns them; a
|
||||
// workflow that declares none ignores it.
|
||||
Workflow string // empty = daemon's default workflow routing
|
||||
Inputs map[string]any
|
||||
Identity string // the identity spawning this task; propagated from Router.Identity
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ type TaskStore interface {
|
||||
// poll, chat spawn, drain loop) do not acquire a binding-specific shape.
|
||||
type TaskLifecycle interface {
|
||||
EnqueueIssue(ctx context.Context, owner, repo string, number int, title, body, labels, identity string) (bool, error)
|
||||
EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*task.Task, error)
|
||||
EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string, inputs map[string]any) (*task.Task, error)
|
||||
ClaimNext(ctx context.Context) (*task.Task, error)
|
||||
ClaimByIssue(ctx context.Context, owner, repo string, number int) (*task.Task, error)
|
||||
Transition(ctx context.Context, taskID int64, from, to, detail string) error
|
||||
|
||||
@@ -8,69 +8,33 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/tools"
|
||||
)
|
||||
|
||||
// PRReviewResult is the structured outcome of an operator-triggered PR
|
||||
// review, returned to the channel that requested it. It mirrors
|
||||
// workflow.ReviewReport without importing the domain package: the gateway
|
||||
// states what it needs and the daemon adapts between the two (the
|
||||
// ChatTaskActor pattern). Status is "completed", "not_run", or "skipped";
|
||||
// a zero-finding "completed" result is a review that ran and cleared, and
|
||||
// is structurally distinct from "not_run".
|
||||
type PRReviewResult struct {
|
||||
Repo string `json:"repo"`
|
||||
Number int `json:"number"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
// Reason explains why a not_run/skipped review did not execute.
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Findings []PRReviewFinding `json:"findings"`
|
||||
// ArtifactURL is the editor deep link for the published review artifact,
|
||||
// empty when artifact publishing is disabled or failed.
|
||||
ArtifactURL string `json:"artifact_url,omitempty"`
|
||||
}
|
||||
|
||||
// PRReviewFinding is one defect from an operator-triggered review.
|
||||
type PRReviewFinding struct {
|
||||
File string `json:"file"`
|
||||
Line int `json:"line"`
|
||||
Defect string `json:"defect"`
|
||||
FailureScenario string `json:"failure_scenario,omitempty"`
|
||||
Verdict string `json:"verdict"`
|
||||
Level string `json:"level"`
|
||||
Category string `json:"category,omitempty"`
|
||||
Blocking bool `json:"blocking"`
|
||||
}
|
||||
|
||||
// ChatPRReviewer is the surface review_pr needs. The gateway states what it
|
||||
// needs and the daemon supplies an adapter over the forge, worktree manager
|
||||
// and reviewer runtime, so this package keeps its independence from
|
||||
// internal/forge, internal/worktree and internal/domain/workflow.
|
||||
// ReviewTools builds the review_pr chat tool. A nil creator omits the tool
|
||||
// rather than registering one that always fails, so a daemon without a task
|
||||
// store advertises nothing.
|
||||
//
|
||||
// identity follows the ChatTaskActor convention: nil denotes an
|
||||
// authenticated dashboard operator who may review any configured
|
||||
// repository; a non-nil identity is a chat identity scoped to its own
|
||||
// configured repositories.
|
||||
type ChatPRReviewer interface {
|
||||
ReviewPR(ctx context.Context, identity *string, repo string, number int) (PRReviewResult, error)
|
||||
}
|
||||
|
||||
// ReviewTools builds the review_pr chat tool. A nil reviewer omits the tool
|
||||
// rather than registering one that always fails, so a daemon without
|
||||
// operator review support advertises nothing.
|
||||
func ReviewTools(reviewer ChatPRReviewer, identity string) []tools.ToolEntry {
|
||||
if reviewer == nil {
|
||||
// The tool queues a pr-review task; it does not review in the turn. The
|
||||
// pipeline needs a sandbox, a prefetched snapshot and minutes of model calls,
|
||||
// so the operator gets a task ID back and watches the task like any other
|
||||
// (docs/prds/pr-review-agent.md, "Triggers").
|
||||
func ReviewTools(creator TaskCreator, identity string) []tools.ToolEntry {
|
||||
if creator == nil {
|
||||
return nil
|
||||
}
|
||||
return []tools.ToolEntry{reviewPRTool(reviewer, identity)}
|
||||
return []tools.ToolEntry{reviewPRTool(creator, identity)}
|
||||
}
|
||||
|
||||
func reviewPRTool(reviewer ChatPRReviewer, identity string) tools.ToolEntry {
|
||||
// prReviewWorkflow is the workflow a queued operator review runs. Its
|
||||
// declared interface requires pr_number, so the tool that names it is also
|
||||
// the only chat path that can satisfy it.
|
||||
const prReviewWorkflow = "pr-review"
|
||||
|
||||
func reviewPRTool(creator TaskCreator, identity string) tools.ToolEntry {
|
||||
return tools.ToolEntry{
|
||||
Name: "review_pr",
|
||||
Toolset: "tasks",
|
||||
Description: "Run the adversarial reviewer against an existing pull request and return its structured findings. " +
|
||||
"Use it when the user asks to review a PR, re-check one after a push, or see what the reviewer found. " +
|
||||
"Only a confirmed error-level finding blocks; a clean result reports zero findings explicitly.",
|
||||
Description: "Queue a review of an existing pull request. Use it when the user asks to review a PR, " +
|
||||
"re-check one after a push, or see what the reviewer found. The review runs as a task in its own " +
|
||||
"sandbox and posts its findings to the pull request; this returns the task ID immediately.",
|
||||
Classification: tools.ClassMutating,
|
||||
Schema: tools.JSONSchema{
|
||||
"type": "object",
|
||||
@@ -95,11 +59,26 @@ func reviewPRTool(reviewer ChatPRReviewer, identity string) tools.ToolEntry {
|
||||
if !ok || number <= 0 {
|
||||
return nil, fmt.Errorf("review_pr: pr_number must be a positive integer")
|
||||
}
|
||||
result, err := reviewer.ReviewPR(ctx, &identity, repo, int(number))
|
||||
id, err := creator.CreateTask(ctx, SpawnRequest{
|
||||
Title: fmt.Sprintf("review %s#%d", repo, number),
|
||||
Body: fmt.Sprintf("Operator-requested review of pull request %s#%d.", repo, number),
|
||||
Repo: repo,
|
||||
Workflow: prReviewWorkflow,
|
||||
// int, not int64: task.Task.EffectivePRNumber reads the
|
||||
// input as json.Number, float64 or int, and an int64 would
|
||||
// resolve to 0 for a task that names a real PR.
|
||||
Inputs: map[string]any{"pr_number": int(number)},
|
||||
// The bound identity, never input["identity"]: CreateTask
|
||||
// enforces the repository allow-list for it.
|
||||
Identity: identity,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("review_pr: %w", err)
|
||||
}
|
||||
return result, nil
|
||||
return TaskSpawnResult{
|
||||
ID: id,
|
||||
Message: fmt.Sprintf("queued pr-review task %d for %s#%d", id, repo, number),
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -6,29 +6,14 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type fakePRReviewer struct {
|
||||
gotIdentity *string
|
||||
gotRepo string
|
||||
gotNumber int
|
||||
result PRReviewResult
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakePRReviewer) ReviewPR(_ context.Context, identity *string, repo string, number int) (PRReviewResult, error) {
|
||||
f.gotIdentity = identity
|
||||
f.gotRepo = repo
|
||||
f.gotNumber = number
|
||||
return f.result, f.err
|
||||
}
|
||||
|
||||
func TestReviewToolOmittedWhenReviewerNil(t *testing.T) {
|
||||
func TestReviewToolOmittedWhenCreatorNil(t *testing.T) {
|
||||
if entries := ReviewTools(nil, "archie"); len(entries) != 0 {
|
||||
t.Fatalf("ReviewTools(nil) = %d entries, want 0 -- a tool that cannot run must not be advertised", len(entries))
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewToolAppearsWhenReviewerNonNil(t *testing.T) {
|
||||
entries := ReviewTools(&fakePRReviewer{}, "archie")
|
||||
func TestReviewToolAppearsWhenCreatorNonNil(t *testing.T) {
|
||||
entries := ReviewTools(&fakeCreator{}, "archie")
|
||||
if len(entries) != 1 {
|
||||
t.Fatalf("ReviewTools() = %d entries, want 1", len(entries))
|
||||
}
|
||||
@@ -37,14 +22,9 @@ func TestReviewToolAppearsWhenReviewerNonNil(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewPRToolBindsIdentityAndReturnsFindings(t *testing.T) {
|
||||
reviewer := &fakePRReviewer{
|
||||
result: PRReviewResult{
|
||||
Repo: "acme/widget", Number: 7, Model: "openai/gpt-5", Status: "completed",
|
||||
Findings: []PRReviewFinding{{File: "a.go", Line: 3, Defect: "nil deref", FailureScenario: "x", Verdict: "confirmed", Level: "error", Category: "nil-risk", Blocking: true}},
|
||||
},
|
||||
}
|
||||
entry := toolNamed(t, ReviewTools(reviewer, "archie"), "review_pr")
|
||||
func TestReviewPRToolQueuesReviewTask(t *testing.T) {
|
||||
creator := &fakeCreator{id: 42}
|
||||
entry := toolNamed(t, ReviewTools(creator, "archie"), "review_pr")
|
||||
|
||||
out, err := entry.Handler(context.Background(), map[string]any{
|
||||
"repo": "acme/widget", "pr_number": float64(7), "identity": "someone-else",
|
||||
@@ -53,27 +33,37 @@ func TestReviewPRToolBindsIdentityAndReturnsFindings(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got := creator.got
|
||||
if got.Workflow != "pr-review" {
|
||||
t.Errorf("workflow = %q, want pr-review -- the operator trigger runs the pipeline, it does not review in the turn", got.Workflow)
|
||||
}
|
||||
if got.Repo != "acme/widget" {
|
||||
t.Errorf("repo = %q, want acme/widget -- CreateTask authorizes against it", got.Repo)
|
||||
}
|
||||
// The model supplied an identity; it must be ignored in favour of the
|
||||
// bound identity.
|
||||
if reviewer.gotIdentity == nil || *reviewer.gotIdentity != "archie" {
|
||||
t.Fatalf("identity = %v, want bound \"archie\"", reviewer.gotIdentity)
|
||||
if got.Identity != "archie" {
|
||||
t.Errorf("identity = %q, want bound %q", got.Identity, "archie")
|
||||
}
|
||||
if reviewer.gotRepo != "acme/widget" || reviewer.gotNumber != 7 {
|
||||
t.Fatalf("ReviewPR called with (%q, %d), want (acme/widget, 7)", reviewer.gotRepo, reviewer.gotNumber)
|
||||
if n, ok := got.Inputs["pr_number"].(int); !ok || n != 7 {
|
||||
t.Errorf("inputs[pr_number] = %#v, want int 7", got.Inputs["pr_number"])
|
||||
}
|
||||
if got.Title == "" || got.Body == "" {
|
||||
t.Errorf("title/body = %q/%q, want both set so the queued task is identifiable", got.Title, got.Body)
|
||||
}
|
||||
|
||||
result, ok := out.(PRReviewResult)
|
||||
result, ok := out.(TaskSpawnResult)
|
||||
if !ok {
|
||||
t.Fatalf("handler returned %T, want PRReviewResult", out)
|
||||
t.Fatalf("handler returned %T, want TaskSpawnResult", out)
|
||||
}
|
||||
if result.Status != "completed" || len(result.Findings) != 1 || !result.Findings[0].Blocking {
|
||||
t.Fatalf("result = %+v, want completed with one blocking finding", result)
|
||||
if result.ID != 42 {
|
||||
t.Errorf("result.ID = %d, want 42", result.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewPRToolValidatesInput(t *testing.T) {
|
||||
reviewer := &fakePRReviewer{}
|
||||
entry := toolNamed(t, ReviewTools(reviewer, "archie"), "review_pr")
|
||||
creator := &fakeCreator{}
|
||||
entry := toolNamed(t, ReviewTools(creator, "archie"), "review_pr")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -91,15 +81,18 @@ func TestReviewPRToolValidatesInput(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
if len(creator.got.Inputs) != 0 || creator.got.Repo != "" {
|
||||
t.Errorf("rejected input still reached CreateTask: %+v", creator.got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReviewPRToolSurfacesReviewerError(t *testing.T) {
|
||||
reviewer := &fakePRReviewer{err: errors.New("review already in progress")}
|
||||
entry := toolNamed(t, ReviewTools(reviewer, "archie"), "review_pr")
|
||||
func TestReviewPRToolSurfacesCreatorError(t *testing.T) {
|
||||
creator := &fakeCreator{err: errors.New("repo not configured")}
|
||||
entry := toolNamed(t, ReviewTools(creator, "archie"), "review_pr")
|
||||
|
||||
if _, err := entry.Handler(context.Background(), map[string]any{
|
||||
"repo": "acme/widget", "pr_number": float64(7),
|
||||
}); err == nil {
|
||||
t.Fatal("handler error = nil, want the reviewer failure surfaced")
|
||||
t.Fatal("handler error = nil, want the creator failure surfaced")
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ type taskProfile struct {
|
||||
// internal/domain/workflow; the daemon supplies an adapter closure over
|
||||
// the store.TaskStore method of the same name.
|
||||
type chatTaskWriter interface {
|
||||
EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string) (taskID int64, err error)
|
||||
EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string, inputs map[string]any) (taskID int64, err error)
|
||||
}
|
||||
|
||||
// NewStoreTaskCreator returns a TaskCreator that enqueues chat-spawned
|
||||
@@ -103,7 +103,7 @@ func (c *StoreTaskCreator) CreateTask(ctx context.Context, req SpawnRequest) (in
|
||||
if owner == "" || repo == "" {
|
||||
return 0, fmt.Errorf("no repo configured for chat-spawned tasks")
|
||||
}
|
||||
return c.store.EnqueueChatTask(ctx, owner, repo, req.Title, req.Body, req.Workflow, req.Identity)
|
||||
return c.store.EnqueueChatTask(ctx, owner, repo, req.Title, req.Body, req.Workflow, req.Identity, req.Inputs)
|
||||
}
|
||||
|
||||
func splitOwnerRepo(s string) (owner, repo string, ok bool) {
|
||||
|
||||
@@ -13,13 +13,15 @@ import (
|
||||
|
||||
type fakeChatTaskWriter struct {
|
||||
owner, repo, title, body, workflow, identity string
|
||||
inputs map[string]any
|
||||
calls int
|
||||
nextID int64
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeChatTaskWriter) EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string) (int64, error) {
|
||||
func (f *fakeChatTaskWriter) EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string, inputs map[string]any) (int64, error) {
|
||||
f.owner, f.repo, f.title, f.body, f.workflow, f.identity = owner, repo, title, body, workflow, identity
|
||||
f.inputs = inputs
|
||||
f.calls++
|
||||
if f.err != nil {
|
||||
return 0, f.err
|
||||
@@ -46,6 +48,26 @@ func TestStoreTaskCreatorCreatesTask(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreTaskCreatorForwardsInputs(t *testing.T) {
|
||||
sw := &fakeChatTaskWriter{}
|
||||
tc := NewStoreTaskCreator(sw, "acme", "example-service", []string{"acme/example-service"})
|
||||
_, err := tc.CreateTask(context.Background(), SpawnRequest{
|
||||
Title: "review",
|
||||
Repo: "acme/example-service",
|
||||
Workflow: "pr-review",
|
||||
Inputs: map[string]any{"pr_number": 7},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateTask: %v", err)
|
||||
}
|
||||
if sw.workflow != "pr-review" {
|
||||
t.Errorf("workflow = %q, want pr-review", sw.workflow)
|
||||
}
|
||||
if n, ok := sw.inputs["pr_number"].(int); !ok || n != 7 {
|
||||
t.Errorf("inputs = %#v, want pr_number 7", sw.inputs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreTaskCreatorRejectsEmptyRepo(t *testing.T) {
|
||||
tc := NewStoreTaskCreator(&fakeChatTaskWriter{}, "", "", nil)
|
||||
_, err := tc.CreateTask(context.Background(), SpawnRequest{Title: "something"})
|
||||
|
||||
@@ -88,7 +88,6 @@ type TurnRunnerConfig struct {
|
||||
TaskLogs ChatTaskLogReader
|
||||
TaskActor ChatTaskActor
|
||||
TaskIdentity string
|
||||
PRReviewer ChatPRReviewer
|
||||
Bus TurnEventPublisher
|
||||
BotUser string
|
||||
Channel string
|
||||
@@ -314,7 +313,7 @@ func (r *TurnRunner) prepareTurn(ctx context.Context, sessionID string, in Inbou
|
||||
TaskTools(r.TaskLister, r.Tasks, r.TaskLogs, r.TaskActor, r.TaskIdentity),
|
||||
SessionTools(r.Sessions, r.Router.SessionTracker(), r.Router.sessionPlatform(in), in.Message)...,
|
||||
)
|
||||
extraTools = append(extraTools, ReviewTools(r.PRReviewer, r.TaskIdentity)...)
|
||||
extraTools = append(extraTools, ReviewTools(r.Tasks, r.TaskIdentity)...)
|
||||
// The dashboard tools (page_index, dashboard_navigate) belong to the web
|
||||
// UI only: a non-web channel has no dashboard to point at.
|
||||
extraTools = append(extraTools, PageIndexTools(r.Channel)...)
|
||||
|
||||
@@ -138,7 +138,7 @@ func titles(t *testing.T, pool *pgxpool.Pool) []string {
|
||||
|
||||
func enqueue(t *testing.T, pool *pgxpool.Pool, title string) {
|
||||
t.Helper()
|
||||
if _, err := New(pool).EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", ""); err != nil {
|
||||
if _, err := New(pool).EnqueueChatTask(t.Context(), "acme", "widget", title, "body", "implement", "", nil); err != nil {
|
||||
t.Fatalf("enqueue %q: %v", title, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ func (q *Queries) EnqueueIssue(ctx context.Context, arg EnqueueIssueParams) (int
|
||||
}
|
||||
|
||||
const insertChatTask = `-- name: InsertChatTask :one
|
||||
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id)
|
||||
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, inputs)
|
||||
VALUES (
|
||||
$1, $2,
|
||||
COALESCE((
|
||||
@@ -266,7 +266,8 @@ VALUES (
|
||||
(SELECT m.org_id FROM memberships m WHERE m.identity_id = $7
|
||||
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
|
||||
'default'
|
||||
)
|
||||
),
|
||||
$8
|
||||
)
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
`
|
||||
@@ -279,12 +280,16 @@ type InsertChatTaskParams struct {
|
||||
Body string
|
||||
Workflow string
|
||||
Identity string
|
||||
Inputs string
|
||||
}
|
||||
|
||||
// The synthetic issue number keeps chat-sourced tasks off the forge's real
|
||||
// issue numbers; this allocator is the single source of truth for it.
|
||||
// fallback_issue_number is only the seed for a repo's first chat task -- the
|
||||
// passed value is not the issue number that lands.
|
||||
// inputs is the chat task's own workflow inputs; a binding dispatch passes
|
||||
// its inputs here too, so this insert is the single writer of the column and
|
||||
// StampTaskBinding adds only the provenance.
|
||||
func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams) (Task, error) {
|
||||
row := q.db.QueryRow(ctx, insertChatTask,
|
||||
arg.Owner,
|
||||
@@ -294,6 +299,7 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
|
||||
arg.Body,
|
||||
arg.Workflow,
|
||||
arg.Identity,
|
||||
arg.Inputs,
|
||||
)
|
||||
var i Task
|
||||
err := row.Scan(
|
||||
@@ -599,23 +605,17 @@ func (q *Queries) SetReviewCursors(ctx context.Context, arg SetReviewCursorsPara
|
||||
}
|
||||
|
||||
const stampTaskBinding = `-- name: StampTaskBinding :exec
|
||||
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1
|
||||
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1
|
||||
`
|
||||
|
||||
type StampTaskBindingParams struct {
|
||||
ID int64
|
||||
BindingID string
|
||||
BindingVersion int64
|
||||
Inputs string
|
||||
}
|
||||
|
||||
func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingParams) error {
|
||||
_, err := q.db.Exec(ctx, stampTaskBinding,
|
||||
arg.ID,
|
||||
arg.BindingID,
|
||||
arg.BindingVersion,
|
||||
arg.Inputs,
|
||||
)
|
||||
_, err := q.db.Exec(ctx, stampTaskBinding, arg.ID, arg.BindingID, arg.BindingVersion)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,10 @@ SELECT status, count(*)::int AS count FROM tasks GROUP BY status;
|
||||
-- issue numbers; this allocator is the single source of truth for it.
|
||||
-- fallback_issue_number is only the seed for a repo's first chat task -- the
|
||||
-- passed value is not the issue number that lands.
|
||||
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id)
|
||||
-- inputs is the chat task's own workflow inputs; a binding dispatch passes
|
||||
-- its inputs here too, so this insert is the single writer of the column and
|
||||
-- StampTaskBinding adds only the provenance.
|
||||
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, inputs)
|
||||
VALUES (
|
||||
sqlc.arg(owner), sqlc.arg(repo),
|
||||
COALESCE((
|
||||
@@ -57,12 +60,13 @@ VALUES (
|
||||
(SELECT m.org_id FROM memberships m WHERE m.identity_id = sqlc.arg(identity)
|
||||
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
|
||||
'default'
|
||||
)
|
||||
),
|
||||
sqlc.arg(inputs)
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: StampTaskBinding :exec
|
||||
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1;
|
||||
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1;
|
||||
|
||||
-- name: UpdateTask :exec
|
||||
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
// runningExecution enqueues and claims one task, the state a step runs in.
|
||||
func runningExecution(t *testing.T, s *Store) *workflow.Task {
|
||||
t.Helper()
|
||||
seed, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
|
||||
seed, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
|
||||
if err != nil || seed == nil {
|
||||
t.Fatalf("EnqueueChatTask: %+v %v", seed, err)
|
||||
}
|
||||
|
||||
@@ -148,10 +148,17 @@ func (s *Store) EnqueueIssue(ctx context.Context, owner, repo string, number int
|
||||
|
||||
// EnqueueChatTask inserts a queued chat-sourced task and returns the full row.
|
||||
// The store allocates the synthetic issue number durably so processes sharing
|
||||
// the database cannot generate the same value.
|
||||
func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*workflow.Task, error) {
|
||||
// the database cannot generate the same value. inputs are the task's workflow
|
||||
// inputs (the operator trigger's pr_number, for instance); a chat task carries
|
||||
// no binding provenance, so the insert is the only writer of that column.
|
||||
func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string, inputs map[string]any) (*workflow.Task, error) {
|
||||
encoded, err := task.EncodeInputs(inputs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, err := s.queries().InsertChatTask(ctx, postgresdb.InsertChatTaskParams{
|
||||
Owner: owner, Repo: repo, Title: title, Body: body, Workflow: wf, Identity: identity,
|
||||
Inputs: encoded,
|
||||
FallbackIssueNumber: syntheticIssueNumberBase - 1,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -161,24 +168,21 @@ func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, w
|
||||
}
|
||||
|
||||
// EnqueueBindingTask enqueues a binding-triggered task and stamps its binding
|
||||
// provenance in a second statement (best-effort, as in the SQLite store).
|
||||
// provenance in a second statement (best-effort, as in the SQLite store). The
|
||||
// inputs travel with the insert, so a failed stamp leaves a task whose inputs
|
||||
// are already right and whose provenance is absent, never the reverse.
|
||||
func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity, bindingID string, bindingVersion int, inputs map[string]any) (*workflow.Task, error) {
|
||||
encoded, err := task.EncodeInputs(inputs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, wf, identity)
|
||||
t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, wf, identity, inputs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.queries().StampTaskBinding(ctx, postgresdb.StampTaskBindingParams{
|
||||
ID: t.ID, BindingID: bindingID, BindingVersion: int64(bindingVersion), Inputs: encoded,
|
||||
ID: t.ID, BindingID: bindingID, BindingVersion: int64(bindingVersion),
|
||||
}); err != nil {
|
||||
return nil, fmt.Errorf("store: stamp binding provenance: %w", err)
|
||||
}
|
||||
t.BindingID = bindingID
|
||||
t.BindingVersion = bindingVersion
|
||||
t.Inputs = inputs
|
||||
return t, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestIllegalTransitionsAreRejected(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := storeFor(t)
|
||||
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
|
||||
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func TestIllegalTransitionsAreRejected(t *testing.T) {
|
||||
// conformance battery has always asserted).
|
||||
func TestStaleFromBeatsIllegalPair(t *testing.T) {
|
||||
s := storeFor(t)
|
||||
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
|
||||
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func TestStaleFromBeatsIllegalPair(t *testing.T) {
|
||||
// and the audit row is written as before.
|
||||
func TestLegalTransitionStillWrites(t *testing.T) {
|
||||
s := storeFor(t)
|
||||
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "")
|
||||
task, err := s.EnqueueChatTask(t.Context(), "acme", "widgets", "t", "b", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestEventAttributionSurvivesTheStateStoreBoundary(t *testing.T) {
|
||||
c = remoteTaskStore(t, local, nil, nil)
|
||||
}
|
||||
|
||||
task, err := c.EnqueueChatTask(ctx, "acme", "widget", "title", "body", "implement", "")
|
||||
task, err := c.EnqueueChatTask(ctx, "acme", "widget", "title", "body", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("EnqueueChatTask = (%+v, %v)", task, err)
|
||||
}
|
||||
|
||||
@@ -75,8 +75,12 @@ func (c *Client) EnqueueIssue(ctx context.Context, owner, repo string, number in
|
||||
return r.Inserted, nil
|
||||
}
|
||||
|
||||
func (c *Client) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*task.Task, error) {
|
||||
r, err := c.client.EnqueueChatTask(ctx, &pb.EnqueueChatTaskRequest{Owner: owner, Repo: repo, Title: title, Body: body, Workflow: wf, Identity: identity})
|
||||
func (c *Client) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string, inputs map[string]any) (*task.Task, error) {
|
||||
encoded, err := task.EncodeInputs(inputs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r, err := c.client.EnqueueChatTask(ctx, &pb.EnqueueChatTaskRequest{Owner: owner, Repo: repo, Title: title, Body: body, Workflow: wf, Identity: identity, InputsJson: encoded})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
}
|
||||
|
||||
@@ -133,10 +133,21 @@ func TestStateStoreConformance(t *testing.T) {
|
||||
}
|
||||
|
||||
// workflow.Store view: EnqueueChatTask, Transition, Update, InsertEvent.
|
||||
task, err := c.EnqueueChatTask(ctx, "acme", "widget", "title", "body", "implement", "")
|
||||
task, err := c.EnqueueChatTask(ctx, "acme", "widget", "title", "body", "implement", "", nil)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("EnqueueChatTask: %+v %v", task, err)
|
||||
}
|
||||
// A chat task's workflow inputs travel with it across the wire
|
||||
// and back out of the store: the operator trigger's pr-review
|
||||
// task names its pull request through this input, and drops it
|
||||
// silently if either mapping forgets it.
|
||||
triggered, err := c.EnqueueChatTask(ctx, "acme", "widget", "review", "body", "pr-review", "", map[string]any{"pr_number": 7})
|
||||
if err != nil || triggered == nil {
|
||||
t.Fatalf("EnqueueChatTask with inputs: %+v %v", triggered, err)
|
||||
}
|
||||
if got := triggered.EffectivePRNumber(); got != 7 {
|
||||
t.Fatalf("queued task EffectivePRNumber = %d, want 7 -- inputs did not round trip", got)
|
||||
}
|
||||
if err := c.Transition(ctx, task.ID, task.Status, "running", "started"); err != nil {
|
||||
t.Fatalf("Transition: %v", err)
|
||||
}
|
||||
|
||||
@@ -178,7 +178,11 @@ func (s *server) EnqueueIssue(ctx context.Context, r *pb.EnqueueIssueRequest) (*
|
||||
}
|
||||
|
||||
func (s *server) EnqueueChatTask(ctx context.Context, r *pb.EnqueueChatTaskRequest) (*pb.EnqueueChatTaskResponse, error) {
|
||||
t, err := s.deps.Tasks.EnqueueChatTask(ctx, r.Owner, r.Repo, r.Title, r.Body, r.Workflow, r.Identity)
|
||||
inputs, err := task.DecodeInputs(r.InputsJson)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
t, err := s.deps.Tasks.EnqueueChatTask(ctx, r.Owner, r.Repo, r.Title, r.Body, r.Workflow, r.Identity, inputs)
|
||||
if err != nil {
|
||||
return nil, s.logErr("EnqueueChatTask", err)
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ func TestTaskGrantAuthorizesTheWorkflowCallRPCs(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
caller, err := admin.EnqueueChatTask(ctx, "acme", "widget", "caller", "body", "implement", "")
|
||||
caller, err := admin.EnqueueChatTask(ctx, "acme", "widget", "caller", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := admin.EnqueueChatTask(ctx, "acme", "widget", "other", "body", "implement", "")
|
||||
other, err := admin.EnqueueChatTask(ctx, "acme", "widget", "other", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -174,11 +174,11 @@ func TestTaskGrantScopesWorkerToItsOwnRPCs(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
taskA, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
taskA, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
taskB, err := admin.EnqueueChatTask(ctx, "acme", "widget", "b", "body", "implement", "")
|
||||
taskB, err := admin.EnqueueChatTask(ctx, "acme", "widget", "b", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func TestOnlyAdminPublishesTheConfigSnapshot(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -308,7 +308,7 @@ func TestOnlyAdminReportsApplyStatus(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -345,7 +345,7 @@ func TestOnlyAdminOwnsThePlaybookLedger(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -379,7 +379,7 @@ func TestOnlyAdminCanRegisterOrRevokeTaskGrants(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
|
||||
admin := dial(t, adminToken)
|
||||
taskA, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
taskA, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -408,7 +408,7 @@ func TestRunCredentialRecordsItsOwnSteps(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
own, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
own, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -421,7 +421,7 @@ func TestRunCredentialRecordsItsOwnSteps(t *testing.T) {
|
||||
if err != nil || own == nil {
|
||||
t.Fatalf("TaskByID: %+v %v", own, err)
|
||||
}
|
||||
other, err := admin.EnqueueChatTask(ctx, "acme", "widget", "b", "body", "implement", "")
|
||||
other, err := admin.EnqueueChatTask(ctx, "acme", "widget", "b", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -478,7 +478,7 @@ func TestTaskGrantCannotCancelAnExecution(t *testing.T) {
|
||||
admin := dial(t, adminToken)
|
||||
ctx := t.Context()
|
||||
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "")
|
||||
task, err := admin.EnqueueChatTask(ctx, "acme", "widget", "a", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestWorkflowCallerConformance(t *testing.T) {
|
||||
c = remoteTaskStore(t, local, nil, nil)
|
||||
}
|
||||
|
||||
caller, err := local.EnqueueChatTask(ctx, "acme", "widget", "caller", "body", "implement", "")
|
||||
caller, err := local.EnqueueChatTask(ctx, "acme", "widget", "caller", "body", "implement", "", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("EnqueueChatTask: %v", err)
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ func TestRejectDoesNotCloseAChatTaskIssue(t *testing.T) {
|
||||
operatorActions(t, srv).issues = closer
|
||||
operatorActions(t, srv).cfg = config.NewHolder(config.Config{MaxRetries: 3})
|
||||
|
||||
task, err := srv.Store.EnqueueChatTask(ctx, "acme", "widget", "chat task", "", "", "")
|
||||
task, err := srv.Store.EnqueueChatTask(ctx, "acme", "widget", "chat task", "", "", "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestWorkRequestRejectsDisabledWorkflow(t *testing.T) {
|
||||
if w.Code != http.StatusConflict {
|
||||
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
|
||||
}
|
||||
if creator.request != (gateway.SpawnRequest{}) {
|
||||
t.Fatalf("creator called with %#v", creator.request)
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -512,6 +512,10 @@ message EnqueueChatTaskRequest {
|
||||
string body = 4;
|
||||
string workflow = 5;
|
||||
string identity = 6;
|
||||
// inputs_json assigns workflow inputs, a JSON object of the same form
|
||||
// EnqueueBindingTaskRequest carries. A chat task sets them at insert
|
||||
// time: it has no binding provenance to stamp afterwards.
|
||||
string inputs_json = 7;
|
||||
}
|
||||
message EnqueueChatTaskResponse { Task task = 1; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user