Skip to content

Conversation

@brunodam
Copy link
Contributor

@brunodam brunodam commented Sep 25, 2025

Issue Description

When using the Go library and calling the Delete() function in the apt backend with ArgsPurge set in CustomCommandArgs, the purge behavior is not applied. The package is removed, but config files remain (dpkg shows state rc).

This pull request updates the APT package manager logic to support an optional purge flag during package deletion, and adds comprehensive tests to verify the correct behavior when the purge flag is used or omitted. The changes improve flexibility and reliability when removing packages.

Example (Go snippet):

opts := &manager.Options{
    AssumeYes:         true,
    CustomCommandArgs: []string{manager.ArgsPurge}, // request purge
}
aptPM.Delete([]string{"ebtables"}, opts)

###Expected
The command executed should be equivalent to:

apt remove --purge ebtables

so that configuration files are also removed.

Actual

The package is removed, but config files remain:

dpkg-query -W -f='${Status}\n' ebtables
# => deinstall ok config-files

Notes

  • This issue is about supporting purge when explicitly requested.
  • Default behavior (apt remove) should remain unchanged.

Important

Add support for APT package purge via CustomCommandArgs in Delete() and include tests for purge behavior.

  • Behavior:
    • Delete() in apt.go now supports --purge flag via CustomCommandArgs.
    • If ArgsPurge is in CustomCommandArgs, --purge is appended to APT command.
    • Default behavior remains unchanged if ArgsPurge is not specified.
  • Tests:
    • TestDelete_WithPurgeFlag in apt_commandrunner_test.go verifies --purge flag inclusion.
    • TestDelete_WithoutPurgeFlag in apt_commandrunner_test.go ensures --purge is not included when not specified.

This description was created by Ellipsis for 1faebef. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Package deletion via APT now supports an explicit purge mode to remove configuration files when requested; default removal behavior unchanged.
    • Command option handling improved to ensure consistent inclusion of force/auto-remove flags and correct handling of dry-run/confirm options.
  • Tests

    • Added tests validating delete behavior both with and without purge to ensure correct command handling and reliable outcomes.

@coderabbitai
Copy link

coderabbitai bot commented Sep 25, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Delete now builds apt remove arguments incrementally: start with base remove args, always include fix-broken and autoremove, conditionally include --purge when present in CustomCommandArgs, append package names, then create the 10-minute timeout context and run the command. Two tests added for purge/no-purge. No public API changes.

Changes

Cohort / File(s) Summary
APT manager implementation
manager/apt/apt.go
Rework Delete argument construction: start with base remove args, always include fix-broken and autoremove flags, conditionally detect and append --purge from CustomCommandArgs, append package names after flags, then create 10-minute timeout context and execute. No exported signatures changed.
APT deletion tests
manager/apt/apt_commandrunner_test.go
Add two subtests to TestAPT_WithMockedCommands verifying command args include --purge when CustomCommandArgs contains it and omit it otherwise; use mocked runner and assert non-nil results and no error.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant PM as PackageManager.Delete
  participant Runner as CommandRunner

  Caller->>PM: Delete(packages, opts)
  PM->>PM: Initialize base args ["apt","remove"]
  PM->>PM: Append fixed flags (ArgsFixBroken, ArgsAutoRemove)
  PM->>PM: Merge CustomCommandArgs (scan for "--purge")
  alt CustomCommandArgs contains "--purge"
    PM->>PM: Append "--purge"
  end
  PM->>PM: Append package names
  PM->>PM: Create 10-minute timeout context
  PM->>Runner: Run(command args, ctx)
  Runner-->>PM: stdout/stderr, exit code
  PM-->>Caller: Return package list or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hop through args with careful paws,
I sniff for purge beneath the clause.
Append flags neat, then names at end,
Ten minutes set — the command I send.
Tests cheer softly in burrowed dens. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the main change of enabling APT purge support through the CustomCommandArgs option, matching the primary update in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gemini-code-assist
Copy link

Summary of Changes

Hello @brunodam, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue in the Go library's APT backend where specifying ArgsPurge during a package deletion operation did not result in the removal of associated configuration files. The changes modify the Delete function to properly detect and apply the purge flag from CustomCommandArgs, ensuring that the apt remove --purge command is executed when intended. This enhancement provides greater control and reliability for package management operations, allowing users to fully clean up packages and their configurations.

Highlights

  • APT Purge Support: The APT package manager's Delete function now correctly processes the ArgsPurge option provided via CustomCommandArgs, ensuring that configuration files are removed along with the package.
  • Correct Command Execution: When ArgsPurge is specified, the underlying apt remove --purge command is now executed, addressing the previous behavior where configuration files remained after deletion.
  • Comprehensive Testing: New test cases have been added to validate both scenarios: package deletion with the purge flag and without it, confirming that the default behavior remains unchanged and the new purge functionality works as expected.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 1faebef in 44 seconds. Click for details.
  • Reviewed 126 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. manager/apt/apt.go:216
  • Draft comment:
    Good use of slices.Contains to conditionally append the purge flag based on CustomCommandArgs. Consider adding a safeguard to prevent appending duplicate '--purge' flags if the flag might already be present in the args.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. manager/apt/apt_commandrunner_test.go:288
  • Draft comment:
    The new tests for Delete with and without the purge flag thoroughly verify the expected command arguments. This ensures that the flag is only appended when requested.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_xJztfvbzGGc0S7KM

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 correctly implements support for the --purge flag in the Delete function for the APT package manager by checking CustomCommandArgs. The logic is sound and directly addresses the issue described. The addition of tests for both cases (with and without the purge flag) is great for ensuring correctness. I have one suggestion to refactor the new tests to improve maintainability by using a table-driven approach, which will reduce code duplication.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
manager/apt/apt.go (1)

17-24: Remove standard-library slices dependency (Go <1.21 build break).

The repository targets Go 1.20 (go.mod), so importing the stdlib slices package (introduced in Go 1.21) breaks compilation. Please inline the check instead of pulling in slices.

-import (
-	"context"
-	"log"
-	"os/exec"
-	"slices"
-	"strings"
+import (
+	"context"
+	"log"
+	"os/exec"
+	"strings"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f6404b and 1faebef.

📒 Files selected for processing (2)
  • manager/apt/apt.go (2 hunks)
  • manager/apt/apt_commandrunner_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
manager/apt/apt_commandrunner_test.go (3)
manager/command_runner.go (1)
  • NewMockCommandRunner (95-102)
manager/apt/apt.go (2)
  • NewPackageManagerWithCustomRunner (79-83)
  • ArgsPurge (41-41)
manager/options.go (1)
  • Options (5-23)
manager/apt/apt.go (3)
manager/yum/yum.go (1)
  • ArgsPurge (51-51)
manager/flatpak/flatpak.go (1)
  • ArgsPurge (36-36)
manager/snap/snap.go (1)
  • ArgsPurge (35-35)
🔇 Additional comments (1)
manager/apt/apt_commandrunner_test.go (1)

288-372: Tests look solid.

Great coverage of both purge/no-purge paths and clear expectations on the mocked command arguments.

@brunodam brunodam force-pushed the 00001-apt-purge-support branch 2 times, most recently from 221a1a7 to 86de072 Compare September 25, 2025 08:14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
manager/apt/apt.go (1)

215-221: Optional: consider passing through additional CustomCommandArgs (whitelist).

If future needs arise (e.g., other safe apt flags), consider appending a curated subset of opts.CustomCommandArgs (e.g., [--allow-change-held-packages], [--reinstall]) rather than only --purge.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1faebef and 86de072.

📒 Files selected for processing (2)
  • manager/apt/apt.go (1 hunks)
  • manager/apt/apt_commandrunner_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • manager/apt/apt_commandrunner_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
manager/apt/apt.go (3)
manager/yum/yum.go (1)
  • ArgsPurge (51-51)
manager/snap/snap.go (1)
  • ArgsPurge (35-35)
manager/flatpak/flatpak.go (1)
  • ArgsPurge (36-36)
🔇 Additional comments (1)
manager/apt/apt.go (1)

215-221: LGTM: --purge is appended only when requested and both purge/no-purge cases are covered by tests.

@bluet bluet requested a review from Copilot September 25, 2025 08:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for APT package purging via the CustomCommandArgs option in the Delete() function. The implementation checks for the ArgsPurge flag in custom command arguments and appends --purge to the APT command when explicitly requested, while maintaining default behavior when not specified.

  • Added purge flag detection logic in the APT package manager's Delete() method
  • Added comprehensive tests to verify both purge and non-purge deletion behaviors
  • Preserved backward compatibility by keeping default removal behavior unchanged

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
manager/apt/apt.go Added logic to detect and apply ArgsPurge flag from CustomCommandArgs
manager/apt/apt_commandrunner_test.go Added test cases for delete operations with and without purge flag

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@brunodam brunodam force-pushed the 00001-apt-purge-support branch from 86de072 to 86cf5df Compare September 25, 2025 20:45
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
manager/apt/apt.go (1)

359-361: Fix printf verb for args logging

Current formatting prints %!s(MISSING) for []string. Use %v or join for readability.

Apply this diff:

-	log.Printf("Running command: %s %s", pm, args)
+	log.Printf("Running command: %s %s", pm, strings.Join(args, " "))
🧹 Nitpick comments (1)
manager/apt/apt.go (1)

213-221: Comment is misleading; code only adds assume-yes

The code adds -y when non-interactive; it does not handle assume-no. Make the comment precise.

Apply this diff:

-	// Add dry-run and assume-yes/no options based on opts
+	// Add dry-run, and assume-yes when non-interactive to avoid hanging
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86de072 and 86cf5df.

📒 Files selected for processing (2)
  • manager/apt/apt.go (1 hunks)
  • manager/apt/apt_commandrunner_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • manager/apt/apt_commandrunner_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
manager/apt/apt.go (3)
manager/yum/yum.go (5)
  • ArgsFixBroken (50-50)
  • ArgsAutoRemove (52-52)
  • ArgsDryRun (49-49)
  • ArgsAssumeYes (46-46)
  • ArgsPurge (51-51)
manager/snap/snap.go (5)
  • ArgsFixBroken (33-33)
  • ArgsAutoRemove (36-36)
  • ArgsDryRun (32-32)
  • ArgsAssumeYes (30-30)
  • ArgsPurge (35-35)
manager/flatpak/flatpak.go (5)
  • ArgsFixBroken (34-34)
  • ArgsAutoRemove (38-38)
  • ArgsDryRun (33-33)
  • ArgsAssumeYes (31-31)
  • ArgsPurge (36-36)
🔇 Additional comments (3)
manager/apt/apt.go (3)

207-212: Correct base args and early flag assembly — LGTM

Starting with "remove" and appending -f and --autoremove up-front is correct and ensures flags precede package names.


223-229: Manual scan for purge — good fix and Go 1.20 compatible

The loop avoids slices.Contains and keeps --purge before pkgs. Matches prior review direction.


231-233: Flag ordering now correct — LGTM

Appending pkgs after flags ensures apt sees --purge before package names as expected.

- Add isPurgeRequested function to check for --purge flag in CustomCommandArgs
- Modify Delete method to conditionally add --purge flag when requested
- Add comprehensive tests for both with and without purge scenarios
- Maintain backward compatibility by keeping --purge optional

Signed-off-by: Bruno De Assis Marques <bruno.marques@swirldslabs.com>
@brunodam brunodam force-pushed the 00001-apt-purge-support branch from 86cf5df to ab6e690 Compare September 25, 2025 21:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86cf5df and ab6e690.

📒 Files selected for processing (2)
  • manager/apt/apt.go (1 hunks)
  • manager/apt/apt_commandrunner_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • manager/apt/apt_commandrunner_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

@brunodam
Copy link
Contributor Author

👋 Hey @bluet, just checking in to see if you’ve had a chance to take a look at this PR.
Happy to make any adjustments or discuss alternatives if needed. Thanks for maintaining syspkg — it’s been great to use!

@bluet
Copy link
Owner

bluet commented Nov 1, 2025

@brunodam thanks for the PR! great job 👍

@bluet bluet merged commit 2ab1382 into bluet:main Nov 1, 2025
4 checks passed
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