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 <noreply@anthropic.com>
This commit is contained in:
Hasan BasbunarandClaude Opus 5.5 committed 2026-11-24 18:53:42 +01:00
1 parent 09633a08f5
commit ec7d465e6c
3 files changed
+25 -1

No files matched your search

+4
View File
@@ -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
+3 -1
View File
@@ -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"
+18
View File
@@ -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")