mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-08 09:10:32 +08:00
feat: add global RUST_ACCEL toggle to enable/disable rust acceleration at runtime
- Introduce RUST_ACCEL config to control all rust fast paths - Fallback to Python implementations when disabled, preserving filter semantics - Expose rust acceleration status in system info API - Update CLI docs to reflect new toggle - Add tests for runtime switch and fallback behavior
This commit is contained in:
45
tests/test_rust_accel_toggle.py
Normal file
45
tests/test_rust_accel_toggle.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from app.core.config import settings
|
||||
from app.utils import rust_accel
|
||||
|
||||
|
||||
class _DummyRustExtension:
|
||||
"""
|
||||
测试用 Rust 扩展替身,用来验证总开关会阻止扩展调用。
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_available() -> bool:
|
||||
"""
|
||||
模拟 Rust 扩展基础能力可用。
|
||||
"""
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def parse_filter_rule_fast(_expression: str) -> list:
|
||||
"""
|
||||
如果总开关关闭后仍调用扩展,测试应立即失败。
|
||||
"""
|
||||
raise AssertionError("Rust extension should not be called")
|
||||
|
||||
|
||||
def test_rust_accel_runtime_switch_disables_fast_paths(monkeypatch):
|
||||
"""
|
||||
RUST_ACCEL 关闭时,即便扩展可用也应回退到 Python 路径。
|
||||
"""
|
||||
monkeypatch.setattr(settings, "RUST_ACCEL", False)
|
||||
monkeypatch.setattr(rust_accel, "_moviepilot_rust", _DummyRustExtension())
|
||||
|
||||
assert rust_accel.is_available()
|
||||
assert not rust_accel.is_enabled()
|
||||
assert rust_accel.parse_filter_rule("HDR") is None
|
||||
|
||||
|
||||
def test_rust_accel_status_reports_enabled_state(monkeypatch):
|
||||
"""
|
||||
状态接口应同时体现扩展可用性和配置开关后的实际启用状态。
|
||||
"""
|
||||
monkeypatch.setattr(settings, "RUST_ACCEL", True)
|
||||
monkeypatch.setattr(rust_accel, "_moviepilot_rust", _DummyRustExtension())
|
||||
|
||||
assert rust_accel.status()["available"] is True
|
||||
assert rust_accel.status()["enabled"] is True
|
||||
Reference in New Issue
Block a user