mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
test(appd): launch complete packages in the supervisor tests
Launch tests wrote manifests without names, versions or entries, which the shared parser rejects. They now write complete packages.
This commit is contained in:
parent
2148ffc8ae
commit
d056045ad8
9 changed files with 107 additions and 55 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -10455,10 +10455,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags 2.11.0",
|
||||
"serde",
|
||||
"servo",
|
||||
"softbuffer",
|
||||
"toml 0.8.23",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"wayland-backend",
|
||||
|
|
|
|||
|
|
@ -628,7 +628,12 @@ fn resolve_weft_system_url(url: &ServoUrl) -> Option<ServoUrl> {
|
|||
|
||||
/// Shows the UI document `ui` of `app_id`, the file weft-appd resolved from
|
||||
/// the package; the shell never looks for the package itself.
|
||||
pub fn run(app_id: &str, session_id: u64, ws_port: u16, ui: &std::path::Path) -> anyhow::Result<()> {
|
||||
pub fn run(
|
||||
app_id: &str,
|
||||
session_id: u64,
|
||||
ws_port: u16,
|
||||
ui: &std::path::Path,
|
||||
) -> anyhow::Result<()> {
|
||||
let url = ServoUrl::from_file_path(ui)
|
||||
.map_err(|()| anyhow::anyhow!("{} is not an absolute path", ui.display()))?;
|
||||
tracing::info!(%app_id, %url, "showing application UI");
|
||||
|
|
|
|||
|
|
@ -48,14 +48,13 @@ pub(crate) fn resolve(app_id: &str) -> Result<LaunchPackage, Refusal> {
|
|||
return from_root(app_id, dir, None);
|
||||
}
|
||||
}
|
||||
Err(Refusal::new(404, format!("package {app_id} is not installed")))
|
||||
Err(Refusal::new(
|
||||
404,
|
||||
format!("package {app_id} is not installed"),
|
||||
))
|
||||
}
|
||||
|
||||
fn from_root(
|
||||
app_id: &str,
|
||||
root: PathBuf,
|
||||
image: Option<Mount>,
|
||||
) -> Result<LaunchPackage, Refusal> {
|
||||
fn from_root(app_id: &str, root: PathBuf, image: Option<Mount>) -> Result<LaunchPackage, Refusal> {
|
||||
let manifest = Manifest::read(&root).map_err(|e| Refusal::new(403, e.to_string()))?;
|
||||
if manifest.package.id != app_id {
|
||||
return Err(Refusal::new(
|
||||
|
|
@ -112,10 +111,8 @@ mod tests {
|
|||
/// A store holding a directory install of `ID`, with WEFT_APP_STORE
|
||||
/// pointing at it. Callers hold env_lock.
|
||||
fn store(name: &str, manifest_id: &str, module: &str) -> PathBuf {
|
||||
let store = std::env::temp_dir().join(format!(
|
||||
"weft_appd_launch_{name}_{}",
|
||||
std::process::id()
|
||||
));
|
||||
let store =
|
||||
std::env::temp_dir().join(format!("weft_appd_launch_{name}_{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&store);
|
||||
let package = store.join(ID);
|
||||
std::fs::create_dir_all(package.join("ui")).unwrap();
|
||||
|
|
@ -172,7 +169,11 @@ mod tests {
|
|||
let refused = refusal(resolve(ID));
|
||||
finish(&store);
|
||||
assert_eq!(refused.code, 403);
|
||||
assert!(refused.message.contains("org.weft.test.other"), "{}", refused.message);
|
||||
assert!(
|
||||
refused.message.contains("org.weft.test.other"),
|
||||
"{}",
|
||||
refused.message
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -183,7 +184,11 @@ mod tests {
|
|||
let refused = refusal(resolve(ID));
|
||||
finish(&store);
|
||||
assert_eq!(refused.code, 403);
|
||||
assert!(refused.message.contains("runtime.module"), "{}", refused.message);
|
||||
assert!(
|
||||
refused.message.contains("runtime.module"),
|
||||
"{}",
|
||||
refused.message
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -233,7 +238,11 @@ mod tests {
|
|||
|
||||
for refused in [&partial, &failed, &absent, &malformed] {
|
||||
assert_eq!(refused.code, 500, "{}", refused.message);
|
||||
assert!(refused.message.contains("verified image"), "{}", refused.message);
|
||||
assert!(
|
||||
refused.message.contains("verified image"),
|
||||
"{}",
|
||||
refused.message
|
||||
);
|
||||
}
|
||||
assert!(partial.message.contains(".app.hash"), "{}", partial.message);
|
||||
assert_eq!(mountpoints, 0, "a failed mount left its mountpoint behind");
|
||||
|
|
|
|||
|
|
@ -597,7 +597,12 @@ async fn resolve_launch(
|
|||
Ok((package, grants))
|
||||
})
|
||||
.await
|
||||
.unwrap_or_else(|e| Err(grants::Refusal::new(500, format!("package resolution failed: {e}"))))
|
||||
.unwrap_or_else(|e| {
|
||||
Err(grants::Refusal::new(
|
||||
500,
|
||||
format!("package resolution failed: {e}"),
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn app_store_roots() -> Vec<std::path::PathBuf> {
|
||||
|
|
@ -688,6 +693,22 @@ mod tests {
|
|||
ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(()))
|
||||
}
|
||||
|
||||
/// Writes a complete package `id` into `dir`; `extra` adds lines to its
|
||||
/// `[package]` table.
|
||||
fn write_test_package(dir: &std::path::Path, id: &str, extra: &str) {
|
||||
std::fs::create_dir_all(dir.join("ui")).unwrap();
|
||||
std::fs::write(dir.join("app.wasm"), b"\0asm\x01\0\0\0").unwrap();
|
||||
std::fs::write(dir.join("ui/index.html"), b"<p>").unwrap();
|
||||
std::fs::write(
|
||||
dir.join("wapp.toml"),
|
||||
format!(
|
||||
"[package]\nid = \"{id}\"\nname = \"T\"\nversion = \"0.1.0\"\n{extra}\n\
|
||||
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn make_registry() -> Registry {
|
||||
Arc::new(Mutex::new(SessionRegistry::default()))
|
||||
}
|
||||
|
|
@ -762,12 +783,11 @@ mod tests {
|
|||
let _env = env_lock().lock().await;
|
||||
let store = std::env::temp_dir().join(format!("weft_refuse_{}", std::process::id()));
|
||||
let app_dir = store.join("org.example.gpu");
|
||||
std::fs::create_dir_all(&app_dir).unwrap();
|
||||
std::fs::write(
|
||||
app_dir.join("wapp.toml"),
|
||||
"[package]\nid = \"org.example.gpu\"\ncapabilities = [\"hw:gpu:compute\"]\n",
|
||||
)
|
||||
.unwrap();
|
||||
write_test_package(
|
||||
&app_dir,
|
||||
"org.example.gpu",
|
||||
"capabilities = [\"hw:gpu:compute\"]",
|
||||
);
|
||||
let prior_store = std::env::var("WEFT_APP_STORE").ok();
|
||||
let prior_bin = std::env::var("WEFT_RUNTIME_BIN").ok();
|
||||
// SAFETY: env_lock is held and the runtime is current_thread.
|
||||
|
|
@ -1163,12 +1183,7 @@ mod tests {
|
|||
use_test_runtime_dir();
|
||||
let dir = std::env::temp_dir().join(format!("weft_test_relay_{}", std::process::id()));
|
||||
let app = dir.join("store/org.example.relay");
|
||||
std::fs::create_dir_all(&app).unwrap();
|
||||
std::fs::write(
|
||||
app.join("wapp.toml"),
|
||||
"[package]\nid = \"org.example.relay\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
write_test_package(&app, "org.example.relay", "");
|
||||
// The runtime reports ready and exits without connecting to the relay.
|
||||
let child = dir.join("child.sh");
|
||||
std::fs::write(
|
||||
|
|
@ -1559,7 +1574,7 @@ mod tests {
|
|||
std::time::Duration::from_secs(20),
|
||||
runtime::supervise(
|
||||
session_id,
|
||||
"test.app",
|
||||
launch::LaunchPackage::unresolved("test.app"),
|
||||
grants::SessionGrants::default(),
|
||||
Arc::clone(®istry),
|
||||
abort_rx,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,10 @@ pub(crate) fn mount(app_id: &str, files: &ImageFiles) -> Result<Mount, String> {
|
|||
for path in [&files.image, &files.hash_tree, &files.root_hash] {
|
||||
let is_file = std::fs::symlink_metadata(path).is_ok_and(|m| m.file_type().is_file());
|
||||
if !is_file {
|
||||
return Err(format!("{} is missing or not a regular file", path.display()));
|
||||
return Err(format!(
|
||||
"{} is missing or not a regular file",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
let root_hash = std::fs::read_to_string(&files.root_hash)
|
||||
|
|
@ -99,7 +102,7 @@ pub(crate) fn mount(app_id: &str, files: &ImageFiles) -> Result<Mount, String> {
|
|||
/// A dm-verity root hash in hex, as `veritysetup format` prints it.
|
||||
fn is_root_hash(text: &str) -> bool {
|
||||
(64..=128).contains(&text.len())
|
||||
&& text.len() % 2 == 0
|
||||
&& text.len().is_multiple_of(2)
|
||||
&& text.bytes().all(|b| b.is_ascii_hexdigit())
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +114,13 @@ mod tests {
|
|||
fn root_hashes_are_hex_digests() {
|
||||
assert!(is_root_hash(&"a".repeat(64)));
|
||||
assert!(is_root_hash(&"0F".repeat(64)));
|
||||
for bad in ["", "abc", &"g".repeat(64), &"a".repeat(65), &"a".repeat(130)] {
|
||||
for bad in [
|
||||
"",
|
||||
"abc",
|
||||
&"g".repeat(64),
|
||||
&"a".repeat(65),
|
||||
&"a".repeat(130),
|
||||
] {
|
||||
assert!(!is_root_hash(bad), "{bad:?}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ use weft_ipc_types::AppdToCompositor;
|
|||
|
||||
use crate::Registry;
|
||||
use crate::compositor_client::CompositorSender;
|
||||
use crate::ipc::{AppStateKind, Response};
|
||||
use crate::launch::LaunchPackage;
|
||||
use crate::mount::Mount;
|
||||
use crate::ipc::{AppStateKind, Response};
|
||||
|
||||
/// The per-session relay between the component's IPC socket and the app
|
||||
/// bridge. It belongs to the session: closing it stops the relay task and
|
||||
|
|
@ -378,8 +378,8 @@ pub(crate) async fn supervise(
|
|||
tokio::spawn(drain_stdout(runtime_stdout, session_id));
|
||||
|
||||
let bridge_token = registry.lock().await.bridge_token(session_id);
|
||||
let mut app_shell = match spawn_app_shell(&shell_bin, session_id, &package, &token, bridge_token)
|
||||
{
|
||||
let mut app_shell =
|
||||
match spawn_app_shell(&shell_bin, session_id, &package, &token, bridge_token) {
|
||||
Ok(child) => child,
|
||||
Err(e) => {
|
||||
return session
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ impl Manifest {
|
|||
/// Reads `<package_root>/wapp.toml`.
|
||||
pub fn read(package_root: &Path) -> Result<Self, ManifestError> {
|
||||
let path = package_root.join(MANIFEST_FILE);
|
||||
let text = std::fs::read_to_string(&path).map_err(|e| ManifestError::Io(path.clone(), e))?;
|
||||
let text =
|
||||
std::fs::read_to_string(&path).map_err(|e| ManifestError::Io(path.clone(), e))?;
|
||||
toml::from_str(&text).map_err(|e| ManifestError::Parse(path, e))
|
||||
}
|
||||
|
||||
|
|
@ -112,8 +113,8 @@ pub fn entry_path(package_root: &Path, entry: &str) -> Result<PathBuf, EntryErro
|
|||
let mut path = package_root.to_path_buf();
|
||||
while let Some(component) = components.next() {
|
||||
path.push(component);
|
||||
let metadata = std::fs::symlink_metadata(&path)
|
||||
.map_err(|_| EntryError::NotAFile(entry.to_owned()))?;
|
||||
let metadata =
|
||||
std::fs::symlink_metadata(&path).map_err(|_| EntryError::NotAFile(entry.to_owned()))?;
|
||||
if metadata.file_type().is_symlink() {
|
||||
return Err(EntryError::Link(entry.to_owned()));
|
||||
}
|
||||
|
|
@ -130,10 +131,7 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
fn package(name: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"weft_manifest_{name}_{}",
|
||||
std::process::id()
|
||||
));
|
||||
let dir = std::env::temp_dir().join(format!("weft_manifest_{name}_{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(dir.join("ui")).unwrap();
|
||||
std::fs::write(dir.join("app.wasm"), b"\0asm").unwrap();
|
||||
|
|
@ -155,7 +153,13 @@ mod tests {
|
|||
#[test]
|
||||
fn entries_must_stay_inside_the_package() {
|
||||
let dir = package("contained");
|
||||
for entry in ["", "/etc/passwd", "../app.wasm", "ui/../app.wasm", "./app.wasm"] {
|
||||
for entry in [
|
||||
"",
|
||||
"/etc/passwd",
|
||||
"../app.wasm",
|
||||
"ui/../app.wasm",
|
||||
"./app.wasm",
|
||||
] {
|
||||
assert_eq!(
|
||||
entry_path(&dir, entry),
|
||||
Err(EntryError::NotContained(entry.to_owned())),
|
||||
|
|
|
|||
|
|
@ -219,7 +219,10 @@ mod tests {
|
|||
fn image_companions_share_the_image_name() {
|
||||
let files = ImageFiles::in_store(Path::new("/store"), "org.weft.demo.notes");
|
||||
assert_eq!(files.image, Path::new("/store/org.weft.demo.notes.app.img"));
|
||||
assert_eq!(files.hash_tree, Path::new("/store/org.weft.demo.notes.app.hash"));
|
||||
assert_eq!(
|
||||
files.hash_tree,
|
||||
Path::new("/store/org.weft.demo.notes.app.hash")
|
||||
);
|
||||
assert_eq!(
|
||||
files.root_hash,
|
||||
Path::new("/store/org.weft.demo.notes.app.roothash")
|
||||
|
|
|
|||
|
|
@ -1275,7 +1275,10 @@ entry = "ui/index.html"
|
|||
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());
|
||||
let escaping = format!(
|
||||
"../{}",
|
||||
tmp.with_extension("wasm").file_name().unwrap().display()
|
||||
);
|
||||
std::fs::write(
|
||||
tmp.join("wapp.toml"),
|
||||
manifest
|
||||
|
|
@ -1286,8 +1289,14 @@ entry = "ui/index.html"
|
|||
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}");
|
||||
assert!(
|
||||
msg.contains("runtime.module") && msg.contains("not a relative path"),
|
||||
"{msg}"
|
||||
);
|
||||
assert!(
|
||||
msg.contains("ui.entry") && msg.contains("symbolic link"),
|
||||
"{msg}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue