37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""运行 ID 和终态合同的离线测试。"""
|
|
import pathlib
|
|
import sys
|
|
|
|
PROJECT_ROOT = pathlib.Path(__file__).resolve().parents[3]
|
|
SCRIPT_DIR = PROJECT_ROOT / "muse" / "authority" / "evidence" / "skills" / "记录运行证据" / "scripts"
|
|
sys.path.insert(0, str(SCRIPT_DIR))
|
|
import run_registry # noqa: E402
|
|
|
|
|
|
def test_new_run_id_is_scoped_and_bounded():
|
|
run_id = run_registry.new_run_id("parse-book/chapters", work_id=12, target_chapter=2)
|
|
assert run_id.startswith("parse-book-chapters-w12-c2-")
|
|
assert len(run_id) <= 64
|
|
|
|
|
|
def test_invalid_terminal_state_is_rejected_before_db_access():
|
|
try:
|
|
run_registry.finish_run("never", "running")
|
|
except ValueError as exc:
|
|
assert "终态非法" in str(exc)
|
|
else:
|
|
raise AssertionError("running 不应被 finish_run 接受")
|
|
|
|
|
|
def main():
|
|
for test in (test_new_run_id_is_scoped_and_bounded,
|
|
test_invalid_terminal_state_is_rejected_before_db_access):
|
|
test()
|
|
print(f" ✓ {test.__name__}")
|
|
print("全部通过")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|