refactor(text): unify Chinese conversion on Rust (#6481)

This commit is contained in:
InfinityPacer
2026-08-27 17:17:06 +08:00
committed by GitHub
parent fcdef31ecf
commit 2b1f590c4d
12 changed files with 71 additions and 80 deletions
+2 -4
View File
@@ -1441,8 +1441,8 @@
"runtime_only": true
}
},
"edge_count": 6836,
"edge_sha256": "3709e09a49257075f48a44aba353be1f25db610471ec756e09cbbfd7070acb9a",
"edge_count": 6834,
"edge_sha256": "07c0b6f24ef3ce3e7ea0fa7c1b617388e11e2453ce2b0b35bddb38ed2d7f5835",
"edges": [
"app -> app.runtime",
"app -> app.runtime.compat",
@@ -5526,8 +5526,6 @@
"app.factory -> app.schemas.response",
"app.factory -> app.startup",
"app.factory -> app.startup.lifecycle",
"app.foundation.text -> app.foundation",
"app.foundation.text -> app.foundation.environment",
"app.main -> app.adapters",
"app.main -> app.adapters.system",
"app.main -> app.adapters.system.host",
+9 -6
View File
@@ -54,7 +54,7 @@ def valid_preflight(variant: str) -> dict:
"gil_disabled": False,
"gil_enabled": True,
"thread_inherit_context": 0,
"has_zhconv_fast": False,
"has_zhconv_fast": True,
"gil_enabled_after_imports": True,
"packages": {
"bcrypt": "4.3.0",
@@ -65,7 +65,7 @@ def valid_preflight(variant: str) -> dict:
"orjson": "3.12.0",
"psycopg": None,
"psycopg2-binary": "2.9.12",
"zhconv-rs": "0.4.1",
"zhconv-rs": None,
},
"native": {
"crcmod_extension": True,
@@ -123,7 +123,7 @@ def valid_preflight(variant: str) -> dict:
"zstandard",
}
expected_imports.update(
{"psycopg2-binary", "zhconv-rs"} if variant == "v3" else {"psycopg"}
{"psycopg2-binary"} if variant == "v3" else {"psycopg"}
)
common["imports"] = {
name: {"imported": True, "gil_after": variant == "v3"}
@@ -341,9 +341,12 @@ def test_preflight_enforces_runtime_and_native_profiles() -> None:
assert harness.validate_preflight("v3", valid_preflight("v3")) == []
assert harness.validate_preflight("v3t", valid_preflight("v3t")) == []
leaked = valid_preflight("v3")
leaked["has_zhconv_fast"] = True
assert any("has_zhconv_fast" in item for item in harness.validate_preflight("v3", leaked))
incomplete_text = valid_preflight("v3")
incomplete_text["has_zhconv_fast"] = False
assert any(
"has_zhconv_fast" in item
for item in harness.validate_preflight("v3", incomplete_text)
)
unsafe = valid_preflight("v3t")
unsafe["gil_enabled_after_imports"] = True
+6 -1
View File
@@ -1,4 +1,4 @@
from app.foundation.text import cut
from app.foundation.text import convert, cut
def test_cut_accepts_hmm_argument():
@@ -19,3 +19,8 @@ def test_cut_preserves_full_mode_contract():
"长江大桥",
"大桥",
]
def test_convert_uses_rust_mediawiki_contract():
"""标准与 free-threaded 运行时应共享同一中文转换语义。"""
assert convert("后台", "zh-hant") == "後台"
+21
View File
@@ -79,6 +79,27 @@ def test_runtime_profiles_share_gil_safe_crcmod_distribution():
} in document["tool"]["uv"]["exclude-dependencies"]
def test_standard_runtime_uses_shared_rust_text_capabilities(monkeypatch):
"""标准镜像的文本能力不得重新引入 profile 专属实现。"""
imported = []
moviepilot_rust = SimpleNamespace(
is_available=lambda: True,
jieba_cut=lambda _value: ["中文", "分词"],
zhconv_fast=lambda value, _target: value,
)
def import_module(name):
imported.append(name)
return moviepilot_rust if name == "moviepilot_rust" else SimpleNamespace()
monkeypatch.setattr(dependency_doctor, "import_module", import_module)
monkeypatch.setattr(dependency_doctor.sysconfig, "get_config_var", lambda _name: None)
dependency_doctor.main()
assert "zhconv_rs" not in imported
def test_runtime_excluded_dependency_pairs_reads_uv_policy(tmp_path: Path):
"""运行时诊断应复用 uv 排除配置,不维护第二份包名特判。"""
project_file = tmp_path / "pyproject.toml"