// Repeatable lag test: one client gets a seeded snapshot delay+jitter (?netlag). The opponent robot must still // move SMOOTHLY on that client (entity interpolation), i.e. no large per-step jumps - the bug Michi reported. 'use strict'; const { test, expect } = require('@playwright/test'); const { login, toLobby } = require('./helpers'); test('a jittery client still sees the opponent move smoothly (interpolation buffer)', async ({ browser }) => { const ctxA = await browser.newContext(), ctxB = await browser.newContext(); const a = await ctxA.newPage(), b = await ctxB.newPage(); const errors = []; for (const p of [a, b]) p.on('pageerror', e => errors.push(e.message)); // michi gets a repeatable snapshot delay + jitter (80 ms +/- 40 ms, seeded) + the position probe await login(a, 'michi', 'Michi2000!', '&netlag=80,40,7&netprobe'); await login(b, 'benni', 'Benni2000!'); await toLobby(a); await toLobby(b); await a.locator('.prow', { hasText: 'benni' }).locator('.chal').click(); await expect(b.locator('#cYes')).toBeVisible(); await b.locator('#cYes').click(); await expect(a.locator('body')).toHaveAttribute('data-mode', 'fight'); await expect(b.locator('body')).toHaveAttribute('data-mode', 'fight'); await a.waitForTimeout(4200); // countdown await a.evaluate(() => { globalThis.__probe.length = 0; }); await b.keyboard.down('w'); // benni drives so his robot moves across michi's screen await a.keyboard.down('a'); // michi turns a bit (keeps both sides active) await a.waitForTimeout(2600); await b.keyboard.up('w'); await a.keyboard.up('a'); const probe = await a.evaluate(() => globalThis.__probe.slice()); // consider only samples while the opponent was actually moving const deltas = []; let moved = 0; for (let i = 1; i < probe.length; i++) { const dx = probe[i].x - probe[i - 1].x, dz = probe[i].z - probe[i - 1].z; const d = Math.hypot(dx, dz); deltas.push(d); moved += d; } expect(probe.length, 'probe collected samples').toBeGreaterThan(30); expect(moved, 'the opponent actually moved (test is meaningful)').toBeGreaterThan(0.8); const maxJump = Math.max(...deltas); // at ~5 m/s over a 60 Hz step a smooth move is ~0.08/step; a snapshot-jump would be several times that. expect(maxJump, 'no large per-step jump despite jitter (smooth interpolation)').toBeLessThan(0.35); expect(errors, 'no JavaScript errors').toEqual([]); await ctxA.close(); await ctxB.close(); });