okami.mom/strata

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

Niko1221desktop: Windows node.exe in the Tauri shell, hidden host console, and fetch-node.ps1 (win-x64, same SHA-256 pin as fetch-node.sh)8a11d125d

main
2.4 KiB56 linesraw
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):
20    def test_both_scripts_pin_the_same_windows_digest_and_version(self):
21        sh = (SCRIPTS / "fetch-node.sh").read_text()
22        ps = (SCRIPTS / "fetch-node.ps1").read_text()
23        sh_digest = re.search(r'win-x64\)\s+echo "([0-9a-f]{64})"', sh).group(1)
24        ps_digest = re.search(r"\$Expected = '([0-9a-f]{64})'", ps).group(1)
25        self.assertEqual(sh_digest, ps_digest)
26        self.assertEqual(re.search(r'STRATA_NODE_VERSION:-([\d.]+)', sh).group(1),
27                         re.search(r"else \{ '([\d.]+)' \}", ps).group(1))
28
29
30@unittest.skipUnless(os.name == "nt" and POWERSHELL, "Windows PowerShell")
31class PowerShellTests(unittest.TestCase):
32    def run_script(self, *args):
33        return subprocess.run([POWERSHELL, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File",
34                               str(SCRIPTS / "fetch-node.ps1"), *args],
35                              capture_output=True, text=True, timeout=120)
36
37    def test_a_zip_with_the_wrong_digest_is_refused_and_nothing_is_installed(self):
38        with tempfile.TemporaryDirectory() as directory:
39            archive = Path(directory) / "node.zip"
40            with zipfile.ZipFile(archive, "w") as bundle:
41                bundle.writestr("node-v24.12.0-win-x64/node.exe", b"not node")
42            dest = Path(directory) / "out"
43            result = self.run_script("-FromFile", str(archive), "-Dest", str(dest))
44            self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
45            self.assertIn("REFUSING", result.stderr)
46            self.assertFalse((dest / "node.exe").exists())
47
48    def test_check_reports_a_missing_runtime(self):
49        with tempfile.TemporaryDirectory() as directory:
50            result = self.run_script("-Check", "-Dest", directory)
51            self.assertEqual(result.returncode, 1)
52            self.assertIn("not installed", result.stderr)
53
54
55if __name__ == "__main__":
56    unittest.main()