const fs = require('fs'); const path = require('path'); // Mock window and MagicBot const callbacks = {}; global.window = { MagicBot: { state: {}, events: { emit: (event, data) => console.log(`[Event] ${event} emitted`) }, on: (event, callback) => { callbacks[event] = callback; } } }; // Load fullstate.json const fullStatePath = '/home/matiss/Documents/Code/magicbot/fullstate.json'; const fullState = JSON.parse(fs.readFileSync(fullStatePath, 'utf8')); // Load state.js content const stateJsPath = '/home/matiss/Documents/Code/magicbot/extension/modules/state.js'; const stateJsContent = fs.readFileSync(stateJsPath, 'utf8'); // Execute state.js eval(stateJsContent); // Simulate receiving the 'Welcome' packet if (callbacks['packet_received']) { console.log("Simulating packet_received with fullstate.json..."); // The message structure in handleWelcome expects 'msg' to be the object that contains 'fullState' property // Looking at fullstate.json, it has "type": "Welcome", and "fullState": { ... } // So we pass the whole object. callbacks['packet_received'](fullState); } else { console.error("No packet_received listener registered!"); process.exit(1); } // Verify results const state = global.window.MagicBot.state; console.log("--- Verification Results ---"); console.log("PlayerID:", state.playerId); console.log("Garden present:", !!state.garden); console.log("Inventory present:", !!state.inventory); console.log("Shops present:", !!state.shops); if (state.garden && state.inventory && state.shops) { console.log("SUCCESS: All key state properties populated."); } else { console.error("FAILURE: Missing state properties."); process.exit(1); }