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>
This commit is contained in:
nyash-codex
2025-12-03 08:42:45 +09:00
parent 2f54e64d27
commit b3de4cac4b
5 changed files with 189 additions and 40 deletions

View File

@ -467,3 +467,83 @@ pub fn initialize_runtime(ring0: Arc<Ring0Context>) -> Result<PluginHost, CoreIn
- CoreServices の自動構築
- ensure_initialized() の4箇所への配置
---
## 10. Phase 93: with_core_from_registry 実装2025-12-03
### 10.1 実装内容
**実装**: `src/runtime/plugin_host.rs`
```rust
impl PluginHost {
pub fn with_core_from_registry(
ring0: Arc<Ring0Context>,
registry: &UnifiedBoxRegistry,
) -> Result<Self, CoreInitError> {
// Phase 93: 各 core_required Box が registry に存在するか確認
for id in CoreServices::required_ids() {
let box_name = id.name();
if !registry.has_type(box_name) {
return Err(CoreInitError::MissingService {
box_id: *id,
message: format!("{} not found in registry", box_name),
});
}
}
// Phase 93: ダミー Service 実装で CoreServices を構築
let core = 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),
};
Ok(PluginHost {
ring0,
core,
optional: HashMap::new(),
})
}
}
```
### 10.2 段階的展開戦略
**Phase 93 アプローチ**:
- 環境変数 `NYASH_USE_PLUGIN_HOST=1` で有効化
- ダミー Service 実装で動作確認
- selfhost のみ統合hack_check は Phase 94
**Phase 94 計画**:
- 実際の Box → Service 変換実装
- 環境変数削除(デフォルトで有効化)
- 全起動パスへの展開
### 10.3 Fail-Fast 設計
**メリット**:
- 起動時に core Box の不足を即座に検出
- CoreInitError で明示的なエラーメッセージ
- デバッグ容易(ランタイムエラーではなく起動時エラー)
### 10.4 動作確認方法
```bash
# Phase 93 動作確認
NYASH_USE_PLUGIN_HOST=1 ./target/release/nyash apps/tests/selfhost_min.hako
# Phase 93 では環境変数なしで従来通り動作
./target/release/nyash apps/tests/selfhost_min.hako
```
### 10.5 実装されたファイル
1. `src/runtime/plugin_host.rs`: with_core_from_registry() + ダミー Service 実装
2. `src/runtime/core_services.rs`: CoreServices::dummy() ヘルパー
3. `src/runtime/mod.rs`: initialize_runtime() 実装(環境変数制御)
4. `src/runner/selfhost.rs`: PluginHost 初期化追加