Skip to content

Commit 7a09bbb

Browse files
committed
chore(repo): isolate default tests and add live-agent CI / 隔离默认测试并新增 live-agent CI
EN: Isolate the default test entrypoint in scripts/test.mjs by clearing live agent provider variables before node --test starts, and add a cross-platform npm run test:live-agent script for explicit provider-backed runs. Add GitHub Actions workflows that keep main CI on npm test while exposing a manual live-agent workflow wired to repository secrets, and document the two paths in the README so contributors know which gate is deterministic. ZH: 在 scripts/test.mjs 中隔离默认测试入口,在启动 node --test 前清理 live agent 相关环境变量,并新增跨平台的 npm run test:live-agent 脚本,供显式的外部 provider 验证使用。 新增 GitHub Actions workflow:主 CI 继续只跑 npm test,另外提供一个 依赖仓库 secrets 的手动 live-agent workflow;同时在 README 中补充两条 测试路径的说明,明确默认门禁与真实集成验证的边界。
1 parent a3f171e commit 7a09bbb

5 files changed

Lines changed: 110 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 20
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 24
22+
cache: npm
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Typecheck
28+
run: npm run typecheck
29+
30+
- name: Run isolated test suite
31+
run: npm test
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Live Agent Tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
live-agent:
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 30
10+
env:
11+
CODEXBRIDGE_AGENT_API_KEY: ${{ secrets.CODEXBRIDGE_AGENT_API_KEY }}
12+
CODEXBRIDGE_AGENT_BASE_URL: ${{ secrets.CODEXBRIDGE_AGENT_BASE_URL }}
13+
CODEXBRIDGE_AGENT_API: ${{ secrets.CODEXBRIDGE_AGENT_API }}
14+
CODEXBRIDGE_AGENT_MODEL: ${{ secrets.CODEXBRIDGE_AGENT_MODEL }}
15+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
16+
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
17+
OPENAI_API_BASE_URL: ${{ secrets.OPENAI_API_BASE_URL }}
18+
OPENAI_MODEL: ${{ secrets.OPENAI_MODEL }}
19+
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 24
29+
cache: npm
30+
31+
- name: Verify live-agent credentials are configured
32+
run: |
33+
if [ -z "${CODEXBRIDGE_AGENT_API_KEY}" ] && [ -z "${OPENAI_API_KEY}" ] && [ -z "${MINIMAX_API_KEY}" ]; then
34+
echo "Missing live-agent credentials. Configure CODEXBRIDGE_AGENT_API_KEY, OPENAI_API_KEY, or MINIMAX_API_KEY as GitHub Actions secrets."
35+
exit 1
36+
fi
37+
38+
- name: Install dependencies
39+
run: npm ci
40+
41+
- name: Typecheck
42+
run: npm run typecheck
43+
44+
- name: Run live-agent test suite
45+
run: npm run test:live-agent

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ npm test
311311

312312
The validation suite is expected to pass on both Linux and Windows.
313313

314+
`npm test` is the isolated default test entrypoint. It clears live agent provider variables such as `CODEXBRIDGE_AGENT_*`, `OPENAI_*`, and `MINIMAX_API_KEY` before starting `node --test`, so unit and integration tests stay deterministic even when the host shell, CI runner, or service manager exports real model credentials.
315+
316+
When you intentionally want to keep live agent credentials and exercise the real external agent path, use the explicit opt-in script instead:
317+
318+
```bash
319+
npm run test:live-agent
320+
```
321+
322+
Keep `test:live-agent` separate from the main suite. It is for deliberate provider-backed verification, not for the default `npm test` gate.
323+
314324
## Deployment Quick Start
315325

316326
### Common Prerequisites
@@ -343,6 +353,7 @@ If `codex --version` still fails, fix that before attempting `weixin:login` or `
343353
npm install
344354
npm run typecheck
345355
npm test
356+
npm run test:live-agent
346357
codex --version
347358
npm run weixin:login
348359
npm run weixin:serve -- --cwd /absolute/path/to/workspace
@@ -358,6 +369,7 @@ Open PowerShell in the repo root and run:
358369
npm install
359370
npm run typecheck
360371
npm test
372+
npm run test:live-agent
361373
codex --version
362374
where codex
363375
npm run weixin:login

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"weixin:login": "tsx src/cli.ts weixin login",
1313
"weixin:clear-context": "tsx src/cli.ts weixin clear-context",
1414
"weixin:serve": "tsx src/cli.ts weixin serve",
15-
"test": "node ./scripts/test.mjs"
15+
"test": "node ./scripts/test.mjs",
16+
"test:live-agent": "node --input-type=module -e \"process.env.CODEXBRIDGE_TEST_ALLOW_LIVE_AGENT='1'; await import('./scripts/test.mjs');\""
1617
},
1718
"engines": {
1819
"node": ">=24"

scripts/test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ import { spawnSync } from 'node:child_process';
55
const distTestDir = path.join(process.cwd(), 'dist', 'test');
66
fs.rmSync(distTestDir, { recursive: true, force: true });
77

8+
const LIVE_AGENT_TEST_ENV_FLAG = 'CODEXBRIDGE_TEST_ALLOW_LIVE_AGENT';
9+
const isolatedEnv = { ...process.env };
10+
11+
if (isolatedEnv[LIVE_AGENT_TEST_ENV_FLAG] !== '1') {
12+
for (const key of [
13+
'CODEXBRIDGE_AGENT_API_KEY',
14+
'CODEXBRIDGE_AGENT_BASE_URL',
15+
'CODEXBRIDGE_AGENT_API',
16+
'CODEXBRIDGE_AGENT_MODEL',
17+
'OPENAI_API_KEY',
18+
'OPENAI_BASE_URL',
19+
'OPENAI_API_BASE_URL',
20+
'OPENAI_MODEL',
21+
'MINIMAX_API_KEY',
22+
]) {
23+
delete isolatedEnv[key];
24+
}
25+
}
26+
827
function collectTestFiles(dir) {
928
const entries = fs.readdirSync(dir, { withFileTypes: true });
1029
const files = [];
@@ -25,6 +44,7 @@ const testArgs =
2544
process.argv.length > 2 ? process.argv.slice(2) : collectTestFiles(path.join(process.cwd(), 'test'));
2645

2746
const result = spawnSync(process.execPath, ['--import', 'tsx', '--test', ...testArgs], {
47+
env: isolatedEnv,
2848
stdio: 'inherit',
2949
});
3050

0 commit comments

Comments
 (0)