Phase 33 NORM canon test: enforce normalized dev route for P1/P2/JP mini
This commit is contained in:
@ -29,7 +29,11 @@ macro_rules! ny_wrap_string {
|
||||
pub fn $name(&self) -> StringBox {
|
||||
match self.$inner() {
|
||||
Ok(result) => StringBox::new(result),
|
||||
Err(e) => panic!("FileHandleBox.{}() failed: {}", stringify!($name).trim_start_matches("ny_"), e),
|
||||
Err(e) => panic!(
|
||||
"FileHandleBox.{}() failed: {}",
|
||||
stringify!($name).trim_start_matches("ny_"),
|
||||
e
|
||||
),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -40,7 +44,11 @@ macro_rules! ny_wrap_bool {
|
||||
pub fn $name(&self) -> BoolBox {
|
||||
match self.$inner() {
|
||||
Ok(result) => BoolBox::new(result),
|
||||
Err(e) => panic!("FileHandleBox.{}() failed: {}", stringify!($name).trim_start_matches("ny_"), e),
|
||||
Err(e) => panic!(
|
||||
"FileHandleBox.{}() failed: {}",
|
||||
stringify!($name).trim_start_matches("ny_"),
|
||||
e
|
||||
),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -51,7 +59,11 @@ macro_rules! ny_wrap_integer {
|
||||
pub fn $name(&self) -> crate::box_trait::IntegerBox {
|
||||
match self.$inner() {
|
||||
Ok(result) => crate::box_trait::IntegerBox::new(result as i64),
|
||||
Err(e) => panic!("FileHandleBox.{}() failed: {}", stringify!($name).trim_start_matches("ny_"), e),
|
||||
Err(e) => panic!(
|
||||
"FileHandleBox.{}() failed: {}",
|
||||
stringify!($name).trim_start_matches("ny_"),
|
||||
e
|
||||
),
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -156,8 +168,8 @@ impl FileHandleBox {
|
||||
}
|
||||
|
||||
// Get FileIo provider to check capabilities
|
||||
let provider = provider_lock::get_filebox_provider()
|
||||
.ok_or_else(provider_not_initialized)?;
|
||||
let provider =
|
||||
provider_lock::get_filebox_provider().ok_or_else(provider_not_initialized)?;
|
||||
|
||||
// NoFs profile check (Fail-Fast)
|
||||
let caps = provider.caps();
|
||||
@ -171,8 +183,8 @@ impl FileHandleBox {
|
||||
// Create NEW independent Ring0FsFileIo instance for this handle
|
||||
// IMPORTANT: We must create a new instance, not clone the Arc
|
||||
// because Ring0FsFileIo has internal state (path field)
|
||||
use crate::runtime::get_global_ring0;
|
||||
use crate::providers::ring1::file::ring0_fs_fileio::Ring0FsFileIo;
|
||||
use crate::runtime::get_global_ring0;
|
||||
|
||||
let ring0 = get_global_ring0();
|
||||
|
||||
@ -281,11 +293,12 @@ impl FileHandleBox {
|
||||
///
|
||||
/// Unified metadata access through FileIo trait.
|
||||
fn metadata_internal(&self) -> Result<crate::boxes::file::provider::FileStat, String> {
|
||||
let io = self.io.as_ref()
|
||||
let io = self
|
||||
.io
|
||||
.as_ref()
|
||||
.ok_or_else(|| "FileHandleBox is not open".to_string())?;
|
||||
|
||||
io.stat()
|
||||
.map_err(|e| format!("Metadata failed: {}", e))
|
||||
io.stat().map_err(|e| format!("Metadata failed: {}", e))
|
||||
}
|
||||
|
||||
/// Get file size in bytes
|
||||
@ -308,7 +321,9 @@ impl FileHandleBox {
|
||||
///
|
||||
/// Uses FileIo::exists() for direct check.
|
||||
pub fn exists(&self) -> Result<bool, String> {
|
||||
let io = self.io.as_ref()
|
||||
let io = self
|
||||
.io
|
||||
.as_ref()
|
||||
.ok_or_else(|| "FileHandleBox is not open".to_string())?;
|
||||
|
||||
Ok(io.exists())
|
||||
@ -395,7 +410,9 @@ impl NyashBox for FileHandleBox {
|
||||
fn to_string_box(&self) -> StringBox {
|
||||
StringBox::new(format!(
|
||||
"FileHandleBox(path={}, mode={}, open={})",
|
||||
self.path, self.mode, self.is_open()
|
||||
self.path,
|
||||
self.mode,
|
||||
self.is_open()
|
||||
))
|
||||
}
|
||||
|
||||
@ -442,8 +459,8 @@ mod tests {
|
||||
|
||||
/// Helper: Initialize FileBox provider for tests
|
||||
fn init_test_provider() {
|
||||
use crate::runtime::ring0::{default_ring0, init_global_ring0};
|
||||
use crate::providers::ring1::file::ring0_fs_fileio::Ring0FsFileIo;
|
||||
use crate::runtime::ring0::{default_ring0, init_global_ring0};
|
||||
use std::panic;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -720,7 +737,7 @@ mod tests {
|
||||
init_test_provider();
|
||||
|
||||
let path = "/tmp/phase111_append_test.txt";
|
||||
let _ = fs::remove_file(path); // cleanup
|
||||
let _ = fs::remove_file(path); // cleanup
|
||||
|
||||
// First write (truncate)
|
||||
let mut handle = FileHandleBox::new();
|
||||
@ -751,7 +768,7 @@ mod tests {
|
||||
// Write test file
|
||||
let mut handle = FileHandleBox::new();
|
||||
handle.open(path, "w").unwrap();
|
||||
handle.write_all("hello").unwrap(); // 5 bytes
|
||||
handle.write_all("hello").unwrap(); // 5 bytes
|
||||
handle.close().unwrap();
|
||||
|
||||
// Check size
|
||||
@ -967,7 +984,9 @@ mod tests {
|
||||
|
||||
// Test metadata_internal() via stat()
|
||||
handle.open(path, "r").unwrap();
|
||||
let stat = handle.metadata_internal().expect("metadata_internal should succeed");
|
||||
let stat = handle
|
||||
.metadata_internal()
|
||||
.expect("metadata_internal should succeed");
|
||||
assert!(stat.is_file);
|
||||
assert!(!stat.is_dir);
|
||||
assert_eq!(stat.size, 5);
|
||||
|
||||
@ -89,8 +89,8 @@ impl FileBox {
|
||||
// Create NEW independent provider instance for this FileBox
|
||||
// IMPORTANT: We must create a new instance, not clone the Arc,
|
||||
// because Ring0FsFileIo has internal state (path field)
|
||||
use crate::runtime::get_global_ring0;
|
||||
use crate::providers::ring1::file::ring0_fs_fileio::Ring0FsFileIo;
|
||||
use crate::runtime::get_global_ring0;
|
||||
|
||||
let ring0 = get_global_ring0();
|
||||
|
||||
@ -126,7 +126,8 @@ impl FileBox {
|
||||
}
|
||||
// Phase 108: UTF-8 conversion (text-oriented design)
|
||||
let text = String::from_utf8_lossy(buf).to_string();
|
||||
provider.write(&text)
|
||||
provider
|
||||
.write(&text)
|
||||
.map_err(|e| format!("Write failed: {:?}", e))
|
||||
} else {
|
||||
Err(no_provider_available())
|
||||
@ -160,7 +161,10 @@ impl FileBox {
|
||||
Err(e) => Box::new(StringBox::new(format!("Error: {:?}", e))),
|
||||
}
|
||||
} else {
|
||||
Box::new(StringBox::new(format!("Error: {}", no_provider_available())))
|
||||
Box::new(StringBox::new(format!(
|
||||
"Error: {}",
|
||||
no_provider_available()
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,8 +234,8 @@ impl std::fmt::Display for FileBox {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::runtime::ring0::{default_ring0, GLOBAL_RING0};
|
||||
use crate::providers::ring1::file::ring0_fs_fileio::Ring0FsFileIo;
|
||||
use crate::runtime::ring0::{default_ring0, GLOBAL_RING0};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
|
||||
@ -345,11 +349,7 @@ mod tests {
|
||||
|
||||
let fb = FileBox::open(tmp_path).expect("open failed");
|
||||
let exists_box = fb.exists();
|
||||
let exists = exists_box
|
||||
.as_any()
|
||||
.downcast_ref::<BoolBox>()
|
||||
.unwrap()
|
||||
.value;
|
||||
let exists = exists_box.as_any().downcast_ref::<BoolBox>().unwrap().value;
|
||||
|
||||
assert!(exists);
|
||||
|
||||
|
||||
@ -60,7 +60,8 @@ impl FileCaps {
|
||||
return Err("Read not supported by FileBox provider".to_string());
|
||||
}
|
||||
}
|
||||
"w" | "a" => { // Phase 111: "a" added
|
||||
"w" | "a" => {
|
||||
// Phase 111: "a" added
|
||||
if !self.write {
|
||||
return Err("Write not supported by FileBox provider".to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user