Skip to content

[AI Improvement] [Task] Compile Auth Emulator OpenAPI validators lazily (lazyCompileValidationSchemas) to cut ~10 s per createApp() - #11176

Merged
joehan merged 9 commits into
mainfrom
ai-improve-566319964-task-compile-auth-emulator-openapi-
Nov 5, 2026
Merged

joehan merged 9 commits into
mainfrom
ai-improve-566319964-task-compile-auth-emulator-openapi-

Conversation

@joehan

@joehan joehan commented Sep 25, 2026

Copy link
Copy Markdown
Member

Resolves Buganizer b/566319964 (parent goal b/566303602)

Proposed Improvement

Pass lazyCompileValidationSchemas: true in exegesisExpress.middleware(specForRouter(), { ... }) inside createApp() in src/emulator/auth/server.ts.

By default, Exegesis eagerly compiles ajv validation schemas for every operation in the 386 KB Identity Toolkit spec at startup, which takes ~10-24 seconds per createApp() invocation. The unit test suite creates one app per mode (NO_WARNING and ERROR), and firebase emulators:start --only auth pays for this compilation once on startup. Enabling lazyCompileValidationSchemas: true defers ajv compilation of an operation's schema until that route is first requested.

Verification

  1. createApp Startup Benchmark:
    • Baseline: ~19,343 ms – 24,455 ms
    • With lazy compilation: ~1,446 ms – 1,556 ms (~12-16x speedup)
  2. Auth Unit Tests (npx mocha 'src/emulator/auth/**/*.spec.ts'):
    • Baseline: 371 passing, 1 pending, 2 failing (due to the 20s hook timeout in singleProjectMode=ERROR during eager schema compilation), taking >3 minutes.
    • With lazy compilation: 372 passing, 1 pending, 0 failing, taking 19 seconds.
  3. Repository Lint: npm run lint:quiet and prettier check passed cleanly.

@joehan joehan self-assigned this Sep 25, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request configures the exegesisExpress middleware in the Auth emulator server to compile validation schemas lazily by setting lazyCompileValidationSchemas to true. This optimization avoids the eager compilation of the 386 KB Identity Toolkit specification, reducing startup time and speeding up unit tests. There are no review comments, and I have no feedback to provide.

@joehan
joehan marked this pull request as ready for review November 5, 2026 00:43
@joehan
joehan requested a review from shettyvarun268 November 5, 2026 00:43

@shettyvarun268 shettyvarun268 left a comment

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.

LGTM

Two small things, both non-blocking:

  • Since this makes the Auth emulator start faster on firebase emulators:start and that seems like a user facing change, should we add a CHANGELOG line? Something like: - Improved Auth emulator startup time by compiling validation schemas lazily.
  • With lazy compile, a bad schema in a future regenerated apiSpec.ts would only show up as a 500 on the first request to that endpoint instead of failing at startup. Might be worth a follow-up test that compiles all validators once so CI still catches that.

@joehan

joehan commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

LGTM

Two small things, both non-blocking:

  • Since this makes the Auth emulator start faster on firebase emulators:start and that seems like a user facing change, should we add a CHANGELOG line? Something like: - Improved Auth emulator startup time by compiling validation schemas lazily.
  • With lazy compile, a bad schema in a future regenerated apiSpec.ts would only show up as a 500 on the first request to that endpoint instead of failing at startup. Might be worth a follow-up test that compiles all validators once so CI still catches that.

Both good points - will address in the PR before merging.

wandamora and others added 5 commits November 5, 2026 22:27
…11370)

* refactor(functions): add KitSourceAdapter for npm and directory kits

* refactor(functions): decouple createdPaths and inline adapter selection

* test(functions): clean up overfitted adapter tests and simplify directory adapter signature
…11418)

### Description

Part 1 of 3 (stacked) for seamless App Check debug tokens (go/firebase-api-sdk-cli-seamless-debug-tokens).

`appcheck:debugtokens:create` now saves the token to `~/.config/configstore/firebase-appcheck.json` so local client SDKs and build plugins can discover it without copy-pasting from the Console.

- **`src/appcheck/localConfig.ts`**: reads/writes `firebase-appcheck.json` (tokens keyed by GMP App ID, plus the optional server resource name under `tokenNames`), mirroring to an absolute `$XDG_CONFIG_HOME` when it differs from `~/.config`. Reads JSON directly so a malformed file raises an actionable error instead of being wiped by `Configstore`.
- **`appcheck:debugtokens:create`**:
  - Saves locally by default; `--no-save-local` opts out (for CI/remote tokens).
  - Defaults `--display-name` to `<username>@<hostname>` (bounded to the backend's 50-char limit), or `CLI Debug Token (<shortHost>)` with `--no-save-local` so CI tokens don't replace the host's own token.
  - Validates UUID v4 / display name before any API call, respects the 20-token limit, creates the replacement before deleting the old token, includes `token` in `--json` output, and prints `.env.local` snippets for Web apps.

### Scenarios Tested

- `npx mocha 'src/appcheck/**/*.spec.ts' 'src/commands/appcheck*.spec.ts'`
- `npm run build`, `npm run test:compile`, lint, prettier.

### Sample Commands

```bash
firebase appcheck:debugtokens:create --app 1:1234567890:ios:abcdef
firebase appcheck:debugtokens:create --app 1:1234567890:web:abcdef --display-name "github-actions" --no-save-local --force --json
```
### Description

Part 2 of 3 (stacked on #11418) for seamless App Check debug tokens (go/firebase-api-sdk-cli-seamless-debug-tokens).

`appcheck:debugtokens:list --local` lists debug tokens saved in `~/.config/configstore/firebase-appcheck.json` as a table of App ID, token prefix, and server status (optionally filtered by `--app`). It works offline (`Unchecked`) and, when authenticated with an active project, reports `Active`, `Revoked`, or `App Deleted`. Without `--local`, `list` is unchanged.

### Scenarios Tested

- `npx mocha 'src/appcheck/**/*.spec.ts' 'src/commands/appcheck*.spec.ts'`
- `npm run build`, `npm run test:compile`, lint, prettier.

### Sample Commands

```bash
firebase appcheck:debugtokens:list --local
firebase appcheck:debugtokens:list --local --app 1:1234567890:ios:abcdef
```
…elete (#11421)

### Description

Part 3 of 3 (stacked on the `list --local` PR) for seamless App Check debug tokens (go/firebase-api-sdk-cli-seamless-debug-tokens).

- **`appcheck:debugtokens:prune`**: removes local entries in `~/.config/configstore/firebase-appcheck.json` for the active project whose app was deleted or whose token was revoked on the server. Prompts for confirmation unless `--force`, and states that server-registered tokens are untouched.
- **`appcheck:debugtokens:delete`**: also removes the matching local entry when deleting this machine's server token; uses `.withForce()`.

### Scenarios Tested

- `npx mocha 'src/appcheck/**/*.spec.ts' 'src/commands/appcheck*.spec.ts' 'src/commands/index.spec.ts'`
- `npm run build`, `npm run test:compile`, lint, prettier.

### Sample Commands

```bash
firebase appcheck:debugtokens:prune
firebase appcheck:debugtokens:prune --force
```
- Add CHANGELOG entry for lazy OpenAPI validation schema compilation.
- Export specForRouter() and support CreateAppOptions in createApp() to allow schema compilation override.
- Add unit test in rest.spec.ts eagerly compiling all OpenAPI validation schemas to catch spec regressions in CI.
@joehan

joehan commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

Addressed both points in commit 9a860fd44:

  1. CHANGELOG: Added the entry:
    - Improved Auth emulator startup time by compiling validation schemas lazily. (#11176)
  2. Schema Compilation Unit Test: Added a dedicated test in src/emulator/auth/rest.spec.ts that initializes the app with { lazyCompileValidationSchemas: false } using the new CreateAppOptions in src/emulator/auth/server.ts. This eagerly traverses and compiles Ajv validators for the entire OpenAPI spec once during test execution (taking ~6s) to ensure any schema issues in a future regenerated apiSpec.ts are caught in CI.

@joehan
joehan enabled auto-merge (squash) November 5, 2026 22:36
…task-compile-auth-emulator-openapi-

# Conflicts:
#	CHANGELOG.md
@joehan
joehan merged commit 95e8582 into main Nov 5, 2026
51 checks passed
@joehan
joehan deleted the ai-improve-566319964-task-compile-auth-emulator-openapi- branch November 5, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants