Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions courtroom/portal/export_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ def apply_personality_styling(html: str) -> str:
return html


def resolve_transcript_path(raw: str) -> Path:
"""Resolve transcript path relative to courtroom/ (BASE_DIR).

Accepts paths relative to repo root (courtroom/transcripts/foo.md),
courtroom/ (transcripts/foo.md), or absolute paths.
"""
src = Path(raw)
if src.is_absolute():
return src
rel = raw.lstrip("/")
if rel.startswith("courtroom/"):
rel = rel[len("courtroom/") :]
return BASE_DIR / rel


def extract_title(md_path: Path, content: str) -> str:
"""Derive a human-readable title from path or first H1."""
m = re.search(r"^#\s+(.+)$", content, re.MULTILINE)
Expand All @@ -229,9 +244,7 @@ def main() -> int:
parser.add_argument("-o", "--output", help="Output HTML path (default: portal/exports/<basename>.html)")
args = parser.parse_args()

src = Path(args.transcript)
if not src.is_absolute():
src = BASE_DIR / args.transcript.lstrip("/")
src = resolve_transcript_path(args.transcript)
if not src.exists():
print(f"Error: File not found: {src}", file=sys.stderr)
return 1
Expand Down
13 changes: 12 additions & 1 deletion litigation/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ def allocate_case_no(category: str = "DEL", *, deliberation: int = 1) -> str:

year = datetime.now().strftime("%Y")
if not REGISTRY_PATH.exists():
return f"{year}-{category}-001-{deliberation:03d}"
case_no = f"{year}-{category}-001-{deliberation:03d}"
data = {
"year": int(year),
"last_updated": datetime.now().strftime("%Y-%m-%d"),
"categories": {category: 2},
}
REGISTRY_PATH.parent.mkdir(parents=True, exist_ok=True)
REGISTRY_PATH.write_text(
yaml.dump(data, default_flow_style=False, sort_keys=False),
encoding="utf-8",
)
return case_no

data = yaml.safe_load(REGISTRY_PATH.read_text(encoding="utf-8")) or {}
year = str(data.get("year", year))
Expand Down
19 changes: 19 additions & 0 deletions tests/test_export_transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ def test_extract_title_from_dated_filename():
mod = _load_export_module()
path = Path("2026-02-15-framework-enhancement-analysis.md")
assert mod.extract_title(path, "") == "Framework Enhancement Analysis"


def test_resolve_transcript_path_accepts_repo_root_prefix():
"""README documents courtroom/transcripts/foo.md from repo root."""
mod = _load_export_module()
sample = "2026-02-15-framework-enhancement-analysis.md"
resolved = mod.resolve_transcript_path(f"courtroom/transcripts/{sample}")
expected = REPO_ROOT / "courtroom" / "transcripts" / sample
assert resolved == expected
assert resolved.exists()


def test_resolve_transcript_path_accepts_courtroom_relative_prefix():
mod = _load_export_module()
sample = "2026-02-15-framework-enhancement-analysis.md"
resolved = mod.resolve_transcript_path(f"transcripts/{sample}")
expected = REPO_ROOT / "courtroom" / "transcripts" / sample
assert resolved == expected
assert resolved.exists()
17 changes: 17 additions & 0 deletions tests/test_litigation_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ 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_allocate_case_no_creates_registry_when_missing(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Missing case-registry.yaml must not return duplicate 001 on every call."""
registry = tmp_path / "case-registry.yaml"
monkeypatch.setattr(litigation_run, "REGISTRY_PATH", registry)

first = litigation_run.allocate_case_no("DEL")
second = litigation_run.allocate_case_no("DEL")

assert first == f"{litigation_run.datetime.now().strftime('%Y')}-DEL-001-001"
assert second == f"{litigation_run.datetime.now().strftime('%Y')}-DEL-002-001"
assert registry.exists()
data = yaml.safe_load(registry.read_text(encoding="utf-8"))
assert data["categories"]["DEL"] == 3