Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ if ($args.Count) { throw 'Usage: .\pi.ps1' }
$installer = Invoke-RestMethod https://pi.dev/install.ps1
& ([scriptblock]::Create($installer + "`n" + @'
$pi = Join-Path (Get-PiBinDir) 'pi.cmd'
$version = & $pi --version
& $pi --version
if ($LASTEXITCODE) { exit $LASTEXITCODE }
if ($version -notmatch '^0\.(86\.[1-9]\d*|87\.\d+)$') { Write-Warning "Pi $version installed; LMM alpha supports 0.86.1 through 0.87.x, plugin skipped."; exit 0 }
$env:LMM_PI_BIN = $pi
npm.cmd exec --yes --package=@tokennotincluded/pi-lmm-provider@0.1.0-alpha.2 -- lmm-pi-provider npm:@tokennotincluded/pi-lmm-provider@0.1.0-alpha.2
npm.cmd exec --yes --package=@tokennotincluded/pi-lmm-provider@alpha -- lmm-pi-provider git:github.com/TokenNotIncluded/pi-lmm-provider
exit $LASTEXITCODE
'@))
5 changes: 2 additions & 3 deletions pi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if [[ -n ${TERMUX_VERSION:-} || ${PREFIX:-} == */com.termux/files/usr ]]; then
fi
installer=$(curl -fsSL https://pi.dev/install.sh)
exec sh -c "$installer"'
pi=$(pi_installed_path); version=$("$pi" --version)
case "$version" in 0.86.[1-9]*|0.87.*) ;; *) echo "Pi $version installed; LMM alpha supports 0.86.1 through 0.87.x, plugin skipped." >&2; exit 0;; esac
pi=$(pi_installed_path); "$pi" --version
command -v npm >/dev/null 2>&1 || { echo "npm is required to install the LMM plugin and remove conflicting sources." >&2; exit 1; }
LMM_PI_BIN="$pi" npm exec --yes --package=@tokennotincluded/pi-lmm-provider@0.1.0-alpha.2 -- lmm-pi-provider npm:@tokennotincluded/pi-lmm-provider@0.1.0-alpha.2'
LMM_PI_BIN="$pi" npm exec --yes --package=@tokennotincluded/pi-lmm-provider@alpha -- lmm-pi-provider git:github.com/TokenNotIncluded/pi-lmm-provider'
6 changes: 4 additions & 2 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ function npm.cmd {
}
function pi.cmd { throw 'must not invoke stale pi on PATH' }
'@
Check 'pi.ps1' $piSetup 0 'lmm-pi-provider\|npm:@tokennotincluded/pi-lmm-provider'
Check 'pi.ps1' $piSetup 0 'lmm-pi-provider\|git:github.com/TokenNotIncluded/pi-lmm-provider'
Check 'pi.ps1' ($piSetup+"`n`$env:PI_TEST_INSTALLER='Write-Output cancelled; exit 0'") 0 'cancelled'
Check 'pi.ps1' ($piSetup+"`n`$env:PI_TEST_INSTALLER='Write-Output failed; exit 9'") 9 'failed'
Check 'pi.ps1' ($piSetup+"`n`$env:PI_TEST_VERSION='0.88.0'; function official-pi { if (`$args[0] -ne '--version') { throw 'unsupported plugin must not run' }; `$env:PI_TEST_VERSION }") 0 'plugin skipped'
foreach ($version in @('0.88.0', '0.99.2', '1.2.0')) {
Check 'pi.ps1' ($piSetup+"`n`$env:PI_TEST_VERSION='$version'") 0 'lmm-pi-provider\|git:github.com/TokenNotIncluded/pi-lmm-provider'
}
Check 'pi.ps1' ($piSetup+"`nfunction official-pi { if (`$args[0] -ne '--version') { throw 'plugin must not run' }; `$global:LASTEXITCODE=8 }") 8 ''
Check 'pi.ps1' ($piSetup+"`nfunction npm.cmd { Write-Output plugin-failed; `$global:LASTEXITCODE=7 }") 7 'plugin-failed'
Check 'pi.ps1' "function Invoke-RestMethod { throw 'download-failed' }" 1 'download-failed'
Expand Down
17 changes: 11 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_pi_delegates_to_official_installer_and_uses_its_environment(self):
self.assertEqual(self.calls(),[
['curl',['-fsSL','https://pi.dev/install.sh']],
['official-pi',['--version']],
['npm',['exec','--yes','--package=@tokennotincluded/pi-lmm-provider@0.1.0-alpha.2','--','lmm-pi-provider','npm:@tokennotincluded/pi-lmm-provider@0.1.0-alpha.2']],
['npm',['exec','--yes','--package=@tokennotincluded/pi-lmm-provider@alpha','--','lmm-pi-provider','git:github.com/TokenNotIncluded/pi-lmm-provider']],
])

def test_pi_official_failure_or_cancellation_stops_plugin(self):
Expand All @@ -118,11 +118,16 @@ def test_pi_official_failure_or_cancellation_stops_plugin(self):
self.assertTrue(all(name=='curl' for name,_ in self.calls()))
shutil.rmtree(self.home/"official pi's bin")

def test_pi_unsupported_host_is_not_downgraded_for_plugin(self):
result=self.run_script('pi.sh',PI_VERSION='0.88.0')
self.assertEqual(result.returncode,0,result.stderr)
self.assertIn('plugin skipped',result.stderr)
self.assertEqual([name for name,_ in self.calls()],['curl','official-pi'])
def test_pi_latest_and_future_hosts_always_install_current_plugin(self):
for version in ('0.88.0', '0.99.2', '1.2.0'):
with self.subTest(version=version):
result=self.run_script('pi.sh',PI_VERSION=version)
self.assertEqual(result.returncode,0,result.stderr)
self.assertNotIn('plugin skipped',result.stderr)
self.assertEqual([name for name,_ in self.calls()],['curl','official-pi','npm'])
self.assertEqual(self.calls()[-1][1][-1], 'git:github.com/TokenNotIncluded/pi-lmm-provider')
shutil.rmtree(self.home/"official pi's bin")
self.log.write_text('')

def test_pi_version_and_plugin_failures_propagate(self):
for env in ({'PI_VERSION_EXIT':'8'},{'NPM_EXIT':'7'}):
Expand Down
Loading