Skip to content

Adding codebase support to firebase functions:delete - #10929

Open
shettyvarun268 wants to merge 6 commits into
mainfrom
shettyvarun268/functions-codebase-delete
Open

Adding codebase support to firebase functions:delete#10929
shettyvarun268 wants to merge 6 commits into
mainfrom
shettyvarun268/functions-codebase-delete

Conversation

@shettyvarun268

Copy link
Copy Markdown
Contributor

Summary

Extends firebase functions:delete to support deleting by codebase (<codebase>) and codebase-qualified function (<codebase>:<function>), achieving parity with firebase deploy --only functions:....

Motivation

Previously, functions:delete bypassed the central parseFunctionSelector and relied solely on raw function ID prefix matching (f.split(/[-.]/)). This caused:

  1. Inability to delete codebases whose function exports don't share the codebase name (e.g. kit firestore-to-bigquery exporting syncDocs).
  2. Inability to target a specific codebase (functions:delete <codebase>:<function>).
  3. Accidental deletions across overlapping instance names (e.g. kit-bq deleting kit-bq-staging).

Key Changes

  1. Reused Central Selector Parser (functions-delete.ts): Normalized firebase.json via projectConfig.normalizeAndValidate() (supporting standard codebases and Function Kit instances) and routed filters through helper.parseFunctionSelector().
  2. Enhanced Matching & Boundary Safety (functionsDeployHelper.ts): Added whole-codebase matching when !filter.idChunks and enforced strict hyphen boundary checks to prevent substring collisions across instances.
  3. Collision Handling (functions-delete.ts): When a target matches both a codebase and a function in default, codebase deletion takes precedence and the CLI prints a helpful notice for the default:<name> workaround.

Verification

  • Unit Tests: Added test cases for whole-codebase matching, instance isolation, and boundary safety (32 passing).
  • Edge Cases: Verified 9 edge-case scenarios in simulation.
  • Live GCP: Verified against live Google Cloud infrastructure on project varun-test-project-auth for both whole-codebase and codebase-qualified function deletions.

@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 updates the functions:delete command to support deleting functions by codebase, exact name, or hierarchical group, aligning the selector syntax with firebase deploy. It also adds a warning for name collisions between codebase names and default codebase function names. Feedback on the changes highlights a potential regression where running the command outside of a Firebase project directory (or without functions configured) will throw an error due to missing configuration normalization. Additionally, the filtering logic in endpointMatchesFilter needs adjustment to prevent legacy functions with undefined codebases from being incorrectly matched when targeting a specific codebase, along with a corresponding unit test to cover this edge case.

Comment thread src/commands/functions-delete.ts Outdated
Comment thread src/deploy/functions/functionsDeployHelper.ts
Comment thread src/deploy/functions/functionsDeployHelper.spec.ts
@shettyvarun268
shettyvarun268 force-pushed the shettyvarun268/functions-codebase-delete branch 2 times, most recently from 3e1e726 to 9fb02b3 Compare August 12, 2026 21:43
@shettyvarun268

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 enhances the functions:delete command to support deleting functions by codebase, exact name, or hierarchical group, and adds name collision detection between codebases and default functions. It also updates endpointMatchesFilter to enforce strict hyphen boundaries and adds corresponding unit tests. The reviewer pointed out a style guide violation where as unknown as projectConfig.ValidatedConfig is used as an escape hatch, suggesting a structurally valid dummy configuration instead.

Comment thread src/commands/functions-delete.ts Outdated
@shettyvarun268
shettyvarun268 force-pushed the shettyvarun268/functions-codebase-delete branch from 9fb02b3 to 859cff1 Compare August 12, 2026 22:01
@shettyvarun268
shettyvarun268 marked this pull request as ready for review August 12, 2026 22:06
@shettyvarun268
shettyvarun268 requested a review from inlined August 12, 2026 22:11

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

Can look more carefully later but one quick test suggestion. Nothing else jumped out at me from a quick review :)

Comment thread src/deploy/functions/functionsDeployHelper.spec.ts

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

If I build and try to run this every single attempt to do firebase functions:delete <X> results in the error:

Error: functions.codebase must be unique but 'default' was used more than once.

I've interrigated Jeski about this and I think it's because you're on an older version of tools that doesn't yet support kits and I have a bunch of kits in my test project. But since delete update is for kits we should definitely test it with kits so... maybe a first step is rebase onto main and then we go from there?

// This allows us to filter using idChunks across all codebases.
// Only enforce codebase-based filtering when both the endpoint and filter provide them.
// This allows us to filter using idChunks across all codebases or target a specific codebase.
if (endpoint.codebase && filter.codebase) {

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.

My gemini instance thinks there is a bug here and that you need to do a

const endpointCodebase = endpoint.codebase || DEFAULT_CODEBASE

and compare against that. I was trying to dig into it and understand more myself and see if this is a hallucination, but I'm unable to run functions:delete on anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebased the PR onto main. The kits should validate now with the experiments turned on

As for Gemini's suggestion, I think it's a hallucination here. We intentionally don't enforce DEFAULT_CODEBASE on function names so we can still match older GCP functions without codebase labels (there's an existing test for this: "should match function if backend's codebase is undefined"). We only enforce it for whole-codebase deletes.

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.

Yeah... I was a bit skeptical myself since it was encouraging changing this and a unit test together that you didn't touch. But... I think it might be a real thing.

The claim is that if you have a function without a codebase like helloWorld that it would be deleted if you specify any codebase like default:helloWorld (which I'd expect to work) but also my-new-codebase:helloWorld. That may have been the old behavior but it doesn't really make sense right? We'll put any function with no codebase into the default codebase right?

So I think that if it has no codebase then helloWorld or default:helloWorld should match but my-function-kit:helloWorld probably shouldn't match this legacy function?

Can you look into it a bit more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out.

  1. Changed the behavior regarding legacy functions which did not have codebases attached to them. Now if the entrypoint.codebase == undefined, it will behave as if it has the default code base attached to it.

  2. After our discussion, decided to keep the old behavior in the delete functionality where running bare functions:delete foo (without a codebase prefix) continues to match across all codebases as it previously did. This would avoid us doing a breaking change and can be changed in the (future when we decide to actually push through a breaking change and package this in.

@shettyvarun268
shettyvarun268 force-pushed the shettyvarun268/functions-codebase-delete branch from e1b9dd7 to defe96e Compare August 13, 2026 01:33

@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 think we do have a behavior change here. I have in my test setup a function node-functions:v2-helloWorldNode. Before this change

firebase functions:delete v2-helloWorldNode would prompt me to delete node-functions:v2-helloWorldNode. Now it finds nothing. However before the opposite was true node-functions:v2-helloWorldNode didn't work and now it does.

I think the new functionality is strictly more powerful, and more inline with how only/except work. So it's probably a good change. But it is a larger behavior change. So I think we should rediscuss with folks on if we have to be more careful with how we roll this out.

// This allows us to filter using idChunks across all codebases.
// Only enforce codebase-based filtering when both the endpoint and filter provide them.
// This allows us to filter using idChunks across all codebases or target a specific codebase.
if (endpoint.codebase && filter.codebase) {

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.

Yeah... I was a bit skeptical myself since it was encouraging changing this and a unit test together that you didn't touch. But... I think it might be a real thing.

The claim is that if you have a function without a codebase like helloWorld that it would be deleted if you specify any codebase like default:helloWorld (which I'd expect to work) but also my-new-codebase:helloWorld. That may have been the old behavior but it doesn't really make sense right? We'll put any function with no codebase into the default codebase right?

So I think that if it has no codebase then helloWorld or default:helloWorld should match but my-function-kit:helloWorld probably shouldn't match this legacy function?

Can you look into it a bit more?

Comment thread src/commands/functions-delete.ts Outdated
Comment thread src/commands/functions-delete.ts Outdated
Comment thread src/commands/functions-delete.ts Outdated
Comment thread src/commands/functions-delete.ts Outdated
Comment thread src/commands/functions-delete.ts Outdated
Comment thread src/commands/functions-delete.ts Outdated
@shettyvarun268
shettyvarun268 requested a review from inlined August 17, 2026 16:35
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.

5 participants