okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0af0f9f12
main
1"""0.2.3 RC stress test: #11 (A01b/A05) an install from an older feed shows the real reason with both sequence numbers, the folder that holds the 2old state and one next step, and the installer prints the whole cause; #12 (A04) the Windows installer unpacks into a folder whose name has 3accented letters.""" 4 5import hashlib 6import os 7import shutil 8import subprocess 9import tempfile 10import unittest 11import zipfile 12from pathlib import Path 13 14from strata_control import feed as feedmod ,updater 15from tests .terminal import test_updater 16 17ROOT = Path (__file__ ).resolve ().parents [2 ] 18INSTALL_PS1 = ROOT / "packaging" / "install.ps1" 19POWERSHELL = shutil .which ("powershell" )if os .name == "nt" else None 20 21 22class ReplayedFeedWords (test_updater .UpdaterCase ): 23def test_the_refusal_gives_both_numbers_the_folder_and_one_next_step (self ): 24self .publish (("0.1.46" ,test_updater .fx .GOOD_ENGINE ),sequence = 108 ) 25updater .check (self .ctx ())# accepts sequence 108 and remembers it 26self .publish (("0.1.46" ,test_updater .fx .GOOD_ENGINE ),sequence = 107 ) 27with self .assertRaises (feedmod .FeedDowngrade )as caught : 28updater .check (self .ctx ()) 29text = str (caught .exception ) 30self .assertIn ("older than the one already accepted" ,text ) 31self .assertIn ("its sequence is 107" ,text ) 32self .assertIn ("the accepted one is 108" ,text ) 33self .assertIn (str (self .components / ".updates" ),text ) 34self .assertIn ("state.json" ,text ) 35self .assertEqual (text .count ("Use the newest release folder" ),1 ) 36 37 38def stub_release (folder :Path ,body :str )-> str : 39folder .mkdir (parents = True ) 40archive = folder / "terminal.zip" 41with zipfile .ZipFile (archive ,"w" ,zipfile .ZIP_DEFLATED )as z : 42z .writestr ("strata-terminal-0.1.48-windows-x86_64/bin/strata.cmd" ,body ) 43z .writestr ("strata-terminal-0.1.48-windows-x86_64/strata.py" ,"# stub\n" ) 44 (folder / "install-manifest.txt" ).write_text ( 45f"windows-x86_64 0.1.48 terminal.zip { hashlib . sha256 ( archive . read_bytes ()). hexdigest () } { archive . stat (). st_size } \n" ) 46return "file:///" + folder .as_posix () 47 48 49@ unittest . skipUnless ( POWERSHELL , "the Windows installer runs only on Windows" ) 50class WindowsInstaller (unittest .TestCase ): 51def setUp (self ): 52self .temp = tempfile .TemporaryDirectory (prefix = "strata-inst-" ) 53self .addCleanup (self .temp .cleanup ) 54self .root = Path (self .temp .name ) 55 56def run_installer (self ,feed :str ,data :Path ): 57runner = self .root / "run.ps1" 58runner .write_text ("$ErrorActionPreference = 'Continue'\n" 59f"$env:STRATA_FEED = ' { feed } '; $env:STRATA_DATA_DIR = ' { data } '; $env:STRATA_NO_PATH = '1'\n" 60f"try {{ Invoke-Expression (Get-Content -Raw -LiteralPath ' { INSTALL_PS1 } ') }} catch {{ Write-Host \"STOPPED\" }}\n" , 61encoding = "utf-8-sig" ) 62done = subprocess .run ([POWERSHELL ,"-NoProfile" ,"-ExecutionPolicy" ,"Bypass" ,"-File" ,str (runner )],capture_output = True ,text = True , 63encoding = "utf-8" ,errors = "replace" ,timeout = 300 ) 64return done .stdout + done .stderr 65 66def test_a_folder_with_accented_letters_is_unpacked (self ): 67feed = stub_release (self .root / "feed" ,"@echo off\r\nexit /b 0\r\n" ) 68data = self .root / "Ünï test" 69out = self .run_installer (feed ,data ) 70self .assertIn ("Installed. Run: strata launch" ,out ,out ) 71self .assertTrue ((data / "terminal" / "0.1.48" / "bin" / "strata.cmd" ).is_file ()) 72self .assertEqual ([p .name for p in (data / "terminal" ).iterdir ()if p .name .startswith ("u" )and p .suffix in ("" ,".zip" )], []) 73 74def test_the_whole_cause_is_printed_not_the_first_six_lines (self ): 75lines = ["echo strata update: this update source is older than the one already accepted (its sequence is 107, the accepted one is 108)." ] 76lines += [f"echo detail { i } " for i in range (2 ,9 )]+ ["echo the last line of the cause" ] 77feed = stub_release (self .root / "feed2" ,"@echo off\r\n" + "\r\n" .join (lines )+ "\r\nexit /b 5\r\n" ) 78out = self .run_installer (feed ,self .root / "data" ) 79self .assertIn ("the last line of the cause" ,out ) 80self .assertIn ("its sequence is 107" ,out ) 81self .assertIn ("The reason is printed above" ,out ) 82self .assertIn ("STOPPED" ,out ) 83self .assertFalse ((self .root / "data" / "terminal" / "0.1.48" ).exists (),"nothing is installed" ) 84 85 86if __name__ == "__main__" : 87unittest .main ()