import test from 'node:test'; import assert from 'node:assert/strict'; import http from 'node:http'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { SPECIES_LIST, SPECIES_BY_ID } from '../src/data/species.js'; import { getPokemonMoveset } from '../src/data/movesets.js'; import { getGame } from '../src/data/games/index.js'; import { computeGameProgress, createTrackerStore, indexGameSpecies, } from '../src/state/tracker-store.js'; import { getExternalLinksForSpecies, renderExternalLinksControl } from '../src/ui/external-links.js'; import { renderRoutesView } from '../src/ui/routes-view.js'; import { renderHeader } from '../src/ui/header.js'; import { renderPokedexView } from '../src/ui/pokedex-view.js'; import { renderSpeciesModal } from '../src/ui/modal.js'; import { getPokemonSpriteUrls } from '../src/ui/sprites.js'; import { createStaticServer } from '../server.mjs'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const ROOT_DIR = path.resolve(__dirname, '..'); function makeMemoryStorage() { const map = new Map(); return { getItem(k) { return map.has(k) ? map.get(k) : null; }, setItem(k, v) { map.set(k, String(v)); }, removeItem(k) { map.delete(k); }, keys() { return [...map.keys()]; }, }; } test('Pokédex totals equal exact 547 default and 550 with Special Forms enabled', () => { const baseSpecies = SPECIES_LIST.filter((s) => !s.isSpecialForm); const specialSpecies = SPECIES_LIST.filter((s) => s.isSpecialForm); assert.equal(baseSpecies.length, 547); assert.equal(specialSpecies.length, 3); assert.equal(SPECIES_LIST.length, 550); const game = getGame('luminescent-platinum'); const progBase = computeGameProgress(game, new Set(), 'solo', { includeSpecialForms: false }); assert.equal(progBase.totalObtainable, 547); assert.equal(progBase.sections.at(-1).cumulativeTotal, 547); assert.equal(progBase.sections.length, 10); const progFull = computeGameProgress(game, new Set(), 'solo', { includeSpecialForms: true }); assert.equal(progFull.totalObtainable, 550); assert.equal(progFull.sections.at(-1).cumulativeTotal, 550); // Marking all 547 caught gives 100% completion const allBaseCaught = new Set(baseSpecies.map((s) => s.id)); const doneBase = computeGameProgress(game, allBaseCaught, 'solo', { includeSpecialForms: false }); assert.equal(doneBase.totalCaught, 547); assert.equal(doneBase.percent, 100); }); test('Level caps and item/story gates match Luminescent Platinum v2.1 rules', () => { const game = getGame('luminescent-platinum'); const { earliestBySpecies } = indexGameSpecies(game, { includeSpecialForms: true }); const secOf = (id) => earliestBySpecies.get(id)?.sectionId; // Section 1: Roark Lv. 16 cap assert.equal(secOf('kadabra'), 'pre-badge-1'); assert.equal(secOf('ivysaur'), 'pre-badge-1'); assert.equal(secOf('mewth-alola') || secOf('meowth-alola'), 'pre-badge-1'); assert.equal(secOf('persian-alola'), 'pre-badge-1'); // Friendship evo! // Section 2: Gardenia Lv. 26 cap (Floaroma/Eterna/Windworks/Coronet 211/Rt 216 early + Mining stones) assert.equal(secOf('lucario'), 'pre-badge-2'); // Aura Sphere Lv. 26 assert.equal(secOf('mr-mime'), 'pre-badge-2'); // Mime Jr. Route 205S + Mimic Lv. 18 assert.equal(secOf('stitched-gengar'), 'pre-badge-2'); // Old Chateau Static assert.equal(secOf('leafeon'), 'pre-badge-2'); assert.equal(secOf('glaceon'), 'pre-badge-2'); // Section 3: Fantina Lv. 33 cap (Cut, Wayward Cave, Magnetic Field, High Beauty) assert.equal(secOf('magnezone'), 'pre-badge-3'); assert.equal(secOf('milotic'), 'pre-badge-3'); // High Beauty Hearthome assert.equal(secOf('mismagius'), 'pre-badge-3'); // Dusk Stone Wayward Cave assert.equal(secOf('steelix'), 'pre-badge-3'); // Metal Coat Route 207 // Section 4: Maylene Lv. 39 cap (Bonsly Rt 209, Lv. 36 trade replacements, Veilstone Dept Store, Nursery) assert.equal(secOf('sudowoodo'), 'pre-badge-4'); // Bonsly first wild spawn Route 209 assert.equal(secOf('alakazam'), 'pre-badge-4'); assert.equal(secOf('machamp'), 'pre-badge-4'); assert.equal(secOf('golem'), 'pre-badge-4'); assert.equal(secOf('manaphy'), 'pre-badge-4'); assert.equal(secOf('phione'), 'pre-badge-4'); // Manaphy + Ditto Solaceon Nursery assert.equal(secOf('weavile'), 'pre-badge-4'); // Razor Claw Rt 215 assert.equal(secOf('gliscor'), 'pre-badge-4'); // Razor Fang Rt 215 assert.equal(secOf('kleavor'), 'pre-badge-4'); // Scyther Rt 209 + King's Rock // Section 5: Wake Lv. 44 cap (Move Reminder Ancient Power, Jirachi Lv. 42) assert.equal(secOf('mamoswine'), 'pre-badge-5'); assert.equal(secOf('jirachi'), 'pre-badge-5'); // Section 6: Byron Lv. 53 cap (Surf, Protector Iron Island, Quests Mew/Celebi/Crystal Onix/Spiky Pichu) assert.equal(secOf('rhyperior'), 'pre-badge-6'); assert.equal(secOf('ursaluna'), 'pre-badge-6'); // Lv. 48 Night assert.equal(secOf('mew'), 'pre-badge-6'); assert.equal(secOf('celebi'), 'pre-badge-6'); assert.equal(secOf('crystal-onix'), 'pre-badge-6'); assert.equal(secOf('spiky-eared-pichu'), 'pre-badge-6'); // Section 7: Candice Lv. 56 cap (Super Rod & Snowpoint Held-Trade Vendor) assert.equal(secOf('lapras'), 'pre-badge-7'); assert.equal(secOf('dragonite'), 'pre-badge-7'); // Lv. 55 assert.equal(secOf('porygon-z'), 'pre-badge-7'); assert.equal(secOf('electivire'), 'pre-badge-7'); // Section 8: Volkner Lv. 62 cap (Post-Distortion World Rowan Quests Lv. 60) assert.equal(secOf('uxie'), 'pre-badge-8'); assert.equal(secOf('articuno'), 'pre-badge-8'); assert.equal(secOf('raikou'), 'pre-badge-8'); // Section 9: Cynthia Lv. 78 cap (Waterfall Victory Road Moltres Lv. 60) assert.equal(secOf('moltres'), 'pre-champion'); // Section 10: Post-Game assert.equal(secOf('heatran'), 'post-game'); assert.equal(secOf('giratina'), 'post-game'); assert.equal(secOf('arceus'), 'post-game'); // Every Pre-Badge Evolution Checklist obeys its section's Gym Leader level cap for (const sec of game.sections) { const evoArea = sec.areas.find((a) => a.id.startsWith('evolutions-')); if (!evoArea) continue; for (const grp of evoArea.groups) { for (const entry of grp.entries) { const m = String(entry.levels || '').match(/Lv\.?\s*(\d+)|Level\s+(\d+)/i); if (m) { const lv = Number(m[1] || m[2]); assert.ok( lv <= sec.levelCap, `${entry.speciesId} in ${sec.id} requires Lv.${lv} > cap ${sec.levelCap}`, ); } } } } }); test('Jubilife Gift Egg (Only 1) picks early bonus without double counting or locking later spawns', () => { const storage = makeMemoryStorage(); const store = createTrackerStore({ storage }); store.toggleJubilifeEggPick('elekid'); let st = store.getState(); assert.equal(st.jubilifeEggPick, 'elekid'); assert.equal(st.caught.has('elekid'), true); // Total obtainable remains strictly 547 const prog = computeGameProgress(store.getGame(), st.caught, 'solo', { includeSpecialForms: false }); assert.equal(prog.totalObtainable, 547); // Other babies like magby and togepi remain catchable/checkable in later routes! store.toggleCaught('magby', true); assert.equal(store.getState().caught.has('magby'), true); // Toggling Jubilife egg pick again clears pick label store.toggleJubilifeEggPick('elekid'); assert.equal(store.getState().jubilifeEggPick, null); }); test('Every species has a valid Luminescent Movedex, forms are distinct, and Crystal Onix has Rock/Ice', () => { const empty = []; for (const sp of SPECIES_LIST) { const ms = getPokemonMoveset(sp); const total = ms.levelUp.length + ms.machine.length + ms.tutor.length + ms.egg.length; if (total === 0) empty.push(sp.id); } assert.deepEqual(empty, []); const crystalOnix = SPECIES_BY_ID['crystal-onix']; assert.deepEqual(crystalOnix.types, ['Rock', 'Ice']); assert.equal(crystalOnix.spriteFile, 'pm0095_01_00_00_L.webp'); assert.equal(crystalOnix.shinySpriteFile, 'pm0095_01_01_L.webp'); const charizardMoves = getPokemonMoveset('charizard'); assert.ok(charizardMoves.levelUp.some((m) => m.level === 0 && m.name === 'Air Slash')); assert.ok(charizardMoves.machine.some((m) => /^TM\d{2}$/.test(m.machine))); // Distinct regional moveset check: Raichu vs Raichu-A const rBase = getPokemonMoveset('raichu'); const rAlola = getPokemonMoveset('raichu-alola'); assert.ok(rAlola.levelUp.some((m) => /Psychic/i.test(m.name))); assert.notEqual( JSON.stringify(rBase.levelUp.slice(0, 5)), JSON.stringify(rAlola.levelUp.slice(0, 5)), ); }); test('Routes trainer drawers, Boss [Team 1-4] variants, Starter filtering, and Pokedex/Movedex render cleanly', () => { const storage = makeMemoryStorage(); const store = createTrackerStore({ storage }); const game = store.getGame(); // Route 201 has Barry starter variants; Oreburgh City has Roark Team 1..4 variants const sec1 = game.sections[0]; const rt201 = sec1.areas.find((a) => a.name.includes('Route 201')); const oreburgh = sec1.areas.find((a) => a.name.includes('Oreburgh City')); assert.ok(rt201?.trainers?.length > 0); assert.ok(oreburgh?.trainers?.some((t) => t.teamVariants && Object.keys(t.teamVariants).length === 4)); // Expand Oreburgh trainers and switch team variant to Team 3 store.toggleAreaTrainersExpanded(oreburgh.id); store.setSelectedTeamVariant('Team 3'); store.setChosenStarter('chimchar'); const html = renderRoutesView( game, store.getState(), computeGameProgress(game, store.getState().caught, 'solo'), ); assert.ok(html.includes('Gym Leader Roark')); assert.ok(html.includes('Team 3:')); assert.ok(!html.includes('Team 2:')); assert.ok(html.includes('Trainer Battles') || html.includes('Trainer & Boss Battles')); // Pokedex table renders Search/Links/Movedex const dexHtml = renderPokedexView(store, store.getState()); assert.ok(dexHtml.includes('Bulbasaur')); assert.ok(dexHtml.includes('Tinkaton')); store.setSelectedSpeciesId('tinkaton'); store.toggleExternalMenu('tinkaton', 'modal'); const modalHtml = renderSpeciesModal(game, store.getState()); assert.ok(modalHtml.includes('Luminescent Platinum Movedex')); assert.ok(modalHtml.includes('https://luminescent.team/pokedex/tinkaton')); assert.ok(modalHtml.includes('https://www.serebii.net/pokedex-sv/tinkaton/')); }); test('External links and sprites resolve cleanly for standard, regional, and special form Pokémon', () => { const alolaVulpix = SPECIES_BY_ID['vulpix-alola']; const links = getExternalLinksForSpecies(alolaVulpix); assert.equal(links[0].url, 'https://luminescent.team/pokedex/alola-vulpix'); assert.equal(links[1].url, 'https://www.serebii.net/pokedex-sv/vulpix/'); assert.equal(links[2].url, 'https://bulbapedia.bulbagarden.net/wiki/Vulpix_(Pok%C3%A9mon)'); const spUrl = getPokemonSpriteUrls(SPECIES_BY_ID['spiky-eared-pichu'], { shiny: true }); assert.ok(spUrl.primary.endsWith('/shinypkm/pm0172_01_11_L.webp')); const rotomUrl = getPokemonSpriteUrls(SPECIES_BY_ID['rotom'], { shiny: true }); assert.ok(rotomUrl.primary.endsWith('/shinypkm/pm0479_00_21_L.webp')); const extHtml = renderExternalLinksControl(alolaVulpix, { openExternalMenu: { speciesId: 'vulpix-alola', context: 'pokedex' } }, 'pokedex'); assert.ok(extHtml.includes('Team Luminescent Pokédex')); }); test('Save profiles, isolated storage prefix, and JSON export/import round-trip accurately', () => { const storage = makeMemoryStorage(); const store = createTrackerStore({ storage }); store.toggleCaught('bulbasaur', true); store.toggleJubilifeEggPick('magby'); store.setIncludeSpecialForms(true); const p2 = store.createProfile('Nuzlocke Run'); assert.equal(store.getState().caught.size, 0); store.toggleCaught('piplup', true); store.switchProfile('default'); assert.equal(store.getState().caught.has('bulbasaur'), true); assert.equal(store.getState().caught.has('piplup'), false); assert.equal(store.getState().includeSpecialForms, true); const exported = store.exportJson(); assert.ok(storage.keys().every((k) => k.startsWith('lumi-poc-tracker:v1:'))); store.switchProfile(p2.id); store.importJson(exported); assert.equal(store.getState().caught.has('bulbasaur'), true); assert.equal(store.getState().jubilifeEggPick, 'magby'); store.renameProfile(p2.id, 'Main Lumi'); assert.equal(store.getActiveProfile().name, 'Main Lumi'); assert.equal(store.deleteProfile(p2.id), true); assert.equal(store.deleteProfile('default'), false); }); test('Static HTTP server serves Luminescent app assets and rejects directory traversal', async () => { const server = createStaticServer(ROOT_DIR); await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); const { port } = server.address(); try { const htmlRes = await fetch(`http://127.0.0.1:${port}/`); assert.equal(htmlRes.status, 200); const html = await htmlRes.text(); assert.ok(html.includes('Luminescent Platinum')); const statusRes = await fetch(`http://127.0.0.1:${port}/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: '/../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('Method levels never leak Surfing labels onto Old Rod/Gifts and Old Rod backtracks order after Jubilife Gatehouse', () => { const game = getGame('luminescent-platinum'); const sec1 = game.sections[0]; const areaIds = sec1.areas.map((a) => a.id); // Twinleaf initial card has only Gift (Eevee Lv. 5), no premature Old Rod and no (Surfing) const twinleafInit = sec1.areas.find((a) => a.id === 'area-1'); assert.ok(twinleafInit); assert.equal(twinleafInit.groups.length, 1); assert.equal(twinleafInit.groups[0].method, 'Gift'); assert.equal(twinleafInit.groups[0].entries[0].speciesId, 'eevee'); assert.equal(twinleafInit.groups[0].entries[0].levels, 'Lv. 5'); assert.ok(!/Surfing/i.test(twinleafInit.sublabel)); // Old Rod backtracks (Twinleaf, Lake Verity, Route 219) come chronologically after Jubilife City & Route 218 Gatehouse const jubilifeIdx = areaIds.indexOf('area-7'); const route218Idx = areaIds.indexOf('area-8'); const twinleafRodIdx = areaIds.indexOf('area-1-oldrod'); const verityRodIdx = areaIds.indexOf('area-3-oldrod'); const route219Idx = areaIds.indexOf('area-5'); assert.ok(jubilifeIdx > -1 && route218Idx > jubilifeIdx); assert.ok(twinleafRodIdx > route218Idx); assert.ok(verityRodIdx > route218Idx); assert.ok(route219Idx > route218Idx); assert.equal(sec1.areas[twinleafRodIdx].groups[0].entries[0].levels, 'Lv. 10'); // Across the entire game, no non-Surf group or card without Surf ever displays "(Surfing)" for (const sec of game.sections) { for (const area of sec.areas) { const hasSurf = area.groups.some((g) => g.method === 'Surf' || g.method === 'Any Incense Surf'); if (!hasSurf) { assert.ok(!/Surfing/i.test(area.sublabel), `Sublabel leaked Surfing on ${area.name}`); } for (const g of area.groups) { for (const e of g.entries) { assert.ok(Boolean(e.levels), `Empty levels on ${area.name} -> ${g.method} -> ${e.speciesId}`); if (g.method !== 'Surf' && g.method !== 'Any Incense Surf') { assert.ok(!/Surfing/i.test(e.levels), `Entry ${e.speciesId} (${g.method} @ ${area.name}) leaked Surfing: ${e.levels}`); } } } } } }); test('Route 201 includes initial Sinnoh Starter options synced with store.pickStarter and UI rendering', () => { const storage = makeMemoryStorage(); const store = createTrackerStore({ storage }); const game = store.getGame(); const route201 = game.sections[0].areas.find((a) => a.id === 'area-2'); assert.ok(route201); const starterGroup = route201.groups.find((g) => g.method === 'Starter'); assert.ok(starterGroup); assert.deepEqual( starterGroup.entries.map((e) => e.speciesId), ['turtwig', 'chimchar', 'piplup'], ); assert.ok(starterGroup.entries.every((e) => e.levels === 'Lv. 5')); store.pickStarter('chimchar'); assert.equal(store.getState().chosenStarter, 'chimchar'); assert.equal(store.getState().caught.has('chimchar'), true); // Remaining starters stay claimable in Sandgem Town and total obtainable stays 547 const prog = computeGameProgress(game, store.getState().caught, 'solo', { includeSpecialForms: false }); assert.equal(prog.totalObtainable, 547); const html = renderRoutesView(game, store.getState(), prog); assert.ok(html.includes('data-pick-starter="chimchar"')); assert.ok(html.includes('Starter: Chimchar')); assert.ok(html.includes('Starter Picked')); assert.ok(html.includes('Other Picked')); }); test('Incense Burner toggle persists per profile and dynamically updates overwritten Grass & Surf rates', () => { const storage = makeMemoryStorage(); const store = createTrackerStore({ storage }); const game = store.getGame(); // Off by default: normal rates shown on Morning/Surf, Any Incense shows 0% (ON: 20%) assert.equal(store.getState().incenseActive, false); const prog = computeGameProgress(game, store.getState().caught, 'solo', { includeSpecialForms: false }); let htmlOff = renderRoutesView(game, store.getState(), prog); assert.ok(htmlOff.includes('0% until ON')); assert.ok(htmlOff.includes('data-toggle-incense')); assert.ok(htmlOff.includes('section-incense-toggle')); assert.ok(!htmlOff.includes('Replaced by Incense')); // Toggle ON: Any Incense becomes active and Grass/Surf slot shifts + inline checkboxes update store.setIncenseActive(true); assert.equal(store.getState().incenseActive, true); const hdrHtml = renderHeader(game, store.getState(), prog); assert.ok(hdrHtml.includes('id="incense-burner-toggle"')); assert.ok(hdrHtml.includes('Incense Burner (ON)')); let htmlOn = renderRoutesView(game, store.getState(), prog); assert.ok(htmlOn.includes('Spawning')); assert.ok(htmlOn.includes('Slot Rates Adjusted')); assert.ok(htmlOn.includes('Incense Burner ON')); assert.ok(htmlOn.includes('was 30%')); // Jump to Sec 6 (Canalave Surf) where Shellos 30% is completely overwritten to 0% store.setActiveSectionId('pre-badge-6'); const sec6Html = renderRoutesView(game, store.getState(), prog); assert.ok(sec6Html.includes('Replaced by Incense')); assert.ok(sec6Html.includes('was 30%')); // Persists across JSON backup round-trip const backup = store.exportJson(); store.setIncenseActive(false); assert.equal(store.getState().incenseActive, false); store.importJson(backup); assert.equal(store.getState().incenseActive, true); });