Skip to content
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

cask/quarantine: sudo correctly during tests. #15968

Merged
merged 1 commit into from
Sep 6, 2023
Merged

cask/quarantine: sudo correctly during tests. #15968

merged 1 commit into from
Sep 6, 2023

Conversation

MikeMcQuaid
Copy link
Member

Fixes #15958

@Bo98
Copy link
Member

Bo98 commented Sep 5, 2023

What is to here and why is it not writeable? Seems like there's a problem here if we're demanding sudo and it doesn't fail without it.

@MikeMcQuaid
Copy link
Member Author

What is to here and why is it not writeable?

It's explicitly set to not be writable in the test.

Seems like there's a problem here if we're demanding sudo and it doesn't fail without it.

If you can reproduce the same behaviour in Not The Test Environment: sure. This just feels like an omission when underlying functionality was changed, though.

@Bo98
Copy link
Member

Bo98 commented Sep 6, 2023

Right I understand the situation now.

In the test we pass NeverSudoSystemCommand to install_phase. This down the line gets passed, in this case, to Cask::Artifact::Moved#move as the command parameter, where we run command.run! instead of system_command!.

The issue here is we don't pass this further down to the Quarantine.copy_xattrs call. It seems like we should be doing so here.

@apainintheneck
Copy link
Contributor

I tested out @Bo98's idea and the failing test now succeeds for me locally.

diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb
index d41e62cec..a9e3470d7 100644
--- a/Library/Homebrew/cask/artifact/moved.rb
+++ b/Library/Homebrew/cask/artifact/moved.rb
@@ -91,7 +91,7 @@ module Cask
             command.run!("/bin/cp", args: ["-pR", *source.children, target],
                                     sudo: true)
           end
-          Quarantine.copy_xattrs(source, target)
+          Quarantine.copy_xattrs(source, target, command: command)
           source.rmtree
         elsif target.dirname.writable?
           FileUtils.move(source, target)
diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb
index 227790629..e038011e6 100644
--- a/Library/Homebrew/cask/quarantine.rb
+++ b/Library/Homebrew/cask/quarantine.rb
@@ -174,11 +174,11 @@ module Cask
       raise CaskQuarantinePropagationError.new(to, quarantiner.stderr)
     end
 
-    sig { params(from: Pathname, to: Pathname).void }
-    def self.copy_xattrs(from, to)
+    sig { params(from: Pathname, to: Pathname, command: T.class_of(SystemCommand)).void }
+    def self.copy_xattrs(from, to, command:)
       odebug "Copying xattrs from #{from} to #{to}"
 
-      system_command!(
+      command.run!(
         swift,
         args: [
           *swift_target_args,

@MikeMcQuaid
Copy link
Member Author

@Bo98 Good catch, will try to take a look, thanks.

@MikeMcQuaid MikeMcQuaid changed the title cask/quarantine: don't try to sudo during tests. cask/quarantine: sudo correctly during tests. Sep 6, 2023
@MikeMcQuaid
Copy link
Member Author

Thanks @Bo98 @apainintheneck have updated accordingly based on your feedback and diff.

@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label Sep 6, 2023
Use `NeverSudoSystemCommand` and pass it through to
`Quarantine.copy_xattrs` so `brew tests` doesn't try to `sudo`.

Fixes #15958

Co-authored-by: Bo Anderson <[email protected]>
Co-authored-by: Kevin <[email protected]>
@MikeMcQuaid MikeMcQuaid merged commit d5d7478 into Homebrew:master Sep 6, 2023
24 checks passed
@MikeMcQuaid MikeMcQuaid deleted the cask_upgrade_sudo_test_fix branch September 6, 2023 14:17
@apainintheneck
Copy link
Contributor

Thanks for the help with fixing this! I thought it was maybe a local problem when I first saw it pop up since CI has been green the whole time.

@github-actions github-actions bot added the outdated PR was locked due to age label Oct 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cask Upgrade test consistently fails because it asks for sudo
4 participants