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

feat(testing) Add bin/sandbox.ps1 to easily test using a Windows sandbox #5349

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

rasa
Copy link
Member

@rasa rasa commented Jan 20, 2023

This script allows one to easily test apps inside a Windows sandbox. I recently used it to test over 20 PRs found at https://github.com/ScoopInstaller/Nonportable/pulls?q=is%3Apr+is%3Aclosed and it works great.

To speed up testing, you can cache the apps the script installs by default:

scoop cache rm -a
scoop update -f main/7zip
scoop update -f main/git
scoop update -f main/innounp
scoop update -f main/dark
scoop update -f main/lessmsi

The script will then copy the files from scoop's local cache to scoop's cache in the sandbox, so scoop doesn't need to download them.

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@jspraul
Copy link

jspraul commented Feb 4, 2023

Scoop is almost a requirement for Windows Sandbox; the Windows Store (and thus winget) does not work. Managing a cache for Windows Sandbox would make the initial startup less painful; I might even install Scoop on my host machine!

A couple 🥧pie in the sky☁ Windows Sandbox-specific scoop feature ideas that may already be (close to) possible:

  1. don't block install as admin if username is WDAGUtilityAccount (or some other way of detecting being inside the Sandbox)
  2. don't unzip the scoop.main.zip etc. files, I only want a couple apps for a few minutes with no plan to update the sources

Keep up the good work!

@rashil2000
Copy link
Member

I believe @roysubs made some scripts to automate testing in Sandbox. @roysubs would you mind taking a look here?

@rasa
Copy link
Member Author

rasa commented Feb 5, 2023

I believe @roysubs made some scripts to automate testing in Sandbox. @roysubs would you mind taking a look here?

@roysubs Yeah, my script is just a hack of https://github.com/microsoft/winget-pkgs/blob/HEAD/Tools/SandboxTest.ps1, so it certainly can be improved on/replaced with something better.

Write-Host @'
--> Installing Scoop, 7zip, git, innounp, dark and lessmsi
'@
`$ProgressPreference = 'SilentlyContinue'
Copy link
Member

@r15ch13 r15ch13 Feb 18, 2023

Choose a reason for hiding this comment

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

$ProgressPreference has been fixed with ScoopInstaller/Install#42
Edit: Okay it also mutes the output of Invoke-RestMethod 😄

@r15ch13
Copy link
Member

r15ch13 commented Feb 18, 2023

Do we need Update-EnvironmentVariables() and Get-ARPTable() for this to work?

Just a simple bootstrap.ps1 like this should be enough.

$global:ProgressPreference = 'SilentlyContinue'
# $global:VerbosePreference = 'Continue'

Invoke-RestMethod get.scoop.sh | Invoke-Expression

scoop config aria2-warning-enabled false
scoop install --no-update-scoop main/7zip
scoop install --no-update-scoop main/aria2
scoop install --no-update-scoop main/mingit
# scoop install --no-update-scoop main/innounp
# scoop install --no-update-scoop main/dark
# scoop install --no-update-scoop main/lessmsi
scoop install --no-update-scoop main/pwsh
scoop bucket add extras
PowerShell Start-Process ~\scoop\apps\pwsh\current\pwsh.exe -WorkingDirectory ~

Instead of copying the cache (multiple GB) we could just mount it:

    <MappedFolder>
      <HostFolder>$scoopCache</HostFolder>
      <SandboxFolder>%USERPROFILE%\scoop\cache</SandboxFolder>
    </MappedFolder>

@rasa
Copy link
Member Author

rasa commented Feb 19, 2023

Do we need Update-EnvironmentVariables() and Get-ARPTable() for this to work?

@r15ch13 We can certainly toss them if they are causing issues, but they both are helpful when testing apps from the NonPortable bucket.

Instead of copying the cache (multiple GB) we could just mount it:

That's a great idea. Much simpler than my hack.

@r15ch13
Copy link
Member

r15ch13 commented Feb 27, 2023

Another neat feature, add Scoop and bootstrap directory to Quick Access:

$o = New-Object -ComObject Shell.Application
$o.Namespace("$env:USERPROFILE\scoop").Self.InvokeVerb("pintohome")
$o.Namespace("$env:USERPROFILE\bootstrap").Self.InvokeVerb("pintohome")

@r15ch13
Copy link
Member

r15ch13 commented Feb 27, 2023

This creates a functioning Scoop installation by mounting my local dev repo:

scoop-dev.wsb

<Configuration>
  <MappedFolders>
    <MappedFolder>
      <HostFolder>.\bootstrap</HostFolder>
      <SandboxFolder>C:\Users\WDAGUtilityAccount\bootstrap</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
    <MappedFolder>
      <HostFolder>X:\~projects\~powershell\scoop</HostFolder><!-- Change to local dev directory-->
      <SandboxFolder>C:\Users\WDAGUtilityAccount\scoop\apps\scoop\current</SandboxFolder>
      <ReadOnly>true</ReadOnly>
    </MappedFolder>
    <MappedFolder>
      <HostFolder>%USERPROFILE%\scoop\cache</HostFolder>
      <SandboxFolder>C:\Users\WDAGUtilityAccount\scoop\cache</SandboxFolder>
      <!-- <ReadOnly>true</ReadOnly> -->
    </MappedFolder>
  </MappedFolders>
  <LogonCommand>
    <Command>PowerShell Start-Process PowerShell -WindowStyle Maximized -WorkingDirectory 'C:\Users\WDAGUtilityAccount\bootstrap' -ArgumentList '-ExecutionPolicy Bypass -NoLogo -File scoop-dev.ps1'</Command>
  </LogonCommand>
</Configuration>

bootstrap\scoop-dev.ps1

$global:ProgressPreference = 'SilentlyContinue'
# $global:VerbosePreference = 'Continue'
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force -ErrorAction SilentlyContinue

# Pin to Quick Access
$o = New-Object -ComObject Shell.Application
$o.Namespace("$env:USERPROFILE\scoop").Self.InvokeVerb("pintohome")
$o.Namespace("$env:USERPROFILE\bootstrap").Self.InvokeVerb("pintohome")

## Short Scoop Installer
function Install-Scoop() {
    $SCOOP_SHIMS_DIR = "$env:USERPROFILE\scoop\shims"
    $null = New-Item -Path $SCOOP_SHIMS_DIR -ItemType Directory -ErrorAction SilentlyContinue

    $ps1text = @(
        "`$path = Join-Path `$PSScriptRoot `"..\apps\scoop\current\bin\scoop.ps1`"",
        "if (`$MyInvocation.ExpectingInput) { `$input | & `$path $arg @args } else { & `$path $arg @args }",
        "exit `$LASTEXITCODE"
    )
    [System.IO.File]::WriteAllLines("$SCOOP_SHIMS_DIR\scoop.ps1", $ps1text -join "`r`n")

    $userEnvPath = (Get-Item -Path 'HKCU:').OpenSubKey('Environment', $true).GetValue('PATH', $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)

    & "$($env:SystemRoot)\System32\setx.exe" PATH `""$SCOOP_SHIMS_DIR;$userEnvPath"`" | Out-Null
    $env:PATH = "$SCOOP_SHIMS_DIR;$env:PATH"
}
Install-Scoop

## Install git
scoop install --no-update-scoop https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/mingit-busybox.json

## Add buckets
git clone https://github.com/ScoopInstaller/Main "$env:USERPROFILE\scoop\buckets\main" --depth=1
git clone https://github.com/ScoopInstaller/Extras "$env:USERPROFILE\scoop\buckets\extras" --depth=1

## Install default software
scoop config aria2-warning-enabled false
scoop config debug true
scoop install --no-update-scoop main/7zip main/aria2 main/pwsh
# scoop install --no-update-scoop main/innounp main/dark main/lessmsi

## Start test shell
PowerShell Start-Process "$env:USERPROFILE\scoop\apps\pwsh\current\pwsh.exe" -WorkingDirectory ~

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.

4 participants