yang-pcg 0.2.0

个人使用地图生成
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
// 生成结果数据模型测试
// 验证需求: 1.3, 2.5, 14.2

use crate::debug::DebugBundle;
use crate::model::result::*;
use crate::model::room::RoomGraph;

#[test]
fn test_result_metadata_creation() {
    // 测试结果元数据创建
    let metadata = ResultMetadata {
        seed: 12345,
        config_digest: "abc123def456".to_string(),
        schema_version: "1.0.0".to_string(),
        algorithm_version: "0.1.0".to_string(),
        target_engine_version: Some("UE5.5".to_string()),
        trace_id: Some("trace-001".to_string()),
    };

    assert_eq!(metadata.seed, 12345);
    assert_eq!(metadata.config_digest, "abc123def456");
    assert_eq!(metadata.schema_version, "1.0.0");
    assert_eq!(metadata.algorithm_version, "0.1.0");
    assert_eq!(metadata.target_engine_version, Some("UE5.5".to_string()));
    assert_eq!(metadata.trace_id, Some("trace-001".to_string()));
}

#[test]
fn test_generation_result_creation() {
    // 测试生成结果创建
    let result = GenerationResult {
        metadata: ResultMetadata {
            seed: 99999,
            config_digest: "digest123".to_string(),
            schema_version: "1.0.0".to_string(),
            algorithm_version: "0.1.0".to_string(),
            target_engine_version: None,
            trace_id: None,
        },
        topology: RoomGraph {
            nodes: vec![],
            edges: vec![],
            critical_path: vec![],
            branches: vec![],
        },
        rooms: vec![],
        door_anchors: vec![],
        corridors: vec![],
        terrains: vec![],
        item_spawns: vec![],
        enemy_spawns: vec![],
        chunks: vec![],
        debug: None,
    };

    assert_eq!(result.metadata.seed, 99999);
    assert!(result.rooms.is_empty());
    assert!(result.corridors.is_empty());
    assert!(result.debug.is_none());
}

#[test]
fn test_generation_result_with_debug() {
    // 测试带调试信息的生成结果
    let result = GenerationResult {
        metadata: ResultMetadata {
            seed: 54321,
            config_digest: "test_digest".to_string(),
            schema_version: "1.0.0".to_string(),
            algorithm_version: "0.1.0".to_string(),
            target_engine_version: Some("UE5.6".to_string()),
            trace_id: Some("debug-trace".to_string()),
        },
        topology: RoomGraph {
            nodes: vec![],
            edges: vec![],
            critical_path: vec![],
            branches: vec![],
        },
        rooms: vec![],
        door_anchors: vec![],
        corridors: vec![],
        terrains: vec![],
        item_spawns: vec![],
        enemy_spawns: vec![],
        chunks: vec![],
        debug: Some(DebugBundle::default()),
    };

    assert!(result.debug.is_some());
    assert_eq!(result.metadata.trace_id, Some("debug-trace".to_string()));
}

#[test]
fn test_result_metadata_minimal() {
    // 测试最小结果元数据
    let metadata = ResultMetadata {
        seed: 1,
        config_digest: "minimal".to_string(),
        schema_version: "1.0.0".to_string(),
        algorithm_version: "0.1.0".to_string(),
        target_engine_version: None,
        trace_id: None,
    };

    assert!(metadata.target_engine_version.is_none());
    assert!(metadata.trace_id.is_none());
}

#[test]
fn test_generation_result_json_roundtrip() {
    let result = GenerationResult {
        metadata: ResultMetadata {
            seed: 11,
            config_digest: "digest".to_string(),
            schema_version: "1.0.0".to_string(),
            algorithm_version: "0.1.0".to_string(),
            target_engine_version: None,
            trace_id: Some("trace".to_string()),
        },
        topology: RoomGraph {
            nodes: vec![],
            edges: vec![],
            critical_path: vec![],
            branches: vec![],
        },
        rooms: vec![],
        door_anchors: vec![],
        corridors: vec![],
        terrains: vec![],
        item_spawns: vec![],
        enemy_spawns: vec![],
        chunks: vec![],
        debug: Some(DebugBundle::default()),
    };

    let json = serde_json::to_string(&result).expect("结果应可序列化为 JSON");
    let restored: GenerationResult = serde_json::from_str(&json).expect("结果应可从 JSON 反序列化");

    assert_eq!(restored.metadata.seed, 11);
    assert_eq!(restored.metadata.trace_id.as_deref(), Some("trace"));
}

/// 验证需求: 14.1 - GenerationResult 及所有子结构可完整序列化/反序列化
/// 使用包含所有子结构的完整数据进行 JSON 往返测试
#[test]
fn test_generation_result_full_json_roundtrip() {
    use crate::debug::{DebugChannels, RejectionReason, SpawnDebugInfo, StageStat};
    use crate::model::chunk::{Chunk, StreamingMetadata};
    use crate::model::geometry::{
        CardinalDir, GridPoint, GridSize, RoomBounds, Transform3, WorldPoint,
    };
    use crate::model::room::{
        Branch, BranchPurpose, Corridor, CorridorPath, DoorAnchor, Room, RoomEdge, RoomType,
    };
    use crate::model::spawn::{SpawnKind, SpawnMetadata, SpawnPoint};
    use crate::model::terrain::{
        ConnectivitySummary, Grid2D, ReservedZone, ReservedZoneBounds, Terrain, TileKind,
    };
    use crate::validation::{ValidationItem, ValidationReport};

    // 构建包含所有子结构的完整 GenerationResult
    let rooms = vec![
        Room {
            id: "room-0".to_string(),
            room_type: RoomType::Start,
            depth_from_start: 0,
            branch_id: None,
            difficulty: 0,
            theme_tags: vec!["dungeon".to_string()],
            bounds: Some(RoomBounds {
                min: GridPoint { x: 0, y: 0 },
                max: GridPoint { x: 10, y: 10 },
            }),
            template_ref: None,
            grammar_token: None,
        },
        Room {
            id: "room-1".to_string(),
            room_type: RoomType::Boss,
            depth_from_start: 3,
            branch_id: Some("branch-0".to_string()),
            difficulty: 5,
            theme_tags: vec!["fire".to_string(), "boss".to_string()],
            bounds: Some(RoomBounds {
                min: GridPoint { x: 20, y: 0 },
                max: GridPoint { x: 35, y: 15 },
            }),
            template_ref: Some("boss_arena_01".to_string()),
            grammar_token: None,
        },
    ];

    let topology = RoomGraph {
        nodes: rooms.clone(),
        edges: vec![RoomEdge {
            id: "edge-0".to_string(),
            from_room: "room-0".to_string(),
            to_room: "room-1".to_string(),
            is_critical: true,
        }],
        critical_path: vec!["room-0".to_string(), "room-1".to_string()],
        branches: vec![Branch {
            id: "branch-0".to_string(),
            start_room: "room-0".to_string(),
            end_room: "room-1".to_string(),
            room_ids: vec!["room-1".to_string()],
            purpose: BranchPurpose::Reward,
        }],
    };

    let door_anchors = vec![DoorAnchor {
        id: "door-0".to_string(),
        room_id: "room-0".to_string(),
        edge_id: "edge-0".to_string(),
        grid_pos: GridPoint { x: 10, y: 5 },
        facing: CardinalDir::East,
        width_tiles: 2,
        socket_tag: None,
    }];

    let corridors = vec![Corridor {
        id: "corridor-0".to_string(),
        from_room: "room-0".to_string(),
        to_room: "room-1".to_string(),
        from_anchor: "door-0".to_string(),
        to_anchor: "door-1".to_string(),
        width_tiles: 2,
        path: CorridorPath::Orthogonal(vec![
            GridPoint { x: 10, y: 5 },
            GridPoint { x: 15, y: 5 },
            GridPoint { x: 15, y: 3 },
            GridPoint { x: 20, y: 3 },
        ]),
        segment_tags: Vec::new(),
    }];

    // 构建包含 Grid2D 的地形数据
    let terrain_tiles = Grid2D::new(5, 3, TileKind::Floor).expect("有效尺寸应创建成功");
    let terrains = vec![Terrain {
        room_id: "room-0".to_string(),
        grid_size: GridSize {
            width: 5,
            height: 3,
        },
        tiles: terrain_tiles,
        reserved_zones: vec![
            ReservedZone {
                id: "zone-0".to_string(),
                zone_type: "boss_center".to_string(),
                bounds: ReservedZoneBounds::Rect {
                    min: GridPoint { x: 1, y: 1 },
                    max: GridPoint { x: 4, y: 2 },
                },
                allow_items: false,
                allow_enemies: true,
            },
            ReservedZone {
                id: "zone-1".to_string(),
                zone_type: "entrance".to_string(),
                bounds: ReservedZoneBounds::Circle {
                    center: GridPoint { x: 2, y: 2 },
                    radius: 3,
                },
                allow_items: true,
                allow_enemies: false,
            },
            ReservedZone {
                id: "zone-2".to_string(),
                zone_type: "treasure_spot".to_string(),
                bounds: ReservedZoneBounds::Polygon {
                    points: vec![
                        GridPoint { x: 0, y: 0 },
                        GridPoint { x: 3, y: 0 },
                        GridPoint { x: 3, y: 3 },
                    ],
                },
                allow_items: true,
                allow_enemies: false,
            },
        ],
        connectivity_summary: ConnectivitySummary {
            all_doors_connected: true,
            walkable_tile_count: 12,
            total_tile_count: 15,
            connected_region_count: 1,
        },
    }];

    let item_spawns = vec![SpawnPoint {
        id: "item-0".to_string(),
        room_id: "room-0".to_string(),
        kind: SpawnKind::Item,
        grid_pos: GridPoint { x: 3, y: 3 },
        world_transform: Some(Transform3 {
            position: WorldPoint {
                x: 300.0,
                y: 300.0,
                z: 0.0,
            },
            rotation: (0.0, 90.0, 0.0),
            scale: (1.0, 1.0, 1.0),
        }),
        metadata: SpawnMetadata {
            spawn_tag: "chest_gold".to_string(),
            rarity_tier: Some(2),
            enemy_pool_tag: None,
            encounter_id: None,
            wave_id: None,
            difficulty: Some(3),
            seed: 42,
        },
    }];

    let enemy_spawns = vec![SpawnPoint {
        id: "enemy-0".to_string(),
        room_id: "room-1".to_string(),
        kind: SpawnKind::Boss,
        grid_pos: GridPoint { x: 7, y: 7 },
        world_transform: None,
        metadata: SpawnMetadata {
            spawn_tag: "boss_dragon".to_string(),
            rarity_tier: None,
            enemy_pool_tag: Some("elite_pool".to_string()),
            encounter_id: Some("enc-001".to_string()),
            wave_id: Some("wave-1".to_string()),
            difficulty: Some(10),
            seed: 99,
        },
    }];

    let chunks = vec![Chunk {
        id: "chunk-0".to_string(),
        bounds: RoomBounds {
            min: GridPoint { x: 0, y: 0 },
            max: GridPoint { x: 32, y: 32 },
        },
        room_ids: vec!["room-0".to_string(), "room-1".to_string()],
        dependencies: vec!["chunk-1".to_string()],
        streaming_metadata: StreamingMetadata {
            data_layer: Some("DL_Dungeon_01".to_string()),
            external_data_layer: Some("EDL_Dungeon_01".to_string()),
            hlod_layer: Some("HLOD_0".to_string()),
            streaming_priority: Some(100),
        },
    }];

    // 构建完整的 DebugBundle
    let debug = DebugBundle {
        trace_id: Some("trace-full-test".to_string()),
        stage_stats: vec![
            StageStat {
                stage_name: "topology".to_string(),
                duration_ms: 5,
                iterations: 1,
                produced_count: 2,
            },
            StageStat {
                stage_name: "layout".to_string(),
                duration_ms: 12,
                iterations: 3,
                produced_count: 2,
            },
        ],
        notes: vec!["测试备注".to_string()],
        validation_report: Some(ValidationReport {
            reachability: ValidationItem::passed("reachability"),
            no_overlap: ValidationItem::passed("no_overlap"),
            terrain_connectivity: ValidationItem::passed("terrain_connectivity"),
            spawn_spacing: ValidationItem::failed("spawn_spacing", "间距不足"),
            all_passed: false,
            passed_count: 3,
            failed_count: 1,
        }),
        debug_channels: Some(DebugChannels {
            critical_path_nodes: vec!["room-0".to_string(), "room-1".to_string()],
            door_anchor_positions: vec![GridPoint { x: 10, y: 5 }],
            corridor_centerlines: vec![vec![GridPoint { x: 10, y: 5 }, GridPoint { x: 20, y: 5 }]],
            rejected_rooms: vec!["room-rejected".to_string()],
            spawn_debug: Some(SpawnDebugInfo {
                candidate_count: 20,
                rejected_count: 5,
                rejection_reasons: vec![RejectionReason {
                    position: GridPoint { x: 1, y: 1 },
                    reason: "间距不足".to_string(),
                }],
                accepted_count: 15,
            }),
        }),
    };

    let result = GenerationResult {
        metadata: ResultMetadata {
            seed: 42,
            config_digest: "full-test-digest-abc123".to_string(),
            schema_version: "1.0.0".to_string(),
            algorithm_version: "0.2.0".to_string(),
            target_engine_version: Some("UE5.5".to_string()),
            trace_id: Some("trace-full-test".to_string()),
        },
        topology,
        rooms,
        door_anchors,
        corridors,
        terrains,
        item_spawns,
        enemy_spawns,
        chunks,
        debug: Some(debug),
    };

    // 序列化为 JSON
    let json =
        serde_json::to_string_pretty(&result).expect("完整 GenerationResult 应可序列化为 JSON");

    // 验证 JSON 包含关键字段
    assert!(json.contains("room-0"));
    assert!(json.contains("room-1"));
    assert!(json.contains("boss_arena_01"));
    assert!(json.contains("Orthogonal"));
    assert!(json.contains("boss_center"));
    assert!(json.contains("chest_gold"));
    assert!(json.contains("chunk-0"));
    assert!(json.contains("DL_Dungeon_01"));
    assert!(json.contains("trace-full-test"));
    assert!(json.contains("topology"));
    assert!(json.contains("terrain_connectivity"));

    // 反序列化回 GenerationResult
    let restored: GenerationResult =
        serde_json::from_str(&json).expect("完整 JSON 应可反序列化为 GenerationResult");

    // 验证元数据
    assert_eq!(restored.metadata.seed, 42);
    assert_eq!(restored.metadata.config_digest, "full-test-digest-abc123");
    assert_eq!(restored.metadata.schema_version, "1.0.0");
    assert_eq!(restored.metadata.algorithm_version, "0.2.0");
    assert_eq!(
        restored.metadata.target_engine_version.as_deref(),
        Some("UE5.5")
    );

    // 验证拓扑
    assert_eq!(restored.topology.nodes.len(), 2);
    assert_eq!(restored.topology.edges.len(), 1);
    assert_eq!(restored.topology.critical_path.len(), 2);
    assert_eq!(restored.topology.branches.len(), 1);
    assert_eq!(restored.topology.branches[0].purpose, BranchPurpose::Reward);

    // 验证房间
    assert_eq!(restored.rooms.len(), 2);
    assert_eq!(restored.rooms[0].room_type, RoomType::Start);
    assert_eq!(restored.rooms[1].room_type, RoomType::Boss);
    assert_eq!(
        restored.rooms[1].template_ref.as_deref(),
        Some("boss_arena_01")
    );

    // 验证门锚点
    assert_eq!(restored.door_anchors.len(), 1);
    assert_eq!(restored.door_anchors[0].facing, CardinalDir::East);
    assert_eq!(restored.door_anchors[0].width_tiles, 2);

    // 验证走廊(含 CorridorPath 枚举)
    assert_eq!(restored.corridors.len(), 1);
    match &restored.corridors[0].path {
        CorridorPath::Orthogonal(points) => assert_eq!(points.len(), 4),
        _ => panic!("走廊路径类型应为 Orthogonal"),
    }

    // 验证地形(含 Grid2D 自定义容器)
    assert_eq!(restored.terrains.len(), 1);
    assert_eq!(restored.terrains[0].tiles.width, 5);
    assert_eq!(restored.terrains[0].tiles.height, 3);
    assert_eq!(restored.terrains[0].tiles.data.len(), 15);
    assert_eq!(restored.terrains[0].tiles.get(0, 0), Some(&TileKind::Floor));

    // 验证保留区(含 ReservedZoneBounds 枚举的三种变体)
    assert_eq!(restored.terrains[0].reserved_zones.len(), 3);
    match &restored.terrains[0].reserved_zones[0].bounds {
        ReservedZoneBounds::Rect { min, max } => {
            assert_eq!(min.x, 1);
            assert_eq!(max.x, 4);
        }
        _ => panic!("第一个保留区应为 Rect 类型"),
    }
    match &restored.terrains[0].reserved_zones[1].bounds {
        ReservedZoneBounds::Circle { center, radius } => {
            assert_eq!(center.x, 2);
            assert_eq!(*radius, 3);
        }
        _ => panic!("第二个保留区应为 Circle 类型"),
    }
    match &restored.terrains[0].reserved_zones[2].bounds {
        ReservedZoneBounds::Polygon { points } => {
            assert_eq!(points.len(), 3);
        }
        _ => panic!("第三个保留区应为 Polygon 类型"),
    }

    // 验证连通性摘要
    assert!(
        restored.terrains[0]
            .connectivity_summary
            .all_doors_connected
    );
    assert_eq!(
        restored.terrains[0]
            .connectivity_summary
            .walkable_tile_count,
        12
    );

    // 验证交互物点位(含 Transform3)
    assert_eq!(restored.item_spawns.len(), 1);
    assert_eq!(restored.item_spawns[0].kind, SpawnKind::Item);
    assert!(restored.item_spawns[0].world_transform.is_some());
    let transform = restored.item_spawns[0].world_transform.as_ref().unwrap();
    assert_eq!(transform.position.x, 300.0);
    assert_eq!(transform.rotation.1, 90.0);

    // 验证敌人点位
    assert_eq!(restored.enemy_spawns.len(), 1);
    assert_eq!(restored.enemy_spawns[0].kind, SpawnKind::Boss);
    assert_eq!(
        restored.enemy_spawns[0].metadata.enemy_pool_tag.as_deref(),
        Some("elite_pool")
    );

    // 验证分块(含 StreamingMetadata)
    assert_eq!(restored.chunks.len(), 1);
    assert_eq!(restored.chunks[0].id, "chunk-0");
    assert_eq!(restored.chunks[0].room_ids.len(), 2);
    assert_eq!(
        restored.chunks[0].streaming_metadata.data_layer.as_deref(),
        Some("DL_Dungeon_01")
    );
    assert_eq!(
        restored.chunks[0].streaming_metadata.streaming_priority,
        Some(100)
    );

    // 验证调试信息(含 ValidationReport 和 DebugChannels)
    let debug = restored.debug.as_ref().expect("调试信息应存在");
    assert_eq!(debug.trace_id.as_deref(), Some("trace-full-test"));
    assert_eq!(debug.stage_stats.len(), 2);
    assert_eq!(debug.stage_stats[0].stage_name, "topology");
    assert_eq!(debug.stage_stats[0].duration_ms, 5);
    assert_eq!(debug.notes, vec!["测试备注"]);

    // 验证 ValidationReport
    let report = debug.validation_report.as_ref().expect("验证报告应存在");
    assert!(report.reachability.passed);
    assert!(!report.spawn_spacing.passed);
    assert_eq!(
        report.spawn_spacing.error_message.as_deref(),
        Some("间距不足")
    );
    assert!(!report.all_passed);
    assert_eq!(report.passed_count, 3);
    assert_eq!(report.failed_count, 1);

    // 验证 DebugChannels
    let channels = debug.debug_channels.as_ref().expect("调试通道应存在");
    assert_eq!(channels.critical_path_nodes.len(), 2);
    assert_eq!(channels.door_anchor_positions.len(), 1);
    assert_eq!(channels.corridor_centerlines.len(), 1);
    assert_eq!(channels.rejected_rooms, vec!["room-rejected"]);

    // 验证 SpawnDebugInfo
    let spawn_debug = channels.spawn_debug.as_ref().expect("点位调试信息应存在");
    assert_eq!(spawn_debug.candidate_count, 20);
    assert_eq!(spawn_debug.rejected_count, 5);
    assert_eq!(spawn_debug.rejection_reasons.len(), 1);
    assert_eq!(spawn_debug.accepted_count, 15);
}

/// 验证 `room_by_id` 按 ID 正确查找房间
#[test]
fn test_room_by_id() {
    use crate::model::geometry::{GridPoint, RoomBounds};
    use crate::model::room::{Room, RoomType};

    let room_start = Room {
        id: "room-start".to_string(),
        room_type: RoomType::Start,
        depth_from_start: 0,
        branch_id: None,
        difficulty: 0,
        theme_tags: vec!["dungeon".to_string()],
        bounds: Some(RoomBounds {
            min: GridPoint { x: 0, y: 0 },
            max: GridPoint { x: 10, y: 10 },
        }),
        template_ref: None,
        grammar_token: None,
    };
    let room_boss = Room {
        id: "room-boss".to_string(),
        room_type: RoomType::Boss,
        depth_from_start: 5,
        branch_id: None,
        difficulty: 10,
        theme_tags: vec!["fire".to_string()],
        bounds: Some(RoomBounds {
            min: GridPoint { x: 30, y: 0 },
            max: GridPoint { x: 45, y: 15 },
        }),
        template_ref: None,
        grammar_token: None,
    };

    let result = GenerationResult {
        metadata: ResultMetadata {
            seed: 777,
            config_digest: "test-digest".to_string(),
            schema_version: "1.0.0".to_string(),
            algorithm_version: "0.1.0".to_string(),
            target_engine_version: None,
            trace_id: None,
        },
        topology: RoomGraph {
            nodes: vec![],
            edges: vec![],
            critical_path: vec![],
            branches: vec![],
        },
        rooms: vec![room_start.clone(), room_boss.clone()],
        door_anchors: vec![],
        corridors: vec![],
        terrains: vec![],
        item_spawns: vec![],
        enemy_spawns: vec![],
        chunks: vec![],
        debug: None,
    };

    // 正常查找
    let found = result.room_by_id("room-boss").expect("应找到 room-boss");
    assert_eq!(found.room_type, RoomType::Boss);
    assert_eq!(found.depth_from_start, 5);
    assert!(found.bounds.is_some(), "room_by_id 返回的房间应有 bounds");

    // 查找第一个房间
    let found_start = result.room_by_id("room-start").expect("应找到 room-start");
    assert_eq!(found_start.room_type, RoomType::Start);

    // 不存在的 ID
    assert!(result.room_by_id("nonexistent").is_none());
}