Agent review pass.
This commit is contained in:
1 parent
e9b2e9508b
commit
64ee749a8e
105 files changed
+2098
-320
No files matched your search
+48
-23
@@ -15,6 +15,40 @@ from native_test_session import run_private_session
|
||||
from native_x11 import wait_for
|
||||
|
||||
|
||||
def stop_process(process):
|
||||
if process is None or process.poll() is not None:
|
||||
return
|
||||
try:
|
||||
process.terminate()
|
||||
try:
|
||||
process.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
process.kill()
|
||||
process.wait(timeout=5)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def diagnose():
|
||||
import pyatspi
|
||||
def describe(node, depth=0):
|
||||
if depth > 8:
|
||||
return
|
||||
if node.getRoleName() in ('tree', 'table', 'frame', 'table cell'):
|
||||
print(node.getRoleName(), repr(node.name), node.getState().getStates(), flush=True)
|
||||
if node.getRoleName() in ('tree', 'table'):
|
||||
table = node.queryTable()
|
||||
print('ROWS', table.getSelectedRows(), flush=True)
|
||||
for row in range(table.nRows):
|
||||
cell = table.getAccessibleAt(row, 0)
|
||||
print('CELL', repr(cell.name), cell.getState().getStates(), flush=True)
|
||||
for child in node:
|
||||
describe(child, depth+1)
|
||||
for app in pyatspi.Registry.getDesktop(0):
|
||||
if app.name.lower() == 'audacious':
|
||||
describe(app)
|
||||
|
||||
|
||||
def run_inside():
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
temporary = Path(os.environ['XDG_CONFIG_HOME'])
|
||||
@@ -68,32 +102,23 @@ def run_inside():
|
||||
subprocess.run(['go', 'test', './internal/app', '-run', '^TestNativeAudacious$',
|
||||
'-count=1', '-v', '-timeout=90s'], cwd=root, check=True, timeout=120)
|
||||
finally:
|
||||
if process is not None:
|
||||
process.terminate()
|
||||
process.wait(timeout=5)
|
||||
manager.terminate()
|
||||
manager.wait(timeout=5)
|
||||
stop_process(process)
|
||||
stop_process(manager)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if '--diagnose' in sys.argv:
|
||||
import pyatspi
|
||||
def describe(node, depth=0):
|
||||
if depth > 8:
|
||||
return
|
||||
if node.getRoleName() in ('tree', 'table', 'frame', 'table cell'):
|
||||
print(node.getRoleName(), repr(node.name), node.getState().getStates(), flush=True)
|
||||
if node.getRoleName() in ('tree', 'table'):
|
||||
table = node.queryTable()
|
||||
print('ROWS', table.getSelectedRows(), flush=True)
|
||||
for row in range(table.nRows):
|
||||
cell = table.getAccessibleAt(row, 0)
|
||||
print('CELL', repr(cell.name), cell.getState().getStates(), flush=True)
|
||||
for child in node:
|
||||
describe(child, depth+1)
|
||||
for app in pyatspi.Registry.getDesktop(0):
|
||||
if app.name.lower() == 'audacious':
|
||||
describe(app)
|
||||
if '--diagnose-inside' in sys.argv:
|
||||
diagnose()
|
||||
elif '--diagnose' in sys.argv:
|
||||
# Never walk the live desktop: diagnose only inside a private
|
||||
# session, like every other mode of this script.
|
||||
with tempfile.TemporaryDirectory(prefix='cthulhu-audacious-') as temporary:
|
||||
environment = dict(os.environ, XDG_CONFIG_HOME=temporary,
|
||||
XDG_CACHE_HOME=temporary, XDG_DATA_HOME=temporary, XDG_STATE_HOME=temporary,
|
||||
QT_QPA_PLATFORM='xcb',
|
||||
QT_LINUX_ACCESSIBILITY_ALWAYS_ON='1', NO_AT_BRIDGE='0')
|
||||
run_private_session(['xvfb-run', '-a', 'dbus-run-session', '--',
|
||||
sys.executable, __file__, '--diagnose-inside'], env=environment, check=True)
|
||||
elif '--inside' in sys.argv:
|
||||
run_inside()
|
||||
else:
|
||||
|
||||
@@ -18,6 +18,20 @@ from native_test_session import run_private_session
|
||||
from native_x11 import set_active_window, wait_for
|
||||
|
||||
|
||||
def stop_process(process):
|
||||
if process is None or process.poll() is not None:
|
||||
return
|
||||
try:
|
||||
process.terminate()
|
||||
try:
|
||||
process.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
process.kill()
|
||||
process.wait(timeout=5)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def run_inside():
|
||||
import gi
|
||||
gi.require_version('Atspi', '2.0')
|
||||
@@ -240,9 +254,7 @@ def run_inside():
|
||||
if sys.exc_info()[0] is not None and logPath:
|
||||
print(logPath.read_text()[-3000:], flush=True)
|
||||
for process in (mumble, observer, windowManager):
|
||||
if process and process.poll() is None:
|
||||
process.kill()
|
||||
process.wait(timeout=5)
|
||||
stop_process(process)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
+30
-12
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Exercise build/toolchain boundaries without network access or a reader."""
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -34,9 +34,8 @@ elif tool == "pkg-config":
|
||||
sys.exit(1 if args[-1] == os.environ.get("MISSING_LIBRARY") else 0)
|
||||
elif tool == "curl":
|
||||
if args[-1].endswith(".sha256"):
|
||||
print(os.environ["ARCHIVE_SHA"])
|
||||
else:
|
||||
shutil.copyfile(os.environ["ARCHIVE_PATH"], args[args.index("--output") + 1])
|
||||
sys.exit(3) # The script must use its pinned digest, never fetch one.
|
||||
shutil.copyfile(os.environ["ARCHIVE_PATH"], args[args.index("--output") + 1])
|
||||
elif tool in ("go", "bootstrap-go"):
|
||||
if args == ["version"]:
|
||||
version = "1.24.0" if tool == "bootstrap-go" else os.environ["INSTALLED_GO"]
|
||||
@@ -58,7 +57,7 @@ class BuildScriptTests(unittest.TestCase):
|
||||
source = Path(__file__).resolve().parents[1] / "build-cthulhu.sh"
|
||||
self.script = self.project / source.name
|
||||
shutil.copyfile(source, self.script)
|
||||
(self.project / "go.mod").write_text("module example.invalid/reader\n\ngo 1.24.0\n")
|
||||
(self.project / "go.mod").write_text("module example.invalid/reader\n\ngo 1.27.2\n")
|
||||
self.caller = self.root / "caller directory"
|
||||
self.caller.mkdir()
|
||||
self.binDir = self.root / "bin"
|
||||
@@ -76,12 +75,14 @@ class BuildScriptTests(unittest.TestCase):
|
||||
entry.size = len(data)
|
||||
entry.mode = 0o755
|
||||
archive.addfile(entry, io.BytesIO(data))
|
||||
# Pin the fixture archive's digest in the copied script, standing in
|
||||
# for the official amd64 digest shipped in build-cthulhu.sh.
|
||||
self.pin_amd64_digest(hashlib.sha256(self.archive.read_bytes()).hexdigest())
|
||||
self.logPath = self.root / "calls.jsonl"
|
||||
self.env = dict(os.environ, PATH=f"{self.binDir}:/usr/bin:/bin",
|
||||
INSTALLED_GO="1.24.0", BUILD_LOG=str(self.logPath),
|
||||
INSTALLED_GO="1.27.2", BUILD_LOG=str(self.logPath),
|
||||
XDG_CACHE_HOME=str(self.root / "cache"),
|
||||
ARCHIVE_PATH=str(self.archive),
|
||||
ARCHIVE_SHA=hashlib.sha256(self.archive.read_bytes()).hexdigest(),
|
||||
GOTOOLCHAIN="auto", CGO_ENABLED="1", GOFLAGS="-mod=readonly",
|
||||
CGO_CFLAGS="-O2", GOMODCACHE=str(self.root / "modules"))
|
||||
|
||||
@@ -89,6 +90,12 @@ class BuildScriptTests(unittest.TestCase):
|
||||
return subprocess.run(["/bin/bash", str(self.script), *args], cwd=self.caller,
|
||||
env=self.env, text=True, capture_output=True, check=False)
|
||||
|
||||
def pin_amd64_digest(self, digest):
|
||||
text, count = re.subn(r"(1\.27\.2:amd64\) expectedChecksum=)[0-9a-f]{64}",
|
||||
r"\g<1>" + digest, self.script.read_text())
|
||||
assert count == 1, "pinned amd64 digest not found in build-cthulhu.sh"
|
||||
self.script.write_text(text)
|
||||
|
||||
def calls(self, name):
|
||||
if not self.logPath.exists():
|
||||
return []
|
||||
@@ -117,20 +124,31 @@ class BuildScriptTests(unittest.TestCase):
|
||||
result = self.run_build()
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertTrue((self.project / "cthulhu-braille").is_file())
|
||||
self.assertEqual(len(self.calls("curl")), 2)
|
||||
self.assertEqual(len(self.calls("curl")), 1)
|
||||
self.assertFalse(any(call[1][-1].endswith(".sha256") for call in self.calls("curl")))
|
||||
result = self.run_build()
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(len(self.calls("curl")), 2)
|
||||
self.assertEqual(len(self.calls("curl")), 1)
|
||||
self.assertEqual(len([c for c in self.calls("bootstrap-go") if c[1][0] == "build"]), 6)
|
||||
|
||||
def test_checksum_failure_never_executes_download(self):
|
||||
self.env.update(INSTALLED_GO="1.20.14", ARCHIVE_SHA="0" * 64)
|
||||
self.pin_amd64_digest("0" * 64)
|
||||
self.env["INSTALLED_GO"] = "1.20.14"
|
||||
result = self.run_build()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("checksum mismatch", result.stderr)
|
||||
self.assertFalse(self.calls("bootstrap-go"))
|
||||
self.assertFalse(list((self.root / "cache").rglob("*.download.*")))
|
||||
|
||||
def test_unverified_cached_toolchain_rejected(self):
|
||||
self.env["INSTALLED_GO"] = "1.20.14"
|
||||
self.assertEqual(self.run_build().returncode, 0)
|
||||
digest_file = next((self.root / "cache").rglob(".archive.sha256"))
|
||||
digest_file.write_text("0" * 64 + "\n")
|
||||
result = self.run_build()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("unverified", result.stderr)
|
||||
|
||||
def test_bootstrap_without_installed_go(self):
|
||||
(self.binDir / "go").unlink()
|
||||
for name in ("python3", "dirname", "awk", "mkdir", "mktemp", "tar",
|
||||
@@ -140,14 +158,14 @@ class BuildScriptTests(unittest.TestCase):
|
||||
self.env["PATH"] = str(self.binDir)
|
||||
result = self.run_build()
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(len(self.calls("curl")), 2)
|
||||
self.assertEqual(len(self.calls("curl")), 1)
|
||||
self.assertTrue((self.project / "cthulhu").is_file())
|
||||
|
||||
def test_local_old_go_does_not_download(self):
|
||||
self.env.update(INSTALLED_GO="1.20.14", GOTOOLCHAIN="local")
|
||||
result = self.run_build()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("Install Go 1.24.0", result.stderr)
|
||||
self.assertIn("Install Go 1.27.2", result.stderr)
|
||||
self.assertFalse(self.calls("curl"))
|
||||
|
||||
def test_preflight_and_arguments_do_not_download(self):
|
||||
|
||||
@@ -14,6 +14,8 @@ from pathlib import Path
|
||||
import sys
|
||||
args = sys.argv[1:]
|
||||
assert args[0] == "build"
|
||||
assert os.environ.get("GOWORK") == "off", "build() must export GOWORK=off"
|
||||
assert os.environ.get("GOTOOLCHAIN") == "local", "build() must export GOTOOLCHAIN=local"
|
||||
assert Path(args[-1]).is_dir(), "build target is absent from this source version"
|
||||
if args[-1] == os.environ.get("FAIL_BUILD_TARGET"):
|
||||
sys.exit(2)
|
||||
@@ -120,6 +122,29 @@ sys.exit(int(os.environ["CHECK_EXIT_CODE"]))
|
||||
for binary in binaries:
|
||||
self.assertTrue(os.access(installed / binary, os.X_OK))
|
||||
|
||||
def test_patches_referenced_and_srcinfo_present(self):
|
||||
import re
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
recipes = sorted((root / "distro-packages").rglob("PKGBUILD"))
|
||||
self.assertTrue(recipes)
|
||||
for recipe in recipes:
|
||||
with self.subTest(recipe=recipe.parent.name):
|
||||
text = recipe.read_text()
|
||||
source_block = re.search(r"^source=\((.*?)\)", text, re.S | re.M)
|
||||
self.assertIsNotNone(source_block)
|
||||
for patch in recipe.parent.glob("*.patch"):
|
||||
self.assertIn(patch.name, source_block.group(1),
|
||||
f"unreferenced patch {patch.name}")
|
||||
srcinfo = recipe.parent / ".SRCINFO"
|
||||
self.assertTrue(srcinfo.is_file(), ".SRCINFO missing; run makepkg --printsrcinfo")
|
||||
content = srcinfo.read_text()
|
||||
pkgbase = re.search(r"^pkgbase=(\S+)", text, re.M)
|
||||
srcinfo_base = re.search(r"^pkgbase = (\S+)", content, re.M)
|
||||
self.assertIsNotNone(srcinfo_base)
|
||||
if pkgbase:
|
||||
self.assertEqual(srcinfo_base.group(1), pkgbase.group(1).strip("'\""))
|
||||
self.assertRegex(content, r"(?m)^pkgname = \S+")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user