fix(integrations): keep a simulated connection's accounts on reconnect

Open
#529 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
next.js, playwright, react, typescript
Domain
backend, testing

Research direction

Start with src/lib/adapters/simulated/index.ts and trace how exchangeCode gets its seed during reconnect, then read the reconnect flow in src/app/api/dev/fake-provider/authorize/route.ts. Update the simulated webhook setup in src/lib/adapters/simulated/webhooks.ts and Polar twin in src/lib/adapters/simulated/polar.ts; run npx vitest run src/lib/adapters/simulated. Finish by covering the refusal path in e2e/webhook-setup-polar.spec.ts with the keyboard and verifying reconnect preserves the included accounts.

Written by the indexing model from the issue text.

Description

area: integrations bug impact: low priority: P2 size: S

Context

Found while fixing the Fable review of #525 (Polar webhooks, #429).

A simulated provider's exchangeCode (src/lib/adapters/simulated/index.ts) mints a fresh seed for every grant ("A fresh seed per grant, so two simulated connections never share accounts or events"), and the twin's accounts are named after that seed (Polar's sim-org-<seed>). A reconnect, such as the write access consent of automatic webhook setup, is a new grant. So connect.ts upserts a second account with a new seed and leaves the first one included. Observed in an e2e run on #525: after the consent, the simulated Polar connection held sim-org-402df0db and sim-org-0f23f197, both included. The stale account no longer belongs to the grant, so the twin's sync refuses it ("Simulated has no such account").

The cost is concrete for #525. Polar's automatic setup needs a connection that includes exactly one organization (AutomaticWebhookSetup.accounts: "one"). Polar's twin therefore does not forward that limit (src/lib/adapters/simulated/polar.ts), or every simulated automatic setup would be refused after its own consent. The one-organization refusal is unit tested but cannot run end to end against the twin.

Plan

  1. Keep the seed on a reconnect of a simulated connection, for example by carrying the stored credential's seed through the reconnect state to the simulated consent screen and into the code exchangeCode reads.
  2. With the seed kept, forward accounts in simulatedConnectionSetup (src/lib/adapters/simulated/webhooks.ts), and drop the note in simulated/polar.ts.
  3. Add the one-organization refusal to e2e/webhook-setup-polar.spec.ts: seed a second included organization, choose automatic setup, and assert no consent screen and the refusal banner.

Acceptance criteria

  • Reconnecting a simulated connection leaves its accounts unchanged.
  • Polar's twin carries accounts: "one", and its automatic setup still succeeds after the consent.
  • Unit test for the reconnect seed; Playwright: the refusal path in e2e/webhook-setup-polar.spec.ts, with the keyboard.

Files and areas

  • src/lib/adapters/simulated/index.ts, src/lib/adapters/simulated/webhooks.ts, src/lib/adapters/simulated/polar.ts, src/app/api/dev/fake-provider/authorize/route.ts, e2e/webhook-setup-polar.spec.ts.
  • Non-goals: what a real provider's reconnect does with accounts it no longer lists.

Verification

  • npx vitest run src/lib/adapters/simulated
  • the Polar webhook setup spec through the guarded runner

Branch: <issue-number>-simulated-reconnect-seed
Closes with a Closes #<issue-number> footer on the commit or pull request.

Model: anthropic/claude-opus-5-5 | Reasoning effort: not reported by the harness

Dominant language
TypeScript
Stars
13
Forks
2
Avg merge
5h 20m
Merged PRs (30d)
287

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eddiejaoude/StackDash

All issues in eddiejaoude/StackDash

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.