test(minigames): e2e smoke for the leaderboards page and document periods
Phase 8 of the minigame periods feature: - e2e smoke: the unified leaderboards page shows the period boards, the Core game tabs and the achievements section; switching to All-Time reveals the cardtable games; a game page shows its anchored period standings card. (Passes with the bundled Chromium via E2E_BROWSER_PATH; Vivaldi crashes under automation, as the root guide warns.) - Integration coverage already added alongside each phase: entry recording, the close pipeline and awards, month/year windows, the registry, the read model and the in-app notifications, plus a pure bot renderer test. - Document the periods, achievements and registry invariants in the minigames AGENTS guide.
This commit is contained in:
parent
08f2630442
commit
e59e16344e
2 changed files with 88 additions and 0 deletions
|
|
@ -9,3 +9,43 @@ Five XP-earning minigames under one parent: routes live at `/minigames/*` (moved
|
|||
- **Radio Traffic**: `/minigames/radio`, sprint + watch modes, procedural message generation (`src/components/frontend/minigames/radio/messageGenerator.ts`). Action `submitRadioResult` emits `minigame:radio-traffic`; stats under `progression.minigames.radioTraffic` (incl. `bestSprintTimeMs`).
|
||||
- **Flight Simulator**: `/minigames/flappy` (canvas game + leaderboard). **Minefield Clearance (EOD)**: `/minigames/eod`. **OPORD Recall**: `/minigames/opord` (`src/lib/minigames/opord-recall.ts`).
|
||||
- Leaderboards match active players by user id (not display name) — see commit 72715c4 if leaderboard queries look wrong.
|
||||
|
||||
## Periods, achievements & the game registry
|
||||
|
||||
Anchored 14-day scoring periods, close-time achievements, and a registry that lets
|
||||
games be phased in and out without losing history. Full behavior is documented in the
|
||||
code; the invariants are:
|
||||
|
||||
- **Scope**: only the Core five (flappy, eod, radio, qualification, opord) score periods.
|
||||
Poker and Blackjack keep their all-time profile boards and are out of periods.
|
||||
- **Anchor**: `minigame-rules.anchorDate` (default `2026-10-12T00:00:00Z`) starts Period 1
|
||||
and is treated as immutable; changing it re-slices and re-labels every period. All math
|
||||
is UTC.
|
||||
- **Ledger**: `minigame-entries` is an append-only row per completed scored run, written
|
||||
ONLY by the five submit actions through `recordMinigameEntry` (`src/lib/minigames/periods/record.ts`),
|
||||
which swallows failures so a ledger hiccup never breaks a submission. Each row carries
|
||||
`occurredAt` (the run's own instant) plus its `period`.
|
||||
- **Boards & awards**: `src/lib/minigames/periods/boards.ts` is pure. Best score ranks each
|
||||
board, the top-N placement ladder (default 10) sums across the Core boards, and ties break
|
||||
on raw period score then earliest submission. Period awards: period-champion, diligence,
|
||||
dedication, precision (min `precisionMinAttempts`), most-improved (skipped in Period 1).
|
||||
- **Close pipeline**: `src/lib/minigames/periods/lifecycle.ts` closes a period, writes its
|
||||
`achievements` rows and marks it closed. Idempotent: the status is re-checked before
|
||||
committing and the `achievements` unique key (`type:windowStart:user`) makes a duplicate
|
||||
close insert nothing. `closeCalendarWindows` additionally crowns Player of the Month and
|
||||
Player of the Year for completed calendar windows (scored by run `occurredAt`; the first
|
||||
window of each kind is partial).
|
||||
- **Tick & override**: the `period-tick` bin (`src/scripts/periodTick.ts`, external cron) runs
|
||||
the sweep; the admin close/reopen control
|
||||
(`src/components/admin/minigames/PeriodCloseControl.tsx` → `POST /api/minigame-periods/close`,
|
||||
permission `minigame-periods:close`) is the manual override.
|
||||
- **Registry**: `minigames` drives the sidebar grouping and period scoring. Retired games leave
|
||||
the nav and stop accruing next-period points while their ledger history stays. Period scoring
|
||||
uses core games with `countsForPeriods`; `loadMinigameRegistry` falls back to
|
||||
`BUILTIN_MINIGAMES` if the collection is empty.
|
||||
- **Surfaces**: `/minigames/leaderboards` (period selector + game tabs + achievements honor roll,
|
||||
fed by `GET /api/minigames/leaderboards?period=current|<id>|all-time`) and a `PeriodStandingsCard`
|
||||
on each Core game page. All-Time reads the untouched `profiles.progression.minigames.*` bests.
|
||||
- **Notifications**: winners are notified in-app on close (`minigame:achievement`, muteable);
|
||||
the Discord bot service `src/bot/services/achievementAnnouncements.ts` posts ONE embed per
|
||||
window to `DISCORD_ANNOUNCE_CHANNEL_ID` and stamps `announcedAt` + `discordMessageId`.
|
||||
|
|
|
|||
48
tests/e2e/minigame-leaderboards.e2e.spec.ts
Normal file
48
tests/e2e/minigame-leaderboards.e2e.spec.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { expect, test } from "@playwright/test";
|
||||
|
||||
/**
|
||||
* Smoke coverage for the unified minigames leaderboards: the period view, the
|
||||
* All-Time switch (which also reveals the cardtable games) and the inline period
|
||||
* standings card on a game page.
|
||||
*/
|
||||
test.describe("Minigame leaderboards", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await page.getByLabel("Username").fill("dev");
|
||||
await page.getByLabel("Password").fill("Test123");
|
||||
await page.getByRole("button", { name: "Log in" }).click();
|
||||
await page.waitForURL((url) => !url.pathname.startsWith("/login"), { timeout: 30_000 });
|
||||
});
|
||||
|
||||
test("shows the period boards, game tabs and achievements", async ({ page }) => {
|
||||
await page.goto("/minigames/leaderboards");
|
||||
|
||||
await expect(
|
||||
page.getByRole("heading", { level: 1, name: "Minigame Leaderboards" }),
|
||||
).toBeVisible();
|
||||
await expect(page.getByRole("tab", { name: "Flight Simulator" })).toBeVisible();
|
||||
await expect(page.getByRole("tab", { name: "OPORD Recall" })).toBeVisible();
|
||||
// Cardtable games are not period-scored, so they only appear All-Time.
|
||||
await expect(page.getByRole("tab", { name: "Poker" })).toHaveCount(0);
|
||||
await expect(page.getByText("Achievements", { exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("switching to All-Time surfaces every registered game", async ({ page }) => {
|
||||
await page.goto("/minigames/leaderboards");
|
||||
|
||||
await page.getByRole("combobox").click();
|
||||
await page.getByRole("option", { name: /All-Time/ }).click();
|
||||
|
||||
await expect(page.getByRole("tab", { name: "Poker" })).toBeVisible({ timeout: 15_000 });
|
||||
await expect(page.getByRole("tab", { name: "Blackjack" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("a game page shows its anchored period standings card", async ({ page }) => {
|
||||
await page.goto("/minigames/flappy");
|
||||
|
||||
await expect(
|
||||
page.getByRole("heading", { level: 2, name: "Anchored period standings" }),
|
||||
).toBeVisible();
|
||||
await expect(page.getByRole("link", { name: "All boards" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue