mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-25 23:16:45 +00:00
- 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
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
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
|