Skip to content
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ apps, which nobody could connect there. An app's own page, reached from an older
available yet and that an administrator has to finish setting it up, instead of naming the setting.
The administrator's page for the app still names `COMPOSIO_API_KEY`.

### A new desktop install of v0.2.0 gets past Install again

A desktop app built from `main` stopped every new install at "Installing OpenBot" with
`shared/package.json: No such file or directory`. It had started reading `shared` and `toolkit` as
packages, which v0.2.0 does not have: there `shared` is plain source and there is no `toolkit`. It now
reads them only when the release includes them.

### A new desktop install starts its server again

A desktop install of v0.2.0 stopped at start with `server stopped straight away (exit status: 1)` and
Expand Down
42 changes: 40 additions & 2 deletions desktop/src-tauri/src/preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ pub const FILE: &str = ".openbot-prepared.json";
const DEPENDENCIES: &str = ".openbot-dependencies.json";
const LAUNCH: &str = ".openbot-launched.json";
const PACKAGES: [&str; 6] = ["", "server", "app", "worker", "shared", "toolkit"];
/// Packages a release has only since #784. v0.2.0, still the latest release when this desktop was
/// built, has `shared` as plain source and no `toolkit`; requiring their manifests failed every new
/// install with "shared/package.json: No such file or directory".
const LATER_PACKAGES: [&str; 2] = ["shared", "toolkit"];

/// The packages this release actually has: every one in `PACKAGES`, less a later one it predates.
fn packages(root: &Path) -> impl Iterator<Item = &'static str> + '_ {
PACKAGES.into_iter().filter(move |package| {
!LATER_PACKAGES.contains(package) || root.join(package).join("package.json").is_file()
})
}

#[derive(Serialize, Deserialize)]
struct Dependencies {
Expand Down Expand Up @@ -124,7 +135,7 @@ fn dependency_fingerprint(root: &Path) -> Result<String, Problem> {
hash_files(
root,
std::iter::once(PathBuf::from("bun.lock"))
.chain(PACKAGES.map(|path| Path::new(path).join("package.json"))),
.chain(packages(root).map(|path| Path::new(path).join("package.json"))),
)
}

Expand Down Expand Up @@ -165,7 +176,7 @@ pub fn invalidate(root: &Path) -> Result<(), Problem> {
/// Record resolved package manifests, not just the existence of a partial node_modules directory.
fn package_files(root: &Path) -> Result<Vec<PathBuf>, Problem> {
let mut files = BTreeSet::new();
for package in PACKAGES {
for package in packages(root) {
let directory = root.join(package);
let manifest: serde_json::Value = serde_json::from_slice(
&std::fs::read(directory.join("package.json")).map_err(|e| required(e.to_string()))?,
Expand Down Expand Up @@ -354,6 +365,33 @@ pub fn image_settings(
mod tests {
use super::*;

#[test]
fn a_release_from_before_the_toolkit_needs_no_shared_or_toolkit_manifest() {
let root = crate::test_support::temp_root("preparation-v020-layout");
for package in ["", "server", "app", "worker"] {
std::fs::create_dir_all(root.join(package)).unwrap();
std::fs::write(root.join(package).join("package.json"), "{}").unwrap();
}
// v0.2.0: `shared` is source with no manifest, and there is no `toolkit`.
std::fs::create_dir_all(root.join("shared")).unwrap();
assert_eq!(
packages(&root).collect::<Vec<_>>(),
["", "server", "app", "worker"]
);
std::fs::write(root.join("bun.lock"), "lock").unwrap();
assert!(dependency_fingerprint(&root).is_ok());
assert!(package_files(&root).is_ok());
// A release that has them is held to them.
for package in ["shared", "toolkit"] {
std::fs::create_dir_all(root.join(package)).unwrap();
std::fs::write(root.join(package).join("package.json"), "{}").unwrap();
}
assert_eq!(packages(&root).count(), PACKAGES.len());
// The packages every release has stay required.
std::fs::remove_file(root.join("server").join("package.json")).unwrap();
assert!(dependency_fingerprint(&root).is_err());
}

struct Fixture {
root: PathBuf,
bun: PathBuf,
Expand Down
Loading