集成测试
TradingCopilot 在 internal/integration 下包含可选集成测试。正常执行 go test ./... 时这些测试会被跳过,只有设置匹配的 TC_INTEGRATION_* 环境变量时才会运行。
不要提交真实 API key、token、Telegram hash、session 载荷、数据库 dump 或本地 .env 文件。
Redis / asynq
bash
TC_INTEGRATION_REDIS=1 go test ./internal/integration -run TestRedisAsynqIntegrationHarness -v -count=1如需验证消费者级处理:
bash
TC_INTEGRATION_REDIS=1 TC_REDIS_CONSUMER_E2E=1 go test ./internal/integration -run TestRedisAsynqIntegrationHarness -v -count=1PostgreSQL / TimescaleDB
bash
TC_INTEGRATION_POSTGRES=1 TC_REQUIRE_TIMESCALE=1 go test ./internal/integration -run TestPostgresTimescaleSchemaInitHarness -v -count=1该检查会执行数据库自动迁移和 Timescale 设置。
行情提供方
bash
TC_INTEGRATION_MARKET=1 TC_MARKET_PROVIDER=adata TC_MARKET_CODE=600519 go test ./internal/integration -run TestMarketProviderIntegrationHarness -v -count=1Tushare 路径需要额外 token 和账户权限。
AI 提供方
bash
TC_INTEGRATION_AI=1 \
TC_AI_BASE_URL="<openai-compatible-base-url>" \
TC_AI_API_KEY="<api-key>" \
TC_AI_MODEL="<model>" \
go test ./internal/integration -run TestAIProviderIntegrationHarness -v -count=1该检查会发送非流式 OpenAI 兼容 chat 请求,并验证响应解析、重试行为和模型选择。
Telegram MTProto
bash
go run ./cmd/tradingcopilot message-subscription-login-start -app-id "<app_id>" -app-hash "<app_hash>" -phone "<phone>"
go run ./cmd/tradingcopilot message-subscription-login-verify -code "<telegram_code>"登录后测试频道引用:
bash
go run ./cmd/tradingcopilot message-subscription-mtproto-test -channel "@public_channel"集成检查:
bash
TC_INTEGRATION_TELEGRAM=1 \
TC_TELEGRAM_USE_DATABASE=1 \
TC_TELEGRAM_CHANNEL_REF="@public_channel" \
go test ./internal/integration -run TestTelegramMTProtoIntegrationHarness -v -count=1