From f6f9122d24536fbb6f36f1356a9d38a22f4d7dba Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2026 01:20:56 +0000 Subject: [PATCH] fix(infra): write_jsonl mkdir+sort_keys, q16_div raise on zero - write_jsonl: add path.parent.mkdir(parents=True, exist_ok=True) to prevent FileNotFoundError when output dir doesn't exist - write_jsonl: add sort_keys=True to match original callers' deterministic output behavior (AGENTS.md: identical SHA256 on consecutive runs) - q16_div: raise ZeroDivisionError instead of silently returning 0, matching the original fractal_dimension.py semantics Co-Authored-By: Allaun Silverfox --- 4-Infrastructure/lib/jsonl.py | 5 +++-- 4-Infrastructure/lib/q16.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) 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