fix(nightly): answer queries without a data folder and close review gaps

The tar launcher answers --version/--help before the data-folder check, so a
query is not turned into an error, and the recorder test covers it.

The write probe uses a fresh name per attempt, so a probe left behind by an
interrupted launch cannot make a writable profile look unwritable. The profile
validator also fences Dictionaries/user.dic, so a link there cannot append
words to the stable app's dictionary.

The exit-hook test runs in a child with DECKCRAFT_NO_PREFS=1, nightly.ps1
passes -TargetDir to Cargo, the Windows signing fixture derives its source
identity from the checkout, and the release tests reject a concurrency block
on the producer. The Flatpak bundler documents which of the two ids is the
bundle id and which is the window id.
This commit is contained in:
skylartaylor
2026-11-25 00:58:30 +01:00
parent 37a82eac0a
commit 659c586765
9 changed files with 77 additions and 28 deletions
+14 -6
View File
@@ -98,13 +98,21 @@ pub fn user_dictionary() -> Option<PathBuf> {
/// The app's exclusive write probe: a new file created in `dir` and removed again. It never falls
/// back to another directory, so the Nightly validator can refuse a root it cannot write.
pub fn ensure_writable(dir: &Path) -> std::io::Result<()> {
let probe = dir.join(".deckcraft-write-probe");
let file = std::fs::OpenOptions::new().write(true).create_new(true).open(&probe)?;
drop(file);
match std::fs::remove_file(probe) {
Ok(()) => Ok(()),
Err(error) => Err(error),
// A probe left behind by an interrupted launch must not make a writable profile look
// unwritable, so each attempt uses a fresh name and a collision tries the next one.
// `create_new` still guarantees a create rather than a truncation.
for attempt in 0..8u32 {
let probe = dir.join(format!(".deckcraft-write-probe-{}-{attempt}", std::process::id()));
match std::fs::OpenOptions::new().write(true).create_new(true).open(&probe) {
Ok(file) => {
drop(file);
return std::fs::remove_file(probe);
}
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(error) => return Err(error),
}
}
Err(std::io::Error::new(std::io::ErrorKind::AlreadyExists, "no free write-probe name in the profile"))
}
#[cfg(test)]
+24 -14
View File
@@ -533,23 +533,33 @@ mod tests {
}
/// The exit hook (the Nightly session record) runs once, on the one exit path macOS has.
/// Not on macOS itself: there `on_exit` ends this test process (after writing the real stable
/// settings), which is the behaviour the child-process test above checks.
/// The check runs in a child with `DECKCRAFT_NO_PREFS=1`: `on_exit` saves the preferences
/// otherwise, and this test never loads the ones already on the machine. Not on macOS
/// itself: there `on_exit` ends the process, which is the behaviour the test above checks.
#[cfg(not(target_os = "macos"))]
#[test]
fn leaving_runs_the_exit_hook_once() {
let runs = std::rc::Rc::new(std::cell::Cell::new(0));
let counted = runs.clone();
let services = Services { at_exit: Some(Box::new(move || counted.set(counted.get() + 1))), ..Default::default() };
let mut app = App(
SlideApp::new(Session::new(), services),
#[cfg(target_os = "macos")]
fmv_macos_events::Inbox::default(),
);
eframe::App::on_exit(&mut app);
assert_eq!(runs.get(), 1);
eframe::App::on_exit(&mut app);
assert_eq!(runs.get(), 1, "a second exit must not run the hook again");
if std::env::var_os("DECKCRAFT_TEST_EXIT_HOOK").is_some() {
let runs = std::rc::Rc::new(std::cell::Cell::new(0));
let counted = runs.clone();
let services = Services { at_exit: Some(Box::new(move || counted.set(counted.get() + 1))), ..Default::default() };
let mut app = App(SlideApp::new(Session::new(), services));
eframe::App::on_exit(&mut app);
assert_eq!(runs.get(), 1);
eframe::App::on_exit(&mut app);
assert_eq!(runs.get(), 1, "a second exit must not run the hook again");
println!("exit hook ran once");
return;
}
let out = std::process::Command::new(std::env::current_exe().unwrap())
.args(["--exact", "tests::leaving_runs_the_exit_hook_once", "--nocapture"])
.env("DECKCRAFT_TEST_EXIT_HOOK", "1")
.env("DECKCRAFT_NO_PREFS", "1")
.output()
.unwrap();
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(out.status.success(), "{stdout}");
assert!(stdout.contains("exit hook ran once"), "the child didn't run the test: {stdout}");
}
#[test]
+3
View File
@@ -164,6 +164,9 @@ fn entries_stay_inside(root: &Path) -> Result<(), String> {
let entry = entry.map_err(|e| format!("cannot inspect the nightly profile: {e}"))?;
private_subdirectory(root, entry.file_name(), "profile entry")?;
}
// The one nested file Nightly writes itself: a link at Dictionaries/user.dic would append
// "add to dictionary" words to the stable app's file instead of this profile's.
private_subdirectory(root, std::path::Path::new("Dictionaries").join("user.dic"), "user dictionary")?;
Ok(())
}
+4
View File
@@ -64,6 +64,10 @@ if [[ "$FLATPAK_ID" != "$APP_ID" ]]; then
|| { echo "error: the nightly $TARBALL has no bin/deckcraft-bin and bin/deckcraft-nightly" >&2; exit 1; }
NIGHTLY_ICON="$ROOT/assets/app-icon/deckcraft-nightly.png"
[[ -f "$NIGHTLY_ICON" ]] || NIGHTLY_ICON="$ROOT/assets/app-icon/hicolor/256x256/apps/$APP_ID.png"
# Two ids meet here on purpose. The bundle id is the Flatpak app id (`$APP_ID.nightly`), so the
# exported desktop entry, its basename and the icon carry it. The window keeps the flavor id
# (`$APP_ID.nightly-v1`) that every other Linux format's desktop entry is renamed to, so
# StartupWMClass names the window id: that is what ties this launcher to the running window.
sed -e "s|^Icon=$APP_ID$|Icon=$FLATPAK_ID|" \
-e "s|^Name=DeckCraft$|Name=DeckCraft Nightly|" \
-e "s#^Exec=deckcraft\\([[:space:]]\\|$\\)#Exec=deckcraft-nightly\\1#" \
+4
View File
@@ -87,6 +87,10 @@ chmod 755 "$work/nodata/deckcraft"
status=0
env -u XDG_DATA_HOME -u HOME "$work/nodata/deckcraft" book.pptx >/dev/null 2>&1 || status=$?
[[ "$status" -eq 2 ]] || { printf 'a launcher with no data folder must exit 2, got %s\n' "$status" >&2; exit 1; }
# A query is not a launch: it answers without a data folder instead of becoming that error.
actual=$(env -u XDG_DATA_HOME -u HOME "$work/nodata/deckcraft" --version) \
|| { printf 'a no-data-folder --version must still answer\n' >&2; exit 1; }
[[ "$actual" == '<--version>' ]] || { printf 'a no-data-folder --version printed:\n%s\n' "$actual" >&2; exit 1; }
# ---- the /usr/bin rule: the fixed /usr/lib copy is named, and no parent path is ever used ----
# The launcher's text is searched literally, so `$here` must not expand here.
+8 -6
View File
@@ -40,6 +40,14 @@ if [ -z "$real" ]; then
exit 2
fi
# A bare version/help query and the Launcher's own protocol pass straight through: they are not
# file names, need no data folder, and a profile the caller already supplied is never wrapped
# twice. This runs before the data-folder check, so `deckcraft-nightly --version` still answers
# where HOME and XDG_DATA_HOME are both unset.
case "${1-}" in
--launch-profile | --profile-root | --version | -V | --help | -h) exec "$real" "$@" ;;
esac
if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then
echo "deckcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2
exit 2
@@ -47,12 +55,6 @@ fi
# The same root as every other format's launcher: beside the fenced stable `deckcraft` folder,
# never inside it.
profile="${XDG_DATA_HOME:-$HOME/.local/share}/deckcraft-nightly/launcher/profiles/deckcraft"
# A bare version/help query and the Launcher's own protocol pass straight through: they are not
# file names, and a profile the caller already supplied is never wrapped twice.
case "${1-}" in
--launch-profile | --profile-root | --version | -V | --help | -h) exec "$real" "$@" ;;
esac
# A caller-written `--` is the separator this launcher adds below. Drop it, so it can never reach
# the app as a file name.
if [ "${1-}" = "--" ]; then
+9
View File
@@ -155,6 +155,15 @@ class TrustedSourcePreparation(unittest.TestCase):
def test_signer_serialization_contract_is_enforced(self):
assert_nightly_serialization((ROOT / ".github/workflows/nightly-sign.yml").read_text())
def test_the_producer_declares_no_serialization_of_its_own(self):
# Only the signer serializes, because one protected release at a time is what the policy
# needs. The producer is a manual, stateless dispatch, so a concurrency block there would
# be a second, unreviewed gate; this keeps one from slipping in unnoticed.
source = (ROOT / ".github/workflows/nightly.yml").read_text()
executable = "\n".join(line for line in source.splitlines() if not line.lstrip().startswith("#"))
self.assertNotRegex(executable, r"(?m)^\s*concurrency:")
self.assertNotIn("cancel-in-progress", executable)
def test_weakened_or_malformed_serialization_is_rejected(self):
source = (ROOT / ".github/workflows/nightly-sign.yml").read_text()
for old, new in (
+8 -1
View File
@@ -20,8 +20,15 @@ $global:SigningFixtureCargoCalls = 0
if (-not [IO.Path]::IsPathRooted($FixtureRoot)) { throw 'use an owned absolute FixtureRoot' }
$root = Join-Path $FixtureRoot ('signing-policy-' + [Guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $root | Out-Null
$version = '0.23.1-nightly.20261121.12345.1.gaaaaaaaaaaaa'
# The fixture mocks Cargo, but nightly.ps1 checks the same source identity a packaging run does:
# the version names this checkout's commit and the run's UTC date, and the tree is clean. Deriving
# them here keeps the fixture reaching the mocked compiler instead of failing in source validation.
$sha = "$(git -C $PSScriptRoot rev-parse HEAD)".Trim()
$runDate = (Get-Date).ToUniversalTime().ToString('yyyyMMdd')
$version = "0.23.1-nightly.$runDate.12345.1.g$($sha.Substring(0, 12))"
$env:DECKCRAFT_VERSION = $version
$env:DECKCRAFT_BUILD_SHA = $sha
$env:DECKCRAFT_BUILD_DATE = "$($runDate.Substring(0, 4))-$($runDate.Substring(4, 2))-$($runDate.Substring(6, 2))"
function Invoke-Build([switch] $BuildOnly) {
$arguments = @{Arch='x64';Version=$version;Target='x86_64-pc-windows-msvc';TargetDir=$root;Dist=(Join-Path $root 'dist')}
if ($BuildOnly) { $arguments.BuildOnly = $true }
+3 -1
View File
@@ -84,7 +84,9 @@ try {
$env:DECKCRAFT_BUILD_CHANNEL = 'nightly-v1'
$env:DECKCRAFT_REQUIRE_WINRES = '1'
$env:CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS = '-C target-feature=+crt-static'
cargo build --release --locked -p deckcraft --target $Target
# The same directory the packaging steps below read from, so a custom -TargetDir cannot leave
# Cargo writing somewhere else and the steps reading a stale executable.
cargo build --release --locked -p deckcraft --target $Target --target-dir $TargetDir
if ($LASTEXITCODE -ne 0) { throw "nightly cargo build failed: $LASTEXITCODE" }
} finally {
$env:DECKCRAFT_BUILD_CHANNEL = $oldChannel