linux-boot: harden boot-digest/run-boot dedup, empty-stats, and argument checks #2274

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/linux-boot-scripts-safety into main 2026-11-28 19:40:37 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 12:02:23 +00:00

Claimed in the coordination issue as: LINUX-BOOT-SCRIPTS-EXACT-DEDUP-EMPTY-STATS-AND-ARG-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191439979)

What and why

scripts/linux-boot/boot-digest.sh and scripts/linux-boot/run-boot.sh previously:

  • Hardcoded /opt/leonida instead of defaulting via LEONIDA_BOOT_ROOT, lacked directory creation before digest/ledger writes in boot-digest.sh, and ran flock without checking availability.
  • Used grep -q -P "^[^\t]*\t$AGENT\t$N\t" for ledger deduplication, allowing regex metacharacters in agent names (e.g. a.b matching axb).
  • Checked [ -f "$CAP/index.txt" ] (emitting broken counts for 0-byte index.txt) and ignored sample row counts in awk over resources.tsv (printing empty MB stats and 0 peak MB on header-only files), while leaving sed stderr unguarded when boot-<n>.meta was missing.
  • Accepted invalid AGENT, N, SECS (<= 0 or non-numeric), and malformed KEY=VALUE environment overrides without upfront validation.

This adds LEONIDA_BOOT_ROOT support, upfront argument validation, literal awk ledger deduplication, [ -s "$CAP/index.txt" ] and awk sample-count checks, flock / .meta guards, LF preservation, and stdlib bash regression tests in tests/test_linux_boot_scripts.py.

Tested

  • python -I tests/test_linux_boot_scripts.py -v (3 passed)
  • Detached upstream/main baseline negative control: failed with tests/test_linux_boot_scripts.py before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
Claimed in the coordination issue as: LINUX-BOOT-SCRIPTS-EXACT-DEDUP-EMPTY-STATS-AND-ARG-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191439979) ### What and why `scripts/linux-boot/boot-digest.sh` and `scripts/linux-boot/run-boot.sh` previously: - Hardcoded `/opt/leonida` instead of defaulting via `LEONIDA_BOOT_ROOT`, lacked directory creation before digest/ledger writes in `boot-digest.sh`, and ran `flock` without checking availability. - Used `grep -q -P "^[^\t]*\t$AGENT\t$N\t"` for ledger deduplication, allowing regex metacharacters in agent names (e.g. `a.b` matching `axb`). - Checked `[ -f "$CAP/index.txt" ]` (emitting broken counts for 0-byte `index.txt`) and ignored sample row counts in `awk` over `resources.tsv` (printing empty MB stats and `0` peak MB on header-only files), while leaving `sed` stderr unguarded when `boot-<n>.meta` was missing. - Accepted invalid `AGENT`, `N`, `SECS` (`<= 0` or non-numeric), and malformed `KEY=VALUE` environment overrides without upfront validation. This adds `LEONIDA_BOOT_ROOT` support, upfront argument validation, literal `awk` ledger deduplication, `[ -s "$CAP/index.txt" ]` and `awk` sample-count checks, `flock` / `.meta` guards, LF preservation, and stdlib bash regression tests in `tests/test_linux_boot_scripts.py`. ### Tested - `python -I tests/test_linux_boot_scripts.py -v` (3 passed) - Detached `upstream/main` baseline negative control: failed with `tests/test_linux_boot_scripts.py` before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
real-rusher commented 2026-11-26 12:23:22 +00:00

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no Wine). Merges cleanly. With this PR, python -I tests/test_linux_boot_scripts.py: 3 tests OK. The PR's test file against main's scripts: 1 failure, so the new test fails on main and passes with the change. compileall clean.

AI-assisted: yes (Claude Code)

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no Wine). Merges cleanly. With this PR, python -I tests/test_linux_boot_scripts.py: 3 tests OK. The PR's test file against main's scripts: 1 failure, so the new test fails on main and passes with the change. compileall clean. AI-assisted: yes (Claude Code)
MoonEyes commented 2026-11-28 19:40:34 +00:00

Red/green: tests/test_linux_boot_scripts.py fails 1 assertion on main (boot-digest.sh/run-boot.sh dedup, empty stats and argument guards) and passes with the PR (cloud run on main 7daa4a4).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: tests/test_linux_boot_scripts.py fails 1 assertion on main (boot-digest.sh/run-boot.sh dedup, empty stats and argument guards) and passes with the PR (cloud run on main 7daa4a4). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.