97c1f689e4
* feat(workflow): explicit step-completion signal for auto-advance Adds `step_complete_kandev` MCP tool + `WorkflowStep.auto_advance_requires_signal` column so workflow steps can gate their `on_turn_complete` transitions on an agent-emitted completion signal instead of inferring "done" from any turn-end. See docs/decisions/0015-explicit-completion-signal-for-auto-advance.md for the motivation, alternatives considered, and trade-offs. * fix(workflow): address PR review feedback for explicit completion signal - Dedup `LoadPendingStepSignal` into `internal/task/models` so the MCP handler (write site) and the orchestrator (read site) share one decoder. - Gate the out-of-band subscriber on `WorkflowStep.AutoAdvanceRequiresSignal` so `step_complete_kandev` is not an unintended manual-advance path for signalless steps. - Fail closed on step-load errors in `processOnTurnCompleteViaEngine`: a loader hiccup must block the transition rather than silently bypass the gate. - Reject `step_complete_kandev` for terminal sessions (Completed / Failed / Cancelled) so the agent gets a clear error instead of `accepted: true` followed by a no-op. - Surface bus-publish failures back to the agent instead of swallowing them — the idempotency guard makes the retry safe and prevents the session from getting stuck. - New `TestOnStepCompletionSignaled` covers the subscriber paths (RUNNING / WAITING+match / stale step / not signal-gated). - ADR doc fixes: payload field list now matches the wire shape, writer ownership is documented, the unsubstantiated 250ms-debounce claim is removed, and the late-signal re-close race is recorded as a deferred open question. - Drop the new toggle's HelpTip in favour of an inline description — the shadcn tooltip portal was intercepting clicks on the agent-profile dropdown options in the workflow settings E2E. * fix(workflow): round-2 review fixes for explicit completion signal - Split `handleStepComplete` into `resolveStepCompleteTarget` + `publishStepCompletionEvent` helpers so the entrypoint clears funlen (88 → under 80 lines) and the two halves are independently testable. - Classify session/task load errors instead of returning `NotFound` for every failure: use the exported `taskrepo.ErrTaskNotFound` sentinel for task lookups, substring-match for the session repo (no sentinel today), and surface anything else as `InternalError` with the raw error logged but not leaked to the agent — so a transient DB hiccup triggers a retry rather than session abandonment. - Pin `step_complete_kandev` explicitly in the mode-specific tool-count tests: `Contains` in `ModeTask`, `NotContains` in `ModeConfig` and `ModeOffice`, so accidental dereg or cross-mode registration is caught by the diff instead of by a still-equal count. * fix(workflow): round-3 review fixes + defer pipeline-editor toggle - Defer the "Wait for agent completion signal" sub-toggle to a follow-up PR. Adding it to the step config card shifts the layout enough that the agent profile select's Radix popper opens into a sibling tooltip's hover path, breaking workflow-agent-profile.spec.ts on shard 7. The backend column ships in this PR — workflows can opt in via the YAML import or the MCP `update_workflow_step_kandev` tool — and the UI affordance gets its own iteration where the test interference can be investigated without blocking the rest of the change. - Re-publish the bus event on the `already_signaled` short-circuit when the session is WAITING_FOR_INPUT. Without this, an agent's retry after the first call's publish failed would short-circuit on the persisted bag, never fire the subscriber, and leave the session stuck. - handleStepComplete docstring: drop the non-existent feature-flag claim and the "audit entry" wording — gating is purely `WorkflowStep.AutoAdvanceRequiresSignal` and the bag is cleared on the next turn start with no separate audit trail. - `step_complete_kandev` tool description: same fix — clarify that the call succeeds for non-gated steps but the signal is discarded on the next turn start (no audit history to query later). * test(workflow): cover handleStepComplete + reword defer-comment - Add `TestHandleStepComplete_*` (6 subtests, all passing) covering the uncovered handler paths flagged by Claude/cubic on round 3: missing-fields validation, session-does-not-belong-to-task ownership guard, terminal-session rejection (Completed/Failed/Cancelled), first-call happy path (bag persisted + bus payload shape pinned), dedup while RUNNING (no re-publish), and dedup while WAITING_FOR_INPUT (the retry-after-publish-failure path — must re-publish so the subscriber fires). - Reword the deferred-toggle comment to drop the YAML-export claim: the workflow export model doesn't yet serialize `auto_advance_requires_signal`, so MCP `update_workflow_step_kandev` is the only configuration path that round-trips today. Note the follow-up needs to extend the export schema alongside the UI toggle. * test(workflow): pin signaled_at + drop redundant GetTaskSession on bag-clear - Assert `signaled_at` is present and parses as RFC3339Nano in `TestHandleStepComplete_FirstCallAccepted`. The field is part of the handler's documented response contract; pinning it catches accidental drop/rename regressions. - Add `clearPendingStepSignalByID(ctx, sessionID)` as a thin DB-only variant of `clearPendingStepSignal` and use it from `executeStepTransition`, where the session struct isn't read after the clear. Avoids an extra `GetTaskSession` round-trip per transition. `clearPendingStepSignal(session)` still exists for the in-memory-mutation case (subscriber's stale-step path). * fix(workflow): subscriber stale-clear guard + ADR/comment drift fixes - onStepCompletionSignaled's stale-step path now reads the bag and only clears it when its current StepID matches the (stale) event's stepID. Previously the unconditional clear could destroy a valid signal that the new step's agent had just written when sessions are reused across steps without auto_start_agent. (Greptile P1.) - Drop the "feature flag" phrase from WorkflowStep.AutoAdvanceRequiresSignal docstring — leftover from an earlier draft. The gating is purely the boolean field; the global flag was removed two rounds ago. - Merge the two adjacent `if triggerOnEnter` blocks in executeStepTransition so the full triggerOnEnter=true path reads top- to-bottom in one place. (CodeRabbit + cubic.) - ADR 0015 Mechanism section: re-label the SessionStepHistory.Metadata audit annotation, the `step_complete_signaled` system message, and the expvar telemetry counters as deferred. They're planned shapes, not current behaviour — calling them "Audit" / "Chat visibility" / "Telemetry" in present tense was misleading for future readers. * fix(workflow): drop subscriber complexity + reload session on stale-clear - Extract `parseStepCompletionEvent` and `stepIsSignalGated` helpers from `onStepCompletionSignaled`. Cyclomatic complexity goes 17 → under 15 (cyclop on new code, CI lint regression after the round-6 stale-clear guard). - The stale-step branch now re-loads the session from the DB before deciding whether to clear the bag. The previous round-6 fix checked the local `session.Metadata` snapshot, which can be older than a concurrent write from the new step's agent — that check could see a stale signal that had since been overwritten with a valid one and erase the new bag entry. The narrower load-on-clear is cheap and closes the cubic P1 hole. (The broader race in `processOnTurnCompleteViaEngine` reading session.Metadata is the monotonic-marker open question in ADR 0015; out of scope here.) * test(workflow): pin stale-event guard's preserve-current-bag side + dedup StringFromAny - Add `TestOnStepCompletionSignaled` subtest "stale event → valid bag for CURRENT step is preserved" — fires a stale step-A event while the bag holds a valid step-B signal, asserts the bag still contains StepID=step_b after the subscriber runs. Pins the negative side of the round-6 `existing.StepID == stepID` guard, so a regression that drops or inverts the guard (and would silently leave signal-gated steps stuck) fails the test instead of slipping through. - Promote `pendingSignalString` to exported `models.StringFromAny` and reuse it from the orchestrator subscriber's `parseStepCompletionEvent`. Eliminates the byte-for-byte duplicate helper across the two packages; the bag-shape decoder and the bus- event decoder now share one source of truth for "missing string". --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
394 lines
15 KiB
Go
394 lines
15 KiB
Go
package mcp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kandev/kandev/internal/common/logger"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func newTestLogger(t *testing.T) *logger.Logger {
|
|
t.Helper()
|
|
log, err := logger.NewLogger(logger.LoggingConfig{Level: "error", Format: "console"})
|
|
require.NoError(t, err)
|
|
return log
|
|
}
|
|
|
|
// getRegisteredToolNames returns the names of all tools registered on the MCP server.
|
|
func getRegisteredToolNames(s *Server) []string {
|
|
toolsMap := s.mcpServer.ListTools()
|
|
names := make([]string, 0, len(toolsMap))
|
|
for name := range toolsMap {
|
|
names = append(names, name)
|
|
}
|
|
return names
|
|
}
|
|
|
|
func TestServerModeTask_RegistersCorrectTools(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeTask)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
|
|
// Task mode should have kanban tools
|
|
assert.Contains(t, tools, "list_workspaces_kandev")
|
|
assert.Contains(t, tools, "list_workflows_kandev")
|
|
assert.Contains(t, tools, "list_workflow_steps_kandev")
|
|
assert.Contains(t, tools, "list_tasks_kandev")
|
|
assert.Contains(t, tools, "create_task_kandev")
|
|
assert.Contains(t, tools, "update_task_kandev")
|
|
assert.Contains(t, tools, "move_task_kandev")
|
|
assert.Contains(t, tools, "message_task_kandev")
|
|
assert.Contains(t, tools, "get_task_conversation_kandev")
|
|
|
|
// Task mode should have plan tools
|
|
assert.Contains(t, tools, "create_task_plan_kandev")
|
|
assert.Contains(t, tools, "get_task_plan_kandev")
|
|
assert.Contains(t, tools, "update_task_plan_kandev")
|
|
assert.Contains(t, tools, "delete_task_plan_kandev")
|
|
|
|
// Task mode should have interaction tools
|
|
assert.Contains(t, tools, "ask_user_question_kandev")
|
|
|
|
// Task mode should have profile listing tools (needed for create_task)
|
|
assert.Contains(t, tools, "list_agents_kandev")
|
|
assert.Contains(t, tools, "list_executor_profiles_kandev")
|
|
|
|
// Task mode keeps list_related_tasks_kandev (sibling discovery) but
|
|
// drops the task-document tools — those are office-only.
|
|
assert.Contains(t, tools, "list_related_tasks_kandev")
|
|
assert.NotContains(t, tools, "list_task_documents_kandev")
|
|
assert.NotContains(t, tools, "get_task_document_kandev")
|
|
assert.NotContains(t, tools, "write_task_document_kandev")
|
|
|
|
// Task mode exposes delete + archive so agents can clean up the tasks
|
|
// they fan out. Restore/unarchive is intentionally NOT exposed via MCP —
|
|
// it stays a user action in the UI.
|
|
assert.Contains(t, tools, "delete_task_kandev")
|
|
assert.Contains(t, tools, "archive_task_kandev")
|
|
assert.NotContains(t, tools, "restore_task_kandev")
|
|
|
|
// Task mode should NOT have config/mutation tools
|
|
assert.NotContains(t, tools, "create_workflow_kandev")
|
|
assert.NotContains(t, tools, "update_workflow_kandev")
|
|
assert.NotContains(t, tools, "delete_workflow_kandev")
|
|
assert.NotContains(t, tools, "create_workflow_step_kandev")
|
|
assert.NotContains(t, tools, "update_workflow_step_kandev")
|
|
assert.NotContains(t, tools, "update_agent_kandev")
|
|
assert.NotContains(t, tools, "create_agent_profile_kandev")
|
|
assert.NotContains(t, tools, "delete_agent_profile_kandev")
|
|
assert.NotContains(t, tools, "list_agent_profiles_kandev")
|
|
assert.NotContains(t, tools, "update_agent_profile_kandev")
|
|
assert.NotContains(t, tools, "get_mcp_config_kandev")
|
|
assert.NotContains(t, tools, "update_mcp_config_kandev")
|
|
assert.NotContains(t, tools, "list_executors_kandev")
|
|
assert.NotContains(t, tools, "create_executor_profile_kandev")
|
|
assert.NotContains(t, tools, "update_executor_profile_kandev")
|
|
assert.NotContains(t, tools, "delete_executor_profile_kandev")
|
|
assert.NotContains(t, tools, "update_task_state_kandev")
|
|
assert.NotContains(t, tools, "delete_workflow_step_kandev")
|
|
assert.NotContains(t, tools, "reorder_workflow_steps_kandev")
|
|
}
|
|
|
|
func TestServerModeConfig_RegistersCorrectTools(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeConfig)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
|
|
// Config mode should have workflow config tools
|
|
assert.Contains(t, tools, "list_workspaces_kandev")
|
|
assert.Contains(t, tools, "list_workflows_kandev")
|
|
assert.Contains(t, tools, "list_repositories_kandev")
|
|
assert.Contains(t, tools, "create_workflow_kandev")
|
|
assert.Contains(t, tools, "update_workflow_kandev")
|
|
assert.Contains(t, tools, "delete_workflow_kandev")
|
|
assert.Contains(t, tools, "import_workflow_kandev")
|
|
assert.Contains(t, tools, "list_workflow_steps_kandev")
|
|
assert.Contains(t, tools, "create_workflow_step_kandev")
|
|
assert.Contains(t, tools, "update_workflow_step_kandev")
|
|
assert.Contains(t, tools, "delete_workflow_step_kandev")
|
|
assert.Contains(t, tools, "reorder_workflow_steps_kandev")
|
|
|
|
// Config mode should have agent tools
|
|
assert.Contains(t, tools, "list_agents_kandev")
|
|
assert.Contains(t, tools, "update_agent_kandev")
|
|
assert.Contains(t, tools, "create_agent_profile_kandev")
|
|
assert.Contains(t, tools, "delete_agent_profile_kandev")
|
|
|
|
// Config mode should have MCP config tools
|
|
assert.Contains(t, tools, "list_agent_profiles_kandev")
|
|
assert.Contains(t, tools, "update_agent_profile_kandev")
|
|
assert.Contains(t, tools, "get_mcp_config_kandev")
|
|
assert.Contains(t, tools, "update_mcp_config_kandev")
|
|
|
|
// Config mode should have executor profile tools
|
|
assert.Contains(t, tools, "list_executors_kandev")
|
|
assert.Contains(t, tools, "list_executor_profiles_kandev")
|
|
assert.Contains(t, tools, "create_executor_profile_kandev")
|
|
assert.Contains(t, tools, "update_executor_profile_kandev")
|
|
assert.Contains(t, tools, "delete_executor_profile_kandev")
|
|
|
|
// Config mode should have task tools
|
|
assert.Contains(t, tools, "list_tasks_kandev")
|
|
assert.Contains(t, tools, "move_task_kandev")
|
|
assert.Contains(t, tools, "delete_task_kandev")
|
|
assert.Contains(t, tools, "archive_task_kandev")
|
|
assert.Contains(t, tools, "update_task_state_kandev")
|
|
assert.Contains(t, tools, "get_task_conversation_kandev")
|
|
|
|
// Config mode should have interaction tools
|
|
assert.Contains(t, tools, "ask_user_question_kandev")
|
|
|
|
// Config mode should NOT have plan tools
|
|
assert.NotContains(t, tools, "create_task_plan_kandev")
|
|
assert.NotContains(t, tools, "get_task_plan_kandev")
|
|
assert.NotContains(t, tools, "update_task_plan_kandev")
|
|
assert.NotContains(t, tools, "delete_task_plan_kandev")
|
|
|
|
// Config mode should NOT have task-mode kanban create/update tools
|
|
assert.NotContains(t, tools, "create_task_kandev")
|
|
assert.NotContains(t, tools, "update_task_kandev")
|
|
}
|
|
|
|
func TestServerModeDefault_DefaultsToTask(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, "")
|
|
require.NotNil(t, s)
|
|
assert.Equal(t, ModeTask, s.mode)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
assert.Contains(t, tools, "create_task_kandev")
|
|
assert.Contains(t, tools, "create_task_plan_kandev")
|
|
assert.NotContains(t, tools, "create_workflow_step_kandev")
|
|
}
|
|
|
|
func TestServerModeConfig_DisableAskQuestion(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", true, ModeConfig)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
assert.NotContains(t, tools, "ask_user_question_kandev")
|
|
assert.Contains(t, tools, "list_agents_kandev")
|
|
assert.Contains(t, tools, "create_workflow_step_kandev")
|
|
}
|
|
|
|
func TestServerModeTask_DisableAskQuestion(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", true, ModeTask)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
assert.NotContains(t, tools, "ask_user_question_kandev")
|
|
assert.Contains(t, tools, "create_task_kandev")
|
|
assert.Contains(t, tools, "create_task_plan_kandev")
|
|
}
|
|
|
|
func TestServerModeTask_ToolCount(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeTask)
|
|
tools := getRegisteredToolNames(s)
|
|
// 13 kanban (incl. delete + archive task) + 1 add_branch_to_task +
|
|
// 1 update_repository_base_branch + 1 step_complete (ADR 0015) +
|
|
// 1 interaction + 4 plan + 1 related-tasks = 22. Task-document tools
|
|
// (list/get/write) are office-only.
|
|
assert.Contains(t, tools, "step_complete_kandev", "ADR 0015 explicit-completion signal must be registered in task mode")
|
|
assert.Equal(t, 22, len(tools))
|
|
}
|
|
|
|
func TestServerModeConfig_ToolCount(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeConfig)
|
|
tools := getRegisteredToolNames(s)
|
|
// 12 workflow (incl. list_repositories + import_workflow) + 4 agent + 4 mcp + 5 executor + 6 task + 1 interaction = 32
|
|
assert.NotContains(t, tools, "step_complete_kandev", "step_complete_kandev requires a live task session; must NOT register in config mode")
|
|
assert.Equal(t, 32, len(tools))
|
|
}
|
|
|
|
func TestServerModeConfig_ToolDescriptions(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeConfig)
|
|
|
|
toolsMap := s.mcpServer.ListTools()
|
|
|
|
assert.Contains(t, toolsMap["create_workflow_step_kandev"].Tool.Description, "Create a new workflow step")
|
|
assert.Contains(t, toolsMap["list_agents_kandev"].Tool.Description, "List all configured agents")
|
|
assert.Contains(t, toolsMap["get_mcp_config_kandev"].Tool.Description, "Get MCP server configuration")
|
|
}
|
|
|
|
func TestServerModeOffice_RegistersCorrectTools(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeOffice)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
|
|
// Office mode should have plan tools
|
|
assert.Contains(t, tools, "create_task_plan_kandev")
|
|
assert.Contains(t, tools, "get_task_plan_kandev")
|
|
assert.Contains(t, tools, "update_task_plan_kandev")
|
|
assert.Contains(t, tools, "delete_task_plan_kandev")
|
|
|
|
// Office mode should have interaction tools
|
|
assert.Contains(t, tools, "ask_user_question_kandev")
|
|
|
|
// delegate_task_kandev was removed from ModeOffice when the
|
|
// agentctl CLI started covering task creation/delegation via
|
|
// `agentctl kandev task create --parent $KANDEV_TASK_ID …`.
|
|
assert.NotContains(t, tools, "delegate_task_kandev")
|
|
|
|
// Office mode exposes the cross-task handoff tools.
|
|
assert.Contains(t, tools, "list_related_tasks_kandev")
|
|
assert.Contains(t, tools, "list_task_documents_kandev")
|
|
assert.Contains(t, tools, "get_task_document_kandev")
|
|
assert.Contains(t, tools, "write_task_document_kandev")
|
|
|
|
// Office mode should NOT have kanban tools
|
|
assert.NotContains(t, tools, "create_task_kandev")
|
|
assert.NotContains(t, tools, "list_tasks_kandev")
|
|
assert.NotContains(t, tools, "update_task_kandev")
|
|
assert.NotContains(t, tools, "list_workspaces_kandev")
|
|
assert.NotContains(t, tools, "list_workflows_kandev")
|
|
assert.NotContains(t, tools, "list_workflow_steps_kandev")
|
|
assert.NotContains(t, tools, "list_agents_kandev")
|
|
assert.NotContains(t, tools, "list_executor_profiles_kandev")
|
|
|
|
// Office mode should NOT have config tools
|
|
assert.NotContains(t, tools, "create_workflow_kandev")
|
|
assert.NotContains(t, tools, "update_workflow_kandev")
|
|
assert.NotContains(t, tools, "update_agent_kandev")
|
|
}
|
|
|
|
func TestServerModeOffice_ToolCount(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", false, ModeOffice)
|
|
tools := getRegisteredToolNames(s)
|
|
// 4 plan + 1 interaction + 1 related-tasks + 3 task-documents = 9
|
|
// (delegate_task_kandev retired in favour of `agentctl kandev task create …`).
|
|
assert.NotContains(t, tools, "step_complete_kandev", "step_complete_kandev is kanban-task-only; office mode advances tasks via its own approval surface")
|
|
assert.Equal(t, 9, len(tools))
|
|
}
|
|
|
|
func TestServerModeOffice_DisableAskQuestion(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "test-session", "test-task", 10005, log, "", true, ModeOffice)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
assert.NotContains(t, tools, "ask_user_question_kandev")
|
|
assert.Contains(t, tools, "create_task_plan_kandev")
|
|
// delegate_task_kandev was retired from ModeOffice (now lives in
|
|
// the agentctl CLI as `agentctl kandev task create --parent …`).
|
|
assert.NotContains(t, tools, "delegate_task_kandev")
|
|
// 4 plan + 1 related-tasks + 3 task-documents = 8 (no ask_user_question, no delegate)
|
|
assert.Equal(t, 8, len(tools))
|
|
}
|
|
|
|
func TestServerModeConstants(t *testing.T) {
|
|
assert.Equal(t, "task", ModeTask)
|
|
assert.Equal(t, "config", ModeConfig)
|
|
assert.Equal(t, "external", ModeExternal)
|
|
assert.Equal(t, "office", ModeOffice)
|
|
}
|
|
|
|
func TestServerModeExternal_RegistersCorrectTools(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "", "", 0, log, "", true, ModeExternal)
|
|
require.NotNil(t, s)
|
|
|
|
tools := getRegisteredToolNames(s)
|
|
|
|
// External mode includes all config tools
|
|
assert.Contains(t, tools, "list_workspaces_kandev")
|
|
assert.Contains(t, tools, "list_repositories_kandev")
|
|
assert.Contains(t, tools, "create_workflow_kandev")
|
|
assert.Contains(t, tools, "list_agents_kandev")
|
|
assert.Contains(t, tools, "get_mcp_config_kandev")
|
|
assert.Contains(t, tools, "list_executors_kandev")
|
|
assert.Contains(t, tools, "move_task_kandev")
|
|
|
|
// External mode includes create_task_kandev so external agents can spawn tasks
|
|
assert.Contains(t, tools, "create_task_kandev")
|
|
|
|
// External mode does NOT include session-scoped tools
|
|
assert.NotContains(t, tools, "ask_user_question_kandev")
|
|
assert.NotContains(t, tools, "create_task_plan_kandev")
|
|
assert.NotContains(t, tools, "get_task_plan_kandev")
|
|
assert.NotContains(t, tools, "update_task_plan_kandev")
|
|
assert.NotContains(t, tools, "delete_task_plan_kandev")
|
|
|
|
// External mode does NOT include kanban update_task_kandev (config has its own update_task_state)
|
|
assert.NotContains(t, tools, "update_task_kandev")
|
|
|
|
// External mode does NOT include message_task_kandev (no live session context)
|
|
assert.NotContains(t, tools, "message_task_kandev")
|
|
}
|
|
|
|
func TestServerModeExternal_ToolCount(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := New(backend, "", "", 0, log, "", true, ModeExternal)
|
|
tools := getRegisteredToolNames(s)
|
|
// 12 workflow (incl. list_repositories + import_workflow) + 4 agent + 4 mcp + 5 executor + 6 task + 1 create_task = 32.
|
|
// add_branch_to_task_kandev is task-mode only — external coding agents have no live session to attach a worktree to.
|
|
assert.Equal(t, 32, len(tools))
|
|
assert.NotContains(t, tools, "add_branch_to_task_kandev")
|
|
}
|
|
|
|
func TestNewExternal_Constructs(t *testing.T) {
|
|
log := newTestLogger(t)
|
|
backend := NewChannelBackendClient(log)
|
|
defer backend.Close()
|
|
|
|
s := NewExternal(backend, "http://localhost:38429", log, "")
|
|
require.NotNil(t, s)
|
|
assert.Equal(t, ModeExternal, s.mode)
|
|
assert.True(t, s.disableAskQuestion)
|
|
assert.Empty(t, s.sessionID)
|
|
assert.Empty(t, s.taskID)
|
|
assert.NotNil(t, s.sseServer)
|
|
assert.NotNil(t, s.httpServer)
|
|
}
|