Skip to content

feat(appcheck): save debug tokens to local machine config on create - #11418

Merged
AustinBenoit merged 1 commit into
firebase:mainfrom
AustinBenoit:feat/appcheck-seamless-debug-tokens
Nov 5, 2026
Merged

AustinBenoit merged 1 commit into
firebase:mainfrom
AustinBenoit:feat/appcheck-seamless-debug-tokens

Conversation

@AustinBenoit

@AustinBenoit AustinBenoit commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Stack

  1. feat(appcheck): save debug tokens to local machine config on create #11418 (this PR): save debug tokens locally on create
  2. feat(appcheck): add --local to appcheck:debugtokens:list #11420: appcheck:debugtokens:list --local
  3. feat(appcheck): add appcheck:debugtokens:prune and local cleanup on delete #11421: appcheck:debugtokens:prune + local cleanup on delete

@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 introduces local machine configuration persistence for Firebase App Check debug tokens, adding --local support to appcheck:debugtokens:list, and introducing a new appcheck:debugtokens:prune command to clean up stale local tokens. It also updates the create, delete, and list commands to integrate with this local configuration store while ensuring secure logging and input validation. Feedback on the changes suggests wrapping the individual server status checks in a try-catch block within resolveProjectTokenStatuses to prevent a single failure from rejecting the entire Promise.all operation.

Comment thread src/appcheck/debugTokens.ts Resolved
@AustinBenoit
AustinBenoit force-pushed the feat/appcheck-seamless-debug-tokens branch 4 times, most recently from 01b714d to c9cc23e Compare November 3, 2026 22:23
@AustinBenoit AustinBenoit changed the title feat(appcheck): persist debug tokens locally and add list --local and prune feat(appcheck): save debug tokens to local machine config on create Nov 3, 2026
@AustinBenoit
AustinBenoit marked this pull request as ready for review November 3, 2026 22:25
@AustinBenoit
AustinBenoit force-pushed the feat/appcheck-seamless-debug-tokens branch from c9cc23e to 178cbbe Compare November 3, 2026 22:30
@joehan

joehan commented Nov 3, 2026

Copy link
Copy Markdown
Member

/joe-review

@codecov-commenter

codecov-commenter commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.15596% with 28 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@a5f7f61). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/appcheck/localConfig.ts 87.06% 7 Missing and 8 partials ⚠️
src/commands/appcheck-debugtokens-create.ts 78.12% 4 Missing and 3 partials ⚠️
src/appcheck/debugTokens.ts 91.42% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11418   +/-   ##
=======================================
  Coverage        ?   59.45%           
=======================================
  Files           ?      861           
  Lines           ?    50315           
  Branches        ?    10085           
=======================================
  Hits            ?    29913           
  Misses          ?    18107           
  Partials        ?     2295           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with robonits

Comment thread src/appcheck/localConfig.ts Resolved
Comment thread src/appcheck/localConfig.ts Resolved
### 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
```
@AustinBenoit
AustinBenoit force-pushed the feat/appcheck-seamless-debug-tokens branch from 6af97a4 to d4f2225 Compare November 5, 2026 21:23
@AustinBenoit
AustinBenoit enabled auto-merge (squash) November 5, 2026 21:24
@AustinBenoit
AustinBenoit merged commit 1b4baa9 into firebase:main Nov 5, 2026
47 checks passed
@AustinBenoit
AustinBenoit deleted the feat/appcheck-seamless-debug-tokens branch November 5, 2026 21:37
AustinBenoit added a commit that referenced this pull request Nov 5, 2026
### 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
```
joehan pushed a commit that referenced this pull request Nov 5, 2026
…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
```
joehan pushed a commit that referenced this pull request Nov 5, 2026
### 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
```
joehan added a commit that referenced this pull request Nov 5, 2026
…ly (lazyCompileValidationSchemas) to cut ~10 s per createApp() (#11176)

* perf(auth-emulator): lazily compile OpenAPI validation schemas (b/566319964)

* refactor(functions): add KitSourceAdapter for npm and directory kits (#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

* feat(appcheck): save debug tokens to local machine config on create (#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
```

* feat(appcheck): add --local to appcheck:debugtokens:list (#11420)

### 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
```

* feat(appcheck): add appcheck:debugtokens:prune and local cleanup on delete (#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
```

* fix: address PR review feedback on PR #11176

- 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.

---------

Co-authored-by: shettyvarun268 <[email protected]>
Co-authored-by: Wanda Mora <[email protected]>
Co-authored-by: Austin Benoit <[email protected]>
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.

3 participants