Skip to content

Add tests for retryWithBackoff (auth retry helpers have no test file) #884

Description

@TortoiseWolfe

The task

src/lib/auth/retry-utils.ts exports sleep, retryWithBackoff and retrySupabaseAuth, and
has no test file. Add one.

Why this is a good first issue

The module has zero references to document, window, fetch, localStorage or a database
client — the retry logic is self-contained, and you supply the function it retries. That means
you can test it by passing in a function you control: one that always fails, one that fails
twice then succeeds, one that succeeds immediately.

Where the test goes

src/lib/auth/retry-utils.test.ts, beside the source.

Acceptance criteria

  • A test file exists at src/lib/auth/retry-utils.test.ts
  • retryWithBackoff succeeds on the first try without retrying — assert the supplied
    function was called exactly once, not just that the result was right
  • It retries and then succeeds — a function that throws twice then returns
  • It gives up after the maximum attempts and surfaces the error rather than swallowing it
  • Use fake timers (vi.useFakeTimers()) rather than really waiting for the backoff — a test
    that sleeps for real makes the whole suite slower for everyone
  • docker compose exec scripthammer pnpm test --run src/lib/auth/retry-utils.test.ts passes

The one thing that matters here

Count the calls, don't just check the answer. expect(fn).toHaveBeenCalledTimes(3) is the
assertion that actually proves retrying happened; asserting only the final value would pass
against an implementation that never retried at all.

Then break it on purpose — set max attempts to 1, or delete the retry loop — and confirm your
test goes red. Say which mutation you tried in the PR. A test that cannot fail is the most
common defect in this repo (#396).

Getting set up

docker compose up -d
docker compose exec scripthammer pnpm test --run src/lib/auth/retry-utils.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions