test: Add comprehensive E2E tests for unified registry system

- Add reserved name guard test to prevent non-builtin factories from hijacking builtin names
- Add Handle TLV encoding/decoding test for FileBox copyFrom method
- Add CounterBox plugin tests for inc/get operations and clone/share behavior
- All unified registry E2E tests passing 

統一レジストリシステムの包括的なE2Eテスト追加
- ビルトイン名保護テスト
- Handle型TLVエンコーディングテスト
- CounterBoxプラグインテスト
- 全テスト成功確認

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-21 16:46:07 +09:00
parent 6551a2935f
commit d6529b477b
10 changed files with 476 additions and 23 deletions

View File

@ -234,17 +234,21 @@ impl NyashInterpreter {
/// 新しいインタープリターを作成
pub fn new() -> Self {
let shared = SharedState::new();
// ランタイムを構築し、ユーザー定義Boxファクトリを注入グローバル登録を避ける
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
let runtime = NyashRuntimeBuilder::new().with_factory(udf).build();
// Step 5: SharedState分解の第一歩として、
// box_declarationsの保管先をRuntimeに寄せる
// 先にランタイムを構築UDFは後から同一SharedStateで注入)
let runtime = NyashRuntimeBuilder::new().build();
// Runtimeのbox_declarationsを共有状態に差し替え、同一の参照を保つ
let mut shared = shared; // 可変化
shared.box_declarations = runtime.box_declarations.clone();
// ユーザー定義Boxファクトリを、差し替え済みSharedStateで登録
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
if let Ok(mut reg) = runtime.box_registry.lock() {
reg.register(udf);
}
Self {
shared,
local_vars: HashMap::new(),
@ -262,16 +266,22 @@ impl NyashInterpreter {
pub fn new_with_groups(groups: crate::box_factory::builtin::BuiltinGroups) -> Self {
let shared = SharedState::new();
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
// 先にランタイム(組み込みグループのみ)を構築
let runtime = NyashRuntimeBuilder::new()
.with_builtin_groups(groups)
.with_factory(udf)
.build();
// Runtimeのbox_declarationsを共有状態に差し替え
let mut shared = shared; // 可変化
shared.box_declarations = runtime.box_declarations.clone();
// 差し替え済みSharedStateでUDFを登録
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
if let Ok(mut reg) = runtime.box_registry.lock() {
reg.register(udf);
}
Self {
shared,
local_vars: HashMap::new(),
@ -287,15 +297,20 @@ impl NyashInterpreter {
/// 共有状態から新しいインタープリターを作成(非同期実行用)
pub fn with_shared(shared: SharedState) -> Self {
// 共有状態に紐づいたランタイムを構築
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
let runtime = NyashRuntimeBuilder::new().with_factory(udf).build();
// 共有状態に紐づいたランタイムを先に構築
let runtime = NyashRuntimeBuilder::new().build();
// Step 5: Runtimeのbox_declarationsに寄せ替え
// Runtimeのbox_declarationsに寄せ替え
let mut shared = shared; // 可変化
shared.box_declarations = runtime.box_declarations.clone();
// 差し替え済みSharedStateでUDFを登録
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
if let Ok(mut reg) = runtime.box_registry.lock() {
reg.register(udf);
}
Self {
shared,
local_vars: HashMap::new(),
@ -311,16 +326,21 @@ impl NyashInterpreter {
/// 共有状態+グループ構成を指定して新しいインタープリターを作成(非同期実行用)
pub fn with_shared_and_groups(shared: SharedState, groups: crate::box_factory::builtin::BuiltinGroups) -> Self {
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
// 先にランタイム(組み込みグループのみ)を構築
let runtime = NyashRuntimeBuilder::new()
.with_builtin_groups(groups)
.with_factory(udf)
.build();
let mut shared = shared; // 可変化
shared.box_declarations = runtime.box_declarations.clone();
// 差し替え済みSharedStateでUDFを登録
use crate::box_factory::user_defined::UserDefinedBoxFactory;
let udf = Arc::new(UserDefinedBoxFactory::new(shared.clone()));
if let Ok(mut reg) = runtime.box_registry.lock() {
reg.register(udf);
}
Self {
shared,
local_vars: HashMap::new(),