mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 18:54:03 +01:00
412 lines -> 135, with the nine functions in lib/music_detect.sh (133), lib/music_monitor.sh (91) and lib/music_status.sh (85). find_music_services and kill_music_services stay together: the first writes MUSIC_FOUND_PROCESS/MUSIC_FOUND_WINDOW and the second reads them, so splitting between them would thread mutable state across files. The test suite caught what the static checks could not. The harness copies the script into a temp worktree to stub common.sh, and copied exactly one file -- so after the split every source line failed and the script died before any behaviour under test ran. Teaching it to copy lib/ too is a harness fix under decision 8: no assertion changed, the same five checks run, exit 0 before and after. bash -n also earned its keep: the first splice dropped notify_user's closing brace, and shellcheck reported that only as SC1094 "parsing of sourced file failed" against the entry. One rename, not a suppression: monitor_loop's local `music_services` became `active_services` after shellcheck flagged SC2153 against the MUSIC_SERVICES config array now visible in the same file. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
59 lines
4.5 KiB
JSON
59 lines
4.5 KiB
JSON
{
|
|
"intent": "Bring music_parallelism.sh under the 250-line cap by moving its nine functions into three sourced libs, leaving its behaviour and its test outcomes unchanged.",
|
|
"scope": [
|
|
"linux_configuration/scripts/periodic_background/digital_wellbeing/music_parallelism.sh (412 -> 135 lines)",
|
|
"New: lib/music_{detect,monitor,status}.sh",
|
|
"linux_configuration/tests/test_music_parallelism.sh -- harness only, so the libs reach the temp worktree",
|
|
"Non-goal: changing any assertion, interval, or detection pattern"
|
|
],
|
|
"changes": [
|
|
"Moved wait_seconds, contains_music_process, find_music_services and kill_music_services into lib/music_detect.sh. The first two of those four share the MUSIC_FOUND_PROCESS / MUSIC_FOUND_WINDOW pair, so they stay in one file and no mutable state crosses a boundary.",
|
|
"Moved notify_user, instant_monitor_loop and monitor_loop into lib/music_monitor.sh; notify_user is called only by those two loops.",
|
|
"Moved show_status and show_usage into lib/music_status.sh.",
|
|
"The entry script keeps the header, the common.sh dual-path source, all configuration arrays and the command dispatch case, and sources the three libs after the configuration they read.",
|
|
"Renamed monitor_loop's local music_services to active_services. shellcheck flagged the local as a possible misspelling of the MUSIC_SERVICES config array (SC2153) once both appeared in the same file; renaming the purely internal local is the fix, not a suppression.",
|
|
"Taught the test harness to copy the script's lib/ directory into its temp worktree alongside the script. No assertion, expectation or check was changed."
|
|
],
|
|
"verification": [
|
|
{
|
|
"command": "bash linux_configuration/tests/test_music_parallelism.sh",
|
|
"result": "pass",
|
|
"evidence": "Exit 0, the same five checks as before the split, by the same names: stable-focus backoff, conflict retry interval, idle interval, conflict-path xdotool deduplication, monitor-loop xdotool deduplication. Baseline was captured before any edit and matches."
|
|
},
|
|
{
|
|
"command": "shellcheck music_parallelism.sh lib/music_*.sh",
|
|
"result": "pass",
|
|
"evidence": "Zero findings across all four files at the repo's no-severity-filter setting, with no suppression added."
|
|
},
|
|
{
|
|
"command": "bash -n on the entry and each lib",
|
|
"result": "pass",
|
|
"evidence": "All four parse. This check earned its keep: the first splice dropped notify_user's closing brace, and shellcheck reported it only as SC1094 'parsing of sourced file failed' on the entry, which reads like a lint nicety rather than a broken file."
|
|
},
|
|
{
|
|
"command": "bash ~/utils/scripts/check_file_length.sh",
|
|
"result": "pass",
|
|
"evidence": "entry 135, detect 133, monitor 91, status 85. None of the four appears in the violation list."
|
|
},
|
|
{
|
|
"command": "diff of the function set against HEAD",
|
|
"result": "pass",
|
|
"evidence": "Identical: all nine functions preserved, each defined exactly once across the four files. No lib sources another; the entry sources all three."
|
|
},
|
|
{
|
|
"command": "sorted line-set diff of HEAD:music_parallelism.sh against entry+libs concatenated",
|
|
"result": "pass",
|
|
"evidence": "The only differences are the three lines carrying the deliberate music_services -> active_services rename, and the three added source lines. No executable line lost."
|
|
}
|
|
],
|
|
"risks": [
|
|
"The test harness previously copied one file; it now copies a directory too. If a future split adds a lib elsewhere the same fix will be needed again, but the failure is loud -- the source line aborts the script and every check fails, which is how this one was caught.",
|
|
"The entry keeps the existing $0-based SCRIPT_DIR rather than ${BASH_SOURCE[0]}. Safe here because nothing sources music_parallelism.sh: it is invoked as a command by its dispatch case, and grep over linux_configuration finds no other reference than the test.",
|
|
"The script has a /usr/local/lib/common.sh fallback for its shared library, but no installed copy of the script itself exists (checked /usr/local/bin), so the new libs are only ever resolved from the repo."
|
|
],
|
|
"rollback": [
|
|
"git revert the commit; music_parallelism.sh returns to its 412-line single-file form, the three libs disappear, and the test harness stops copying a lib/ directory that no longer exists.",
|
|
"After rollback, re-run bash linux_configuration/tests/test_music_parallelism.sh and confirm the same five checks still pass."
|
|
]
|
|
}
|