Let signed-in visitors open shared replays and add five transport controls.
Shared links should play back for anyone with the URL, and start/step/play/end buttons replace the old double-click shortcuts. Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -150,8 +150,8 @@ The feedback tests cover free and poisoned captures, exchanges, mate, allowing m
150
150
151
151
## Saved games
152
152
153
Games newly entering Your turn go to the end of the queue; the ordering survives reloads. The account summary’s hourglass opens finished games, newest first, showing opponent, outcome and end date. Both players retain access after exiting a tile or starting a rematch. Replay uses the same board orientation and tile styling, with Back/Next stepping one ply (double-click for beginning/end), and Play/Pause advancing every 500 ms. Closing the dialog stops playback. A saved result animates once per player/browser toward the hourglass; reduced-motion preferences suppress motion.
153
Games newly entering Your turn go to the end of the queue; the ordering survives reloads. The account summary’s hourglass opens finished games, newest first, showing opponent, outcome and end date. Both players retain access after exiting a tile or starting a rematch. Replay uses the same board orientation and tile styling, with jump-to-start, step back, play/pause, step forward and jump-to-end controls. Play/Pause advances every 500 ms. Closing the dialog stops playback. A saved result animates once per player/browser toward the hourglass; reduced-motion preferences suppress motion.
154
154
155
155
Replays store the initial position plus two binary bytes per ply, including promotions, separately from permanent result/rating statistics. Saved games have no retention limit and are not automatically deleted based on age. Existing finished tiles can be imported when their original color and complete history are still available. Older rematches whose color was overwritten cannot be reconstructed reliably and are not imported. Data exports include available replay positions. No scheduled worker is required.
156
156
157
The replay footer’s chain icon copies a permanent link with an unguessable token. Anyone with that link can view and play back that one game without signing in. Shared links open a standalone replay page containing only the tile and playback/share controls, with no modal, close button or surrounding application interface, plus a Microchess link back to the home page. Replay headers identify White and Black with their king icons; transport buttons use previous-track, play/pause and next-track icons with accessible labels. Public replay responses include player names and game positions, not account IDs or private history. Invalid tokens return 404.
157
The replay footer’s chain icon copies a permanent link with an unguessable token. Anyone with that link can view and play back that one game, signed in or not. Shared links open a standalone replay page containing only the tile and playback/share controls, with no modal, close button or surrounding application interface, plus a Microchess link back to the home page. Replay headers identify White and Black with their king icons; transport buttons use jump-to-start, rewind, play/pause, fast-forward and jump-to-end icons with accessible labels. Public replay responses include player names and game positions, not account IDs or private history. Invalid tokens return 404.
@@ -150,8 +150,8 @@ The feedback tests cover free and poisoned captures, exchanges, mate, allowing m150
150
151
## Saved games151
## Saved games152
152
153
Games newly entering Your turn go to the end of the queue; the ordering survives reloads. The account summary’s hourglass opens finished games, newest first, showing opponent, outcome and end date. Both players retain access after exiting a tile or starting a rematch. Replay uses the same board orientation and tile styling, with Back/Next stepping one ply (double-click for beginning/end), and Play/Pause advancing every 500 ms. Closing the dialog stops playback. A saved result animates once per player/browser toward the hourglass; reduced-motion preferences suppress motion.153
Games newly entering Your turn go to the end of the queue; the ordering survives reloads. The account summary’s hourglass opens finished games, newest first, showing opponent, outcome and end date. Both players retain access after exiting a tile or starting a rematch. Replay uses the same board orientation and tile styling, with jump-to-start, step back, play/pause, step forward and jump-to-end controls. Play/Pause advances every 500 ms. Closing the dialog stops playback. A saved result animates once per player/browser toward the hourglass; reduced-motion preferences suppress motion.154
154
155
Replays store the initial position plus two binary bytes per ply, including promotions, separately from permanent result/rating statistics. Saved games have no retention limit and are not automatically deleted based on age. Existing finished tiles can be imported when their original color and complete history are still available. Older rematches whose color was overwritten cannot be reconstructed reliably and are not imported. Data exports include available replay positions. No scheduled worker is required.155
Replays store the initial position plus two binary bytes per ply, including promotions, separately from permanent result/rating statistics. Saved games have no retention limit and are not automatically deleted based on age. Existing finished tiles can be imported when their original color and complete history are still available. Older rematches whose color was overwritten cannot be reconstructed reliably and are not imported. Data exports include available replay positions. No scheduled worker is required.156
156
157
The replay footer’s chain icon copies a permanent link with an unguessable token. Anyone with that link can view and play back that one game without signing in. Shared links open a standalone replay page containing only the tile and playback/share controls, with no modal, close button or surrounding application interface, plus a Microchess link back to the home page. Replay headers identify White and Black with their king icons; transport buttons use previous-track, play/pause and next-track icons with accessible labels. Public replay responses include player names and game positions, not account IDs or private history. Invalid tokens return 404.157
The replay footer’s chain icon copies a permanent link with an unguessable token. Anyone with that link can view and play back that one game, signed in or not. Shared links open a standalone replay page containing only the tile and playback/share controls, with no modal, close button or surrounding application interface, plus a Microchess link back to the home page. Replay headers identify White and Black with their king icons; transport buttons use jump-to-start, rewind, play/pause, fast-forward and jump-to-end icons with accessible labels. Public replay responses include player names and game positions, not account IDs or private history. Invalid tokens return 404.@@ -3,6 +3,7 @@ require __DIR__.'/lib/bootstrap.php';
3
3
try {
4
4
// A random share token grants read-only access to this replay without a session.
5
5
if ($_SERVER['REQUEST_METHOD']==='GET' && ($_GET['action']??'')==='shared_replay') {
6
session_write_close();
6
7
$token=$_GET['token']??'';
7
8
if (!is_string($token) || !preg_match('/^[a-f0-9]{48}$/D',$token)) fail('Saved game not found.',404);
8
9
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();
@@ -3,6 +3,7 @@ require __DIR__.'/lib/bootstrap.php';3
try {3
try {4
// A random share token grants read-only access to this replay without a session.4
// A random share token grants read-only access to this replay without a session.5
if ($_SERVER['REQUEST_METHOD']==='GET' && ($_GET['action']??'')==='shared_replay') {5
if ($_SERVER['REQUEST_METHOD']==='GET' && ($_GET['action']??'')==='shared_replay') {6
session_write_close();6
$token=$_GET['token']??'';7
$token=$_GET['token']??'';7
if (!is_string($token) || !preg_match('/^[a-f0-9]{48}$/D',$token)) fail('Saved game not found.',404);8
if (!is_string($token) || !preg_match('/^[a-f0-9]{48}$/D',$token)) fail('Saved game not found.',404);8
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();9
$r=query('SELECT r.a,r.b,r.winner,r.reason,r.ended,p.white,p.moves FROM replay_links l JOIN replays p ON p.result_id=l.result_id JOIN results r ON r.id=p.result_id WHERE l.token=?',[$token])->fetch();@@ -1421,7 +1421,7 @@ dialog .avatar-credits {
1421
1421
.history-entry { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; text-align: left; }
1422
1422
.history-entry strong { overflow-wrap: anywhere; }
1423
1423
dialog.replay-modal { width: min(400px, calc(100vw - 24px)); }
1424
.replay-controls { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }
1424
.replay-controls { display: flex; justify-content: space-between; gap: 6px; margin-top: 18px; }
1425
1425
#replay-progress { font-size: 12px; text-align: center; }
1426
1426
.saved-hourglass { position: fixed; z-index: 100; pointer-events: none; font-size: 24px; }
1427
1427
@@ -1430,7 +1430,7 @@ dialog.replay-modal { width: min(400px, calc(100vw - 24px)); }
1430
1430
.replay-players img { width: 24px; height: 24px; flex-shrink: 0; }
1431
1431
.replay-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
1432
1432
#replay-share { margin-left: auto; font-size: 22px; }
1433
.replay-controls button { font-size: 21px; min-width: 52px; }
1433
.replay-controls button { font-size: 18px; min-width: 0; flex: 1; padding-inline: 8px; }
1434
1434
1435
1435
body.replay-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 12px; }
1436
1436
#replay-page { width: min(360px, 100%); }
@@ -1421,7 +1421,7 @@ dialog .avatar-credits {1421
.history-entry { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; text-align: left; }1421
.history-entry { display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; text-align: left; }1422
.history-entry strong { overflow-wrap: anywhere; }1422
.history-entry strong { overflow-wrap: anywhere; }1423
dialog.replay-modal { width: min(400px, calc(100vw - 24px)); }1423
dialog.replay-modal { width: min(400px, calc(100vw - 24px)); }1424
.replay-controls { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }1424
.replay-controls { display: flex; justify-content: space-between; gap: 6px; margin-top: 18px; }1425
#replay-progress { font-size: 12px; text-align: center; }1425
#replay-progress { font-size: 12px; text-align: center; }1426
.saved-hourglass { position: fixed; z-index: 100; pointer-events: none; font-size: 24px; }1426
.saved-hourglass { position: fixed; z-index: 100; pointer-events: none; font-size: 24px; }1427
1427
@@ -1430,7 +1430,7 @@ dialog.replay-modal { width: min(400px, calc(100vw - 24px)); }1430
.replay-players img { width: 24px; height: 24px; flex-shrink: 0; }1430
.replay-players img { width: 24px; height: 24px; flex-shrink: 0; }1431
.replay-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }1431
.replay-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }1432
#replay-share { margin-left: auto; font-size: 22px; }1432
#replay-share { margin-left: auto; font-size: 22px; }1433
.replay-controls button { font-size: 21px; min-width: 52px; }1433
.replay-controls button { font-size: 18px; min-width: 0; flex: 1; padding-inline: 8px; }1434
1434
1435
body.replay-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 12px; }1435
body.replay-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 12px; }1436
#replay-page { width: min(360px, 100%); }1436
#replay-page { width: min(360px, 100%); }@@ -395,8 +395,8 @@ async function openReplay (id)
395
395
}
396
396
function showReplay (game)
397
397
{
398
const content = '<div id="replay-card"></div><div class="replay-controls"><button class="secondary" data-replay-control="back" aria-label="Previous move" title="Previous move; double-click for beginning">⏮</button><button class="primary" data-replay-control="play" aria-label="Play">▶</button><button class="secondary" data-replay-control="next" aria-label="Next move" title="Next move; double-click for end">⏭</button></div><p id="replay-progress" aria-live="polite"></p><div class="replay-bottom">' + (game.shared ? '<a class="text-button" href="./">Microchess ↗</a>' : '<button class="text-button" id="history-return">← Game history</button>') + '<button class="text-button" id="replay-share" aria-label="Copy game link" title="Copy game link">🔗</button></div>';
399
if (game.shared) { stopReplay(); $('#modal-content').innerHTML = content; }
398
const content = '<div id="replay-card"></div><div class="replay-controls"><button class="secondary" data-replay-control="start" aria-label="Jump to start" title="Jump to start">⏮</button><button class="secondary" data-replay-control="back" aria-label="Step back" title="Step back">⏪</button><button class="primary" data-replay-control="play" aria-label="Play">▶</button><button class="secondary" data-replay-control="next" aria-label="Step forward" title="Step forward">⏩</button><button class="secondary" data-replay-control="end" aria-label="Jump to end" title="Jump to end">⏭</button></div><p id="replay-progress" aria-live="polite"></p><div class="replay-bottom">' + (game.shared ? '<a class="text-button" href="./">Microchess ↗</a>' : '<button class="text-button" id="history-return">← Game history</button>') + '<button class="text-button" id="replay-share" aria-label="Copy game link" title="Copy game link">🔗</button></div>';
399
if ($('#replay-page')) { stopReplay(); $('#modal-content').innerHTML = content; }
400
400
else { showModal(content); modal.classList.add('replay-modal'); }
401
401
replay = { ...game, index: 0 };
402
402
renderReplay();
@@ -417,9 +417,12 @@ function renderReplay ()
417
417
const g = { ...replay, id: 'replay', replay: true, status: 'replay', yourTurn: false, legal: [], check: false, state: replay.positions[replay.index] };
418
418
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span><img src="${pieceUrl('K')}" alt="White">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span><img src="${pieceUrl('k')}" alt="Black">${esc(replay.blackName)}</span></div>${board(g)}</article>`;
419
419
$('#replay-progress').textContent = `${replay.index} / ${replay.positions.length - 1} · ${replay.shared ? replay.outcome : replay.outcome === 'win' ? 'Won' : replay.outcome === 'loss' ? 'Lost' : 'Draw'} · ${replay.reason}`;
420
const last = replay.positions.length - 1;
420
421
$('[data-replay-control="play"]').textContent = replayTimer ? '⏸' : '▶';
421
422
$('[data-replay-control="play"]').setAttribute('aria-label', replayTimer ? 'Pause' : 'Play');
422
$('[data-replay-control="play"]').disabled = replay.positions.length < 2;
423
$('[data-replay-control="play"]').disabled = last < 1;
424
$('[data-replay-control="start"]').disabled = $('[data-replay-control="back"]').disabled = replay.index === 0;
425
$('[data-replay-control="next"]').disabled = $('[data-replay-control="end"]').disabled = replay.index === last;
423
426
}
424
427
$('#modal-content').addEventListener('click', e => {
425
428
const b = e.target.closest('button'); if (!b) return;
@@ -440,15 +443,11 @@ $('#modal-content').addEventListener('click', e => {
440
443
}
441
444
} else {
442
445
stopReplay();
443
replay.index = Math.max(0, Math.min(replay.positions.length - 1, replay.index + (control === 'back' ? -1 : 1)));
446
const last = replay.positions.length - 1;
447
replay.index = control === 'start' ? 0 : control === 'end' ? last : Math.max(0, Math.min(last, replay.index + (control === 'back' ? -1 : 1)));
444
448
}
445
449
renderReplay();
446
450
});
447
$('#modal-content').addEventListener('dblclick', e => {
448
const control = e.target.closest('button')?.dataset.replayControl;
449
if (!replay || !['back', 'next'].includes(control)) return;
450
stopReplay(); replay.index = control === 'back' ? 0 : replay.positions.length - 1; renderReplay();
451
});
452
451
const savedAnimations = new Set();
453
452
function animateSavedGames ()
454
453
{
@@ -472,7 +471,11 @@ function animateSavedGames ()
472
471
473
472
if (new URLSearchParams(location.search).has('replay')) {
474
473
const token = new URLSearchParams(location.search).get('replay');
475
historyFetch('shared_replay&token=' + encodeURIComponent(token)).then(showReplay).catch(e => {
474
fetch('api.php?action=shared_replay&token=' + encodeURIComponent(token), { credentials: 'omit' }).then(async response => {
475
const data = await response.json();
476
if (!response.ok) throw new Error(data.error || 'Unable to load saved games.');
477
showReplay(data);
478
}).catch(e => {
476
479
$('#modal-content').innerHTML = `<h1>Game unavailable</h1><p>${esc(e.message)}</p>`;
477
480
});
478
481
}
@@ -395,8 +395,8 @@ async function openReplay (id)395
}395
}396
function showReplay (game)396
function showReplay (game)397
{397
{398
const content = '<div id="replay-card"></div><div class="replay-controls"><button class="secondary" data-replay-control="back" aria-label="Previous move" title="Previous move; double-click for beginning">⏮</button><button class="primary" data-replay-control="play" aria-label="Play">▶</button><button class="secondary" data-replay-control="next" aria-label="Next move" title="Next move; double-click for end">⏭</button></div><p id="replay-progress" aria-live="polite"></p><div class="replay-bottom">' + (game.shared ? '<a class="text-button" href="./">Microchess ↗</a>' : '<button class="text-button" id="history-return">← Game history</button>') + '<button class="text-button" id="replay-share" aria-label="Copy game link" title="Copy game link">🔗</button></div>';398
const content = '<div id="replay-card"></div><div class="replay-controls"><button class="secondary" data-replay-control="start" aria-label="Jump to start" title="Jump to start">⏮</button><button class="secondary" data-replay-control="back" aria-label="Step back" title="Step back">⏪</button><button class="primary" data-replay-control="play" aria-label="Play">▶</button><button class="secondary" data-replay-control="next" aria-label="Step forward" title="Step forward">⏩</button><button class="secondary" data-replay-control="end" aria-label="Jump to end" title="Jump to end">⏭</button></div><p id="replay-progress" aria-live="polite"></p><div class="replay-bottom">' + (game.shared ? '<a class="text-button" href="./">Microchess ↗</a>' : '<button class="text-button" id="history-return">← Game history</button>') + '<button class="text-button" id="replay-share" aria-label="Copy game link" title="Copy game link">🔗</button></div>';399
if (game.shared) { stopReplay(); $('#modal-content').innerHTML = content; }399
if ($('#replay-page')) { stopReplay(); $('#modal-content').innerHTML = content; }400
else { showModal(content); modal.classList.add('replay-modal'); }400
else { showModal(content); modal.classList.add('replay-modal'); }401
replay = { ...game, index: 0 };401
replay = { ...game, index: 0 };402
renderReplay();402
renderReplay();@@ -417,9 +417,12 @@ function renderReplay ()417
const g = { ...replay, id: 'replay', replay: true, status: 'replay', yourTurn: false, legal: [], check: false, state: replay.positions[replay.index] };417
const g = { ...replay, id: 'replay', replay: true, status: 'replay', yourTurn: false, legal: [], check: false, state: replay.positions[replay.index] };418
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span><img src="${pieceUrl('K')}" alt="White">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span><img src="${pieceUrl('k')}" alt="Black">${esc(replay.blackName)}</span></div>${board(g)}</article>`;418
$('#replay-card').innerHTML = `<article class="game-card" data-game="replay"><div class="card-header replay-players" id="modal-title"><span><img src="${pieceUrl('K')}" alt="White">${esc(replay.whiteName)}</span><span aria-hidden="true">–</span><span><img src="${pieceUrl('k')}" alt="Black">${esc(replay.blackName)}</span></div>${board(g)}</article>`;419
$('#replay-progress').textContent = `${replay.index} / ${replay.positions.length - 1} · ${replay.shared ? replay.outcome : replay.outcome === 'win' ? 'Won' : replay.outcome === 'loss' ? 'Lost' : 'Draw'} · ${replay.reason}`;419
$('#replay-progress').textContent = `${replay.index} / ${replay.positions.length - 1} · ${replay.shared ? replay.outcome : replay.outcome === 'win' ? 'Won' : replay.outcome === 'loss' ? 'Lost' : 'Draw'} · ${replay.reason}`;420
const last = replay.positions.length - 1;420
$('[data-replay-control="play"]').textContent = replayTimer ? '⏸' : '▶';421
$('[data-replay-control="play"]').textContent = replayTimer ? '⏸' : '▶';421
$('[data-replay-control="play"]').setAttribute('aria-label', replayTimer ? 'Pause' : 'Play');422
$('[data-replay-control="play"]').setAttribute('aria-label', replayTimer ? 'Pause' : 'Play');422
$('[data-replay-control="play"]').disabled = replay.positions.length < 2;423
$('[data-replay-control="play"]').disabled = last < 1;424
$('[data-replay-control="start"]').disabled = $('[data-replay-control="back"]').disabled = replay.index === 0;425
$('[data-replay-control="next"]').disabled = $('[data-replay-control="end"]').disabled = replay.index === last;423
}426
}424
$('#modal-content').addEventListener('click', e => {427
$('#modal-content').addEventListener('click', e => {425
const b = e.target.closest('button'); if (!b) return;428
const b = e.target.closest('button'); if (!b) return;@@ -440,15 +443,11 @@ $('#modal-content').addEventListener('click', e => {440
}443
}441
} else {444
} else {442
stopReplay();445
stopReplay();443
replay.index = Math.max(0, Math.min(replay.positions.length - 1, replay.index + (control === 'back' ? -1 : 1)));446
const last = replay.positions.length - 1;447
replay.index = control === 'start' ? 0 : control === 'end' ? last : Math.max(0, Math.min(last, replay.index + (control === 'back' ? -1 : 1)));444
}448
}445
renderReplay();449
renderReplay();446
});450
});447
$('#modal-content').addEventListener('dblclick', e => {448
const control = e.target.closest('button')?.dataset.replayControl;449
if (!replay || !['back', 'next'].includes(control)) return;450
stopReplay(); replay.index = control === 'back' ? 0 : replay.positions.length - 1; renderReplay();451
});452
const savedAnimations = new Set();451
const savedAnimations = new Set();453
function animateSavedGames ()452
function animateSavedGames ()454
{453
{@@ -472,7 +471,11 @@ function animateSavedGames ()472
471
473
if (new URLSearchParams(location.search).has('replay')) {472
if (new URLSearchParams(location.search).has('replay')) {474
const token = new URLSearchParams(location.search).get('replay');473
const token = new URLSearchParams(location.search).get('replay');475
historyFetch('shared_replay&token=' + encodeURIComponent(token)).then(showReplay).catch(e => {474
fetch('api.php?action=shared_replay&token=' + encodeURIComponent(token), { credentials: 'omit' }).then(async response => {475
const data = await response.json();476
if (!response.ok) throw new Error(data.error || 'Unable to load saved games.');477
showReplay(data);478
}).catch(e => {476
$('#modal-content').innerHTML = `<h1>Game unavailable</h1><p>${esc(e.message)}</p>`;479
$('#modal-content').innerHTML = `<h1>Game unavailable</h1><p>${esc(e.message)}</p>`;477
});480
});478
}481
}@@ -163,10 +163,11 @@ try{
163
163
await white.locator('.history-entry').first().click();
164
164
await white.locator('#replay-card .board').waitFor();
165
165
assert.equal(await white.locator('#replay-card [data-square="5"] img').count(),1,'Replay starts before promotion');
166
await white.locator('[data-replay-control="next"]').dblclick();
166
assert.equal(await white.locator('.replay-controls button').count(),5,'Replay has start, step, play, step and end controls');
167
await white.locator('[data-replay-control="end"]').click();
167
168
assert.match(await white.locator('#replay-card [data-square="1"] img').getAttribute('src'),/nlt/,'Replay preserves underpromotion');
168
await white.locator('[data-replay-control="back"]').dblclick();
169
assert.match(await white.locator('#replay-progress').innerText(),/^0 \/ 1/,'Double back returns to beginning');
169
await white.locator('[data-replay-control="start"]').click();
170
assert.match(await white.locator('#replay-progress').innerText(),/^0 \/ 1/,'Jump to start returns to beginning');
170
171
await white.locator('[data-replay-control="play"]').click();
171
172
assert.equal(await white.locator('[data-replay-control="play"]').getAttribute('aria-label'),'Pause','Play becomes pause');
172
173
await white.waitForTimeout(600);
@@ -197,9 +198,15 @@ try{
197
198
await guest.reload();
198
199
await guest.locator('#replay-card .board').waitFor();
199
200
200
await guest.locator('[data-replay-control="next"]').dblclick();
201
await guest.locator('[data-replay-control="end"]').click();
201
202
assert.match(await guest.locator('#replay-card [data-square="1"] img').getAttribute('src'),/nlt/,'Shared replay plays the same promotion');
202
203
await guestContext.close();
204
await black.goto(replayUrl);
205
await black.locator('#replay-card .board').waitFor();
206
assert.equal(await black.locator('#replay-page').count(),1,'Signed-in visitor sees the standalone shared replay');
207
assert.equal(await black.locator('.topbar, .login, #sidebar, #your-games').count(),0,'Signed-in shared replay has no account chrome');
208
await black.goto(base);
209
await black.locator('#your-games').waitFor();
203
210
await white.screenshot({path:path.join(web,'tests/artifacts/game-replay.png')});
204
211
await white.locator('#modal-close').click();
205
212
await white.evaluate(()=>refresh(true));
@@ -163,10 +163,11 @@ try{163
await white.locator('.history-entry').first().click();163
await white.locator('.history-entry').first().click();164
await white.locator('#replay-card .board').waitFor();164
await white.locator('#replay-card .board').waitFor();165
assert.equal(await white.locator('#replay-card [data-square="5"] img').count(),1,'Replay starts before promotion');165
assert.equal(await white.locator('#replay-card [data-square="5"] img').count(),1,'Replay starts before promotion');166
await white.locator('[data-replay-control="next"]').dblclick();166
assert.equal(await white.locator('.replay-controls button').count(),5,'Replay has start, step, play, step and end controls');167
await white.locator('[data-replay-control="end"]').click();167
assert.match(await white.locator('#replay-card [data-square="1"] img').getAttribute('src'),/nlt/,'Replay preserves underpromotion');168
assert.match(await white.locator('#replay-card [data-square="1"] img').getAttribute('src'),/nlt/,'Replay preserves underpromotion');168
await white.locator('[data-replay-control="back"]').dblclick();169
await white.locator('[data-replay-control="start"]').click();169
assert.match(await white.locator('#replay-progress').innerText(),/^0 \/ 1/,'Double back returns to beginning');170
assert.match(await white.locator('#replay-progress').innerText(),/^0 \/ 1/,'Jump to start returns to beginning');170
await white.locator('[data-replay-control="play"]').click();171
await white.locator('[data-replay-control="play"]').click();171
assert.equal(await white.locator('[data-replay-control="play"]').getAttribute('aria-label'),'Pause','Play becomes pause');172
assert.equal(await white.locator('[data-replay-control="play"]').getAttribute('aria-label'),'Pause','Play becomes pause');172
await white.waitForTimeout(600);173
await white.waitForTimeout(600);@@ -197,9 +198,15 @@ try{197
await guest.reload();198
await guest.reload();198
await guest.locator('#replay-card .board').waitFor();199
await guest.locator('#replay-card .board').waitFor();199
200
200
await guest.locator('[data-replay-control="next"]').dblclick();201
await guest.locator('[data-replay-control="end"]').click();201
assert.match(await guest.locator('#replay-card [data-square="1"] img').getAttribute('src'),/nlt/,'Shared replay plays the same promotion');202
assert.match(await guest.locator('#replay-card [data-square="1"] img').getAttribute('src'),/nlt/,'Shared replay plays the same promotion');202
await guestContext.close();203
await guestContext.close();204
await black.goto(replayUrl);205
await black.locator('#replay-card .board').waitFor();206
assert.equal(await black.locator('#replay-page').count(),1,'Signed-in visitor sees the standalone shared replay');207
assert.equal(await black.locator('.topbar, .login, #sidebar, #your-games').count(),0,'Signed-in shared replay has no account chrome');208
await black.goto(base);209
await black.locator('#your-games').waitFor();203
await white.screenshot({path:path.join(web,'tests/artifacts/game-replay.png')});210
await white.screenshot({path:path.join(web,'tests/artifacts/game-replay.png')});204
await white.locator('#modal-close').click();211
await white.locator('#modal-close').click();205
await white.evaluate(()=>refresh(true));212
await white.evaluate(()=>refresh(true));@@ -154,6 +154,11 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:
154
154
public=json.load(response)
155
155
check(public['positions']==saved['positions'] and public['outcome']=='White won','Anonymous shared replay contains original game')
156
156
check(not {'a','b','csrf','opponentId'} & public.keys(),'Public replay exposes no account identifiers or session data')
157
check(white.get('/api.php?action=shared_replay&token='+token)['positions']==saved['positions'],'Signed-in player can open a shared replay')
158
check(black.get('/api.php?action=shared_replay&token='+token)['outcome']=='White won','Opponent session can open the same shared replay')
159
with white.opener.open(base+'/?replay='+token) as response:
160
page=response.read().decode()
161
check('id="replay-page"' in page and 'id="your-games"' not in page,'Signed-in visitor gets the standalone replay page')
157
162
check(white.get(f'/api.php?action=replay&id={saved_id}')['shareToken']==token,'Share token remains stable')
158
163
try:
159
164
urllib.request.urlopen(urllib.request.Request(base+'/api.php?action=shared_replay&token='+'0'*48,headers={'Host':'example.test'}))
@@ -329,7 +334,10 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:
329
334
with sqlite3.connect(root/'data/microchess.sqlite') as archive_db:
330
335
private_id=archive_db.execute("INSERT INTO results(game_id,a,b,winner,reason,state,ended) SELECT game_id,'queue:oldest','queue:near',NULL,'Draw','{}',ended FROM results WHERE id=?",(saved_id,)).lastrowid
331
336
archive_db.execute("INSERT INTO replays SELECT ?,'queue:oldest',moves FROM replays WHERE result_id=?",(private_id,saved_id))
337
outsider_token=os.urandom(24).hex()
338
archive_db.execute('INSERT INTO replay_links(result_id,token) VALUES(?,?)',(private_id,outsider_token))
332
339
check(all(r['id']!=private_id for r in a.get('/api.php?action=history')),'History excludes other players games')
340
check(a.get('/api.php?action=shared_replay&token='+outsider_token)['shared'] is True,'Signed-in outsider can view another pair\'s shared replay')
333
341
try:
334
342
a.get(f'/api.php?action=replay&id={private_id}')
335
343
check(False,'Other players replay unavailable')
@@ -154,6 +154,11 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:154
public=json.load(response)154
public=json.load(response)155
check(public['positions']==saved['positions'] and public['outcome']=='White won','Anonymous shared replay contains original game')155
check(public['positions']==saved['positions'] and public['outcome']=='White won','Anonymous shared replay contains original game')156
check(not {'a','b','csrf','opponentId'} & public.keys(),'Public replay exposes no account identifiers or session data')156
check(not {'a','b','csrf','opponentId'} & public.keys(),'Public replay exposes no account identifiers or session data')157
check(white.get('/api.php?action=shared_replay&token='+token)['positions']==saved['positions'],'Signed-in player can open a shared replay')158
check(black.get('/api.php?action=shared_replay&token='+token)['outcome']=='White won','Opponent session can open the same shared replay')159
with white.opener.open(base+'/?replay='+token) as response:160
page=response.read().decode()161
check('id="replay-page"' in page and 'id="your-games"' not in page,'Signed-in visitor gets the standalone replay page')157
check(white.get(f'/api.php?action=replay&id={saved_id}')['shareToken']==token,'Share token remains stable')162
check(white.get(f'/api.php?action=replay&id={saved_id}')['shareToken']==token,'Share token remains stable')158
try:163
try:159
urllib.request.urlopen(urllib.request.Request(base+'/api.php?action=shared_replay&token='+'0'*48,headers={'Host':'example.test'}))164
urllib.request.urlopen(urllib.request.Request(base+'/api.php?action=shared_replay&token='+'0'*48,headers={'Host':'example.test'}))@@ -329,7 +334,10 @@ with tempfile.TemporaryDirectory(prefix='api-', dir=ARTIFACTS) as tmp:329
with sqlite3.connect(root/'data/microchess.sqlite') as archive_db:334
with sqlite3.connect(root/'data/microchess.sqlite') as archive_db:330
private_id=archive_db.execute("INSERT INTO results(game_id,a,b,winner,reason,state,ended) SELECT game_id,'queue:oldest','queue:near',NULL,'Draw','{}',ended FROM results WHERE id=?",(saved_id,)).lastrowid335
private_id=archive_db.execute("INSERT INTO results(game_id,a,b,winner,reason,state,ended) SELECT game_id,'queue:oldest','queue:near',NULL,'Draw','{}',ended FROM results WHERE id=?",(saved_id,)).lastrowid331
archive_db.execute("INSERT INTO replays SELECT ?,'queue:oldest',moves FROM replays WHERE result_id=?",(private_id,saved_id))336
archive_db.execute("INSERT INTO replays SELECT ?,'queue:oldest',moves FROM replays WHERE result_id=?",(private_id,saved_id))337
outsider_token=os.urandom(24).hex()338
archive_db.execute('INSERT INTO replay_links(result_id,token) VALUES(?,?)',(private_id,outsider_token))332
check(all(r['id']!=private_id for r in a.get('/api.php?action=history')),'History excludes other players games')339
check(all(r['id']!=private_id for r in a.get('/api.php?action=history')),'History excludes other players games')340
check(a.get('/api.php?action=shared_replay&token='+outsider_token)['shared'] is True,'Signed-in outsider can view another pair\'s shared replay')333
try:341
try:334
a.get(f'/api.php?action=replay&id={private_id}')342
a.get(f'/api.php?action=replay&id={private_id}')335
check(False,'Other players replay unavailable')343
check(False,'Other players replay unavailable')