diff --git a/scripts/install_menu.py b/scripts/install_menu.py index 040b0088..0f64cbf8 100644 --- a/scripts/install_menu.py +++ b/scripts/install_menu.py @@ -1378,6 +1378,8 @@ def orbi_item(output=None): LADYBIRD_RELEASES = 'https://download.ladybird.org/releases.json' LADYBIRD_DOWNLOADS = 'https://download.ladybird.org/' LADYBIRD_ARCH = {'x86_64': 'x86_64', 'amd64': 'x86_64', 'aarch64': 'aarch64', 'arm64': 'aarch64'} +LADYBIRD_LAYOUTS = (('usr/bin/ladybird', 'usr/bin/ladybird-driver'), + ('usr/bin/Ladybird', 'usr/bin/WebDriver')) def ladybird_arch(): @@ -1478,10 +1480,12 @@ def install_ladybird(output=None): version, asset = ladybird_release(arch) root = ladybird_root() release = root / version - wanted = {browser: release / 'usr/bin/Ladybird', driver: release / 'usr/bin/WebDriver'} - if (before == version and all(path.is_symlink() and Path(os.readlink(path)) == target - and os.access(target, os.X_OK) for path, target in wanted.items())): - return f'{browser}: Ladybird {version}; current (release checked; download skipped)' + links = (browser, driver) + if before == version and all(link.is_symlink() for link in links): + targets = tuple(link.readlink() for link in links) + if (any(targets == tuple(release / path for path in layout) for layout in LADYBIRD_LAYOUTS) + and all(target.is_file() and os.access(target, os.X_OK) for target in targets)): + return f'{browser}: Ladybird {version}; current (release checked; download skipped)' root.mkdir(parents=True, exist_ok=True) # Unpack beside the final folder so the move into place is one rename. @@ -1499,17 +1503,23 @@ def install_ladybird(output=None): # Unpacking needs no FUSE, and gives the WebDriver binary its own command. unpack = subprocess.run([str(image), '--appimage-extract'], cwd=directory, stdin=subprocess.DEVNULL, capture_output=True, text=True, errors='replace', timeout=600) - unpacked = Path(directory) / 'squashfs-root' - if unpack.returncode or not all(os.access(unpacked / target.relative_to(release), os.X_OK) - for target in wanted.values()): + if unpack.returncode: raise OSError(f'{asset["name"]} did not unpack: {failure_summary(unpack.stderr or unpack.stdout)}; ' 'nothing was replaced') - if ladybird_version(unpacked / 'usr/bin/Ladybird') != version: + unpacked = Path(directory) / 'squashfs-root' + layout = next((layout for layout in LADYBIRD_LAYOUTS + if all((unpacked / path).is_file() and os.access(unpacked / path, os.X_OK) + for path in layout)), None) + if layout is None: + expected = ' or '.join(' and '.join(pair) for pair in LADYBIRD_LAYOUTS) + raise OSError(f'{asset["name"]} unpacked without a complete executable layout: expected {expected}; ' + 'nothing was replaced') + if ladybird_version(unpacked / layout[0]) != version: raise OSError(f'the unpacked Ladybird does not report version {version}; nothing was replaced') if os.path.lexists(release): shutil.rmtree(release) # an unlinked or broken earlier unpack of this version os.rename(unpacked, release) - notes = ''.join(replace_link(path, target) for path, target in wanted.items()) + notes = ''.join(replace_link(link, release / path) for link, path in zip(links, layout)) if ladybird_version(browser) != version: raise OSError(f'{browser} does not report version {version} after linking') for old in root.iterdir(): diff --git a/tests/test_install_menu.py b/tests/test_install_menu.py index 82802f4f..5f7afcaf 100644 --- a/tests/test_install_menu.py +++ b/tests/test_install_menu.py @@ -42,12 +42,12 @@ def orbi_uv(head=ORBI_HEAD): ORBI_UV = orbi_uv() # The fixture's root account is uid 0 (a system account) unless the suite itself runs as root. LADYBIRD_VERSION = '3.4.5' # any release; the installer follows the index -# `--appimage-extract` unpacks two launchers; each logs its call and reports its version. +# `--appimage-extract` unpacks the listed launchers; each logs its call and reports its version. LADYBIRD_APPIMAGE = '''#!/bin/sh echo "appimage $*" >> "$FAKE_LOG" [ "$1" = --appimage-extract ] || exit 2 mkdir -p squashfs-root/usr/bin -for name in Ladybird WebDriver; do +for name in BINARY_NAMES; do printf '#!/bin/sh\\necho "%s $*" >> "$FAKE_LOG"\\necho "Version VERSION"\\n' "$name" > squashfs-root/usr/bin/$name chmod 755 squashfs-root/usr/bin/$name done @@ -251,10 +251,10 @@ def setUp(self): destination.start() self.addCleanup(destination.stop) - def ladybird_release(self, version, sha256=None): + def ladybird_release(self, version, sha256=None, *, names=('ladybird', 'ladybird-driver')): """Publish a fake AppImage that unpacks a Ladybird reporting this version.""" image = self.home / 'ladybird.AppImage' - image.write_text(LADYBIRD_APPIMAGE.replace('VERSION', version)) + image.write_text(LADYBIRD_APPIMAGE.replace('VERSION', version).replace('BINARY_NAMES', shlex.join(names))) image.chmod(0o755) data = image.read_bytes() downloads = [{'platform': 'Linux', 'architecture': arch, 'name': f'ladybird-{version}-Linux-{arch}.AppImage', @@ -1600,10 +1600,21 @@ def ladybird_row(self, result): summary = result.stdout.split('\nSummary:', 1)[1] return next(line for line in summary.splitlines() if line.startswith(' ladybird ')) + @unittest.skipUnless(install_menu.ladybird_arch(), 'Ladybird ships AppImages for Linux x86-64 and ARM64 only') + def test_ladybird_installs_lowercase_layout(self): + links = self.home / '.local/bin' + release = self.home / '.local/share/kit/ladybird' / LADYBIRD_VERSION + result = self.install('--only', 'ladybird') + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertRegex(self.ladybird_row(result), rf'^ ladybird +installed +\S*ladybird: Ladybird {LADYBIRD_VERSION}$') + self.assertEqual((links / 'ladybird').readlink(), release / 'usr/bin/ladybird') + self.assertEqual((links / 'ladybird-driver').readlink(), release / 'usr/bin/ladybird-driver') + @unittest.skipUnless(install_menu.ladybird_arch(), 'Ladybird ships AppImages for Linux x86-64 and ARM64 only') def test_ladybird_installs_the_newest_verified_release_and_follows_new_ones(self): browser, driver = self.home / '.local/bin/ladybird', self.home / '.local/bin/ladybird-driver' store = self.home / '.local/share/kit/ladybird' + self.ladybird_release(LADYBIRD_VERSION, names=('Ladybird', 'WebDriver')) first = self.install('--only', 'ladybird') self.assertEqual(first.returncode, 0, first.stdout + first.stderr) self.assertRegex(self.ladybird_row(first), rf'^ ladybird +installed +\S*ladybird: Ladybird {LADYBIRD_VERSION}$') @@ -1621,9 +1632,43 @@ def test_ladybird_installs_the_newest_verified_release_and_follows_new_ones(self newer = self.install('--only', 'ladybird') self.assertEqual(newer.returncode, 0, newer.stdout + newer.stderr) self.assertIn(f'Ladybird 3.4.6 (was {LADYBIRD_VERSION})', newer.stdout) - self.assertEqual(os.readlink(browser), str(store / '3.4.6/usr/bin/Ladybird')) + self.assertEqual(os.readlink(browser), str(store / '3.4.6/usr/bin/ladybird')) + self.assertEqual(os.readlink(driver), str(store / '3.4.6/usr/bin/ladybird-driver')) self.assertEqual(sorted(p.name for p in store.iterdir()), ['3.4.6']) # only the linked one is kept + @unittest.skipUnless(install_menu.ladybird_arch(), 'Ladybird ships AppImages for Linux x86-64 and ARM64 only') + def test_ladybird_repairs_mixed_links_and_prefers_lowercase_layout(self): + links = self.home / '.local/bin' + binaries = self.home / '.local/share/kit/ladybird' / LADYBIRD_VERSION / 'usr/bin' + self.ladybird_release(LADYBIRD_VERSION, names=('ladybird', 'ladybird-driver', 'Ladybird', 'WebDriver')) + first = self.install('--only', 'ladybird') + self.assertEqual(first.returncode, 0, first.stdout + first.stderr) + self.assertEqual((links / 'ladybird').readlink(), binaries / 'ladybird') + driver = links / 'ladybird-driver' + driver.unlink() + driver.symlink_to(binaries / 'WebDriver') + + repaired = self.install('--only', 'ladybird') + self.assertEqual(repaired.returncode, 0, repaired.stdout + repaired.stderr) + self.assertEqual(self.calls('appimage'), ['appimage --appimage-extract'] * 2) + self.assertEqual((links / 'ladybird').readlink(), binaries / 'ladybird') + self.assertEqual(driver.readlink(), binaries / 'ladybird-driver') + + @unittest.skipUnless(install_menu.ladybird_arch(), 'Ladybird ships AppImages for Linux x86-64 and ARM64 only') + def test_ladybird_reports_expected_paths_when_appimage_has_no_complete_layout(self): + self.ladybird_release(LADYBIRD_VERSION, names=('ladybird', 'WebDriver')) + result = self.install('--only', 'ladybird') + self.assertEqual(result.returncode, 1, result.stdout + result.stderr) + row = self.ladybird_row(result) + self.assertRegex(row, r'^ ladybird +failed ') + for path in ('usr/bin/ladybird', 'usr/bin/ladybird-driver', 'usr/bin/Ladybird', 'usr/bin/WebDriver'): + self.assertIn(path, row) + self.assertNotIn('command failed', row) + self.assertTrue(row.endswith('nothing was replaced'), row) + self.assertFalse(os.path.lexists(self.home / '.local/bin/ladybird')) + self.assertFalse(os.path.lexists(self.home / '.local/bin/ladybird-driver')) + self.assertEqual(list((self.home / '.local/share/kit/ladybird').iterdir()), []) + @unittest.skipUnless(install_menu.ladybird_arch(), 'Ladybird ships AppImages for Linux x86-64 and ARM64 only') def test_ladybird_rejects_a_download_that_does_not_match_the_index(self): self.ladybird_release(LADYBIRD_VERSION, sha256='0' * 64)