okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8a11d125d
main
1"""fetch-node.ps1 (Windows) and fetch-node.sh pin the same Node archive digest, and the PowerShell 2script refuses a download that does not match it.""" 3 4from __future__import annotations 5 6import os 7import re 8import shutil 9import subprocess 10import tempfile 11import unittest 12import zipfile 13from pathlib import Path 14 15SCRIPTS = Path (__file__ ).resolve ().parents [2 ]/ "apps" / "desktop" / "scripts" 16POWERSHELL = shutil .which ("powershell" )or shutil .which ("pwsh" ) 17 18 19class PinTests (unittest .TestCase ): 20def test_both_scripts_pin_the_same_windows_digest_and_version (self ): 21sh = (SCRIPTS / "fetch-node.sh" ).read_text () 22ps = (SCRIPTS / "fetch-node.ps1" ).read_text () 23sh_digest = re .search (r'win-x64\)\s+echo "([0-9a-f]{64})"' ,sh ).group (1 ) 24ps_digest = re .search (r"\$Expected = '([0-9a-f]{64})'" ,ps ).group (1 ) 25self .assertEqual (sh_digest ,ps_digest ) 26self .assertEqual (re .search (r'STRATA_NODE_VERSION:-([\d.]+)' ,sh ).group (1 ), 27re .search (r"else \{ '([\d.]+)' \}" ,ps ).group (1 )) 28 29 30@ unittest . skipUnless ( os . name == "nt" and POWERSHELL , "Windows PowerShell" ) 31class PowerShellTests (unittest .TestCase ): 32def run_script (self ,* args ): 33return subprocess .run ([POWERSHELL ,"-NoProfile" ,"-ExecutionPolicy" ,"Bypass" ,"-File" , 34str (SCRIPTS / "fetch-node.ps1" ),* args ], 35capture_output = True ,text = True ,timeout = 120 ) 36 37def test_a_zip_with_the_wrong_digest_is_refused_and_nothing_is_installed (self ): 38with tempfile .TemporaryDirectory ()as directory : 39archive = Path (directory )/ "node.zip" 40with zipfile .ZipFile (archive ,"w" )as bundle : 41bundle .writestr ("node-v24.12.0-win-x64/node.exe" ,b"not node" ) 42dest = Path (directory )/ "out" 43result = self .run_script ("-FromFile" ,str (archive ),"-Dest" ,str (dest )) 44self .assertEqual (result .returncode ,1 ,result .stdout + result .stderr ) 45self .assertIn ("REFUSING" ,result .stderr ) 46self .assertFalse ((dest / "node.exe" ).exists ()) 47 48def test_check_reports_a_missing_runtime (self ): 49with tempfile .TemporaryDirectory ()as directory : 50result = self .run_script ("-Check" ,"-Dest" ,directory ) 51self .assertEqual (result .returncode ,1 ) 52self .assertIn ("not installed" ,result .stderr ) 53 54 55if __name__ == "__main__" : 56unittest .main ()