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>
79 lines
3.3 KiB
PHP
79 lines
3.3 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
/**
|
||
* The release store (#266) on a scratch directory. Plain PHP like snapshots.test.php; CI runs it
|
||
* with `php tests/php/releases.test.php` and reads the last line.
|
||
*/
|
||
|
||
require __DIR__ . '/../../api/lib/AtomicFile.php';
|
||
require __DIR__ . '/../../api/lib/Store.php';
|
||
require __DIR__ . '/../../api/lib/ReleaseStore.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-releases-' . bin2hex(random_bytes(4));
|
||
mkdir($dir);
|
||
$releases = new ReleaseStore($dir);
|
||
|
||
check('a project that was never released has none', $releases->of('p1') === null);
|
||
check('taking down a project without a release says so', $releases->takeDown('p1') === false);
|
||
|
||
$doc = ['id' => 'p1', 'name' => 'Game', 'revision' => 4, 'project' => ['id' => 'p1', 'assets' => [['id' => 'a']]]];
|
||
$first = $releases->publish($doc);
|
||
check('publishing hands out a 128-bit token', ReleaseStore::isValidToken($first['token']), $first);
|
||
check('the summary names the revision it copied', $first['revision'] === 4, $first);
|
||
check('the project now has that release', $releases->of('p1') === $first, $releases->of('p1'));
|
||
|
||
$loaded = $releases->load($first['token']);
|
||
check(
|
||
'the token loads the copy, its name and its project',
|
||
$loaded !== null && $loaded['project'] === $doc['project'] && $loaded['name'] === 'Game' && $loaded['projectId'] === 'p1',
|
||
$loaded,
|
||
);
|
||
check('the release file is not readable for the web server', (fileperms("{$dir}/{$first['token']}.json") & 0o007) === 0);
|
||
check('nor is the file that says which link a project has', (fileperms("{$dir}/projects/p1.json") & 0o007) === 0);
|
||
|
||
$changed = ['revision' => 7, 'project' => ['id' => 'p1', 'assets' => []]] + $doc;
|
||
$second = $releases->publish($changed);
|
||
check('publishing again keeps the link', $second['token'] === $first['token'], $second);
|
||
check('and replaces the copy', $releases->load($first['token'])['project'] === $changed['project']);
|
||
check('with the new revision', $second['revision'] === 7, $second);
|
||
|
||
$other = $releases->publish(['id' => 'p2'] + $doc);
|
||
check('another project gets another link', $other['token'] !== $first['token']);
|
||
|
||
check('an unknown token loads nothing', $releases->load(str_repeat('0', 32)) === null);
|
||
check('a token of the wrong shape loads nothing', $releases->load('../projects/p1') === null);
|
||
check('a project id is not a token', $releases->load('p1') === null);
|
||
|
||
check('taking down a release says so', $releases->takeDown('p1') === true);
|
||
check('the link is dead afterwards', $releases->load($first['token']) === null);
|
||
check('and the project has no release', $releases->of('p1') === null);
|
||
check('the other project keeps its own', $releases->load($other['token']) !== null);
|
||
|
||
$again = $releases->publish($doc);
|
||
check('publishing after a take-down hands out a new link', $again['token'] !== $first['token'], $again);
|
||
|
||
foreach (array_merge(glob("{$dir}/projects/*") ?: [], glob("{$dir}/*.json") ?: []) as $file) {
|
||
unlink($file);
|
||
}
|
||
@rmdir("{$dir}/projects");
|
||
@rmdir($dir);
|
||
|
||
echo $failed === 0 ? "ALL PASSED – {$passed} checks\n" : "{$failed} FAILED, {$passed} passed\n";
|
||
exit($failed === 0 ? 0 : 1);
|