Files
gridcraft/packaging/linux/nightly-linux-launch-tests.py
T
skylartaylor f59fdf3e84 Linux nightlies: start every format through the flavor's launch profile
Dylan's ports keep the nightly identities but start the GUI directly, and a nightly build
refuses to start without --launch-profile nightly-v1 --profile-root <dir>. Ship the launcher
every Linux nightly format needs, so an installed, extracted or sandboxed nightly never runs
against the stable profile (his remaining re-review items close with it).

- deb/rpm: usr/bin/gridcraft-nightly is a launcher; the GUI moves to
  usr/lib/gridcraft-nightly/gridcraft, which nfpm.yaml carries with mode 0755. A stable stage
  has no such file, so the three-line entry is dropped and the rendered stable nfpm.yaml stays
  byte-identical to his head.
- AppImage: AppRun is a script, not the usr/bin/gridcraft symlink, and usr/bin/gridcraft-nightly
  is installed beside it; the desktop Exec/TryExec name the launcher.
- Arch handoff: nightly-arch-launch.sh passes the profile tokens instead of relocating the four
  XDG folders (the profile holds settings, logs, the control token and the session record).
- Flatpak: bin/gridcraft-nightly is installed and is the manifest's command: and the desktop
  entry's Exec/TryExec. profile_root now accepts that package's own id
  (ai.storyteller.gridcraft.nightly) and still refuses the stable id and every other one.
- plain tarballs: bin/gridcraft-nightly in package.sh's tree and gridcraft-nightly in the flat
  nightly.sh archive, which nightly-archive.py now requires.

The profile root is ${XDG_DATA_HOME:-$HOME/.local/share}/gridcraft-nightly/profile in every
format; it sits beside, never inside, the stable rows.

Also from the re-review: the nightly metainfo no longer lists mediatypes and names the launcher
as its binary, the nightly desktop file and metainfo are validated now that the tools are
present, and nightly-common.sh passes GRIDCRAFT_VERSION on the build command as well as
inheriting it and checks the exact identity the binary prints (with the output in the message).
packaging/linux/nightly-linux-launch-tests.py runs the launcher in both moved-tree layouts and
stages deb, tar and AppImage with stub nfpm/appimagetool/strip, so the wrappers are tested
without cargo; nightly-arch-tar-test.sh asserts the launcher argv.

Builds on dylanmtaylor's co-installable Linux packages (#4733, @dylanmtaylor).

skylartaylor <skylartaylor@users.noreply.github.com>
2026-11-24 23:19:36 +01:00

234 lines
12 KiB
Python

#!/usr/bin/env python3
"""The Linux launch profile, staged the way each format ships it; no cargo build, no GUI, no network.
What is checked, all synthetic:
* `nightly-launch.sh` (the AppImage and tar launcher) passes the flavor's own tokens and nothing else;
* `package.sh` stages the deb/rpm, AppImage and tar launchers and a nightly desktop entry, and
leaves a stable tree exactly as it was. `nfpm`, `appimagetool` and `strip` are stubs on PATH.
"""
import os
from pathlib import Path
import shutil
import subprocess
import tarfile
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
LAUNCHER = ROOT / "packaging/linux/nightly-launch.sh"
PACKAGE = ROOT / "packaging/linux/package.sh"
NIGHTLY_VERSION = "0.19.1-nightly.20261124.7.1.gabcdef012345"
PROFILE = "gridcraft-nightly/profile"
RECORDER = """#!/bin/sh
printf '<%s>\\n' "$@"
"""
def run(argv, cwd, env, check=True):
return subprocess.run(argv, cwd=cwd, env=env, check=check, capture_output=True, text=True)
class MovedTreeLauncher(unittest.TestCase):
"""nightly-launch.sh as AppRun and as an unpacked tar's launcher."""
def setUp(self):
self.scratch = tempfile.TemporaryDirectory()
self.addCleanup(self.scratch.cleanup)
self.root = Path(self.scratch.name)
self.data = self.root / "data"
self.env = {"PATH": os.environ["PATH"], "XDG_DATA_HOME": str(self.data)}
def install(self, layout):
"""AppImage layout: launcher at the root; tar layout: launcher beside the binary."""
tree = self.root / layout
binary = tree / ("usr/bin/gridcraft" if layout == "appdir" else "gridcraft")
binary.parent.mkdir(parents=True)
binary.write_text(RECORDER)
binary.chmod(0o755)
launcher = tree / ("AppRun" if layout == "appdir" else "gridcraft-nightly")
shutil.copy2(LAUNCHER, launcher)
launcher.chmod(0o755)
return launcher
def query(self, launcher, *args):
return run([str(launcher), *args], cwd=self.root, env=self.env)
def tokens(self):
return ["<--launch-profile>", "<nightly-v1>", "<--profile-root>", f"<{self.data / PROFILE}>", "<-->"]
def test_both_layouts_start_the_gui_through_the_launch_profile(self):
for layout in ("appdir", "tar"):
with self.subTest(layout=layout):
launcher = self.install(layout)
self.assertEqual(self.query(launcher).stdout.splitlines(), self.tokens())
self.assertEqual(
self.query(launcher, "workbook with spaces.xlsx", "--other-name.xlsx").stdout.splitlines(),
self.tokens() + ["<workbook with spaces.xlsx>", "<--other-name.xlsx>"],
)
def test_a_bare_version_query_and_the_launcher_protocol_pass_through(self):
launcher = self.install("appdir")
for args in (["--version"], ["-V"], ["--launch-profile", "nightly-v1", "--profile-root", "/launcher", "--", "book.xlsx"]):
with self.subTest(args=args):
self.assertEqual(self.query(launcher, *args).stdout.splitlines(), [f"<{arg}>" for arg in args])
def test_a_missing_data_folder_or_binary_refuses_before_running_anything(self):
launcher = self.install("appdir")
refused = run([str(launcher), "book.xlsx"], cwd=self.root, env={"PATH": os.environ["PATH"]}, check=False)
self.assertEqual(refused.returncode, 2)
self.assertIn("XDG_DATA_HOME and HOME are both unset", refused.stderr)
(self.root / "appdir/usr/bin/gridcraft").unlink()
missing = run([str(launcher)], cwd=self.root, env=self.env, check=False)
self.assertEqual(missing.returncode, 2)
self.assertIn("no GridCraft binary", missing.stderr)
self.assertFalse(self.data.exists(), "a refused launch creates no data folder")
def test_the_launcher_is_portable_shell(self):
run(["sh", "-n", str(LAUNCHER)], cwd=self.root, env=self.env)
self.assertTrue(LAUNCHER.read_text().startswith("#!/bin/sh\n"))
class StagedFormats(unittest.TestCase):
"""package.sh with stub binaries, a stub nfpm and a stub strip."""
def setUp(self):
self.scratch = tempfile.TemporaryDirectory()
self.addCleanup(self.scratch.cleanup)
self.root = Path(self.scratch.name)
self.target = self.root / "target"
self.dist = self.root / "dist"
self.stubs = self.root / "stubs"
for directory in (self.target / "release", self.dist, self.stubs):
directory.mkdir(parents=True, exist_ok=True)
for name in ("gridcraft", "gridcraft-cli"):
binary = self.target / "release" / name
binary.write_text(RECORDER)
binary.chmod(0o755)
# `strip` would refuse the recorder scripts; the real one is a no-op for a non-ELF file too.
(self.stubs / "strip").write_text("#!/bin/sh\nexit 0\n")
(self.stubs / "strip").chmod(0o755)
(self.stubs / "nfpm").write_text(
'#!/bin/sh\n'
'while [ "$#" -gt 0 ]; do [ "$1" = "-f" ] && cp "$2" "$STUB_NFPM_DIR/rendered.yaml"; shift; done\n'
'exit 0\n'
)
(self.stubs / "nfpm").chmod(0o755)
self.env = {
"PATH": f"{self.stubs}:{os.environ['PATH']}",
"HOME": os.environ.get("HOME", str(self.root)),
"CARGO_TARGET_DIR": str(self.target),
"DIST": str(self.dist),
"STUB_NFPM_DIR": str(self.root),
"GRIDCRAFT_BUILD_DATE": "2026-11-24",
"GRIDCRAFT_BUILD_SHA": "a" * 40,
}
def stage(self, formats="deb tar", **extra):
env = dict(self.env, **extra)
run(["bash", str(PACKAGE), "--skip-build", "--formats", formats], cwd=ROOT, env=env)
return self.target / "linux-package"
def nightly(self):
return self.stage(GRIDCRAFT_BUILD_CHANNEL="nightly-v1", GRIDCRAFT_VERSION=NIGHTLY_VERSION)
def test_nightly_deb_installs_a_launcher_and_the_gui_beside_it(self):
work = self.nightly()
stage = work / "nfpm-root"
launcher = stage / "usr/bin/gridcraft-nightly"
gui = stage / "usr/lib/gridcraft-nightly/gridcraft"
self.assertTrue(self.executable(launcher))
self.assertTrue(self.executable(gui))
self.assertFalse((stage / "usr/bin/gridcraft").exists(), "the GUI moved out of usr/bin")
self.assertTrue(self.executable(stage / "usr/bin/gridcraft-nightly-cli"))
text = launcher.read_text()
self.assertIn('exec "/usr/lib/gridcraft-nightly/gridcraft" --launch-profile nightly-v1', text)
self.assertIn(f"/{PROFILE}", text)
self.assertEqual(gui.read_text(), RECORDER, "the packaged GUI is the built binary, unchanged")
rendered = (self.root / "rendered.yaml").read_text()
self.assertIn(f"src: {stage}/usr/lib/gridcraft-nightly/gridcraft", rendered)
self.assertIn("dst: /usr/lib/gridcraft-nightly/gridcraft", rendered)
self.assertIn("file_info: { mode: 0755 }", rendered)
def test_nightly_desktop_and_metainfo_are_the_nightly_identity(self):
work = self.nightly()
applications = work / "nfpm-root/usr/share/applications"
desktop = applications / "ai.storyteller.gridcraft.nightly-v1.desktop"
self.assertEqual(sorted(p.name for p in applications.iterdir()), [desktop.name])
text = desktop.read_text()
self.assertIn("Exec=gridcraft-nightly %F\n", text)
self.assertIn("TryExec=gridcraft-nightly\n", text)
self.assertIn("StartupWMClass=ai.storyteller.gridcraft.nightly-v1\n", text)
self.assertIn("Name=GridCraft Nightly\n", text)
self.assertNotIn("MimeType=", text)
metainfo = (work / "nfpm-root/usr/share/metainfo/ai.storyteller.gridcraft.nightly-v1.metainfo.xml").read_text()
self.assertNotIn("<mediatype>", metainfo)
self.assertIn("<binary>gridcraft-nightly</binary>", metainfo)
def test_nightly_tar_ships_the_launcher_beside_the_binary(self):
self.nightly()
archive = self.dist / f"gridcraft-{NIGHTLY_VERSION}-linux-x86_64.tar.gz"
with tarfile.open(archive) as tar:
names = {member.name.split("/", 1)[-1] for member in tar.getmembers()}
launcher = tar.extractfile("gridcraft-%s-linux-x86_64/bin/gridcraft-nightly" % NIGHTLY_VERSION).read().decode()
binary = tar.extractfile("gridcraft-%s-linux-x86_64/bin/gridcraft" % NIGHTLY_VERSION).read().decode()
desktop = tar.extractfile("gridcraft-%s-linux-x86_64/share/applications/ai.storyteller.gridcraft.desktop" % NIGHTLY_VERSION).read().decode()
self.assertIn("bin/gridcraft", names)
self.assertEqual(binary, RECORDER)
self.assertEqual(launcher, LAUNCHER.read_text())
self.assertIn("Exec=gridcraft-nightly %F\n", desktop)
self.assertIn("Name=GridCraft Nightly\n", desktop)
self.assertNotIn("MimeType=", desktop)
def test_a_stable_tree_is_unchanged(self):
work = self.stage()
stage = work / "root"
self.assertEqual(stage, work / "root", "a stable build packages its one stage")
self.assertTrue(self.executable(stage / "usr/bin/gridcraft"))
self.assertTrue(self.executable(stage / "usr/bin/gridcraft-cli"))
self.assertFalse((stage / "usr/bin/gridcraft-nightly").exists())
self.assertFalse((stage / "usr/lib").exists())
rendered = (self.root / "rendered.yaml").read_text()
self.assertNotIn("gridcraft-nightly", rendered)
self.assertIn(f"src: {stage}/usr/bin/gridcraft\n", rendered)
desktop = (stage / "usr/share/applications/ai.storyteller.gridcraft.desktop").read_text()
self.assertIn("Exec=gridcraft %F\n", desktop)
self.assertIn("MimeType=", desktop)
with tarfile.open(self.dist / "gridcraft-0.19.1-linux-x86_64.tar.gz") as tar:
names = {member.name.split("/", 1)[-1] for member in tar.getmembers()}
self.assertIn("bin/gridcraft", names)
self.assertNotIn("bin/gridcraft-nightly", names)
def test_nightly_appimage_runs_its_launcher_as_apprun(self):
tool = self.stubs / "appimagetool"
tool.write_text("#!/bin/sh\nprintf '%s\\n' \"$@\" >\"$STUB_NFPM_DIR/appimagetool.argv\"\n")
tool.chmod(0o755)
(self.stubs / "runtime").write_text("runtime fixture")
work = self.stage(
"appimage",
GRIDCRAFT_BUILD_CHANNEL="nightly-v1",
GRIDCRAFT_VERSION=NIGHTLY_VERSION,
APPIMAGETOOL=str(tool),
APPIMAGE_RUNTIME=str(self.stubs / "runtime"),
)
appdir = work / "GridCraft.AppDir"
self.assertTrue(self.executable(appdir / "AppRun"))
self.assertEqual((appdir / "AppRun").read_text(), LAUNCHER.read_text(), "AppRun is the launcher, not a symlink")
self.assertFalse((appdir / "AppRun").is_symlink())
self.assertEqual((appdir / "usr/bin/gridcraft-nightly").read_text(), LAUNCHER.read_text())
self.assertEqual((appdir / "usr/bin/gridcraft").read_text(), RECORDER, "the binary stays in usr/bin")
desktop = (appdir / "usr/share/applications/ai.storyteller.gridcraft.nightly-v1.desktop").read_text()
self.assertIn("Exec=gridcraft-nightly %F\n", desktop)
self.assertIn("TryExec=gridcraft-nightly\n", desktop)
self.assertIn("StartupWMClass=ai.storyteller.gridcraft.nightly-v1\n", desktop)
self.assertNotIn("MimeType=", desktop)
def executable(self, path):
self.assertTrue(path.is_file(), f"{path} is not a file")
self.assertTrue(os.access(path, os.X_OK), f"{path} is not executable")
return True
if __name__ == "__main__":
unittest.main()