Files
archie/internal/app/archied/composition_order_test.go
T
sam 207b071917 fix(archied): build the Gateway's worktree manager so it serves review_pr
boot.prReviewer returns nil without a worktree manager, and a nil reviewer
omits review_pr from every channel's tool set. RunGateway never called
buildTreesAndIdentities, so the Gateway resolved a nil reviewer and no
channel could review a PR.

Extract the manager's construction into boot.buildWorktreeManager, called
by buildTreesAndIdentities (daemon, unchanged field-for-field) and by
startGatewayRuntime before setupGatewayChat. The Gateway does not call
buildTreesAndIdentities: that also registers daemon identity runners the
Gateway must not own, and PR review only needs a clone of the PR head,
which worktree.Manager.CheckoutPR does from the forge.

Pin the ordering by source position in composition_order_test.go, alongside
the memory-engine ordering the same function already carries, and pin both
compositions behaviourally in worktree_manager_composition_test.go: the
Gateway's step must yield a reviewer that advertises review_pr, and the
daemon must still build its root manager plus one runner per identity with
a distinct WorkDir.

Correct docs/prds/operator-pr-review.md, which still asserted the daemon
supplies ChatPRReviewer and holds the review in-flight set.
2026-09-22 03:44:45 +10:00

61 lines
2.9 KiB
Go

package archied
import (
"go/parser"
"go/token"
"testing"
)
// TestStartGatewayRuntimeSetsUpMemoryBeforeGatewayChat pins the ordering
// docs/prds/memory-engine-unification.md §4's "Prerequisite" note requires.
// startGatewayRuntime (gateway.go) constructs the only chat turn runner in
// production via setupGatewayChat, and a turn runner captures b.memEngines at
// construction time via boot.memoryStore(). Built the other way round it
// captures a nil engine and the chat <memory> block never appears, silently,
// because renderMemory treats a nil engine the same as a failed read. Nothing
// at runtime observes the order, so it is asserted by source position, the
// same way TestSetupBackendsRegistersContainerCleanupAfterNATS in
// bootstrap_nats_test.go pins cleanup ordering for the same reason.
func TestStartGatewayRuntimeSetsUpMemoryBeforeGatewayChat(t *testing.T) {
fileset := token.NewFileSet()
file, err := parser.ParseFile(fileset, "gateway.go", nil, 0)
if err != nil {
t.Fatal(err)
}
run := methodBody(t, file, "startGatewayRuntime")
memoryEngine := methodCallPosition(run, "setupMemoryEngine")
chat := methodCallPosition(run, "setupGatewayChat")
if memoryEngine == token.NoPos || chat == token.NoPos {
t.Fatalf("startGatewayRuntime call positions: setupMemoryEngine=%v setupGatewayChat=%v, want both present", memoryEngine, chat)
}
if chat < memoryEngine {
t.Fatal("startGatewayRuntime wires setupGatewayChat before setupMemoryEngine; the turn runner would capture a nil memory engine")
}
}
// TestStartGatewayRuntimeBuildsWorktreeManagerBeforeGatewayChat pins the
// Gateway's own worktree-manager ordering. The Gateway owns PR review, so
// startGatewayRuntime must compose the process-wide worktree manager before
// setupGatewayChat resolves boot.prReviewer: prReviewer returns nil without a
// manager, and a nil reviewer omits review_pr from every channel's tool set
// (internal/gateway/review_tools.go). The Gateway deliberately does not call
// buildTreesAndIdentities -- that also registers daemon identity runners it
// must not own -- so nothing at runtime connects the manager to this
// composition phase except the call this asserts on.
func TestStartGatewayRuntimeBuildsWorktreeManagerBeforeGatewayChat(t *testing.T) {
fileset := token.NewFileSet()
file, err := parser.ParseFile(fileset, "gateway.go", nil, 0)
if err != nil {
t.Fatal(err)
}
run := methodBody(t, file, "startGatewayRuntime")
trees := methodCallPosition(run, "buildWorktreeManager")
chat := methodCallPosition(run, "setupGatewayChat")
if trees == token.NoPos || chat == token.NoPos {
t.Fatalf("startGatewayRuntime call positions: buildWorktreeManager=%v setupGatewayChat=%v, want both present", trees, chat)
}
if chat < trees {
t.Fatal("startGatewayRuntime wires setupGatewayChat before buildWorktreeManager; the Gateway would resolve a nil reviewer and never advertise review_pr")
}
}