//! The plan and todos ports run through real world extension snapshots and survive restart. use sausage::world::World; use std::path::Path; const BUNDLE: &str = include_str!("../js/plan-todos-test-bundle.js"); #[tokio::test(flavor = "current_thread")] async fn plan_todos_and_restart() -> anyhow::Result<()> { let userland = Path::new(env!("CARGO_MANIFEST_DIR")).join("../userland"); let target = Path::new(env!("CARGO_TARGET_TMPDIR")).parent().unwrap(); if !userland.join("cwd-init/init.o").is_file() { assert!( std::process::Command::new("nu") .args(["--no-config-file", "cwd-init/build.nu"]) .current_dir(&userland) .status()? .success() ); } assert!( std::process::Command::new("cargo") .args(["build", "--release", "-p", "git", "--manifest-path"]) .arg(userland.join("Cargo.toml")) .args(["--target", "wasm32-wasip2", "--target-dir"]) .arg(target) .args(["-j", "2", "--locked"]) .current_dir(&userland) .status()? .success() ); let dir = tempfile::tempdir()?; let disk = dir.path().join("world"); let _world = World::open(dir.path())?; std::fs::create_dir_all(disk.join("bin"))?; std::fs::copy( target.join("wasm32-wasip2/release/git.wasm"), disk.join("bin/git.wasm"), )?; let repo = disk.join("src/sausage"); std::fs::create_dir_all(&repo)?; assert!( std::process::Command::new("git") .args(["init", "-b", "main"]) .arg(&repo) .status()? .success() ); for name in ["plan", "todos"] { let destination = repo.join("extensions").join(name); std::fs::create_dir_all(&destination)?; std::fs::copy( Path::new(env!("CARGO_MANIFEST_DIR")) .join("../extensions") .join(name) .join("server.ts"), destination.join("server.ts"), )?; } assert!( std::process::Command::new("git") .args(["add", "."]) .current_dir(&repo) .status()? .success() ); assert!( std::process::Command::new("git") .args([ "-c", "user.name=Test", "-c", "user.email=test@example.com", "commit", "--no-gpg-sign", "-m", "plan and todos" ]) .current_dir(&repo) .status()? .success() ); for restart in [false, true] { let world = World::open(dir.path())?; let exec = sausage::process::exec(World { root: world.root.clone(), host_dir: world.host_dir.clone(), processes: world.processes.clone(), })?; sausage::harness::run_module( world, exec, &format!("globalThis.planTodosRestart={restart};\n{BUNDLE}"), ) .await?; } Ok(()) }