Skip to content

refactor(functions): add KitSourceAdapter for npm and directory kits - #11370

Merged
wandamora merged 4 commits into
mainfrom
morawand/kits-source-adapters
Nov 5, 2026
Merged

wandamora merged 4 commits into
mainfrom
morawand/kits-source-adapters

Conversation

@wandamora

@wandamora wandamora commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Introduces the KitSourceAdapter interface and source adapter implementations on top of #11368:

  • src/functions/kits/sources/types.ts: KitSourceAdapter and PreparedKitSource interfaces (decoupling rollback path tracking from prepareSource)
  • src/functions/kits/sources/directory.ts & directory.spec.ts: createDirectoryAdapter(config, directory) and unit tests
  • src/functions/kits/sources/npm.ts & npm.spec.ts: createNpmPackageAdapter, ScaffoldKitFilesOptions, and ScaffoldedKitSourcePaths (updating scaffoldKitFiles to scaffold only the kit source directory without requiring an instanceId), plus unit tests
  • src/functions/kits/sources/index.ts: removed barrel file in favor of direct exports from install.ts
  • src/functions/kits/install.ts: updates scaffoldKit and resolvePackageSource to pass ScaffoldKitFilesOptions and create config-${instanceId} directly

Part 2 of 3 (#11368 -> #11370 -> #11366).

Scenarios Tested

  • Unit tests across src/functions/kits/sources/directory.spec.ts, src/functions/kits/sources/npm.spec.ts, and src/functions/kits/install.spec.ts.

Sample Commands

N/A (internal refactor, no CLI behavior changes)

@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 a KitSourceAdapter interface and corresponding adapter implementations for local directory kits (createDirectoryAdapter) and NPM package kits (createNpmPackageAdapter), along with a resolver function resolveSourceAdapter to select the appropriate adapter. The feedback highlights two main issues in the NPM package adapter: first, a security risk where mutable state (isThirdParty) could bypass script-execution safety checks if lifecycle methods are called out of order; and second, potential workspace pollution due to hardcoded instance IDs during scaffolding.

Comment thread src/functions/kits/sources/npm.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
@wandamora
wandamora added this pull request to stack #11371 October 27, 2026 20:34
@wandamora
wandamora force-pushed the morawand/kits-source-adapters branch 2 times, most recently from af4b39a to 8ae4851 Compare October 27, 2026 21:37
@wandamora
wandamora force-pushed the morawand/kits-source-adapters branch 2 times, most recently from aa65ccc to e632247 Compare October 29, 2026 20:11
Base automatically changed from morawand/kits-extract-sources to main October 29, 2026 20:37
@wandamora
wandamora force-pushed the morawand/kits-source-adapters branch 2 times, most recently from 00659ec to bcc3ef1 Compare October 29, 2026 21:26

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

I like the direction this is going, but as discussed in person I think we should think about the right balance of unit testing to not have onerous setup but not overfit the tests to the exact implementation rather than the contract we need publicly for the install command.

Comment thread src/functions/kits/sources/types.ts Resolved
Comment thread src/functions/kits/sources/index.ts Resolved
Comment thread src/functions/kits/sources/types.ts Resolved
@wandamora
wandamora force-pushed the morawand/kits-source-adapters branch from bcc3ef1 to 3db6eed Compare November 5, 2026 18:47
@wandamora
wandamora force-pushed the morawand/kits-source-adapters branch from 21279cf to 8809e87 Compare November 5, 2026 20:52
@wandamora
wandamora enabled stacked auto-merge (squash) November 5, 2026 21:18
@wandamora
wandamora merged commit a5f7f61 into main Nov 5, 2026
51 checks passed
@wandamora
wandamora deleted the morawand/kits-source-adapters branch November 5, 2026 21:23
joehan pushed a commit that referenced this pull request Nov 5, 2026
…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
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.

2 participants