Repository navigation
fix(kits): batch endpoint deletion prompts when uninstalling a kit - #11189
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the function kits uninstallation process to batch the deletion of deployed Cloud Functions across all instances in a kit, grouping them by project ID. It also introduces a helper function getInstanceEnvNames to retrieve environment names. The review feedback highlights two potential crash scenarios where the code attempts to read or check directories that might not exist, suggesting robust existence checks using config.projectDirExists before performing operations on those paths.
ajperel
left a comment
There was a problem hiding this comment.
I don't think we should do it in this PR because it's a larger testing change, but I think the tests could become dramatically better if we used mock-fs and don't stub all the file system interactions.
Overall this seemed like a good UX for users, and a nice catch on deletion across projects. I think we could also get that to a single yes/no but it's a much bigger change and probably much rarer so... I don't think now is the time to tackle it.
I think at the highest level my feedback (beyond nits) boils down to: we should duplicate as little code as possible and you added some good stuff but should re-unify the uninstallInstance and uninstallKit path because they diverged a fair bit. And we should continually refactor the tests and add test helpers as well as necessary to make it easy to have short tests that test just what we want in a very easy to read and write way.
|
Thanks for the review @ajperel Good call on unifying uninstallInstance and uninstallKit and cleaning up createMockConfig, it made the tests much cleaner too. Addressed all the comments in the latest commit. |
ajperel
left a comment
There was a problem hiding this comment.
You must add a CHANGELOG entry now that we've launched kits!
When running functions:kits:uninstall --kit <kitId> on a kit with multiple instances, uninstallKit previously iterated through each instance sequentially, triggering separate deleteFunctionsByEndpointFilters calls and interactive confirmation prompts for each instance. Group instances by project ID and batch all instance codebase filters into a single deleteFunctionsByEndpointFilters invocation per project, displaying a single confirmation prompt across all functions and managed service accounts. Also extract getInstanceEnvNames to deduplicate environment file discovery.
…tests - Extract ENV_FILE_PREFIX constant and replace hardcoded literals across functions - Add JSDoc comments to getInstanceEnvNames, cleanInstanceFiles, and deleteInstancesFunctions - Re-unify teardown between uninstallKit and uninstallInstance via shared helpers - Remove redundant Set wrapper when collecting instanceIds - Restore conservative deletion mode unit test - Standardize createMockConfig on Record<string, string> with declarative filesByDir mock filesystem - Update GCP failure test to use expect().to.be.rejectedWith()
55ee54e to
9e1c69d
Compare
Description
Fixes an issue where running
firebase functions:kits:uninstall --kit <kitId>on a kit with multiple instances prompted the user once per instance for Cloud Functions and Managed Service Account deletions, as well as rewritingfirebase.jsononce per instance.Changes
projectId(supporting.firebasercaliases) and passes all codebase filters (filters: [{ codebase: id }, ...]) into a singledeleteFunctionsByEndpointFiltersinvocation per project, displaying a single combined confirmation prompt.0matching endpoints).deleteInstancesFunctions,cleanInstanceFiles, andgetInstanceEnvNamesto unify remote/local teardown and.env.<projectId>discovery acrosshandleInstance,uninstallInstance, anduninstallKit.firebase.jsonis updated and saved once at the completion of kit uninstallation..firebasercalias resolution, conservative deletion mode cleanup, and deletion failure abort safety.Test Plan
npx mocha src/commands/functions-kits-uninstall.spec.ts(10 passing).npm run test:compile.npm run lint.--kitand--instanceuninstall flows with multiple active instances.