Skip to content

Commit 3a270cc

Browse files
authored
Merge pull request #10 from 4xian/feat_test
feat: 新增环境变量,API有效性测试
2 parents 2e11132 + d9c68f8 commit 3a270cc

File tree

14 files changed

+672
-573
lines changed

14 files changed

+672
-573
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ src/*
22
rollup.config.js
33
.*
44
logs/*
5-
node_modules
5+
node_modules
6+
*.map

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ ccapi -v
4141
初次使用需要设置 Claude Code 的 settings.json 文件路径和自定义API配置文件路径:
4242

4343
```bash
44-
例如:
45-
# 同时设置两个路径
44+
# windows 默认settings.json路径在 C:\Users\Administrator\.claude\settings.json
45+
# mac 默认settings.json路径在 ~/.claude/settings.json
46+
47+
# 1. 示例: mac同时设置两个路径
4648
ccapi set --settings ~/.claude/settings.json --api /Users/4xian/Desktop/api.json5
4749

48-
# 分别设置
50+
# 2. 分别设置
4951
ccapi set --settings ~/.claude/settings.json
5052
ccapi set --api /Users/4xian/Desktop/api.json5
5153

52-
# 直接在配置文件中修改路径
54+
# 3. 直接在配置文件中修改路径
5355
~/.ccapi-config.json 文件中(与.claude同级),有存储路径的变量,直接修改即可
5456
{
5557
"settingsPath": "~/.claude/settings.json",
@@ -65,7 +67,7 @@ ccapi set
6567
支持多种配置文件格式:**JSON、JSON5、YAML、TOML**
6668
创建一个配置文件(如 `api.json``api.yaml``api.json5``api.toml`),格式如下:
6769

68-
**JSON 格式示例:**
70+
**JSON5 格式示例:**
6971

7072
```json5
7173
{
@@ -284,29 +286,40 @@ ccapi ping openrouter
284286

285287
### 8. 测试API可用性
286288

287-
测试中转站API配置在Cluade Code中是否可用,可以真实的反映出配置是否有效
289+
测试中转站API配置在Claude Code中是否可用,可以真实的反映出配置是否有效
288290

289291
```bash
290292
# 测试所有配置
291293
ccapi test
292294
293295
# 测试指定配置
294296
ccapi test openrouter
297+
298+
# 使用 Claude Code CLI 方式测试(更准确,但速度较慢)
299+
ccapi test -c
300+
ccapi test -c openrouter
295301
```
296302

297-
**测试说明:**
303+
**测试方式说明:**
304+
305+
- **默认方式**:使用接口模拟方式,直接模拟Claude CLI请求,速度快,准确性较高(部分厂商只允许在cli中调用,会出现不允许调用的情况,这种时候你可忽略结果,默认为成功)
306+
- **CLI方式**(`-c` 选项):使用真实的Claude Code CLI环境,准确度最高,可能会出现调用各种mcp服务情况,速度较慢(1分钟左右)
307+
308+
**配置说明:**
298309

299310
- **ping测试超时时间**:默认为5秒,可在 ~/.ccapi-config.json 文件中新增变量控制超时,如:pingTimeout: 5000
300-
- **test测试超时时间**:默认为60秒,可在 ~/.ccapi-config.json 文件中新增变量控制超时,如:testTimeout: 60000 (该测试由于需要等待Claude Code响应,时间可能稍长,超时时间建议设置大点)
301-
- **测试返回的结果**:默认不显示,由于厂商不同,返回结果仅供参考,可在 ~/.ccapi-config.json 文件中新增变量是否显示结果,如:testResponse: true
311+
- **test测试超时时间**:默认为30秒(接口模拟方式)或 100秒(CLI方式),可在 ~/.ccapi-config.json 文件中新增变量控制超时,如:testTimeout: 30000
312+
- **测试返回的结果**:默认显示,由于厂商不同,返回结果仅供参考,可在 ~/.ccapi-config.json 文件中新增变量是否显示结果,如:testResponse: true
313+
- **test cli模式测试并发**:默认为3,cli模式测试由于消耗性能较高,采用分批测试,若测试结果全部都超时,建议数值小点,超时时间拉长
302314

303315
```json5
304316
{
305317
"settingsPath": "~/.claude/settings.json",
306318
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
307319
"pingTimeout": 5000,
308-
"testTimeout": 60000,
309-
"testResponse": false
320+
"testTimeout": 30000,
321+
"testResponse": true,
322+
"testConcurrency": 3
310323
}
311324
```
312325

@@ -441,11 +454,11 @@ ccapi lang en
441454
# api配置文件路径
442455
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
443456
# ping命令超时时间
444-
"pingTimeout": 5000,
457+
"pingTimeout": 30000,
445458
# test命令超时时间
446-
"testTimeout": 80000,
459+
"testTimeout": 100000,
447460
# ping、test命令返回结果显示
448-
"testResponse": false,
461+
"testResponse": true,
449462
# 是否需要更新提示
450463
"update": true,
451464
# 使用use命令时是否同步修改系统环境变量

README_EN.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ First-time use requires setting the path to Claude Code's settings.json file and
4242

4343
```bash
4444
Examples:
45-
# Set both paths simultaneously
45+
# windows default path: C:\Users\Administrator\.claude\settings.json
46+
# mac default path: ~/.claude/settings.json
47+
48+
# mac: Set both paths simultaneously
4649
ccapi set --settings ~/.claude/settings.json --api /Users/4xian/Desktop/api.json5
4750

4851
# Set them separately
@@ -65,7 +68,7 @@ ccapi set
6568
Supports multiple configuration file formats: **JSON, JSON5, YAML, TOML**
6669
Create a configuration file (such as `api.json`, `api.yaml`, `api.json5` or `api.toml`) with the following format:
6770

68-
**JSON Format Example:**
71+
**JSON5 Format Example:**
6972

7073
```json5
7174
{
@@ -287,29 +290,43 @@ ccapi ping openrouter
287290
Test whether gateway API configurations are available in Claude Code, which can truly reflect whether configurations are effective
288291

289292
```bash
290-
# Test all configurations
293+
# Test all configurations (default uses API mock method, fast)
291294
ccapi test
292295
293-
# Test specific configuration
296+
# Test specific configuration (default uses API mock method)
294297
ccapi test openrouter
298+
299+
# Use Claude Code CLI method for testing (more accurate but slower)
300+
ccapi test -c
301+
ccapi test -c openrouter
302+
303+
# Test using specific Key or Token index
304+
ccapi test openrouter -k 1 # Use 1st Key
305+
ccapi test openrouter -t 2 # Use 2nd Token
295306
```
296307

297-
**Test Description:**
308+
**Test Method Description:**
309+
310+
- **Default Method**: Uses API mock method, directly simulates Claude CLI request headers, fast (2-3 seconds), supports retry mechanism
311+
- **CLI Method** (`-c` option): Uses real Claude Code CLI environment, highest accuracy but slower (40-50 seconds)
312+
313+
**Configuration Description:**
298314

299315
- **ping test timeout**: Defaults to 5 seconds, can be controlled by adding timeout variable in ~/.ccapi-config.json file, e.g.: pingTimeout: 5000
300-
- **test timeout**: Defaults to 60 seconds, can be controlled by adding timeout variable in ~/.ccapi-config.json file, e.g.: testTimeout: 60000 (This test requires waiting for Claude Code response, may take longer, recommended to set timeout higher)
301-
- **Test result response**: Not displayed by default. Since different providers return different results, response results are for reference only. Can enable result display by adding variable in ~/.ccapi-config.json file, e.g.: testResponse: true
316+
- **test timeout**: Defaults to 30 seconds (API mock method) or 60 seconds (CLI method), can be controlled by adding timeout variable in ~/.ccapi-config.json file, e.g.: testTimeout: 30000
317+
- **Test result response**: Displayed by default. Since different providers return different results, response results are for reference only. Can enable result display by adding variable in ~/.ccapi-config.json file, e.g.: testResponse: true
318+
- **Test concurrency in cli mode**: The default value is 3. Due to the high performance consumption of cli mode testing, batch testing is adopted. If all test results are timed out, it is recommended to set a smaller value and extend the timeout period.
302319

303320
```json5
304321
{
305322
"settingsPath": "~/.claude/settings.json",
306323
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
307324
"pingTimeout": 5000,
308-
"testTimeout": 60000,
309-
"testResponse": false
325+
"testTimeout": 30000,
326+
"testResponse": true,
327+
"testConcurrency": 3
310328
}
311329
```
312-
313330
- For array format URLs, all URL addresses will be tested, array configuration URLs will not be sorted by latency internally, maintaining original URL order
314331
- Configurations sorted by best latency, lowest latency configurations appear first
315332
- Shows optimal route (fastest URL address) for each configuration
@@ -442,10 +459,10 @@ This file is the configuration file used by ccapi, where you can configure optio
442459
"apiConfigPath": "/Users/4xian/Desktop/api.json5",
443460
# ping command timeout
444461
"pingTimeout": 5000,
445-
# test command timeout
446-
"testTimeout": 80000,
462+
# test command timeout (default 30s for API mock method, 60s for CLI method)
463+
"testTimeout": 30000,
447464
# ping, test command result display
448-
"testResponse": false,
465+
"testResponse": true,
449466
# whether update prompts are needed
450467
"update": true,
451468
# whether to synchronously modify system environment variables when using use command

dist/index.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)