Something went wrong. Try again.
Manifests and a static winget source for jcollie's Windows programs, built and signed on Linux.
Something went wrong. Try again.
5.5 kB · 129 lines
Python
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us># SPDX-License-Identifier: MIT
import hashlibimport pathlibimport tempfileimport unittest
from wingetsource import check
from .helpers import write_manifest
REPO = pathlib.Path(__file__).parent.parent
_URL = "https://git.jcollie.dev/jeff/thing/releases/download/v1.0.0/thing.exe"_CONTENT = b"an installer"
def _installer(url: str = _URL, sha256: str = hashlib.sha256(_CONTENT).hexdigest().upper(), extra: str = "") -> str: return ( "InstallerType: portable\n" + extra + f"Installers:\n- Architecture: x64\n InstallerUrl: {url}\n InstallerSha256: {sha256}\n" )
def _messages(problems) -> str: return "\n".join(str(p) for p in problems)
class CheckDirectory(unittest.TestCase): def setUp(self): self.tmp = tempfile.TemporaryDirectory() self.root = pathlib.Path(self.tmp.name) / "manifests"
def tearDown(self): self.tmp.cleanup()
def problems(self, directory): return check.check_directory(directory, self.root)
def test_repository_manifests_pass(self): tree = REPO / "manifests" for directory in sorted({p.parent for p in tree.rglob("*.yaml")}): with self.subTest(directory=str(directory)): self.assertEqual([], check.check_directory(directory, tree))
def test_good_manifest_passes(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer()) self.assertEqual([], self.problems(directory))
def test_typed_fields_validate_as_winget_reads_them(self): # Integers and booleans only exist for the fields winget converts; # everything else, a version that looks like a number included, is a # string to the schema. installer = _installer(extra="InstallerSuccessCodes:\n- 3010\nInstallerAbortsTerminal: yes\n") directory = write_manifest(self.root, "JCOllie.Thing", "1.10", installer=installer) self.assertEqual([], self.problems(directory))
def test_schema_errors_are_reported(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer(extra="Scope: everywhere\n")) self.assertIn("Scope", _messages(self.problems(directory)))
def test_identifier_must_be_ours(self): directory = write_manifest(self.root, "Example.Thing", "1.0.0", installer=_installer()) self.assertIn("must start with JCOllie.", _messages(self.problems(directory)))
def test_directory_must_match(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer()) moved = directory.parent / "2.0.0" directory.rename(moved) self.assertIn("belongs in", _messages(self.problems(moved)))
def test_file_names_must_match(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer()) (directory / "JCOllie.Thing.installer.yaml").rename(directory / "installer.yaml") self.assertIn("should be named JCOllie.Thing.installer.yaml", _messages(self.problems(directory)))
def test_default_locale_must_agree(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer()) path = directory / "JCOllie.Thing.yaml" path.write_text(path.read_text().replace("DefaultLocale: en-US", "DefaultLocale: en-GB")) self.assertIn("DefaultLocale", _messages(self.problems(directory)))
def test_manifest_version_is_pinned(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer()) path = directory / "JCOllie.Thing.yaml" path.write_text(path.read_text().replace("ManifestVersion: 1.12.0", "ManifestVersion: 1.10.0")) self.assertIn("ManifestVersion must be 1.12.0", _messages(self.problems(directory)))
def test_singletons_are_refused(self): directory = self.root / "j" / "JCOllie" / "Thing" / "1.0.0" directory.mkdir(parents=True) (directory / "JCOllie.Thing.yaml").write_text("ManifestType: singleton\nManifestVersion: 1.12.0\n") self.assertIn("ManifestType must be one of", _messages(self.problems(directory)))
class CheckInstallers(unittest.TestCase): def setUp(self): self.tmp = tempfile.TemporaryDirectory() self.root = pathlib.Path(self.tmp.name) / "manifests"
def tearDown(self): self.tmp.cleanup()
@staticmethod def download(url): return hashlib.sha256(_CONTENT).digest()
def test_matching_hash_passes(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer()) self.assertEqual([], check.check_installers(directory, download=self.download))
def test_hash_mismatch(self): directory = write_manifest(self.root, "JCOllie.Thing", "1.0.0", installer=_installer(sha256="0" * 64)) self.assertIn("SHA-256 is", _messages(check.check_installers(directory, download=self.download)))
def test_other_hosts_are_refused_without_downloading(self): def refuse(url): raise AssertionError("downloaded")
directory = write_manifest( self.root, "JCOllie.Thing", "1.0.0", installer=_installer(url="https://codeberg.org/jcollie/thing/thing.exe") ) self.assertIn("must download from https://git.jcollie.dev/", _messages(check.check_installers(directory, download=refuse)))
if __name__ == "__main__": unittest.main()