Skip to content

Commit 8c3b86d

Browse files
CrazyBoyMclaude
andcommitted
feat(test): add comprehensive CI agent test suite
- Add streamlined ci-agent.test.ts with 10 essential tests for CI - Add comprehensive-agent.test.ts with 38 tests for thorough coverage - Fix .env.test priority to override process.env variables - Add reasoningTransport: 'text' for Zhipu API compatibility - Update CI workflow with comprehensive agent tests stage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9b84765 commit 8c3b86d

5 files changed

Lines changed: 1575 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,37 +168,58 @@ jobs:
168168
- name: Create test environment
169169
run: |
170170
cat > .env.test << 'EOF'
171-
# Use OpenAI for integration tests (most reliable)
172-
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
173-
OPENAI_MODEL_ID=${{ vars.OPENAI_MODEL_ID }}
174-
OPENAI_BASE_URL=${{ vars.OPENAI_BASE_URL }}
175-
OPENAI_API=chat
176-
177-
# Anthropic backup
171+
# Use Anthropic-compatible API for integration tests
178172
ANTHROPIC_API_KEY=${{ secrets.ANTHROPIC_API_KEY }}
179173
ANTHROPIC_MODEL_ID=${{ vars.ANTHROPIC_MODEL_ID }}
180174
ANTHROPIC_BASE_URL=${{ vars.ANTHROPIC_BASE_URL }}
181-
182-
# Gemini backup
183-
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
184-
GEMINI_MODEL_ID=${{ vars.GEMINI_MODEL_ID }}
185-
GEMINI_BASE_URL=${{ vars.GEMINI_BASE_URL }}
186175
EOF
187176
188177
- name: Run Agent Integration Tests
189178
run: npx ts-node tests/integration/agent/ci-integration.test.ts
190179
env:
191-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
192180
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
193-
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
181+
182+
# ===========================================================================
183+
# Stage 4: Comprehensive Agent Tests (deep agent workflow testing)
184+
# ===========================================================================
185+
comprehensive-agent-tests:
186+
name: Comprehensive Agent Tests
187+
runs-on: ubuntu-latest
188+
needs: [agent-integration]
189+
timeout-minutes: 45
190+
191+
steps:
192+
- uses: actions/checkout@v4
193+
194+
- name: Setup Node.js
195+
uses: actions/setup-node@v4
196+
with:
197+
node-version: ${{ env.NODE_VERSION }}
198+
cache: 'npm'
199+
200+
- name: Install dependencies
201+
run: npm ci
202+
203+
- name: Create test environment
204+
run: |
205+
cat > .env.test << 'EOF'
206+
ANTHROPIC_API_KEY=${{ secrets.ANTHROPIC_API_KEY }}
207+
ANTHROPIC_MODEL_ID=${{ vars.ANTHROPIC_MODEL_ID }}
208+
ANTHROPIC_BASE_URL=${{ vars.ANTHROPIC_BASE_URL }}
209+
EOF
210+
211+
- name: Run Comprehensive Agent Tests
212+
run: npx ts-node --transpileOnly tests/integration/agent/ci-agent.test.ts
213+
env:
214+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
194215

195216
# ===========================================================================
196217
# Summary job
197218
# ===========================================================================
198219
ci-summary:
199220
name: CI Summary
200221
runs-on: ubuntu-latest
201-
needs: [lint-and-typecheck, unit-tests, provider-e2e, agent-integration]
222+
needs: [lint-and-typecheck, unit-tests, provider-e2e, agent-integration, comprehensive-agent-tests]
202223
if: always()
203224
steps:
204225
- name: Check results
@@ -208,11 +229,13 @@ jobs:
208229
echo "Unit Tests: ${{ needs.unit-tests.result }}"
209230
echo "Provider E2E: ${{ needs.provider-e2e.result }}"
210231
echo "Agent Integration: ${{ needs.agent-integration.result }}"
232+
echo "Comprehensive Agent Tests: ${{ needs.comprehensive-agent-tests.result }}"
211233
212234
if [ "${{ needs.lint-and-typecheck.result }}" == "failure" ] || \
213235
[ "${{ needs.unit-tests.result }}" == "failure" ] || \
214236
[ "${{ needs.provider-e2e.result }}" == "failure" ] || \
215-
[ "${{ needs.agent-integration.result }}" == "failure" ]; then
237+
[ "${{ needs.agent-integration.result }}" == "failure" ] || \
238+
[ "${{ needs.comprehensive-agent-tests.result }}" == "failure" ]; then
216239
echo "Some tests failed!"
217240
exit 1
218241
fi

tests/helpers/fixtures.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,22 @@ export interface IntegrationConfig {
4343

4444
/**
4545
* 加载集成测试配置
46+
* 注意:.env.test 文件配置优先于环境变量,确保测试配置可控
4647
*/
4748
export function loadIntegrationConfig(): IntegrationConfig {
4849
let envConfig: Record<string, string> = {};
4950

5051
if (fs.existsSync(ENV_PATH)) {
5152
envConfig = parseEnvFile(ENV_PATH);
53+
// .env.test 配置强制覆盖 process.env,确保测试使用文件配置
54+
for (const [key, value] of Object.entries(envConfig)) {
55+
process.env[key] = value;
56+
}
5257
}
5358

59+
// .env.test 优先于 process.env
5460
const get = (key: string): string | undefined => {
55-
const val = process.env[key] || envConfig[key];
61+
const val = envConfig[key] || process.env[key];
5662
return val?.trim() || undefined;
5763
};
5864

tests/helpers/setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ export async function createIntegrationTestAgent(options: IntegrationTestAgentOp
165165
modelFactory: (config) => new AnthropicProvider(
166166
config.apiKey!,
167167
config.model,
168-
config.baseUrl ?? apiConfig.baseUrl
168+
config.baseUrl ?? apiConfig.baseUrl,
169+
undefined,
170+
{ reasoningTransport: 'text' }
169171
),
170172
};
171173

0 commit comments

Comments
 (0)