Skip to content
Draft
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
2 changes: 1 addition & 1 deletion codewhale.mjs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createRequire } from 'node:module';
import { createInterface } from 'node:readline/promises';
import { pathToFileURL } from 'node:url';

export const PROVIDER_REV = '2b0d6b22af069ac8685dd677d99dbbfd2340514e';
export const PROVIDER_REV = 'e34e356ab7e815b24e89bab05688b3404d2cc638';
export const PROVIDER_URL = `https://github.com/TokenNotIncluded/codewhale-lmm-provider/archive/${PROVIDER_REV}.tar.gz`;
const require = createRequire(import.meta.url);
const actions = ['setup', 'install', 'login', 'run', 'models', 'status', 'balance', 'usage', 'logout', 'doctor', 'menu', 'help'];
Expand Down
4 changes: 2 additions & 2 deletions codewhale.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ try {
$work = Join-Path ([IO.Path]::GetTempPath()) ('lmm-codewhale-' + [guid]::NewGuid())
New-Item -ItemType Directory -Path $work | Out-Null
$helper = Join-Path $work 'codewhale.mjs'
Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/TokenNotIncluded/lmm-scripts/967563d3e00a53c9deaddb7276247407935598ad/codewhale.mjs' -OutFile $helper
if ((Get-FileHash -LiteralPath $helper -Algorithm SHA256).Hash -ne 'e30adefd8b94d9806a437a98b9c669759c1c13e78a50485b43e68f98b854d2f7') {
Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/TokenNotIncluded/lmm-scripts/19e058e4760e130fb1c42d83ac4e2c8dc731fc4b/codewhale.mjs' -OutFile $helper
if ((Get-FileHash -LiteralPath $helper -Algorithm SHA256).Hash -ne '501ec67693bb133309b953c24716ab85e6ac3b7001de52c2f4fc0474b7ea9826') {
throw 'Codewhale setup script checksum mismatch; nothing was executed.'
}
}
Expand Down
4 changes: 2 additions & 2 deletions codewhale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ temp_root=${TMPDIR:-/tmp}
if [[ -n ${TERMUX_VERSION:-} || ${PREFIX:-} == */com.termux/files/usr ]]; then temp_root=${TMPDIR:-${PREFIX:-/data/data/com.termux/files/usr}/tmp}; fi
work=$(mktemp -d "$temp_root/lmm-codewhale.XXXXXX")
trap 'rm -rf -- "$work"' EXIT
curl --proto '=https' --proto-redir '=https' -fsSL 'https://raw.githubusercontent.com/TokenNotIncluded/lmm-scripts/967563d3e00a53c9deaddb7276247407935598ad/codewhale.mjs' -o "$work/codewhale.mjs"
node -e 'const fs=require("node:fs"),crypto=require("node:crypto");if(crypto.createHash("sha256").update(fs.readFileSync(process.argv[1])).digest("hex")!==process.argv[2]){console.error("Codewhale setup script checksum mismatch; nothing was executed.");process.exit(1)}' "$work/codewhale.mjs" 'e30adefd8b94d9806a437a98b9c669759c1c13e78a50485b43e68f98b854d2f7'
curl --proto '=https' --proto-redir '=https' -fsSL 'https://raw.githubusercontent.com/TokenNotIncluded/lmm-scripts/19e058e4760e130fb1c42d83ac4e2c8dc731fc4b/codewhale.mjs' -o "$work/codewhale.mjs"
node -e 'const fs=require("node:fs"),crypto=require("node:crypto");if(crypto.createHash("sha256").update(fs.readFileSync(process.argv[1])).digest("hex")!==process.argv[2]){console.error("Codewhale setup script checksum mismatch; nothing was executed.");process.exit(1)}' "$work/codewhale.mjs" '501ec67693bb133309b953c24716ab85e6ac3b7001de52c2f4fc0474b7ea9826'
node "$work/codewhale.mjs" "$@"
32 changes: 24 additions & 8 deletions dsh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@ $ErrorActionPreference = 'Stop'
if ($args.Count) { throw 'Usage: .\dsh.ps1 [-Profile name]' }
npm.cmd install -g @deepseek-ai/dsh@latest pnpm@latest
if ($LASTEXITCODE) { exit $LASTEXITCODE }
$response = Invoke-WebRequest -UseBasicParsing -Method Head -Uri 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/latest'
$finalUri = $response.BaseResponse.ResponseUri
if (-not $finalUri) { $finalUri = $response.BaseResponse.RequestMessage.RequestUri }
$url = [Uri]$finalUri
if (-not $url -or $url.Scheme -ne 'https' -or $url.Host -ne 'github.com' -or -not $url.IsDefaultPort -or $url.UserInfo -or $url.Query -or $url.Fragment -or $url.AbsolutePath -notmatch '^/TokenNotIncluded/dsh-lmm-provider/releases/tag/([a-zA-Z0-9][a-zA-Z0-9._-]*)$') { throw 'Unexpected plugin release URL' }
$pluginUrl = 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/' + $Matches[1] + '/dsh-lmm-provider.tgz'
dsh.cmd plugin --profile $Profile add $pluginUrl --ignore-scripts
exit $LASTEXITCODE
$dshRoot = $env:DSH_HOME
if ([string]::IsNullOrWhiteSpace($dshRoot)) { $dshRoot = Join-Path $HOME '.dsh' }
elseif ($dshRoot -match '^~([\\/]|$)') { $dshRoot = Join-Path $HOME $dshRoot.Substring(1).TrimStart('/','\') }
$cache = Join-Path $dshRoot 'lmm-provider-packages'
New-Item -ItemType Directory -Path $cache -Force | Out-Null
$info = Get-Item -LiteralPath $cache -Force
if (-not $info.PSIsContainer -or ($info.Attributes -band [IO.FileAttributes]::ReparsePoint)) { throw 'Unsafe DSH cache' }
$cache = $info.FullName
$expected = '21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1'
$plugin = Join-Path $cache ($expected + '.tgz')
$work = Join-Path $cache ('.download-' + [guid]::NewGuid())
New-Item -ItemType Directory -Path $work | Out-Null
try {
$download = Join-Path $work 'plugin.tgz'
Invoke-WebRequest -UseBasicParsing 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/v0.1.0-alpha.9/dsh-lmm-provider.tgz' -OutFile $download
if ((Get-FileHash -LiteralPath $download -Algorithm SHA256).Hash -ne $expected) { throw 'DSH checksum mismatch.' }
if (-not (Test-Path -LiteralPath $plugin)) { [IO.File]::Move($download, $plugin) }
$info = Get-Item -LiteralPath $plugin -Force
if ($info.PSIsContainer -or ($info.Attributes -band [IO.FileAttributes]::ReparsePoint) -or (Get-FileHash -LiteralPath $plugin -Algorithm SHA256).Hash -ne $expected) { throw 'DSH checksum mismatch.' }
dsh.cmd plugin --profile $Profile add $plugin --ignore-scripts
exit $LASTEXITCODE
} finally {
Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue
}
24 changes: 14 additions & 10 deletions dsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
set -euo pipefail
[[ $# -le 1 && ${1:-web} =~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]] || { echo 'Usage: bash dsh.sh [profile]' >&2; exit 2; }
npm install -g @deepseek-ai/dsh@latest pnpm@latest
# Resolve the current built release rather than installing an unbuilt Git checkout
# or a cached npm preview package. A versioned asset URL also refreshes pnpm's source.
release_url=$(curl -fsSLI -o /dev/null -w '%{url_effective}' https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/latest)
plugin_url=$(node --input-type=module -e '
const url=new URL(process.argv[1]);
const prefix="/TokenNotIncluded/dsh-lmm-provider/releases/tag/", tag=url.pathname.slice(prefix.length);
if(url.origin!=="https://github.com" || url.username || url.password || url.search || url.hash || !url.pathname.startsWith(prefix) || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(tag)) throw Error("Unexpected plugin release URL");
console.log("https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/"+tag+"/dsh-lmm-provider.tgz");
' "$release_url")
dsh plugin --profile "${1:-web}" add "$plugin_url" --ignore-scripts
cache=$(node -e '
const fs=require("node:fs"),os=require("node:os"),p=require("node:path");let h=process.env.DSH_HOME;if(!h?.trim())h=p.join(os.homedir(),".dsh");else if(/^~(?:[\\/]|$)/.test(h))h=p.join(os.homedir(),h.slice(2));
const dir=p.resolve(h,"lmm-provider-packages");fs.mkdirSync(dir,{recursive:true,mode:0o700});const s=fs.lstatSync(dir);if(!s.isDirectory()||s.isSymbolicLink()||s.uid!==process.getuid()||(s.mode&0o022))throw Error("Unsafe DSH cache");console.log(fs.realpathSync(dir));
')
sha='21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1'
plugin="$cache/$sha.tgz"
work=$(mktemp -d "$cache/.download.XXXXXX")
trap 'rm -rf -- "$work"' EXIT
curl --proto '=https' --proto-redir '=https' -fsSL 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/v0.1.0-alpha.9/dsh-lmm-provider.tgz' -o "$work/plugin.tgz"
node -e '
const fs=require("node:fs"),crypto=require("node:crypto"),[source,target,sha]=process.argv.slice(1);const check=path=>{const s=fs.lstatSync(path);if(!s.isFile()||s.isSymbolicLink()||s.uid!==process.getuid()||(s.mode&0o022)||crypto.createHash("sha256").update(fs.readFileSync(path)).digest("hex")!==sha)throw Error("DSH checksum mismatch.");};
check(source);fs.chmodSync(source,0o600);try{fs.linkSync(source,target);}catch(error){if(error.code!=="EEXIST")throw error;}check(target);
' "$work/plugin.tgz" "$plugin" "$sha"
dsh plugin --profile "${1:-web}" add "$plugin" --ignore-scripts
2 changes: 1 addition & 1 deletion test-codewhale.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ process.exit(Number(process.env.TEST_CURL_EXIT||0));\n`;
const result = f.runShell('--help');
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Codewhale \+ LMM/);
assert.ok(f.calls()[0][1].some(arg => /967563d3e00a53c9deaddb7276247407935598ad\/codewhale.mjs/.test(arg)));
assert.ok(f.calls()[0][1].some(arg => /19e058e4760e130fb1c42d83ac4e2c8dc731fc4b\/codewhale.mjs/.test(arg)));
});
test('truncated downloads fail before execution even when bytes were written', t => {
const f = shellFixture(t); f.env.TEST_BAD_DOWNLOAD = '1'; f.env.TEST_CURL_EXIT = '18';
Expand Down
46 changes: 40 additions & 6 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,48 @@ function npm.cmd { Write-Output 'npm failed'; $global:LASTEXITCODE=9 }
function dsh.cmd { throw 'plugin must not run' }
'@
Check 'dsh.ps1' $npmFailure 9 'npm failed'
$npmSuccess = @'
$dshTestRoot = Join-Path ([IO.Path]::GetTempPath()) ('lmm-dsh-tests-' + [guid]::NewGuid())
New-Item -ItemType Directory -Path $dshTestRoot | Out-Null
try {
$npmSuccess = @'
# Load built-in functions before registering the checksum mock.
Import-Module Microsoft.PowerShell.Utility
function npm.cmd { Write-Output ($args -join '|'); $global:LASTEXITCODE=0 }
function dsh.cmd { Write-Output ($args -join '|'); $global:LASTEXITCODE=0 }
function Invoke-WebRequest { param($Uri,$Method,[switch]$UseBasicParsing) if ($Uri -ne 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/latest' -or $Method -ne 'Head') { throw 'wrong release URL' }; return [pscustomobject]@{BaseResponse=[pscustomobject]@{ResponseUri=[Uri]'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/tag/v0.1.0-alpha.5'}} }
function dsh.cmd {
if ($args[4] -notmatch '[\\/]21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1\.tgz$' -or -not (Test-Path -LiteralPath $args[4] -PathType Leaf)) { throw 'verified persistent package is missing' }
Write-Output ($args -join '|'); $global:LASTEXITCODE=0
}
function Invoke-WebRequest {
param($Uri,$OutFile,[switch]$UseBasicParsing)
if ($Uri -ne 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/v0.1.0-alpha.9/dsh-lmm-provider.tgz') { throw 'wrong pinned release URL' }
[IO.File]::WriteAllText($OutFile,'fixture')
}
function Get-FileHash {
param($LiteralPath,$Algorithm)
if ($Algorithm -ne 'SHA256') { throw 'wrong digest algorithm' }
# This mock maps only known fixture bytes; production still uses Get-FileHash.
$digest = if ([IO.File]::ReadAllText($LiteralPath) -eq 'fixture') { '21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1' } else { 'invalid' }
[pscustomobject]@{Hash=$digest}
}
$hashCommand = Get-Command Get-FileHash
if ($hashCommand.CommandType -ne 'Function' -or $hashCommand.ModuleName) { throw 'checksum fixture mock was not selected' }
'@
Check 'dsh.ps1' $npmSuccess 0 'plugin\|--profile\|headless.*releases/download/v0.1.0-alpha.5/dsh-lmm-provider.tgz' '-Profile headless'
Check 'dsh.ps1' ($npmSuccess+"`nfunction Invoke-WebRequest { throw 'missing-release' }") 1 'missing-release'
Check 'dsh.ps1' ($npmSuccess+"`nfunction Invoke-WebRequest { [pscustomobject]@{BaseResponse=[pscustomobject]@{ResponseUri=[Uri]'https://evil.invalid/plugin.tgz'}} }") 1 'Unexpected plugin release URL'
$npmSuccess = "`$env:DSH_HOME='" + $dshTestRoot.Replace("'","''") + "'`n" + $npmSuccess
Check 'dsh.ps1' $npmSuccess 0 'plugin\|--profile\|headless\|add\|.*\.tgz\|--ignore-scripts' '-Profile headless'
$cachedPackage = Join-Path (Join-Path $dshTestRoot 'lmm-provider-packages') '21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1.tgz'
if ([IO.File]::ReadAllText($cachedPackage) -ne 'fixture') { throw 'package must survive installation for profile updates' }
Check 'dsh.ps1' ($npmSuccess+"`nfunction Invoke-WebRequest { throw 'missing-release' }") 1 'missing-release'
Check 'dsh.ps1' ($npmSuccess+"`nfunction Invoke-WebRequest { param(`$Uri,`$OutFile,[switch]`$UseBasicParsing) [IO.File]::WriteAllText(`$OutFile,'altered') }") 1 'checksum mismatch'
Check 'dsh.ps1' ($npmSuccess+"`nfunction Invoke-WebRequest { param(`$Uri,`$OutFile,[switch]`$UseBasicParsing) [IO.File]::WriteAllText(`$OutFile,'fixture'); throw 'truncated-download' }") 1 'truncated-download'
Check 'dsh.ps1' ($npmSuccess+"`nfunction dsh.cmd { Write-Output 'plugin-failed'; `$global:LASTEXITCODE=17 }") 17 'plugin-failed'
if ([IO.File]::ReadAllText($cachedPackage) -ne 'fixture') { throw 'verified package lost after plugin failure' }
[IO.File]::WriteAllText($cachedPackage,'changed')
Check 'dsh.ps1' $npmSuccess 1 'checksum mismatch'
if ([IO.File]::ReadAllText($cachedPackage) -ne 'changed') { throw 'corrupt package was overwritten' }
if (@(Get-ChildItem -LiteralPath (Join-Path $dshTestRoot 'lmm-provider-packages') -Force -Filter '.download-*').Count) { throw 'temporary download was not cleaned' }
} finally {
Remove-Item -LiteralPath $dshTestRoot -Recurse -Force -ErrorAction SilentlyContinue
}
$upstream = @'
function Invoke-RestMethod { return 'param([string]$Version) Write-Output "upstream:$Version"' }
'@
Expand Down
81 changes: 74 additions & 7 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Offline command-contract tests. No packages are installed."""
import json
import hashlib
import os
from pathlib import Path
import sys
Expand All @@ -9,6 +10,9 @@
import unittest

ROOT = Path(__file__).resolve().parent
DSH_SHA256 = '21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1'
DSH_FIXTURE_SHA256 = hashlib.sha256(b'fixture').hexdigest()
DSH_URL = 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/v0.1.0-alpha.9/dsh-lmm-provider.tgz'
STUB = r'''#!/usr/bin/env python3
import json, os, sys
from pathlib import Path
Expand Down Expand Up @@ -39,9 +43,11 @@
print('printf "%s\\n" "$@" > "$HOME/received-args"')
elif url.endswith('/desktop.sh'):
print(Path(os.environ['PROJECT'], 'desktop.sh').read_text())
elif url == 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/latest':
elif '/TokenNotIncluded/dsh-lmm-provider/releases/' in url:
assert url == 'https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/v0.1.0-alpha.9/dsh-lmm-provider.tgz'
if os.environ.get('NO_ASSET'): sys.exit(22)
print(os.environ.get('DSH_ASSET_URL','https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/tag/v0.1.0-alpha.5'))
Path(args[args.index('-o')+1]).write_bytes(b'altered' if os.environ.get('DSH_BAD_BYTES') else b'fixture')
if os.environ.get('DSH_TRUNCATED'): sys.exit(18)
elif '/releases/latest' in url:
print(json.dumps({'assets': [] if os.environ.get('NO_ASSET') else [
{'name': 'Tool-amd64.deb', 'browser_download_url': 'https://github.com/official/tool.deb'},
Expand Down Expand Up @@ -99,7 +105,16 @@ def stub(self,name):
path.chmod(0o755)

def run_script(self,name,*args,**env):
return subprocess.run([shutil.which('bash'),str(ROOT/name),*args],env=self.env|env,text=True,capture_output=True,timeout=10)
script=ROOT/name
if name=='dsh.sh':
# Only this offline copy substitutes the expected hash for fixture bytes.
text=script.read_text()
self.assertEqual(text.count(DSH_SHA256),1)
self.assertIn(DSH_URL,text)
script=self.home/'dsh.sh'
script.write_text(text.replace(DSH_SHA256,DSH_FIXTURE_SHA256))
env={'DSH_HOME':str(self.home/'dsh'),**env}
return subprocess.run([shutil.which('bash'),str(script),*args],env=self.env|env,text=True,capture_output=True,timeout=10)

def calls(self):
return [json.loads(line) for line in self.log.read_text().splitlines()]
Expand Down Expand Up @@ -150,17 +165,69 @@ def test_pi_termux_dependency_failure_stops_before_official_bootstrap(self):
self.assertEqual(self.calls(),[['pkg',['install','nodejs','npm','git']]])

def test_dsh_keeps_documented_commands_and_lmm_plugin(self):
self.assertEqual(self.run_script('dsh.sh','headless').returncode,0)
result=self.run_script('dsh.sh','headless')
self.assertEqual(result.returncode,0,result.stderr)
self.assertEqual(self.calls()[0], ['npm',['install','-g','@deepseek-ai/dsh@latest','pnpm@latest']])
self.assertEqual(self.calls()[-1], ['dsh',['plugin','--profile','headless','add','https://github.com/TokenNotIncluded/dsh-lmm-provider/releases/download/v0.1.0-alpha.5/dsh-lmm-provider.tgz','--ignore-scripts']])
package=self.home/'dsh/lmm-provider-packages'/(DSH_FIXTURE_SHA256+'.tgz')
self.assertEqual(self.calls()[-1], ['dsh',['plugin','--profile','headless','add',str(package.resolve()),'--ignore-scripts']])
self.assertEqual(package.read_bytes(),b'fixture')
self.assertEqual(package.stat().st_mode & 0o777,0o600)
self.assertEqual(list(package.parent.glob('.download.*')),[])
download=next(args for name,args in self.calls() if name=='curl')
self.assertIn(DSH_URL,download)
self.assertIn('--proto-redir',download)
# A second install must reuse the same verified persistent file.
self.assertEqual(self.run_script('dsh.sh','headless').returncode,0)
self.assertEqual(package.read_bytes(),b'fixture')
self.assertEqual(list(package.parent.glob('.download.*')),[])

def test_dsh_missing_release_does_not_install_plugin(self):
self.assertNotEqual(self.run_script('dsh.sh',NO_ASSET='1').returncode,0)
self.assertTrue(all(name!='dsh' for name,_ in self.calls()))

def test_dsh_rejects_foreign_release_urls(self):
self.assertNotEqual(self.run_script('dsh.sh',DSH_ASSET_URL='https://evil.invalid/plugin.tgz').returncode,0)
def test_dsh_rejects_altered_release_bytes(self):
result=self.run_script('dsh.sh',DSH_BAD_BYTES='1')
self.assertNotEqual(result.returncode,0)
self.assertIn('checksum mismatch',result.stderr)
self.assertTrue(all(name!='dsh' for name,_ in self.calls()))
self.assertEqual(list((self.home/'dsh/lmm-provider-packages').iterdir()),[])

def test_dsh_truncated_download_never_installs_or_retains_package(self):
self.assertEqual(self.run_script('dsh.sh',DSH_TRUNCATED='1').returncode,18)
self.assertTrue(all(name!='dsh' for name,_ in self.calls()))
self.assertEqual(list((self.home/'dsh/lmm-provider-packages').iterdir()),[])

def test_dsh_corrupt_cached_package_is_not_replaced_or_installed(self):
cache=self.home/'dsh/lmm-provider-packages'
cache.mkdir(parents=True,mode=0o700)
package=cache/(DSH_FIXTURE_SHA256+'.tgz')
package.write_bytes(b'changed')
result=self.run_script('dsh.sh')
self.assertNotEqual(result.returncode,0)
self.assertIn('checksum mismatch',result.stderr)
self.assertEqual(package.read_bytes(),b'changed')
self.assertTrue(all(name!='dsh' for name,_ in self.calls()))
self.assertEqual(list(cache.glob('.download.*')),[])

def test_dsh_cache_symlink_is_rejected_before_download(self):
target=self.home/'foreign'
target.mkdir(mode=0o700)
(self.home/'dsh').mkdir()
(self.home/'dsh/lmm-provider-packages').symlink_to(target,target_is_directory=True)
self.assertNotEqual(self.run_script('dsh.sh').returncode,0)
self.assertEqual([name for name,_ in self.calls()],['npm'])
self.assertEqual(list(target.iterdir()),[])

def test_dsh_plugin_failure_retains_verified_file_and_exit_status(self):
self.assertEqual(self.run_script('dsh.sh',COMMAND_EXIT='17').returncode,17)
package=self.home/'dsh/lmm-provider-packages'/(DSH_FIXTURE_SHA256+'.tgz')
self.assertEqual(package.read_bytes(),b'fixture')
self.assertEqual(list(package.parent.glob('.download.*')),[])

def test_dsh_invalid_profiles_stop_before_host_install(self):
for args in [('../bad',),('two words',),('--help',),('web','extra')]:
self.assertEqual(self.run_script('dsh.sh',*args).returncode,2)
self.assertEqual(self.calls(),[])

def test_npm_failure_never_installs_plugin(self):
self.assertEqual(self.run_script('dsh.sh',NPM_EXIT='9').returncode,9)
Expand Down
Loading