Skip to content
Merged
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: 7 additions & 1 deletion crates/dimcode/tests/cli_daemon_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,13 @@ echo 'Installed package'
}
fs::write(&resume, "continue").unwrap();
}
assert_eq!(terminal.wait().success(), !fail);
let status = terminal.wait();
assert_eq!(
status.success(),
!fail,
"update (fail={fail}) reported {status}; terminal:\n{}",
terminal.transcript
);
let outcome = if fail {
"Error: fixture install failed"
} else {
Expand Down
55 changes: 46 additions & 9 deletions crates/dimcode/tests/cli_flow/staged_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,65 @@ struct Installed {
updater: PathBuf,
prefix: PathBuf,
home: Home,
_root: InstallRoot,
}

/// One flow's fake installation root, under the test target's temporary
/// directory so it shares a filesystem with the built binary. It is removed
/// when the flow ends, including while it is still being built.
struct InstallRoot(PathBuf);

impl InstallRoot {
fn new() -> Self {
let path = PathBuf::from(env!("CARGO_TARGET_TMPDIR"))
.join(format!("dim-cli-update-{}", uuid::Uuid::new_v4()));
fs::create_dir_all(&path).unwrap();
Self(path)
}
}

impl Drop for InstallRoot {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}

/// Puts this test's own `dimcode` at `destination`, inside the package the
/// update runs from. The installation tree lives beside the built binary in
/// the test target's temporary directory, so a link cannot cross a filesystem;
/// one that still cannot be made installs a copy.
fn install_updater(destination: &Path) {
let status = Command::new("install")
.args(["-m", "700", env!("CARGO_BIN_EXE_dimcode")])
let source = Path::new(env!("CARGO_BIN_EXE_dimcode"));
if fs::hard_link(source, destination).is_ok() {
return;
}
let output = Command::new("install")
.args(["-m", "700"])
.arg(source)
.arg(destination)
.status()
.output()
.unwrap();
assert!(
status.success(),
"install updater at {destination:?}: {status}"
output.status.success(),
"install {source:?} at {destination:?} failed ({}):\nstdout: {}\nstderr: {}",
output.status,
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
}

impl Installed {
fn new(version: &str, commands: &[&str]) -> Self {
let home = Home::new();
fs::remove_dir_all(home.0.join("rust")).unwrap();
let prefix = home.0.join("node prefix");
let root = InstallRoot::new();
let prefix = root.0.join("node prefix");
let package = prefix.join("lib/node_modules/dimcode-alpha");
fs::create_dir_all(package.join("bin")).unwrap();
fs::create_dir_all(package.join("node_modules/dimcode-darwin-arm64/bin")).unwrap();
fs::create_dir_all(prefix.join("bin")).unwrap();
// The update runs from inside the package, as the installed command
// does, so the copy it runs from is how it finds the installation.
// does, so the file it runs from is how it finds the installation.
let updater = package.join("bin/dimcode");
install_updater(&updater);
let launcher = package.join("bin/dimcode.mjs");
Expand All @@ -123,6 +157,7 @@ impl Installed {
updater: fs::canonicalize(updater).unwrap(),
prefix: fs::canonicalize(prefix).unwrap(),
home,
_root: root,
}
}

Expand Down Expand Up @@ -289,8 +324,10 @@ printf '%s\n' "$UPDATE_BINS" | while IFS= read -r line; do
done
if [ -n "$UPDATE_NATIVE" ]; then
mkdir -p "$package/bin"
cp "$UPDATE_NATIVE" "$package/bin/dimcode"
chmod 700 "$package/bin/dimcode"
if ! ln "$UPDATE_NATIVE" "$package/bin/dimcode" 2>/dev/null; then
cp "$UPDATE_NATIVE" "$package/bin/dimcode"
chmod 700 "$package/bin/dimcode"
fi
fi
rm -rf "$retired"
echo 'Installed package'
Expand Down