Repository navigation
Description
Finding
infra/github-backup/systemd/drain-wrapper.sh — the systemd drainer's only Bitwarden credential path for the github-backup estate mirror — had its credential-loading logic changed twice in one evening, and none of it is tested:
- PR github-backup: portable Bitwarden env in drain wrapper #3222 (github-backup: portable Bitwarden env in drain wrapper #3222, commit a0d2da4) replaced the hard
source ~/tools/bws-env.shwith a three-way branch (sandbox~/tools, laptop~/hatch/tools, raw access-token file). - PR github-backup: drain wrapper bws access fix (laptop token store) #3226 (github-backup: drain wrapper bws access fix (laptop token store) #3226, commit 6361b89) replaced that again: export
~/.config/bws/access-tokenwhen present, then probebws secret listand only on failure source abws-env.shfrom either candidate path, with sourcing failures masked (source "$f" || true).
Both PRs touched only drain-wrapper.sh (verified from both merge commits' file lists). On current main (3adad8fc9e2e) the fallback logic is at drain-wrapper.sh:11-18, and there is no test for the wrapper anywhere in the repo: infra/github-backup/systemd/ contains no test file (directory listing verified), and a code search for drain-wrapper returns only nixos/home/github-backup.nix and the drain service unit.
Why it matters
The fallback branch is precisely the code that runs only on a machine where the primary credential path has already failed — the situation both PRs were written for (the laptop drain). Its failure modes are silent or late:
- If bare
bwsfails andbws-env.shis missing or itself fails, the|| truemask lets the script continue to the Pythoneval, which then dies with a raw traceback/KeyError at timer fire time, not at deploy time. - Path drift (the wrapper already moved conventions once:
~/toolsvs~/hatch/toolsvs~/.config/bws) breaks the fallback without any signal until a drain run fails and the estate mirror silently stops draining.
The sibling scripts in this fleet's backup tooling carry stubbed tests (e.g. pkgs/cold-store-reaper/tests/); the drain wrapper — which handles live credentials — has none.
Acceptance criteria
- A stubbed shell test for
drain-wrapper.sh(fake HOME, stubbws, stub drain target — no real Bitwarden, no network) covering all four branches:BWS_ACCESS_TOKENalready set in the environment → no token-file export, nobws-env.shsourcing, drain proceeds.- Token file present at
~/.config/bws/access-token→ exported, barebwssucceeds, no fallback sourcing, drain proceeds. - Bare
bws secret listfails and abws-env.shexists (each candidate path) → it is sourced, credentials load, drain proceeds. This is the PR github-backup: drain wrapper bws access fix (laptop token store) #3226 branch that currently has zero coverage. - No working credential path → the wrapper exits non-zero before invoking the drain, with a comprehensible error.
- The test runs in the same place/convention as the repo's other shell-script tests and passes.
- Production behavior of
drain-wrapper.shis unchanged unless a branch is shown broken by the new test, in which case the fix is part of this issue.
Found by pr-diff-review lane B reviewing PRs #3222 and #3226 (batch 3217–3251, 2026-11-03). Cross-checks that this is not already covered: open tracker issue #3215 (estate mirror system) does not mention wrapper tests; issue #3240 covers non-atomic state JSON writes in the fetch/drain scripts, a different defect.
Activity
dezren39 commentedon Nov 4, 2026
🤖 Agent note · picked up
dezren39 commentedon Nov 4, 2026
🤖 Agent note · filed
packet-5222-triage.jsonin the goal's hidden_files; evidence in the issue body.185 remaining items
test(github-backup): stubbed test for drain-wrapper.sh credential bra…
Merge pull request #6542 from developing-today/queue/8957-5222-drain-…
dezren39 commentedon Nov 11, 2026
Agent note — task 8957 picked up (lane any-a): writing the stubbed drain-wrapper shell test direct
user/reviewwas already reviewed by lane M ("acceptance criteria are explicit and scoped; no Drew decision needed — proceed"). This lane takes the fix direct and says so here; no other worker can act on the task while the row is bound.infra/github-backup/systemd/drain-wrapper.test.sh) covering the four credential branches — env token, ~/.config/bws/access-token file, bws-env.sh fallback after a bare-bws failure, and total failure (exit 1, exact stderr, drain not exec'd) — withbwsand the drain entry point stubbed (no real credentials anywhere), plus a scripts-test CI step in the run-switch pattern so it runs.Merge pull request #8658 from developing-today/queue/8957-5222-drain-…
dezren39 commentedon Nov 11, 2026
Agent note — task 8957 done (lane any-a): drain-wrapper fallback test landed via PR #8658
f192614702a9373324f4156bc5f3c612ae68bf62: addsinfra/github-backup/systemd/drain-wrapper.test.sh(stubbedbws+ stub drain entry; 13 checks across the four credential branches — env token, access-token file, bws-env.sh fallback, total failure — plus env-over-file precedence) and ascripts-testCI step in the run-switch pattern.drain-wrapper.shunchanged: every branch behaved as documented, so the packet's no-behavior-change exclude held.lib/sops-atomic-writers.test.shandlib/run-switch.test.shexit 0. One real-world finding baked into the test: hosts that inject credential helpers into shells (exported functions / BASH_ENV) defeat credential stubs, so the wrapper is invoked viaenv -iwith a controlled HOME/PATH.