import json import engine_rust def test_live_cards_added_to_deck_rust(): """ Regression Test (Rust Engine): Verify that Live Cards passed to initialize_game are actually added to the player's deck in the Rust implementation. """ # 1. Create minimal DB JSON matching Rust struct keys EXACTLY db_json = { "member_db": { "1": { "card_id": 1, "card_no": "M001", "name": "Test Member", "cost": 1, "hearts": [0, 0, 0, 0, 0, 0, 0], "blade_hearts": [0, 0, 0, 0, 0, 0, 0], "blades": 1, "groups": [], "units": [], "abilities": [], "volume_icons": 0, "draw_icons": 0, # Optional fields with default "ability_text": "", "char_id": 0, "img_path": "", } }, "live_db": { "10001": { "card_id": 10001, "card_no": "L001", "name": "Live 1", "score": 1, "required_hearts": [0, 0, 0, 0, 0, 0, 0], "burst_locks": [ 0, 0, 0, 0, 0, 0, 0, ], # Rust might not have this? Checked logic.rs, it does NOT have burst_locks in LiveCard struct. # Wait, wait. Let's re-verify LiveCard struct in logic.rs. # 214: pub struct LiveCard { # ... # 225: #[serde(default)] rare, ability_text, img_path # It accepts: card_id, card_no, name, score, required_hearts, abilities, groups, units, volume_icons, blade_hearts. # "burst_locks" NOT present in logic.rs line 214-230. "abilities": [], "groups": [], "units": [], "volume_icons": 0, "blade_hearts": [0, 0, 0, 0, 0, 0, 0], "rare": "N", "ability_text": "", "img_path": "", } }, "energy_db": { "20001": {"id": 20001, "card_id": 20001} # Energy might just be ID? # Checking EnergyCard in logic.rs? It wasn't in the snippet. # Assuming simple struct or just ID mapping. # Logic.rs: pub const ENERGY_ID_OFFSET = 20000; # CardDatabase struct: members, lives. DOES NOT HAVE energy_db? # Logic.rs: struct CardDatabase { members: HashMap, lives: HashMap } # It does NOT store energy cards explicitly? # But from_json might ignore extra fields? }, } # Rust CardDatabase struct in logic.rs lines 378+ DEFINITELY only has members and lives fields. # But from_json might read energy_db? # Logic.rs: let data: serde_json::Value = serde_json::from_str(json_str)?; # It parses member_db and live_db. # It seems to ignore energy_db. db_str = json.dumps(db_json) db = engine_rust.PyCardDatabase(db_str) game = engine_rust.PyGameState(db) # Official sizes members = [1] * 48 lives = [10001] * 12 energy = [20001] * 12 # Passing explicit lives game.initialize_game( members, # p0 deck members, # p1 deck energy, # p0 energy energy, # p1 energy lives, # p0 lives (Should be added to deck) lives, # p1 lives ) p0 = game.get_player(0) assert p0.deck_count + len(p0.hand) == 60, "Total cards count mismatch" def test_can_draw_live_card_rust(): # Similar fix for second test db_json = { "member_db": { "1": { "card_id": 1, "card_no": "M001", "name": "Test Member", "cost": 1, "hearts": [0] * 7, "blade_hearts": [0] * 7, "blades": 1, "groups": [], "units": [], "abilities": [], "volume_icons": 0, "draw_icons": 0, } }, "live_db": { "10001": { "card_id": 10001, "card_no": "L001", "name": "Live 1", "score": 1, "required_hearts": [0] * 7, "blade_hearts": [0] * 7, "abilities": [], "groups": [], "units": [], "volume_icons": 0, } }, } db = engine_rust.PyCardDatabase(json.dumps(db_json)) game = engine_rust.PyGameState(db) # Official sizes members = [1] * 48 lives = [10001] * 12 energy = [20001] * 12 game.initialize_game(members, members, energy, energy, lives, lives) p0 = game.get_player(0) # Check hand + main deck for the live card # Total cards = 60. assert p0.deck_count + len(p0.hand) == 60, "Total cards count mismatch"