feat(phase109): RuntimeProfile設計で FileBox を条件付き optional に

Phase 109 完全実装完了:
- RuntimeProfile enum (Default, NoFs) で profile 制御
- CoreBoxId.is_required_in(profile) で条件付き required/optional
- initialize_runtime() で env 読み込み責務を一元化(修正1)
- NoFsFileIo スタブで no-fs プロファイルでの FileBox 無効化(修正2)
- Logger/ConsoleService は no-fs でも有効と明示(修正2)
- Profile 拡張予定(TestMock/Sandbox/ReadOnly/Embedded)を予約(修正3)

実装ファイル:
- src/runtime/runtime_profile.rs (新規)
- src/providers/ring1/file/nofs_fileio.rs (新規)
- src/runtime/core_box_ids.rs (修正)
- src/runtime/plugin_host.rs (修正)
- src/runtime/provider_lock.rs (修正)
- docs 更新

テスト: Phase 109 11/11 PASS 
ビルド: cargo build --release SUCCESS 

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-03 19:37:32 +09:00
parent 2eda4bc86b
commit 4ef3e7f56c
12 changed files with 634 additions and 53 deletions

View File

@ -9,6 +9,7 @@ pub mod deprecations;
pub mod gc;
pub mod plugin_host; // Phase 91: PluginHost skeleton
pub mod ring0; // Phase 88: Ring0Context - OS API 抽象化レイヤー
pub mod runtime_profile; // Phase 109: RuntimeProfile enum (Default/NoFs)
pub mod gc_controller;
pub mod gc_mode;
pub mod gc_trace;
@ -42,6 +43,7 @@ pub use box_registry::{get_global_registry, BoxFactoryRegistry, BoxProvider};
pub use core_box_ids::{CoreBoxCategory, CoreBoxId, CoreMethodId}; // Phase 87: 型安全enum
pub use plugin_config::PluginConfig;
pub use ring0::{get_global_ring0, init_global_ring0, Ring0Context}; // Phase 88: Ring0 公開 API
pub use runtime_profile::RuntimeProfile; // Phase 109: RuntimeProfile enum
pub use plugin_host::CoreInitError; // Phase 92: CoreServices 初期化エラー
pub use plugin_loader_unified::{
get_global_plugin_host, init_global_plugin_host, MethodHandle, PluginBoxType, PluginHost,
@ -98,21 +100,55 @@ macro_rules! console_println {
};
}
/// Runtime 初期化Phase 95: global accessor 実装完了
/// Runtime 初期化Phase 95/109: profile-aware initialization
///
/// Phase 94: フォールバック削除 - 常に実際の Box を使用
/// Phase 95: global に登録して get_core_plugin_host() でアクセス可能に
/// Phase 109: RuntimeProfile に基づく条件付き初期化
///
/// # Responsibility Separation (Phase 109 Modification 1)
///
/// - **initialize_runtime**: 環境変数から profile を読む(唯一の env reader
/// - **PluginHost**: profile を引数として受け取るenv に依存しない)
///
/// # Profile behavior
///
/// - **Default**: FileBox provider 必須Fail-Fast、全 core services 有効
/// - **NoFs**: FileBox provider optionaldisabled stub、core services のみ有効
pub fn initialize_runtime(ring0: std::sync::Arc<Ring0Context>) -> Result<(), CoreInitError> {
use crate::box_factory::UnifiedBoxRegistry;
use crate::box_factory::builtin::BuiltinBoxFactory;
// Phase 109: Read RuntimeProfile from environment (this layer only)
let profile = RuntimeProfile::from_env();
let mut registry = UnifiedBoxRegistry::with_env_policy();
// Phase 94: BuiltinBoxFactory を登録して core_required Boxes を提供
registry.register(std::sync::Arc::new(BuiltinBoxFactory::new()));
// Phase 94: 常に実際の Box → Service 変換を使用Fail-Fast原則
let plugin_host = plugin_host::PluginHost::with_core_from_registry(ring0, &registry)?;
// Phase 109: Profile-aware FileBox provider initialization
// Note: This is done BEFORE PluginHost initialization to allow plugin override
match profile {
RuntimeProfile::Default => {
// Default profile: FileBox provider will be auto-registered in PluginHost
// (no action needed here, kept for documentation)
}
RuntimeProfile::NoFs => {
// NoFs profile: Register NoFsFileIo stub
use crate::runtime::provider_lock;
let _ = provider_lock::init_filebox_provider_for_profile(&ring0, &profile);
// Ignore error - PluginHost will handle missing provider gracefully
}
}
// Phase 109: Pass profile to PluginHost (env-independent)
let plugin_host = plugin_host::PluginHost::with_core_from_registry_optional(
ring0,
&registry,
plugin_host::CoreServicesConfig::all_enabled(),
&profile,
)?;
plugin_host.ensure_core_initialized();
// Phase 95: global に登録