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

Open

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
    queue/queuedHas a queued task in the Supabase agent queue
    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
    queue/queuedHas a queued task in the Supabase agent queue
    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. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged

    • Agent: queue worker (repo-worker-code), lane code-n
    • Session / ID: task 8954
    • Found via: queue claim
    • Verdict: CONFIRMED at current main (f486f2aab6a98cf709a4b37659441f318eafa0f8). Fresh reads this run:
      • infra/github-backup/systemd/drain-wrapper.sh on main carries exactly the filed credential logic: token-file export first, then a probe of the bare credential CLI, and only on failure a masked, non-fatal source of a fallback env script from either candidate path (lines 11–18, matching the issue's evidence).
      • infra/github-backup/systemd/ on main contains only the wrapper, the service/timer units, and install-units.sh — no test file.
      • No branch of that fallback logic has any automated coverage; branch 4 of the acceptance criteria (no working credential path) currently continues past the masked source toward the drain invocation rather than exiting early with a comprehensible error — the follow-up test will pin the expected behavior and any fix it demonstrates.
    • Routing: the stubbed four-branch shell test is well-scoped and low-risk; enqueued as a follow-up small_fix queue task by this triage (see the queue task id in the completion of task 8954). Production behavior stays unchanged unless the new test demonstrates a broken branch.
    • Links: source PR github-backup: portable Bitwarden env in drain wrapper #3222 · PR github-backup: drain wrapper bws access fix (laptop token store) #3226 · sibling coverage note: issue github-backup(state): plan.json, state.json and MANIFEST.json are written non-atomically and loaded with bare json.load — one torn write wedges the daily fetch, the drainer and manifest regeneration #3240 is a different defect (state-JSON atomicity), not this test gap.
  5. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — triage task 8954 complete: issue #5222 confirmed at main f486f2aab; the four-branch stubbed test work is enqueued as task 8957 (queue repo-health-code-pilot). Issue #5222 stays open under task 8957.

  6. added
    queue/queuedHas a queued task in the Supabase agent queue
    and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 4, 2026
  7. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · correction

    • Agent: pr-diff-review-b
    • Session / ID: cron pr-diff-review-b run 2026-11-03 17:18 CST
    • Found via: filed this run
    • Task: Correction to the filed note above (comment 6619355838): the triage packet for this issue is task 8954 in repo-health-code-pilot (enqueue receipt 2026-11-04T00:42:30Z, dedupe key repo-health:v1:triage:developing-today/code:issue:5222), not task 8959 — that number came from a fabricated tool delivery during the run and is retracted. Everything else in the filed note stands.
  8. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 4, 2026
  9. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

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 fixespriority/lowNice to have; do when convenientqueue/claimedQueue worker lifecycle statesource/pr-diff-reviewFiled by the pr-diff-review jobstatus/in-progressQueue worker lifecycle statetask/triageQueue packet kind: verify, reproduce, and route this itemwork/assignedQueue worker lifecycle state

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions