Repository navigation
fix: three live-tier device-flow test failures - #1301
Merged
Merged
Conversation
/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.
This was referenced Sep 8, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the three
integration-devfailures 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/verifyunconditionally promotesstatus='pending'to'verified'in the same transaction that mints the session (backend/src/services/email-verification.ts:200-248,applyEmailVerification; wired into the route atbackend/src/routes/auth-web.ts:603-632). Both tests seedpending, then sign in through the real/auth/code/request+/auth/code/verifyflow (signIn()) before hitting/auth/device/confirm— so by the time they hold a session cookie, the account is alreadyverified, notpending.account_pendingis unreachable at/auth/device/confirmthrough this path, for the same shape of reason ADR 0047 already documents foraccount_revokedbeing unreachable atlookup/confirm/deny(findSessionByCookieIdfilters 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
pendingrow, ran/code/request+/code/verify, then re-read the row via the idempotent seed-fixture endpoint — status came backverified.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 inauth-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'saccount_pendingrefusal 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 totoBe(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'sguardNonInteractive(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 bareseedWebUser(email, "verified")fixture leavesusername=NULLandgiven_name/family_nameunset, so sign-in's username auto-assignment (pickUsernameForName) has nothing to work from,usernamestays aprofile_gapsentry, 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'sorcid_verifiedrow (shared/contract/profile-gaps.ts:186-197) blocksupload_accessregardless of ORCID linkage, andgiven_name/family_nameare "raised even under a verified ORCID iD" per the matrix's own comment — none of which the fixture set, and none of whichcompleteProfilecan 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 seedinggiven_name/family_name/orcid/orcid_verified: true(matching what a real ORCID-created web account looks like) and passing--usernameexplicitly. Also swapped the GitHub handle fromoctocattomojombo: once the PATCH actually runs,octocatwould get claimed by the fixture account, breakingtest/api.test.ts's"valid but unregistered github returns registered: false"assertion — an incident already documented once inauth-passwordless.test.ts's own comments. The test now releasesmojomboin afinallyblock so reruns of either file don't 409. Strengthened the assertion to actually checkGET /auth/me(not just exit code), since the test's own name is a claim about server state.Mutations used:
expect(meBody.user?.city).toBe("San Diego")to"Wrong City"— red, reverted.given_name/family_namefrom the fixture (the actual bug class) — reproducedexitCode === 1, reverted.Verification
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 andauth-passwordless.test.ts's mojombo test both still pass.bun run lint,bun run typecheck, andbackend/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'saccount_pending/account_revokedrefusal logic — untouched; it's correct, just unreachable via these fixture paths.GET /users/menot returningcity/country/upload_access_requested_aton the wire (backend/src/routes/users.ts) — a real gap next toGET /auth/me's fullerpublicUser()shape, discovered while writing the new assertions. Out of scope here; worked around by verifying viaGET /auth/mewith the session cookie instead.