feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
|
|
use anyhow::Context;
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
use weft_ipc_types::manifest::{Manifest, entry_path};
|
|
|
|
|
use weft_ipc_types::package::ImageFiles;
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
|
|
|
|
|
|
match args.get(1).map(String::as_str) {
|
|
|
|
|
Some("check") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack check <dir>")?;
|
|
|
|
|
let result = check_package(Path::new(dir))?;
|
|
|
|
|
println!("{result}");
|
|
|
|
|
}
|
|
|
|
|
Some("info") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack info <dir>")?;
|
|
|
|
|
let manifest = load_manifest(Path::new(dir))?;
|
|
|
|
|
print_info(&manifest);
|
|
|
|
|
}
|
2026-03-11 08:45:31 +00:00
|
|
|
Some("install") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack install <dir>")?;
|
|
|
|
|
install_package(Path::new(dir))?;
|
|
|
|
|
}
|
2026-03-11 08:54:39 +00:00
|
|
|
Some("uninstall") => {
|
|
|
|
|
let app_id = args.get(2).context("usage: weft-pack uninstall <app_id>")?;
|
|
|
|
|
uninstall_package(app_id)?;
|
|
|
|
|
}
|
2026-03-11 10:57:08 +00:00
|
|
|
Some("list") => {
|
|
|
|
|
list_installed();
|
|
|
|
|
}
|
2026-03-11 14:39:18 +00:00
|
|
|
Some("build-image") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack build-image <dir>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str());
|
|
|
|
|
build_image(Path::new(dir), out.map(Path::new))?;
|
|
|
|
|
}
|
|
|
|
|
Some("build-verity") => {
|
|
|
|
|
let img = args.get(2).context("usage: weft-pack build-verity <img>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str());
|
|
|
|
|
build_verity(Path::new(img), out.map(Path::new))?;
|
|
|
|
|
}
|
2026-03-11 14:37:53 +00:00
|
|
|
Some("bundle") => {
|
|
|
|
|
let dir = args.get(2).context("usage: weft-pack bundle <dir>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str());
|
|
|
|
|
bundle_package(Path::new(dir), out.map(Path::new))?;
|
|
|
|
|
}
|
|
|
|
|
Some("unbundle") => {
|
|
|
|
|
let archive = args.get(2).context("usage: weft-pack unbundle <archive>")?;
|
|
|
|
|
let out = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--out")
|
|
|
|
|
.map(|w| w[1].as_str())
|
|
|
|
|
.unwrap_or(".");
|
|
|
|
|
unbundle_package(Path::new(archive), Path::new(out))?;
|
|
|
|
|
}
|
2026-03-11 14:29:49 +00:00
|
|
|
Some("generate-key") => {
|
|
|
|
|
let out = args.get(2).map(String::as_str).unwrap_or(".");
|
|
|
|
|
generate_key(Path::new(out))?;
|
|
|
|
|
}
|
|
|
|
|
Some("sign") => {
|
|
|
|
|
let dir = args
|
|
|
|
|
.get(2)
|
|
|
|
|
.context("usage: weft-pack sign <dir> --key <keyfile>")?;
|
|
|
|
|
let key = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--key")
|
|
|
|
|
.map(|w| &w[1])
|
|
|
|
|
.context("missing --key <keyfile>")?;
|
|
|
|
|
sign_package(Path::new(dir), Path::new(key))?;
|
|
|
|
|
}
|
|
|
|
|
Some("verify") => {
|
|
|
|
|
let dir = args
|
|
|
|
|
.get(2)
|
|
|
|
|
.context("usage: weft-pack verify <dir> --key <pubkeyfile>")?;
|
|
|
|
|
let key = args
|
|
|
|
|
.windows(2)
|
|
|
|
|
.find(|w| w[0] == "--key")
|
|
|
|
|
.map(|w| &w[1])
|
|
|
|
|
.context("missing --key <pubkeyfile>")?;
|
|
|
|
|
let ok = verify_package(Path::new(dir), Path::new(key))?;
|
|
|
|
|
if ok {
|
|
|
|
|
println!("OK");
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("INVALID signature");
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
_ => {
|
|
|
|
|
eprintln!("usage:");
|
2026-03-11 14:29:49 +00:00
|
|
|
eprintln!(" weft-pack check <dir> validate a package directory");
|
|
|
|
|
eprintln!(" weft-pack info <dir> print package metadata");
|
|
|
|
|
eprintln!(" weft-pack install <dir> install package to app store");
|
|
|
|
|
eprintln!(" weft-pack uninstall <app_id> remove installed package");
|
|
|
|
|
eprintln!(" weft-pack list list installed packages");
|
2026-03-11 14:43:59 +00:00
|
|
|
eprintln!(
|
|
|
|
|
" weft-pack build-image <dir> [--out <img>] create EROFS image with mkfs.erofs"
|
|
|
|
|
);
|
2026-03-11 14:39:18 +00:00
|
|
|
eprintln!(" weft-pack build-verity <img> [--out <hash>] add dm-verity hash tree");
|
2026-03-11 14:37:53 +00:00
|
|
|
eprintln!(" weft-pack bundle <dir> [--out <dir>] create .app.tar.zst archive");
|
|
|
|
|
eprintln!(" weft-pack unbundle <archive> [--out <dir>] extract .app.tar.zst");
|
2026-03-11 14:29:49 +00:00
|
|
|
eprintln!(" weft-pack generate-key [<outdir>] generate Ed25519 keypair");
|
|
|
|
|
eprintln!(" weft-pack sign <dir> --key <key> sign package with private key");
|
|
|
|
|
eprintln!(" weft-pack verify <dir> --key <pub> verify package signature");
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn check_package(dir: &Path) -> anyhow::Result<String> {
|
|
|
|
|
let mut errors: Vec<String> = Vec::new();
|
|
|
|
|
|
|
|
|
|
let manifest = match load_manifest(dir) {
|
|
|
|
|
Ok(m) => Some(m),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
errors.push(format!("wapp.toml: {e}"));
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
// Earlier versions kept app data in `<package>/data`; the name stays
|
|
|
|
|
// reserved so package content is never mistaken for user data.
|
|
|
|
|
if std::fs::symlink_metadata(dir.join("data")).is_ok() {
|
|
|
|
|
errors.push("a top-level 'data' entry is reserved and cannot be part of a package".into());
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
if let Some(ref m) = manifest {
|
fix(runtime): close fetch and preopen gaps in grant enforcement
A component with a host-specific fetch grant could reach another origin
by setting its own Host header, and could inject request lines through
the method string, which ureq writes unvalidated. Fetch now accepts only
standard methods and refuses Host, framing and hop-by-hop headers. Fetch
grants accept canonical DNS names and dotted IPv4 addresses only, so a
grant can never be written in a form that silently never matches.
--preopen split host and guest at the first `::`, so a host path
containing `::` widened the preopened directory; it now splits from the
right, and appd refuses host paths that are not UTF-8 or contain `::`.
appd validated capabilities one at a time, creating the data directory
before a later capability was refused, and required HOME even for
packages without filesystem capabilities. It now checks every capability
first, resolves host directories only when needed, validates the app ID
with the rule weft-pack uses (now shared in weft_ipc_types::package), and
reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is
read as a shell would: the last assignment wins, $HOME must be followed
by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is
not used.
The grants probe now also overwrites, renames, removes and creates
directories in read-only data, and sends a forged Host header, an
injected method and a file: URL; it fails when directory permissions of
a read-only preopen are widened or the header check is removed. A new
CI job builds the runtime with its engine and fetch support and runs the
check. The mount test that sets WEFT_APP_STORE now holds the env lock.
Package images are still located separately from directory installs;
deriving grants from the verified image is part of resolving one package
descriptor.
2026-10-09 08:25:40 +00:00
|
|
|
if !weft_ipc_types::package::is_valid_app_id(&m.package.id) {
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
errors.push(format!(
|
|
|
|
|
"package.id '{}' does not match required pattern",
|
|
|
|
|
m.package.id
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
if m.package.name.is_empty() {
|
|
|
|
|
errors.push("package.name is empty".into());
|
|
|
|
|
}
|
|
|
|
|
if m.package.name.len() > 64 {
|
|
|
|
|
errors.push(format!(
|
|
|
|
|
"package.name exceeds 64 characters ({})",
|
|
|
|
|
m.package.name.len()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
match entry_path(dir, &m.runtime.module) {
|
|
|
|
|
Err(e) => errors.push(format!("runtime.module: {e}")),
|
|
|
|
|
Ok(wasm_path) if !is_wasm_module(&wasm_path) => errors.push(format!(
|
2026-03-11 09:21:43 +00:00
|
|
|
"runtime.module '{}' is not a valid Wasm module (bad magic bytes)",
|
|
|
|
|
wasm_path.display()
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
)),
|
|
|
|
|
Ok(_) => {}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
if let Err(e) = entry_path(dir, &m.ui.entry) {
|
|
|
|
|
errors.push(format!("ui.entry: {e}"));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
2026-03-11 17:33:05 +00:00
|
|
|
|
|
|
|
|
for cap in m.package.capabilities.iter().flatten() {
|
fix(runtime): enforce effective capability grants per session
Every host import was registered and callable whatever the package
declared, read-only directory capabilities were preopened read-write,
and appd launched packages whose capabilities it could not satisfy. The
fetch import also could not be linked: the host returned a tuple where
the WIT declares the response record, so any component importing
weft:app/fetch failed to instantiate.
One capability vocabulary now lives in weft_ipc_types::capability and
is used by weft-pack, weft-appd and weft-runtime. weft-appd derives a
session's grants once, before the session exists, and refuses the launch
with error 403 when a capability is unknown, unsupported (hw:gpu:*) or
unsatisfiable (documents without an XDG documents directory). The
documents directory now comes from user-dirs.dirs instead of a guessed
~/Documents.
The runtime receives grants explicitly (--grant CAP, --preopen
HOST::GUEST::ro|rw), preopens read-only directories read-only, and checks
the grant on every notifications, clipboard and fetch call. Fetch accepts
only http and https to granted hosts, returns redirects and HTTP error
statuses as responses instead of following or failing them, and bounds
connect time, total time and response size. The file portal takes
read-only directories with --allow-read and refuses writes there.
tests/runtime/check_grants.py runs the real runtime on a probe component
under each kind of grant and checks the outcome of every operation; it
fails when read-only data is writable or an import ignores its grant.
The appd dispatch tests that read WEFT_RUNTIME_BIN now hold the env lock
shared with the tests that set it.
2026-10-09 08:08:58 +00:00
|
|
|
if let Err(e) = cap.parse::<weft_ipc_types::capability::Capability>() {
|
|
|
|
|
errors.push(e.to_string());
|
2026-03-11 17:33:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if errors.is_empty() {
|
|
|
|
|
Ok("OK".into())
|
|
|
|
|
} else {
|
|
|
|
|
Err(anyhow::anyhow!("{}", errors.join("\n")))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_manifest(dir: &Path) -> anyhow::Result<Manifest> {
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
Ok(Manifest::read(dir)?)
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn print_info(m: &Manifest) {
|
|
|
|
|
println!("id: {}", m.package.id);
|
|
|
|
|
println!("name: {}", m.package.name);
|
|
|
|
|
println!("version: {}", m.package.version);
|
|
|
|
|
if let Some(ref d) = m.package.description {
|
|
|
|
|
println!("desc: {d}");
|
|
|
|
|
}
|
|
|
|
|
if let Some(ref a) = m.package.author {
|
|
|
|
|
println!("author: {a}");
|
|
|
|
|
}
|
|
|
|
|
println!("module: {}", m.runtime.module);
|
|
|
|
|
println!("ui: {}", m.ui.entry);
|
2026-03-11 14:20:51 +00:00
|
|
|
if let Some(ref caps) = m.package.capabilities {
|
|
|
|
|
for cap in caps {
|
|
|
|
|
println!("cap: {cap}");
|
|
|
|
|
}
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:21:43 +00:00
|
|
|
fn is_wasm_module(path: &Path) -> bool {
|
|
|
|
|
const MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6D];
|
|
|
|
|
let mut buf = [0u8; 4];
|
|
|
|
|
match std::fs::File::open(path) {
|
|
|
|
|
Ok(mut f) => {
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
f.read_exact(&mut buf)
|
|
|
|
|
.map(|_| buf == MAGIC)
|
|
|
|
|
.unwrap_or(false)
|
|
|
|
|
}
|
|
|
|
|
Err(_) => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:45:31 +00:00
|
|
|
fn resolve_install_root() -> anyhow::Result<PathBuf> {
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
if let Ok(explicit) = std::env::var("WEFT_APP_STORE") {
|
2026-03-11 08:45:31 +00:00
|
|
|
return Ok(PathBuf::from(explicit));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
if let Ok(home) = std::env::var("HOME") {
|
2026-03-11 08:45:31 +00:00
|
|
|
return Ok(PathBuf::from(home)
|
|
|
|
|
.join(".local")
|
|
|
|
|
.join("share")
|
|
|
|
|
.join("weft")
|
|
|
|
|
.join("apps"));
|
|
|
|
|
}
|
|
|
|
|
anyhow::bail!("cannot determine install root: HOME and WEFT_APP_STORE are both unset")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:49:34 +00:00
|
|
|
fn install_package(path: &Path) -> anyhow::Result<()> {
|
2026-03-11 08:54:39 +00:00
|
|
|
let root = resolve_install_root()?;
|
2026-03-11 14:49:34 +00:00
|
|
|
install_package_to(path, &root)
|
2026-03-11 08:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:49:34 +00:00
|
|
|
fn install_package_to(path: &Path, store_root: &Path) -> anyhow::Result<()> {
|
|
|
|
|
let dir_buf;
|
|
|
|
|
let dir: &Path = if path.extension().is_some_and(|e| e == "zst" || e == "tar")
|
|
|
|
|
|| path.to_string_lossy().ends_with(".app.tar.zst")
|
|
|
|
|
{
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!(
|
|
|
|
|
"weft-install-{}",
|
|
|
|
|
std::time::SystemTime::now()
|
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
.subsec_nanos()
|
|
|
|
|
));
|
|
|
|
|
std::fs::create_dir_all(&tmp)
|
|
|
|
|
.with_context(|| format!("create temp dir {}", tmp.display()))?;
|
|
|
|
|
unbundle_package(path, &tmp)?;
|
|
|
|
|
let name = path
|
|
|
|
|
.file_name()
|
|
|
|
|
.and_then(|n| n.to_str())
|
|
|
|
|
.and_then(|n| n.strip_suffix(".app.tar.zst"))
|
|
|
|
|
.context("cannot determine app_id from archive filename")?;
|
|
|
|
|
dir_buf = tmp.join(name);
|
|
|
|
|
&dir_buf
|
|
|
|
|
} else {
|
|
|
|
|
path
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-11 08:45:31 +00:00
|
|
|
check_package(dir)?;
|
|
|
|
|
let manifest = load_manifest(dir)?;
|
|
|
|
|
let app_id = &manifest.package.id;
|
|
|
|
|
let dest = store_root.join(app_id);
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
// An earlier weft-appd could leave only app data, or an empty directory,
|
|
|
|
|
// where the package now goes; move the data to its own location so it
|
|
|
|
|
// neither blocks nor joins the package.
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
if dest.is_dir() && only_holds_app_data(&dest)? {
|
2026-10-09 09:01:28 +00:00
|
|
|
if std::fs::symlink_metadata(dest.join("data")).is_ok() && is_user_store(store_root) {
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
move_app_data_out(app_id, &dest)?;
|
|
|
|
|
}
|
|
|
|
|
let _ = std::fs::remove_dir(&dest);
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
}
|
2026-03-11 08:45:31 +00:00
|
|
|
if dest.exists() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"package '{}' is already installed at {}; remove it first",
|
|
|
|
|
app_id,
|
|
|
|
|
dest.display()
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
);
|
|
|
|
|
}
|
2026-03-11 08:45:31 +00:00
|
|
|
copy_dir(dir, &dest)
|
|
|
|
|
.with_context(|| format!("copy {} -> {}", dir.display(), dest.display()))?;
|
|
|
|
|
println!("installed {} -> {}", app_id, dest.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:54:39 +00:00
|
|
|
fn uninstall_package(app_id: &str) -> anyhow::Result<()> {
|
|
|
|
|
let root = resolve_install_root()?;
|
|
|
|
|
uninstall_package_from(app_id, &root)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn uninstall_package_from(app_id: &str, store_root: &Path) -> anyhow::Result<()> {
|
fix(runtime): close fetch and preopen gaps in grant enforcement
A component with a host-specific fetch grant could reach another origin
by setting its own Host header, and could inject request lines through
the method string, which ureq writes unvalidated. Fetch now accepts only
standard methods and refuses Host, framing and hop-by-hop headers. Fetch
grants accept canonical DNS names and dotted IPv4 addresses only, so a
grant can never be written in a form that silently never matches.
--preopen split host and guest at the first `::`, so a host path
containing `::` widened the preopened directory; it now splits from the
right, and appd refuses host paths that are not UTF-8 or contain `::`.
appd validated capabilities one at a time, creating the data directory
before a later capability was refused, and required HOME even for
packages without filesystem capabilities. It now checks every capability
first, resolves host directories only when needed, validates the app ID
with the rule weft-pack uses (now shared in weft_ipc_types::package), and
reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is
read as a shell would: the last assignment wins, $HOME must be followed
by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is
not used.
The grants probe now also overwrites, renames, removes and creates
directories in read-only data, and sends a forged Host header, an
injected method and a file: URL; it fails when directory permissions of
a read-only preopen are widened or the header check is removed. A new
CI job builds the runtime with its engine and fetch support and runs the
check. The mount test that sets WEFT_APP_STORE now holds the env lock.
Package images are still located separately from directory installs;
deriving grants from the verified image is part of resolving one package
descriptor.
2026-10-09 08:25:40 +00:00
|
|
|
if !weft_ipc_types::package::is_valid_app_id(app_id) {
|
2026-03-11 08:54:39 +00:00
|
|
|
anyhow::bail!("'{}' is not a valid app ID", app_id);
|
|
|
|
|
}
|
|
|
|
|
let target = store_root.join(app_id);
|
|
|
|
|
if !target.exists() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"package '{}' is not installed at {}",
|
|
|
|
|
app_id,
|
|
|
|
|
target.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-10-09 09:01:28 +00:00
|
|
|
// A `data` directory is never removed with the package: packages cannot
|
|
|
|
|
// ship one, so it holds app data from an earlier version. It is moved to
|
|
|
|
|
// the app data directory when this is the user store and the package
|
|
|
|
|
// declares app data (or its manifest cannot be read); otherwise uninstall
|
|
|
|
|
// stops and leaves everything in place.
|
|
|
|
|
if std::fs::symlink_metadata(target.join("data")).is_ok() {
|
|
|
|
|
let may_hold_app_data = load_manifest(&target).map_or(true, |m| declares_app_data(&m));
|
|
|
|
|
if !(may_hold_app_data && is_user_store(store_root)) {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"{} contains a 'data' directory that may hold app data; move it aside before \
|
|
|
|
|
uninstalling",
|
|
|
|
|
target.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
move_app_data_out(app_id, &target)?;
|
|
|
|
|
}
|
2026-10-09 09:01:28 +00:00
|
|
|
// Moving the data removes a package directory it leaves empty.
|
|
|
|
|
match std::fs::remove_dir_all(&target) {
|
|
|
|
|
Err(e) if e.kind() != std::io::ErrorKind::NotFound => {
|
|
|
|
|
return Err(e).with_context(|| format!("remove {}", target.display()));
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
2026-03-11 08:54:39 +00:00
|
|
|
println!("uninstalled {}", app_id);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
/// Whether a package directory is empty or contains nothing but `data`.
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
fn only_holds_app_data(package_dir: &Path) -> anyhow::Result<bool> {
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let entries = std::fs::read_dir(package_dir)
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
.with_context(|| format!("read {}", package_dir.display()))?
|
|
|
|
|
.map(|entry| entry.map(|e| e.file_name()))
|
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
Ok(entries.is_empty() || entries == ["data"])
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
/// Whether the manifest declares an app-data capability; only such apps
|
|
|
|
|
/// had data kept in the package directory.
|
|
|
|
|
fn declares_app_data(manifest: &Manifest) -> bool {
|
|
|
|
|
use weft_ipc_types::capability::Capability;
|
|
|
|
|
manifest
|
|
|
|
|
.package
|
|
|
|
|
.capabilities
|
|
|
|
|
.iter()
|
|
|
|
|
.flatten()
|
|
|
|
|
.any(|c| matches!(c.parse(), Ok(Capability::AppData(_))))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 09:01:28 +00:00
|
|
|
/// Whether `store_root` is the user package store, where earlier versions of
|
|
|
|
|
/// weft-appd kept app data, however the path is spelled.
|
|
|
|
|
fn is_user_store(store_root: &Path) -> bool {
|
|
|
|
|
let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
let user_store = home.join(".local/share/weft/apps");
|
|
|
|
|
match (
|
|
|
|
|
std::fs::canonicalize(store_root),
|
|
|
|
|
std::fs::canonicalize(user_store),
|
|
|
|
|
) {
|
|
|
|
|
(Ok(a), Ok(b)) => a == b,
|
|
|
|
|
_ => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Moves app data that an earlier weft-appd kept in `<package_dir>/data` in
|
|
|
|
|
/// the user store to the app's data directory, which package operations
|
|
|
|
|
/// never remove. Fails, changing nothing, if the data cannot be moved.
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
fn move_app_data_out(app_id: &str, package_dir: &Path) -> anyhow::Result<()> {
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
use weft_ipc_types::package::{
|
2026-10-09 09:01:28 +00:00
|
|
|
Migration, app_data_dir, data_home, make_private, migrate_app_data,
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
};
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let legacy = package_dir.join("data");
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let data_home = data_home().context("cannot locate the data home to keep app data")?;
|
|
|
|
|
let target = app_data_dir(&data_home, app_id);
|
|
|
|
|
if migrate_app_data(&legacy, &target).with_context(|| format!("keep app data of {app_id}"))?
|
|
|
|
|
== Migration::Moved
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
{
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
make_private(&target).with_context(|| format!("restrict {}", target.display()))?;
|
|
|
|
|
println!("app data kept at {}", target.display());
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 10:57:08 +00:00
|
|
|
fn list_installed_roots() -> Vec<PathBuf> {
|
|
|
|
|
if let Ok(explicit) = std::env::var("WEFT_APP_STORE") {
|
|
|
|
|
return vec![PathBuf::from(explicit)];
|
|
|
|
|
}
|
|
|
|
|
let mut roots = Vec::new();
|
|
|
|
|
if let Ok(home) = std::env::var("HOME") {
|
|
|
|
|
roots.push(
|
|
|
|
|
PathBuf::from(home)
|
|
|
|
|
.join(".local")
|
|
|
|
|
.join("share")
|
|
|
|
|
.join("weft")
|
|
|
|
|
.join("apps"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
roots.push(PathBuf::from("/usr/share/weft/apps"));
|
|
|
|
|
roots
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn list_installed() {
|
|
|
|
|
let mut seen = std::collections::HashSet::new();
|
|
|
|
|
let mut count = 0usize;
|
|
|
|
|
for root in list_installed_roots() {
|
|
|
|
|
let Ok(entries) = std::fs::read_dir(&root) else {
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
let mut pkgs: Vec<(String, String, String)> = Vec::new();
|
|
|
|
|
for entry in entries.flatten() {
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
let Ok(m) = Manifest::read(&entry.path()) else {
|
2026-03-11 10:57:08 +00:00
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
if seen.insert(m.package.id.clone()) {
|
|
|
|
|
pkgs.push((m.package.id, m.package.name, m.package.version));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pkgs.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
|
for (id, name, version) in pkgs {
|
|
|
|
|
println!("{id} {name} {version}");
|
|
|
|
|
count += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if count == 0 {
|
|
|
|
|
println!("no packages installed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:45:31 +00:00
|
|
|
fn copy_dir(src: &Path, dst: &Path) -> anyhow::Result<()> {
|
|
|
|
|
std::fs::create_dir_all(dst)?;
|
|
|
|
|
for entry in std::fs::read_dir(src)? {
|
|
|
|
|
let entry = entry?;
|
|
|
|
|
let src_path = entry.path();
|
|
|
|
|
let dst_path = dst.join(entry.file_name());
|
|
|
|
|
if src_path.is_dir() {
|
|
|
|
|
copy_dir(&src_path, &dst_path)?;
|
|
|
|
|
} else {
|
|
|
|
|
std::fs::copy(&src_path, &dst_path)
|
|
|
|
|
.with_context(|| format!("copy {}", src_path.display()))?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:39:18 +00:00
|
|
|
fn build_image(dir: &Path, out_path: Option<&Path>) -> anyhow::Result<()> {
|
|
|
|
|
let manifest = load_manifest(dir)?;
|
|
|
|
|
let app_id = &manifest.package.id;
|
|
|
|
|
let output = match out_path {
|
|
|
|
|
Some(p) => p.to_path_buf(),
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
None => ImageFiles::in_store(Path::new(""), app_id).image,
|
2026-03-11 14:39:18 +00:00
|
|
|
};
|
|
|
|
|
if output.exists() {
|
|
|
|
|
anyhow::bail!("{} already exists", output.display());
|
|
|
|
|
}
|
|
|
|
|
let status = std::process::Command::new("mkfs.erofs")
|
|
|
|
|
.arg(&output)
|
|
|
|
|
.arg(dir)
|
|
|
|
|
.status()
|
|
|
|
|
.context("spawn mkfs.erofs; ensure erofs-utils is installed")?;
|
|
|
|
|
if !status.success() {
|
|
|
|
|
anyhow::bail!("mkfs.erofs failed with status {status}");
|
|
|
|
|
}
|
|
|
|
|
println!("image: {}", output.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn build_verity(img: &Path, hash_out: Option<&Path>) -> anyhow::Result<()> {
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
let companions = ImageFiles::for_image(img);
|
|
|
|
|
let hash_path = hash_out
|
|
|
|
|
.map(|p| p.to_path_buf())
|
|
|
|
|
.unwrap_or(companions.hash_tree);
|
2026-03-11 14:39:18 +00:00
|
|
|
if hash_path.exists() {
|
|
|
|
|
anyhow::bail!("{} already exists", hash_path.display());
|
|
|
|
|
}
|
|
|
|
|
let output = std::process::Command::new("veritysetup")
|
2026-03-11 14:43:59 +00:00
|
|
|
.args([
|
|
|
|
|
"format",
|
|
|
|
|
&img.to_string_lossy(),
|
|
|
|
|
&hash_path.to_string_lossy(),
|
|
|
|
|
])
|
2026-03-11 14:39:18 +00:00
|
|
|
.output()
|
|
|
|
|
.context("spawn veritysetup; ensure cryptsetup-bin is installed")?;
|
|
|
|
|
if !output.status.success() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"veritysetup failed: {}",
|
|
|
|
|
String::from_utf8_lossy(&output.stderr)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let root_hash = stdout
|
|
|
|
|
.lines()
|
|
|
|
|
.find(|l| l.starts_with("Root hash:"))
|
|
|
|
|
.context("root hash not found in veritysetup output")?;
|
|
|
|
|
let hash_value = root_hash.trim_start_matches("Root hash:").trim();
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
let roothash_path = companions.root_hash;
|
2026-03-11 14:39:18 +00:00
|
|
|
std::fs::write(&roothash_path, hash_value)
|
|
|
|
|
.with_context(|| format!("write {}", roothash_path.display()))?;
|
|
|
|
|
println!("hash image: {}", hash_path.display());
|
|
|
|
|
println!("root hash: {hash_value}");
|
|
|
|
|
println!("roothash: {}", roothash_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:37:53 +00:00
|
|
|
fn bundle_package(dir: &Path, out_dir: Option<&Path>) -> anyhow::Result<()> {
|
|
|
|
|
let manifest = load_manifest(dir)?;
|
|
|
|
|
let app_id = &manifest.package.id;
|
|
|
|
|
let archive_name = format!("{app_id}.app.tar.zst");
|
|
|
|
|
let dest_dir = out_dir.unwrap_or_else(|| Path::new("."));
|
|
|
|
|
let archive_path = dest_dir.join(&archive_name);
|
|
|
|
|
if archive_path.exists() {
|
|
|
|
|
anyhow::bail!("{} already exists", archive_path.display());
|
|
|
|
|
}
|
|
|
|
|
let file = std::fs::File::create(&archive_path)
|
|
|
|
|
.with_context(|| format!("create {}", archive_path.display()))?;
|
|
|
|
|
let encoder = zstd::Encoder::new(file, 0)
|
|
|
|
|
.context("create zstd encoder")?
|
|
|
|
|
.auto_finish();
|
|
|
|
|
let mut tar = tar::Builder::new(encoder);
|
|
|
|
|
tar.follow_symlinks(false);
|
|
|
|
|
tar.append_dir_all(app_id, dir)
|
|
|
|
|
.with_context(|| format!("append {} to archive", dir.display()))?;
|
|
|
|
|
tar.finish().context("finish tar archive")?;
|
|
|
|
|
println!("bundled: {}", archive_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn unbundle_package(archive: &Path, out_dir: &Path) -> anyhow::Result<()> {
|
|
|
|
|
let file =
|
|
|
|
|
std::fs::File::open(archive).with_context(|| format!("open {}", archive.display()))?;
|
|
|
|
|
let decoder = zstd::Decoder::new(file).context("create zstd decoder")?;
|
|
|
|
|
let mut tar = tar::Archive::new(decoder);
|
|
|
|
|
tar.unpack(out_dir)
|
|
|
|
|
.with_context(|| format!("unpack to {}", out_dir.display()))?;
|
|
|
|
|
println!("unbundled: {} -> {}", archive.display(), out_dir.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:29:49 +00:00
|
|
|
fn collect_bundle_files(
|
|
|
|
|
base: &Path,
|
|
|
|
|
dir: &Path,
|
|
|
|
|
entries: &mut Vec<(String, [u8; 32])>,
|
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
|
use sha2::{Digest, Sha256};
|
|
|
|
|
for entry in std::fs::read_dir(dir).with_context(|| format!("read dir {}", dir.display()))? {
|
|
|
|
|
let entry = entry?;
|
|
|
|
|
let path = entry.path();
|
|
|
|
|
let rel = path
|
|
|
|
|
.strip_prefix(base)
|
|
|
|
|
.context("strip prefix")?
|
|
|
|
|
.to_string_lossy()
|
|
|
|
|
.into_owned();
|
|
|
|
|
if rel == "signature.sig" {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if path.is_dir() {
|
|
|
|
|
collect_bundle_files(base, &path, entries)?;
|
|
|
|
|
} else {
|
|
|
|
|
let contents =
|
|
|
|
|
std::fs::read(&path).with_context(|| format!("read {}", path.display()))?;
|
|
|
|
|
let hash: [u8; 32] = Sha256::digest(&contents).into();
|
|
|
|
|
entries.push((rel, hash));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn canonical_bundle_hash(dir: &Path) -> anyhow::Result<[u8; 32]> {
|
|
|
|
|
use sha2::{Digest, Sha256};
|
|
|
|
|
let mut entries: Vec<(String, [u8; 32])> = Vec::new();
|
|
|
|
|
collect_bundle_files(dir, dir, &mut entries)?;
|
|
|
|
|
entries.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
|
|
let mut canonical = String::new();
|
|
|
|
|
for (path, hash) in &entries {
|
|
|
|
|
canonical.push_str(&format!("{path}\t{}\n", hex::encode(hash)));
|
|
|
|
|
}
|
|
|
|
|
Ok(Sha256::digest(canonical.as_bytes()).into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn generate_key(output_dir: &Path) -> anyhow::Result<()> {
|
|
|
|
|
use ed25519_dalek::SigningKey;
|
|
|
|
|
use rand::rngs::OsRng;
|
|
|
|
|
let key_path = output_dir.join("weft-sign.key");
|
|
|
|
|
let pub_path = output_dir.join("weft-sign.pub");
|
|
|
|
|
if key_path.exists() || pub_path.exists() {
|
|
|
|
|
anyhow::bail!(
|
|
|
|
|
"key files already exist in {}; remove them first",
|
|
|
|
|
output_dir.display()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
let signing_key = SigningKey::generate(&mut OsRng);
|
|
|
|
|
let verifying_key = signing_key.verifying_key();
|
|
|
|
|
std::fs::create_dir_all(output_dir)
|
|
|
|
|
.with_context(|| format!("create {}", output_dir.display()))?;
|
|
|
|
|
std::fs::write(&key_path, hex::encode(signing_key.to_bytes()))
|
|
|
|
|
.with_context(|| format!("write {}", key_path.display()))?;
|
|
|
|
|
std::fs::write(&pub_path, hex::encode(verifying_key.to_bytes()))
|
|
|
|
|
.with_context(|| format!("write {}", pub_path.display()))?;
|
|
|
|
|
println!("private key: {}", key_path.display());
|
|
|
|
|
println!("public key: {}", pub_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sign_package(dir: &Path, key_file: &Path) -> anyhow::Result<()> {
|
|
|
|
|
use ed25519_dalek::{Signer, SigningKey};
|
|
|
|
|
let key_hex = std::fs::read_to_string(key_file)
|
|
|
|
|
.with_context(|| format!("read {}", key_file.display()))?;
|
|
|
|
|
let key_bytes: [u8; 32] = hex::decode(key_hex.trim())
|
|
|
|
|
.context("decode signing key: expected 64 hex chars")?
|
|
|
|
|
.try_into()
|
|
|
|
|
.map_err(|_| anyhow::anyhow!("signing key must be 32 bytes"))?;
|
|
|
|
|
let signing_key = SigningKey::from_bytes(&key_bytes);
|
|
|
|
|
let hash = canonical_bundle_hash(dir)?;
|
|
|
|
|
let signature = signing_key.sign(&hash);
|
|
|
|
|
let sig_path = dir.join("signature.sig");
|
|
|
|
|
std::fs::write(&sig_path, hex::encode(signature.to_bytes()))
|
|
|
|
|
.with_context(|| format!("write {}", sig_path.display()))?;
|
|
|
|
|
println!("signed: {}", sig_path.display());
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn verify_package(dir: &Path, pub_key_file: &Path) -> anyhow::Result<bool> {
|
|
|
|
|
use ed25519_dalek::{Signature, Verifier, VerifyingKey};
|
|
|
|
|
let pub_hex = std::fs::read_to_string(pub_key_file)
|
|
|
|
|
.with_context(|| format!("read {}", pub_key_file.display()))?;
|
|
|
|
|
let pub_bytes: [u8; 32] = hex::decode(pub_hex.trim())
|
|
|
|
|
.context("decode public key: expected 64 hex chars")?
|
|
|
|
|
.try_into()
|
|
|
|
|
.map_err(|_| anyhow::anyhow!("public key must be 32 bytes"))?;
|
|
|
|
|
let verifying_key = VerifyingKey::from_bytes(&pub_bytes).context("invalid public key bytes")?;
|
|
|
|
|
let sig_path = dir.join("signature.sig");
|
|
|
|
|
let sig_hex = std::fs::read_to_string(&sig_path)
|
|
|
|
|
.with_context(|| format!("read {}", sig_path.display()))?;
|
|
|
|
|
let sig_bytes: [u8; 64] = hex::decode(sig_hex.trim())
|
|
|
|
|
.context("decode signature: expected 128 hex chars")?
|
|
|
|
|
.try_into()
|
|
|
|
|
.map_err(|_| anyhow::anyhow!("signature must be 64 bytes"))?;
|
|
|
|
|
let signature = Signature::from_bytes(&sig_bytes);
|
|
|
|
|
let hash = canonical_bundle_hash(dir)?;
|
|
|
|
|
Ok(verifying_key.verify(&hash, &signature).is_ok())
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
/// Serialises the tests that change the process environment; the test
|
|
|
|
|
/// harness runs tests on parallel threads that share it.
|
|
|
|
|
static ENV_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
|
|
|
|
|
|
|
|
|
fn env_lock() -> std::sync::MutexGuard<'static, ()> {
|
|
|
|
|
ENV_LOCK.lock().unwrap_or_else(|p| p.into_inner())
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
/// A minimal valid package for `app_id` in `src` declaring `capabilities`.
|
|
|
|
|
fn write_package(src: &Path, app_id: &str, capabilities: &str) {
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
std::fs::create_dir_all(src.join("ui")).unwrap();
|
|
|
|
|
std::fs::write(src.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
std::fs::write(src.join("ui/index.html"), b"").unwrap();
|
|
|
|
|
std::fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"D\"\nversion = \"1.0.0\"\n\
|
|
|
|
|
capabilities = [{capabilities}]\n\n\
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
/// Runs `f` with HOME set to `home` and XDG_DATA_HOME to `home/share`.
|
|
|
|
|
fn with_home<T>(home: &Path, f: impl FnOnce() -> T) -> T {
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let _env = env_lock();
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let prior: Vec<_> = ["HOME", "XDG_DATA_HOME"]
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|k| (*k, std::env::var_os(k)))
|
|
|
|
|
.collect();
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
// SAFETY: env_lock serialises every test that touches the environment.
|
|
|
|
|
unsafe {
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
std::env::set_var("HOME", home);
|
|
|
|
|
std::env::set_var("XDG_DATA_HOME", home.join("share"));
|
|
|
|
|
}
|
|
|
|
|
let result = f();
|
|
|
|
|
for (key, value) in prior {
|
|
|
|
|
unsafe {
|
|
|
|
|
match value {
|
|
|
|
|
Some(v) => std::env::set_var(key, v),
|
|
|
|
|
None => std::env::remove_var(key),
|
|
|
|
|
}
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
fn temp_root(name: &str) -> PathBuf {
|
|
|
|
|
let root = std::env::temp_dir().join(format!("weft_pack_{name}_{}", std::process::id()));
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let _ = std::fs::remove_dir_all(&root);
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const APP_DATA: &str = "\"fs:rw:app-data\"";
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn uninstall_keeps_app_data_from_the_user_store() {
|
|
|
|
|
let home = temp_root("keep");
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let app_id = "com.example.keep";
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
write_package(&home.join("src"), app_id, APP_DATA);
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
|
|
|
|
install_package_to(&home.join("src"), &store).unwrap();
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let legacy = store.join(app_id).join("data");
|
|
|
|
|
std::fs::create_dir_all(&legacy).unwrap();
|
|
|
|
|
std::fs::write(legacy.join("notes.txt"), "first\nsecond").unwrap();
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
assert!(!store.join(app_id).exists());
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let kept = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read_to_string(kept.join("notes.txt")).unwrap(),
|
|
|
|
|
"first\nsecond"
|
|
|
|
|
);
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
|
|
|
let mode = std::fs::metadata(&kept).unwrap().permissions().mode();
|
|
|
|
|
assert_eq!(mode & 0o777, 0o700);
|
|
|
|
|
}
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
|
|
|
|
|
// A second copy cannot be merged: uninstall refuses and removes nothing.
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
install_package_to(&home.join("src"), &store).unwrap();
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
std::fs::create_dir_all(&legacy).unwrap();
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &store)).is_err());
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
assert!(legacy.is_dir() && kept.is_dir());
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-10-09 09:01:28 +00:00
|
|
|
fn data_that_is_not_moved_is_never_removed() {
|
|
|
|
|
let home = temp_root("refuse");
|
|
|
|
|
let app_id = "com.example.refuse";
|
|
|
|
|
// No app-data capability: the data directory is left and uninstall stops.
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
write_package(&home.join("src"), app_id, "");
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
|
|
|
|
install_package_to(&home.join("src"), &store).unwrap();
|
|
|
|
|
std::fs::create_dir_all(store.join(app_id).join("data")).unwrap();
|
2026-10-09 09:01:28 +00:00
|
|
|
std::fs::write(store.join(app_id).join("data/x"), "x").unwrap();
|
|
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &store)).is_err());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read_to_string(store.join(app_id).join("data/x")).unwrap(),
|
|
|
|
|
"x"
|
|
|
|
|
);
|
|
|
|
|
std::fs::remove_dir_all(store.join(app_id)).unwrap();
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
|
2026-10-09 09:01:28 +00:00
|
|
|
// Another store: earlier versions never kept data there, so it stops too.
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
write_package(&home.join("src2"), app_id, APP_DATA);
|
|
|
|
|
let other = home.join("other-store");
|
|
|
|
|
install_package_to(&home.join("src2"), &other).unwrap();
|
|
|
|
|
std::fs::create_dir_all(other.join(app_id).join("data")).unwrap();
|
2026-10-09 09:01:28 +00:00
|
|
|
assert!(with_home(&home, || uninstall_package_from(app_id, &other)).is_err());
|
|
|
|
|
assert!(other.join(app_id).join("data").is_dir());
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
assert!(!home.join("share").exists());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-09 09:01:28 +00:00
|
|
|
#[test]
|
|
|
|
|
fn data_left_without_a_manifest_is_moved_not_deleted() {
|
|
|
|
|
let home = temp_root("orphan");
|
|
|
|
|
let app_id = "org.weft.demo.notes";
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
|
|
|
|
std::fs::create_dir_all(store.join(app_id).join("data")).unwrap();
|
|
|
|
|
std::fs::write(store.join(app_id).join("data/notes.txt"), "kept").unwrap();
|
|
|
|
|
// The store reached through another spelling of the same path.
|
|
|
|
|
let spelled = home.join(".local/share/weft/../weft/apps");
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &spelled)).unwrap();
|
|
|
|
|
let kept = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
std::fs::read_to_string(kept.join("notes.txt")).unwrap(),
|
|
|
|
|
"kept"
|
|
|
|
|
);
|
|
|
|
|
assert!(!store.join(app_id).exists());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_linked_home_still_finds_the_user_store() {
|
|
|
|
|
let root = temp_root("linked");
|
|
|
|
|
let real = root.join("var-home");
|
|
|
|
|
let app_id = "org.weft.demo.notes";
|
|
|
|
|
std::fs::create_dir_all(
|
|
|
|
|
real.join(".local/share/weft/apps")
|
|
|
|
|
.join(app_id)
|
|
|
|
|
.join("data"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
std::os::unix::fs::symlink(&real, root.join("home")).unwrap();
|
|
|
|
|
let store = real.join(".local/share/weft/apps");
|
|
|
|
|
with_home(&root.join("home"), || {
|
|
|
|
|
uninstall_package_from(app_id, &store)
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(weft_ipc_types::package::app_data_dir(&root.join("home/share"), app_id).is_dir());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&root);
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
#[test]
|
|
|
|
|
fn packages_cannot_ship_a_top_level_data_entry() {
|
|
|
|
|
let root = temp_root("ships-data");
|
|
|
|
|
let src = root.join("src");
|
|
|
|
|
write_package(&src, "com.example.ships", "");
|
|
|
|
|
std::fs::create_dir_all(src.join("data")).unwrap();
|
|
|
|
|
std::fs::write(src.join("data/asset.json"), "{}").unwrap();
|
|
|
|
|
let err = check_package(&src).unwrap_err().to_string();
|
|
|
|
|
assert!(err.contains("'data'"), "{err}");
|
|
|
|
|
assert!(install_package_to(&src, &root.join("store")).is_err());
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let _ = std::fs::remove_dir_all(&root);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn install_moves_leftover_app_data_out_of_the_way() {
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let home = temp_root("leftover");
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let app_id = "com.example.leftover";
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
write_package(&home.join("src"), app_id, APP_DATA);
|
|
|
|
|
let store = home.join(".local/share/weft/apps");
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
std::fs::create_dir_all(store.join(app_id).join("data")).unwrap();
|
|
|
|
|
std::fs::write(store.join(app_id).join("data/x"), "x").unwrap();
|
|
|
|
|
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
with_home(&home, || install_package_to(&home.join("src"), &store)).unwrap();
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
assert!(store.join(app_id).join("wapp.toml").exists());
|
|
|
|
|
assert!(!store.join(app_id).join("data").exists());
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
let kept = weft_ipc_types::package::app_data_dir(&home.join("share"), app_id);
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
assert_eq!(std::fs::read_to_string(kept.join("x")).unwrap(), "x");
|
fix(appd): move only real app data and never replace a directory
weft-pack treated any top-level data directory in a package as app
data from the earlier layout, in every store and for every app: a
package shipping data/ lost that content to the app data directory on
uninstall and could then no longer be uninstalled. Data is now moved
only from ~/.local/share/weft/apps/<id>/data, the only place earlier
versions wrote it, and only for packages declaring an app-data
capability; packages may no longer contain a top-level data entry.
The move left an empty package directory behind, which then blocked
weft-pack install although nothing was listed; an emptied package
directory is now removed, and install accepts an empty leftover. The
rename uses RENAME_NOREPLACE, so a target created after the check is
reported as a conflict instead of being replaced, and a move across
filesystems is refused with a message naming both locations instead of
a bare OS error. Directories moved by weft-pack are made private too,
and a symbolic link at the target is refused rather than followed.
The system UI now shows launch refusals, which it only logged, and the
weft-appd unit may write under ~/.local/share/weft, which
ProtectSystem=strict made read-only. check_app_data.py also types into
Notes after the move and requires the save to reach the moved file, and
checks that no empty package directory remains.
2026-10-09 08:52:09 +00:00
|
|
|
|
|
|
|
|
// An empty directory left behind does not block installation either.
|
|
|
|
|
with_home(&home, || uninstall_package_from(app_id, &store)).unwrap();
|
|
|
|
|
std::fs::create_dir_all(store.join(app_id)).unwrap();
|
|
|
|
|
with_home(&home, || install_package_to(&home.join("src"), &store)).unwrap();
|
|
|
|
|
let _ = std::fs::remove_dir_all(&home);
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn app_id_valid() {
|
fix(runtime): close fetch and preopen gaps in grant enforcement
A component with a host-specific fetch grant could reach another origin
by setting its own Host header, and could inject request lines through
the method string, which ureq writes unvalidated. Fetch now accepts only
standard methods and refuses Host, framing and hop-by-hop headers. Fetch
grants accept canonical DNS names and dotted IPv4 addresses only, so a
grant can never be written in a form that silently never matches.
--preopen split host and guest at the first `::`, so a host path
containing `::` widened the preopened directory; it now splits from the
right, and appd refuses host paths that are not UTF-8 or contain `::`.
appd validated capabilities one at a time, creating the data directory
before a later capability was refused, and required HOME even for
packages without filesystem capabilities. It now checks every capability
first, resolves host directories only when needed, validates the app ID
with the rule weft-pack uses (now shared in weft_ipc_types::package), and
reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is
read as a shell would: the last assignment wins, $HOME must be followed
by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is
not used.
The grants probe now also overwrites, renames, removes and creates
directories in read-only data, and sends a forged Host header, an
injected method and a file: URL; it fails when directory permissions of
a read-only preopen are widened or the header check is removed. A new
CI job builds the runtime with its engine and fetch support and runs the
check. The mount test that sets WEFT_APP_STORE now holds the env lock.
Package images are still located separately from directory installs;
deriving grants from the verified image is part of resolving one package
descriptor.
2026-10-09 08:25:40 +00:00
|
|
|
assert!(weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com.example.notes"
|
|
|
|
|
));
|
|
|
|
|
assert!(weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"org.weft.calculator"
|
|
|
|
|
));
|
|
|
|
|
assert!(weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"io.github.username.app"
|
|
|
|
|
));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn app_id_invalid() {
|
fix(runtime): close fetch and preopen gaps in grant enforcement
A component with a host-specific fetch grant could reach another origin
by setting its own Host header, and could inject request lines through
the method string, which ureq writes unvalidated. Fetch now accepts only
standard methods and refuses Host, framing and hop-by-hop headers. Fetch
grants accept canonical DNS names and dotted IPv4 addresses only, so a
grant can never be written in a form that silently never matches.
--preopen split host and guest at the first `::`, so a host path
containing `::` widened the preopened directory; it now splits from the
right, and appd refuses host paths that are not UTF-8 or contain `::`.
appd validated capabilities one at a time, creating the data directory
before a later capability was refused, and required HOME even for
packages without filesystem capabilities. It now checks every capability
first, resolves host directories only when needed, validates the app ID
with the rule weft-pack uses (now shared in weft_ipc_types::package), and
reports 400, 404, 403 or 500 according to the cause. user-dirs.dirs is
read as a shell would: the last assignment wins, $HOME must be followed
by a slash, escaped values are ignored and a relative XDG_CONFIG_HOME is
not used.
The grants probe now also overwrites, renames, removes and creates
directories in read-only data, and sends a forged Host header, an
injected method and a file: URL; it fails when directory permissions of
a read-only preopen are widened or the header check is removed. A new
CI job builds the runtime with its engine and fetch support and runs the
check. The mount test that sets WEFT_APP_STORE now holds the env lock.
Package images are still located separately from directory installs;
deriving grants from the verified image is part of resolving one package
descriptor.
2026-10-09 08:25:40 +00:00
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id("com.example"));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"Com.example.notes"
|
|
|
|
|
));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com.example.notes-app"
|
|
|
|
|
));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com..example.notes"
|
|
|
|
|
));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(""));
|
|
|
|
|
assert!(!weft_ipc_types::package::is_valid_app_id(
|
|
|
|
|
"com.Example.notes"
|
|
|
|
|
));
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_missing_manifest() {
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_empty");
|
|
|
|
|
let _ = std::fs::create_dir_all(&tmp);
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 12:07:45 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_missing_wasm() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_no_wasm");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.nowasm"
|
|
|
|
|
name = "No Wasm"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_missing_ui_entry() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_no_ui");
|
|
|
|
|
let _ = fs::create_dir_all(&tmp);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.noui"
|
|
|
|
|
name = "No UI"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_valid() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_valid");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.test"
|
|
|
|
|
name = "Test App"
|
|
|
|
|
version = "1.0.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_ok(), "{result:?}");
|
|
|
|
|
assert_eq!(result.unwrap(), "OK");
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 08:54:39 +00:00
|
|
|
#[test]
|
|
|
|
|
fn install_package_copies_to_store() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("weft.pack.install{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(format!("weft_pack_install_src_{}", id));
|
|
|
|
|
let store = std::env::temp_dir().join(format!("weft_pack_install_store_{}", id));
|
|
|
|
|
let ui_dir = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
let app_id = format!("com.example.t{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"Test\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = install_package_to(&src, &store);
|
|
|
|
|
assert!(result.is_ok(), "{result:?}");
|
|
|
|
|
assert!(store.join(&app_id).join("app.wasm").exists());
|
|
|
|
|
assert!(store.join(&app_id).join("wapp.toml").exists());
|
|
|
|
|
assert!(store.join(&app_id).join("ui").join("index.html").exists());
|
|
|
|
|
assert!(install_package_to(&src, &store).is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn uninstall_package_removes_directory() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("weft.pack.uninstall{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(format!("weft_pack_uninstall_src_{}", id));
|
|
|
|
|
let store = std::env::temp_dir().join(format!("weft_pack_uninstall_store_{}", id));
|
|
|
|
|
let ui_dir = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
let app_id = format!("com.example.u{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"U\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
install_package_to(&src, &store).unwrap();
|
|
|
|
|
assert!(store.join(&app_id).exists());
|
|
|
|
|
let result = uninstall_package_from(&app_id, &store);
|
|
|
|
|
assert!(result.is_ok(), "{result:?}");
|
|
|
|
|
assert!(!store.join(&app_id).exists());
|
|
|
|
|
assert!(uninstall_package_from(&app_id, &store).is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:21:43 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_bad_wasm_magic() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_bad_wasm");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"NOT_WASM").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "com.example.badwasm"
|
|
|
|
|
name = "Bad Wasm"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let msg = result.unwrap_err().to_string();
|
|
|
|
|
assert!(msg.contains("bad magic bytes"), "got: {msg}");
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_invalid_app_id() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let tmp = std::env::temp_dir().join("weft_pack_test_invalid_id");
|
|
|
|
|
let ui_dir = tmp.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui_dir);
|
|
|
|
|
fs::write(tmp.join("app.wasm"), b"\0asm").unwrap();
|
|
|
|
|
fs::write(ui_dir.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
r#"
|
|
|
|
|
[package]
|
|
|
|
|
id = "bad-id"
|
|
|
|
|
name = "Bad"
|
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
|
|
[runtime]
|
|
|
|
|
module = "app.wasm"
|
|
|
|
|
|
|
|
|
|
[ui]
|
|
|
|
|
entry = "ui/index.html"
|
|
|
|
|
"#,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
let _ = fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
2026-03-11 11:00:44 +00:00
|
|
|
|
2026-03-11 14:49:34 +00:00
|
|
|
#[test]
|
|
|
|
|
fn install_package_from_archive() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("instarch_{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(&id);
|
|
|
|
|
let ui = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
let app_id = format!("com.example.ia{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"IA\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let bundle_dir = std::env::temp_dir().join(format!("{id}_bnd"));
|
|
|
|
|
let _ = fs::create_dir_all(&bundle_dir);
|
|
|
|
|
bundle_package(&src, Some(&bundle_dir)).unwrap();
|
|
|
|
|
let archive = bundle_dir.join(format!("{app_id}.app.tar.zst"));
|
|
|
|
|
|
|
|
|
|
let store = std::env::temp_dir().join(format!("{id}_store"));
|
|
|
|
|
let _ = fs::create_dir_all(&store);
|
|
|
|
|
install_package_to(&archive, &store).unwrap();
|
|
|
|
|
assert!(store.join(&app_id).join("app.wasm").exists());
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&bundle_dir);
|
|
|
|
|
let _ = fs::remove_dir_all(&store);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:37:53 +00:00
|
|
|
#[test]
|
|
|
|
|
fn bundle_and_unbundle_roundtrip() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("bundle_{}", std::process::id());
|
|
|
|
|
let src = std::env::temp_dir().join(&id);
|
|
|
|
|
let out = std::env::temp_dir().join(format!("{id}_out"));
|
|
|
|
|
let ui = src.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(src.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
let app_id = format!("com.example.b{}", std::process::id());
|
|
|
|
|
fs::write(
|
|
|
|
|
src.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{app_id}\"\nname = \"B\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let _ = fs::create_dir_all(&out);
|
|
|
|
|
bundle_package(&src, Some(&out)).unwrap();
|
|
|
|
|
let archive = out.join(format!("{app_id}.app.tar.zst"));
|
|
|
|
|
assert!(archive.exists());
|
|
|
|
|
|
|
|
|
|
let unpack = std::env::temp_dir().join(format!("{id}_unpack"));
|
|
|
|
|
let _ = fs::create_dir_all(&unpack);
|
|
|
|
|
unbundle_package(&archive, &unpack).unwrap();
|
|
|
|
|
assert!(unpack.join(&app_id).join("app.wasm").exists());
|
|
|
|
|
assert!(unpack.join(&app_id).join("ui").join("index.html").exists());
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&src);
|
|
|
|
|
let _ = fs::remove_dir_all(&out);
|
|
|
|
|
let _ = fs::remove_dir_all(&unpack);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 11:00:44 +00:00
|
|
|
#[test]
|
2026-03-11 14:29:49 +00:00
|
|
|
fn sign_and_verify_roundtrip() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("sign_verify_{}", std::process::id());
|
|
|
|
|
let dir = std::env::temp_dir().join(&id);
|
|
|
|
|
let key_dir = std::env::temp_dir().join(format!("{id}_keys"));
|
|
|
|
|
let ui = dir.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
dir.join("wapp.toml"),
|
|
|
|
|
"[package]\nid = \"com.example.signed\"\nname = \"S\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
generate_key(&key_dir).unwrap();
|
|
|
|
|
let key_file = key_dir.join("weft-sign.key");
|
|
|
|
|
let pub_file = key_dir.join("weft-sign.pub");
|
|
|
|
|
|
|
|
|
|
sign_package(&dir, &key_file).unwrap();
|
|
|
|
|
assert!(dir.join("signature.sig").exists());
|
|
|
|
|
|
|
|
|
|
let ok = verify_package(&dir, &pub_file).unwrap();
|
|
|
|
|
assert!(ok, "signature should verify");
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&dir);
|
|
|
|
|
let _ = fs::remove_dir_all(&key_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn verify_rejects_tampered_bundle() {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let id = format!("tamper_{}", std::process::id());
|
|
|
|
|
let dir = std::env::temp_dir().join(&id);
|
|
|
|
|
let key_dir = std::env::temp_dir().join(format!("{id}_keys"));
|
|
|
|
|
let ui = dir.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"<!DOCTYPE html>").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
dir.join("wapp.toml"),
|
|
|
|
|
"[package]\nid = \"com.example.tamper\"\nname = \"T\"\nversion = \"1.0.0\"\n\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n\n[ui]\nentry = \"ui/index.html\"\n",
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
generate_key(&key_dir).unwrap();
|
|
|
|
|
sign_package(&dir, &key_dir.join("weft-sign.key")).unwrap();
|
|
|
|
|
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\x01").unwrap();
|
|
|
|
|
|
|
|
|
|
let ok = verify_package(&dir, &key_dir.join("weft-sign.pub")).unwrap();
|
|
|
|
|
assert!(!ok, "tampered bundle should not verify");
|
|
|
|
|
|
|
|
|
|
let _ = fs::remove_dir_all(&dir);
|
|
|
|
|
let _ = fs::remove_dir_all(&key_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2026-03-11 11:00:44 +00:00
|
|
|
fn list_installed_roots_uses_weft_app_store_when_set() {
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let _env = env_lock();
|
2026-03-11 11:00:44 +00:00
|
|
|
let prior = std::env::var("WEFT_APP_STORE").ok();
|
|
|
|
|
unsafe { std::env::set_var("WEFT_APP_STORE", "/custom/store") };
|
|
|
|
|
let roots = list_installed_roots();
|
|
|
|
|
unsafe {
|
|
|
|
|
match prior {
|
|
|
|
|
Some(v) => std::env::set_var("WEFT_APP_STORE", v),
|
|
|
|
|
None => std::env::remove_var("WEFT_APP_STORE"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(roots, vec![PathBuf::from("/custom/store")]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn list_installed_roots_includes_system_path() {
|
fix(appd): keep app data apart from installed packages
App data lived in ~/.local/share/weft/apps/<id>/data, inside the user
package store under the installed package directory. Uninstalling a
package deleted its data, and launching a package installed elsewhere
created that directory, after which installing the package for the user
failed because its directory already existed.
App data now lives in $XDG_DATA_HOME/weft/app-data/<id>, one shared
rule in weft_ipc_types::package, and is made private (0700) on every
launch. Data in the earlier location is moved there in one rename on the
first launch with an app-data capability, and by weft-pack before it
uninstalls a package or installs over a directory holding only data. If
both locations hold data, nothing is moved: the launch is refused with
409 and weft-pack stops, so neither copy is lost or merged.
tests/frame/check_app_data.py launches the Notes demo on the nested
desktop with notes in the earlier location and checks that they arrive
byte for byte (including a literal backslash sequence and non-ASCII
text), that the old directory is gone, that the new one is 0700 and that
a second copy makes the next launch fail with 409 without changing
either. The weft-pack tests that change the environment now share a lock.
2026-10-09 08:43:42 +00:00
|
|
|
let _env = env_lock();
|
2026-03-11 11:00:44 +00:00
|
|
|
let prior = std::env::var("WEFT_APP_STORE").ok();
|
|
|
|
|
unsafe { std::env::remove_var("WEFT_APP_STORE") };
|
|
|
|
|
let roots = list_installed_roots();
|
|
|
|
|
unsafe {
|
|
|
|
|
if let Some(v) = prior {
|
|
|
|
|
std::env::set_var("WEFT_APP_STORE", v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert!(
|
|
|
|
|
roots
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|p| p == &PathBuf::from("/usr/share/weft/apps"))
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-11 17:35:07 +00:00
|
|
|
|
|
|
|
|
fn make_valid_package(dir: &std::path::Path, id: &str, caps: &str) {
|
|
|
|
|
use std::fs;
|
|
|
|
|
let ui = dir.join("ui");
|
|
|
|
|
let _ = fs::create_dir_all(&ui);
|
|
|
|
|
fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
fs::write(ui.join("index.html"), b"").unwrap();
|
|
|
|
|
fs::write(
|
|
|
|
|
dir.join("wapp.toml"),
|
|
|
|
|
format!(
|
|
|
|
|
"[package]\nid = \"{id}\"\nname = \"T\"\nversion = \"0.1.0\"\n{caps}\n\
|
|
|
|
|
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
fix(appd): resolve each launch to one package and fail closed on images
The runtime, the app shell and grant derivation each searched the
package stores and parsed wapp.toml on their own, so they could use
different roots; the runtime ignored [runtime].module, the image loader
looked for companion files the builder never wrote, and a failed image
mount fell back to the mutable directory install.
weft-appd now resolves a launch once: a verified image wins over a
directory in the same store, and when any image file exists the image
must mount or the launch is refused. The manifest must declare the
requested ID, and both entries must be plain relative paths to regular
files without links. The runtime receives --module and the app shell
--ui; neither looks for the package. Grants come from the same
manifest, and the mount belongs to the session.
The manifest parser and the image file names move to weft-ipc-types,
shared with weft-pack, whose check now applies the same entry rules.
Mapper devices are named after their per-launch mountpoint, so
concurrent sessions no longer collide.
2026-10-09 10:03:40 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_refuses_entries_outside_the_package() {
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_pack_entries_{}", std::process::id()));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
make_valid_package(&tmp, "com.example.entries", "");
|
|
|
|
|
std::fs::write(tmp.with_extension("wasm"), b"\0asm\x01\0\0\0").unwrap();
|
|
|
|
|
std::os::unix::fs::symlink("index.html", tmp.join("ui/linked.html")).unwrap();
|
|
|
|
|
let manifest = std::fs::read_to_string(tmp.join("wapp.toml")).unwrap();
|
|
|
|
|
let escaping = format!("../{}", tmp.with_extension("wasm").file_name().unwrap().display());
|
|
|
|
|
std::fs::write(
|
|
|
|
|
tmp.join("wapp.toml"),
|
|
|
|
|
manifest
|
|
|
|
|
.replace("module = \"app.wasm\"", &format!("module = \"{escaping}\""))
|
|
|
|
|
.replace("ui/index.html", "ui/linked.html"),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let msg = check_package(&tmp).unwrap_err().to_string();
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
let _ = std::fs::remove_file(tmp.with_extension("wasm"));
|
|
|
|
|
assert!(msg.contains("runtime.module") && msg.contains("not a relative path"), "{msg}");
|
|
|
|
|
assert!(msg.contains("ui.entry") && msg.contains("symbolic link"), "{msg}");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:35:07 +00:00
|
|
|
#[test]
|
|
|
|
|
fn check_package_unknown_capability_errors() {
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_pack_caps_bad_{}", std::process::id()));
|
|
|
|
|
make_valid_package(&tmp, "com.example.caps", "capabilities = [\"network:tcp\"]");
|
|
|
|
|
let result = check_package(&tmp);
|
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
assert!(result.unwrap_err().to_string().contains("network:tcp"));
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn check_package_known_capabilities_accepted() {
|
|
|
|
|
let tmp = std::env::temp_dir().join(format!("weft_pack_caps_ok_{}", std::process::id()));
|
|
|
|
|
make_valid_package(
|
|
|
|
|
&tmp,
|
|
|
|
|
"com.example.caps",
|
|
|
|
|
"capabilities = [\"fs:rw:app-data\", \"fs:read:xdg-documents\"]",
|
|
|
|
|
);
|
|
|
|
|
assert!(check_package(&tmp).is_ok());
|
|
|
|
|
let _ = std::fs::remove_dir_all(&tmp);
|
|
|
|
|
}
|
feat(pack): add weft-pack package validator tool
New crate: weft-pack — command-line tool for validating WEFT application
package directories against the app-package-format spec.
src/main.rs:
- check <dir>: loads wapp.toml, validates app ID format, verifies
package.name is non-empty and <=64 chars, confirms runtime.module and
ui.entry files exist. Prints 'OK' on success or the list of errors.
- info <dir>: prints all manifest fields to stdout.
- load_manifest(): reads and parses wapp.toml with toml crate.
- is_valid_app_id(): enforces reverse-domain convention (>=3 components,
each starting with a lowercase letter, digits allowed, no hyphens or
uppercase).
Tests (5):
- app_id_valid: accepts well-formed reverse-domain IDs.
- app_id_invalid: rejects two-component, uppercase, hyphen, empty IDs.
- check_package_missing_manifest: error when wapp.toml is absent.
- check_package_valid: full happy-path with real temp files.
- check_package_invalid_app_id: error on a hyphenated app ID.
New deps: toml 0.8, serde 1 (derive).
Added weft-pack to workspace Cargo.toml; wsl-test.sh extended.
2026-03-11 08:40:34 +00:00
|
|
|
}
|