Skip to content

feat(container-indicator): add delete entry with confirmation - #555

Merged
ggbond268 merged 3 commits into
mactools-app:mainfrom
AndrewDi:feat/container-indicator-delete-entry
Dec 1, 2026
Merged

ggbond268 merged 3 commits into
mactools-app:mainfrom
AndrewDi:feat/container-indicator-delete-entry

Conversation

@AndrewDi

@AndrewDi AndrewDi commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a delete action for stopped containers in the ContainerIndicator plugin.

When a container is stopped, a trash button appears to the left of the start button. Clicking it presents a confirmation dialog naming the entry; confirming runs container delete <id> (without --force, which refuses running containers).

The delete is guarded so a stale confirmation can never remove the wrong object:

  • State verification. The list is re-read at confirm time. A container that started, disappeared, or is no longer the same incarnation cancels deletion with a clear message.
  • Incarnation identity. The container's creation date is captured when the dialog opens and compared against a fresh read, so a replacement that reuses the same ID is not deleted.

Scope: machine deletion is deferred

container machine delete unconditionally stops then deletes (try? await client.stop(id:) → delete), so it cannot enforce the "still stopped" condition the confirmation promises. Per review, the VM delete action is deferred until the CLI offers a conditional delete; machines keep only their existing lifecycle controls.

Changes

  • ContainerIndicatorController: deleteContainerIfStopped(id:createdAt:) re-reads the list and deletes only when the entry is still the same stopped container.
  • ContainerIndicatorWidgetViews: pending-deletion state + confirmation alert; trash button in the stopped container branch, left of start. Machine rows pass no delete action.
  • Tests: cover the delete command, the failure path, and regression tests for both state changes that cancel deletion (container started; replacement reused the ID).
  • Localization: panel.action.delete, panel.action.cancel, panel.delete.title, panel.delete.message, panel.error.deleteStateChanged (12 languages).
  • Changelog: plugin fragment under changes/unreleased/.

Verification

  • make build-plugin PLUGIN=ContainerIndicator ✓
  • make validate-localization ✓
  • make validate-changelog ✓
  • Test file type-checks against the built plugin module ✓ (full make test needs a Rust 1.97.1 toolchain for the VoiceControlPlugin Cua SDK, unavailable in this environment)

Stopped containers and virtual machines now show a delete button beside
the start action. Clicking it asks for confirmation before running the
CLI delete, so a stopped entry can be removed directly from the panel.
@AndrewDi

Copy link
Copy Markdown
Contributor Author

@xcv58 PTAL

@xcv58

xcv58 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks, @AndrewDi. I reproduced two cases with a fake CLI that I’d like us to address before merging.

  • A VM can start while the confirmation is open. Confirming still calls container machine delete, which stops the running VM and deletes it. Can we verify that the VM is still stopped and use a delete operation that enforces that at execution? If we’re staying with the current CLI, I’d defer VM deletion. Apple CLI implementation
  • A replacement container can reuse the selected container’s ID. The old confirmation can then delete the replacement. Please capture the selected container’s creation identity and cancel if a fresh read can’t verify it. Upstream ID reuse report

Could you add regression tests that verify both state changes cancel deletion?

…chine deletion

Address review feedback: the confirmation dialog can stay open while the
daemon changes underneath it. Deleting now re-reads the list first and
only deletes when the container is still the same stopped incarnation,
so a container that started, disappeared, or was replaced by one reusing
the same ID cancels instead of deleting the wrong object. Container
delete (without --force) also refuses running containers at execution.

The machine delete action is deferred because 'container machine delete'
unconditionally stops then deletes, so it cannot enforce the stopped
condition the confirmation promises. Regression tests cover both state
changes that cancel deletion.
@AndrewDi

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review. Both cases are now addressed:

  1. VM starting while the confirmation is open. container machine delete stops-then-deletes unconditionally, so it cannot enforce the stopped condition at execution. I've deferred the machine delete action until the CLI offers a conditional delete; machines keep only their existing lifecycle controls.

  2. A replacement container reusing the selected ID. The delete now captures the container's creation date when the dialog opens and re-reads the list at confirm time (deleteContainerIfStopped). It cancels with a clear message if the entry started, disappeared, or is a different incarnation (creation date no longer matches). Container delete is also run without --force, so the CLI refuses running containers again at execution.

Regression tests were added for both state changes (testContainerDeleteCancelsWhenContainerStartsWhileConfirming, testContainerDeleteCancelsWhenReplacementReusesID), each asserting the delete command is never issued.

Note: full make test still needs a Rust 1.97.1 toolchain here (VoiceControlPlugin's Cua SDK build step), so I verified via make build-plugin and a type-check of the test file against the built plugin module. Happy to run the suite on a machine with the toolchain.

@xcv58

xcv58 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

@AndrewDi I opened a follow-up PR against your branch. It uses a fresh inspection before Delete, keeps the row controls in sync with the container’s state, and preserves timeout feedback until a refresh can resolve it. The 22 focused tests passed with a fake CLI. Native confirmation and screenshots are still pending. Once the follow-up is merged into your branch, #555 will update automatically.

@AndrewDi

Copy link
Copy Markdown
Contributor Author

Integrated @xcv58's follow-up (commit 02ee8777 from PR #4) into this branch and pushed. It reworks deletion to run a fresh container inspect immediately before delete, tracks runtime status (running/stopped/stopping/unknown) for row controls, preserves timeout feedback until a healthy list read resolves it, and adds the regression tests for both races (container started during confirmation, and replacement reusing the ID).

Validated locally:

  • make build-plugin PLUGIN=ContainerIndicator ✓
  • make build-plugin-scheme PLUGIN=ContainerIndicator ✓
  • Test file swiftc -typecheck against the fresh module ✓ (EXIT=0)
  • make validate-localization ✓ (83 catalogs, 6942 keys)
  • make validate-changelog ✓

The full make test TEST_FILTER=ContainerIndicatorPluginTests still cannot run on this machine because the MacToolsTests target depends on every plugin, and VoiceControlPlugin's CuaDriver SDK build needs the Rust 1.97.1 toolchain, which is not installed (rustup not found). Please run make test TEST_FILTER=ContainerIndicatorPluginTests on a machine with Rust available.

@AndrewDi

Copy link
Copy Markdown
Contributor Author

@xcv58 PTAL

@ggbond268
ggbond268 merged commit f5a7624 into mactools-app:main Dec 1, 2026
2 checks passed
@AndrewDi
AndrewDi deleted the feat/container-indicator-delete-entry branch December 1, 2026 10:20
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.

3 participants