fix: gateway copy keeps its execute bit; packaging test ships a gateway fixture

- install_gateway returned an identical copy before setting its mode, so a
  copy that had lost its execute bit was reused and clients couldn't start
  it. The mode is now checked on both paths (Unix). Test extended: a 0644
  copy with the right bytes comes back executable (fails without the fix;
  run in Linux).
- packaging/linux/test-package-metadata.sh builds packages from a fake
  release folder; it now has a craft-ai-mcp fixture too, since the packages
  install the gateway beside the launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-12 22:12:09 +01:00
1 parent afaaa8f872
commit acbf667f49
3 files changed
+36 -15

No files matched your search

+27 -14
View File
@@ -310,24 +310,37 @@ pub fn install_gateway(src: &Path, dir: &Path) -> Result<PathBuf, String> {
(Err(e), _) => return Err(format!("couldn't read the Craft gateway at {} ({e})", src.display())),
_ => false,
};
if current {
return Ok(dest);
}
let bytes = std::fs::read(src).map_err(|e| format!("couldn't read the Craft gateway at {} ({e})", src.display()))?;
match crate::paths::write_atomic(&dest, &bytes) {
Ok(()) => {}
Err(_) if dest.is_file() => return Ok(dest),
Err(e) => return Err(e),
}
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&dest, std::fs::Permissions::from_mode(0o755))
.map_err(|e| format!("couldn't make {} executable ({e})", dest.display()))?;
if !current {
let bytes = std::fs::read(src).map_err(|e| format!("couldn't read the Craft gateway at {} ({e})", src.display()))?;
match crate::paths::write_atomic(&dest, &bytes) {
Ok(()) => {}
// A client still running the old copy keeps it busy on Windows: keep using it.
Err(_) if dest.is_file() => {}
Err(e) => return Err(e),
}
}
// Also for a copy with the right bytes: one that lost its execute bit couldn't be started.
make_executable(&dest)?;
Ok(dest)
}
/// Make the gateway copy executable for everyone who may run it (`0755`) when it isn't already.
#[cfg(unix)]
fn make_executable(path: &Path) -> Result<(), String> {
use std::os::unix::fs::PermissionsExt;
let mode = std::fs::metadata(path).map_err(|e| format!("couldn't read {} ({e})", path.display()))?.permissions().mode();
if mode & 0o111 == 0o111 {
return Ok(());
}
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o755)).map_err(|e| format!("couldn't make {} executable ({e})", path.display()))
}
/// Windows has no execute bit.
#[cfg(not(unix))]
fn make_executable(_path: &Path) -> Result<(), String> {
Ok(())
}
/// Serialises every change to the app list and the gateway copy. Detection refreshes them on a
/// background thread while Settings may be turning agents off; without this, a refresh that
/// read "on" just before the switch could write the list back after it was removed.
+6 -1
View File
@@ -230,7 +230,12 @@ fn the_gateway_copy_is_executable() {
let src = src_dir.path().join("craft-ai-mcp");
std::fs::write(&src, b"#!/bin/sh\n").unwrap();
let copy = install_gateway(&src, dir.path()).unwrap();
assert_eq!(std::fs::metadata(copy).unwrap().permissions().mode() & 0o111, 0o111);
assert_eq!(std::fs::metadata(&copy).unwrap().permissions().mode() & 0o111, 0o111);
// A copy with the right bytes that lost its execute bit gets it back instead of being reused
// as it is: clients couldn't start it.
std::fs::set_permissions(&copy, std::fs::Permissions::from_mode(0o644)).unwrap();
let again = install_gateway(&src, dir.path()).unwrap();
assert_eq!(std::fs::metadata(again).unwrap().permissions().mode() & 0o111, 0o111);
}
#[test]
+3
View File
@@ -16,6 +16,9 @@ check_packages() {
mkdir -p "$work/target/$target/release"
printf '#!/bin/sh\necho "ArtCraft Launcher packaging fixture"\n' >"$work/target/$target/release/artcraft-launcher"
chmod +x "$work/target/$target/release/artcraft-launcher"
# The packages ship the craft-ai-mcp gateway beside the launcher (Settings › AI agents).
printf '#!/bin/sh\necho "craft-ai-mcp packaging fixture"\n' >"$work/target/$target/release/craft-ai-mcp"
chmod +x "$work/target/$target/release/craft-ai-mcp"
# A set cross target skips the version smoke execution; no target binary is run.
(
unset EMULATOR