Skip to content

fix(kits): batch endpoint deletion prompts when uninstalling a kit - #11189

Merged
shettyvarun268 merged 7 commits into
mainfrom
shettyvarun268/batch-kits-uninstall-prompts
Oct 1, 2026
Merged

shettyvarun268 merged 7 commits into
mainfrom
shettyvarun268/batch-kits-uninstall-prompts

Conversation

@shettyvarun268

@shettyvarun268 shettyvarun268 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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 rewriting firebase.json once per instance.

Changes

  • Batched Deletion: Groups instances by resolved projectId (supporting .firebaserc aliases) and passes all codebase filters (filters: [{ codebase: id }, ...]) into a single deleteFunctionsByEndpointFilters invocation per project, displaying a single combined confirmation prompt.
  • Fail-Safe Ordering: Remote Cloud Functions teardown occurs across all projects prior to local file/directory deletions so local state is preserved if a prompt is rejected (re-running after a partial multi-project abort is idempotent since already-deleted projects return 0 matching endpoints).
  • Unified Teardown & DRY Helpers: Extracted deleteInstancesFunctions, cleanInstanceFiles, and getInstanceEnvNames to unify remote/local teardown and .env.<projectId> discovery across handleInstance, uninstallInstance, and uninstallKit.
  • Single Config Write: firebase.json is updated and saved once at the completion of kit uninstallation.
  • Tests: Added mocha unit tests covering multi-instance single-project batching, multi-project grouping with .firebaserc alias resolution, conservative deletion mode cleanup, and deletion failure abort safety.

Test Plan

  • Run mocha unit tests: npx mocha src/commands/functions-kits-uninstall.spec.ts (10 passing).
  • Run full typecheck: npm run test:compile.
  • Run linter: npm run lint.
  • Manually verified --kit and --instance uninstall flows with multiple active instances.

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

@shettyvarun268
shettyvarun268 marked this pull request as ready for review September 29, 2026 22: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 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.

@shettyvarun268

Copy link
Copy Markdown
Contributor Author

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

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()
@shettyvarun268
shettyvarun268 force-pushed the shettyvarun268/batch-kits-uninstall-prompts branch from 55ee54e to 9e1c69d Compare October 1, 2026 17:57
@shettyvarun268
shettyvarun268 merged commit 10ebed8 into main Oct 1, 2026
51 checks passed
@shettyvarun268
shettyvarun268 deleted the shettyvarun268/batch-kits-uninstall-prompts branch October 1, 2026 18:15
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