-
Notifications
You must be signed in to change notification settings - Fork 8
v0.1.7: APT Clean dry-run safety + docker test exit-code propagation #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+152
−39
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
239fb4b
fix(apt): honor DryRun in Clean() to prevent silent destructive ops
bluet 16a87d4
ci(docker): make test failures propagate + harden test-all service
bluet 3dd42ce
docs(changelog): add v0.1.7 entry
bluet 1e42e97
ci(docker): apply review feedback on test-all hardening
bluet 5594581
ci(docker): switch to --abort-on-container-failure to stop killing sl…
bluet 0b84517
ci(docker): use Compose v2 syntax (`docker compose`) for new flag
bluet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package apt_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/bluet/syspkg/manager" | ||
| "github.com/bluet/syspkg/manager/apt" | ||
| ) | ||
|
bluet marked this conversation as resolved.
|
||
|
|
||
| // TestCleanRespectsDryRun is the regression test for the security-relevant bug | ||
| // where Clean() executed `apt autoclean` even when opts.DryRun was true. | ||
| // Behavior contract: Clean(DryRun=true) MUST NOT execute any underlying command. | ||
| func TestCleanRespectsDryRun(t *testing.T) { | ||
| mockRunner := manager.NewMockCommandRunner() | ||
| pm := apt.NewPackageManagerWithCustomRunner(mockRunner) | ||
|
|
||
| if err := pm.Clean(&manager.Options{DryRun: true}); err != nil { | ||
| t.Fatalf("Clean(DryRun=true) returned error: %v", err) | ||
| } | ||
|
|
||
| if got := len(mockRunner.EnvCalls); got != 0 { | ||
| t.Errorf("Clean(DryRun=true) executed %d non-interactive command(s); expected 0. Calls: %v", | ||
| got, mockRunner.EnvCalls) | ||
| } | ||
| if got := len(mockRunner.InteractiveCalls); got != 0 { | ||
| t.Errorf("Clean(DryRun=true) executed %d interactive command(s); expected 0. Calls: %v", | ||
| got, mockRunner.InteractiveCalls) | ||
| } | ||
| } | ||
|
|
||
| // TestCleanRunsWithoutDryRun guards against the Clean(DryRun) fix being | ||
| // implemented as a blanket no-op. Without DryRun, Clean MUST invoke | ||
| // `apt autoclean`. | ||
| func TestCleanRunsWithoutDryRun(t *testing.T) { | ||
| mockRunner := manager.NewMockCommandRunner() | ||
| mockRunner.AddCommand("apt", []string{"autoclean"}, []byte("Reading package lists...\n"), nil) | ||
| pm := apt.NewPackageManagerWithCustomRunner(mockRunner) | ||
|
|
||
| if err := pm.Clean(&manager.Options{DryRun: false}); err != nil { | ||
| t.Fatalf("Clean(DryRun=false) returned error: %v", err) | ||
| } | ||
|
|
||
| if _, ok := mockRunner.EnvCalls["apt autoclean"]; !ok { | ||
| t.Errorf("Clean(DryRun=false) didn't invoke 'apt autoclean'. Recorded calls: %v", | ||
| mockRunner.EnvCalls) | ||
| } | ||
| } | ||
|
|
||
| // TestCleanRespectsDryRunWithNilOptsDefault verifies the nil-opts branch: | ||
| // when opts == nil, the code path defaults DryRun to false, so Clean | ||
| // SHOULD execute (proving the nil-opts default is preserved by the fix). | ||
| func TestCleanRunsWithNilOpts(t *testing.T) { | ||
| mockRunner := manager.NewMockCommandRunner() | ||
| mockRunner.AddCommand("apt", []string{"autoclean"}, []byte("Reading package lists...\n"), nil) | ||
| pm := apt.NewPackageManagerWithCustomRunner(mockRunner) | ||
|
|
||
| if err := pm.Clean(nil); err != nil { | ||
| t.Fatalf("Clean(nil) returned error: %v", err) | ||
| } | ||
|
|
||
| if _, ok := mockRunner.EnvCalls["apt autoclean"]; !ok { | ||
| t.Errorf("Clean(nil) didn't invoke 'apt autoclean'. Recorded calls: %v", | ||
| mockRunner.EnvCalls) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.