feat(runtime): support Studio Play and separate integration gates
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good

Add the windowless Studio host with authenticated binary control/frame channels,
managed input, pause/resume/stop, frame ownership and save-aware shutdown.
Preserve deterministic headless execution and add protocol/process fixtures.
Separate unit CI and coverage from opt-in integration/socket qualification,
retaining the prior combined coverage floors in the configuration history.

Validation: tooling make verify passed runtime ci-domains and integration.
This commit is contained in:
2026-11-19 17:32:02 +00:00
parent 2d5735cb13
commit f1adf86dd5
19 changed files with 1484 additions and 38 deletions
@@ -151,6 +151,7 @@ pub struct HostRunner {
render_frame_store: LatestRenderFrameStore,
/// Tracks whether a new logical frame or host-only surface invalidation requires presentation.
presentation: PresentationState,
studio_capture: bool,
}
impl HostRunner {
@@ -238,9 +239,161 @@ impl HostRunner {
audio: HostAudio::new(),
render_frame_store,
presentation: PresentationState::default(),
studio_capture: false,
}
}
/// One canonical interactive slice, shared by desktop and Studio pacing.
fn tick_machine(&mut self) {
self.audio.service();
if !self.debugger.waiting_for_start {
if self.studio_capture {
let mut platform = crate::studio::platform::StudioPlatform {
hardware: &mut self.hardware,
store: &self.render_frame_store,
};
self.firmware.tick(&self.input.signals, &mut platform);
} else {
self.firmware.tick(&self.input.signals, &mut self.hardware);
}
self.stats.record_host_cpu_time(self.firmware.os.vm().last_frame_cpu_time_us());
}
self.hardware.audio.set_paused(
self.firmware.game_lifecycle_audio_paused()
|| self.firmware.os.vm().paused()
|| self.debugger.waiting_for_start,
);
self.audio.service();
}
pub(crate) fn studio_audio_init(&mut self) {
if let Err(error) = self.audio.init(self.hardware.audio.transport()) {
eprintln!("[HostAudio] Disabled: {error}");
}
}
pub(crate) fn studio_boot_step(&mut self, disposable: bool) -> Result<bool, String> {
self.studio_capture = true;
if matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
return Ok(true);
}
if matches!(self.firmware.state, FirmwareState::AppCrashes(_)) {
return Err("Cartridge failed during Studio boot".into());
}
self.firmware.os.memcard().poll(Instant::now());
if let FirmwareState::LoadCartridge(step) = &mut self.firmware.state
&& step.needs_memcard_choice()
&& !self.firmware.os.memcard().preparation_active()
{
let choice = if disposable {
prometeu_system::memcard::admission::Choice::MemoryFresh
} else {
prometeu_system::memcard::admission::Choice::Persistent
};
step.choose_memcard(
&mut self.firmware.os,
choice,
self.hardware.wall_clock().utc_unix_seconds(),
)
.map_err(|e| format!("Studio save selection failed: {e:?}"))?;
}
self.tick_machine();
self.studio_logs();
Ok(matches!(self.firmware.state, FirmwareState::GameRunning(_)))
}
pub(crate) fn studio_step(
&mut self,
signals: prometeu_hal::InputSignals,
) -> Result<(), String> {
self.input.signals = signals;
self.tick_machine();
self.studio_logs();
if matches!(self.firmware.state, FirmwareState::AppCrashes(_)) {
return Err("Cartridge faulted during Studio Play".into());
}
Ok(())
}
pub(crate) fn studio_pause(&mut self, paused: bool) {
self.input.clear_guest_signals();
self.firmware.os.vm().set_paused(paused);
self.hardware.audio.set_paused(paused);
self.audio.service();
}
pub(crate) fn studio_dimensions(&self) -> (usize, usize) {
self.hardware.display_size()
}
pub(crate) fn studio_tick_index(&mut self) -> u64 {
self.firmware.os.frame_index()
}
pub(crate) fn studio_frame(
&mut self,
previous: Option<(RenderOwnership, prometeu_hal::FrameId)>,
) -> Option<OwnedRgba8888Frame> {
let active = self.firmware.os.vm().active_render_ownership();
self.render_frame_store
.latest_frame_after(previous)
.filter(|frame| should_present_worker_frame(&self.firmware.state, frame, active))
}
fn studio_logs(&mut self) {
let last = self.log_sink.last_seq();
let events = match last {
Some(seq) => self.firmware.os.logs_after(seq),
None => self.firmware.os.recent_logs(4096),
};
self.log_sink.process_events(events);
}
pub(crate) fn studio_stop(&mut self, disposable: bool) -> Result<(), String> {
self.studio_pause(true);
let deadline = Instant::now() + Duration::from_secs(2);
loop {
let service = self.firmware.os.memcard();
service.poll(Instant::now());
if !service.session.io_active()
&& !service.session.has_deferred_write()
&& !service.preparation_active()
{
break;
}
if Instant::now() >= deadline {
return Err("Save IO has not finished; retry Stop".into());
}
let lane = service.lane.clone();
lane.wait_for_progress(lane.progress_stamp(), Duration::from_millis(5));
}
if self.firmware.os.memcard().session.unsaved() && !disposable {
return Err("Unsaved game data; resume and save before stopping".into());
}
self.firmware
.os
.stop_background_io()
.map_err(|e| format!("Save shutdown failed: {e:?}"))?;
self.firmware.os.memcard().session.end_session();
self.firmware.os.memcard().poll(Instant::now());
self.firmware
.os
.memcard()
.uninstall_card()
.map_err(|e| format!("Save detach failed: {e:?}"))?;
self.firmware
.os
.vm()
.stop_render_worker()
.map_err(|e| format!("Render shutdown failed: {e:?}"))?;
Ok(())
}
pub(crate) fn studio_abort(&mut self) {
self.studio_pause(true);
let _ = self.firmware.os.vm().stop_render_worker();
let _ = self.firmware.os.stop_background_io();
}
fn window(&self) -> &'static Window {
self.window.expect("window not created yet")
}
@@ -435,18 +588,7 @@ impl ApplicationHandler for HostRunner {
while self.accumulator >= self.frame_target_dt {
// Reclaim returned audio owners before another guest attempt, even
// when the previous attempt paused or stopped at backpressure.
self.audio.service();
// Unless the debugger is waiting for a 'start' command, advance the system.
if !self.debugger.waiting_for_start {
self.firmware.tick(&self.input.signals, &mut self.hardware);
self.stats.record_host_cpu_time(self.firmware.os.vm().last_frame_cpu_time_us());
}
let is_paused = self.firmware.game_lifecycle_audio_paused()
|| self.firmware.os.vm().paused()
|| self.debugger.waiting_for_start;
self.hardware.audio.set_paused(is_paused);
self.audio.service();
self.tick_machine();
self.accumulator -= self.frame_target_dt;
self.stats.record_frame();
@@ -500,6 +642,73 @@ impl ApplicationHandler for HostRunner {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn studio_can_boot_and_publish_without_a_window() {
let cart = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../../test-cartridges/dummy-boy");
let mut host = HostRunner::new(None, None);
host.set_boot_target(BootTarget::Cartridge {
path: cart.to_string_lossy().into_owned(),
debug: false,
debug_port: 0,
});
let deadline = Instant::now() + Duration::from_secs(5);
while !host.studio_boot_step(true).unwrap() {
assert!(Instant::now() < deadline);
std::thread::sleep(Duration::from_millis(1));
}
host.studio_pause(true);
host.studio_pause(false);
for _ in 0..60 {
host.studio_step(Default::default()).unwrap();
std::thread::sleep(Duration::from_millis(2));
}
let frame = host.studio_frame(None);
let published = host.render_frame_store.latest_frame().map(|f| (f.frame_id, f.ownership));
let active = host.firmware.os.vm().active_render_ownership();
assert!(
frame.is_some(),
"store {published:?}, owner {active:?}, state {:?}, frame {}",
host.firmware.state,
host.firmware.os.frame_index()
);
let frame = frame.unwrap();
assert!(host.studio_frame(Some((frame.ownership, frame.frame_id))).is_none());
// Exercise the same audio transport/callback through Studio lifecycle,
// without requiring a physical output device in this contract test.
use prometeu_hal::{AudioBridge, LoopMode, sample::Sample};
let (mut callback, mut reclaimer) = crate::audio::AudioCallback::new();
assert_eq!(
host.hardware.audio.play_sample(
Arc::new(Sample::new(48000, vec![1000; 32])),
0,
255,
0,
1.0,
0,
LoopMode::On,
),
prometeu_hal::AudioOpStatus::Ok
);
host.hardware.audio.finish_frame();
let transport = host.hardware.audio.transport();
let mut pcm = [0.0; 64];
callback.render(&transport, &mut pcm);
assert!(pcm.iter().any(|sample| *sample != 0.0));
reclaimer.service(&transport);
host.studio_pause(true);
callback.render(&transport, &mut pcm);
assert!(pcm.iter().all(|sample| *sample == 0.0));
reclaimer.service(&transport);
host.studio_pause(false);
callback.render(&transport, &mut pcm);
assert!(pcm.iter().any(|sample| *sample != 0.0));
reclaimer.service(&transport);
host.studio_stop(true).unwrap();
callback.render(&transport, &mut pcm);
assert!(pcm.iter().all(|sample| *sample == 0.0));
}
use prometeu_firmware::BootTarget;
use prometeu_firmware::firmware::firmware_state::{
GameRunningStep, HubHomeStep, ShellRunningStep,