Skip to content

ADFA-5444: Skip the Downloads restore/collision check for plugin templates - #2049

Open
jimturner-adfa wants to merge 1 commit into
stagefrom
ADFA-5444-Extensions-manager-Cant-uninstall-a-Flutter-template
Open

jimturner-adfa wants to merge 1 commit into
stagefrom
ADFA-5444-Extensions-manager-Cant-uninstall-a-Flutter-template

Conversation

@jimturner-adfa

@jimturner-adfa jimturner-adfa commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-5444

Summary

Uninstalling a plugin-provided template (reported with the Flutter plugin) unconditionally tried to "restore" it to Downloads first, tripping a false "already exists" collision whenever an unrelated file happened to share its name there. The template was extracted straight from the plugin's own bundled resources (PluginProjectManager.extractBundledCgtTemplates) and never touched Downloads in the first place, so the error was both blocking and factually wrong - matching the ticket's exact repro and screenshot.

  • A plugin-provenance item now just gets deleted from the templates directory on uninstall, skipping the Downloads restore/collision check entirely.
  • This matches how PluginProjectManager/IdeTemplateServiceImpl already remove plugin templates elsewhere (cleanupPluginTemplates/unregisterTemplate).
  • User-imported templates keep the existing restore-to-Downloads behavior, since those genuinely came from there.

Testing

  • Added uninstallTemplate_pluginProvenance_neverChecksOrTouchesDownloads; verified it fails without the fix with the exact reported error (IllegalStateException: A download named '...' already exists in ...) and passes with it.
  • Reproduced the bug on a physical device using a real installed Flutter plugin (com.ali.fluttertemplate): created a same-named stale file in Downloads for one of its templates, confirmed uninstall previously would have blocked on it, then confirmed with the fix it deletes cleanly - the real template file is removed from the templates directory and the unrelated Downloads file is left untouched. No crashes.

🤖 Generated with Claude Code

…lates

Uninstalling a plugin-provided template (e.g. from the Flutter plugin)
unconditionally tried to "restore" it to Downloads, tripping a false
"already exists" collision whenever an unrelated file happened to
share its name there - even though the template was extracted
straight from the plugin's own bundled resources and never touched
Downloads in the first place.

A plugin-provenance item now just gets deleted from the templates
directory on uninstall, matching how PluginProjectManager and
IdeTemplateServiceImpl already remove these templates elsewhere.
User-imported templates keep the existing restore-to-Downloads
behavior, since those genuinely came from there.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: d9cb48b3-b24a-462f-b671-fe9546f2519d

📥 Commits

Reviewing files that changed from the base of the PR and between 5a26dfa and fee3efb.

📒 Files selected for processing (3)
  • app/src/main/java/com/itsaky/androidide/repositories/TemplateRepository.kt
  • app/src/main/java/com/itsaky/androidide/repositories/TemplateRepositoryImpl.kt
  • app/src/test/java/com/itsaky/androidide/repositories/TemplateRepositoryImplTest.kt

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Summary
  • Plugin-provided templates are deleted directly from the templates directory.
  • The uninstall flow no longer restores plugin templates to Downloads or checks for filename collisions.
  • User-imported templates retain the existing restore-to-Downloads behavior.
  • Added regression coverage for plugin-template uninstall behavior.
  • Validation with an installed Flutter plugin confirmed that the plugin template is removed and an unrelated same-named Downloads file remains unchanged.
  • Risk: Plugin-template files are permanently deleted instead of being restored to Downloads.

Walkthrough

uninstallTemplate now deletes plugin-provenance templates directly. User-imported templates keep the restore-to-Downloads flow. KDoc and a regression test describe and verify the behavior.

Changes

Plugin Template Uninstall

Layer / File(s) Summary
Direct plugin uninstall path
app/src/main/java/com/itsaky/androidide/repositories/TemplateRepository.kt, app/src/main/java/com/itsaky/androidide/repositories/TemplateRepositoryImpl.kt, app/src/test/java/com/itsaky/androidide/repositories/TemplateRepositoryImplTest.kt
The implementation deletes plugin-provenance templates without checking or writing to Downloads. User-imported templates retain the existing restore flow. KDoc documents both paths, and the test verifies that Downloads remains unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to fee3e

The plugin uninstall path deletes plugin-provided templates without interacting with Downloads, while user-imported templates retain their restore behavior. No merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: plugin templates skip the Downloads restore and collision check during uninstall.
Description check ✅ Passed The description directly explains the bug, the plugin-template uninstall fix, preserved user-template behavior, and test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ADFA-5444-Extensions-manager-Cant-uninstall-a-Flutter-template

A rabbit watched the plugin file go,
No Downloads copy had to show.
The template vanished from its place,
While user files kept their restore case.
Tests guarded every path with care.

Comment @coderabbitai help to get the list of available commands.

@jimturner-adfa

Copy link
Copy Markdown
Collaborator Author

Merge-order note: if this merges after #2045 (ADFA-5446), you'll hit one real conflict in TemplateRepository.kt - both PRs edit the uninstallTemplate doc comment/signature (this PR describes the plugin/user provenance split; #2045 adds the overwrite param for the Downloads-replace flow). They're not contradictory - I simulated the merge locally and the actual implementation in TemplateRepositoryImpl.kt combines both changes correctly with no manual work needed (the plugin-provenance branch runs first, then the overwrite/collision logic). Only the interface doc comment needs reconciling by hand.

Resolution to use when that conflict comes up:

	/**
	 * Removes [item] from the templates directory and reloads templates. A plugin-provided item is
	 * just deleted, since it never came from Downloads in the first place. A user-imported item is
	 * restored to Downloads first, failing with [TemplateReplaceConflictException] if a file of the
	 * same name already exists there, unless [overwrite] is true.
	 */
	suspend fun uninstallTemplate(
		item: CgtFileItem,
		overwrite: Boolean = false,
	): Result<Unit>

No other files conflict between the two PRs - confirmed with a full local merge simulation (compiles clean, all 22 tests across both PRs pass together).

@Elissa-AppDevforAll Elissa-AppDevforAll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I could uninstall the individual templates created by the Flutter plugin.

@hal-eisen-adfa

Copy link
Copy Markdown
Collaborator

There's a logic bug here. It doesn't matter where a template comes from (plugin or cgt file). We don't need a "restore" function for templates. If you want to add a "disable" feature to match the plugins, I could see that. But uninstalling a template doesn't need special undo functionality. The user can re-install the original cgt file.

check(item.installed) { "'${item.name}' is not installed" }
check(item.provenance != TemplateProvenance.BUNDLED) { "Cannot uninstall the bundled template" }

if (item.provenance == TemplateProvenance.PLUGIN) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Templates come from cgt files, not plugins.

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