Skip to content

fix(cliproxy): 对齐 /v0/management/logs 真实契约,修复部署后 502#200

Merged
g1331 merged 1 commit into
masterfrom
hotfix/cliproxy-logs-contract
May 31, 2026
Merged

fix(cliproxy): 对齐 /v0/management/logs 真实契约,修复部署后 502#200
g1331 merged 1 commit into
masterfrom
hotfix/cliproxy-logs-contract

Conversation

@g1331

@g1331 g1331 commented May 31, 2026

Copy link
Copy Markdown
Owner

Summary

部署后 GET /api/admin/cliproxy/instances/:id/logs 返回 502。经 deepwiki 核对 CLIProxyAPI 源码,真实接口契约与本仓库实现不一致:

  • 查询参数为 limit + after(Unix 秒),不是 since(ISO 字符串)
  • 响应为 { lines: string[], "line-count": number, "latest-timestamp": number },不是日志条目数组
  • 上游要求 CLIProxyAPI 启用 LoggingToFile,否则返回 400(被 AutoRouter 客户端原样吞掉再映射成 502,错误原因丢失)

Changes

  • 类型:CliproxyLogEntry 替换为 CliproxyLogsResult / CliproxyLogsQuery,service / route / hook / panel 全部跟改
  • 管理 API 客户端读取上游错误正文并拼接到 CliproxyManagementApiError.message,让 "logging to file is disabled" 等具体原因能透传给用户
  • 日志面板改为渲染原始日志行字符串,按行内关键字(ERROR / WARN / INFO / DEBUG)启发式上色
  • 测试:management-client / instance-logs-service / logs API route / use-cliproxy / logs panel 全部对齐新契约,并新增上游 400 错误正文透传断言

Test plan

  • pnpm exec tsc --noEmit
  • pnpm lint
  • pnpm test:run(168 文件、2646 通过、1 skip)
  • CI 全绿
  • 部署后从浏览器实际打开实例日志面板验证

Fixes 部署后观察到的 GET /api/admin/cliproxy/instances/<id>/logs 502

CLIProxyAPI 真实接口契约:

- 查询参数为 limit + after(Unix 秒),不是 since(ISO 字符串)
- 响应为 { lines: string[], "line-count": number, "latest-timestamp": number },不是日志条目数组
- 上游要求 LoggingToFile 启用,否则返回 400

对此做端到端对齐:

- CliproxyLogEntry 类型替换为 CliproxyLogsResult / CliproxyLogsQuery,service / route / hook / panel 全部跟改
- 管理 API 客户端读上游错误正文并拼到 CliproxyManagementApiError.message,让 LoggingToFile 关闭等具体原因能透传到 502 响应
- 日志面板改为渲染原始日志行字符串,按行内关键字(ERROR / WARN / INFO / DEBUG)启发式上色
- 测试同步:management-client / instance-logs-service / logs API route / use-cliproxy / logs panel 全部对齐新契约,并新增 400 错误正文透传断言
@g1331 g1331 merged commit de6385b into master May 31, 2026
10 checks passed
@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.78571% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (4cbec49) to head (425c13b).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #200      +/-   ##
==========================================
+ Coverage   74.41%   74.44%   +0.02%     
==========================================
  Files         160      160              
  Lines       11595    11624      +29     
  Branches     3965     3980      +15     
==========================================
+ Hits         8628     8653      +25     
- Misses       1727     1731       +4     
  Partials     1240     1240              
Flag Coverage Δ
verify 74.44% <76.78%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@g1331 g1331 deleted the hotfix/cliproxy-logs-contract branch May 31, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant