Decouple gameplay input from rendering and wait for world synchronization

This commit is contained in:
dingo
2026-09-09 06:48:04 -04:00
parent c52bdea026
commit 8f999c837e
5 changed files with 71 additions and 15 deletions
+36 -6
View File
@@ -5,20 +5,24 @@ async function enter(page, name = 'Wayfarer') {
await expect(page.locator('#connection-status')).toHaveText('World online');
await page.getByLabel('Character name').fill(name);
await page.getByRole('button', { name: 'Enter world' }).click();
await expect(page.locator('#connection-status')).toHaveText('Connected');
await expect(page.locator('#game-controls')).toBeVisible();
await expectWorldReady(page);
}
async function expectWorldReady(page, characterId?: string) {
// Software-rendered CI can take longer than the default 5s to process the
// initial snapshot. test.slow() extends the test, not this assertion's budget.
// Keep the nine-chunk requirement and include both sides in failure output.
await expect.poll(() => page.evaluate(() => {
await expect.poll(() => page.evaluate(expectedId => {
const game = (window as any).__aeternalis;
return {
connection: document.getElementById('connection-status')?.textContent,
subscribedChunks: game?.snapshot?.chunkKeys.length ?? 0,
renderedChunks: game?.diagnostics().chunks ?? 0,
characterMatches: expectedId ? game?.snapshot?.self.entity.id === expectedId : !!game?.snapshot?.self.entity.id,
};
}), { timeout: 20000, message: 'Initial server subscription and rendered terrain must contain all nine chunks' })
.toEqual({ connection: 'Connected', subscribedChunks: 9, renderedChunks: 9 });
}, characterId), { timeout: 20000, message: 'World readiness requires the expected character and all nine subscribed/rendered chunks' })
.toEqual({ connection: 'Connected', subscribedChunks: 9, renderedChunks: 9, characterMatches: true });
}
test('desktop renders models, moves authoritatively, gathers, and reconnects', async ({ page }) => {
@@ -56,9 +60,21 @@ test('desktop renders models, moves authoritatively, gathers, and reconnects', a
expect(pixels).toBeGreaterThan(8);
const diagnostics = await page.evaluate(() => (window as any).__aeternalis.diagnostics());
expect(diagnostics.models).toBe(6); expect(diagnostics.frames).toBeGreaterThan(10); expect(diagnostics.triangles).toBeGreaterThan(1000);
// Keep the real server connection, but hold incoming snapshots until we have
// checked that an open socket alone does not claim the world is synchronized.
let releaseSnapshots: (() => void) | undefined;
await page.routeWebSocket('**/ws', socket => {
const server = socket.connectToServer();
let held = true;
const buffered: (string | Buffer)[] = [];
server.onMessage(message => { if (held) buffered.push(message); else socket.send(message); });
releaseSnapshots = () => { held = false; for (const message of buffered) socket.send(message); buffered.length = 0; };
});
await page.reload();
await expect(page.locator('#connection-status')).toHaveText('Connected');
await expect.poll(() => page.evaluate(() => (window as any).__aeternalis?.snapshot?.self.entity.id)).toBe(id);
await expect(page.locator('#connection-status')).toHaveText('Synchronizing world', { timeout: 20000 });
expect(await page.evaluate(() => (window as any).__aeternalis?.snapshot)).toBeUndefined();
releaseSnapshots!();
await expectWorldReady(page, id);
expect(errors).toEqual([]);
});
@@ -96,14 +112,28 @@ test('boss event is visible and accepts server-authoritative combat', async ({ p
// timeout ever gets to fire and report cleanly. slow() triples this test's budget.
test.slow();
await page.setViewportSize({ width: 1440, height: 900 });
// Hold rendering after the target click. Input and server combat must keep
// progressing even when requestAnimationFrame is stalled on a slow GPU.
await page.addInitScript(() => {
const raf = window.requestAnimationFrame.bind(window);
window.requestAnimationFrame = callback => raf(time => {
const deliver = () => {
if ((window as any).__holdGameFrames) setTimeout(deliver, 50);
else callback(time);
};
deliver();
});
});
await enter(page, 'Boss witness');
await page.getByRole('button', { name: 'Display settings' }).click();
await page.getByRole('button', { name: 'Awaken Harbinger' }).click();
await expect(page.locator('#phase-label')).toHaveText('THE UNRAVELING');
await page.getByRole('button', { name: 'Close display settings' }).click();
const hp = await page.evaluate(() => (window as any).__aeternalis.snapshot.world.bossHp);
await page.locator('#target-boss').evaluate(button => button.addEventListener('click', () => { (window as any).__holdGameFrames = true; }, { once: true }));
await page.getByRole('button', { name: 'Target Harbinger', exact: true }).click();
await expect.poll(() => page.evaluate(() => (window as any).__aeternalis.snapshot.world.bossHp), { timeout: 20000 }).toBeLessThan(hp);
await page.evaluate(() => { (window as any).__holdGameFrames = false; });
await expect(page.locator('#boss-bar')).toBeVisible();
await page.screenshot({ path: 'test-results/boss.png' });
});