test(stress): isolate music cartridge fixture directories
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good

Reserve temporary directories exclusively, cover equal timestamps and include host logs in boot failures.

Work: WRK-0027 (DEC-0002). Validation: make -C tooling verify, run 20261127T004152Z-e028bb55, PASSED.
This commit is contained in:
2026-11-27 00:51:37 +00:00
parent 0d20194aa2
commit e9fcf35580
@@ -1,25 +1,45 @@
use prometeu_drivers::bank_format::{decode_audio_bank, DecodedAudioBank}; use prometeu_drivers::bank_format::{decode_audio_bank, DecodedAudioBank};
use prometeu_host_headless::{AdvanceFrameOutcome, HeadlessHost}; use prometeu_host_headless::{AdvanceFrameOutcome, HeadlessHost};
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::atomic::{AtomicU64, Ordering};
struct Cartridge(PathBuf); struct Cartridge(PathBuf);
impl Cartridge { impl Cartridge {
fn new() -> Self { fn new() -> Self {
let unique = let unique =
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(); std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos();
let path = std::env::temp_dir() Self::with_timestamp(unique)
.join(format!("stress-console-music-{}-{unique}", std::process::id())); }
std::fs::create_dir_all(&path).unwrap();
std::fs::write(path.join("program.pbx"), pbxgen_stress::build_program()).unwrap(); fn with_timestamp(timestamp: u128) -> Self {
std::fs::write(path.join("manifest.json"), pbxgen_stress::manifest_json()).unwrap(); static NEXT_ID: AtomicU64 = AtomicU64::new(0);
std::fs::write(path.join("assets.pa"), pbxgen_stress::build_assets_pack().unwrap()) let path = loop {
let id = NEXT_ID.fetch_add(1, Ordering::Relaxed);
let candidate = std::env::temp_dir()
.join(format!("stress-console-music-{}-{timestamp}-{id}", std::process::id()));
match std::fs::create_dir(&candidate) {
Ok(()) => break candidate,
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(error) => panic!("create cartridge directory {candidate:?}: {error}"),
}
};
let cartridge = Self(path);
std::fs::write(cartridge.0.join("program.pbx"), pbxgen_stress::build_program()).unwrap();
std::fs::write(cartridge.0.join("manifest.json"), pbxgen_stress::manifest_json()).unwrap();
std::fs::write(cartridge.0.join("assets.pa"), pbxgen_stress::build_assets_pack().unwrap())
.unwrap(); .unwrap();
Self(path) cartridge
} }
fn boot(&self) -> HeadlessHost { fn boot(&self) -> HeadlessHost {
let mut host = HeadlessHost::new(); let mut host = HeadlessHost::new();
host.boot(self.0.to_string_lossy()).unwrap(); if let Err(error) = host.boot(self.0.to_string_lossy()) {
panic!(
"boot cartridge {:?}: {error:?}; logs: {:?}",
self.0,
host.log_snapshot(None, 128)
);
}
assert!(matches!( assert!(matches!(
host.advance_frame().unwrap(), host.advance_frame().unwrap(),
AdvanceFrameOutcome::FrameCompleted { .. } AdvanceFrameOutcome::FrameCompleted { .. }
@@ -34,6 +54,19 @@ impl Drop for Cartridge {
} }
} }
#[test]
fn equal_timestamps_keep_cartridge_lifetimes_independent() {
let (first, second) = std::thread::scope(|scope| {
let first = scope.spawn(|| Cartridge::with_timestamp(0));
let second = scope.spawn(|| Cartridge::with_timestamp(0));
(first.join().unwrap(), second.join().unwrap())
});
assert_ne!(first.0, second.0);
drop(first);
drop(second.boot());
drop(second.boot());
}
#[test] #[test]
fn bank_preserves_transcription_and_mixed_samples() { fn bank_preserves_transcription_and_mixed_samples() {
let bytes = include_bytes!("../music/storm-eagle.mbnk"); let bytes = include_bytes!("../music/storm-eagle.mbnk");