Files
hakorune/src/runtime/ring0/mod.rs

259 lines
7.0 KiB
Rust
Raw Normal View History

//! Phase 88: Ring0Context - OS API 抽象化レイヤー
//!
//! Ring0 は Box を知らない、Nyash を知らない純粋な OS API 層。
mod errors;
mod std_impls;
mod traits;
pub use errors::{IoError, TimeError};
pub use std_impls::{NoFsApi, NoopMem, StdFs, StdIo, StdLog, StdMem, StdThread, StdTime};
pub use traits::{
FsApi, FsMetadata, IoApi, LogApi, LogLevel, MemApi, MemStats, ThreadApi, TimeApi,
};
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
use crate::runtime::runtime_profile::RuntimeProfile;
use std::sync::{Arc, OnceLock};
/// Phase 88: Ring0 コンテキスト
///
/// OS API レイヤーを trait で抽象化し、1つの構造体に束ねる。
pub struct Ring0Context {
pub mem: Arc<dyn MemApi>,
pub io: Arc<dyn IoApi>,
pub time: Arc<dyn TimeApi>,
pub log: Arc<dyn LogApi>,
pub fs: Arc<dyn FsApi>, // Phase 90-A
pub thread: Arc<dyn ThreadApi>, // Phase 90-D
}
impl Ring0Context {
/// 新規 Ring0Context を作成
pub fn new(
mem: Arc<dyn MemApi>,
io: Arc<dyn IoApi>,
time: Arc<dyn TimeApi>,
log: Arc<dyn LogApi>,
fs: Arc<dyn FsApi>,
thread: Arc<dyn ThreadApi>,
) -> Self {
Self {
mem,
io,
time,
log,
fs,
thread,
}
}
}
impl std::fmt::Debug for Ring0Context {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Ring0Context")
.field("mem", &"<dyn MemApi>")
.field("io", &"<dyn IoApi>")
.field("time", &"<dyn TimeApi>")
.field("log", &"<dyn LogApi>")
.field("fs", &"<dyn FsApi>")
.field("thread", &"<dyn ThreadApi>")
.finish()
}
}
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
/// Phase 112: Ring0 service registry
///
/// profile ごとに適切な FsApi 実装(等)を選択して Ring0Context を構築する factory。
pub struct Ring0Registry;
impl Ring0Registry {
/// Ring0Context を profile に応じて構築
pub fn build(profile: RuntimeProfile) -> Ring0Context {
match profile {
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
RuntimeProfile::Default => Self::build_with_fs(Arc::new(StdFs)),
RuntimeProfile::NoFs => Self::build_with_fs(Arc::new(NoFsApi)),
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
}
}
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
fn build_with_fs(fs: Arc<dyn FsApi>) -> Ring0Context {
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
Ring0Context {
mem: Arc::new(StdMem::new()),
io: Arc::new(StdIo),
time: Arc::new(StdTime),
log: Arc::new(StdLog),
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
fs,
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
thread: Arc::new(StdThread),
}
}
}
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
/// Phase 88: デフォルト Ring0Context を作成
///
/// Phase 112 以降は、initialize_runtime() を通じて
/// Ring0Registry::build(profile) 経由で初期化されることが推奨。
///
/// この関数は直接呼び出しに対する互換性レイヤーとして保持。
pub fn default_ring0() -> Ring0Context {
Ring0Registry::build(RuntimeProfile::Default)
}
// ===== グローバル Ring0Context =====
pub static GLOBAL_RING0: OnceLock<Arc<Ring0Context>> = OnceLock::new();
/// グローバル Ring0Context を初期化
pub fn init_global_ring0(ctx: Ring0Context) {
GLOBAL_RING0
.set(Arc::new(ctx))
.expect("[Phase 88] Ring0Context already initialized");
}
/// グローバル Ring0Context を取得
pub fn get_global_ring0() -> Arc<Ring0Context> {
GLOBAL_RING0
.get()
.expect("[Phase 88] Ring0Context not initialized")
.clone()
}
// ===== テスト =====
#[cfg(test)]
mod tests {
use super::*;
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
fn unsafe_dealloc(ptr: *mut u8, size: usize) {
unsafe { std::alloc::dealloc(ptr, std::alloc::Layout::from_size_align_unchecked(size, 1)) }
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
}
#[test]
fn test_ring0_context_creation() {
let ring0 = default_ring0();
ring0.log.info("test message");
}
#[test]
fn test_io_api() {
let ring0 = default_ring0();
let result = ring0.io.stdout_write(b"test\n");
assert!(result.is_ok());
}
#[test]
fn test_time_api() {
let ring0 = default_ring0();
let now = ring0.time.now();
assert!(now.is_ok());
let instant = ring0.time.monotonic_now();
assert!(instant.is_ok());
}
#[test]
fn test_log_levels() {
let ring0 = default_ring0();
ring0.log.debug("debug message");
ring0.log.info("info message");
ring0.log.warn("warn message");
ring0.log.error("error message");
}
#[test]
fn test_default_ring0_uses_stdmem() {
let ring0 = default_ring0();
let ptr = ring0.mem.alloc(512);
assert!(!ptr.is_null(), "default_ring0 should use StdMem");
ring0.mem.free(ptr);
// Clean up
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
unsafe_dealloc(ptr, 512);
}
feat(phase112): Ring0 Service Registry統一化実装完了 Ring0 初期化を Ring0Registry::build(profile) に集約し、プロファイル対応を統一化 【実装内容】 - Task 2: Ring0Registry struct + build(profile) メソッド実装 - RuntimeProfile::Default → StdFs を使用 - RuntimeProfile::NoFs → NoFsApi を使用 - build_default()/build_no_fs() の内部メソッド分離 - Task 3: NoFsApi struct 実装(FsApi trait) - すべてのファイルシステム操作を「disabled」として失敗させる - read/write/append/metadata/canonicalize が IoError を返す - exists() は false を返す - 49行の新規実装 - Task 4: initialize_runtime() SSOT パターン確認 - env 読み込み → RuntimeProfile::from_env() - Ring0Context 構築 → Ring0Registry::build(profile) - グローバル登録 → init_global_ring0() - 唯一の責務分離を確立 - Task 5: PluginHost/FileBox/FileHandleBox からの Ring0 統合 - Ring0.fs = NoFsApi の場合、すべての上位層が自動的に disabled - 特別なロジック不要(カスケード disabled パターン) - Task 6: ドキュメント更新 - core_boxes_design.md: Section 17 追加(88行) - ring0-inventory.md: Phase 112 エントリ追加(16行) - CURRENT_TASK.md: Phase 106-112 完了表更新 - phase112_ring0_registry_design.md: 完全設計書(426行) 【統計】 - 8ファイル修正(+261行, -30行) - 3つの新テスト追加(Ring0Registry関連) - test_ring0_registry_default_profile - test_ring0_registry_nofs_profile - test_default_ring0_uses_registry - cargo build --release: SUCCESS - 全テスト PASS 【設計原則確立】 - Ring0Registry factory pattern で profile-aware 実装選択を一本化 - NoFsApi による自動 disabled により、上位層の特別処理を排除 - initialize_runtime() が唯一の env 読み込み入口として SSOT 確立 - 将来の profile 追加(TestMock/Sandbox/ReadOnly/Embedded等)が容易に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:19:24 +09:00
// Phase 112: Ring0Registry tests
#[test]
fn test_ring0_registry_default_profile() {
let ctx = Ring0Registry::build(RuntimeProfile::Default);
// Verify basic operations work
ctx.log.info("Test message from Default profile");
assert!(ctx.time.now().is_ok());
}
#[test]
fn test_ring0_registry_nofs_profile() {
use std::path::Path;
let ctx = Ring0Registry::build(RuntimeProfile::NoFs);
// Verify NoFsApi returns errors
let result = ctx.fs.read_to_string(Path::new("/tmp/test.txt"));
assert!(result.is_err());
// Verify exists returns false
assert!(!ctx.fs.exists(Path::new("/tmp/test.txt")));
// Other services should still work
ctx.log.info("Test message from NoFs profile");
assert!(ctx.time.now().is_ok());
}
#[test]
fn test_default_ring0_uses_registry() {
let ctx = default_ring0();
// Should behave same as Default profile
ctx.log.info("Test from default_ring0()");
assert!(ctx.time.now().is_ok());
}
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
#[test]
fn test_nofs_api_read_to_string() {
let api = NoFsApi;
let result = api.read_to_string(std::path::Path::new("/tmp/test.txt"));
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("disabled"));
}
#[test]
fn test_nofs_api_read() {
let api = NoFsApi;
assert!(api.read(std::path::Path::new("/tmp/test.txt")).is_err());
}
#[test]
fn test_nofs_api_write_all() {
let api = NoFsApi;
assert!(api
.write_all(std::path::Path::new("/tmp/test.txt"), b"data")
.is_err());
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
}
#[test]
fn test_nofs_api_append_all() {
let api = NoFsApi;
assert!(api
.append_all(std::path::Path::new("/tmp/test.txt"), b"data")
.is_err());
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
}
#[test]
fn test_nofs_api_exists() {
let api = NoFsApi;
assert!(!api.exists(std::path::Path::new("/tmp/test.txt")));
}
#[test]
fn test_nofs_api_metadata() {
let api = NoFsApi;
assert!(api.metadata(std::path::Path::new("/tmp/test.txt")).is_err());
}
#[test]
fn test_nofs_api_canonicalize() {
let api = NoFsApi;
assert!(api
.canonicalize(std::path::Path::new("/tmp/test.txt"))
.is_err());
refactor(phase112): Ring0 Service Registry コード改善 Phase 112 実装後のコード品質向上として4つの改善を実施 【改善1】NoFsApi エラーメッセージの定数化 - NOFS_ERROR_MSG 定数を定義して一元管理 - 5箇所の重複メッセージを1つの定数参照に統一 - タイポリスク低減・保守性向上 【改善2】Ring0Registry の build_with_fs() 抽出 - build_default() と build_no_fs() の重複(14行)を削除 - 新規ヘルパーメソッド build_with_fs(fs: Arc<dyn FsApi>) を追加 - build() メソッドを2行の match 式に簡潔化 - 将来の profile 追加時の拡張性向上 【改善3】NoFsApi テスト追加 - 7つの新規テストを追加(全 FsApi メソッドをカバー) - test_nofs_api_read_to_string - test_nofs_api_read - test_nofs_api_write_all - test_nofs_api_append_all - test_nofs_api_exists - test_nofs_api_metadata - test_nofs_api_canonicalize - テストカバレッジ大幅向上 【改善4】unsafe dealloc ヘルパー化 - unsafe_dealloc(ptr, size) ヘルパー関数を追加 - 3箇所の unsafe dealloc 呼び出しを統一 - コード可読性向上・unsafe 領域最小化 【統計】 - 2ファイル修正(+77行, -40行) - テスト: 19 passed(既存12 + 新規7) - ビルド: SUCCESS 【効果】 - コード重複削減(14行削除) - テストカバレッジ向上(NoFsApi 全メソッドテスト化) - 保守性向上(定数一元管理) - 可読性向上(build() メソッド簡潔化) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 03:18:49 +09:00
}
}