mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-14 20:20:47 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
123 lines
5.2 KiB
Bash
Executable File
123 lines
5.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tests for lib/arch_perf_fixes.sh: fix_journal, fix_nm_wait_online and
|
|
# fix_media_organizer.
|
|
set -uo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=arch_perf_harness.sh
|
|
. "${SCRIPT_DIR}/arch_perf_harness.sh"
|
|
|
|
# shellcheck source=../arch_perf_fixes.sh
|
|
. "${FIXES_DIR}/lib/arch_perf_fixes.sh"
|
|
|
|
dropin="${JOURNALD_CONF_DIR}/size-limit.conf"
|
|
unit="${SYSTEMD_UNIT_DIR}/media-organizer.service"
|
|
|
|
# --- fix_journal ------------------------------------------------------------
|
|
|
|
# A multi-gigabyte journal is vacuumed AND capped. This only fires because the
|
|
# size regex now tolerates journalctl's spaceless "4.2G" output; with the old
|
|
# pattern the vacuum was unreachable.
|
|
arch_reset
|
|
_t_stub journalctl 'echo "Archived and active journals take up 4.2G in the file system."'
|
|
fix_journal
|
|
_t_contains "$(_t_calls)" "journalctl --vacuum-size=300M" \
|
|
"fix_journal: vacuums a multi-gigabyte journal"
|
|
_t_contains "$(cat "$dropin" 2>/dev/null)" "SystemMaxUse=300M" \
|
|
"fix_journal: writes the permanent size cap"
|
|
_t_contains "$(_t_calls)" "systemctl restart systemd-journald" \
|
|
"fix_journal: restarts journald after writing the cap"
|
|
|
|
# A journal already under a gigabyte is left alone, but still capped.
|
|
arch_reset
|
|
_t_stub journalctl 'echo "Archived and active journals take up 240.0M in the file system."'
|
|
out="$(fix_journal 2>&1)"
|
|
_t_contains "$out" "already under 1GiB" \
|
|
"fix_journal: reports a journal that is already small enough"
|
|
_t_lacks "$(_t_calls)" "journalctl --vacuum-size" \
|
|
"fix_journal: does not vacuum a journal measured in megabytes"
|
|
_t_contains "$(cat "$dropin" 2>/dev/null)" "SystemMaxUse=300M" \
|
|
"fix_journal: still writes the cap for a small journal"
|
|
|
|
# The cap already exists: it is not rewritten and journald is not restarted.
|
|
arch_reset
|
|
_t_stub journalctl 'echo "120.0M"'
|
|
printf '[Journal]\nSystemMaxUse=300M\n' >"$dropin"
|
|
out="$(fix_journal 2>&1)"
|
|
_t_contains "$out" "size cap already configured" \
|
|
"fix_journal: reports an already-configured size cap"
|
|
_t_lacks "$(_t_calls)" "systemctl restart systemd-journald" \
|
|
"fix_journal: does not restart journald when the cap already exists"
|
|
|
|
# --- fix_nm_wait_online -----------------------------------------------------
|
|
|
|
arch_reset
|
|
_t_stub systemctl 'exit 0'
|
|
fix_nm_wait_online
|
|
_t_contains "$(_t_calls)" "systemctl disable NetworkManager-wait-online.service" \
|
|
"fix_nm_wait_online: disables the wait-online unit when it is enabled"
|
|
|
|
arch_reset
|
|
_t_stub systemctl 'exit 1'
|
|
out="$(fix_nm_wait_online 2>&1)"
|
|
_t_contains "$out" "already disabled" \
|
|
"fix_nm_wait_online: reports a unit that is already disabled"
|
|
_t_lacks "$(_t_calls)" "systemctl disable" \
|
|
"fix_nm_wait_online: does not re-disable an already-disabled unit"
|
|
|
|
# --- fix_media_organizer ----------------------------------------------------
|
|
|
|
# The organizer script is nowhere to be found: the fix is skipped. Both
|
|
# candidate paths are absolute; the first is overridden into the tmpdir and
|
|
# the second is a real home path that does not exist on this machine.
|
|
arch_reset
|
|
if [[ -f /home/kuhy/linux-configuration/scripts/utils/organize_downloads.sh ]]; then
|
|
_t_pass "fix_media_organizer: SKIP not-found case (the second candidate exists here)"
|
|
else
|
|
out="$(fix_media_organizer 2>&1)"
|
|
_t_contains "$out" "not found — skipping" \
|
|
"fix_media_organizer: skips when no organize_downloads.sh exists"
|
|
_t_lacks "$(_t_calls)" "systemctl daemon-reload" \
|
|
"fix_media_organizer: writes no unit when the script is missing"
|
|
fi
|
|
|
|
# The script exists: the unit is written, reloaded and enabled.
|
|
arch_reset
|
|
printf '#!/bin/bash\necho organize\n' >"$ORGANIZE_SCRIPT_CANDIDATES"
|
|
out="$(SUDO_USER="kuhy" fix_media_organizer 2>&1)"
|
|
unit_text="$(cat "$unit" 2>/dev/null)"
|
|
_t_contains "$unit_text" "Description=Media File Organizer" \
|
|
"fix_media_organizer: writes the unit description"
|
|
_t_contains "$unit_text" "User=kuhy" \
|
|
"fix_media_organizer: runs the unit as the invoking user, not root"
|
|
_t_contains "$unit_text" "ExecStart=${ORGANIZE_SCRIPT_CANDIDATES}" \
|
|
"fix_media_organizer: points ExecStart at the script it found"
|
|
_t_contains "$(_t_calls)" "systemctl daemon-reload" \
|
|
"fix_media_organizer: reloads systemd after writing the unit"
|
|
_t_contains "$(_t_calls)" "systemctl enable media-organizer.service" \
|
|
"fix_media_organizer: enables the unit"
|
|
_t_contains "$(_t_calls)" "systemctl stop media-organizer.service" \
|
|
"fix_media_organizer: stops the old unit before replacing it"
|
|
|
|
# An already-correct unit is left alone.
|
|
arch_reset
|
|
printf '#!/bin/bash\n' >"$ORGANIZE_SCRIPT_CANDIDATES"
|
|
printf 'User=kuhy\nExecStart=%s\n' "$ORGANIZE_SCRIPT_CANDIDATES" >"$unit"
|
|
out="$(SUDO_USER="kuhy" fix_media_organizer 2>&1)"
|
|
_t_contains "$out" "already correctly configured" \
|
|
"fix_media_organizer: skips a unit that is already correct"
|
|
_t_eq "" "$(_t_calls)" \
|
|
"fix_media_organizer: runs no systemctl command when the unit is correct"
|
|
|
|
# A unit that exists but names the WRONG user is rewritten.
|
|
arch_reset
|
|
printf '#!/bin/bash\n' >"$ORGANIZE_SCRIPT_CANDIDATES"
|
|
printf 'User=someoneelse\nExecStart=%s\n' "$ORGANIZE_SCRIPT_CANDIDATES" >"$unit"
|
|
out="$(SUDO_USER="kuhy" fix_media_organizer 2>&1)"
|
|
_t_contains "$(cat "$unit")" "User=kuhy" \
|
|
"fix_media_organizer: rewrites a unit that names the wrong user"
|
|
|
|
echo
|
|
echo "arch_perf_fixes: ${PASS} passed, ${FAIL} failed"
|
|
((FAIL == 0))
|