okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cd9745050
main
1"""install.ps1 / install.sh: an ARM computer is refused with the reason and the way out; the Windows script survives the usual environment trouble.""" 2 3import os 4import shutil 5import subprocess 6import unittest 7from pathlib import Path 8 9ROOT = Path (__file__ ).resolve ().parents [2 ] 10PS1 = ROOT / "packaging" / "install.ps1" 11SH = ROOT / "packaging" / "install.sh" 12 13 14class Text (unittest .TestCase ): 15def test_the_readme_one_liner_cannot_succeed_on_a_failed_download (self ): 16for name in ("README.md" ,"README.de.md" ,"docs/INSTALL.md" ,"docs/TERMINAL_LAUNCH.md" ): 17text = (ROOT / name ).read_text (encoding = "utf-8" ) 18self .assertNotIn ("install.sh | sh" ,text ,name )# `curl ... | sh` runs nothing and exits 0 when curl fails 19self .assertIn ("install.sh -o install.sh && sh install.sh" ,text ,name ) 20 21def setUp (self ): 22self .ps1 = PS1 .read_text (encoding = "utf-8" ) 23self .sh = SH .read_text (encoding = "utf-8" ) 24 25def test_arm_is_refused_with_a_reason_and_a_next_step (self ): 26self .assertIn ("Windows on ARM PC" ,self .ps1 ) 27self .assertIn ("no engine for ARM" ,self .ps1 ) 28self .assertNotIn ("has no Strata Terminal yet" ,self .ps1 ) 29self .assertIn ("NVIDIA DGX Spark" ,self .sh )# 0.2.7.1: Linux ARM64 installs the Terminal (the engine is for the Spark only) 30self .assertIn ("Apple silicon" ,self .sh ) 31 32def test_tls12_proxy_sign_in_and_the_real_error_text (self ): 33self .assertIn ("Tls12" ,self .ps1 ) 34self .assertIn ("DefaultNetworkCredentials" ,self .ps1 ) 35self .assertIn ("$($_.Exception.Message)" ,self .ps1 ) 36 37def test_long_paths_junction_and_running_version (self ): 38self .assertIn ("tar.exe" ,self .ps1 ) 39self .assertIn ("STRATA_DATA_DIR to a short folder" ,self .ps1 ) 40self .assertIn ("$LASTEXITCODE -ne 0 -or -not (Test-Path (Join-Path $current" ,self .ps1 ) 41self .assertIn ("a program is using it" ,self .ps1 ) 42self .assertIn ("Windows did not say where your user folder is" ,self .ps1 ) 43self .assertNotIn ("is the disk full?" ,self .ps1 ) 44 45 46@ unittest . skipUnless ( shutil . which ( "powershell" ), "no PowerShell" ) 47class Run (unittest .TestCase ): 48def test_native_arm_stops_before_any_download (self ): 49env = dict (os .environ ,PROCESSOR_ARCHITECTURE = "ARM64" ,STRATA_FEED = "http://127.0.0.1:9" ) 50env .pop ("PROCESSOR_ARCHITEW6432" ,None ) 51done = subprocess .run (["powershell" ,"-NoProfile" ,"-ExecutionPolicy" ,"Bypass" ,"-File" ,str (PS1 )], 52capture_output = True ,text = True ,env = env ,timeout = 120 ) 53self .assertNotEqual (done .returncode ,0 ) 54self .assertIn ("Windows on ARM PC" ,done .stderr + done .stdout ) 55self .assertNotIn ("Downloading" ,done .stdout ) 56 57 58if __name__ == "__main__" : 59unittest .main () 60 61 62@ unittest . skipUnless ( shutil . which ( "sh" ) and os . uname (). sysname in ( "Linux" , "Darwin" ) if hasattr( os , "uname" ) else False , "needs sh on Linux or macOS" ) 63class InstallShFailsVisibly (unittest .TestCase ): 64"""A broken download of install.sh must not look like a finished install.""" 65 66def run_sh (self ,text ,** env ): 67import tempfile 68with tempfile .TemporaryDirectory ()as d : 69f = Path (d )/ "install.sh" 70f .write_text (text ,encoding = "utf-8" ,newline = "\n" ) 71home = Path (d )/ "home" 72home .mkdir () 73r = subprocess .run (["sh" ,str (f )],capture_output = True ,text = True ,timeout = 120 , 74env = {** os .environ ,"HOME" :str (home ),"STRATA_DATA_DIR" :str (home / "data" ),"STRATA_BIN_DIR" :str (home / "bin" ),** env }) 75return r ,home 76 77def test_the_script_is_one_function_called_on_the_last_line (self ): 78text = SH .read_text (encoding = "utf-8" ) 79self .assertIn ("\nmain() {" ,text ) 80self .assertEqual (text .rstrip ().splitlines ()[- 1 ],'main "$@"' ) 81 82def test_syntax (self ): 83self .assertEqual (subprocess .run (["sh" ,"-n" ,str (SH )],capture_output = True ).returncode ,0 ) 84 85def test_a_half_downloaded_script_runs_nothing_and_fails (self ): 86lines = SH .read_text (encoding = "utf-8" ).splitlines (True ) 87r ,home = self .run_sh ("" .join (lines [:int (len (lines )* 0.8 )])) 88self .assertNotEqual (r .returncode ,0 ) 89self .assertFalse ((home / "data" ).exists ()or (home / "bin" ).exists ()) 90 91def hardware_line (self ,nvidia_smi ,lspci ): 92"""The 'This computer:' line install.sh prints, with fake nvidia-smi and lspci first on PATH.""" 93import tempfile 94if os .uname ().sysname != "Linux" or os .uname ().machine not in ("x86_64" ,"amd64" ): 95self .skipTest ("the line is printed for Linux x86_64 here" ) 96with tempfile .TemporaryDirectory ()as d : 97fakes = Path (d )/ "fakes" 98fakes .mkdir () 99for name ,body in (("nvidia-smi" ,nvidia_smi ), ("lspci" ,lspci )): 100 (fakes / name ).write_text ("#!/bin/sh" + chr (10 )+ (body if body is not None else "exit 1" )+ chr (10 ),encoding = "utf-8" ,newline = chr (10 )) 101 (fakes / name ).chmod (0o755 ) 102path = str (fakes )+ os .pathsep + os .environ ["PATH" ]# the fakes win over any real tool 103r ,_ = self .run_sh (SH .read_text (encoding = "utf-8" ),STRATA_FEED = "http://127.0.0.1:9" ,PATH = path ) 104return next ((l for l in r .stdout .splitlines ()if "This computer:" in l ),r .stdout + r .stderr ) 105 106def test_the_graphics_line_is_a_card_not_an_ssd_or_an_error_sentence (self ): 107if not shutil .which ("curl" )and not shutil .which ("wget" ): 108self .skipTest ("no curl or wget" ) 109lspci = ("echo '01:00.0 Non-Volatile memory controller: Sandisk Corp WD Black 3D NAND SN850X'; " 110"echo '03:00.0 Display controller: Advanced Micro Devices, Inc. [AMD/ATI] Navi 48 [Radeon AI PRO R9700]'" ) 111line = self .hardware_line (None ,lspci ) 112self .assertIn ("graphics: Advanced Micro Devices" ,line ) 113self .assertNotIn ("Sandisk" ,line ) 114broken = "echo \"NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver.\"; exit 9" 115line = self .hardware_line (broken ,"echo '00:02.0 VGA compatible controller: Intel Corporation DG2 [Arc A750]'" ) 116self .assertNotIn ("failed" ,line ) 117self .assertIn ("graphics: Intel Corporation" ,line ) 118line = self .hardware_line ("echo 'NVIDIA RTX A6000'" ,None ) 119self .assertIn ("NVIDIA RTX A6000" ,line ) 120 121def test_an_unreachable_release_folder_stops_with_a_reason_and_a_failing_exit (self ): 122if not shutil .which ("curl" )and not shutil .which ("wget" ): 123self .skipTest ("no curl or wget" ) 124r ,home = self .run_sh (SH .read_text (encoding = "utf-8" ),STRATA_FEED = "http://127.0.0.1:9" ) 125self .assertEqual (r .returncode ,1 ) 126self .assertIn ("127.0.0.1 did not answer (or this computer is offline), so the installer could not start." ,r .stderr )# lane NET W10 127self .assertFalse ((home / "bin" / "strata" ).exists ())