Adding codebase support to firebase functions:delete - #10929
Adding codebase support to firebase functions:delete#10929shettyvarun268 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
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.
3e1e726 to
9fb02b3
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
9fb02b3 to
859cff1
Compare
ajperel
left a comment
There was a problem hiding this comment.
Can look more carefully later but one quick test suggestion. Nothing else jumped out at me from a quick review :)
ajperel
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Thanks for pointing this out.
-
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.
-
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.
e1b9dd7 to
defe96e
Compare
ajperel
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
…ion across codebases
Summary
Extends
firebase functions:deleteto support deleting by codebase (<codebase>) and codebase-qualified function (<codebase>:<function>), achieving parity withfirebase deploy --only functions:....Motivation
Previously,
functions:deletebypassed the centralparseFunctionSelectorand relied solely on raw function ID prefix matching (f.split(/[-.]/)). This caused:firestore-to-bigqueryexportingsyncDocs).functions:delete <codebase>:<function>).kit-bqdeletingkit-bq-staging).Key Changes
functions-delete.ts): Normalizedfirebase.jsonviaprojectConfig.normalizeAndValidate()(supporting standard codebases and Function Kit instances) and routed filters throughhelper.parseFunctionSelector().functionsDeployHelper.ts): Added whole-codebase matching when!filter.idChunksand enforced strict hyphen boundary checks to prevent substring collisions across instances.functions-delete.ts): When a target matches both a codebase and a function indefault, codebase deletion takes precedence and the CLI prints a helpful notice for thedefault:<name>workaround.Verification
32 passing).varun-test-project-authfor both whole-codebase and codebase-qualified function deletions.