testsAndMisc/linux_configuration/fixes/lib/tests/test_thorium_repairs.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
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
2026-08-23 18:53:30 +02:00

133 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# lib/tests/test_thorium_repairs.sh — tests for thorium_repairs.sh's profile
# repairs: Local State, singleton locks, GPU cache and crash reports.
#
# fix_aggressive and test_thorium live in test_thorium_repairs_deep.sh, split
# out to hold every file under the 250-line cap.
#
# Calls go through _t_run rather than `out="$(...)"`: command substitution
# forks a subshell, and kcov does not register a lib whose first execution
# happens inside one.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=thorium_harness.sh
. "${SCRIPT_DIR}/thorium_harness.sh"
# shellcheck source=../thorium_repairs.sh
. "${FIXES_DIR}/lib/thorium_repairs.sh"
printf '\n-- fix_local_state --\n'
# Case 1: no Local State at all -- a fresh install.
thorium_reset
_t_run fix_local_state
_t_eq "0" "$?" "fix_local_state: returns 0 with no Local State"
_t_contains "$out" "No Local State file found" "fix_local_state: reports a fresh install"
# Case 2: valid JSON is STILL backed up -- the lib treats a readable Local
# State as a crash source in its own right, not just a corrupt one.
thorium_reset
_t_profile "Local State"
_t_stub python3 'exit 0'
_t_run fix_local_state
_t_contains "$out" "backing up (common crash source)" \
"fix_local_state: backs up even valid JSON"
_t_eq "no" "$(_t_exists "Local State")" "fix_local_state: moves the valid file aside"
_t_eq "yes" "$(_t_exists "Local State${BACKUP_SUFFIX}")" \
"fix_local_state: the backup carries the suffix"
# Case 3: corrupted JSON -- python3 exits non-zero.
thorium_reset
_t_profile "Local State"
_t_stub python3 'exit 1'
_t_run fix_local_state
_t_contains "$out" "appears corrupted" "fix_local_state: reports corruption"
_t_eq "yes" "$(_t_exists "Local State${BACKUP_SUFFIX}")" \
"fix_local_state: backs up the corrupt file"
# Case 4: dry-run leaves the file in place.
thorium_reset
_t_profile "Local State"
_t_stub python3 'exit 0'
DRY_RUN=true
_t_run fix_local_state
_t_eq "yes" "$(_t_exists "Local State")" "fix_local_state: dry-run keeps the file"
_t_contains "$out" "Would backup" "fix_local_state: dry-run says what it would do"
printf '\n-- fix_singleton_locks --\n'
# Case 5: no locks present.
thorium_reset
_t_run fix_singleton_locks
_t_contains "$out" "No stale lock files found" "fix_singleton_locks: reports none found"
# Case 6: all three locks present -> all cleared.
thorium_reset
_t_profile SingletonLock SingletonSocket SingletonCookie
_t_run fix_singleton_locks
_t_eq "no" "$(_t_exists SingletonLock)" "fix_singleton_locks: clears SingletonLock"
_t_eq "no" "$(_t_exists SingletonSocket)" "fix_singleton_locks: clears SingletonSocket"
_t_eq "no" "$(_t_exists SingletonCookie)" "fix_singleton_locks: clears SingletonCookie"
_t_lacks "$out" "No stale lock files found" \
"fix_singleton_locks: does not claim none were found"
# Case 7: only one lock present -- the partial case, which the counter must
# still treat as "something was cleared".
thorium_reset
_t_profile SingletonLock
_t_run fix_singleton_locks
_t_eq "no" "$(_t_exists SingletonLock)" "fix_singleton_locks: clears the one lock"
_t_lacks "$out" "No stale lock files found" \
"fix_singleton_locks: counts a single lock as cleared"
printf '\n-- fix_gpu_cache --\n'
# Case 8: nothing cached.
thorium_reset
_t_run fix_gpu_cache
_t_contains "$out" "No GPU cache to clear" "fix_gpu_cache: reports an empty cache"
# Case 9: all four cache locations, including the Default/ ones.
thorium_reset
_t_profile GPUCache/f "Default/GPUCache/f" ShaderCache/f "Default/ShaderCache/f"
_t_run fix_gpu_cache
_t_eq "no" "$(_t_exists GPUCache)" "fix_gpu_cache: clears the top-level GPUCache"
_t_eq "no" "$(_t_exists Default/GPUCache)" "fix_gpu_cache: clears the profile GPUCache"
_t_eq "no" "$(_t_exists ShaderCache)" "fix_gpu_cache: clears the top-level ShaderCache"
_t_eq "no" "$(_t_exists Default/ShaderCache)" "fix_gpu_cache: clears the profile ShaderCache"
_t_lacks "$out" "No GPU cache to clear" "fix_gpu_cache: does not claim the cache was empty"
printf '\n-- fix_crash_reports --\n'
# Case 10: no crash directory.
thorium_reset
_t_run fix_crash_reports
_t_eq "0" "$?" "fix_crash_reports: returns 0 with no crash directory"
# Case 11: crash directory present but EMPTY -> left alone, since the count
# gate is what decides, not the directory's existence.
thorium_reset
mkdir -p "${THORIUM_CONFIG_DIR}/Crash Reports"
_t_run fix_crash_reports
_t_eq "yes" "$(_t_exists "Crash Reports")" "fix_crash_reports: keeps an empty crash dir"
# Case 12: crash reports present -> removed and counted.
thorium_reset
_t_profile "Crash Reports/a" "Crash Reports/b"
_t_run fix_crash_reports
_t_eq "no" "$(_t_exists "Crash Reports")" "fix_crash_reports: removes the crash dir"
_t_contains "$out" "Cleared 2 crash report(s)" "fix_crash_reports: counts the reports"
# Case 13: dry-run reports the count without deleting.
thorium_reset
_t_profile "Crash Reports/a"
DRY_RUN=true
_t_run fix_crash_reports
_t_eq "yes" "$(_t_exists "Crash Reports")" "fix_crash_reports: dry-run keeps the dir"
_t_contains "$out" "Would clear 1 crash report(s)" "fix_crash_reports: dry-run states the count"
printf '\nthorium_repairs (profile): %d passed, %d failed\n' "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]]