Conversation
## Because - `recoveryKey.spec.ts` built its account details from `generateEmail()`, which only returns a string. It never registered the account with `TestAccountTracker`, so teardown could not destroy it. - The in-test UI delete was the only removal. Any failure before it left a real account on stage, with no error and nothing in CI. The spec runs 8 parameterized cases. - `changeEmail.spec.ts` re-pointed `credentials.email` only at the end of each test. If a test failed after the promotion, the tracker held an address that was by then a secondary, and cleanup's sign-in failed. ## This pull request - Replaces the hand-built object in `recoveryKey.spec.ts` with `testAccountTracker.generateAccountDetails()`. It uses the default `signin` email prefix and registers the account. - Keeps the in-test UI delete. `destroyAllAccounts()` checks `accountStatusByEmail` first and skips accounts that no longer exist. - Moves each `credentials.email` re-point in `changeEmail.spec.ts` to directly after the promotion it tracks. This covers the four tests that swap the primary email. The third test promotes twice, so it re-points twice. - Re-points the password in the fourth test directly after the new account is created. - Drops two trailing password assignments that these moves made into duplicates. ## Issue that this pull request solves Closes: https://mozilla-hub.atlassian.net/browse/FXA-14285
Contributor
There was a problem hiding this comment.
Pull request overview
Improves functional-test account cleanup after failures.
Changes:
- Registers recovery-key test accounts with
TestAccountTracker. - Updates tracked email/password credentials earlier during account mutations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/functional-tests/tests/settings/changeEmail.spec.ts |
Moves cleanup credential updates closer to account changes. |
packages/functional-tests/tests/key-stretching-v2/recoveryKey.spec.ts |
Generates registered account details for reliable teardown. |
Suppressed comments (4)
packages/functional-tests/tests/settings/changeEmail.spec.ts:69
- This mutation still happens only after
changePrimaryEmail's post-promotion assertions. If the promotion succeeds but either assertion fails, cleanup retains the former primary address and cannot sign in. Have the helper update the tracked credentials immediately after the promotion click, before validating the resulting UI.
// Update which email to use for account cleanup
credentials.email = newEmail;
packages/functional-tests/tests/settings/changeEmail.spec.ts:117
- This update is not reached when one of
changePrimaryEmail's assertions fails after the address was successfully promoted. In that failure mode teardown still holdsinitialEmail, now a secondary address, and leaks the account. Move the tracker mutation into the helper immediately after the promotion action and before its assertions.
// Update which email to use for account cleanup
credentials.email = secondEmail;
packages/functional-tests/tests/settings/changeEmail.spec.ts:148
- The promotion has completed before the alert assertion, so an assertion failure here leaves the tracker pointing at
secondEmail, which has become secondary. Updatecredentials.emailimmediately afterconfirmMfaGuardand before checking the alert so teardown remains usable when the UI assertion fails.
// The primary email is back to the initial one, so cleanup needs it again
credentials.email = initialEmail;
packages/functional-tests/tests/settings/changeEmail.spec.ts:188
- This assignment runs after both
changePrimaryEmail's internal assertions and the additional primary-email assertion on line 185. Any of those can fail after a successful promotion, leaving cleanup on the now-secondary old address. Update the tracked email immediately after the helper's promotion click, before all result assertions.
// Update which email to use for account cleanup
credentials.email = newEmail;
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+30
to
+31
| // Update which email to use for account cleanup | ||
| credentials.email = newEmail; |
Comment on lines
80
to
81
| // Update which password to use for account cleanup | ||
| credentials.password = newPassword; |
## Because - Registering the recoveryKey account with the tracker made teardown destroy it, but the test also deleted it through the UI. `accountStatusByEmail` still reported the account, so `destroyAccount` ran and failed with "Unknown account". All four v2 cases failed in teardown with a passing body. - `changePrimaryEmail` and `setNewPassword` assert after the server has already changed the address or the password. A failing assertion skipped the tracker update that followed the call, which is the leak this branch is fixing. ## This pull request - Drops the in-test delete from recoveryKey.spec.ts and lets teardown own the account lifecycle. Nothing asserted on that delete. - Moves the tracker updates inside `changePrimaryEmail` and `setNewPassword`, before their assertions, and passes the credentials in. - Sets the tracked email before the assertion on the promotion back to the initial address, for the same reason. - Drops a redundant second assignment of the same password in that test. The password assignment for the newly created account is unchanged: it tracks a different account and belongs where it is.
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.
Because
recoveryKey.spec.tsbuilt its account details fromgenerateEmail(), which only returns a string. It never registered the account withTestAccountTracker, so teardown could not destroy it.changeEmail.spec.tsre-pointedcredentials.emailonly at the end of each test. If a test failed after the promotion, the tracker held an address that was by then a secondary, and cleanup's sign-in failed.This pull request
recoveryKey.spec.tswithtestAccountTracker.generateAccountDetails(). It uses the defaultsigninemail prefix and registers the account.destroyAllAccounts()checksaccountStatusByEmailfirst and skips accounts that no longer exist.credentials.emailre-point inchangeEmail.spec.tsto directly after the promotion it tracks. This covers the four tests that swap the primary email. The third test promotes twice, so it re-points twice.Issue that this pull request solves
Closes: https://mozilla-hub.atlassian.net/browse/FXA-14285
Checklist
Put an
xin the boxes that applyHow to review (Optional)
recoveryKey.spec.ts, and eachcredentials.emailassignment inchangeEmail.spec.ts.recoveryKey.spec.tsfirst, thenchangeEmail.spec.tstest by test.generateAccountDetails()returns the tracked object by reference. The existingaccountDetails.password = newPasswordline therefore keeps the tracker in sync after the reset.Screenshots (Optional)
None. There is no user interface change.
Other information (Optional)
I did not run the specs locally. They are Playwright functional tests. They need a running stack and real stage accounts, so CI covers them. I ran these checks instead:
tsc --noEmitonpackages/functional-tests. It reports three pre-existing errors inlib/. The output is identical to the baseline with the changes stashed, so this branch adds no new errors.nx lint functional-tests: exit 0, 0 errors.prettier --checkon both files: clean.One trade-off. A failed promotion now leaves the tracker on an address that is only a secondary. This is the same class of failure as before, but it fails loudly, unlike the silent leak this PR fixes.
No assertion changed. No test was added, removed, or skipped.
lib/testAccountTracker.tsis untouched.