Skip to content

test(auth): replace any types in passkey specs - #21438

Merged
nshirley merged 1 commit into
mainfrom
fxa-13338
Oct 12, 2026
Merged

nshirley merged 1 commit into
mainfrom
fxa-13338

Conversation

@fxa-agent

@fxa-agent fxa-agent Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Because

  • Five passkey spec files used any for mocks, routes, and requests, so tsc could not check them.

This pull request

  • Changes five test files only. No test is added, removed, or renamed. No assertion changes.
  • passkeys.spec.ts: the mocks are now DeepMocked<T> built with createMock<T>. Every existing return value stays.
  • passkey-wraps.spec.ts: a Route alias types the found routes. as Schema types the validate schemas.
  • passkeys.in.spec.ts and passkey_wraps.in.spec.ts: createMock<StatsD>() and createMock<LoggerService>() replace the hand-built mocks. Event callbacks use (e: { name: string }).
  • passkey.challenge.manager.spec.ts: uses as unknown as Redis and as unknown as StatsD. This adds no dependency to libs/accounts.
  • runTest in passkeys.spec.ts now throws when a route is not found. It has a generic return type.
  • The PasskeyHandler constructor call now passes the missing 10th config argument. This was a tsc error on main.
  • Three mocks use as jest.Mock. Their test values break the declared type on purpose: an unknown transport and two partial accounts.

Issue that this pull request solves

Closes: FXA-13338

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

How to review (Optional)

  • Key files/areas to focus on: passkeys.spec.ts, where the mocks move to createMock.
  • Suggested review order: passkeys.spec.ts, passkey-wraps.spec.ts, the two remote specs, then passkey.challenge.manager.spec.ts.
  • Risky or complex parts: createMock auto-mocks any method that a test does not stub. A new unstubbed call no longer throws a TypeError. Every existing test passes unchanged. No test failed after the move to createMock.

Screenshots (Optional)

None. There is no user-visible change, so there is no functional test or screenshot.

Other information (Optional)

  • any remains only on the JS test client holders in the two remote specs. This includes the getMfaAccessTokenForPasskey(clientInstance: any) parameter, which holds the same client.
  • The ticket suggested inline narrowing where .pre is read in passkey-wraps.spec.ts. The file compiles without it, so I added none.
  • Open PRs feat(auth): emit passkey wrap_invalidated on stale replace and reset #21423 and fix(auth): decouple login.complete from flow events, fix Sync and reset #21418 touch these files. This branch is based on main. A later rebase handles any conflict.
  • Checks from /fxa-verify --run --plan:
    • Unit passkeys.spec.ts and passkey-wraps.spec.ts: 212 passed.
    • Library passkey.challenge.manager.spec.ts: 14 passed.
    • Integration test/remote/passkeys.in.spec.ts and passkey_wraps.in.spec.ts: 25 passed. MySQL and Redis run in the sandbox.
    • ESLint and Prettier: PASS.
    • tsc --noEmit -p packages/fxa-auth-server/tsconfig.json and -p libs/accounts/passkey/tsconfig.spec.json: no errors in the five files.

@fxa-agent fxa-agent Bot added the auto label Oct 9, 2026
@fxa-agent
fxa-agent Bot requested a review from a team as a code owner October 9, 2026 17:52
@fxa-agent fxa-agent Bot added the auto label Oct 9, 2026
glean: DeepMocked<GleanMetricsType>,
routes: ReturnType<typeof passkeyRoutes>,
route: ReturnType<typeof passkeyRoutes>[number] | undefined,
request: AuthRequest &

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this intersection doesn't buy anything: these are already typed any on AuthRequest, and any & jest.Mock collapses back to any. request: AuthRequest should compile identically and reads easier. (The real fix is typing those four fields in types.ts, but that's a different PR.)


await expect(
route.options.response.schema.validateAsync(result)
(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These inline option casts repeat the same shape seven times. Would one typed accessor near runTest do?

type TestRouteOptions = {
  auth: { strategies: string[] };
  validate: { payload: Schema; params: Schema };
  response: { schema: Schema };
};
const optionsOf = (r: typeof route) => {
  if (!r) throw new Error('route not found');
    return r.options as TestRouteOptions;
  };
// optionsOf(route).validate.payload

That also removes the route?. optional chains since the helper narrows. I looked at whether annotating passkeyRoutes as ServerRoute[] would make the cast unnecessary and it wouldn't. Hapi types options as RouteOptions | (server) => RouteOptions and auth as false | string | RouteOptionsAccess, so you'd still narrow.

},
};
return route.handler(request);
return route.handler(request as unknown as AuthRequest);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The as unknown as AuthRequest accepts any object, so a typo like credentails passes type-check and surfaces as a confusing runtime failure. Could typing the literal against golevelup's deep partial first do the job here and elsewhere?

import type { PartialFuncReturn } from '@golevelup/ts-jest';
const asRequest = (r: PartialFuncReturn<AuthRequest>) => r as AuthRequest;

Because:

- The passkey specs used `any` for mocks, requests and route options, so tsc did not check them.

This commit:

- Builds the passkeys.spec.ts mocks as DeepMocked<T> with createMock<T>.
- Types found routes with an optionsOf helper and requests with asRequest.
- Passes the missing PasskeyHandler config argument.
- Uses createMock<StatsD>() and createMock<LoggerService>() in the remote specs.
- Uses `as unknown as` casts in passkey.challenge.manager.spec.ts.

Closes FXA-13338
@fxa-agent

fxa-agent Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

🤖 This review round pushed a new commit:

@nshirley
nshirley merged commit f42f663 into main Oct 12, 2026
20 checks passed
@nshirley
nshirley deleted the fxa-13338 branch October 12, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant