cargo.build: write the SDK copy in the cache only when a build needs it
An unwritable cache makes only a build fail, with the folder in data.output. The host still starts.
This commit is contained in:
@@ -268,6 +268,42 @@ async fn native_discovery_and_error_paths() {
|
||||
);
|
||||
host.stop().await;
|
||||
}
|
||||
/// Rework 3: an unavailable cache prevents builds, not host startup or SDK installation.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn cache_failure_is_deferred_until_build() {
|
||||
let world = TestWorld::new();
|
||||
world.source("simple", &fixture("cargo-test-fail"));
|
||||
// A file blocks directory creation even when the test runs as root.
|
||||
let cache = world.0.join("blocked-cache");
|
||||
std::fs::write(&cache, "not a directory").unwrap();
|
||||
let host = Host::start_with_cache(&world.0, &cache).await.unwrap();
|
||||
assert!(world.0.join("plugins/cargo/sdk/src/lib.rs").is_file());
|
||||
let error = host
|
||||
.call("cargo.build", json!({"plugin":"simple"}))
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(error["code"], -32004);
|
||||
let output = error["data"]["output"].as_str().unwrap();
|
||||
assert!(output.contains(cache.to_str().unwrap()), "{output}");
|
||||
assert!(output.contains("create"), "{output}");
|
||||
host.stop().await;
|
||||
|
||||
let standalone = TestWorld::new();
|
||||
standalone.source("simple", &fixture("cargo-test-fail"));
|
||||
let builder = sausage::cargo::Cargo::with_runner(
|
||||
World::open(&standalone.0).unwrap(),
|
||||
PathBuf::from(env!("CARGO_BIN_EXE_sausage")),
|
||||
&cache,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(standalone.0.join("plugins/cargo/sdk/src/lib.rs").is_file());
|
||||
let error = builder
|
||||
.build(&standalone.0.join("plugins/simple/source"))
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(error.output.contains(cache.to_str().unwrap()), "{error}");
|
||||
assert!(cache.is_file());
|
||||
}
|
||||
/// T23: release-only failures use data.output and retain successful WASI totals.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn release_only_failure() {
|
||||
|
||||
Reference in New Issue
Block a user