Testing

April 7, 2026 · View on GitHub

Unit Tests

# Run all tests
go test ./...

# Run tests with coverage
go test ./... -cover

Integration Tests

Integration tests exercise the full MCP handler workflow (add → list → get → execute → get_task_result) for both shell command and AI task types.

# Run integration tests only
go test ./internal/server/ -run TestIntegration -v

AI Integration Tests

AI task execution tests require API keys and are skipped by default. Enable them with environment variables:

# Run with OpenAI (requires OPENAI_API_KEY)
MCP_CRON_ENABLE_OPENAI_TESTS=true go test ./...

# Run with Anthropic (requires ANTHROPIC_API_KEY)
MCP_CRON_ENABLE_ANTHROPIC_TESTS=true go test ./...

What the Integration Tests Cover

TestDescription
TestIntegration_ShellCommandFullLifecycleAdd, list, get, execute, and retrieve result for a shell command task
TestIntegration_AITaskFullLifecycleFull CRUD + execution for an AI task (execution gated behind env var)
TestIntegration_EnableDisableFlowEnable/disable toggling and idempotency
TestIntegration_ShellCommandFailureVerifies failed commands produce correct error results
TestIntegration_ErrorCasesTable-driven tests for missing fields and not-found errors
TestIntegration_MultipleTasksIsolationExecuting one task does not affect other tasks' results
TestIntegration_OnDemandTaskCreate and execute an on-demand task (no schedule)
TestIntegration_RunTaskrun_task handler: disabled task error, enable + sync run with result, not-found, missing ID
TestIntegration_OnDemandAITaskCreate an on-demand AI task and verify type/schedule
TestIntegration_OnDemandRunTaskLifecycleFull on-demand lifecycle via poll loop (shell + AI subtests)
TestIntegration_ScheduledRunTaskResumesSchedulerun_task on a scheduled task resumes its cron schedule after execution (shell + AI subtests)
TestIntegration_AITaskGetTaskResultAI task calls internal get_task_result to access prior execution output
TestRunTaskIntegration_InternalGetTaskResult_MCPNamespaceOpenAI model discovers get_task_result from system message alone (no tool name in prompt)
TestRunTaskIntegration_InternalGetTaskResult_MCPNamespaceAnthropicAnthropic model discovers get_task_result from system message alone
TestRunTaskIntegrationOpenAI AI task execution with config-based setup
TestRunTaskIntegrationAnthropicAnthropic AI task execution with config-based setup
TestRunTaskIntegrationListToolsAI task lists available MCP tools (OpenAI + Anthropic subtests)
TestIntegration_QueryTaskResultquery_task_result handler with SQL queries (JOIN across tasks and results)
TestIntegration_QueryTaskResultRejectsNonSelectNon-SELECT queries are rejected
TestIntegration_QueryTaskResultTruncationResults exceeding 1000 rows return truncation warning
TestStopWaitsForInFlightTasksScheduler Stop() blocks until in-flight task goroutines complete
TestSchedulerContinuesAfterTransportExitScheduler poll loop keeps running after MCP transport exits (stdin EOF)

Linting

go tool golangci-lint run

golangci-lint is installed as a Go tool dependency in go.mod.