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>
This commit is contained in:
@ -1863,3 +1863,91 @@ impl FileHandleBox {
|
||||
|
||||
**Phase 110 実装完了日**: 2025-12-03
|
||||
**Phase 111 実装完了日**: 2025-12-03(Commit fce7555e)
|
||||
|
||||
## Section 17: Phase 112 - Ring0 Service Registry 統一化
|
||||
|
||||
### 概要
|
||||
|
||||
Ring0Context の初期化を「Ring0Registry::build(profile)」に集約。
|
||||
profile ごとに実装を切り替える factory パターンで、
|
||||
プロファイル対応と将来の拡張を簡素化。
|
||||
|
||||
### 設計
|
||||
|
||||
- **default_ring0()**: Ring0Registry::build(RuntimeProfile::Default) に統一
|
||||
- **NoFsApi**: NoFs profile で FsApi 無効化(Ring0 レベル)
|
||||
- **initialize_runtime()**: env 読み込み → Ring0Registry.build() → init_global_ring0()
|
||||
|
||||
### プロファイル別の Ring0Context
|
||||
|
||||
| Profile | mem | io | time | log | fs | thread |
|
||||
|---------|-----|----|----|-----|----|----|
|
||||
| Default | ✅ StdMem | ✅ StdIo | ✅ StdTime | ✅ StdLog | ✅ StdFs | ✅ StdThread |
|
||||
| NoFs | ✅ StdMem | ✅ StdIo | ✅ StdTime | ✅ StdLog | ❌ NoFsApi | ✅ StdThread |
|
||||
|
||||
### 責務分離 (Phase 112)
|
||||
|
||||
```
|
||||
【Layer】 【責務】 【実装】
|
||||
─────────────────────────────────────────────────────
|
||||
env User configuration NYASH_RUNTIME_PROFILE
|
||||
initialize_runtime env 読み込み + Ring0 初期化 src/runtime/mod.rs
|
||||
Ring0Registry Profile 応じた実装選択 src/runtime/ring0/mod.rs
|
||||
Std* / NoFsApi 具体実装(std::fs など) src/runtime/ring0/std_impls.rs
|
||||
Ring0Context API 統合 Ring0
|
||||
PluginHost/FileBox Ring0 の利用者 runtime/boxes
|
||||
```
|
||||
|
||||
### Ring0.fs が NoFsApi の場合の連鎖効果
|
||||
|
||||
**設計**: Ring0 レベルで NoFsApi を使うと、すべての上位層が自動的に disabled
|
||||
|
||||
```
|
||||
Ring0Registry::build(RuntimeProfile::NoFs)
|
||||
↓
|
||||
Ring0Context { fs: Arc::new(NoFsApi), ... }
|
||||
↓
|
||||
Ring0FsFileIo が内部で ring0.fs.read/write/append を呼ぶ
|
||||
↓
|
||||
→ すべて IoError で失敗する(自動的に disabled)
|
||||
↓
|
||||
FileBox.read() / FileHandleBox.open() も失敗
|
||||
↓
|
||||
→ ユーザー側は「FileBox/FileHandleBox が使えない」と認識
|
||||
```
|
||||
|
||||
**つまり**: Ring0.fs が NoFsApi なら、PluginHost/FileBox/FileHandleBox は何もしなくても自動的に disabled になる!
|
||||
|
||||
### 実装ファイル
|
||||
|
||||
- `src/runtime/ring0/mod.rs`: Ring0Registry struct + build() メソッド
|
||||
- `src/runtime/ring0/std_impls.rs`: NoFsApi struct(FsApi trait 実装)
|
||||
- `src/runtime/mod.rs`: initialize_runtime() のドキュメント更新
|
||||
- `src/runner/mod.rs`: NyashRunner::new() で Ring0Registry 使用
|
||||
|
||||
### 将来の拡張例
|
||||
|
||||
```rust
|
||||
// Phase 113+ で以下のように拡張可能
|
||||
impl Ring0Registry {
|
||||
pub fn build(profile: RuntimeProfile) -> Ring0Context {
|
||||
match profile {
|
||||
RuntimeProfile::Default => Self::build_default(),
|
||||
RuntimeProfile::NoFs => Self::build_no_fs(),
|
||||
RuntimeProfile::TestMock => Self::build_test_mock(), // ← 追加
|
||||
RuntimeProfile::Sandbox => Self::build_sandbox(), // ← 追加
|
||||
RuntimeProfile::ReadOnly => Self::build_readonly(), // ← 追加
|
||||
RuntimeProfile::Embedded => Self::build_embedded(), // ← 追加
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 関連ドキュメント
|
||||
|
||||
- [Phase 112 設計書](phase112_ring0_registry_design.md) - 完全仕様
|
||||
- [Ring0 Inventory](ring0-inventory.md) - Ring0 レイヤー全体設計
|
||||
|
||||
---
|
||||
|
||||
**Phase 112 実装完了日**: 2025-12-03
|
||||
|
||||
@ -589,10 +589,18 @@ Phase 106–108 では FileBox provider_lock / Ring0FsFileIo / write/write_all
|
||||
- 実装: `src/boxes/file/handle_box.rs` (7テスト全PASS)
|
||||
- API: open(path, mode) → read/write → close()
|
||||
- プロファイル対応: Default ✅、NoFs ❌
|
||||
- **Phase 111: Fs metadata 拡張 + append mode**
|
||||
- ✅ **Phase 111: Fs metadata 拡張 + append mode** (COMPLETED - 2025-12-03)
|
||||
- FileHandleBox に append mode ("a") を追加
|
||||
- `exists/metadata/canonicalize` を FileIo / FileBox 側にきちんとエクスポート
|
||||
- Ring0.FsApi の stat 情報を Nyash 側から扱えるようにする
|
||||
- 実装: append_all() + metadata() 完全実装
|
||||
- テスト: 4個の新テスト全PASS
|
||||
- ✅ **Phase 112: Ring0 Service Registry 統一化** (COMPLETED - 2025-12-03)
|
||||
- Ring0Context 初期化を Ring0Registry::build(profile) factory パターンに集約
|
||||
- NoFsApi struct 実装(Ring0 レベルで FsApi を無効化)
|
||||
- Profile 応じた実装選択(Default → StdFs、NoFs → NoFsApi)
|
||||
- default_ring0() を Ring0Registry 経由に統一(互換性維持)
|
||||
- 将来の拡張準備(TestMock/Sandbox/ReadOnly/Embedded プロファイル対応可能)
|
||||
|
||||
さらに長期的には、Ring0 全体を「統一サービスレジストリ」として扱うフェーズ(Mem/Io/Time/Log/Fs/Thread の trait 統合)を
|
||||
Phase 11x 以降で検討する予定だよ。
|
||||
さらに長期的には、Ring0 全体を「統一サービスレジストリ」として扱うフェーズ(Mem/Io/Time/Log/Fs/Thread の trait 統合)を
|
||||
Phase 11x 以降で検討する予定だよ。Phase 112 で factory pattern による拡張基盤が整備された!
|
||||
|
||||
Reference in New Issue
Block a user