mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-04-22 16:49:15 +00:00
WIP: Mostly working version that uses the eventqueue
We've mostly got this working. Events get executed in the array of events. We don't use setTimeout anymore thankfully. I'm not in love with this system, it still isn't straight forward about what events happen where, but I do at least now have an ability to better control the flow.
This commit is contained in:
parent
a929bf5ee6
commit
ef3e3a79fe
11 changed files with 336 additions and 393 deletions
|
|
@ -9,98 +9,120 @@ interface MessageRecord {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets expected messages for current power from the browser's game data
|
||||
* Comprehensive test to verify message system functionality and data quality
|
||||
*/
|
||||
async function getExpectedMessagesFromBrowser(page: Page): Promise<Array<{
|
||||
sender: string;
|
||||
recipient: string;
|
||||
message: string;
|
||||
phase: string;
|
||||
}>> {
|
||||
async function verifyMessageSystemHealth(page: Page): Promise<{
|
||||
hasValidGameData: boolean;
|
||||
messageCount: number;
|
||||
eventQueueActive: boolean;
|
||||
momentsWithNoMessages: number;
|
||||
}> {
|
||||
return await page.evaluate(() => {
|
||||
const gameData = window.gameState?.gameData;
|
||||
const currentPower = window.gameState?.currentPower;
|
||||
const momentsData = window.gameState?.momentsData;
|
||||
|
||||
if (!gameData || !currentPower) return [];
|
||||
|
||||
const relevantMessages: Array<{
|
||||
sender: string;
|
||||
recipient: string;
|
||||
message: string;
|
||||
phase: string;
|
||||
}> = [];
|
||||
if (!gameData || !currentPower) {
|
||||
return {
|
||||
hasValidGameData: false,
|
||||
messageCount: 0,
|
||||
eventQueueActive: false,
|
||||
momentsWithNoMessages: 0
|
||||
};
|
||||
}
|
||||
|
||||
// Count relevant messages
|
||||
let messageCount = 0;
|
||||
gameData.phases.forEach((phase: any) => {
|
||||
if (phase.messages) {
|
||||
phase.messages.forEach((msg: any) => {
|
||||
// Apply same filtering logic as updateChatWindows()
|
||||
if (msg.sender === currentPower ||
|
||||
msg.recipient === currentPower ||
|
||||
msg.recipient === 'GLOBAL') {
|
||||
relevantMessages.push({
|
||||
sender: msg.sender,
|
||||
recipient: msg.recipient,
|
||||
message: msg.message,
|
||||
phase: phase.name
|
||||
});
|
||||
messageCount++;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return relevantMessages;
|
||||
// Check for moments that might have no messages (data quality issue)
|
||||
let momentsWithNoMessages = 0;
|
||||
if (momentsData && Array.isArray(momentsData)) {
|
||||
momentsData.forEach((moment: any) => {
|
||||
if (moment.interest_score >= 8.0 && moment.powers_involved?.length >= 2) {
|
||||
const power1 = moment.powers_involved[0];
|
||||
const power2 = moment.powers_involved[1];
|
||||
|
||||
// Find the phase for this moment
|
||||
const phaseForMoment = gameData.phases.find((p: any) => p.name === moment.phase);
|
||||
if (phaseForMoment && phaseForMoment.messages) {
|
||||
const conversationMessages = phaseForMoment.messages.filter((msg: any) => {
|
||||
const sender = msg.sender?.toUpperCase();
|
||||
const recipient = msg.recipient?.toUpperCase();
|
||||
const p1 = power1?.toUpperCase();
|
||||
const p2 = power2?.toUpperCase();
|
||||
|
||||
return (sender === p1 && recipient === p2) || (sender === p2 && recipient === p1);
|
||||
});
|
||||
|
||||
if (conversationMessages.length === 0) {
|
||||
momentsWithNoMessages++;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
hasValidGameData: true,
|
||||
messageCount,
|
||||
eventQueueActive: window.gameState?.eventQueue?.pendingEvents?.length > 0 || false,
|
||||
momentsWithNoMessages
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
test.describe('Message Flow Verification', () => {
|
||||
test('should verify basic message system functionality', async ({ page }) => {
|
||||
// This test verifies the message system works and doesn't get stuck
|
||||
test('should verify message system health and data quality', async ({ page }) => {
|
||||
// This test verifies the message system works and validates data quality
|
||||
await page.goto('http://localhost:5173');
|
||||
await waitForGameReady(page);
|
||||
|
||||
// Enable instant mode for faster testing
|
||||
await enableInstantMode(page);
|
||||
|
||||
// Verify game state is accessible
|
||||
const gameState = await page.evaluate(() => ({
|
||||
hasGameData: !!window.gameState?.gameData,
|
||||
currentPower: window.gameState?.currentPower,
|
||||
phaseIndex: window.gameState?.phaseIndex,
|
||||
hasEventQueue: !!window.gameState?.eventQueue
|
||||
}));
|
||||
// Get comprehensive health check
|
||||
const healthStatus = await verifyMessageSystemHealth(page);
|
||||
|
||||
expect(gameState.hasGameData).toBe(true);
|
||||
expect(gameState.currentPower).toBeTruthy();
|
||||
expect(gameState.hasEventQueue).toBe(true);
|
||||
expect(healthStatus.hasValidGameData).toBe(true);
|
||||
|
||||
console.log(`Game loaded with current power: ${gameState.currentPower}`);
|
||||
console.log(`Message system health check:`);
|
||||
console.log(`- Total relevant messages: ${healthStatus.messageCount}`);
|
||||
console.log(`- Event queue active: ${healthStatus.eventQueueActive}`);
|
||||
console.log(`- Moments with no messages: ${healthStatus.momentsWithNoMessages}`);
|
||||
|
||||
// Start playback for a short time to verify message system works
|
||||
// Data quality verification: should have no moments without messages
|
||||
// (Our new error-throwing approach prevents these from being processed)
|
||||
if (healthStatus.momentsWithNoMessages > 0) {
|
||||
console.warn(`⚠️ Found ${healthStatus.momentsWithNoMessages} high-interest moments with no messages`);
|
||||
console.warn(`This indicates potential data quality issues that would now throw errors`);
|
||||
}
|
||||
|
||||
// Start playback briefly to verify system works
|
||||
await page.click('#play-btn');
|
||||
|
||||
// Monitor for basic functionality over 10 seconds
|
||||
let messageAnimationDetected = false;
|
||||
// Monitor for basic functionality over 5 seconds
|
||||
let eventQueueActive = false;
|
||||
|
||||
for (let i = 0; i < 100; i++) { // 10 seconds in 100ms intervals
|
||||
for (let i = 0; i < 50; i++) { // 5 seconds in 100ms intervals
|
||||
const status = await page.evaluate(() => ({
|
||||
isAnimating: window.gameState?.messagesPlaying || false,
|
||||
hasEvents: window.gameState?.eventQueue?.pendingEvents?.length > 0 || false,
|
||||
phase: document.querySelector('#phase-display')?.textContent?.replace('Era: ', '') || ''
|
||||
}));
|
||||
|
||||
if (status.isAnimating) {
|
||||
messageAnimationDetected = true;
|
||||
}
|
||||
|
||||
if (status.hasEvents) {
|
||||
eventQueueActive = true;
|
||||
}
|
||||
|
||||
// If we've detected both, we can finish early
|
||||
if (messageAnimationDetected && eventQueueActive) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -110,14 +132,10 @@ test.describe('Message Flow Verification', () => {
|
|||
// Stop playback
|
||||
await page.click('#play-btn');
|
||||
|
||||
// Verify basic functionality was detected
|
||||
console.log(`Message animation detected: ${messageAnimationDetected}`);
|
||||
console.log(`Event queue active: ${eventQueueActive}`);
|
||||
|
||||
// At minimum, the event queue should be active (even if no messages in first phase)
|
||||
// At minimum, the event queue should be active
|
||||
expect(eventQueueActive).toBe(true);
|
||||
|
||||
console.log('✅ Basic message system functionality verified');
|
||||
console.log('✅ Message system health and data quality verified');
|
||||
});
|
||||
|
||||
test('should verify no simultaneous message animations', async ({ page }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue