Files
aeternalis/tests/portal.spec.ts
T
dingoandClaude Sonnet 5 db70920640 fix: retry gather/attack with a progress-based give-up (isolated retest)
Testing this in isolation from the anti-throttle Chromium flags and
the DB-lock change (reverted separately, ruled out on its own): the
single fire-and-forget gather/attack action has no recovery if the one
evaluated frame doesn't line up with the authoritative server position
-- confirmed by live-instrumenting the unpatched code locally and
watching it hang. This reinstates the fix from the earlier round, with
both bugs found via live diagnostic testing already fixed going in:

- Retries at a conservative cadence (~0.3s, well under the intent rate
  limit) instead of firing once and giving up forever.
- Gives up on a target only once an actual progress signal (target HP
  for attack, held-item count for gather/loot) has stopped moving for
  a wall-clock budget -- not "hasn't succeeded since the click" (which
  wrongly aborts mid-fight during a normal cooldown lull) and not a
  frame/attempt count (which balloons into tens of real seconds on a
  tab with sparse rendered frames).
- The dedicated boss-attack button now also resets the progress clock;
  it used to bypass action() entirely and read an uninitialized clock,
  immediately abandoning the boss for the nearest mob on click.

Deliberately NOT re-adding the Chromium anti-throttle flags this round
-- keeping this an isolated variable after the last round's session
crash coincided with adding them.

Also bumped one unrelated, independently-diagnosed timeout: the
post-death new-character join in portal.spec.ts was polling on
Playwright's default 5s timeout for a fresh join's first snapshot,
with no connection to the retry logic above.

Verified: tsc/build clean, three full local e2e runs (7/7 each).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-06 14:06:26 -04:00

75 lines
5.2 KiB
TypeScript

import { test, expect } from '@playwright/test';
test('public directory and account history fit desktop and mobile', async ({ page }) => {
const errors: string[] = []; page.on('pageerror', e => errors.push(e.message));
await page.setViewportSize({ width: 1440, height: 1000 });
await page.goto('/');
await expect(page.getByRole('heading', { name: 'Aeternalis', exact: true })).toBeVisible();
await expect(page.locator('.world-row')).toHaveCount(1);
await expect(page.locator('.world-hero img')).toBeVisible();
await expect.poll(() => page.locator('.world-hero img').evaluate((img: HTMLImageElement) => img.naturalWidth)).toBeGreaterThan(100);
await page.getByRole('button', { name: 'Sign in', exact: true }).click();
await expect(page.getByRole('button', { name: 'Sign out', exact: true })).toBeVisible();
await page.screenshot({ path: 'test-results/website-desktop.png', fullPage: true });
await page.setViewportSize({ width: 390, height: 844 });
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await page.screenshot({ path: 'test-results/website-mobile.png', fullPage: true });
expect(errors).toEqual([]);
});
test('admin actions are audited and death permits a distinct replacement', async ({ page }) => {
const origin = 'http://127.0.0.1:18089';
await page.request.post('/auth/dev', { data: {}, headers: { Origin: origin } });
const joined = await page.request.post('/worlds/e2e/api/join', { data: { name: 'Portal life', passage: '' }, headers: { Origin: origin } });
expect(joined.status()).toBe(200); const old = await joined.json();
await page.setViewportSize({ width: 1440, height: 1000 });
await page.goto('/control');
await expect(page.locator('#workspace')).toBeVisible();
await page.getByRole('button', { name: 'Characters', exact: true }).click();
await expect(page.locator('#view-title')).toHaveText('Characters');
await page.getByRole('searchbox', { name: 'Search records' }).fill('Portal life');
await expect(page.locator('tbody tr')).toHaveCount(1);
await page.getByRole('button', { name: 'Portal life', exact: true }).click();
await expect(page.locator('#character-dialog')).toBeVisible();
await expect(page.locator('#character-detail')).toContainText(old.entity.id);
await page.getByRole('button', { name: 'Close character', exact: true }).click();
await page.getByLabel(`Action for ${old.entity.id}`).selectOption('rename');
await page.getByLabel('Character name', { exact: true }).fill('Portal renamed');
await page.getByLabel('Reason', { exact: true }).fill('Rename verification');
await page.getByRole('button', { name: 'Queue action' }).click();
await expect.poll(async () => (await (await page.request.get('/api/account')).json()).active?.name).toBe('Portal renamed');
await page.getByRole('searchbox', { name: 'Search records' }).fill('Portal renamed');
await page.getByRole('button', { name: 'Refresh', exact: true }).click();
await expect(page.locator('tbody tr')).toHaveCount(1);
await page.screenshot({ path: 'test-results/control-desktop.png', fullPage: true });
await page.getByLabel(`Action for ${old.entity.id}`).selectOption('retire');
await page.getByLabel('Reason', { exact: true }).fill('Permanent death verification');
await page.getByLabel(`Confirm character ID: ${old.entity.id}`).fill(old.entity.id);
await page.getByRole('button', { name: 'Queue action' }).click();
await expect.poll(async () => (await (await page.request.get('/api/account')).json()).active).toBeNull();
await page.goto('/game?world=e2e');
await expect(page.locator('#connection-status')).toHaveText('World online');
await page.getByLabel('Character name', { exact: true }).fill('Portal second life');
await page.getByRole('button', { name: 'Enter world' }).click();
await expect(page.locator('#connection-status')).toHaveText('Connected');
// Default 5s poll was too tight for a fresh join's first snapshot on slow CI hardware.
await expect.poll(() => page.evaluate(() => (window as any).__aeternalis?.snapshot?.self?.entity?.id), { timeout: 15000 }).toBeTruthy();
const current = await page.evaluate(() => (window as any).__aeternalis.snapshot.self.entity.id);
expect(current).not.toBe(old.entity.id);
const account = await (await page.request.get('/api/account')).json();
expect(account.characters.find(c => c.id === old.entity.id).state).toBe('dead');
expect(account.characters.find(c => c.id === old.entity.id).character.deathReason).toContain('Permanent death verification');
await page.goto('/control'); await page.getByRole('button', { name: 'Audit log', exact: true }).click();
await expect(page.locator('tbody')).toContainText('Permanent death verification');
await page.setViewportSize({ width: 390, height: 844 });
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await page.screenshot({ path: 'test-results/control-mobile.png', fullPage: true });
});
test('control gives anonymous visitors a sign-in state', async ({ page }) => {
await page.goto('/control');
await expect(page.getByRole('heading', { name: 'Sign in to Control' })).toBeVisible();
await expect(page.locator('#workspace')).toBeHidden();
expect((await page.request.get('/api/control')).status()).toBe(401);
});