diff --git a/internal/agentexec/nats_test.go b/internal/agentexec/nats_test.go index 2afdcab32..432e92302 100644 --- a/internal/agentexec/nats_test.go +++ b/internal/agentexec/nats_test.go @@ -15,9 +15,53 @@ import ( arnats "github.com/samcharles93/archie-core/internal/nats" ) +// ── regression tests for PRD gaps ──────────────────────────────────── +// These must FAIL until the gaps are closed. + +func TestAgentRequestMessageHasWorkflowField(t *testing.T) { + // Gap 1: archie-agent is per-stage, not per-task. + // PRD section 1 says the agent runs full multi-stage workflows. + // AgentRequestMessage must carry the workflow name. + msg := AgentRequestMessage{Workflow: "implement"} + if msg.Workflow == "" { + t.Error("Gap 1: AgentRequestMessage.Workflow is empty. " + + "Add a Workflow field so the agent can run full multi-stage workflows per PRD section 1.") + } +} + +func TestAgentResponseEnvelopeHasChannelField(t *testing.T) { + // Gap 3: no response/system channel split. + // PRD section 2: archie.agent..response vs .system. + // The envelope must distinguish human-destined responses from + // internal system messages the daemon never forwards. + env := AgentResponseEnvelope{Channel: "system"} + if env.Channel == "" { + t.Error("Gap 3: AgentResponseEnvelope has no Channel field. " + + "Add a Channel field (\"response\"|\"system\") per PRD section 2.") + } +} + +func TestSubjectForAgentResponseExists(t *testing.T) { + // Gap 3: subject functions for response/system channels. + subj := arnats.SubjectForAgentResponse(42) + if subj == "" { + t.Error("Gap 3: SubjectForAgentResponse not implemented. " + + "Add SubjectForAgentResponse(taskID) returning archie.agent..response per PRD section 2.") + } +} + +func TestSubjectForAgentSystemExists(t *testing.T) { + subj := arnats.SubjectForAgentSystem(42) + if subj == "" { + t.Error("Gap 3: SubjectForAgentSystem not implemented. " + + "Add SubjectForAgentSystem(taskID) returning archie.agent..system per PRD section 2.") + } +} + +// ── existing tests ─────────────────────────────────────────────────── + func startEmbeddedNATS(t *testing.T) *server.Server { t.Helper() - // RunRandClientPortServer doesn't enable JetStream. Enable it separately. srv := natssrv.RunRandClientPortServer() t.Cleanup(srv.Shutdown) if err := srv.EnableJetStream(&server.JetStreamConfig{StoreDir: t.TempDir()}); err != nil { @@ -26,7 +70,6 @@ func startEmbeddedNATS(t *testing.T) *server.Server { return srv } -// handler subscribes to archie.agent.> and replies with a canned result. func startHandler(t *testing.T, nc *natsio.Conn) { t.Helper() js, err := jetstream.New(nc) @@ -53,7 +96,7 @@ func startHandler(t *testing.T, nc *natsio.Conn) { } go func() { for { - batch, err := cons.Fetch(1, jetstream.FetchMaxWait(5 * time.Second)) + batch, err := cons.Fetch(1, jetstream.FetchMaxWait(5*time.Second)) if err != nil { return } @@ -95,7 +138,6 @@ func TestNATSRunnerRoundTrip(t *testing.T) { } defer client.Close() - // Start the handler that simulates archie-agent. startHandler(t, client.Conn()) runner := &NATSRunner{ diff --git a/internal/workflow/agent_test.go b/internal/workflow/agent_test.go index f0fc2001c..a0c337fc7 100644 --- a/internal/workflow/agent_test.go +++ b/internal/workflow/agent_test.go @@ -175,6 +175,33 @@ func TestFeasibilityRejectsNullFitValue(t *testing.T) { } } +// ── regression: Gap 5 — daemon review step ────────────────────────── + +func TestAgentStageHasReviewHook(t *testing.T) { + // Gap 5: no daemon review step before human delivery. + // PRD section 1 says the daemon reviews agent responses before + // forwarding to human channels (issue comments, labels, PRs). + // AgentStage must have a ReviewResult hook that gates + // stage output before OnResult forwards it to humans. + reviewed := false + stage := AgentStage{ + Name: "plan", + Role: "planner", + Mission: func(*TaskContext) string { return "test" }, + ReviewResult: func(_ *TaskContext, _ agentexec.Result) error { + reviewed = true + return nil + }, + } + if stage.ReviewResult == nil { + t.Error("Gap 5: AgentStage.ReviewResult is nil. " + + "Add a ReviewResult func(*TaskContext, agentexec.Result) error hook " + + "that gates agent output before OnResult forwards to human channels, per PRD section 1.") + } + // Verify the field is settable and has the right signature. + _ = reviewed +} + func TestRunLeavesInterruptedTaskForCrashRecovery(t *testing.T) { st, err := store.Open(filepath.Join(t.TempDir(), "archie.db")) if err != nil {