feat(phase91): PluginHost/CoreServices skeleton complete
Phase 91 完了: Ring1-Core 構造の明確化 **実装内容**: - CoreServices 定義(6つの Service trait) - StringService, IntegerService, BoolService - ArrayService, MapService, ConsoleService - PluginHost 構造体(Ring0 ⇔ CoreServices 橋渡し) - NyashPlugin trait(プラグインシステム標準IF) - PluginRegistry skeleton **Phase 87 整合性**: - CoreServices は core_required (6個) を完全カバー - String, Integer, Bool, Array, Map, Console - CoreBoxId との対応表をドキュメント化 **設計原則確立**: - Ring1-Core 構造明確化 - core_required は必ず揃う(型レベル保証) - Fail-Fast 設計(ensure_initialized) - 既存影響ゼロ(新規ファイルのみ) **テスト結果**: - 5件追加(全て合格) - ビルド成功 - 既存テストに影響なし **次のステップ**: Phase 92 (UnifiedBoxRegistry との統合) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
67
src/runtime/core_services.rs
Normal file
67
src/runtime/core_services.rs
Normal file
@ -0,0 +1,67 @@
|
||||
//! Phase 91: CoreServices 定義
|
||||
//!
|
||||
//! Ring1-Core: core_required Box の Service trait 群。
|
||||
//! Phase 87 CoreBoxId の core_required (6個) 全てをカバー。
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
/// 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 92 以降で各 Service の初期化を検証
|
||||
pub fn ensure_initialized(&self) {
|
||||
// Phase 91 では trait が空なので何もしない
|
||||
// Phase 92 以降で各 Service の初期化を検証
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,10 @@
|
||||
|
||||
pub mod box_registry;
|
||||
pub mod core_box_ids; // Phase 87: CoreBoxId/CoreMethodId 型安全enum
|
||||
pub mod core_services; // Phase 91: CoreServices trait 定義
|
||||
pub mod deprecations;
|
||||
pub mod gc;
|
||||
pub mod plugin_host; // Phase 91: PluginHost skeleton
|
||||
pub mod ring0; // Phase 88: Ring0Context - OS API 抽象化レイヤー
|
||||
pub mod gc_controller;
|
||||
pub mod gc_mode;
|
||||
|
||||
163
src/runtime/plugin_host.rs
Normal file
163
src/runtime/plugin_host.rs
Normal file
@ -0,0 +1,163 @@
|
||||
//! Phase 91: PluginHost/CoreServices skeleton
|
||||
//!
|
||||
//! Ring1-Core(Box 実装層)の構造定義。
|
||||
//! Phase 92 で UnifiedBoxRegistry と接続予定。
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use std::any::Any;
|
||||
|
||||
/// Plugin の基本情報
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginDescriptor {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub capabilities: Vec<String>, // "json", "http", "cli" など
|
||||
}
|
||||
|
||||
/// Nyash Plugin の trait
|
||||
pub trait NyashPlugin: Send + Sync {
|
||||
fn descriptor(&self) -> PluginDescriptor;
|
||||
fn register(&self, host: &mut PluginRegistry);
|
||||
}
|
||||
|
||||
/// Plugin 登録レジストリ(skeleton のみ、Phase 92 で実装)
|
||||
pub struct PluginRegistry {
|
||||
_placeholder: (),
|
||||
}
|
||||
|
||||
impl PluginRegistry {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
_placeholder: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use super::core_services::CoreServices;
|
||||
use super::ring0::Ring0Context;
|
||||
|
||||
/// PluginHost: Ring0Context と CoreServices の橋渡し
|
||||
pub struct PluginHost {
|
||||
pub ring0: Arc<Ring0Context>,
|
||||
pub core: CoreServices,
|
||||
pub optional: HashMap<String, Arc<dyn Any>>,
|
||||
}
|
||||
|
||||
impl PluginHost {
|
||||
/// Phase 91: skeleton のみ(core は未実装)
|
||||
/// Phase 92 以降で from_registry() を実装予定
|
||||
#[allow(dead_code)]
|
||||
pub fn new_skeleton(ring0: Arc<Ring0Context>) -> Self {
|
||||
// ダミー実装(Phase 92 で削除)
|
||||
unimplemented!("Phase 92 で from_registry() 実装後に削除")
|
||||
}
|
||||
|
||||
/// core_required が全て揃っているか検証
|
||||
pub fn ensure_core_initialized(&self) {
|
||||
self.core.ensure_initialized();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::runtime::core_services::*;
|
||||
|
||||
#[test]
|
||||
fn test_plugin_descriptor() {
|
||||
let desc = PluginDescriptor {
|
||||
name: "test_plugin".to_string(),
|
||||
version: "1.0.0".to_string(),
|
||||
capabilities: vec!["json".to_string()],
|
||||
};
|
||||
assert_eq!(desc.name, "test_plugin");
|
||||
assert_eq!(desc.version, "1.0.0");
|
||||
assert_eq!(desc.capabilities.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plugin_registry_creation() {
|
||||
let _registry = PluginRegistry::new();
|
||||
// panic しないことを確認
|
||||
}
|
||||
|
||||
// ダミー Service 実装
|
||||
struct DummyStringService;
|
||||
impl StringService for DummyStringService {}
|
||||
|
||||
struct DummyIntegerService;
|
||||
impl IntegerService for DummyIntegerService {}
|
||||
|
||||
struct DummyBoolService;
|
||||
impl BoolService for DummyBoolService {}
|
||||
|
||||
struct DummyArrayService;
|
||||
impl ArrayService for DummyArrayService {}
|
||||
|
||||
struct DummyMapService;
|
||||
impl MapService for DummyMapService {}
|
||||
|
||||
struct DummyConsoleService;
|
||||
impl ConsoleService for DummyConsoleService {}
|
||||
|
||||
#[test]
|
||||
fn test_core_services_all_fields() {
|
||||
let services = CoreServices {
|
||||
string: Arc::new(DummyStringService),
|
||||
integer: Arc::new(DummyIntegerService),
|
||||
bool: Arc::new(DummyBoolService),
|
||||
array: Arc::new(DummyArrayService),
|
||||
map: Arc::new(DummyMapService),
|
||||
console: Arc::new(DummyConsoleService),
|
||||
};
|
||||
services.ensure_initialized();
|
||||
// panic しないことを確認(Phase 92 で検証ロジック追加予定)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_core_services_coverage() {
|
||||
// Phase 87 CoreBoxId の core_required (6個) 全てをカバーすることを検証
|
||||
let services = CoreServices {
|
||||
string: Arc::new(DummyStringService),
|
||||
integer: Arc::new(DummyIntegerService),
|
||||
bool: Arc::new(DummyBoolService),
|
||||
array: Arc::new(DummyArrayService),
|
||||
map: Arc::new(DummyMapService),
|
||||
console: Arc::new(DummyConsoleService),
|
||||
};
|
||||
|
||||
// Phase 87 core_required (6個) と一致することを確認
|
||||
// String, Integer, Bool, Array, Map, Console
|
||||
let _string = &services.string;
|
||||
let _integer = &services.integer;
|
||||
let _bool = &services.bool;
|
||||
let _array = &services.array;
|
||||
let _map = &services.map;
|
||||
let _console = &services.console;
|
||||
|
||||
// 全フィールドが存在することを確認
|
||||
}
|
||||
|
||||
struct DummyPlugin;
|
||||
impl NyashPlugin for DummyPlugin {
|
||||
fn descriptor(&self) -> PluginDescriptor {
|
||||
PluginDescriptor {
|
||||
name: "dummy".to_string(),
|
||||
version: "0.1.0".to_string(),
|
||||
capabilities: vec![],
|
||||
}
|
||||
}
|
||||
fn register(&self, _host: &mut PluginRegistry) {
|
||||
// ダミー実装
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plugin_trait_implementation() {
|
||||
let plugin = DummyPlugin;
|
||||
let desc = plugin.descriptor();
|
||||
assert_eq!(desc.name, "dummy");
|
||||
assert_eq!(desc.version, "0.1.0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user