From 497b5d9ae67e9e31bef7f347cee285275716c56c Mon Sep 17 00:00:00 2001 From: saphid <4596216+saphid@users.noreply.github.com> Date: Thu, 1 Oct 2026 21:21:34 +1000 Subject: [PATCH] Don't launch from the hero's Install, and check page names with V8 From the independent review of this PR: - After installing the featured app, the hero's Install on the Frame took the installed branch and launched it on the headset. It now opens the details, whose button says Open in Steam, without acting. - The duplicate-name test matched declarations at column zero only, so an indented second loadPanels (the bug it was written for) passed, and so did classes, destructuring and later declarators. It now compiles both inline scripts as one strict-mode block, where V8 rejects any name declared twice in the shared scope, with fixtures for each case and for same-named helpers in different functions (which are fine). - A card's "Won't run" overstated the check's "Might not work"; it now says May not run. - Removed styles and the source-filter state that nothing used any more. Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/test_page_scripts.py | 41 ++++++++++++++++++++++++++++++++------ ui/index.html | 20 +++++++++---------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/tests/test_page_scripts.py b/tests/test_page_scripts.py index 35ba048..f04468c 100644 --- a/tests/test_page_scripts.py +++ b/tests/test_page_scripts.py @@ -1,21 +1,50 @@ """The page's inline scripts share one global scope, so a second top-level function or variable with a name already used replaces the first everywhere, silently.""" -import collections +import json import pathlib import re +import shutil +import subprocess import unittest ROOT = pathlib.Path(__file__).resolve().parents[1] +# Compiles the scripts as one strict-mode block. There, functions are block scoped like let +# and const, so V8 itself rejects a name declared twice in the shared scope (however it's +# indented or declared: function, class, let, const, destructuring), while helpers with the +# same name inside different functions stay legal. +CHECK = r''' +const vm = require('vm'); +const scripts = JSON.parse(require('fs').readFileSync(0, 'utf8')); +try { new vm.Script('"use strict"; {\n' + scripts.join('\n;\n') + '\n}'); console.log('ok'); } +catch (e) { console.log(e.message); } +''' + +def check(scripts): + r = subprocess.run(['node', '-e', CHECK], input=json.dumps(scripts), capture_output=True, text=True) + return r.stdout.strip() or r.stderr.strip() + + +@unittest.skipUnless(shutil.which('node'), 'Node parses the page scripts') class PageScripts(unittest.TestCase): def test_no_top_level_name_is_declared_twice(self): page = (ROOT / 'ui/index.html').read_text(encoding='utf-8') - names = collections.Counter() - for js in re.findall(r'', page, re.S): - for m in re.finditer(r'^(?:async\s+)?function\s+(\w+)|^(?:const|let|var)\s+(\w+)\s*=', js, re.M): - names[m.group(1) or m.group(2)] += 1 - self.assertEqual({k: n for k, n in names.items() if n > 1}, {}) + self.assertEqual(check(re.findall(r'', page, re.S)), 'ok') + + def test_the_check_finds_what_it_should(self): + twice = { + 'indented function': ['function loadPanels() {}', ' async function loadPanels() {}'], + 'class': ['class Panel {}', 'class Panel {}'], + 'destructured': ['const { a, b } = {};', 'let [b] = [];'], + 'later declarator': ['let x = 1;', 'const y = 2, x = 3;'], + 'function and const': ['function f() {}', 'const f = 1;'], + } + for what, scripts in twice.items(): + with self.subTest(what): + self.assertIn('already been declared', check(scripts)) + helpers = ['function a() { function help() {} }', 'function b() { const help = 1; }'] + self.assertEqual(check(helpers), 'ok') if __name__ == '__main__': diff --git a/ui/index.html b/ui/index.html index 69e61ed..5404c6c 100644 --- a/ui/index.html +++ b/ui/index.html @@ -575,7 +575,6 @@ .store-chips { display:flex; flex-wrap:wrap; gap:7px; } .store-chips button { border-radius:20px; font-size:12px; height:34px; padding:0 14px; background:#ffffff07; color:#b5c0cb; border:1px solid #ffffff0c; } .store-chips button[aria-pressed=true] { background:#235779; border-color:#5287a5; color:white; } - .store-source-select select { max-width:180px; padding:8px 26px 8px 10px; font:inherit; font-size:12px; border:0; border-radius:5px; color:var(--text); background:#1d2b3b; } .store-notice { color:#a8b5c2; font-size:12px; margin:12px 0; } .store-heading a, .cross-link a { color:var(--link); } .cross-link { margin:-6px 0 12px; } @@ -619,10 +618,8 @@ .store-card-title strong { font-size:15px; color:var(--bright); text-overflow:ellipsis; overflow:hidden; white-space:nowrap; } .store-summary { display:block; color:#a8b5c2; font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; } .store-card-foot { display:flex; justify-content:space-between; align-items:center; gap:6px; margin-top:16px; font-size:11px; color:#a8b5c2; } - .store-card-foot b { color:#dbeecf; font-weight:500; } .store-badges { display:flex; flex-wrap:wrap; gap:7px; } .store-badge { font-size:11px; color:#b7d8ec; background:#6ec9ff14; padding:4px 9px; border-radius:5px; } - .store-badge.works { color:#b8e2ab; background:#70bb5418; } .store-empty { display:flex; flex-direction:column; align-items:center; text-align:center; padding:58px 20px 70px; } .store-empty svg { width:110px; height:90px; color:var(--link); margin-bottom:14px; } .store-empty h2 { font-size:23px; color:var(--bright); margin:8px 0; text-transform:none; letter-spacing:0; } @@ -3189,7 +3186,7 @@ document.body.addEventListener("click", async e => { loadOwned(); // ---- Discover apps ---- -const sourceState = { vr: null, installable: false, source: "", apps: [], sources: [], request: 0, detail: null, detailRequest: 0, jobs: new Map() }; +const sourceState = { vr: null, installable: false, apps: [], sources: [], request: 0, detail: null, detailRequest: 0, jobs: new Map() }; const storeName = s => String(s || "").replace(/ \(demo\)$/i, ""); const storeHue = name => [...String(name)].reduce((n, c) => (n * 31 + c.charCodeAt(0)) >>> 0, 7) % 360; const storeInitial = name => [...String(name || "?")][0].toUpperCase(); // the small icon's stand-in @@ -3230,7 +3227,7 @@ async function loadSources() { } catch (e) { $("sourceError").textContent = e.message; } } // Will it run? Short enough for a card; the full sentence is in its tooltip and the details. -const RUNS = { works: ["✓ Works on the Frame", "works"], ready: ["Should install", "ready"], unknown: ["Not checked yet", "unknown"], blocked: ["Won't run", "blocked"] }; +const RUNS = { works: ["✓ Works on the Frame", "works"], ready: ["Should install", "ready"], unknown: ["Not checked yet", "unknown"], blocked: ["May not run", "blocked"] }; function storeRuns(o) { const [text, cls] = RUNS[o.verdict?.tone] || RUNS.unknown; return `${text}`; @@ -3245,7 +3242,7 @@ function storeEmpty(message) { return `

${message ? "Couldn't load apps" : "No apps found"}

${message ? esc(message) : "Try another name, or clear the filters."}

`; } function renderStore() { - const apps=sourceState.apps, browsing=!$("sourceQ").value.trim() && sourceState.vr === null && !sourceState.installable && !sourceState.source; + const apps=sourceState.apps, browsing=!$("sourceQ").value.trim() && sourceState.vr === null && !sourceState.installable; $("searchCount").textContent = browsing ? "" : `${apps.length} ${apps.length===1 ? "app" : "apps"}${$("sourceQ").value.trim() ? ` for “${$("sourceQ").value.trim()}”` : ""}`; if (!apps.length) { $("searchGrid").innerHTML=storeEmpty(); return; } if (!browsing) { $("searchGrid").innerHTML=`
${apps.map(storeCard).join("")}
`; return; } @@ -3272,7 +3269,7 @@ async function searchSources(quiet) { const request=++sourceState.request; $("searchGrid").setAttribute("aria-busy","true"); if(!quiet)$("searchGrid").innerHTML=`
${Array.from({length:8},()=>'').join("")}
`; - const params=new URLSearchParams({q:$("sourceQ").value,source:sourceState.source,installable:String(sourceState.installable)}); + const params=new URLSearchParams({q:$("sourceQ").value,installable:String(sourceState.installable)}); if(sourceState.vr!==null)params.set("vr",String(sourceState.vr)); try { const result=await api("/api/search?"+params);if(request!==sourceState.request)return; @@ -3316,7 +3313,10 @@ async function openStoreApp(index, install=false) { const app=sourceState.apps[index];if(!app)return; sourceState.detail={app:{...app,offers:app.offers.map(o=>({...o}))},choice:0}; renderAppDetail();if(!$("appDetail").open)$("appDetail").showModal();$("appDetail").scrollTop=0; - if(install)installStoreApp(); // the hero's Install: the details show its progress + // The hero's Install: the details show its progress. Already installed or installing: just + // the details, whose button says what it does (Open in Steam would launch it). + const o=currentOffer(); + if(install&&!sourceState.jobs.has(`${o.source}:${o.id}`))installStoreApp(); await loadOfferDetails(); } async function loadOfferDetails() { @@ -3347,7 +3347,7 @@ async function installStoreApp() { } async function changeSource(body) { $("sourceError").textContent="Saving your sources…"; - try { const result=await api('/api/sources',body);$("sourceError").textContent=result.message;sourceState.source='';await loadSources();await searchSources(); } + try { const result=await api('/api/sources',body);$("sourceError").textContent=result.message;await loadSources();await searchSources(); } catch(e) { $("sourceError").textContent=e.message;await loadSources(); } } let storeSearchTimer; @@ -3365,7 +3365,7 @@ async function addSource(body) { let error=""; const result=await runJob('Add repository',`repo:${body.url}`,()=>api('/api/sources',body).catch(e=>{error=e.message;throw e;}),j=>{error=j.error||"";}); $("sourceError").textContent=result ? result.message : error || "We couldn't add that repository."; - if(result){$("addSource").reset();sourceState.source='';await loadSources();await searchSources();} + if(result){$("addSource").reset();await loadSources();await searchSources();} } $("addSource").onsubmit=e=>{e.preventDefault();const f=new FormData(e.target);addSource({action:'add',url:f.get('url'),fingerprint:f.get('fingerprint')});}; document.querySelectorAll('[data-close]').forEach(b=>b.onclick=()=>$(b.dataset.close).close());