implements PLN-0086 render boundary validation

This commit is contained in:
2026-05-25 14:29:02 +01:00
parent 232fb7106d
commit 91fab7de96
3 changed files with 79 additions and 2 deletions
@@ -483,6 +483,7 @@ fn tick_shell_profile_closes_gfxui_commands_into_shell_packet() {
};
assert_eq!(packet.commands.len(), 1);
assert!(matches!(packet.commands[0], prometeu_hal::GfxUiCommand::Clear { .. }));
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x11223344).raw());
}
#[test]
@@ -782,6 +783,82 @@ fn tick_draw_text_survives_no_scene_frame_path() {
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x11223344).raw());
}
#[test]
fn tick_game_submissions_are_immutable_and_latest_complete_wins() {
let mut runtime = VirtualMachineRuntime::new(None);
let mut log_service = LogService::new(4096);
let mut fs = VirtualFS::new();
let mut fs_state = FsState::Unmounted;
let mut memcard = MemcardService::new();
let mut open_files: HashMap<u32, String> = HashMap::new();
let mut next_handle = 1;
let mut vm = VirtualMachine::default();
let signals = InputSignals::default();
let code = assemble("PUSH_I32 287454020\nHOSTCALL 0\nFRAME_SYNC\nHALT").expect("assemble");
let program = serialized_single_function_module(
code,
vec![SyscallDecl {
module: "gfx2d".into(),
name: "clear".into(),
version: 1,
arg_slots: 1,
ret_slots: 0,
}],
);
let cartridge = cartridge_with_program(program, caps::GFX);
let mut hardware = Hardware::new();
runtime.initialize_vm(&mut log_service, &mut vm, &cartridge).expect("runtime must initialize");
let first_report = runtime.tick(
&mut log_service,
&mut fs,
&mut fs_state,
&mut memcard,
&mut open_files,
&mut next_handle,
&mut vm,
&signals,
&mut hardware,
);
assert!(first_report.is_none());
let first_submission =
runtime.render_manager.latest_complete_submission().expect("first submission").clone();
let prometeu_hal::RenderSubmissionPacket::Game2D(first_packet) = &first_submission.packet
else {
panic!("expected first Game2D submission");
};
assert_eq!(first_packet.gfx2d.len(), 1);
assert!(matches!(
first_packet.gfx2d[0],
prometeu_hal::Gfx2dCommand::Clear { color } if color == Color::from_raw(0x11223344)
));
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x11223344).raw());
let second_packet = prometeu_hal::Game2DFramePacket::new(
Default::default(),
vec![prometeu_hal::Gfx2dCommand::Clear { color: Color::from_raw(0x55667788) }],
);
runtime
.render_manager
.close_frame_with_packet(prometeu_hal::RenderSubmissionPacket::Game2D(second_packet))
.expect("manual Game2D packet matches active mode");
let latest = runtime.render_manager.latest_complete_submission().expect("latest submission");
assert_ne!(latest.frame_id, first_submission.frame_id);
let prometeu_hal::RenderSubmissionPacket::Game2D(latest_packet) = &latest.packet else {
panic!("expected latest Game2D submission");
};
let prometeu_hal::Gfx2dCommand::Clear { color: latest_color } = latest_packet.gfx2d[0] else {
panic!("expected latest clear command");
};
assert_eq!(latest_color, Color::from_raw(0x55667788));
assert!(matches!(
first_packet.gfx2d[0],
prometeu_hal::Gfx2dCommand::Clear { color } if color == Color::from_raw(0x11223344)
));
prometeu_hal::HardwareBridge::publish_render_submission(&mut hardware, latest);
assert_eq!(hardware.gfx.front_buffer()[0], Color::from_raw(0x55667788).raw());
}
#[test]
fn initialize_vm_success_clears_previous_crash_report() {
let mut runtime = VirtualMachineRuntime::new(None);