From ec7d465e6c29f6db2aac2fade1ae12495d78dc2a Mon Sep 17 00:00:00 2001 From: Hasan Basbunar Date: Tue, 24 Nov 2026 18:53:42 +0100 Subject: [PATCH] oc-fit-limits: an empty opencode.major is the default OpenCode, as a missing one is Its first line was read as [0] of no lines: an IndexError at import, which the "except OSError" let through, so the whole tool failed, and the cockpit's fit after a boot with it. Found while fixing the code review of v1.62.0. The test fails on the code before (IndexError). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ oc-fit-limits.py | 4 +++- tests/test_oc_fit_limits.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf37018..f0bdb1ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,10 @@ as every lane, decision 1564). proof asked the container that ran before the run: a lane serving older files than the run installed restarts first; and, found while fixing the first, its Load window warned that agent clients on :30001 lose their engine, which its Load, stopping nothing, never does. +- **Also**: oc-fit-limits.py read the first line of an empty `opencode.major` as `[0]` of no lines, an IndexError + its `except OSError` let through, at import: the whole tool failed, the cockpit's fit after a boot with it. An + empty marker is now the default OpenCode, as a missing one is (`tests/test_oc_fit_limits.py`, check 9, fails on + the code before). Tests: `tests/test_embed_lane.py` runs the installer's `--stage` in a throwaway home and reads the unit it writes (the pins, the snapshot by its path, no key and loopback only, the cgroup cap and diff --git a/oc-fit-limits.py b/oc-fit-limits.py index a9188094..8239233a 100755 --- a/oc-fit-limits.py +++ b/oc-fit-limits.py @@ -39,7 +39,9 @@ def _oc_major() -> str: compaction merge writes the v2 block on such a box, as install.sh exports OC_MAJOR for its own calls.""" try: - return (CONFIG_DIR / "opencode.major").read_text().splitlines()[0].strip() or "1" + # an empty marker is the default too: [0] of its no lines raised IndexError, which OSError does not catch, and + # the tool failed at import (2026-11-24) + return ((CONFIG_DIR / "opencode.major").read_text().splitlines() or [""])[0].strip() or "1" except OSError: return "1" diff --git a/tests/test_oc_fit_limits.py b/tests/test_oc_fit_limits.py index 009d75d0..166ef247 100644 --- a/tests/test_oc_fit_limits.py +++ b/tests/test_oc_fit_limits.py @@ -403,6 +403,24 @@ def main() -> None: finally: keeper.doCleanups() + # 9. An empty opencode.major (written whole as nothing: a full disk, a truncated copy) is the default OpenCode, as + # a missing one is: its first line was read as [0] of no lines, an IndexError at import that "except OSError" + # let through, and the whole tool failed, the cockpit's fit after a boot with it (found on 2026-11-24). + import tempfile + from pathlib import Path as P + with tempfile.TemporaryDirectory(prefix="oc-fit-major-") as d: + before = os.environ.get("CONFIG_DIR") + os.environ["CONFIG_DIR"] = d + try: + for text, want in (("", "1"), ("\n", "1"), ("2\n# asked\n", "2")): + (P(d) / "opencode.major").write_text(text) + assert load()._oc_major() == want, (text, want) + finally: + if before is None: + del os.environ["CONFIG_DIR"] + else: + os.environ["CONFIG_DIR"] = before + print("test_oc_fit_limits: OK")