fix(ads): fire the hint interstitial on the confirmed move, not on the hint
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Successful in 21s
CI / ui (pull_request) Successful in 1m10s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m48s

Taking a hint fired the post-move interstitial immediately, when the hint's
preview tiles landed — interrupting the turn and reverting the board to the
rack on the ad's close while the hint stayed spent. Move the trigger to the
move confirmation: a hint applied this turn marks it (hintUsedThisTurn), and
the confirmed play fires the hint-kind interstitial (its own cooldown)
instead of the plain move one; the marker clears on any turn boundary
(applyMoveResult) so a hint-then-pass does not leak into the next move.

e2e: taking a hint fires no ad; confirming a move does.
This commit is contained in:
Ilia Denisov
2026-07-10 03:12:30 +02:00
parent 13be7c3d9a
commit 2ce80c241d
2 changed files with 42 additions and 6 deletions
+27
View File
@@ -48,6 +48,33 @@ test('placing a tile and confirming via ✅ commits the move', async ({ page })
await expect(page.locator('.make')).toBeHidden(); await expect(page.locator('.make')).toBeHidden();
}); });
// Regression: taking a hint must NOT fire the post-move interstitial. Firing on the hint interrupted
// placing the preview and reverted the board on the ad's close while the hint stayed spent (the
// reported bug). In mock mode the ad stub shows an "ad fired" toast, standing in for a real VK ad.
test('taking a hint does not fire the interstitial', async ({ page }) => {
await openGame(page);
// Take a hint (the control confirms on a second tap). It produces a legal preview, so the ✅
// control appears — proof the hint fired.
const hint = page.getByRole('button', { name: 'Hint' });
await hint.click();
await hint.click();
await expect(page.locator('.make')).toBeVisible();
// A spurious ad would have toasted by now; none may.
await page.waitForTimeout(400);
await expect(page.getByText('ad fired')).toHaveCount(0);
});
// The interstitial fires once the move is CONFIRMED (never on the hint / pass / exchange / resign).
test('confirming a move fires the interstitial', async ({ page }) => {
await openGame(page);
await page.locator('.rack .tile').first().click();
await page.locator('[data-cell]:not(.filled)').nth(30).click();
await expect(page.locator('[data-cell].pending')).toHaveCount(1);
await page.locator('.make').click();
await expect(page.getByText('ad fired')).toBeVisible();
});
test('a placed tile is saved as a draft and restored on reopening the game', async ({ page }) => { test('a placed tile is saved as a draft and restored on reopening the game', async ({ page }) => {
await openGame(page); await openGame(page);
await page.locator('.rack .tile').first().click(); await page.locator('.rack .tile').first().click();
+15 -6
View File
@@ -94,6 +94,11 @@
let exchangeOpen = $state(false); let exchangeOpen = $state(false);
let exchangeSel = $state<number[]>([]); let exchangeSel = $state<number[]>([]);
let resignOpen = $state(false); let resignOpen = $state(false);
// hintUsedThisTurn marks that a hint was applied on the current turn, so a confirmed play earns
// the hint-kind interstitial (its own 1-min cooldown) instead of the plain move one. Set in
// doHint when the hint's tiles land, read in commit, and cleared on any turn boundary
// (applyMoveResult) so a hint-then-pass does not leak into the next turn's move.
let hintUsedThisTurn = $state(false);
let drag = $state<{ letter: string; blank: boolean; x: number; y: number; touch: boolean } | null>(null); let drag = $state<{ letter: string; blank: boolean; x: number; y: number; touch: boolean } | null>(null);
// Landscape (wide) layout: when the viewport is wider than tall the game switches to a // Landscape (wide) layout: when the viewport is wider than tall the game switches to a
// two-column layout — the board fills the right side as a square fitted to the height (no // two-column layout — the board fills the right side as a square fitted to the height (no
@@ -820,6 +825,9 @@
// applyMoveResult renders the actor's own just-committed move from the response — the move, the // applyMoveResult renders the actor's own just-committed move from the response — the move, the
// post-move game and the refilled rack — without a follow-up game.state + game.history. // post-move game and the refilled rack — without a follow-up game.state + game.history.
function applyMoveResult(r: MoveResult) { function applyMoveResult(r: MoveResult) {
// A turn boundary (play / pass / exchange / resign): clear the hint marker so it never leaks
// into the next turn. commit captures it before this runs.
hintUsedThisTurn = false;
view = { view = {
game: r.game, game: r.game,
seat: r.move.player, seat: r.move.player,
@@ -942,6 +950,9 @@
const sub = toSubmit(placement); const sub = toSubmit(placement);
if (!sub) return; if (!sub) return;
busy = true; busy = true;
// Capture the hint marker before applyMoveResult clears it: a move played off a hint earns the
// hint-kind interstitial (own cooldown), a plain move the move-kind one.
const usedHint = hintUsedThisTurn;
try { try {
applyMoveResult(await source.submitPlay(id, sub.tiles, variant)); applyMoveResult(await source.submitPlay(id, sub.tiles, variant));
if (view?.game.hotseat) await advanceHotseat(); if (view?.game.hotseat) await advanceHotseat();
@@ -949,7 +960,7 @@
zoomed = false; zoomed = false;
// A confirmed move may trigger a post-move interstitial (VK, frequency-gated, client-mirrored). // A confirmed move may trigger a post-move interstitial (VK, frequency-gated, client-mirrored).
// Only submitPlay earns one — never a pass / exchange / resign. Fire-and-forget. // Only submitPlay earns one — never a pass / exchange / resign. Fire-and-forget.
void maybeShowInterstitial(app.profile?.ads, 'move', { void maybeShowInterstitial(app.profile?.ads, usedHint ? 'hint' : 'move', {
vsAi: !!view?.game.vsAi, vsAi: !!view?.game.vsAi,
online: connection.online && !offlineMode.active, online: connection.online && !offlineMode.active,
}); });
@@ -1014,13 +1025,11 @@
} }
try { try {
const h = await source.hint(id); const h = await source.hint(id);
// Applying a hint triggers its own post-move interstitial, independent of the move cooldown.
void maybeShowInterstitial(app.profile?.ads, 'hint', {
vsAi: !!view?.game.vsAi,
online: connection.online && !offlineMode.active,
});
if (h.move.tiles.length && view) { if (h.move.tiles.length && view) {
placement = placementFromHint(h.move.tiles, view.rack); placement = placementFromHint(h.move.tiles, view.rack);
// Mark the turn as hinted: the interstitial fires when the player CONFIRMS the move (commit),
// not now — showing it here would interrupt placing the preview and revert the board on close.
hintUsedThisTurn = true;
// Scroll the (zoomed) board to the hint's placement rather than the top-left: // Scroll the (zoomed) board to the hint's placement rather than the top-left:
// focus the centre of the laid tiles' bounding box. // focus the centre of the laid tiles' bounding box.
const p = placement.pending; const p = placement.pending;