okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Installer: an older feed shows its real reason; a folder with accented letters unpacks (TUI stress #11 A01b/A05, #12 A04)0af0f9f12

main
4.4 KiB87 linesraw
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):
23    def test_the_refusal_gives_both_numbers_the_folder_and_one_next_step(self):
24        self.publish(("0.1.46", test_updater.fx.GOOD_ENGINE), sequence=108)
25        updater.check(self.ctx())                                      # accepts sequence 108 and remembers it
26        self.publish(("0.1.46", test_updater.fx.GOOD_ENGINE), sequence=107)
27        with self.assertRaises(feedmod.FeedDowngrade) as caught:
28            updater.check(self.ctx())
29        text = str(caught.exception)
30        self.assertIn("older than the one already accepted", text)
31        self.assertIn("its sequence is 107", text)
32        self.assertIn("the accepted one is 108", text)
33        self.assertIn(str(self.components / ".updates"), text)
34        self.assertIn("state.json", text)
35        self.assertEqual(text.count("Use the newest release folder"), 1)
36
37
38def stub_release(folder: Path, body: str) -> str:
39    folder.mkdir(parents=True)
40    archive = folder / "terminal.zip"
41    with zipfile.ZipFile(archive, "w", zipfile.ZIP_DEFLATED) as z:
42        z.writestr("strata-terminal-0.1.48-windows-x86_64/bin/strata.cmd", body)
43        z.writestr("strata-terminal-0.1.48-windows-x86_64/strata.py", "# stub\n")
44    (folder / "install-manifest.txt").write_text(
45        f"windows-x86_64 0.1.48 terminal.zip {hashlib.sha256(archive.read_bytes()).hexdigest()} {archive.stat().st_size}\n")
46    return "file:///" + folder.as_posix()
47
48
49@unittest.skipUnless(POWERSHELL, "the Windows installer runs only on Windows")
50class WindowsInstaller(unittest.TestCase):
51    def setUp(self):
52        self.temp = tempfile.TemporaryDirectory(prefix="strata-inst-")
53        self.addCleanup(self.temp.cleanup)
54        self.root = Path(self.temp.name)
55
56    def run_installer(self, feed: str, data: Path):
57        runner = self.root / "run.ps1"
58        runner.write_text("$ErrorActionPreference = 'Continue'\n"
59                          f"$env:STRATA_FEED = '{feed}'; $env:STRATA_DATA_DIR = '{data}'; $env:STRATA_NO_PATH = '1'\n"
60                          f"try {{ Invoke-Expression (Get-Content -Raw -LiteralPath '{INSTALL_PS1}') }} catch {{ Write-Host \"STOPPED\" }}\n",
61                          encoding="utf-8-sig")
62        done = subprocess.run([POWERSHELL, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(runner)], capture_output=True, text=True,
63                              encoding="utf-8", errors="replace", timeout=300)
64        return done.stdout + done.stderr
65
66    def test_a_folder_with_accented_letters_is_unpacked(self):
67        feed = stub_release(self.root / "feed", "@echo off\r\nexit /b 0\r\n")
68        data = self.root / "Ünï test"
69        out = self.run_installer(feed, data)
70        self.assertIn("Installed. Run: strata launch", out, out)
71        self.assertTrue((data / "terminal" / "0.1.48" / "bin" / "strata.cmd").is_file())
72        self.assertEqual([p.name for p in (data / "terminal").iterdir() if p.name.startswith("u") and p.suffix in ("", ".zip")], [])
73
74    def test_the_whole_cause_is_printed_not_the_first_six_lines(self):
75        lines = ["echo strata update: this update source is older than the one already accepted (its sequence is 107, the accepted one is 108)."]
76        lines += [f"echo detail {i}" for i in range(2, 9)] + ["echo the last line of the cause"]
77        feed = stub_release(self.root / "feed2", "@echo off\r\n" + "\r\n".join(lines) + "\r\nexit /b 5\r\n")
78        out = self.run_installer(feed, self.root / "data")
79        self.assertIn("the last line of the cause", out)
80        self.assertIn("its sequence is 107", out)
81        self.assertIn("The reason is printed above", out)
82        self.assertIn("STOPPED", out)
83        self.assertFalse((self.root / "data" / "terminal" / "0.1.48").exists(), "nothing is installed")
84
85
86if __name__ == "__main__":
87    unittest.main()