Skip to content

feat: add firebase.json schema support and validation for function kits - #10842

Open
wandamora wants to merge 19 commits into
mainfrom
morawand-function-kits
Open

feat: add firebase.json schema support and validation for function kits#10842
wandamora wants to merge 19 commits into
mainfrom
morawand-function-kits

Conversation

@wandamora

@wandamora wandamora commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

Adds comprehensive support for Function Kits in firebase.json (kit stanza as a peer to codebase), including configuration parsing, validation, JSON schema updates, deployment handling, and emulator / local serving integration behind the kits experiment flag.

Specifically, this PR:

  • Config & Validation (src/firebaseConfig.ts, src/functions/projectConfig.ts):
    • Adds KitSourcePackage and KitFunctionConfig types, updating the FunctionConfig union.
    • Adds ValidatedKitSingle type and validation logic in src/functions/projectConfig.ts enforcing:
      • Mutual exclusivity between kit and codebase / remoteSource / prefix.
      • Required instances map mapping instance IDs to configuration subdirectories (configDir).
      • Project-wide kit name and kit instance ID uniqueness across kit stanzas.
      • Mutual exclusivity between standard codebase names and kit instance IDs.
      • Format and character validation for kit names and instance IDs.
    • Updates isLocalConfig and requireLocal, and adds isKitConfig type guards.
    • Adds configForCodebase helper for resolving configurations by standard codebase name or kit instance ID.
  • Schema & Experiments (schema/firebase-config.json, src/experiments.ts):
    • Updates generated JSON schema (schema/firebase-config.json) to include kit stanzas with instance mapping.
    • Registers the kits experiment flag (ALL_EXPERIMENTS.kits).
  • Deployment Support & Kit Instance Prefixing (src/deploy/functions/):
    • Treats kit instances as codebases during deployment (functionsDeployHelper.ts and prepare.ts).
    • Sets the prefix for every kit instance backend to kit-<instance-id>, automatically applying kit-<instance-id>- to all function endpoint IDs during discovery in prepare.ts to isolate instances and prevent function name collisions.
    • Updates function selector parsing (parseFunctionSelector) and target codebase resolution (targetCodebases) to recognize kit instance IDs alongside codebase names.
  • Emulator & Local Serving (src/emulator/controller.ts, src/serve/functions.ts):
    • Adds support for kit backends in the Functions emulator and serve commands by instantiating an EmulatableBackend for each kit instance with its assigned configDir and kit-<instance-id> prefix.

Scenarios Tested

  • firebase deploy --only functions with a mix of standard codebase stanzas and kit stanzas
  • firebase deploy --only functions:<instance-id>
  • firebase deploy --only functions:<instance-id>:<function-name>

@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 support for "functions kits" by adding the KitFunctionConfig schema, TypeScript types, validation logic, and corresponding unit tests. The review feedback identifies several critical issues and improvement opportunities: a missing runtime property in ValidatedKitSingle that causes TypeScript compilation errors, a regression in isLocalConfig that breaks kit deployment via requireLocal, a JSON schema generation issue when using Record<string, string> for instances, a validation bypass when kit is an empty string, and a lack of naming constraint validation for kit instance IDs.

Comment thread src/functions/projectConfig.ts
Comment thread src/functions/projectConfig.ts
Comment thread src/firebaseConfig.ts Outdated
Comment thread src/functions/projectConfig.ts Outdated
Comment thread src/functions/projectConfig.ts
@wandamora
wandamora force-pushed the morawand-function-kits branch from a6f6df7 to ad01fb4 Compare July 24, 2026 00:05
@wandamora

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 support for 'Functions Kits' under a new experiment flag, updating the configuration schema, validation logic, and deployment helpers to handle kit configurations and instances. The reviewer feedback highlights a critical issue where excluding kits from isLocalConfig breaks deployment via requireLocal, and suggests stricter validation for kit properties and instance IDs. Additionally, the reviewer recommends replacing unsafe type assertions (as any and as unknown as) in the test files with safer alternatives to comply with the repository's style guide.

Comment thread src/functions/projectConfig.ts
Comment thread src/functions/projectConfig.ts
Comment thread src/functions/projectConfig.ts Outdated
Comment thread src/deploy/functions/functionsDeployHelper.spec.ts Outdated
Comment thread src/deploy/functions/functionsDeployHelper.spec.ts Outdated
@wandamora
wandamora force-pushed the morawand-function-kits branch from 85bfd78 to 30285e0 Compare July 27, 2026 18:55
@wiz-9635d3485b

wiz-9635d3485b Bot commented Jul 28, 2026

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 6 Medium
Software Management Finding Software Management Findings -
Total 6 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio.

@wandamora
wandamora force-pushed the morawand-function-kits branch from 5dd4284 to f160329 Compare July 28, 2026 20:32
@wandamora
wandamora marked this pull request as ready for review July 28, 2026 20:49
@wandamora
wandamora force-pushed the morawand-function-kits branch from c6824f9 to 3dc10f4 Compare July 28, 2026 23:42
@wandamora
wandamora requested review from ajperel and inlined July 29, 2026 17:10
Comment thread src/deploy/functions/prepare.ts Outdated
wandamora added 14 commits July 29, 2026 21:45
Adds support for Function Kits schema in `firebase.json` (`kit` stanza as a peer to `codebase`). This includes:
- Added `KitSourcePackage` and `KitFunctionConfig` types to `src/firebaseConfig.ts`.
- Updated `FunctionConfig` union to include `KitFunctionConfig`.
- Added `ValidatedKitSingle` and validation logic in `src/functions/projectConfig.ts` to enforce:
  - Mutual exclusivity between `kit` and `codebase`/`remoteSource`/`prefix`.
  - Project-wide kit name and kit instance ID uniqueness across kit stanzas.
  - Mutual exclusivity between codebase names and kit instance IDs.
- Updated `isLocalConfig` and added `isKitConfig` type guards.
- Regenerated JSON schema (`schema/firebase-config.json`).

- Validated parsing of valid Function Kit configurations.
- Verified validation failures when `kit` is combined with `codebase`, `remoteSource`, or `prefix`.
- Verified validation failure when `kit` is missing required `source`.
- Verified duplicate `kit` name rejection across stanzas.
- Verified duplicate kit instance ID rejection across stanzas.
- Verified mutual exclusivity error when a codebase name matches a kit instance ID.
- Verified type guard narrowing for `isLocalConfig`, `isRemoteConfig`, and `isKitConfig`.

- `npm run generate:json-schema`
- `npm run lint:changed-files`
- `npx mocha src/functions/projectConfig.spec.ts`
This change sets instances as codebases in the backend, and adds a
new "kit" identifier to further differentiate standard function
codebases with function kits.
If a user specifies a target to deploy that a kit and instance share
a name for, confirm with the user if they'd like to deploy the full
kit or indiviual instance. The prompt will only appear for kits with
more than one instance.
We decided that introducing "kits" filtering overcomplicates the parser.
@wandamora
wandamora force-pushed the morawand-function-kits branch from 55f5117 to ae5380b Compare July 29, 2026 21:45

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

Very nice! A few comments but all pretty minor.

Comment thread schema/firebase-config.json Outdated
Comment thread src/deploy/functions/functionsDeployHelper.ts Outdated
Comment thread src/deploy/functions/functionsDeployHelper.ts Outdated
Comment thread src/emulator/controller.ts Outdated
Comment thread src/functions/projectConfig.ts
Comment thread src/functions/projectConfig.ts Outdated

@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 don't think this is new to your PR, but Gemini also suggests we validate that configDir resolves to something in the project.

There's probably not a good reason to allow something like: "inst1": "../../../../some/other/repo/config"

@wandamora
wandamora force-pushed the morawand-function-kits branch from d06f134 to 5e642a7 Compare July 30, 2026 00:13
@wandamora
wandamora force-pushed the morawand-function-kits branch from 5e642a7 to 8203892 Compare July 30, 2026 00:19
@wandamora
wandamora force-pushed the morawand-function-kits branch from 466ae98 to cd1ee2a Compare July 30, 2026 17:24

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

Looks good and if there are subtle issues .... it's behind an experiment and we'll keep iterating.

Comment thread src/functions/projectConfig.ts
Comment thread src/experiments.ts Outdated
this should not have been public in the first place
@wandamora
wandamora force-pushed the morawand-function-kits branch from 918926f to b31a9e6 Compare July 30, 2026 17:44
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