Unified Professor Oak Tracker hub (ORAS and Luminescent Platinum) with Docker and Unraid setup

This commit is contained in:
FaroeGames committed 2026-11-17 15:14:41 -07:00
commit f86f5d8bef
61 files changed
+58805

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
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';
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/"'));
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']) {
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(typeof statusJson.hasLocalSprites, 'boolean');
}
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'] }),
});
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 fakeDoc = {
getElementById(id) {
if (id === 'oras-save-badge') return orasEl;
if (id === 'lumi-save-badge') return lumiEl;
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);
});
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="../"'));
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="../"'));
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}`);
}
const nginxConf = await fs.readFile(path.join(ROOT_DIR, 'docker/nginx.conf'), 'utf8');
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'));
});