Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ jobs:
- name: Test updater channel isolation and release versions
run: python3 -m pytest scripts/tests/test_generate_latest_json.py scripts/tests/test_configure_tauri_release.py scripts/tests/test_tauri_bundle_version.py -q

- name: Test host-ABI gate
run: python3 -m pytest scripts/tests/test_host_abi_gate.py -q
- name: Test host-ABI and glibc-floor gates
run: python3 -m pytest scripts/tests/test_host_abi_gate.py scripts/tests/test_abi_gate.py -q

- name: Test Windows arch detection and PE zip assertion
run: python3 -m pytest scripts/tests/test_get_arch.py scripts/tests/test_assert_windows_pe_arch.py -q
Expand Down Expand Up @@ -1069,7 +1069,9 @@ jobs:
python39-libs \
squashfs-tools \
zip \
wget
wget \
file \
binutils

- name: Set up Python PATH
run: |
Expand Down
17 changes: 14 additions & 3 deletions scripts/package/abi-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ scan_elfs() {
local total=0 scanned=0
while IFS= read -r elf; do
total=$((total + 1))
local versions
versions=$(readelf --version-info "$elf" 2>/dev/null \
local versions version_info
if ! version_info=$(readelf --version-info "$elf" 2>/dev/null); then
echo "ERROR: could not inspect ELF version information: $elf" >&2
exit 2
fi
versions=$(printf '%s\n' "$version_info" \
| grep -oP 'GLIBC_[0-9]+\.[0-9]+(\.[0-9]+)?' \
| sort -Vu) || true
[ -z "$versions" ] && continue
Expand All @@ -51,9 +55,16 @@ scan_elfs() {
| tee -a "$VIOLATION_LOG"
fi
done <<< "$versions"
done < <(find "$dir" -type f -exec file {} + 2>/dev/null \
done < <(find "$dir" -type f -exec file -N {} + 2>/dev/null \
| grep -E ': ELF ' | cut -d: -f1)
echo " ELFs with GLIBC refs: $scanned / $total files scanned"
# Fail closed: a scan that inspected nothing (no ELFs found, or file(1) /
# readelf output with no version references) proves
# nothing about the floor and must not report PASS.
if [ "$scanned" -eq 0 ]; then
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
echo "ERROR: no ELF with GLIBC version references found in $label — is file(1)/readelf installed and the archive complete?" >&2
exit 2
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
fi
}

extract_appimage() {
Expand Down
145 changes: 145 additions & 0 deletions scripts/tests/test_abi_gate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""Tests for scripts/package/abi-gate.sh failing closed.

The gate proves the manylinux bundle stays under the glibc 2.28 floor. A run
that inspected no ELF at all (missing file/readelf, or an archive with no
binaries) proves nothing and must not print PASS.
"""

from __future__ import annotations

import os
import shutil
import stat
import subprocess
import zipfile
from pathlib import Path

import pytest

ABI_GATE = Path(__file__).parents[1] / "package" / "abi-gate.sh"

pytestmark = pytest.mark.skipif(
shutil.which("readelf") is None or shutil.which("file") is None,
reason="needs binutils readelf and file(1)",
)


def _zip(tmp_path: Path, members: dict[str, Path | str]) -> Path:
archive = tmp_path / "bundle.zip"
with zipfile.ZipFile(archive, "w") as zf:
for name, src in members.items():
if isinstance(src, Path):
zf.write(src, f"activitywatch/{name}")
else:
zf.writestr(f"activitywatch/{name}", src)
return archive


def _stub(bindir: Path, name: str, body: str) -> None:
bindir.mkdir(exist_ok=True)
path = bindir / name
path.write_text("#!/bin/bash\n" + body)
path.chmod(path.stat().st_mode | stat.S_IEXEC)


def run_gate(tmp_path: Path, archive: Path, bindir: Path | None = None):
env = dict(os.environ)
if bindir is not None:
env["PATH"] = f"{bindir}:{env['PATH']}"
return subprocess.run(
["bash", str(ABI_GATE), str(archive)],
env=env,
capture_output=True,
text=True,
timeout=60,
)


def test_archive_without_elfs_fails(tmp_path: Path) -> None:
archive = _zip(tmp_path, {"README.txt": "no binaries here\n"})
result = run_gate(tmp_path, archive)
assert result.returncode == 2, result
assert "no ELF with GLIBC version references found" in result.stderr
assert "PASS" not in result.stdout


def test_broken_file_tool_fails(tmp_path: Path) -> None:
archive = _zip(tmp_path, {"aw-qt": Path(shutil.which("ls") or "/bin/ls")})
bindir = tmp_path / "bin"
_stub(bindir, "file", "exit 127\n")
result = run_gate(tmp_path, archive, bindir)
assert result.returncode == 2, result
assert "no ELF with GLIBC version references found" in result.stderr
assert "PASS" not in result.stdout


def test_broken_readelf_fails(tmp_path: Path) -> None:
archive = _zip(tmp_path, {"aw-qt": Path(shutil.which("ls") or "/bin/ls")})
bindir = tmp_path / "bin"
_stub(bindir, "readelf", "exit 127\n")
result = run_gate(tmp_path, archive, bindir)
assert result.returncode == 2, result
assert "could not inspect ELF version information" in result.stderr
assert "PASS" not in result.stdout


def test_partial_readelf_failure_fails_closed(tmp_path: Path) -> None:
binary = Path(shutil.which("ls") or "/bin/ls")
archive = _zip(tmp_path, {"aw-qt": binary, "aw-server": binary})
bindir = tmp_path / "bin"
_stub(
bindir, "readelf", 'case "$2" in */aw-qt) exit 1;; *) echo GLIBC_2.28;; esac\n'
)
result = run_gate(tmp_path, archive, bindir)
assert result.returncode == 2, result
assert "could not inspect ELF version information" in result.stderr
assert "aw-qt" in result.stderr
assert "PASS" not in result.stdout


@pytest.mark.parametrize("short_version, expected_code", [("2.28", 0), ("2.29", 1)])
def test_mixed_length_paths_are_all_scanned(
tmp_path: Path, short_version: str, expected_code: int
) -> None:
binary = Path(shutil.which("ls") or "/bin/ls")
archive = _zip(
tmp_path,
{
"aw-qt": binary,
"longer-binary-name": binary,
"a-much-longer-readme-name.txt": "not an ELF\n",
},
)
# Keep file(1) real so its padding is exercised; make symbol versions
# deterministic, with any violation confined to the shorter binary.
bindir = tmp_path / "bin"
_stub(
bindir,
"readelf",
f'case "$2" in */aw-qt) echo GLIBC_{short_version};; '
"*) echo GLIBC_2.28;; esac\n",
)
result = run_gate(tmp_path, archive, bindir)
assert "ELFs with GLIBC refs: 2 / 2" in result.stdout, result
assert result.returncode == expected_code, result
if expected_code == 0:
assert "PASS" in result.stdout
else:
assert "VIOLATION in aw-qt: GLIBC_2.29" in result.stdout
assert "PASS" not in result.stdout


def test_real_binary_is_scanned(tmp_path: Path) -> None:
# Host binaries may legitimately exceed the floor; either verdict is fine
# as long as the binary was actually inspected.
binary = Path(shutil.which("ls") or "/bin/ls")
versions = subprocess.run(
["readelf", "--version-info", str(binary)], capture_output=True, text=True
)
assert versions.returncode == 0, versions
if "GLIBC_" not in versions.stdout:
pytest.skip("host ls has no GLIBC version references")
archive = _zip(tmp_path, {"aw-qt": binary})
result = run_gate(tmp_path, archive)
assert "ELFs with GLIBC refs: 1 / 1" in result.stdout, result.stdout
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
assert result.returncode in (0, 1)
Loading