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

Merged
kirigayakazima merged 1 commit from upstream-pr/2274 into main 2026-11-28 19:40:37 +00:00
kirigayakazima commented 2026-11-26 12:02:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T12:02:23Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5509662915 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2274). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T12:02:23Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:22Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191938010 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2274#issuecomment-7191938010). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:23:22Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T19:40:34Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7244721946 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2274#issuecomment-7244721946). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T19:40:34Z. --- 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 reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2274
No description provided.