Skip to content

github-backup: drain-wrapper Bitwarden fallback (PRs #3222/#3226) has no test — the bws-env branch runs only where the primary path already failed #5222

Closed

Description

@dezren39

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:

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 bws fails and bws-env.sh is missing or itself fails, the || true mask lets the script continue to the Python eval, which then dies with a raw traceback/KeyError at timer fire time, not at deploy time.
  • Path drift (the wrapper already moved conventions once: ~/tools vs ~/hatch/tools vs ~/.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, stub bws, stub drain target — no real Bitwarden, no network) covering all four branches:
    1. BWS_ACCESS_TOKEN already set in the environment → no token-file export, no bws-env.sh sourcing, drain proceeds.
    2. Token file present at ~/.config/bws/access-token → exported, bare bws succeeds, no fallback sourcing, drain proceeds.
    3. Bare bws secret list fails and a bws-env.sh exists (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.
    4. 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.sh is 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

  1. added
    kind/testTest coverage, test infrastructure, or test-only fixes
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    effort/sSmall: expected under 2 hours of work
    app/github-backupinfra/github-backup estate mirror system
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 4, 2026
  2. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  3. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. 185 remaining items

  5. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 11, 2026
  6. added 2 commits that reference this issue on Nov 11, 2026
  7. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Agent note — task 8957 picked up (lane any-a): writing the stubbed drain-wrapper shell test direct

    • Lane-binding record: assignment row 2101 binds task 8957 to opencode session ses_e5e37ae0456ffewgY9JTN0lNvp; task progress records that session as cleared 2026-11-11T02:02:11Z via park_task, and this lane's exclusion flip was refused (row unchanged) — the stale-binding anomaly seen on tasks 14653/14553/6513/6599 today. Task 8957 is at attempts 31/32, its scope is a single self-contained test file, and the prior user/review was 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.
    • Plan: new stubbed shell test beside the wrapper (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) — with bws and the drain entry point stubbed (no real credentials anywhere), plus a scripts-test CI step in the run-switch pattern so it runs.
  8. added a commit that references this issue on Nov 11, 2026
  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Agent note — task 8957 done (lane any-a): drain-wrapper fallback test landed via PR #8658

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/github-backupinfra/github-backup estate mirror systemeffort/sSmall: expected under 2 hours of workkind/testTest coverage, test infrastructure, or test-only fixesmeta/protocol-gapAn agent touched this without the required agent-note comment or labels; needs review of whypriority/lowNice to have; do when convenientsource/pr-diff-reviewFiled by the pr-diff-review jobtask/pr-shepherdQueue packet kind: shepherd an open PR or PR set to merge

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions