coding-proxy 0.1.4a5__tar.gz → 0.1.4a6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of coding-proxy might be problematic. Click here for more details.
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/PKG-INFO +1 -1
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/pyproject.toml +1 -1
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/cli/__init__.py +15 -12
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/logging/stats.py +29 -2
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_cli_usage.py +22 -4
- coding_proxy-0.1.4a6/tests/test_time_range.py +120 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/uv.lock +1 -1
- coding_proxy-0.1.4a5/tests/test_time_range.py +0 -48
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/.github/workflows/ci.yml +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/.github/workflows/coverage.yml +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/.github/workflows/promote.yml +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/.github/workflows/release.yml +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/.gitignore +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/AGENTS.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/CHANGELOG.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/CLAUDE.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/LICENSE +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/README.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/docs/ci-cd.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/docs/framework.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/docs/user-guide.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/docs/zh-CN/README.md +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/__main__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/providers/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/providers/base.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/providers/github.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/providers/google.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/runtime.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/auth/store.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/cli/auth_commands.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/cli/banner.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/compat/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/compat/canonical.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/compat/session_store.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/auth_schema.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/config.default.yaml +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/loader.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/resiliency.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/routing.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/schema.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/server.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/config/vendors.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/anthropic_to_gemini.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/anthropic_to_openai.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/gemini_sse_adapter.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/gemini_to_anthropic.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/openai_to_anthropic.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/logging/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/logging/db.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/auth.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/compat.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/constants.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/pricing.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/token.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/model/vendor.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/pricing.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/circuit_breaker.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/error_classifier.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/executor.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/model_mapper.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/quota_guard.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/rate_limit.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/retry.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/router.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/session_manager.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/tier.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/usage_parser.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/routing/usage_recorder.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/server/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/server/app.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/server/factory.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/server/request_normalizer.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/server/responses.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/server/routes.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/streaming/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/streaming/anthropic_compat.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/anthropic.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/antigravity.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/base.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/copilot.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/copilot_models.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/copilot_token_manager.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/copilot_urls.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/mixins.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/token_manager.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/zhipu.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/__init__.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_antigravity.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_app_routes.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_auto_login.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_banner.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_circuit_breaker.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_compat.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_config_init.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_config_loader.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_convert_request.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_convert_response.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_convert_sse.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_copilot.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_copilot_convert_request.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_copilot_convert_response.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_copilot_models.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_copilot_urls.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_currency.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_error_classifier.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_mixins.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_auth.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_compat.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_constants.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_mapper.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_pricing.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_token.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_model_vendor.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_parse_usage.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_pricing.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_quota_guard.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_rate_limit.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_request_normalizer.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_router_chain.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_router_executor.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_runtime_reauth.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_schema.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_streaming_anthropic_compat.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_tier.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_tiers_config.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_token_logger.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_token_manager.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_types.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_vendor_streaming.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_vendors.py +0 -0
- {coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/tests/test_zhipu.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: coding-proxy
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4a6
|
|
4
4
|
Summary: A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM.
|
|
5
5
|
Project-URL: Source Code, https://github.com/ThreeFish-AI/coding-proxy
|
|
6
6
|
Project-URL: User Guide, https://github.com/ThreeFish-AI/coding-proxy/blob/master/docs/user-guide.md
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "coding-proxy"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.4a6"
|
|
4
4
|
description = "A High-Availability, Transparent, and Smart Multi-Vendor Proxy for Claude Code. Support Claude Plans, GitHub Copilot, Google Antigravity, ZAI/GLM."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -51,8 +51,8 @@ def _build_token_store(cfg_path: Path | None = None):
|
|
|
51
51
|
def _resolve_period(
|
|
52
52
|
*,
|
|
53
53
|
days: int = 7,
|
|
54
|
-
week:
|
|
55
|
-
month:
|
|
54
|
+
week: int | None = None,
|
|
55
|
+
month: int | None = None,
|
|
56
56
|
total: bool = False,
|
|
57
57
|
) -> tuple[TimePeriod, int]:
|
|
58
58
|
"""将互斥的时间维度标志解析为 (TimePeriod, count) 元组.
|
|
@@ -60,15 +60,14 @@ def _resolve_period(
|
|
|
60
60
|
优先级: ``-t`` > ``-m`` > ``-w`` > ``-d``。
|
|
61
61
|
|
|
62
62
|
Returns:
|
|
63
|
-
``(period, count)`` 元组。``count``
|
|
64
|
-
``WEEK`` / ``MONTH`` / ``TOTAL`` 维度始终使用 count=1。
|
|
63
|
+
``(period, count)`` 元组。``count`` 表示查询最近第 N 个周期的数据。
|
|
65
64
|
"""
|
|
66
65
|
if total:
|
|
67
66
|
return TimePeriod.TOTAL, 1
|
|
68
|
-
if month:
|
|
69
|
-
return TimePeriod.MONTH, 1
|
|
70
|
-
if week:
|
|
71
|
-
return TimePeriod.WEEK, 1
|
|
67
|
+
if month is not None:
|
|
68
|
+
return TimePeriod.MONTH, max(1, month)
|
|
69
|
+
if week is not None:
|
|
70
|
+
return TimePeriod.WEEK, max(1, week)
|
|
72
71
|
return TimePeriod.DAY, max(1, days)
|
|
73
72
|
|
|
74
73
|
|
|
@@ -143,8 +142,12 @@ def status(
|
|
|
143
142
|
@app.command()
|
|
144
143
|
def usage(
|
|
145
144
|
days: int = typer.Option(7, "--days", "-d", help="统计天数(与 -w/-m/-t 互斥)"),
|
|
146
|
-
week:
|
|
147
|
-
|
|
145
|
+
week: int | None = typer.Option(
|
|
146
|
+
None, "--week", "-w", help="最近第 N 周统计(按周聚合,默认 1)"
|
|
147
|
+
),
|
|
148
|
+
month: int | None = typer.Option(
|
|
149
|
+
None, "--month", "-m", help="最近第 N 月统计(按月聚合,默认 1)"
|
|
150
|
+
),
|
|
148
151
|
total: bool = typer.Option(False, "--total", "-t", help="统计全部历史记录"),
|
|
149
152
|
vendor: str | None = typer.Option(None, "--vendor", "-v", help="过滤供应商"),
|
|
150
153
|
model: str | None = typer.Option(None, "--model", help="过滤请求模型"),
|
|
@@ -156,8 +159,8 @@ def usage(
|
|
|
156
159
|
|
|
157
160
|
\b
|
|
158
161
|
-d 7 最近 7 天(默认,按日聚合)
|
|
159
|
-
-w
|
|
160
|
-
-m
|
|
162
|
+
-w [N] 最近第 N 周(按周聚合,默认 1=本周)
|
|
163
|
+
-m [N] 最近第 N 月(按月聚合,默认 1=本月)
|
|
161
164
|
-t 全部历史(按供应商+模型聚合)
|
|
162
165
|
"""
|
|
163
166
|
period, count = _resolve_period(days=days, week=week, month=month, total=total)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from datetime import datetime, timedelta
|
|
5
6
|
from typing import TYPE_CHECKING
|
|
6
7
|
|
|
7
8
|
from rich.console import Console
|
|
@@ -23,12 +24,38 @@ _PERIOD_TITLES: dict[TimePeriod, str] = {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
|
|
27
|
+
def _week_date_range(count: int) -> str:
|
|
28
|
+
"""计算最近第 count 周的周一~周日日期范围字符串.
|
|
29
|
+
|
|
30
|
+
count=1 表示本周,count=2 表示上周,以此类推。
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
格式为 ``YYYY-MM-DD ~ YYYY-MM-DD`` 的日期范围字符串。
|
|
34
|
+
"""
|
|
35
|
+
today = datetime.now().date()
|
|
36
|
+
# 本周周一
|
|
37
|
+
this_monday = today - timedelta(days=today.weekday())
|
|
38
|
+
# 目标周的周一
|
|
39
|
+
target_monday = this_monday - timedelta(weeks=count - 1)
|
|
40
|
+
target_sunday = target_monday + timedelta(days=6)
|
|
41
|
+
return (
|
|
42
|
+
f"{target_monday.strftime('%Y-%m-%d')} ~ {target_sunday.strftime('%Y-%m-%d')}"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
26
46
|
def _build_title(period: TimePeriod, count: int) -> str:
|
|
27
|
-
"""根据时间维度构建表格标题.
|
|
47
|
+
"""根据时间维度构建表格标题.
|
|
48
|
+
|
|
49
|
+
WEEK 维度会附加具体日期范围(如 ``2026-04-07 ~ 2026-04-13``),
|
|
50
|
+
其他维度仅显示统计周期标签。
|
|
51
|
+
"""
|
|
28
52
|
if period is TimePeriod.TOTAL:
|
|
29
53
|
return "Token 使用统计(全部)"
|
|
30
54
|
label = _PERIOD_TITLES[period]
|
|
31
|
-
|
|
55
|
+
base = f"Token 使用统计(最近 {count} {label}"
|
|
56
|
+
if period is TimePeriod.WEEK:
|
|
57
|
+
base += f":{_week_date_range(count)}"
|
|
58
|
+
return base + ")"
|
|
32
59
|
|
|
33
60
|
|
|
34
61
|
# ── 格式化工具 ───────────────────────────────────────────────
|
|
@@ -160,20 +160,38 @@ class TestTimeDimensionFlags:
|
|
|
160
160
|
|
|
161
161
|
def test_week_flag(self, _isolate_cli_deps):
|
|
162
162
|
mock_show = _isolate_cli_deps
|
|
163
|
-
result = runner.invoke(app, ["usage", "-w"])
|
|
163
|
+
result = runner.invoke(app, ["usage", "-w", "1"])
|
|
164
164
|
assert result.exit_code == 0
|
|
165
165
|
kw = _kwargs(mock_show)
|
|
166
166
|
assert kw["period"] == TimePeriod.WEEK
|
|
167
167
|
assert kw["count"] == 1
|
|
168
168
|
|
|
169
|
+
def test_week_flag_count(self, _isolate_cli_deps):
|
|
170
|
+
"""``-w 3`` 应查询最近 3 周."""
|
|
171
|
+
mock_show = _isolate_cli_deps
|
|
172
|
+
result = runner.invoke(app, ["usage", "-w", "3"])
|
|
173
|
+
assert result.exit_code == 0
|
|
174
|
+
kw = _kwargs(mock_show)
|
|
175
|
+
assert kw["period"] == TimePeriod.WEEK
|
|
176
|
+
assert kw["count"] == 3
|
|
177
|
+
|
|
169
178
|
def test_month_flag(self, _isolate_cli_deps):
|
|
170
179
|
mock_show = _isolate_cli_deps
|
|
171
|
-
result = runner.invoke(app, ["usage", "-m"])
|
|
180
|
+
result = runner.invoke(app, ["usage", "-m", "1"])
|
|
172
181
|
assert result.exit_code == 0
|
|
173
182
|
kw = _kwargs(mock_show)
|
|
174
183
|
assert kw["period"] == TimePeriod.MONTH
|
|
175
184
|
assert kw["count"] == 1
|
|
176
185
|
|
|
186
|
+
def test_month_flag_count(self, _isolate_cli_deps):
|
|
187
|
+
"""``-m 2`` 应查询最近 2 月."""
|
|
188
|
+
mock_show = _isolate_cli_deps
|
|
189
|
+
result = runner.invoke(app, ["usage", "-m", "2"])
|
|
190
|
+
assert result.exit_code == 0
|
|
191
|
+
kw = _kwargs(mock_show)
|
|
192
|
+
assert kw["period"] == TimePeriod.MONTH
|
|
193
|
+
assert kw["count"] == 2
|
|
194
|
+
|
|
177
195
|
def test_total_flag(self, _isolate_cli_deps):
|
|
178
196
|
mock_show = _isolate_cli_deps
|
|
179
197
|
result = runner.invoke(app, ["usage", "-t"])
|
|
@@ -192,7 +210,7 @@ class TestTimeDimensionFlags:
|
|
|
192
210
|
def test_week_with_vendor(self, _isolate_cli_deps):
|
|
193
211
|
"""时间维度可与 --vendor 组合使用."""
|
|
194
212
|
mock_show = _isolate_cli_deps
|
|
195
|
-
result = runner.invoke(app, ["usage", "-w", "-v", "anthropic"])
|
|
213
|
+
result = runner.invoke(app, ["usage", "-w", "1", "-v", "anthropic"])
|
|
196
214
|
assert result.exit_code == 0
|
|
197
215
|
kw = _kwargs(mock_show)
|
|
198
216
|
assert kw["period"] == TimePeriod.WEEK
|
|
@@ -209,7 +227,7 @@ class TestTimeDimensionFlags:
|
|
|
209
227
|
def test_month_overrides_week(self, _isolate_cli_deps):
|
|
210
228
|
"""-m 优先级高于 -w."""
|
|
211
229
|
mock_show = _isolate_cli_deps
|
|
212
|
-
result = runner.invoke(app, ["usage", "-w", "-m"])
|
|
230
|
+
result = runner.invoke(app, ["usage", "-w", "1", "-m", "1"])
|
|
213
231
|
assert result.exit_code == 0
|
|
214
232
|
kw = _kwargs(mock_show)
|
|
215
233
|
assert kw["period"] == TimePeriod.MONTH
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""stats 模块纯函数单元测试 — _build_title / _period_to_days / _week_date_range."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from datetime import datetime, timedelta
|
|
5
|
+
|
|
6
|
+
from coding.proxy.logging.db import TimePeriod
|
|
7
|
+
from coding.proxy.logging.stats import (
|
|
8
|
+
_build_title,
|
|
9
|
+
_period_to_days,
|
|
10
|
+
_week_date_range,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
# ── _week_date_range ─────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestWeekDateRange:
|
|
17
|
+
"""_week_date_range 计算正确的周一~周日范围."""
|
|
18
|
+
|
|
19
|
+
def test_this_week_contains_today(self):
|
|
20
|
+
"""count=1 应包含今天."""
|
|
21
|
+
today = datetime.now().date()
|
|
22
|
+
range_str = _week_date_range(1)
|
|
23
|
+
# 解析起止日期
|
|
24
|
+
parts = range_str.split(" ~ ")
|
|
25
|
+
start = datetime.strptime(parts[0], "%Y-%m-%d").date()
|
|
26
|
+
end = datetime.strptime(parts[1], "%Y-%m-%d").date()
|
|
27
|
+
assert start <= today <= end
|
|
28
|
+
|
|
29
|
+
def test_this_week_starts_on_monday(self):
|
|
30
|
+
"""count=1 的起始日期应为周一."""
|
|
31
|
+
range_str = _week_date_range(1)
|
|
32
|
+
start_str = range_str.split(" ~ ")[0]
|
|
33
|
+
start = datetime.strptime(start_str, "%Y-%m-%d").date()
|
|
34
|
+
assert start.weekday() == 0 # Monday
|
|
35
|
+
|
|
36
|
+
def test_this_week_ends_on_sunday(self):
|
|
37
|
+
"""count=1 的结束日期应为周日."""
|
|
38
|
+
range_str = _week_date_range(1)
|
|
39
|
+
end_str = range_str.split(" ~ ")[1]
|
|
40
|
+
end = datetime.strptime(end_str, "%Y-%m-%d").date()
|
|
41
|
+
assert end.weekday() == 6 # Sunday
|
|
42
|
+
|
|
43
|
+
def test_last_week(self):
|
|
44
|
+
"""count=2 应为上周."""
|
|
45
|
+
today = datetime.now().date()
|
|
46
|
+
this_monday = today - timedelta(days=today.weekday())
|
|
47
|
+
last_monday = this_monday - timedelta(weeks=1)
|
|
48
|
+
last_sunday = last_monday + timedelta(days=6)
|
|
49
|
+
|
|
50
|
+
range_str = _week_date_range(2)
|
|
51
|
+
parts = range_str.split(" ~ ")
|
|
52
|
+
start = datetime.strptime(parts[0], "%Y-%m-%d").date()
|
|
53
|
+
end = datetime.strptime(parts[1], "%Y-%m-%d").date()
|
|
54
|
+
assert start == last_monday
|
|
55
|
+
assert end == last_sunday
|
|
56
|
+
|
|
57
|
+
def test_span_is_seven_days(self):
|
|
58
|
+
"""周范围应始终为 7 天."""
|
|
59
|
+
for count in (1, 2, 5):
|
|
60
|
+
range_str = _week_date_range(count)
|
|
61
|
+
parts = range_str.split(" ~ ")
|
|
62
|
+
start = datetime.strptime(parts[0], "%Y-%m-%d").date()
|
|
63
|
+
end = datetime.strptime(parts[1], "%Y-%m-%d").date()
|
|
64
|
+
assert (end - start).days == 6
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# ── _build_title ──────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class TestBuildTitle:
|
|
71
|
+
"""_build_title 根据时间维度生成语义化标题."""
|
|
72
|
+
|
|
73
|
+
def test_day_title(self):
|
|
74
|
+
assert _build_title(TimePeriod.DAY, 7) == "Token 使用统计(最近 7 日)"
|
|
75
|
+
|
|
76
|
+
def test_day_title_single(self):
|
|
77
|
+
assert _build_title(TimePeriod.DAY, 1) == "Token 使用统计(最近 1 日)"
|
|
78
|
+
|
|
79
|
+
def test_month_title(self):
|
|
80
|
+
assert _build_title(TimePeriod.MONTH, 3) == "Token 使用统计(最近 3 月)"
|
|
81
|
+
|
|
82
|
+
def test_total_title(self):
|
|
83
|
+
assert _build_title(TimePeriod.TOTAL, 1) == "Token 使用统计(全部)"
|
|
84
|
+
|
|
85
|
+
def test_week_title_contains_date_range(self):
|
|
86
|
+
"""WEEK 维度标题应包含具体日期范围."""
|
|
87
|
+
title = _build_title(TimePeriod.WEEK, 1)
|
|
88
|
+
# 格式: Token 使用统计(最近 1 周:YYYY-MM-DD ~ YYYY-MM-DD)
|
|
89
|
+
assert title.startswith("Token 使用统计(最近 1 周:")
|
|
90
|
+
assert title.endswith(")")
|
|
91
|
+
assert re.search(r"\d{4}-\d{2}-\d{2} ~ \d{4}-\d{2}-\d{2}", title)
|
|
92
|
+
|
|
93
|
+
def test_week_title_multi_count(self):
|
|
94
|
+
"""WEEK 维度 count>1 也应包含日期范围."""
|
|
95
|
+
title = _build_title(TimePeriod.WEEK, 4)
|
|
96
|
+
assert title.startswith("Token 使用统计(最近 4 周:")
|
|
97
|
+
assert re.search(r"\d{4}-\d{2}-\d{2} ~ \d{4}-\d{2}-\d{2}", title)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# ── _period_to_days ───────────────────────────────────────────
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TestPeriodToDays:
|
|
104
|
+
"""_period_to_days 将 TimePeriod 近似转换为天数."""
|
|
105
|
+
|
|
106
|
+
def test_day(self):
|
|
107
|
+
assert _period_to_days(TimePeriod.DAY, 7) == 7
|
|
108
|
+
|
|
109
|
+
def test_day_clamps_to_one(self):
|
|
110
|
+
assert _period_to_days(TimePeriod.DAY, 0) == 1
|
|
111
|
+
|
|
112
|
+
def test_week(self):
|
|
113
|
+
assert _period_to_days(TimePeriod.WEEK, 2) == 14
|
|
114
|
+
|
|
115
|
+
def test_month(self):
|
|
116
|
+
# 粗略近似:31 * count
|
|
117
|
+
assert _period_to_days(TimePeriod.MONTH, 3) == 93
|
|
118
|
+
|
|
119
|
+
def test_total_returns_none(self):
|
|
120
|
+
assert _period_to_days(TimePeriod.TOTAL, 1) is None
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"""stats 模块纯函数单元测试 — _build_title / _period_to_days."""
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
from coding.proxy.logging.db import TimePeriod
|
|
6
|
-
from coding.proxy.logging.stats import _build_title, _period_to_days
|
|
7
|
-
|
|
8
|
-
# ── _build_title ──────────────────────────────────────────────
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TestBuildTitle:
|
|
12
|
-
"""_build_title 根据时间维度生成语义化标题."""
|
|
13
|
-
|
|
14
|
-
@pytest.mark.parametrize(
|
|
15
|
-
("period", "count", "expected"),
|
|
16
|
-
[
|
|
17
|
-
(TimePeriod.DAY, 7, "Token 使用统计(最近 7 日)"),
|
|
18
|
-
(TimePeriod.DAY, 1, "Token 使用统计(最近 1 日)"),
|
|
19
|
-
(TimePeriod.WEEK, 4, "Token 使用统计(最近 4 周)"),
|
|
20
|
-
(TimePeriod.MONTH, 3, "Token 使用统计(最近 3 月)"),
|
|
21
|
-
(TimePeriod.TOTAL, 1, "Token 使用统计(全部)"),
|
|
22
|
-
],
|
|
23
|
-
)
|
|
24
|
-
def test_title_format(self, period, count, expected):
|
|
25
|
-
assert _build_title(period, count) == expected
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
# ── _period_to_days ───────────────────────────────────────────
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class TestPeriodToDays:
|
|
32
|
-
"""_period_to_days 将 TimePeriod 近似转换为天数."""
|
|
33
|
-
|
|
34
|
-
def test_day(self):
|
|
35
|
-
assert _period_to_days(TimePeriod.DAY, 7) == 7
|
|
36
|
-
|
|
37
|
-
def test_day_clamps_to_one(self):
|
|
38
|
-
assert _period_to_days(TimePeriod.DAY, 0) == 1
|
|
39
|
-
|
|
40
|
-
def test_week(self):
|
|
41
|
-
assert _period_to_days(TimePeriod.WEEK, 2) == 14
|
|
42
|
-
|
|
43
|
-
def test_month(self):
|
|
44
|
-
# 粗略近似:31 * count
|
|
45
|
-
assert _period_to_days(TimePeriod.MONTH, 3) == 93
|
|
46
|
-
|
|
47
|
-
def test_total_returns_none(self):
|
|
48
|
-
assert _period_to_days(TimePeriod.TOTAL, 1) is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/anthropic_to_gemini.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/anthropic_to_openai.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/gemini_sse_adapter.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/gemini_to_anthropic.py
RENAMED
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/convert/openai_to_anthropic.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/streaming/anthropic_compat.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coding_proxy-0.1.4a5 → coding_proxy-0.1.4a6}/src/coding/proxy/vendors/copilot_token_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|