test: add redacted Qoder protocol recorder and replays
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
This commit is contained in:
co-authored by
Simon Shi
parent
1eee02455c
commit
6d5cdfd171
@@ -0,0 +1,47 @@
|
||||
# Qoder protocol replay fixtures
|
||||
|
||||
These JSON files preserve the four protocol interactions used by this provider:
|
||||
|
||||
1. PAT to job-token exchange
|
||||
2. userinfo/identity lookup
|
||||
3. model catalog
|
||||
4. streaming chat (including Qoder's outer SSE envelope and JSON-string `body`)
|
||||
|
||||
`sample-global.json` and `sample-cn.json` are deliberately hand-authored examples,
|
||||
identified by `"source": "sample"` and `"recordedAt": null`. They are not claimed
|
||||
to be captures of live traffic. Offline unit tests replay these files so the same
|
||||
format produced by the live recorder is always exercised.
|
||||
|
||||
## Re-recording
|
||||
|
||||
Use Node 24 or newer and provide both regional PATs:
|
||||
|
||||
```sh
|
||||
QODER_PAT=... QODERCN_PAT=... npm run test:live
|
||||
```
|
||||
|
||||
Long-form aliases are also accepted:
|
||||
|
||||
- Global: `QODER_PAT`, `QODER_PERSONAL_ACCESS_TOKEN`, or `QODER_API_KEY`
|
||||
- China: `QODERCN_PAT`, `QODERCN_PERSONAL_ACCESS_TOKEN`, or `QODERCN_API_KEY`
|
||||
|
||||
To record one region while diagnosing credentials, pass `--region`:
|
||||
|
||||
```sh
|
||||
npm run test:live -- --region global
|
||||
npm run test:live -- --region cn
|
||||
```
|
||||
|
||||
By default the command requires and records both regions. It exits non-zero
|
||||
before making any request when a required PAT is missing. A successful run
|
||||
writes `recorded-global.json` and/or `recorded-cn.json` in this directory.
|
||||
|
||||
Review every generated file before committing it. The recorder removes
|
||||
authorization, cookies, COSY keys/signatures, PATs, job/refresh tokens, emails,
|
||||
user IDs, machine IDs, names, and request/session/chat IDs. It retains
|
||||
non-sensitive protocol headers, response schema, model metadata, and SSE
|
||||
framing. A final leak check rejects the output if it still resembles a token,
|
||||
email address, Authorization header, cookie, or COSY signature material.
|
||||
|
||||
The recorder uses a temporary `HOME`, never writes credentials to the repository,
|
||||
and does not modify the normal `~/.pi` cache.
|
||||
@@ -0,0 +1,120 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"source": "sample",
|
||||
"region": "cn",
|
||||
"recordedAt": null,
|
||||
"interactions": {
|
||||
"patExchange": {
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "https://openapi.qoder.com.cn/api/v1/jobToken/exchange",
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"cosy-version": "1.0.1",
|
||||
"cosy-clienttype": "5"
|
||||
},
|
||||
"body": {
|
||||
"personal_token": "<redacted:pat>"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"token": "<redacted:job-token>",
|
||||
"refresh_token": "<redacted:refresh-token>",
|
||||
"expires_in": 86400000
|
||||
}
|
||||
}
|
||||
},
|
||||
"userinfo": {
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://openapi.qoder.com.cn/api/v1/userinfo",
|
||||
"headers": {
|
||||
"accept": "application/json",
|
||||
"cosy-version": "1.0.1",
|
||||
"cosy-clienttype": "5"
|
||||
},
|
||||
"body": null
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"id": "<redacted:user-id>",
|
||||
"email": "<redacted:email>",
|
||||
"name": "<redacted:name>"
|
||||
}
|
||||
}
|
||||
},
|
||||
"modelList": {
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://gateway.qoder.com.cn/algo/api/v2/model/list",
|
||||
"headers": {
|
||||
"accept": "application/json",
|
||||
"cosy-version": "1.1.38",
|
||||
"cosy-clienttype": "5"
|
||||
},
|
||||
"body": null
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"chat": [
|
||||
{
|
||||
"key": "qmodel",
|
||||
"enable": true,
|
||||
"display_name": "Qwen3.7 Plus",
|
||||
"context_config": {
|
||||
"200K": {
|
||||
"token_count": 200000
|
||||
},
|
||||
"1M": {
|
||||
"token_count": 1000000,
|
||||
"is_default": true
|
||||
}
|
||||
},
|
||||
"is_reasoning": true,
|
||||
"source": "system"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "https://gateway.qoder.com.cn/algo/api/v2/chat",
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"accept": "text/event-stream",
|
||||
"cosy-version": "1.1.38",
|
||||
"cosy-clienttype": "5",
|
||||
"x-model-key": "qmodel",
|
||||
"x-model-source": "system"
|
||||
},
|
||||
"body": {
|
||||
"encoding": "qoder-waf",
|
||||
"byteLength": 512,
|
||||
"value": "<redacted:encoded-request-body>"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "text/event-stream"
|
||||
},
|
||||
"body": "data:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"{\\\"choices\\\":[{\\\"delta\\\":{\\\"content\\\":\\\"OK\\\",\\\"role\\\":\\\"assistant\\\"},\\\"index\\\":0}],\\\"created\\\":1,\\\"id\\\":\\\"<redacted:request-id>\\\",\\\"model\\\":\\\"qmodel\\\",\\\"object\\\":\\\"chat.completion.chunk\\\"}\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\ndata:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"{\\\"choices\\\":[{\\\"finish_reason\\\":\\\"stop\\\",\\\"index\\\":0}],\\\"created\\\":1,\\\"id\\\":\\\"<redacted:request-id>\\\",\\\"model\\\":\\\"qmodel\\\",\\\"object\\\":\\\"chat.completion.chunk\\\",\\\"usage\\\":{\\\"completion_tokens\\\":1,\\\"prompt_tokens\\\":10,\\\"total_tokens\\\":11}}\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\ndata:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"[DONE]\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"source": "sample",
|
||||
"region": "global",
|
||||
"recordedAt": null,
|
||||
"interactions": {
|
||||
"patExchange": {
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "https://openapi.qoder.sh/api/v1/jobToken/exchange",
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"cosy-version": "1.0.1",
|
||||
"cosy-clienttype": "5"
|
||||
},
|
||||
"body": {
|
||||
"personal_token": "<redacted:pat>"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"token": "<redacted:job-token>",
|
||||
"refresh_token": "<redacted:refresh-token>",
|
||||
"expires_in": 86400000
|
||||
}
|
||||
}
|
||||
},
|
||||
"userinfo": {
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://openapi.qoder.sh/api/v1/userinfo",
|
||||
"headers": {
|
||||
"accept": "application/json",
|
||||
"cosy-version": "1.0.1",
|
||||
"cosy-clienttype": "5"
|
||||
},
|
||||
"body": null
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"id": "<redacted:user-id>",
|
||||
"email": "<redacted:email>",
|
||||
"name": "<redacted:name>"
|
||||
}
|
||||
}
|
||||
},
|
||||
"modelList": {
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "https://api3.qoder.sh/algo/api/v2/model/list",
|
||||
"headers": {
|
||||
"accept": "application/json",
|
||||
"cosy-version": "1.1.38",
|
||||
"cosy-clienttype": "5"
|
||||
},
|
||||
"body": null
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
"body": {
|
||||
"chat": [
|
||||
{
|
||||
"key": "lite",
|
||||
"enable": true,
|
||||
"display_name": "Lite",
|
||||
"max_input_tokens": 180000,
|
||||
"is_reasoning": false,
|
||||
"source": "system"
|
||||
},
|
||||
{
|
||||
"key": "gm51model",
|
||||
"enable": true,
|
||||
"display_name": "GLM 5.2",
|
||||
"context_config": {
|
||||
"default": {
|
||||
"token_count": 200000,
|
||||
"is_default": true
|
||||
}
|
||||
},
|
||||
"is_reasoning": true,
|
||||
"source": "system"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "https://api3.qoder.sh/algo/api/v2/chat",
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"accept": "text/event-stream",
|
||||
"cosy-version": "1.1.38",
|
||||
"cosy-clienttype": "5",
|
||||
"x-model-key": "lite",
|
||||
"x-model-source": "system"
|
||||
},
|
||||
"body": {
|
||||
"encoding": "qoder-waf",
|
||||
"byteLength": 512,
|
||||
"value": "<redacted:encoded-request-body>"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "text/event-stream"
|
||||
},
|
||||
"body": "data:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"{\\\"choices\\\":[{\\\"delta\\\":{\\\"role\\\":\\\"assistant\\\"},\\\"index\\\":0}],\\\"created\\\":1,\\\"id\\\":\\\"<redacted:request-id>\\\",\\\"model\\\":\\\"lite\\\",\\\"object\\\":\\\"chat.completion.chunk\\\"}\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\ndata:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"{\\\"choices\\\":[{\\\"delta\\\":{\\\"content\\\":\\\"OK\\\",\\\"role\\\":\\\"assistant\\\"},\\\"index\\\":0}],\\\"created\\\":1,\\\"id\\\":\\\"<redacted:request-id>\\\",\\\"model\\\":\\\"lite\\\",\\\"object\\\":\\\"chat.completion.chunk\\\"}\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\ndata:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"{\\\"choices\\\":[{\\\"finish_reason\\\":\\\"stop\\\",\\\"index\\\":0}],\\\"created\\\":1,\\\"id\\\":\\\"<redacted:request-id>\\\",\\\"model\\\":\\\"lite\\\",\\\"object\\\":\\\"chat.completion.chunk\\\",\\\"usage\\\":{\\\"completion_tokens\\\":1,\\\"prompt_tokens\\\":10,\\\"total_tokens\\\":11}}\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\ndata:{\"headers\":{\"Content-Type\":[\"application/json\"]},\"body\":\"[DONE]\",\"statusCodeValue\":200,\"statusCode\":\"OK\"}\n\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user