From 5514de3adc3313d23572bbe6c361edc3ba3c6985 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 2 Jul 2026 12:05:31 +0000 Subject: [PATCH] test(litigation): cover slugify, registry fallback, and transcript footer Add regression tests for litigation runner edge cases: slug sanitization, case-number allocation without a registry file, courtroom save location, and automatic MORNINGSTAR::SCRIBE certification footer. Co-authored-by: exios4 --- tests/test_litigation_run.py | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/test_litigation_run.py b/tests/test_litigation_run.py index 8e46431..5cc1b2c 100644 --- a/tests/test_litigation_run.py +++ b/tests/test_litigation_run.py @@ -76,3 +76,61 @@ def test_save_transcript_filename_suffix_independent_of_case_no( assert path.name.endswith("-1.md") assert "**Case No.:** 2026-DEL-020-001" in content + + +def test_slugify_strips_special_chars_and_truncates() -> None: + assert litigation_run.slugify("Hello, World!") == "hello-world" + assert litigation_run.slugify("!!!") == "matter" + assert len(litigation_run.slugify("a" * 100)) <= 60 + + +def test_allocate_case_no_without_registry(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + missing = tmp_path / "missing-registry.yaml" + monkeypatch.setattr(litigation_run, "REGISTRY_PATH", missing) + + case_no = litigation_run.allocate_case_no("DEL", deliberation=2) + + assert case_no.endswith("-DEL-001-002") + assert case_no[:4].isdigit() + + +def test_save_transcript_courtroom_location( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + registry = tmp_path / "case-registry.yaml" + registry.write_text( + yaml.dump({"year": 2026, "categories": {"DEL": 1}}), + encoding="utf-8", + ) + monkeypatch.setattr(litigation_run, "REGISTRY_PATH", registry) + monkeypatch.setattr(litigation_run, "REPO_ROOT", tmp_path) + + courtroom_dir = tmp_path / "courtroom" / "transcripts" + path = litigation_run.save_transcript("bench matter", "Ruling text.", location="courtroom") + + assert path.parent == courtroom_dir + assert path.exists() + assert "bench matter" in path.read_text(encoding="utf-8") + + +def test_save_transcript_appends_scribe_certification( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + registry = tmp_path / "case-registry.yaml" + registry.write_text( + yaml.dump({"year": 2026, "categories": {"DEL": 3}}), + encoding="utf-8", + ) + monkeypatch.setattr(litigation_run, "REGISTRY_PATH", registry) + + fake_module = tmp_path / "litigation_pkg" + fake_module.mkdir() + (fake_module / "run.py").write_text("", encoding="utf-8") + (fake_module / "transcripts").mkdir() + monkeypatch.setattr(litigation_run, "__file__", str(fake_module / "run.py")) + + path = litigation_run.save_transcript("scribe test", "Body without footer.") + content = path.read_text(encoding="utf-8") + + assert content.rstrip().endswith("> *Transcript certified by MORNINGSTAR::SCRIBE*") + assert "Body without footer." in content