Files
feuerwerk/tests/php/snapshots.test.php
T
adminandClaude Opus 5.5 043c224cc3 Rename Game Maker to Feuerwerk and serve it at /feuerwerk/ (#422)
The editor gets a name of its own that fits beside Brandmauer,
Glutspeicher and Feuerwehr. This is stage 1, 2 and 4 of #422: the
name, the URL and the stored state in the browser. Repository, CI
runners, containers and the GAME_MAKER_* variables follow in stage 3.

- All paths come from SITE_PATH in src/core/site.ts: the API endpoint,
  the data folders, the play page and the base in vite.config.ts. A
  later move is one line instead of fifteen.
- The window title, the sign-in screen, the playground and the README
  say Feuerwerk. The package, __feuerwerkPlay, the take worklet and the
  writing app in Ogg and Matroska follow.
- The session cookie is now feuerwerk_session, so everyone signs in
  once more.
- localStorage keys are now feuerwerk.*. moveOldStoredKeys copies the
  old game-maker.* keys over on the first start, so settings, panel
  sizes and save games survive.
- tools/ci/serve.sh serves the build under /feuerwerk/. The variable
  GAME_MAKER_BASE_URL keeps its name until stage 3.

Outside the repository, nockal.com/feuerwerk/ is a second symlink to
the same tree. nginx sends the bare /game-maker/ folder there with a
301. Everything else under /game-maker/ is still served directly, so
shared play links and the API keep working.

Finding: when nginx redirects a path without a trailing slash or with
a query, the Brandmauer answers with its own 307 to the same URL plus
a slash, placed after the query. A play link would lose its token that
way, which is why only the bare folder is redirected.

Tests:
- Gate on melektaus-atx: CHECK EXIT 0, 307 files, 4756 tests
  (4 new in site.test.ts).
- Counter-check: when the migration misses the old prefix, 3 of the
  4 new tests fail.
- e2e 60 under /feuerwerk/: ALL PASSED, 20 checks.
- From outside: /feuerwerk/ 200, /game-maker/ 301, an old play
  link 200.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:27:43 +02:00

81 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
/**
* The snapshot store (#231) on a scratch directory. Plain PHP like accounts.test.php; CI runs it
* with `php tests/php/snapshots.test.php` and reads the last line.
*/
require __DIR__ . '/../../api/lib/AtomicFile.php';
require __DIR__ . '/../../api/lib/Store.php';
require __DIR__ . '/../../api/lib/SnapshotStore.php';
$failed = 0;
$passed = 0;
function check(string $name, bool $ok, mixed $got = null): void
{
global $failed, $passed;
if ($ok) {
$passed++;
echo "PASS {$name}\n";
return;
}
$failed++;
echo "FAIL {$name}", $got === null ? '' : ' — got ' . json_encode($got), "\n";
}
$dir = sys_get_temp_dir() . '/feuerwerk-php-snapshots-' . bin2hex(random_bytes(4));
mkdir($dir);
$snapshots = new SnapshotStore($dir);
check('a project without snapshots lists none', $snapshots->list('p1') === []);
$doc = ['revision' => 4, 'project' => ['id' => 'p1', 'name' => 'Game', 'assets' => [['id' => 'a']]]];
$first = $snapshots->create('p1', $doc, 'first');
$second = $snapshots->create('p1', ['revision' => 5] + $doc, 'second');
check('a snapshot keeps its name and the revision it copied', $first['name'] === 'first' && $first['revision'] === 4, $first);
check('two snapshots get two ids', $first['id'] !== $second['id']);
check('the summary carries no project', !isset($first['project']));
check('the snapshot file is not readable for the web server', (fileperms("{$dir}/p1/{$first['id']}.json") & 0o007) === 0);
$listed = $snapshots->list('p1');
check(
'the list is newest first, also within one second',
array_column($listed, 'name') === ['second', 'first'],
array_column($listed, 'name'),
);
// The ids are random, so two files come back from the folder in the right order half the time
// anyway. With eight, the folder's own order matching by chance is one in 40320.
$more = new SnapshotStore("{$dir}/order");
foreach (range(1, 8) as $n) {
$more->create('p', $doc, "n{$n}");
}
check(
'eight made in a row list in reverse order of making',
array_column($more->list('p'), 'name') === ['n8', 'n7', 'n6', 'n5', 'n4', 'n3', 'n2', 'n1'],
array_column($more->list('p'), 'name'),
);
$loaded = $snapshots->load('p1', $first['id']);
check('a snapshot loads the project as it was copied', $loaded !== null && $loaded['project'] === $doc['project'], $loaded);
check('a snapshot of another project is not found', $snapshots->load('p2', $first['id']) === null);
file_put_contents("{$dir}/p1/broken.json", '{"id":"broken"');
check('a broken file is left out of the list', count($snapshots->list('p1')) === 2, $snapshots->list('p1'));
unlink("{$dir}/p1/broken.json");
check('deleting a snapshot says so', $snapshots->delete('p1', $first['id']));
check('it is gone from the list', array_column($snapshots->list('p1'), 'name') === ['second']);
check('deleting it again says it was not there', !$snapshots->delete('p1', $first['id']));
$snapshots->create('p2', $doc, 'other');
$snapshots->deleteAll('p1');
check('deleting all removes the folder of that project', !is_dir("{$dir}/p1"));
check('and leaves the snapshots of other projects', count($snapshots->list('p2')) === 1);
exec('rm -rf ' . escapeshellarg($dir));
echo $failed === 0 ? "ALL PASSED – {$passed} checks\n" : "{$failed} FAILED, {$passed} passed\n";
exit($failed === 0 ? 0 : 1);