Skip to content

refactor(arch): split strategy_plugins monolith and add ruff/mutmut - #811

Merged
Pigbibi merged 7 commits into
mainfrom
refactor/phase-d-plugins-and-mutmut
Nov 23, 2026
Merged

Pigbibi merged 7 commits into
mainfrom
refactor/phase-d-plugins-and-mutmut

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI assistance

  • Model / agent: Gemini / Antigravity

What changed

  • Split src/quant_platform_kit/common/strategy_plugins.py (83KB) into layered DAG modules (_strategy_plugin_helpers.py, _strategy_plugin_models.py, _strategy_plugin_consumption.py, _strategy_plugin_loading.py, _strategy_plugin_alerts.py, all < 35KB) with a 100%-parity compatibility facade in strategy_plugins.py.
  • Added .ruff.toml (E4,E7,E9,F,B,C901 <= 15 with legacy freeze).
  • Added nightly .github/workflows/mutation-test.yml (mutmut==2.5.1) strictly scoped to position_sizing.py and risk/promotion_sizing.py.

How verified

  • uvx ruff check --exclude external . -> 0 errors
  • PYTHONPATH=src uvx --from import-linter==2.1 lint-imports -> 1 kept, 0 broken
  • uvx pyright==1.1.407 -> 0 errors
  • pytest tests/test_strategy_plugins.py tests/test_display_alert_keys.py tests/test_strategy_plugin_alert_dispatcher.py tests/test_position_sizing.py tests/test_promotion_sizing_chain.py -> 120 passed, 58 subtests passed.

Why

  • Execute ADR 0001 Phase D monolith decomposition and nightly risk-core mutation testing (note: QuantStrategyLab/FuseControl has no src/ yet so mutmut targets QuantPlatformKit risk sizing core).

Risk

  • Behavior-preserving refactor behind compatibility facade + additive nightly workflow (requires agent-approved for .github/workflows/**).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T09:51:07.050426Z 6d88af3 Manual request
🔒 Security Review ✅ Completed 2026-11-23T09:52:49.659217Z 6d88af3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@Pigbibi Pigbibi added the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 23, 2026
@Pigbibi Pigbibi added agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation and removed agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation labels Nov 23, 2026
@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / google/gemini-4-hydrogen)

Reviewed the visible PR diff (truncated at 60KB; _strategy_plugin_models.py, _strategy_plugin_loading.py, and the strategy_plugins.py facade were not included in the diff). The visible split modules (_strategy_plugin_helpers.py, _strategy_plugin_consumption.py, _strategy_plugin_alerts.py) preserve cohesive separation, but there are medium-severity issues in the new .ruff.toml lint configuration and the nightly mutation-testing workflow.

Reviewed commit: 7a5e8f8a3e · Coverage: partial · Unresolved findings: true

Findings

  • [MEDIUM] .github/workflows/mutation-test.yml: Using '|| true' on both 'mutmut run' and 'mutmut results' silently swallows baseline pytest/collection failures, missing dependency errors (e.g., numpy/pandas if not installed by editable install), and mutmut crashes, causing the workflow to pass green even when mutation testing never executed properly. Capture mutmut's exit code or check baseline pytest first before ignoring survivor exit status.
  • [MEDIUM] .ruff.toml: Globally ignoring 'F401' (unused imports) and 'F841' (unused local variables) disables checks that default 'ruff check .' previously enforced across the repository, masking dead code and typo/shadowing bugs in new code. Scope any legacy suppressions under [lint.per-file-ignores] (e.g., for compatibility facades) rather than global ignore.
  • [LOW] .ruff.toml: Newly created split modules 'src/quant_platform_kit/common/_strategy_plugin_alerts.py' and 'src/quant_platform_kit/common/_strategy_plugin_loading.py' are immediately exempted from C901 max-complexity checks rather than decomposing complex functions (such as build_strategy_plugin_alert_messages).
  • [LOW] src/quant_platform_kit/common/_strategy_plugin_helpers.py: _translator_uses_zh duplicates translator_uses_zh from quant_platform_kit.common.notification_localization (both are used within _strategy_plugin_alerts.py) and silently swallows all exceptions via 'except Exception: continue'.

@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / google/gemini-4-hydrogen)

Reviewed the visible PR diff (.github/workflows/mutation-test.yml, .ruff.toml, and the new _strategy_plugin_alerts.py, _strategy_plugin_consumption.py, and _strategy_plugin_helpers.py modules; note that the diff was truncated at 60KB so _strategy_plugin_loading.py, _strategy_plugin_models.py, and strategy_plugins.py were not visible). Found a medium-severity silent error swallowing issue in the new mutation-test workflow and two low-severity maintainability issues.

Reviewed commit: 15bcde48eb · Coverage: partial · Unresolved findings: true

Findings

  • [MEDIUM] .github/workflows/mutation-test.yml: Lines 34-37 append || true to both mutmut run and mutmut results without first running a baseline pytest step. This silently swallows setup crashes, missing dependencies (note numpy and pandas from AGENTS.md local checks are not explicitly installed here if not in pyproject.toml), or broken baseline tests, causing the nightly workflow to report green even when mutation testing never actually ran.
  • [LOW] src/quant_platform_kit/common/_strategy_plugin_alerts.py: Imports both translator_uses_zh from quant_platform_kit.common.notification_localization (used in build_strategy_plugin_alert_messages) and a duplicated _translator_uses_zh from _strategy_plugin_helpers.py (used in _strategy_plugin_error_reason). Consolidate on notification_localization.translator_uses_zh to avoid behavioral drift.
  • [LOW] .ruff.toml: Exempts newly created decomposed modules (_strategy_plugin_alerts.py and _strategy_plugin_loading.py) from C901 in [lint.per-file-ignores], bypassing the max-complexity = 15 threshold introduced in the same PR (e.g., build_strategy_plugin_alert_messages remains a ~200-line monolithic function).

@Pigbibi Pigbibi added agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation and removed agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation labels Nov 23, 2026
@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / google/gemini-4-hydrogen)

Reviewed the visible diff for the strategy_plugins decomposition, .ruff.toml, and nightly mutation-test workflow (note: the diff was truncated at 60KB, omitting _strategy_plugin_models.py, _strategy_plugin_loading.py, and strategy_plugins.py). Found one medium-severity control-precedence bug in _strategy_plugin_consumption.py and minor issues around duplicate locale detection, C901 exemptions on newly split modules, and mutation workflow error handling.

Reviewed commit: 77425dc007 · Coverage: partial · Unresolved findings: true

Findings

  • [MEDIUM] src/quant_platform_kit/common/_strategy_plugin_consumption.py: _strategy_plugin_has_auditable_position_control checks _as_bool(controls.get("position_control_allowed"), default=False) or _as_bool(policy.get("position_control_allowed"), default=False) instead of delegating to _strategy_plugin_policy_allows_position_control(signal). Because _is_strategy_position_control_notice (used by both _strategy_plugin_auto_consumption_allowed and _should_alert_strategy_plugin_signal) calls _strategy_plugin_has_auditable_position_control directly, an explicit execution_controls["position_control_allowed"] = False is overridden whenever consumption_policy["position_control_allowed"] is True, wrongly marking auto-consumption as allowed and suppressing alerts.
  • [LOW] src/quant_platform_kit/common/_strategy_plugin_helpers.py: _translator_uses_zh duplicates translator_uses_zh (already imported from quant_platform_kit.common.notification_localization in _strategy_plugin_alerts.py, where both helpers are used in different functions) and silently swallows all Exceptions via except Exception: continue.
  • [LOW] .ruff.toml: The newly created split modules src/quant_platform_kit/common/_strategy_plugin_alerts.py and src/quant_platform_kit/common/_strategy_plugin_loading.py are added to [lint.per-file-ignores] for C901, bypassing the new max-complexity = 15 rule on newly refactored code.
  • [LOW] .github/workflows/mutation-test.yml: mutmut run is wrapped in set +e and only echoes mutmut_exit=$mutmut_rc to $GITHUB_STEP_SUMMARY, so mutmut runtime or configuration failures (not only survived mutants) will silently pass the workflow; also verify numpy/pandas are covered by pip install -e . if required by position_sizing.py or risk/promotion_sizing.py (since AGENTS.md installs them explicitly alongside -e .).

@Pigbibi Pigbibi removed the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 23, 2026
@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / google/gemini-4-hydrogen)

Reviewed the visible PR diff (truncated at 60KB, covering .github/workflows/mutation-test.yml, .ruff.toml, _strategy_plugin_alerts.py, _strategy_plugin_consumption.py, and _strategy_plugin_helpers.py; _strategy_plugin_models.py, _strategy_plugin_loading.py, and strategy_plugins.py were omitted due to diff truncation). The extracted modules preserve clean DAG layering, input coercion/translation safety, and scoped workflow permissions with pinned action SHAs. Only minor cleanup items were observed.

Reviewed commit: b94eb6c907 · Coverage: partial · Unresolved findings: false

Findings

  • [LOW] src/quant_platform_kit/common/_strategy_plugin_alerts.py: Duplicate import of translator_uses_zh: imported directly from notification_localization and also as _translator_uses_zh via _strategy_plugin_helpers. Consolidate to a single import.
  • [LOW] .ruff.toml: PR verification ran 'ruff check --exclude external .', while AGENTS.md specifies 'ruff check .'. If an external/ checkout directory can exist in the workspace, consider adding exclude/extend-exclude in .ruff.toml so plain 'ruff check .' matches.

@Pigbibi Pigbibi added the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 23, 2026
@Pigbibi
Pigbibi force-pushed the refactor/phase-d-plugins-and-mutmut branch from b94eb6c to 0d192cd Compare November 23, 2026 09:30
@Pigbibi Pigbibi added agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation and removed agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation labels Nov 23, 2026
@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / google/gemini-4-hydrogen)

Reviewed the visible diff (.ruff.toml, .github/workflows/mutation-test.yml, and the _strategy_plugin_alerts.py, _strategy_plugin_consumption.py, and _strategy_plugin_helpers.py modules). The split preserves the existing localization, consumption-policy, and alert-building logic cleanly within Ruff's C901<=15 threshold, with no high or medium severity issues found in the reviewed files (note: the diff is truncated before _strategy_plugin_loading.py, _strategy_plugin_models.py, and the strategy_plugins.py facade).

Reviewed commit: 0d192cde29 · Coverage: partial · Unresolved findings: false

Findings

  • [LOW] src/quant_platform_kit/common/_strategy_plugin_alerts.py: Imports the same function twice under two names: translator_uses_zh directly from notification_localization (used in build_strategy_plugin_alert_messages) and _translator_uses_zh from _strategy_plugin_helpers (used in _strategy_plugin_error_reason). Also defines _translate_first_formatted instead of adding optional **kwargs support to _translate_first in _strategy_plugin_helpers.py.
  • [LOW] .github/workflows/mutation-test.yml: In Run scoped mutation tests, mutmut run returns a bitmask exit code where non-zero bits other than 2 (e.g., timeouts or incompetent mutants combined with survived mutants) will fail the nightly job; additionally, pip install omits explicit numpy/pandas if they are not declared in pyproject.toml core dependencies.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d192cde29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0d192cde29

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Pigbibi Pigbibi added agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation and removed agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation labels Nov 23, 2026
@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@qsl-ai-reviewer review

@Pigbibi

Pigbibi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / google/gemini-4-hydrogen)

Reviewed the visible diff for PR #811 (addition of .github/workflows/mutation-test.yml, .ruff.toml, and split modules _strategy_plugin_alerts.py, _strategy_plugin_consumption.py, _strategy_plugin_helpers.py). Note that the diff is truncated at 60KB, so _strategy_plugin_models.py, _strategy_plugin_loading.py, strategy_plugins.py, and any other trailing files could not be inspected. Within the visible changes, no high or medium severity issues were found.

Reviewed commit: 6d88af31bb · Coverage: partial · Unresolved findings: false

Findings

  • [LOW] .ruff.toml: PR verification ran ruff check --exclude external ., whereas .ruff.toml does not configure exclude for external. If CI or local workflows run ruff check . (as documented in AGENTS.md) with an external directory present, it may lint unintended files.
  • [LOW] src/quant_platform_kit/common/_strategy_plugin_helpers.py: _translator_uses_zh uses a broad except Exception: continue when probing translator(key) (lines 108-111), which can silently hide unexpected translator failures instead of narrowing to expected lookup/type errors.
  • [LOW] src/quant_platform_kit/common/_strategy_plugin_helpers.py: DEFAULT_PLUGIN_ARTIFACT_CACHE_DIR uses a deterministic subdirectory inside tempfile.gettempdir() (quant_strategy_plugin_artifacts), which on shared hosts can be susceptible to pre-created directory collisions; consider per-user/scoped cache directories if executed in multi-tenant environments.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 6d88af31bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Pigbibi
Pigbibi merged commit 4b0df54 into main Nov 23, 2026
15 of 18 checks passed
@Pigbibi
Pigbibi deleted the refactor/phase-d-plugins-and-mutmut branch November 23, 2026 09:52
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 6d88af31bb

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants