Files
hakorune/src/runtime/core_services.rs

120 lines
3.3 KiB
Rust
Raw Normal View History

//! Phase 91: CoreServices 定義
//!
//! Ring1-Core: core_required Box の Service trait 群。
//! Phase 87 CoreBoxId の core_required (6個) 全てをカバー。
use std::sync::Arc;
use crate::runtime::CoreBoxId;
/// StringBox Service trait
pub trait StringService: Send + Sync {
// Phase 92 以降で実装
}
/// IntegerBox Service trait
pub trait IntegerService: Send + Sync {
// Phase 92 以降で実装
}
/// BoolBox Service trait
pub trait BoolService: Send + Sync {
// Phase 92 以降で実装
}
/// ArrayBox Service trait
pub trait ArrayService: Send + Sync {
// Phase 92 以降で実装
}
/// MapBox Service trait
pub trait MapService: Send + Sync {
// Phase 92 以降で実装
}
/// ConsoleBox Service trait
pub trait ConsoleService: Send + Sync {
// Phase 92 以降で実装
}
/// CoreServices: core_required Box の集合
///
/// Phase 85 設計原則:
/// - core_required は必ず全て揃っていなければならない
/// - 起動時に全フィールドが初期化されていることを保証
///
/// Phase 87 CoreBoxId との対応:
/// - String → string
/// - Integer → integer
/// - Bool → bool
/// - Array → array
/// - Map → map
/// - Console → console
pub struct CoreServices {
pub string: Arc<dyn StringService>,
pub integer: Arc<dyn IntegerService>,
pub bool: Arc<dyn BoolService>,
pub array: Arc<dyn ArrayService>,
pub map: Arc<dyn MapService>,
pub console: Arc<dyn ConsoleService>,
}
impl CoreServices {
/// Phase 87 CoreBoxId の core_required (6個) を返す
///
/// Phase 87 CoreBoxId::is_core_required() と完全一致する。
pub fn required_ids() -> &'static [CoreBoxId] {
&[
CoreBoxId::String,
CoreBoxId::Integer,
CoreBoxId::Bool,
CoreBoxId::Array,
CoreBoxId::Map,
CoreBoxId::Console,
]
}
/// 全フィールドが初期化されているか検証
/// Phase 92 以降で各 Service の初期化を検証
pub fn ensure_initialized(&self) {
// Phase 91 では trait が空なので何もしない
// Phase 92 以降で各 Service の初期化を検証
}
feat(phase93): with_core_from_registry implementation complete Phase 93 完了: UnifiedBoxRegistry 統合実装 & 起動パス統合 **実装内容**: - with_core_from_registry() 実装 - UnifiedBoxRegistry.has_type() で core Box の存在確認 - 不足時は CoreInitError::MissingService を返す - ダミー Service 実装で CoreServices を構築 - ダミー Service 実装を pub に - DummyStringService, DummyIntegerService 等を公開 - Phase 94 の実変換までの橋渡し - CoreServices::dummy() ヘルパー追加 - フォールバック用ダミー実装 - initialize_runtime() 実装(環境変数制御) - NYASH_USE_PLUGIN_HOST=1 で PluginHost 有効化 - 環境変数なしで従来通り動作(後方互換性) - selfhost に PluginHost 初期化追加 - CoreInitError 発生時は fail-fast - 既存ロジックは変更なし **Fail-Fast 設計**: - 起動時に core Box 不足を即座に検出 - CoreInitError で明示的なエラーメッセージ - デバッグ容易(ランタイムエラーではなく起動時エラー) **テスト結果**: - test_with_core_from_registry_missing_box 追加 - 7件全て成功 - ビルド成功(1分4秒) - 526 passed(既存36失敗は Phase 93 と無関係) **動作確認**: - 環境変数なし: 従来通り動作 ✅ - NYASH_USE_PLUGIN_HOST=1: PluginHost 初期化成功 ✅ - selfhost: fail-fast 動作確認済み ✅ **ドキュメント更新**: - Section 10 追加(77行) - 段階的展開戦略、Fail-Fast 設計を文書化 **次のステップ**: Phase 94 (実際の Box → Service 変換) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 08:42:45 +09:00
/// Phase 93: ダミー実装Phase 94 で削除予定)
pub fn dummy() -> Self {
use crate::runtime::plugin_host::*;
Self {
string: Arc::new(DummyStringService),
integer: Arc::new(DummyIntegerService),
bool: Arc::new(DummyBoolService),
array: Arc::new(DummyArrayService),
map: Arc::new(DummyMapService),
console: Arc::new(DummyConsoleService),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_required_ids_consistency() {
let required = CoreServices::required_ids();
assert_eq!(required.len(), 6);
// Phase 87 CoreBoxId::is_core_required() と一致
for id in required {
assert!(id.is_core_required());
}
// 全ての core_required が含まれているか確認
assert!(required.contains(&CoreBoxId::String));
assert!(required.contains(&CoreBoxId::Integer));
assert!(required.contains(&CoreBoxId::Bool));
assert!(required.contains(&CoreBoxId::Array));
assert!(required.contains(&CoreBoxId::Map));
assert!(required.contains(&CoreBoxId::Console));
}
}