refactor(string): split utilities by responsibility

This commit is contained in:
jxxghp
2026-08-15 08:03:55 +08:00
parent a2117bafc8
commit 96118e73e7
99 changed files with 1608 additions and 1424 deletions
-37
View File
@@ -1,7 +1,5 @@
from importlib.machinery import EXTENSION_SUFFIXES, PathFinder
from pathlib import Path
from app.application.site import _include_legacy_resource_directory
from app.runtime.config import settings
from app.adapters.system.resource import (
ResourceHelper,
@@ -13,41 +11,6 @@ from app.startup import modules_initializer
ROOT_DIR = Path(__file__).resolve().parents[1]
def test_legacy_docker_updater_resource_directory_remains_importable(tmp_path):
"""旧镜像把资源写入 helper 时,canonical 站点包仍应找到对应扩展。"""
package_dir = tmp_path / "app" / "application" / "site"
legacy_dir = tmp_path / "app" / "helper"
package_dir.mkdir(parents=True)
legacy_dir.mkdir(parents=True)
extension_path = legacy_dir / f"sites{EXTENSION_SUFFIXES[0]}"
extension_path.touch()
package_paths = [str(package_dir)]
_include_legacy_resource_directory(package_paths, package_dir)
assert (ROOT_DIR / "app" / "helper" / ".resource-compat").is_file()
assert package_paths == [str(package_dir), str(legacy_dir)]
spec = PathFinder.find_spec("app.application.site.sites", package_paths)
assert spec is not None
assert spec.origin == str(extension_path)
def test_canonical_site_extension_takes_priority_over_legacy_directory(tmp_path):
"""canonical 扩展存在时不得把旧资源目录加入站点包搜索路径。"""
package_dir = tmp_path / "app" / "application" / "site"
legacy_dir = tmp_path / "app" / "helper"
package_dir.mkdir(parents=True)
legacy_dir.mkdir(parents=True)
extension_name = f"sites{EXTENSION_SUFFIXES[0]}"
(package_dir / extension_name).touch()
(legacy_dir / extension_name).touch()
package_paths = [str(package_dir)]
_include_legacy_resource_directory(package_paths, package_dir)
assert package_paths == [str(package_dir)]
def test_resource_helper_uses_v3_only():
"""在线资源更新器必须只请求 V3 清单、目录和站点索引文件。"""
assert settings.VERSION_FLAG == "v3"