Skip to content

refactor(auth): tests sign browsers in through one Browser helper - #573

Merged
PiquelChips merged 4 commits into
mainfrom
refactor/544-tests-sign-in
Nov 21, 2026
Merged

PiquelChips merged 4 commits into
mainfrom
refactor/544-tests-sign-in

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Part of #544. Builds on #571 (merged), whose fixtures this uses.

crate::tests::Browser already signs a browser in, but test modules copied it anyway: Session::create in a transaction, a commit, then the cookie pair formatted by hand. That copy was in the emails, federation, recovery, OIDC and step-up tests, and at four passkey sites. Account creation copied InsertUser::named in six modules.

  • Browser::sign_in_by(database, context, user, credential) signs in from any request context with any credential, such as a given passkey, or a recovery's probation passkey. sign_in_with now calls it, and the copies use it.
  • passkey::tests::Fixture::social_sign_in covers the four passkey sites.
  • Accounts are created with insert_named. Where a test reads the display name ("Browser test", "Test user"), it keeps it.
  • Replicas::database() connects through Database::test(), which it used to repeat with the same pool size and time limits.

deletion/tests.rs still calls Session::create directly, because it asserts that the sign-in fails.

Differences

  • The two email-delivery tests that check a message names its account compared the handle with a literal mail-… string. They now compare it with the account's stored handle, which is the same value, so they don't depend on the fixture's handle format.
  • Fixture accounts keep the same handle prefixes. Their display names change only where no test reads them.

Unchanged

  • No test was merged or removed. Every file keeps the same test names as origin/main.
  • No files edited outside auth-service's test modules.

Checks

  • cargo clippy -p auth-service and -p sourceorigin-repository, --all-targets, pass with and without --all-features, -D warnings.
  • just db test on the top of the stack passes, but for a known audit::tests race that predates this stack and passes when re-run (reported separately).

Council review

Rounds: 2

Delegate Round 1 Round 2
GPT 6.1 Sol 9/10 9/10
Claude Opus 5.5 8/10 8.5/10
Claude Fable 5.2 8.5/10 9/10

Round 2 found no code defects. Its should-fixes were these descriptions, and its nits are applied.

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol, Claude Opus 5.5 and Claude Fable 5.2 (via T3 Code)

Scope: 11 files changed in apps/auth-service. Diff size: +95 / -189 lines.

Shared test infrastructure (src/tests.rs)

  • Adds Browser::sign_in_by(database, context, user_id, credential). It creates a session from the supplied RequestContext and Credential, then returns the browser.
  • Browser::sign_in_with keeps its signature. It now delegates to sign_in_by with RequestContext::TEST.
  • Replicas::database() calls Database::test(). It no longer builds a 5-connection pool and runs migrations directly.
  • Browser::new_account uses InsertUser::named("browser") and keeps the display name "Browser test".

Passkey tests (src/passkey/tests/)

  • Fixture::new seeds its account with InsertUser::named("key"). It takes the generated ID and handle from the record.
  • Adds Fixture::social_sign_in(). It signs another browser into the seeded account using AuthenticationMethod::Federation. The session stays unconfirmed.
  • confirmation.rs and sign_in.rs replace direct session creation with social_sign_in().

Session setup in other test modules

  • federation/tests/mod.rs: the user fixture uses insert_named("fed"). The session fixture uses sign_in_with.
  • emails/tests.rs: Harness::account uses insert_named and sign_in_by. It drops direct user and session construction.
  • oidc/tests/mod.rs and oidc/tests/step_up.rs: session cookies come from Browser helpers, not manual construction.
  • recovery/tests/mod.rs: Scenario::signed_in_with uses sign_in_by and returns the cookie.

Account fixtures and assertions

  • admin/tests/mod.rs: Harness::signed_in uses insert_named("admin").
  • deliveries/email/tests.rs: uses insert_named("mail"). Adds a stored_handle helper. Handle assertions compare against the stored handle, not a literal mail-… value.

Not changed

  • deletion/tests.rs still uses Session::create, because its test asserts that sign-in fails.
  • Test names are unchanged, according to the author.

Not verified here

  • Clippy and test results are author-reported only. This summary does not confirm them.

@PiquelChips PiquelChips added refactor No behviour changes tests Tests labels Nov 20, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The auth-service tests now use shared database and browser helpers to create named accounts and sessions. Email, federation, OIDC, recovery, and passkey test setup replaces direct user or session construction and manual cookie handling with those helpers.

Changes: Auth-service test fixture modernization

Layer / File(s) Summary
Shared test setup and named accounts
apps/auth-service/src/tests.rs, apps/auth-service/src/admin/tests/mod.rs, apps/auth-service/src/passkey/tests/mod.rs, apps/auth-service/src/federation/tests/mod.rs, apps/auth-service/src/deliveries/email/tests.rs
Replicas::database uses Database::test(). Shared browser setup adds sign_in_by, and test fixtures create named accounts. Email tests read persisted handles for verification and recovery-link assertions.
Browser-backed session setup
apps/auth-service/src/emails/tests.rs, apps/auth-service/src/federation/tests/mod.rs, apps/auth-service/src/oidc/tests/mod.rs, apps/auth-service/src/oidc/tests/step_up.rs, apps/auth-service/src/recovery/tests/mod.rs
Tests use browser sign-in helpers to create sessions and obtain cookies instead of constructing sessions and encoding cookies directly.
Passkey social sign-in helper
apps/auth-service/src/passkey/tests/mod.rs, apps/auth-service/src/passkey/tests/confirmation.rs, apps/auth-service/src/passkey/tests/sign_in.rs
The passkey fixture adds social_sign_in(). Passkey tests use the returned browser’s session ID and cookie.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Refactor

Possibly related PRs

Suggested labels: apps/auth-service

Merge Risk: Minimal · up to f1517

This refactor changes only test setup helpers and does not alter production behavior. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title is a conventional commit that names the main change: auth-service tests now sign browsers in through one shared Browser helper. The raw summary and objectives confirm that Browser::sign_in_b…
Description check Passed The description follows the repository template. It has a What and why section that explains the duplicated sign-in code, the change, and the related issue (Part of #544, builds on #571). It has a Tes…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title is a conventional commit that names the main change: auth-service tests now sign browsers in through one shared Browser helper. The raw summary and objectives confirm that Browser::sign_in_by is central and that sign_in_with delegates to it, so the title matches the changeset.

Full details: Description check

Explanation

The description follows the repository template. It has a What and why section that explains the duplicated sign-in code, the change, and the related issue (Part of #544, builds on #571). It has a Testing section that lists the clippy and db test runs and what was not tested (the deletion tests still call Session::create, and the audit::tests race). The checklist is not addressed, and it has no explicit 'Closes' line, but those are non-critical sections under the pass rule.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the sign-in trail,
Named accounts hop where handles were,
Browser cookies ride along,
Test sessions settle into place,
The bunny nods: the helpers work!

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7aea8ad4-e78b-47d8-86be-9caad23dd3ea
Commits

Reviewing files that changed from the base of the PR and between 6fcabb0 and f1517e4.

Files selected for processing: 11

  • apps/auth-service/src/admin/tests/mod.rs
  • apps/auth-service/src/deliveries/email/tests.rs
  • apps/auth-service/src/emails/tests.rs
  • apps/auth-service/src/federation/tests/mod.rs
  • apps/auth-service/src/oidc/tests/mod.rs
  • apps/auth-service/src/oidc/tests/step_up.rs
  • apps/auth-service/src/passkey/tests/confirmation.rs
  • apps/auth-service/src/passkey/tests/mod.rs
  • apps/auth-service/src/passkey/tests/sign_in.rs
  • apps/auth-service/src/recovery/tests/mod.rs
  • apps/auth-service/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@PiquelChips
PiquelChips force-pushed the refactor/544-tests-sign-in branch from e4042be to 2fe8e36 Compare November 20, 2026 08:54
@PiquelChips
PiquelChips marked this pull request as ready for review November 20, 2026 10:13
@PiquelChips
PiquelChips force-pushed the refactor/544-tests-sign-in branch 2 times, most recently from 5c9a78d to d47cd4b Compare November 20, 2026 14:12
Base automatically changed from refactor/544-tests-database-fixtures to main November 20, 2026 14:40
@PiquelChips
PiquelChips force-pushed the refactor/544-tests-sign-in branch from d47cd4b to 93f2765 Compare November 20, 2026 15:02
@PiquelChips
PiquelChips force-pushed the refactor/544-tests-sign-in branch from 93f2765 to f1517e4 Compare November 21, 2026 13:06
@github-project-automation github-project-automation Bot moved this from Needs Triage to Ready in sourceorigin.dev Nov 21, 2026
@PiquelChips
PiquelChips added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 319b802 Nov 21, 2026
14 checks passed
@PiquelChips
PiquelChips deleted the refactor/544-tests-sign-in branch November 21, 2026 13:20
@github-project-automation github-project-automation Bot moved this from Ready to Done in sourceorigin.dev Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor No behviour changes tests Tests

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant