Skip to content

fix(quality): clear pre-existing ruff/format/mypy debt to make Quality Gates real - #2

Merged
cloudQuant merged 8 commits into
masterfrom
fix/quality-gate-debt
Aug 23, 2026
Merged

fix(quality): clear pre-existing ruff/format/mypy debt to make Quality Gates real#2
cloudQuant merged 8 commits into
masterfrom
fix/quality-gate-debt

Conversation

@cloudQuant

Copy link
Copy Markdown
Owner

背景

Quality Gates 从未真正执行过(旧 tests.yml 只触发于不存在的 main/develop,B3)。PR #1 落地治理基线后首次全仓运行,暴露历史债务:

  • ruff: 627 项(569 自动修复:W291×578、UP017、UP045、RUF100 等;手动修复 E701×16、F841、B905、UP042、TC002、F821)
  • ruff format: 44 文件
  • mypy: 73 项/14 文件(mixin 属性注解、陈旧测试属性、Optional 收窄、定向 type-ignore)

关键修复

F821 真实 bug(非风格问题)

ensemble_model.py_update_weights_based_on_performance 调用了 f1_score(...),但该名字在兄弟方法 _update_model_weights 中被局部浮点变量遮蔽、本方法作用域内未导入——运行时会抛 TypeError。已在方法内补齐 from sklearn.metrics import f1_score(与 _evaluate_ensemble 同模式)。

附带

验证

ruff check bt_api_py tests        # All checks passed
ruff format --check bt_api_py tests  # 180 files already formatted
mypy bt_api_py tests --ignore-missing-imports  # Success: no issues in 180 files
bandit -r bt_api_py -c pyproject.toml  # High: 0
pytest tests/test_bt_api_quality.py tests/test_forwarding_schema.py tests/unit/scripts/ tests/test_bt_api_plugin_integration.py -q  # 43 passed

本地基线全套件:628+ passed,覆盖率 74.98%(门槛 40%)。

risk:r1 — 触及 risk_management/mixin 类型注解与一处运行时导入修复;无行为语义变更(F821 修复使原本必然崩溃的路径恢复可用)。

cloudQuant and others added 8 commits August 23, 2026 15:49
Quality Gates never ran before (workflow triggered only on nonexistent
main/develop), so lint and type debt accumulated silently:

- ruff: auto-fix 577 items (trailing whitespace, datetime.UTC, unused
  imports/noqa); manual fixes for E701, F841, B905, UP042 (StrEnum),
  TC002, and an F821 root-cause bug where _update_weights_based_on_
  performance called an f1_score that was shadowed by a local float in
  a sibling method (would raise TypeError at runtime)
- format: normalize 44 files via ruff format
- mypy: annotate mixin-expected attributes in risk_management mixins;
  fix stale test attribute sets; narrow Optional types; targeted
  type-ignore comments only where tests intentionally pass invalid
  input to assert validation behavior
…n plan

Track the v2 implementation/acceptance plan referenced by
docs/governance/decision-log.md as its decision source, following the
existing docs(plan) convention so the audit chain stays inside version
control.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
The mypy-driven stubs added to MarketRiskMixin shadowed the real
implementations in PositionRiskMixin (MRO order), making
_calculate_position_concentration/_calculate_sector_exposure/_serialize_metrics
return None at runtime and crashing MarketRiskMetrics construction.
Move the cross-mixin orchestrator _calculate_market_risk into
RiskCalculator, where all mixin methods are legitimately visible.

Also skip repository-baseline and plugin-discovery tests when submodules
or plugin packages are absent (CI checks out neither).
@cloudQuant
cloudQuant merged commit b26e6bc into master Aug 23, 2026
20 checks passed
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