fix(archied): stop advertising review_pr when no reviewer can run
review_pr was registered on every channel and failed on every call with "worktree manager is not configured". Two independent causes, one contract: The daemon ran setupGateways before buildTreesAndIdentities, so setupGateways reached prReviewer() while b.trees was still nil and captured it; the memoised reviewer then held that nil for the process lifetime. Build the worktree manager before the gateways, which is the ordering the reviewer depends on. Ordering alone cannot fix the standalone Gateway, which calls prReviewer() and never builds trees at all. Have prReviewer() return nil when b.trees is nil, so a reviewer that can never run is not produced. That is what gateway.ReviewTools' existing nil-reviewer guard always intended -- "a tool that cannot run must not be advertised" -- but the guard never fired because the daemon never passed nil. TestPrReviewerIsMemoized asserted a trees-less boot yields a non-nil cached reviewer, encoding the broken precondition as expected behaviour, which is why a green suite hid this since review_pr shipped. It now gives the boot a real worktree manager so its actual subject -- one shared in-flight set across channels -- stays pinned, and two tests are added: one for the nil-trees invariant, and one that composes the real wiring (prReviewer -> ReviewTools) and asserts review_pr is registered only when the reviewer can run. Found by an adversarial package sweep (temp tracker: app-archied-5, .local/issue-tracker/).
This commit is contained in:
1 parent
498fc011a4
commit
372f80628a
3 files changed
+47
-5
No files matched your search
@@ -408,6 +408,9 @@ func Run() int { //nolint:cyclop // the composition root's setup sequence is del
|
||||
if err := b.setupLLMAndChat(); err != nil {
|
||||
return 1
|
||||
}
|
||||
if err := b.buildTreesAndIdentities(ctx); err != nil {
|
||||
return 1
|
||||
}
|
||||
if !b.setupGateways(ctx, args.cfgPath, args.overlayPath) {
|
||||
return 1
|
||||
}
|
||||
@@ -418,9 +421,6 @@ func Run() int { //nolint:cyclop // the composition root's setup sequence is del
|
||||
if err := b.loadPlugins(); err != nil {
|
||||
return 1
|
||||
}
|
||||
if err := b.buildTreesAndIdentities(ctx); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
if err := b.registerNATSRPC(); err != nil {
|
||||
return 1
|
||||
|
||||
@@ -239,6 +239,9 @@ func (b *boot) prReviewer() gateway.ChatPRReviewer {
|
||||
if b.chatPRReviewer != nil {
|
||||
return b.chatPRReviewer
|
||||
}
|
||||
if b.trees == nil {
|
||||
return nil
|
||||
}
|
||||
forgeReader, _ := b.forgeClient.(forge.PullRequestReader)
|
||||
if forgeReader == nil {
|
||||
return nil
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
)
|
||||
|
||||
func TestSplitOwnerRepo(t *testing.T) {
|
||||
@@ -176,9 +178,14 @@ func (reviewCapableForge) GetPullRequest(context.Context, string, string, int) (
|
||||
|
||||
// TestPrReviewerIsMemoized pins the cross-channel single-flight fix: every
|
||||
// gateway must share one prReviewer so a review of the same PR requested from
|
||||
// two channels at once deduplicates instead of running twice.
|
||||
// two channels at once deduplicates instead of running twice. The boot must
|
||||
// own a worktree manager: a reviewer without one can never run and must not be
|
||||
// produced (see TestPrReviewerNilWithoutTrees).
|
||||
func TestPrReviewerIsMemoized(t *testing.T) {
|
||||
b := &boot{forgeClient: reviewCapableForge{Forge: forge.NewNoop(slog.New(slog.DiscardHandler))}}
|
||||
b := &boot{
|
||||
forgeClient: reviewCapableForge{Forge: forge.NewNoop(slog.New(slog.DiscardHandler))},
|
||||
trees: &worktree.Manager{},
|
||||
}
|
||||
|
||||
first := b.prReviewer()
|
||||
if first == nil {
|
||||
@@ -188,3 +195,35 @@ func TestPrReviewerIsMemoized(t *testing.T) {
|
||||
t.Fatal("prReviewer() returned distinct instances; channels would not share the in-flight set")
|
||||
}
|
||||
}
|
||||
|
||||
// TestPrReviewerNilWithoutTrees pins the producer-side invariant: a PR-capable
|
||||
// forge without a worktree manager must yield no reviewer. The standalone
|
||||
// Gateway never builds trees, and the daemon used to capture b.trees before it
|
||||
// was assigned, so both advertised a review_pr tool that always failed.
|
||||
func TestPrReviewerNilWithoutTrees(t *testing.T) {
|
||||
b := &boot{forgeClient: reviewCapableForge{Forge: forge.NewNoop(slog.New(slog.DiscardHandler))}}
|
||||
|
||||
if got := b.prReviewer(); got != nil {
|
||||
t.Fatalf("prReviewer() with no worktree manager = %T, want nil", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestReviewPRToolRegisteredOnlyWithWorkingReviewer composes the real boot
|
||||
// wiring (boot.prReviewer -> gateway.ReviewTools) and asserts review_pr is
|
||||
// advertised only when the reviewer can actually run.
|
||||
func TestReviewPRToolRegisteredOnlyWithWorkingReviewer(t *testing.T) {
|
||||
logger := slog.New(slog.DiscardHandler)
|
||||
b := &boot{
|
||||
forgeClient: reviewCapableForge{Forge: forge.NewNoop(logger)},
|
||||
log: logger,
|
||||
}
|
||||
|
||||
if entries := gateway.ReviewTools(b.prReviewer(), "archie"); len(entries) != 0 {
|
||||
t.Fatalf("ReviewTools with no worktree manager = %d entries, want 0", len(entries))
|
||||
}
|
||||
|
||||
b.trees = &worktree.Manager{}
|
||||
if entries := gateway.ReviewTools(b.prReviewer(), "archie"); len(entries) != 1 {
|
||||
t.Fatalf("ReviewTools with a worktree manager = %d entries, want 1", len(entries))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user