From 6ef376763c730c33ea3209a77550190af1f24bb7 Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Fri, 18 Sep 2026 23:11:49 +0100 Subject: [PATCH] multi-frontend-pvm-neutrality --- crates/console/prometeu-bytecode/src/model.rs | 2 +- .../prometeu-vm/src/virtual_machine.rs | 7 ++ .../tests/pvm_frontend_neutrality.rs | 74 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 crates/dev/prometeu-quality-checks/tests/pvm_frontend_neutrality.rs diff --git a/crates/console/prometeu-bytecode/src/model.rs b/crates/console/prometeu-bytecode/src/model.rs index f357c917..3f3cdb0f 100644 --- a/crates/console/prometeu-bytecode/src/model.rs +++ b/crates/console/prometeu-bytecode/src/model.rs @@ -750,7 +750,7 @@ mod tests { #[test] fn test_invalid_magic() { let mut data = create_header(0); - data[0] = b'X'; + data[0..4].copy_from_slice(b"PBS\0"); assert_eq!(BytecodeLoader::load(&data), Err(LoadError::InvalidMagic)); } diff --git a/crates/console/prometeu-vm/src/virtual_machine.rs b/crates/console/prometeu-vm/src/virtual_machine.rs index f6707fd2..7f2de71d 100644 --- a/crates/console/prometeu-vm/src/virtual_machine.rs +++ b/crates/console/prometeu-vm/src/virtual_machine.rs @@ -2695,6 +2695,13 @@ mod tests { assert_eq!(vm.pc, 0); assert_eq!(vm.program.rom.len(), 2); assert_eq!(vm.cycles, 0); + + vm.prepare_boot_call(); + let mut native = MockNative; + let mut ctx = HostContext::new(None); + let report = vm.run_budget(100, &mut native, &mut ctx).expect("run loaded PBX"); + assert_eq!(report.reason, LogicalFrameEndingReason::Halted); + assert!(vm.is_halted()); } #[test] diff --git a/crates/dev/prometeu-quality-checks/tests/pvm_frontend_neutrality.rs b/crates/dev/prometeu-quality-checks/tests/pvm_frontend_neutrality.rs new file mode 100644 index 00000000..d38ea7a3 --- /dev/null +++ b/crates/dev/prometeu-quality-checks/tests/pvm_frontend_neutrality.rs @@ -0,0 +1,74 @@ +use std::fs; +use std::path::{Path, PathBuf}; + +const TARGET_MANIFESTS: &[&str] = + &["crates/console/prometeu-bytecode/Cargo.toml", "crates/console/prometeu-vm/Cargo.toml"]; + +const FORBIDDEN_DEPENDENCY_FRAGMENTS: &[&str] = &["compiler", "frontend"]; + +#[test] +fn pbx_and_pvm_crates_must_not_depend_on_compiler_or_frontend_crates() { + let workspace_root = find_workspace_root().expect("runtime workspace root"); + let mut violations = Vec::new(); + + for relative_path in TARGET_MANIFESTS { + let manifest_path = workspace_root.join(relative_path); + let manifest = fs::read_to_string(&manifest_path) + .unwrap_or_else(|error| panic!("failed to read {}: {error}", manifest_path.display())); + + for dependency in dependency_names(&manifest) { + let normalized = dependency.to_ascii_lowercase(); + if FORBIDDEN_DEPENDENCY_FRAGMENTS.iter().any(|fragment| normalized.contains(fragment)) { + violations.push(format!("{relative_path}: forbidden dependency `{dependency}`")); + } + } + } + + assert!( + violations.is_empty(), + "PBX/PVM crates must remain independent of compiler and frontend crates:\n{}", + violations.join("\n") + ); +} + +fn dependency_names(manifest: &str) -> Vec<&str> { + let mut names = Vec::new(); + let mut in_dependency_section = false; + + for raw_line in manifest.lines() { + let line = raw_line.trim(); + if line.starts_with('[') && line.ends_with(']') { + let section = &line[1..line.len() - 1]; + in_dependency_section = section == "dependencies" + || section == "dev-dependencies" + || section == "build-dependencies" + || section.ends_with(".dependencies") + || section.ends_with(".dev-dependencies") + || section.ends_with(".build-dependencies"); + continue; + } + + if !in_dependency_section || line.is_empty() || line.starts_with('#') { + continue; + } + + if let Some((name, _)) = line.split_once('=') { + names.push(name.trim().trim_matches('"')); + } + } + + names +} + +fn find_workspace_root() -> Option { + let mut cursor = Path::new(env!("CARGO_MANIFEST_DIR")).to_path_buf(); + loop { + let manifest = cursor.join("Cargo.toml"); + if fs::read_to_string(&manifest).is_ok_and(|contents| contents.contains("[workspace]")) { + return Some(cursor); + } + if !cursor.pop() { + return None; + } + } +} -- 2.47.2