use tensor_wasm_core::types::InstanceId;
use tensor_wasm_wasi_gpu::host::WasiCudaContext;
#[test]
fn last_error_is_per_instance() {
let ctx_a = WasiCudaContext::new(InstanceId(1001));
let ctx_b = WasiCudaContext::new(InstanceId(1002));
assert!(
ctx_a.last_error().is_none(),
"fresh ctx A must have no last_error",
);
assert!(
ctx_b.last_error().is_none(),
"fresh ctx B must have no last_error",
);
ctx_a.record_error_for_test("instance-A failure");
assert_eq!(
ctx_a.last_error().as_deref(),
Some("instance-A failure"),
"ctx A must see its own recorded error",
);
assert!(
ctx_b.last_error().is_none(),
"ctx B must NOT see ctx A's error — last_error is per-instance state, \
got: {:?}",
ctx_b.last_error(),
);
ctx_b.record_error_for_test("instance-B failure");
assert_eq!(
ctx_a.last_error().as_deref(),
Some("instance-A failure"),
"ctx A's slot must not be overwritten by a record on ctx B",
);
assert_eq!(
ctx_b.last_error().as_deref(),
Some("instance-B failure"),
"ctx B must see its own recorded error",
);
}