Skip to content

fix: three live-tier device-flow test failures - #1301

Merged
neuromechanist merged 2 commits into
devfrom
fix/live-tier-device-flow
Sep 8, 2026
Merged

neuromechanist merged 2 commits into
devfrom
fix/live-tier-device-flow

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the three integration-dev failures on dev after epic #1272 (device authorization grant) deployed to api-test.nemar.org. All three failures were the tests' own premise being wrong, not a backend bug — confirmed by reading the code and reproducing each against the live dev worker before changing anything.

1 & 2. "a pending account cannot confirm" (test/auth-device-cli-live.test.ts:323, test/auth-device-flow.test.ts)

Root cause: POST /auth/code/verify unconditionally promotes status='pending' to 'verified' in the same transaction that mints the session (backend/src/services/email-verification.ts:200-248, applyEmailVerification; wired into the route at backend/src/routes/auth-web.ts:603-632). Both tests seed pending, then sign in through the real /auth/code/request + /auth/code/verify flow (signIn()) before hitting /auth/device/confirm — so by the time they hold a session cookie, the account is already verified, not pending. account_pending is unreachable at /auth/device/confirm through this path, for the same shape of reason ADR 0047 already documents for account_revoked being unreachable at lookup/confirm/deny (findSessionByCookieId filters revoked accounts out of session resolution — here it's promotion-on-verify instead of exclusion-at-lookup).

Verified empirically against api-test.nemar.org: seeded a pending row, ran /code/request + /code/verify, then re-read the row via the idempotent seed-fixture endpoint — status came back verified.

The one place a session can legitimately be pending is a brand-new ORCID sign-up (backend/src/routes/auth-orcid.ts's finalize handler mints a session before the first verification code is even sent), which the seed-fixture-plus-passwordless-signin path used here cannot reach — driving real ORCID consent is out of reach for an automated test (documented elsewhere in auth-device-cli-live.test.ts).

Backend or test wrong: the test's premise was wrong. Both tests now assert the true behavior: sign-in promotes, confirm returns 200. backend/src/services/device-auth.ts's account_pending refusal logic itself is untouched and correct — it's just unreachable via this exact fixture path, which the corrected tests' comments now say explicitly, citing ADR 0047 and ADR 0040 phase 2 by content.

Mutation used: flipped expect(res.status).toBe(200) back to toBe(403) in both files — red, as expected — then reverted.

3. "signup with flags lands the PATCH and the upload-access request" (test/auth-device-cli-live.test.ts:393)

Root cause: NOT the ORCID-verification gate hypothesized going in. Temporarily logging the CLI subprocess's stdout/stderr showed the actual cause: completeProfile's guardNonInteractive (src/commands/auth.ts:587-592) printed "Provide --username (this terminal cannot prompt)." and exited 1 before the PATCH or the upload-access request were ever attempted. The bare seedWebUser(email, "verified") fixture leaves username=NULL and given_name/family_name unset, so sign-in's username auto-assignment (pickUsernameForName) has nothing to work from, username stays a profile_gaps entry, and the subprocess (stdin: "ignore") cannot be prompted — so it refuses to hang, correctly.

Fixing that one gap surfaced a second, real one: PROFILE_GAP_MATRIX's orcid_verified row (shared/contract/profile-gaps.ts:186-197) blocks upload_access regardless of ORCID linkage, and given_name/family_name are "raised even under a verified ORCID iD" per the matrix's own comment — none of which the fixture set, and none of which completeProfile can set via a CLI flag (matches this file's own recorded rationale: a real ORCID account supplies these; the fixture is a direct DB seed standing in for one).

Backend or test wrong: the test was wrong — its premise ("a bare seedWebUser(email, "verified") is signup-ready") was false. Fixed by seeding given_name/family_name/orcid/orcid_verified: true (matching what a real ORCID-created web account looks like) and passing --username explicitly. Also swapped the GitHub handle from octocat to mojombo: once the PATCH actually runs, octocat would get claimed by the fixture account, breaking test/api.test.ts's "valid but unregistered github returns registered: false" assertion — an incident already documented once in auth-passwordless.test.ts's own comments. The test now releases mojombo in a finally block so reruns of either file don't 409. Strengthened the assertion to actually check GET /auth/me (not just exit code), since the test's own name is a claim about server state.

Mutations used:

  • Flipped expect(meBody.user?.city).toBe("San Diego") to "Wrong City" — red, reverted.
  • Removed given_name/family_name from the fixture (the actual bug class) — reproduced exitCode === 1, reverted.

Verification

  • All corrected tests pass against https://api-test.nemar.org (TEST_API_URL=https://api-test.nemar.org bun test test/auth-device-cli-live.test.ts test/auth-device-flow.test.ts), run twice to confirm rerun-safety.
  • test/api.test.ts's octocat-unregistered assertion and auth-passwordless.test.ts's mojombo test both still pass.
  • bun run lint, bun run typecheck, and backend/test/device-auth-routes.test.ts + test/contract-device-auth.unit.test.ts (unit tier, closest to the area even though no backend files were touched) all pass.

Left alone

  • backend/src/services/device-auth.ts's account_pending/account_revoked refusal logic — untouched; it's correct, just unreachable via these fixture paths.
  • GET /users/me not returning city/country/upload_access_requested_at on the wire (backend/src/routes/users.ts) — a real gap next to GET /auth/me's fuller publicUser() shape, discovered while writing the new assertions. Out of scope here; worked around by verifying via GET /auth/me with the session cookie instead.

/auth/code/verify promotes pending->verified on every successful
sign-in (ADR 0040 phase 2), so account_pending is unreachable at
/auth/device/confirm through this fixture, the same way ADR 0047
already documents account_revoked as unreachable there.
completeProfile's guardNonInteractive was exiting 1 before the PATCH
or upload-access request ran (username still a gap, stdin ignored),
and separately orcid_verified/given_name/family_name gaps would have
refused upload access. Seed a fixture that looks like a real ORCID
web account and pass --username explicitly; verify the PATCH and
request actually landed via GET /auth/me.
@neuromechanist
neuromechanist merged commit f8f203b into dev Sep 8, 2026
12 checks passed
@neuromechanist
neuromechanist deleted the fix/live-tier-device-flow branch September 8, 2026 15:10
neuromechanist added a commit that referenced this pull request Sep 8, 2026
Six of auth-passwordless.test.ts's assertions were pinned to
pre-epic-#1250/#1272 behavior and had never run since (the
passwordless-auth-test CI job only fires on a PR into main):

- status assertion expected the raw DB "pending"; /code/verify has
  promoted a first-time pending row to verified since ADR 0040
  phase 2, and the wire value is userStatusForDashboard's "active"
  mapping, not the DB status.
- the populated-profile fixture hardcoded ORCID
  "0000-0002-1825-0097", now UNIQUE on live rows (migration 0077)
  and long claimed by earlier runs; switched to a freshOrcid()
  helper mirroring auth-device-cli-live.test.ts's (#1301).
- the pending-cookie-rejected test tried to reach a pending account
  through /code/verify, which no longer leaves one pending; it now
  mints the cookie while approved and demotes the row afterward to
  exercise the isActiveAccountStatus gate directly.
- "name fields are not editable" predated ADR 0042 phase #1253,
  which made given_name/family_name editable for an account with no
  verified ORCID; split into a no-ORCID success case and a
  verified-ORCID 409 case.
- the email-change hijack case expected code_incorrect; the
  session-bound lookup finds no row at all for a different user's
  session and answers code_expired (a pre-existing test bug from the
  same commit that added session binding, unrelated to the epics
  above).
- the final unregistered-address test was failing as a cascade of
  the code_incorrect bug above (the assertion failure aborted the
  test before the email change actually landed); resolved by the
  code_expired fix with no separate change needed.

Every corrected assertion verified against a mutated production
line via a local bun:sqlite + real Hono harness (no mocks): each
mutation reproduced the wrong-premise failure, each revert restored
green.

This branch was previously deployed

1 inactive deployment
npm — 9b0eb577 Deployed Sep 8, 2026 by neuromechanist via publish #2366
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant