diff --git a/4-Infrastructure/lib/jsonl.py b/4-Infrastructure/lib/jsonl.py index 614e2b2e..f1f227a1 100644 --- a/4-Infrastructure/lib/jsonl.py +++ b/4-Infrastructure/lib/jsonl.py @@ -23,11 +23,12 @@ def load_jsonl(path: Path) -> list[dict[str, Any]]: def write_jsonl(path: Path, rows: list[dict[str, Any]], *, append: bool = False) -> None: - """Write a list of dicts as JSONL.""" + """Write a list of dicts as JSONL (sorted keys for deterministic output).""" + path.parent.mkdir(parents=True, exist_ok=True) mode = "a" if append else "w" with path.open(mode, encoding="utf-8") as fh: for row in rows: - fh.write(json.dumps(row, ensure_ascii=False) + "\n") + fh.write(json.dumps(row, sort_keys=True, ensure_ascii=False) + "\n") def stable_json(obj: Any) -> str: diff --git a/4-Infrastructure/lib/q16.py b/4-Infrastructure/lib/q16.py index e38ad388..62c5b64c 100644 --- a/4-Infrastructure/lib/q16.py +++ b/4-Infrastructure/lib/q16.py @@ -38,7 +38,7 @@ def q16_mul(a: int, b: int) -> int: def q16_div(a: int, b: int) -> int: """Divide two Q16_16 values with normalization.""" if b == 0: - return 0 + raise ZeroDivisionError("Q16 division by zero") return (a * Q16_ONE) // b