From 8665a115c1b985804f03bd7c4570e74a9ab1f244 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 20 Nov 2026 20:20:50 +0800 Subject: [PATCH 1/5] fix: pin Codewhale installer to verified provider revision Use provider 81a51a4 after its original unit, host, and Windows environment workflows passed. Keep installer behavior and all workflow definitions unchanged. --- codewhale.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 codewhale.mjs diff --git a/codewhale.mjs b/codewhale.mjs old mode 100755 new mode 100644 index 0637800..cff5290 --- a/codewhale.mjs +++ b/codewhale.mjs @@ -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 = '81a51a427404ee94abf7b76d414a21505632ff2e'; 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']; From 452efac0f1698676060605f10a9e4705b487e6ba Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 20 Nov 2026 20:50:28 +0800 Subject: [PATCH 2/5] fix: synchronize Codewhale bootstrap helper pins Pin both launchers to the already published 8665 helper and its verified SHA256 after the provider revision update. Keep strict download and checksum refusal tests, and update their exact immutable URL expectation. --- codewhale.ps1 | 4 ++-- codewhale.sh | 4 ++-- test-codewhale.mjs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/codewhale.ps1 b/codewhale.ps1 index 7daa867..8126b51 100644 --- a/codewhale.ps1 +++ b/codewhale.ps1 @@ -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/8665a115c1b985804f03bd7c4570e74a9ab1f244/codewhale.mjs' -OutFile $helper + if ((Get-FileHash -LiteralPath $helper -Algorithm SHA256).Hash -ne '24cdb19db5b3ddc3187a6deaa59265e18a710e19b94170d34a361a0bf5fb0b16') { throw 'Codewhale setup script checksum mismatch; nothing was executed.' } } diff --git a/codewhale.sh b/codewhale.sh index 8b3f517..df68721 100755 --- a/codewhale.sh +++ b/codewhale.sh @@ -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/8665a115c1b985804f03bd7c4570e74a9ab1f244/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" '24cdb19db5b3ddc3187a6deaa59265e18a710e19b94170d34a361a0bf5fb0b16' node "$work/codewhale.mjs" "$@" diff --git a/test-codewhale.mjs b/test-codewhale.mjs index f314717..f74ac12 100644 --- a/test-codewhale.mjs +++ b/test-codewhale.mjs @@ -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 => /8665a115c1b985804f03bd7c4570e74a9ab1f244\/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'; From 19e058e4760e130fb1c42d83ac4e2c8dc731fc4b Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 20 Nov 2026 22:14:41 +0800 Subject: [PATCH 3/5] chore(install): prepare verified provider release pins [skip ci] Intermediate review commit makes the new Codewhale helper address immutable. The next commit must bind both bootstraps and their expected SHA before the original installer gates run. DSH uses the verified alpha.9 release with a persistent checked package for subsequent host updates. --- codewhale.mjs | 2 +- dsh.ps1 | 32 +++++++++++++++----- dsh.sh | 24 ++++++++------- test.ps1 | 42 ++++++++++++++++++++++---- test.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 149 insertions(+), 32 deletions(-) diff --git a/codewhale.mjs b/codewhale.mjs index cff5290..52a33f5 100644 --- a/codewhale.mjs +++ b/codewhale.mjs @@ -7,7 +7,7 @@ import { createRequire } from 'node:module'; import { createInterface } from 'node:readline/promises'; import { pathToFileURL } from 'node:url'; -export const PROVIDER_REV = '81a51a427404ee94abf7b76d414a21505632ff2e'; +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']; diff --git a/dsh.ps1 b/dsh.ps1 index 0d2a59f..f00f557 100644 --- a/dsh.ps1 +++ b/dsh.ps1 @@ -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 +} diff --git a/dsh.sh b/dsh.sh index 89e1aca..5517d37 100755 --- a/dsh.sh +++ b/dsh.sh @@ -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 diff --git a/test.ps1 b/test.ps1 index 0c36d4b..994c38e 100644 --- a/test.ps1 +++ b/test.ps1 @@ -54,14 +54,44 @@ 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 = @' 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} +} '@ -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"' } '@ diff --git a/test.py b/test.py index 6aef97f..b40aa5d 100644 --- a/test.py +++ b/test.py @@ -1,5 +1,6 @@ """Offline command-contract tests. No packages are installed.""" import json +import hashlib import os from pathlib import Path import sys @@ -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 @@ -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'}, @@ -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()] @@ -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),'--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) From 104c0ab84a65d21d8b909149cc0b89d960d11c50 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 20 Nov 2026 22:31:21 +0800 Subject: [PATCH 4/5] fix(install): bind released providers to verified package and helper Complete both Codewhale bootstraps with the real helper commit and checksum for alpha.4. DSH installs the verified alpha.9 release archive into a persistent content-addressed path. Preserve original installer errors, host commands, cross-platform tests and workflow budgets. --- codewhale.ps1 | 4 ++-- codewhale.sh | 4 ++-- test-codewhale.mjs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/codewhale.ps1 b/codewhale.ps1 index 8126b51..b42bc1e 100644 --- a/codewhale.ps1 +++ b/codewhale.ps1 @@ -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/8665a115c1b985804f03bd7c4570e74a9ab1f244/codewhale.mjs' -OutFile $helper - if ((Get-FileHash -LiteralPath $helper -Algorithm SHA256).Hash -ne '24cdb19db5b3ddc3187a6deaa59265e18a710e19b94170d34a361a0bf5fb0b16') { + 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.' } } diff --git a/codewhale.sh b/codewhale.sh index df68721..ff550ea 100755 --- a/codewhale.sh +++ b/codewhale.sh @@ -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/8665a115c1b985804f03bd7c4570e74a9ab1f244/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" '24cdb19db5b3ddc3187a6deaa59265e18a710e19b94170d34a361a0bf5fb0b16' +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" "$@" diff --git a/test-codewhale.mjs b/test-codewhale.mjs index f74ac12..c35e056 100644 --- a/test-codewhale.mjs +++ b/test-codewhale.mjs @@ -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 => /8665a115c1b985804f03bd7c4570e74a9ab1f244\/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'; From abde4ef2bdd5f9f42cf5d4397d9109fab49fbcd1 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Fri, 20 Nov 2026 22:55:02 +0800 Subject: [PATCH 5/5] test(install): bind DSH fixtures to real paths and explicit checksum mock Use the resolved persistent package path in the macOS-capable fixture, preserving file content and permission assertions. Load PowerShell Utility before registering its replacement test function and verify command selection, so the original checksum guard is exercised through the intended mock. Keep all runtime scripts, release digests, original assertions and workflow budgets unchanged. The original failed runs remain evidence; PowerShell 5.1 is to be verified by the original PR workflow. --- test.ps1 | 4 ++++ test.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test.ps1 b/test.ps1 index 994c38e..95fec69 100644 --- a/test.ps1 +++ b/test.ps1 @@ -58,6 +58,8 @@ $dshTestRoot = Join-Path ([IO.Path]::GetTempPath()) ('lmm-dsh-tests-' + [guid]:: 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 { if ($args[4] -notmatch '[\\/]21bc853b321906550cf529cecc83719e6d14fd70041cc7cb92e4aecd6316d3f1\.tgz$' -or -not (Test-Path -LiteralPath $args[4] -PathType Leaf)) { throw 'verified persistent package is missing' } @@ -75,6 +77,8 @@ function 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' } '@ $npmSuccess = "`$env:DSH_HOME='" + $dshTestRoot.Replace("'","''") + "'`n" + $npmSuccess Check 'dsh.ps1' $npmSuccess 0 'plugin\|--profile\|headless\|add\|.*\.tgz\|--ignore-scripts' '-Profile headless' diff --git a/test.py b/test.py index b40aa5d..cb2377e 100644 --- a/test.py +++ b/test.py @@ -169,7 +169,7 @@ def test_dsh_keeps_documented_commands_and_lmm_plugin(self): self.assertEqual(result.returncode,0,result.stderr) self.assertEqual(self.calls()[0], ['npm',['install','-g','@deepseek-ai/dsh@latest','pnpm@latest']]) package=self.home/'dsh/lmm-provider-packages'/(DSH_FIXTURE_SHA256+'.tgz') - self.assertEqual(self.calls()[-1], ['dsh',['plugin','--profile','headless','add',str(package),'--ignore-scripts']]) + 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.*')),[])