Files
goclaw/internal/tools/team_tool_backend.go
T
viettranx e9342533e0 refactor(tools): extract TeamToolBackend interface for team task testability
Extract TeamToolBackend interface from concrete *TeamToolManager to enable
unit testing of the 17 team task action handlers without DB or message bus.

- Add TeamToolBackend interface (19 methods) in team_tool_backend.go
- Add exported wrappers on TeamToolManager (cache, helpers, dispatch, manager)
- Migrate 133 call sites across 5 action handler files (pure casing rename)
- Change TeamTasksTool.manager field from *TeamToolManager to TeamToolBackend
- Add mock backend infrastructure (baseNoopTeamStore + mockTaskStore + mockBackend)
- Add 94 unit subtests across 6 test files covering all actions:
  lifecycle (claim/complete/cancel/review/approve/reject),
  create validation, blocker escalation, mutations (comment/progress/attach/update),
  followup (ask_user/clear_ask_user/retry), read actions (notification/policy/list/search/get)

WorkspaceInterceptor and PostTurnProcessor remain on concrete *TeamToolManager.
No behavioral changes — all existing logic preserved.
2026-03-27 22:26:36 +07:00

52 lines
1.9 KiB
Go

package tools
import (
"context"
"github.com/google/uuid"
"github.com/nextlevelbuilder/goclaw/internal/bus"
"github.com/nextlevelbuilder/goclaw/internal/store"
)
// TeamToolBackend abstracts the TeamToolManager for action handlers.
// This interface enables unit testing of action handlers with a mock backend.
// WorkspaceInterceptor and PostTurnProcessor continue to use *TeamToolManager directly.
type TeamToolBackend interface {
// Team resolution & auth
ResolveTeam(ctx context.Context) (*store.TeamData, uuid.UUID, error)
RequireLead(ctx context.Context, team *store.TeamData, agentID uuid.UUID) error
// Store access
Store() store.TeamStore
// Agent resolution
ResolveAgentByKey(ctx context.Context, key string) (uuid.UUID, error)
AgentKeyFromID(ctx context.Context, id uuid.UUID) string
AgentDisplayName(ctx context.Context, key string) string
CachedListMembers(ctx context.Context, teamID, agentID uuid.UUID) ([]store.TeamMemberData, error)
CachedGetAgentByID(ctx context.Context, id uuid.UUID) (*store.AgentData, error)
PreWarmAgentKeyCache(ctx context.Context, keys []string)
PreWarmAgentIDCache(ctx context.Context, ids []uuid.UUID)
// Side effects
BroadcastTeamEvent(ctx context.Context, name string, payload any)
DispatchTaskToAgent(ctx context.Context, task *store.TeamTaskData, team *store.TeamData, agentID uuid.UUID)
TryPublishInbound(msg bus.InboundMessage) bool
// Dispatch helpers
BuildBlockerResultsSummary(ctx context.Context, task *store.TeamTaskData) string
BuildRecentCommentsSummary(ctx context.Context, taskID uuid.UUID) string
RestoreTraceContext(ctx context.Context, task *store.TeamTaskData) context.Context
// Settings helpers
FollowupDelayMinutes(team *store.TeamData) int
FollowupMaxReminders(team *store.TeamData) int
// Data directory for workspace resolution
DataDir() string
}
// Compile-time check: *TeamToolManager must satisfy TeamToolBackend.
var _ TeamToolBackend = (*TeamToolManager)(nil)