From 6aaef4b4022b1b7c46c8f7a2a93e4daf7d19f81c Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 13:31:53 -0500 Subject: [PATCH 1/3] fix(id): make the no-SQLite guard read the resolved graph, not the raw lock The guard asserted the raw Cargo.lock names no SQLite-family crate. #2276 dev-depends on rusqlite (bundled) for the bridge PoC's hosted store, and the lock resolves dev-dependencies too, so the text scan false-fires even though the shipped store is still redb and nothing that ships links SQLite. The test now parses the lock into the resolved package graph: a SQLite-family package may appear only when every package depending on it is SQLite-family itself or this package, and this package's manifest is checked section by section so SQLite names may be declared only under dev-dependencies. A shipped dependency pulling SQLite in, or the manifest moving rusqlite out of dev-dependencies, still fails the guard, as do a missing p2panda-sync or the vendored p2panda-store line losing default-features = false. Refs #3160 --- pkgs/id/src/store_traits.rs | 186 ++++++++++++++++++++++++++++++++---- 1 file changed, 168 insertions(+), 18 deletions(-) diff --git a/pkgs/id/src/store_traits.rs b/pkgs/id/src/store_traits.rs index f39ae25db6..b7f512d05e 100644 --- a/pkgs/id/src/store_traits.rs +++ b/pkgs/id/src/store_traits.rs @@ -538,30 +538,180 @@ mod tests { use crate::chain::{ChainExt, sign}; use crate::waiting::WaitingLimits; - /// The build has no SQLite, with `LogSync` wired in. p2panda-sync's store dependency defaults to - /// SQLite, so the vendored copy turns that default off (`vendor/README.md`). This fails if the - /// lock names SQLite or sqlx, if p2panda-sync is missing, or if the vendored line loses the change. + /// One `[[package]]` entry of the lock: its name and the names it + /// depends on. Dependency entries are `"name"`, `"name version"` or + /// `"name version (source)"`; the name is the first word. + fn lock_packages(lock: &str) -> Vec<(String, Vec)> { + let mut packages = Vec::new(); + let mut current: Option<(String, Vec)> = None; + let mut in_deps = false; + for raw in lock.lines() { + let line = raw.trim(); + if line.starts_with("[[") { + in_deps = false; + if let Some(package) = current.take() { + packages.push(package); + } + } else if current.is_none() { + if let Some(rest) = line.strip_prefix("name = \"") { + current = Some((rest.trim_end_matches('"').to_owned(), Vec::new())); + } + } else if line == "dependencies = [" { + in_deps = true; + } else if in_deps && line == "]" { + in_deps = false; + } else if in_deps { + if let Some(entry) = line.strip_suffix(',') { + let entry = entry.trim_matches('"'); + if let Some(name) = entry.split(' ').next() { + current.as_mut().unwrap().1.push(name.to_owned()); + } + } + } + } + if let Some(package) = current.take() { + packages.push(package); + } + packages + } + + /// Whether a manifest section header opens a dev-dependency section + /// (`Some(true)`), a shipped one — normal or build (`Some(false)`) — or + /// neither. Plain, target-specific and per-crate subtable spellings all + /// count: `[dev-dependencies]`, `[target.'cfg(..)'.dependencies]`, + /// `[dependencies.rusqlite]`. + fn dep_section_dev(section: &str) -> Option { + let tail = section.rsplit('.').next().unwrap_or(section); + match tail { + "dev-dependencies" => Some(true), + "dependencies" | "build-dependencies" => Some(false), + _ if section.starts_with("dev-dependencies.") => Some(true), + _ if section.starts_with("dependencies.") + || section.starts_with("build-dependencies.") => + { + Some(false) + } + _ => None, + } + } + + /// The crate names a manifest declares in dependency sections of one + /// class (`dev` selects dev-dependencies, otherwise the shipped ones). + /// A `package = "..."` rename counts under the real name. + fn manifest_dep_names(manifest: &str, dev: bool) -> Vec { + let mut names = Vec::new(); + let mut in_class = false; + for raw in manifest.lines() { + let line = raw.trim(); + if line.starts_with('#') { + continue; + } + if line.starts_with('[') && line.ends_with(']') { + let section = line.trim_matches(|c| c == '[' || c == ']'); + in_class = dep_section_dev(section) == Some(dev); + if in_class { + // A per-crate subtable names the crate in the header: + // `[dependencies.rusqlite]`. + if let Some((_, name)) = section.rsplit_once('.') + && !matches!( + name, + "dependencies" | "build-dependencies" | "dev-dependencies" + ) + { + names.push(name.to_owned()); + } + } + continue; + } + if !in_class { + continue; + } + if let Some((key, _)) = line.split_once('=') { + let key = key.trim().trim_matches('"'); + if !key.is_empty() + && key + .chars() + .all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_')) + { + names.push(key.to_owned()); + } + } + if let Some((_, rest)) = line.split_once("package = \"") + && let Some(name) = rest.split('"').next() + { + names.push(name.to_owned()); + } + } + names + } + + /// The `[package]` name of a manifest. + fn manifest_package_name(manifest: &str) -> Option { + let mut in_package = false; + for raw in manifest.lines() { + let line = raw.trim(); + if line.starts_with('[') { + in_package = line == "[package]"; + continue; + } + if in_package && let Some(rest) = line.strip_prefix("name = \"") { + return Some(rest.trim_end_matches('"').to_owned()); + } + } + None + } + + /// The shipped build has no SQLite, with `LogSync` wired in. p2panda-sync's store dependency + /// defaults to SQLite, so the vendored copy turns that default off (`vendor/README.md`). + /// + /// The raw lock cannot carry this check on its own: it resolves dev-dependencies too, and + /// #2276 dev-depends on `rusqlite` for the bridge PoC's hosted store, which never ships. + /// So this reads the resolved graph instead. A SQLite-family package may appear only when + /// every package that depends on it is SQLite-family itself or this package — and this + /// package's manifest, checked section by section, must declare SQLite names as + /// dev-dependencies only. It fails if a shipped dependency pulls SQLite in, if the + /// manifest moves it out of dev-dependencies, if p2panda-sync is missing, or if the + /// vendored line loses the change. #[test] fn test_the_lock_has_no_sqlite_with_logsync_wired() { - let lock = - std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.lock")).unwrap(); - for name in ["sqlx", "sqlite", "rusqlite", "libsqlite3-sys"] { - assert!( - !lock.contains(&format!("name = \"{name}")), - "Cargo.lock names {name}: SQLite is back in the build (see vendor/README.md)" - ); - } + const SQLITE: [&str; 4] = ["sqlx", "sqlite", "rusqlite", "libsqlite3-sys"]; + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let lock = std::fs::read_to_string(format!("{manifest_dir}/Cargo.lock")).unwrap(); + let packages = lock_packages(&lock); assert!( - lock.contains("name = \"p2panda-sync\""), + packages.iter().any(|(name, _)| name == "p2panda-sync"), "Cargo.lock does not name p2panda-sync: LogSync is not wired in" ); - let manifest = std::fs::read_to_string(concat!( - env!("CARGO_MANIFEST_DIR"), - "/vendor/p2panda-sync/Cargo.toml" - )) - .unwrap(); - let store_line = manifest + let manifest = std::fs::read_to_string(format!("{manifest_dir}/Cargo.toml")).unwrap(); + let root = manifest_package_name(&manifest).unwrap(); + // This package may declare SQLite names only as dev-dependencies. + let shipped = manifest_dep_names(&manifest, false); + for name in SQLITE { + assert!( + !shipped.iter().any(|declared| declared.as_str() == name), + "Cargo.toml declares {name} outside dev-dependencies: SQLite is back in the \ + shipped build (see vendor/README.md)" + ); + } + // Nothing outside the family itself and this package (dev-only, + // checked above) may depend on a SQLite-family package. + for (name, deps) in &packages { + for dep in deps { + if SQLITE.contains(&dep.as_str()) { + assert!( + SQLITE.contains(&name.as_str()) || name == &root, + "{name} depends on {dep}: SQLite is back in the shipped build (see \ + vendor/README.md)" + ); + } + } + } + + let vendored = + std::fs::read_to_string(format!("{manifest_dir}/vendor/p2panda-sync/Cargo.toml")) + .unwrap(); + let store_line = vendored .lines() .find(|line| line.starts_with("p2panda-store = {")) .unwrap(); From 8907387067629e96510214e29c0e742d13b8a9e5 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 13:31:54 -0500 Subject: [PATCH 2/3] fix(id): re-baseline roc-counter fuel budgets after the pf.Screen migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #565 migrated roc-counter from a bare text view to rendering through pf.Screen, a boxed 20x3 structured screen. Rendering the screen costs more wasmtime fuel than returning a string: View now measures 260,269 and Layout 323,425 against the stale 100,000 budgets (pre-migration baselines were 1,327 and 1,337). Regenerated with the shipped print_fuel_baseline generator under the table's own rule (baseline +25%, rounded up to the next 100,000): View 400,000, Layout 500,000. Both measurements match the failing nix build log exactly; no other row's budget changes. The `id world measure` test carries its own bound (worst call < 1% of the 10,000,000 fuel limit) — the same pre-Screen assumption. Update it consistently with the re-baselined envelope: the worst call is Layout at 3.23%, and the largest per-call budget the table allows this module is 500,000 = 5% of the limit, so the bound is now < 5 percent with the tie to FUEL_BUDGETS spelled out in a comment. Refs #3160 --- pkgs/id/src/commands/world.rs | 7 ++++++- pkgs/id/src/sandbox.rs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/id/src/commands/world.rs b/pkgs/id/src/commands/world.rs index d78afe79ad..3425ed5d1a 100644 --- a/pkgs/id/src/commands/world.rs +++ b/pkgs/id/src/commands/world.rs @@ -1940,7 +1940,12 @@ mod tests { assert!(calls[kind]["fuel_max"].as_u64().unwrap() > 0, "{kind}"); } assert!(calls.get("restore").is_none(), "{report}"); - assert!(report["worst_call_percent_of_limit"].as_f64().unwrap() < 1.0); + // The worst call is layout, rendering the pf.Screen frame. Its + // ceiling is the largest per-call budget FUEL_BUDGETS allows this + // module (500_000 of the 10_000_000 limit), so the report must stay + // under 5 percent; before the Screen migration the bare-text view + // stayed under 1. + assert!(report["worst_call_percent_of_limit"].as_f64().unwrap() < 5.0); // Without a viewport there is no layout call; bad hex is refused // before the module runs. diff --git a/pkgs/id/src/sandbox.rs b/pkgs/id/src/sandbox.rs index aac6fee22a..86dd104836 100644 --- a/pkgs/id/src/sandbox.rs +++ b/pkgs/id/src/sandbox.rs @@ -2105,8 +2105,8 @@ mod tests { const FUEL_BUDGETS: &[(&str, GuestCall, u64)] = &[ ("roc-counter", GuestCall::Init, 100_000), // baseline 1215 ("roc-counter", GuestCall::Update, 100_000), // baseline 3759 - ("roc-counter", GuestCall::View, 100_000), // baseline 1327 - ("roc-counter", GuestCall::Layout, 100_000), // baseline 1337 + ("roc-counter", GuestCall::View, 400_000), // baseline 260269 + ("roc-counter", GuestCall::Layout, 500_000), // baseline 323425 ("roc-counter", GuestCall::Records, 100_000), // baseline 1866 ("roc-counter", GuestCall::Wants, 100_000), // baseline 733 ("roc-counter", GuestCall::Snapshot, 100_000), // baseline 874 From e3061ecb2eefdc0a8a91036dc5874eb5b23e0e70 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 13:31:54 -0500 Subject: [PATCH 3/3] fix(id): world_ws tests catch up with the Screen capability model Compile test: roc-counter's main.roc imports pf.Screen and pf.RocText, and the compile gate admits only capabilities the world has granted. The test world granted nothing, so the gate correctly refused the compile. Grant both through world.update_caps, the same admin path as `id world caps --grant`; the ceiling check itself is untouched. Upload test: the module's view now returns a pf.Screen frame, so the snapshot/event data assertions expecting bare "count=0"/"count=1" text now parse the screen JSON, assert kind == "screen", and assert a row shows the expected count. Both tests share a small assert_screen_data helper. Refs #3160 --- pkgs/id/src/web/world_ws.rs | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/pkgs/id/src/web/world_ws.rs b/pkgs/id/src/web/world_ws.rs index a8c48bc23a..70ebb3d4f5 100644 --- a/pkgs/id/src/web/world_ws.rs +++ b/pkgs/id/src/web/world_ws.rs @@ -1063,6 +1063,26 @@ mod tests { } } + /// Read one presentation frame and assert its data is a `pf.Screen` + /// frame whose rows show the counter at `count`. Since the pf.Screen + /// migration the roc-counter view returns screen JSON, not the bare + /// `count=N` text these tests originally asserted. + #[cfg(feature = "sandbox")] + async fn assert_screen_data(client: &mut Client, count: u8) { + let frame = next_frame(client).await.unwrap(); + let screen: serde_json::Value = + serde_json::from_str(frame["data"].as_str().unwrap()).unwrap(); + assert_eq!(screen["kind"], "screen", "{frame}"); + assert!( + screen["rows"].as_array().unwrap().iter().any(|row| { + row.as_str() + .unwrap_or_default() + .contains(&format!("count={count}")) + }), + "no screen row shows count={count}: {screen}" + ); + } + fn join(capability: &JoinCapability, after: Option) -> serde_json::Value { serde_json::json!({ "type": "join", @@ -1270,7 +1290,7 @@ mod tests { .unwrap(); let mut player = connect(addr, join(&capability, None)).await; assert_eq!(next_frame(&mut player).await.unwrap()["type"], "snapshot"); - assert_eq!(next_frame(&mut player).await.unwrap()["data"], "count=0"); + assert_screen_data(&mut player, 0).await; player .send(ClientMessage::Text( r#"{"type":"input","data_hex":"696e63"}"#.into(), @@ -1278,7 +1298,7 @@ mod tests { .await .unwrap(); assert_eq!(next_frame(&mut player).await.unwrap()["type"], "event"); - assert_eq!(next_frame(&mut player).await.unwrap()["data"], "count=1"); + assert_screen_data(&mut player, 1).await; } #[cfg(feature = "sandbox")] @@ -1314,6 +1334,13 @@ mod tests { )) .unwrap(); let world = WorldHandle::spawn(WorldCore::new("lobby", WorldLimits::default()).unwrap()); + // roc-counter's main.roc imports pf.Screen and pf.RocText, and the + // compile gate admits only capabilities the world has granted; + // grant them the way an admin would (`id world caps --grant`). + world + .update_caps(vec!["Screen".to_owned(), "RocText".to_owned()], Vec::new()) + .await + .unwrap(); let blobs: iroh_blobs::api::Store = MemStore::new().into(); let service = WorldService::new(world.clone(), Some("admin".to_owned())) .with_blob_store(blobs.clone()) @@ -1352,7 +1379,7 @@ mod tests { .unwrap(); let mut player = connect(addr, join(&capability, None)).await; assert_eq!(next_frame(&mut player).await.unwrap()["type"], "snapshot"); - assert_eq!(next_frame(&mut player).await.unwrap()["data"], "count=0"); + assert_screen_data(&mut player, 0).await; player .send(ClientMessage::Text( r#"{"type":"input","data_hex":"696e63"}"#.into(), @@ -1360,7 +1387,7 @@ mod tests { .await .unwrap(); assert_eq!(next_frame(&mut player).await.unwrap()["type"], "event"); - assert_eq!(next_frame(&mut player).await.unwrap()["data"], "count=1"); + assert_screen_data(&mut player, 1).await; } #[cfg(feature = "sandbox")]