Enhance test coverage: sign-in, account changes and session recovery #473

Manually merged
hloth merged 1 commit from Enucatl/open-grind:test/auth-session-coverage into main 2026-10-27 12:08:51 +01:00
Contributor

Cover CAPTCHA retries and failures, successful sign-in, account state
cleanup, reconnect recovery, duplicate deliveries and expired sessions.

Exercise client behavior through controlled native and API responses
without requiring a device or live account.

This is how far we can go, together with the existing coverage, to contribute to #51 without using live accounts and emulators.

Cover CAPTCHA retries and failures, successful sign-in, account state cleanup, reconnect recovery, duplicate deliveries and expired sessions. Exercise client behavior through controlled native and API responses without requiring a device or live account. This is how far we can go, together with the existing coverage, to contribute to #51 without using live accounts and emulators.
Test sign-in, account changes and session recovery
Some checks failed
check / check (pull_request) Has been cancelled
credits / credits (pull_request) Has been cancelled
dbbb6e7dc3
Cover CAPTCHA retries and failures, successful sign-in, account state
cleanup, reconnect recovery, duplicate deliveries and expired sessions.

Exercise client behavior through controlled native and API responses
without requiring a device or live account.
Remove explanatory comments from recovery tests
Some checks failed
ci-orchestrator / provision running on cpx42 in fsn1
credits / credits (pull_request) Failing after 1m4s
check / check (pull_request) Successful in 43m33s
dd31fd1a3b
hloth requested changes 2026-10-26 22:27:35 +01:00
Dismissed
hloth left a comment
  • Rename conversation-recovery.integration.svelte.test.ts to conversation-state-recovery.svelte.test.ts, like the conversation-state-*.svelte.test.ts files next to it
  • Rebase onto main, squash into one signed commit and force push

Thank you!

- Rename conversation-recovery.integration.svelte.test.ts to conversation-state-recovery.svelte.test.ts, like the conversation-state-*.svelte.test.ts files next to it - Rebase onto main, squash into one signed commit and force push Thank you!
Lines 69-70
@ -0,0 +66,5 @@
await Promise.all([
import("@testing-library/svelte"),
import("$lib/chat/conversations-context.svelte"),
import("../../routes/(protected)/(navbar)/settings/(me)/SignOutButton.svelte"),
import("../../routes/auth/sign-in/SignInForm.svelte"),
Owner

The only $lib test that imports routes, and there's no account-switch module here. It drives SignOutButton, SignInForm and the protected layout: move it next to SignOutButton.svelte, e.g. SignOutButton.account-switch.svelte.test.ts like MediaImage.retry.svelte.test.ts.

The only `$lib` test that imports routes, and there's no `account-switch` module here. It drives SignOutButton, SignInForm and the protected layout: move it next to SignOutButton.svelte, e.g. `SignOutButton.account-switch.svelte.test.ts` like `MediaImage.retry.svelte.test.ts`.
Author
Contributor

Moved the test next to SignOutButton.svelte as SignOutButton.account-switch.svelte.test.ts. Updated its imports.

Moved the test next to `SignOutButton.svelte` as `SignOutButton.account-switch.svelte.test.ts`. Updated its imports.
Enucatl marked this conversation as resolved
Lines 290-301
@ -0,0 +287,15 @@
await assertSecondAccount(app);
});
it("keeps the first account's data and notifications when the Google account switch is cancelled", async () => {
const { render, fireEvent, screen } = testing;
const app = await firstAccount();
const { consumeGoogleHandoff } = await import("./google-handoff");
const { default: Confirm } =
await import("$lib/components/feedback/GoogleHandoffConfirmAlert.svelte");
render(Confirm);
const switching = consumeGoogleHandoff();
await fireEvent.click(
await screen.findByRole("button", { name: "Cancel" }),
);
await switching;
Owner

google-handoff.test.ts "keeps the current account and discards the handoff when the switch is declined" already shows nothing gets signed out. Run the confirmed switch end to end instead: the mock answers sign_in_with_google_handoff (line 118), but no test reaches it.

google-handoff.test.ts "keeps the current account and discards the handoff when the switch is declined" already shows nothing gets signed out. Run the confirmed switch end to end instead: the mock answers `sign_in_with_google_handoff` (line 118), but no test reaches it.
Author
Contributor

Replaced the cancelled-switch case with a confirmed Google switch. The test clicks Continue, calls sign_in_with_google_handoff, and checks the new account and the removal of the previous account data.

Replaced the cancelled-switch case with a confirmed Google switch. The test clicks Continue, calls `sign_in_with_google_handoff`, and checks the new account and the removal of the previous account data.
Enucatl marked this conversation as resolved
@ -0,0 +132,5 @@
});
}
function reconnect() {
clock += 3_000;
Owner

3_000 only means "past THROTTLE_MS (2000) in reconcile.ts". Name it. Same at 180 and 245.

`3_000` only means "past `THROTTLE_MS` (2000) in reconcile.ts". Name it. Same at 180 and 245.
Author
Contributor

Named the interval PAST_RECONCILE_THROTTLE_MS and used it for all three clock advances.

Named the interval `PAST_RECONCILE_THROTTLE_MS` and used it for all three clock advances.
Enucatl marked this conversation as resolved
@ -0,0 +169,7 @@
).toEqual(ids);
}
beforeAll(async () => {
emit("ws:connected");
await Promise.resolve();
});
Owner

This uses up the reconciler's first-connect skip (#firstConnect in reconcile.ts). With the comment gone nothing says so, move it into a helper whose name does.

This uses up the reconciler's first-connect skip (`#firstConnect` in reconcile.ts). With the comment gone nothing says so, move it into a helper whose name does.
Author
Contributor

Moved the initial connection into consumeFirstConnectSkip() and used that helper in beforeAll.

Moved the initial connection into `consumeFirstConnectSkip()` and used that helper in `beforeAll`.
Enucatl marked this conversation as resolved
@ -0,0 +251,4 @@
),
).toHaveLength(2),
);
await new Promise((resolve) => setTimeout(resolve, 0));
Owner

Use microtasks() from conversations-test-helpers. Same at 314 and 392.

Use `microtasks()` from conversations-test-helpers. Same at 314 and 392.
Author
Contributor

Replaced all three zero-delay waits with microtasks() from conversations-test-helpers.

Replaced all three zero-delay waits with `microtasks()` from `conversations-test-helpers`.
Enucatl marked this conversation as resolved
Lines 303-305
@ -249,0 +300,6 @@
"completes %s sign-in and drops the previous profile before navigating",
async (vendor) => {
await cachePreviousProfile();
gotoMock.mockImplementation(() => {
expect(isProfileCached(123)).toBe(false);
});
Owner

If this expect fails, it throws inside finishSignIn, which reports it as a sign-in failure, so the test fails on toastMock.error instead of here. Record isProfileCached(123) and assert it after.

If this expect fails, it throws inside `finishSignIn`, which reports it as a sign-in failure, so the test fails on `toastMock.error` instead of here. Record `isProfileCached(123)` and assert it after.
Author
Contributor

The test now records isProfileCached(123) when navigation starts. It checks the recorded value after sign-in completes.

The test now records `isProfileCached(123)` when navigation starts. It checks the recorded value after sign-in completes.
Enucatl marked this conversation as resolved
@ -249,0 +351,4 @@
kind: "restriction",
restriction,
});
expect(isProfileCached(123)).toBe(true);
Owner

Nothing needs the old profile to stay cached here: the restriction popup signs out on close. Drop it.

Nothing needs the old profile to stay cached here: the restriction popup signs out on close. Drop it.
Author
Contributor

Removed the old-profile cache setup and the cache assertion from the restriction test.

Removed the old-profile cache setup and the cache assertion from the restriction test.
Enucatl marked this conversation as resolved
Lines 403-404
@ -249,0 +400,5 @@
},
);
it.each([false, new Error("Assignment check failed")])(
"reports wrong credentials when the CAPTCHA assignment is unavailable (%j)",
Owner

%j prints the Error row as ({}). Name the rows and use %s.

`%j` prints the Error row as `({})`. Name the rows and use `%s`.
Author
Contributor

Named the rows disabled and check failed. The test title now uses %s.

Named the rows `disabled` and `check failed`. The test title now uses `%s`.
Enucatl marked this conversation as resolved
@ -249,0 +444,4 @@
"grindrMissing",
"The reCAPTCHA helper needs the Grindr app installed to verify this sign-in.",
],
["executionFailed", "Captcha verification failed. Try again."],
Owner

No such reason. RecaptchaError in src-tauri/src/api/recaptcha/error.rs sends mintFailed, noToken, failed and others, use a real one for the fallback.

No such reason. `RecaptchaError` in src-tauri/src/api/recaptcha/error.rs sends `mintFailed`, `noToken`, `failed` and others, use a real one for the fallback.
Author
Contributor

Replaced executionFailed with failed, which is a real RecaptchaError reason.

Replaced `executionFailed` with `failed`, which is a real `RecaptchaError` reason.
Enucatl marked this conversation as resolved
Enucatl force-pushed test/auth-session-coverage from dd31fd1a3b
Some checks failed
ci-orchestrator / provision running on cpx42 in fsn1
credits / credits (pull_request) Failing after 1m4s
check / check (pull_request) Successful in 43m33s
to c1bcdb67e1
Some checks failed
ci-orchestrator / provision running on cpx22 in fsn1
audit / audit (pull_request) Failing after 11s
credits / credits (pull_request) Successful in 2m14s
check / check (pull_request) Successful in 38m55s
2026-10-27 04:50:02 +01:00
Compare
Author
Contributor

In reply to the review:

Renamed the recovery test to conversation-state-recovery.svelte.test.ts. All nine inline requests are fixed, with a reply in each thread.

Rebased onto upstream/main, squashed the changes into one signed commit, and force-pushed c1bcdb67.

Validation passed in disposable containers: 4,156 frontend tests, 803 Rust tests, 750 browser cases, and 40 layout guards. Formatting, lint, types, shared config, Rust formatting, and Clippy passed.

Five browser cases passed on retry. Three live Rust tests and one macOS-only browser case were skipped.

In reply to [the review](https://git.opengrind.org/open-grind/open-grind/pulls/473#issuecomment-4635): Renamed the recovery test to `conversation-state-recovery.svelte.test.ts`. All nine inline requests are fixed, with a reply in each thread. Rebased onto `upstream/main`, squashed the changes into one signed commit, and force-pushed [c1bcdb67](https://git.opengrind.org/open-grind/open-grind/commit/c1bcdb67e10b2d42704e93be7ee3ae71a020fcc5). Validation passed in disposable containers: 4,156 frontend tests, 803 Rust tests, 750 browser cases, and 40 layout guards. Formatting, lint, types, shared config, Rust formatting, and Clippy passed. Five browser cases passed on retry. Three live Rust tests and one macOS-only browser case were skipped.
hloth approved these changes 2026-10-27 12:08:31 +01:00
hloth manually merged commit 2800d4e6de into main 2026-10-27 12:08:51 +01:00
Sign in to join this conversation.
No description provided.