48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
def _load_semantic_lint_module():
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
module_path = repo_root / "scripts" / "semantic_lint.py"
|
|
spec = importlib.util.spec_from_file_location("semantic_lint", module_path)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def test_semantic_lint_flags_new_scattered_hint_tables(tmp_path) -> None:
|
|
module = _load_semantic_lint_module()
|
|
target = tmp_path / "backend" / "app" / "services" / "integrations" / "foo.py"
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text('PROJECT_CREATE_HINTS = ("创建项目",)\\n', encoding="utf-8")
|
|
|
|
problems = module.collect_problems(
|
|
root=tmp_path,
|
|
scan_roots=(Path("backend/app/services/integrations"),),
|
|
baseline_path=Path("scripts/semantic_lint_baseline.txt"),
|
|
)
|
|
|
|
assert len(problems) == 1
|
|
assert problems[0].rule_id == "semantic_hint_constant"
|
|
|
|
|
|
def test_semantic_lint_allows_workflow_semantic_planner_directory(tmp_path) -> None:
|
|
module = _load_semantic_lint_module()
|
|
target = tmp_path / "backend" / "app" / "services" / "ai_pmo" / "workflow_semantic_planner" / "foo.py"
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text('PROJECT_CREATE_HINTS = ("创建项目",)\\n', encoding="utf-8")
|
|
|
|
problems = module.collect_problems(
|
|
root=tmp_path,
|
|
scan_roots=(Path("backend/app/services/ai_pmo"),),
|
|
baseline_path=Path("scripts/semantic_lint_baseline.txt"),
|
|
)
|
|
|
|
assert problems == []
|