Files
FaroeGames 6b693cc3c6 Add Legends: Arceus tracker and bundle offline sprites on dev
Add standalone Pokémon Legends: Arceus POC tracker (Hisui 242 Pokédex, Research Tasks & RL10 mode, Satchel MP & Save Mythicals toggles, Noble/story battles, saves/movesets), bundle local sprite packs across all three trackers into Git/Docker/Nginx with attribution credits, and update Hub landing page & unified server/tests.
2026-11-17 17:53:59 -07:00

234 lines
10 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import http from 'node:http';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createPortalServer } from '../server.mjs';
import { renderSavePills } from '../assets/landing.js';
import { renderHeader as renderOrasHeader } from '../oras/src/ui/header.js';
import { getGame as getOrasGame } from '../oras/src/data/games/index.js';
import { createTrackerStore as createOrasStore, computeGameProgress as computeOrasProgress } from '../oras/src/state/tracker-store.js';
import { renderHeader as renderLumiHeader } from '../luminescent-platinum/src/ui/header.js';
import { getGame as getLumiGame } from '../luminescent-platinum/src/data/games/index.js';
import { createTrackerStore as createLumiStore, computeGameProgress as computeLumiProgress } from '../luminescent-platinum/src/state/tracker-store.js';
import { renderHeader as renderPlaHeader } from '../legends-arceus/src/ui/header.js';
import { getGame as getPlaGame } from '../legends-arceus/src/data/games/index.js';
import { createTrackerStore as createPlaStore, computeGameProgress as computePlaProgress } from '../legends-arceus/src/state/tracker-store.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIR = path.resolve(__dirname, '..');
function makeMemoryStorage(initial = {}) {
const map = new Map(Object.entries(initial));
return {
getItem(k) {
return map.has(k) ? map.get(k) : null;
},
setItem(k, v) {
map.set(k, String(v));
},
removeItem(k) {
map.delete(k);
},
};
}
test('Unified hub server serves landing page, trailing-slash redirects, both subfolders, and blocks traversal', async () => {
const server = createPortalServer(ROOT_DIR);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const { port } = server.address();
try {
const hubRes = await fetch(`http://127.0.0.1:${port}/`);
assert.equal(hubRes.status, 200);
const hubHtml = await hubRes.text();
assert.ok(hubHtml.includes('href="./oras/"'));
assert.ok(hubHtml.includes('href="./luminescent-platinum/"'));
assert.ok(hubHtml.includes('href="./legends-arceus/"'));
assert.ok(hubHtml.includes('src="./oras/assets/sprites/'));
assert.ok(hubHtml.includes('src="./luminescent-platinum/assets/sprites/'));
assert.ok(hubHtml.includes('src="./legends-arceus/assets/sprites/'));
assert.equal(hubHtml.includes('https://raw.githubusercontent.com/'), false);
assert.ok(hubHtml.includes('href="./assets/favicon.svg"'));
assert.ok(hubHtml.includes('https://git.trevorstocks.ca/FaroeGames/oaktracker/issues'));
for (const iconPath of ['/assets/favicon.svg', '/oras/favicon.svg', '/luminescent-platinum/favicon.svg', '/legends-arceus/favicon.svg']) {
const iconRes = await fetch(`http://127.0.0.1:${port}${iconPath}`);
assert.equal(iconRes.status, 200);
assert.match(iconRes.headers.get('content-type') || '', /image\/svg\+xml/);
const svgBody = await iconRes.text();
assert.ok(svgBody.includes('<svg'));
}
const cssRes = await fetch(`http://127.0.0.1:${port}/assets/landing.css`);
assert.equal(cssRes.status, 200);
const healthRes = await fetch(`http://127.0.0.1:${port}/health`);
assert.equal(healthRes.status, 200);
assert.deepEqual(await healthRes.json(), { status: 'ok' });
for (const folder of ['/oras', '/luminescent-platinum', '/legends-arceus']) {
const redirRes = await fetch(`http://127.0.0.1:${port}${folder}`, { redirect: 'manual' });
assert.equal(redirRes.status, 301);
assert.equal(redirRes.headers.get('location'), `${folder}/`);
const appRes = await fetch(`http://127.0.0.1:${port}${folder}/`);
assert.equal(appRes.status, 200);
const modRes = await fetch(`http://127.0.0.1:${port}${folder}/src/app.js`);
assert.equal(modRes.status, 200);
assert.match(modRes.headers.get('content-type') || '', /javascript/);
const statusRes = await fetch(`http://127.0.0.1:${port}${folder}/api/assets-status`);
assert.equal(statusRes.status, 200);
const statusJson = await statusRes.json();
assert.equal(statusJson.hasLocalSprites, true);
}
const badStatus = await new Promise((resolve, reject) => {
const req = http.request(
{ hostname: '127.0.0.1', port, path: '/oras/../../package.json', method: 'GET' },
(res) => {
res.resume();
resolve(res.statusCode);
},
);
req.on('error', reject);
req.end();
});
assert.equal(badStatus, 403);
} finally {
await new Promise((resolve) => server.close(resolve));
}
});
test('Landing page save detection reads both ORAS and Luminescent localStorage keys accurately', () => {
const storage = makeMemoryStorage({
'poc-tracker:v1:app-meta': JSON.stringify({
activeGameId: 'omega-ruby',
gameProfiles: {
'omega-ruby': {
activeProfileId: 'p2',
profiles: [
{ id: 'default', name: 'Save 1' },
{ id: 'p2', name: 'Main OR' },
],
},
},
}),
'poc-tracker:v1:omega-ruby:p2': JSON.stringify({ caught: ['mudkip', 'zigzagoon', 'taillow'] }),
'lumi-poc-tracker:v1:app-meta': JSON.stringify({
activeGameId: 'luminescent-platinum',
gameProfiles: {
'luminescent-platinum': {
activeProfileId: 'default',
profiles: [{ id: 'default', name: 'Sinnoh Run' }],
},
},
}),
'lumi-poc-tracker:v1:luminescent-platinum': JSON.stringify({ caught: ['chimchar', 'starly'] }),
'pla-poc-tracker:v1:app-meta': JSON.stringify({
activeGameId: 'legends-arceus',
profilesByGame: {
'legends-arceus': {
activeProfileId: 'default',
profiles: [{ id: 'default', name: 'Hisui Survey' }],
},
},
}),
'pla-poc-tracker:v1:legends-arceus': JSON.stringify({ caught: ['rowlet', 'bidoof', 'starly'], rl10: ['rowlet'] }),
});
const makeEl = () => ({
textContent: '',
classes: new Set(),
classList: {
add(c) {
this._owner.classes.add(c);
},
},
});
const orasEl = makeEl();
orasEl.classList._owner = orasEl;
const lumiEl = makeEl();
lumiEl.classList._owner = lumiEl;
const plaEl = makeEl();
plaEl.classList._owner = plaEl;
const fakeDoc = {
getElementById(id) {
if (id === 'oras-save-badge') return orasEl;
if (id === 'lumi-save-badge') return lumiEl;
if (id === 'pla-save-badge') return plaEl;
return null;
},
};
renderSavePills(fakeDoc, storage);
assert.equal(orasEl.textContent, 'Saved (Omega Ruby · Main OR): 3 caught');
assert.equal(orasEl.classes.has('has-save'), true);
assert.equal(lumiEl.textContent, 'Saved (Sinnoh Run): 2 caught');
assert.equal(lumiEl.classes.has('has-save'), true);
assert.equal(plaEl.textContent, 'Saved (Hisui Survey): 3 caught · 1 RL10');
assert.equal(plaEl.classes.has('has-save'), true);
});
test('Both trackers expose a relative Hub navigation link and valid Docker/Nginx packaging', async () => {
const orasStore = createOrasStore({ storage: makeMemoryStorage() });
const orasGame = getOrasGame('alpha-sapphire');
const orasProg = computeOrasProgress(orasGame, orasStore.getState().caught, orasStore.getState().ruleset);
const orasHdr = renderOrasHeader(orasGame, orasStore.getState(), orasProg);
assert.ok(orasHdr.includes('href="../"'));
assert.ok(orasHdr.includes('https://git.trevorstocks.ca/FaroeGames/oaktracker/issues'));
const lumiStore = createLumiStore({ storage: makeMemoryStorage() });
const lumiGame = getLumiGame();
const lumiProg = computeLumiProgress(lumiGame, lumiStore.getState().caught, lumiStore.getState().ruleset);
const lumiHdr = renderLumiHeader(lumiGame, lumiStore.getState(), lumiProg);
assert.ok(lumiHdr.includes('href="../"'));
assert.ok(lumiHdr.includes('https://git.trevorstocks.ca/FaroeGames/oaktracker/issues'));
const plaStore = createPlaStore({ storage: makeMemoryStorage() });
const plaGame = getPlaGame();
const plaProg = computePlaProgress(plaGame, plaStore.getState().caught, plaStore.getState().rl10, plaStore.getState().progressMode);
const plaHdr = renderPlaHeader(plaGame, plaStore.getState(), plaProg);
assert.ok(plaHdr.includes('href="../"'));
assert.ok(plaHdr.includes('https://git.trevorstocks.ca/FaroeGames/oaktracker/issues'));
const dockerfile = await fs.readFile(path.join(ROOT_DIR, 'Dockerfile'), 'utf8');
for (const match of dockerfile.matchAll(/^COPY\s+(\S+)\s+/gm)) {
const srcRel = match[1];
const stat = await fs.stat(path.join(ROOT_DIR, srcRel));
assert.ok(stat.isFile() || stat.isDirectory(), `Dockerfile COPY target missing: ${srcRel}`);
}
assert.ok(dockerfile.includes('oras/assets/'));
assert.ok(dockerfile.includes('luminescent-platinum/assets/'));
assert.ok(dockerfile.includes('legends-arceus/assets/'));
assert.ok(dockerfile.includes('legends-arceus/src/'));
const nginxConf = await fs.readFile(path.join(ROOT_DIR, 'docker/nginx.conf'), 'utf8');
assert.ok(dockerfile.includes('EXPOSE 28473'));
assert.ok(nginxConf.includes('listen 28473;'));
assert.ok(nginxConf.includes('absolute_redirect off;'));
assert.ok(nginxConf.includes('application/javascript mjs;'));
assert.ok(nginxConf.includes('location = /oras'));
assert.ok(nginxConf.includes('location = /luminescent-platinum'));
assert.ok(nginxConf.includes('location = /legends-arceus'));
assert.ok(nginxConf.includes('try_files /legends-arceus/assets/sprites/.ready.json'));
const giteaWorkflow = await fs.readFile(path.join(ROOT_DIR, '.gitea/workflows/docker-publish.yml'), 'utf8');
assert.ok(giteaWorkflow.includes('git.trevorstocks.ca/faroegames/oaktracker'));
assert.ok(giteaWorkflow.includes('secrets.GITEA_TOKEN'));
const updateScript = await fs.readFile(path.join(ROOT_DIR, 'scripts/unraid-git-update.sh'), 'utf8');
assert.ok(updateScript.includes('docker compose up -d --build'));
const giteaCheckScript = await fs.readFile(path.join(ROOT_DIR, 'scripts/check-gitea.mjs'), 'utf8');
assert.ok(giteaCheckScript.includes('api/v1/repos'));
const bugTpl = await fs.readFile(path.join(ROOT_DIR, '.gitea/ISSUE_TEMPLATE/bug_report.md'), 'utf8');
assert.ok(bugTpl.includes('Bug Report'));
});