mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 18:54:03 +01:00
Location/curfew goes to daemon_location.sh, the derived state files to daemon_state.sh, the app layer to daemon_apps.sh. All 23 functions moved verbatim -- nothing restructured, which matters more here than anywhere else in this session. focus_daemon.sh has five `while IFS= read -r pkg; do ... done <file` loops and EVERY body calls pm. Piping any of them in lets pm inherit and drain the loop's stdin, so it would process one package instead of all of them -- measured elsewhere in this repo as 1 of 54. That audit ran BEFORE the extraction, not after coverage came back short, and all five moved untouched with a note above them saying why. CURRENT_MODE and _CURFEW_TICK_CACHED are each written in both the entry script and a library, so both stay declared with main, same call as NET_BUILT in the curfew split. 110 assertions and 33 mutations, all killed. Two survived the first run and both were defects in my own tests: the whitelist and sysprotect exactness checks used a SUPERSTRING of a listed entry, which fails under grep -qF and grep -qxF alike and so proved nothing about which was in use. Two subjects are NOT at 100%, and the numbers are reported as measured: daemon_state.sh 67/67 = 100.00% daemon_location.sh 26/40 = 65.00% daemon_apps.sh 71/76 = 93.42% Both shortfalls are kcov attribution failures, shown to be artifacts rather than gaps. daemon_location.sh's missing lines are all inside the embedded awk Haversine; mutating the Earth radius and dropping the longitude term both fail the suite, and an isolated probe shows a one-line awk measuring 100% where the identical multi-line one measures 0%. Collapsing the formula to satisfy the tool would cost the readability of the only real mathematics in the repo, so it stays. daemon_apps.sh's five are the trailing `done <file` of the very loops described above. That is the same artifact piping fixed in curfew_net.sh, and it is exactly what must NOT be done here. Redirecting two of them from /dev/null fails the suite, so the lines run; all three are pinned in the mutation spec instead. Over-cap count 19 -> 18. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
77 lines
7.2 KiB
JSON
77 lines
7.2 KiB
JSON
{
|
|
"intent": "Bring focus_daemon.sh under the 250-line cap by extracting three clusters into flat siblings, and test all three — including is_allowed, the single decision that determines whether any app on the phone keeps working, which had no test at all.",
|
|
"scope": [
|
|
"phone_focus_mode/focus_daemon.sh - 543 lines down to 206",
|
|
"phone_focus_mode/daemon_location.sh - new: get_location, calc_distance, _dec, is_curfew_now, curfew_active",
|
|
"phone_focus_mode/daemon_state.sh - new: the four build_*_file helpers, refresh_default_handlers, is_default_handler, write_status_snapshot",
|
|
"phone_focus_mode/daemon_apps.sh - new: reconcile_disabled_apps, is_allowed, enable_focus_mode, disable_focus_mode",
|
|
"phone_focus_mode/deploy.sh - all three added to both hardcoded lists",
|
|
"phone_focus_mode/lib/tests/ - a harness, four case files and one entry point, all new",
|
|
"meta/scripts/fixtures/mutations/daemon_libs.json - new: 33 reproducible mutations",
|
|
"Non-goal: any device deploy."
|
|
],
|
|
"changes": [
|
|
"Audited for stdin-draining loops BEFORE extracting anything. focus_daemon.sh has five `while IFS= read -r pkg; do ... done < file` loops and EVERY body calls pm, which inherits and drains the loop's stdin if the file is piped in instead. All five moved verbatim and none was converted to a pipe. A note above them in daemon_apps.sh says why, because the measured symptom elsewhere in this repo was processing 1 package of 54.",
|
|
"Checked which globals cross the seam. CURRENT_MODE is written by init (staying) and by enable/disable (moving), and read by main; _CURFEW_TICK_CACHED is written by curfew_active (moving) and cleared by main each tick. Both are genuine shared globals and stay declared in the entry script, the same call made for NET_BUILT in the curfew split.",
|
|
"Placed all three as flat siblings and added them to both deploy lists, then verified the lists correspond exactly in both directions.",
|
|
"Wrote 110 assertions concentrated on the decisions that matter: the midnight-wrapping curfew window, the Haversine against known city distances, the day-vs-night whitelist swap, the default-handler safety net that keeps the keyboard enabled, and the fact that each sweep loop processes every package rather than only the first."
|
|
],
|
|
"verification": [
|
|
{
|
|
"command": "bash phone_focus_mode/lib/tests/test_daemon_libs.sh",
|
|
"result": "pass",
|
|
"evidence": "Results: 110 passed, 0 failed. None of this code had a test before."
|
|
},
|
|
{
|
|
"command": "python3 meta/scripts/mutate_shell.py meta/scripts/fixtures/mutations/daemon_libs.json",
|
|
"result": "pass",
|
|
"evidence": "33 killed, 0 not killed. Two survived the first run and both were real test defects: the whitelist and sysprotect exactness assertions used a SUPERSTRING of a listed entry, which fails under both grep -qF and grep -qxF and so proved nothing about which was in use. Rewritten to use a substring, which discriminates."
|
|
},
|
|
{
|
|
"command": "bash meta/scripts/shell_coverage.sh phone_focus_mode/lib/tests/test_daemon_libs.sh daemon_state.sh",
|
|
"result": "pass",
|
|
"evidence": "daemon_state.sh: 67/67 lines = 100.00%."
|
|
},
|
|
{
|
|
"command": "bash meta/scripts/shell_coverage.sh phone_focus_mode/lib/tests/test_daemon_libs.sh daemon_location.sh",
|
|
"result": "fail",
|
|
"evidence": "daemon_location.sh: 26/40 = 65.00%, NOT 100%. Every uncovered line (24-37) is inside the embedded awk Haversine program. kcov instruments those lines but bash never reports them, exactly as it does for multi-line array literals. Demonstrated to be an artifact rather than untested code: mutating R = 6371000.0 to R = 1.0 and dropping the longitude term from the formula BOTH fail the suite, so the awk body is fully exercised. Reproduced the class in an isolated probe where a one-line awk measures 100% and the identical multi-line awk measures 0%. Collapsing the formula onto one line would satisfy kcov at the cost of the readability of the only piece of real mathematics in the repo; that trade was declined."
|
|
},
|
|
{
|
|
"command": "bash meta/scripts/shell_coverage.sh phone_focus_mode/lib/tests/test_daemon_libs.sh daemon_apps.sh",
|
|
"result": "fail",
|
|
"evidence": "daemon_apps.sh: 71/76 = 93.42%, NOT 100%. All five uncovered lines (35, 60, 110, 130, 158) are the trailing `done < file` of a redirect-driven while loop — the same artifact class fixed by piping in curfew_net.sh, which is NOT safe here because every one of these loop bodies calls pm. Demonstrated to be an artifact: redirecting two of them from /dev/null instead fails the suite, so the lines execute and are load-bearing. Both are in the mutation spec permanently."
|
|
},
|
|
{
|
|
"command": "bash meta/scripts/verify_shell_split.sh 35ddf41 phone_focus_mode/focus_daemon.sh phone_focus_mode/focus_daemon.sh phone_focus_mode/daemon_location.sh phone_focus_mode/daemon_state.sh phone_focus_mode/daemon_apps.sh",
|
|
"result": "pass",
|
|
"evidence": "IDENTICAL: all 23 top-level functions moved verbatim. Nothing was restructured, which is the point given the stdin hazard."
|
|
},
|
|
{
|
|
"command": "shellcheck on each touched file individually (no -x); sh -n on the four phone-side scripts",
|
|
"result": "pass",
|
|
"evidence": "All thirteen clean standalone. Seven SC2034 findings — test files resetting a config global for the next file's cases — were each resolved by reading the value back, not by a disable. All four phone scripts parse under ash."
|
|
},
|
|
{
|
|
"command": "deploy-list parity check in both directions",
|
|
"result": "pass",
|
|
"evidence": "comm over the push list and the cp list returns empty both ways. daemon_location.sh, daemon_state.sh and daemon_apps.sh appear in both."
|
|
},
|
|
{
|
|
"command": "bash meta/scripts/check_file_length.sh --all",
|
|
"result": "pass",
|
|
"evidence": "18 over-cap files, down from 19. focus_daemon.sh 206, the three siblings 94/140/165, and the six test files between 21 and 249."
|
|
}
|
|
],
|
|
"risks": [
|
|
"TWO SUBJECTS ARE BELOW 100% LINE COVERAGE and the numbers above are the real ones. Both shortfalls are kcov attribution failures shown by mutation to cover executed code, but anyone auditing the coverage figure alone will see 65% and 93% and should read this entry rather than assume neglect.",
|
|
"UNVERIFIED ON DEVICE. This is the fourth enforcer-family split of the session without a deploy, and the largest. focus_daemon.sh now sources three files; a partial push leaves it unable to start.",
|
|
"The five redirect-driven loops are a standing trap for future edits. A later change that pipes any of them in — a natural-looking cleanup, and one this session performed deliberately in another file — would silently process one package instead of all of them. The comment above them and the three mutations pinning them are the only guards."
|
|
],
|
|
"rollback": [
|
|
"git revert the commit. focus_daemon.sh returns to a single 543-line file, over the cap and untested, and deploy.sh stops pushing the three siblings.",
|
|
"After rollback, run sh -n phone_focus_mode/focus_daemon.sh expecting exit 0, and confirm grep -c 'daemon_location\\|daemon_state\\|daemon_apps' phone_focus_mode/deploy.sh returns 0.",
|
|
"A rollback AFTER a deploy leaves three stale files in $REMOTE_DIR; they are inert once nothing sources them."
|
|
]
|
|
}
|