From 7ae3505288600cb1ee01cdee0a39aedebabdb73b Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Sat, 3 Oct 2026 10:09:34 -0700 Subject: [PATCH 1/3] Select fresh site assets consistently across releases --- .github/workflows/public-shop.yml | 4 ++ docs/site/app.js | 8 +-- docs/site/brand.css | 2 +- docs/site/cite.html | 4 +- docs/site/cite.mjs | 2 +- docs/site/conditionals.mjs | 2 +- docs/site/core.mjs | 2 +- docs/site/dependencies.html | 10 +-- docs/site/dependencies.mjs | 6 +- docs/site/explore-models.mjs | 2 +- docs/site/explore.html | 10 +-- docs/site/explore.mjs | 2 +- docs/site/formal.html | 6 +- docs/site/index.html | 4 +- docs/site/measure.html | 10 +-- docs/site/measure.mjs | 2 +- docs/site/museum.html | 6 +- docs/site/museum.mjs | 6 +- docs/site/reproduce.html | 2 +- docs/site/research.html | 2 +- docs/site/workspace.html | 6 +- tests/test_brand_identity.mjs | 4 +- tests/test_dependency_viewer.mjs | 2 +- tests/test_public_shop_browser_contract.py | 4 +- tests/test_public_shop_frontend.mjs | 5 ++ tests/test_site_asset_release.py | 83 ++++++++++++++++++++++ tests/test_workspace_navigation.mjs | 12 +++- tools/public_shop_browser_check.py | 56 ++++++++++++++- tools/site_asset_release.py | 76 ++++++++++++++++++++ 29 files changed, 283 insertions(+), 57 deletions(-) create mode 100644 tests/test_site_asset_release.py create mode 100644 tools/site_asset_release.py diff --git a/.github/workflows/public-shop.yml b/.github/workflows/public-shop.yml index 6f390a481..d62058712 100644 --- a/.github/workflows/public-shop.yml +++ b/.github/workflows/public-shop.yml @@ -18,6 +18,10 @@ jobs: fetch-depth: 0 - name: Status-export negative controls run: python3 -B -m unittest discover -s tests -p test_public_shop_data.py + - name: Reproducible entry and transitive asset release + run: | + python3 -B tools/site_asset_release.py --check + python3 -B -m unittest tests.test_site_asset_release - name: Browser data-validation controls run: node --test tests/test_public_shop_frontend.mjs tests/test_explore_models.mjs tests/test_reader_navigation.mjs tests/test_source_reference.mjs tests/test_measurement_model.mjs tests/test_dependency_viewer.mjs tests/test_museum_frontend.mjs tests/test_workspace_navigation.mjs - name: Reader navigation and local asset routes diff --git a/docs/site/app.js b/docs/site/app.js index b264b1be2..122b9e218 100644 --- a/docs/site/app.js +++ b/docs/site/app.js @@ -1,6 +1,6 @@ -import {verifiedJSON, verifiedBytes, validateStatus, validateCoefficient, safeSourceURL, hex40, hex64} from './core.mjs'; -import {connectCatalogQuery} from './catalog-query.mjs'; -import {prepareWorkspaceFragment} from './workspace-fragment.mjs'; +import {verifiedJSON, verifiedBytes, validateStatus, validateCoefficient, safeSourceURL, hex40, hex64} from './core.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; +import {connectCatalogQuery} from './catalog-query.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; +import {prepareWorkspaceFragment} from './workspace-fragment.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; const finishFragment=prepareWorkspaceFragment(); const el=id=>document.getElementById(id); const node=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;}; @@ -110,7 +110,7 @@ async function queryIdentity(config) { el('query-note').append(node('code','python -B -S verify_portable_stubs.py --check-math-tip'),node('span','. The command checks file bytes, not commit equality. This page reads only the pinned bundle and performs no live tip check.')); } try { - const response=await fetch('config.json',{credentials:'omit'});if(!response.ok)throw new Error('Shop config unavailable');const config=await response.json(); + const response=await fetch('config.json',{credentials:'omit',cache:'no-store'});if(!response.ok)throw new Error('Shop config unavailable');const config=await response.json(); const jobs=[['status-note',()=>board(config)],['coefficient-state',()=>coefficients(config)],['inventory-state',()=>inventory(config)],['custody-note',()=>custody(config)],['query-note',()=>queryIdentity(config)]]; await Promise.allSettled(jobs.map(async([id,job])=>{try{await job();}catch(e){error(id,e);}})); } catch(e) {['status-note','coefficient-state','inventory-state','custody-note','query-note'].forEach(id=>error(id,e));} diff --git a/docs/site/brand.css b/docs/site/brand.css index 1fea8e0ae..0e63a1ee4 100644 --- a/docs/site/brand.css +++ b/docs/site/brand.css @@ -58,7 +58,7 @@ body > header { color: var(--ul-text); font-weight: 750; letter-spacing: .13em; position: relative; padding-left: 57px; min-height: 44px; line-height: 1.65; } -.brand::before { content: ""; position: absolute; left: 0; top: 1px; width: 42px; height: 42px; background: url("brand/mark.svg") center/contain no-repeat; } +.brand::before { content: ""; position: absolute; left: 0; top: 1px; width: 42px; height: 42px; background: url("brand/mark.svg?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3") center/contain no-repeat; } .brand span { color: var(--ul-muted); font-size: 10px; letter-spacing: .18em; } nav { gap: 12px 24px; flex-wrap: wrap; } nav a { color: var(--ul-text); min-height: 36px; display: inline-flex; align-items: center; font-size: 13px; } diff --git a/docs/site/cite.html b/docs/site/cite.html index 66b80cfa0..89cf458ed 100644 --- a/docs/site/cite.html +++ b/docs/site/cite.html @@ -4,8 +4,8 @@ Cite · Universal Law - - + +
UNIVERSAL LAW MATHEMATICS IN THE OPEN
diff --git a/docs/site/cite.mjs b/docs/site/cite.mjs index 7a9c5a9e0..fa1518eb4 100644 --- a/docs/site/cite.mjs +++ b/docs/site/cite.mjs @@ -1,4 +1,4 @@ -import {wireReferenceForm} from './source-reference.mjs'; +import {wireReferenceForm} from './source-reference.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; const byId = id => document.getElementById(id); wireReferenceForm({form:byId('reference-form'), repository:byId('reference-repository'), commit:byId('reference-commit'), path:byId('reference-path'), output:byId('reference-output'), link:byId('reference-link'), status:byId('reference-status')}); byId('reference-builder').hidden = false; diff --git a/docs/site/conditionals.mjs b/docs/site/conditionals.mjs index 0c52dcbdc..f29342021 100644 --- a/docs/site/conditionals.mjs +++ b/docs/site/conditionals.mjs @@ -93,7 +93,7 @@ export function renderProjection(document,host,data,source){ el(document,'p','Generated from verified source bytes. This graph is not formal verification, a proof review, or a scientific-status register.')); host.replaceChildren(article); } -const services=()=>import('./museum.mjs'); +const services=()=>import('./museum.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'); // The museum module already verifies config → manifest → index/status once per // page fetch and caches every pinned byte request. This route consumes that same // verified startup, so it adds only the audited-descriptor check and projection. diff --git a/docs/site/core.mjs b/docs/site/core.mjs index 9d477abce..1f9c6f2a6 100644 --- a/docs/site/core.mjs +++ b/docs/site/core.mjs @@ -19,7 +19,7 @@ export async function verifiedBytes(pin, fetcher = fetch) { const expected = `https://raw.githubusercontent.com/${pin.repository}/${pin.commit}/${pin.path.split('/').map(encodeURIComponent).join('/')}`; if (target !== expected) throw new Error('Displayed identity does not match source URL'); } - const response = await fetcher(target, {credentials:'omit', redirect:'error'}); + const response = await fetcher(target, {credentials:'omit', redirect:'error', ...(target.startsWith('https:')?{}:{cache:'no-store'})}); if (!response.ok) throw new Error(`Source unavailable (${response.status})`); const data = new Uint8Array(await response.arrayBuffer()); if (data.byteLength !== pin.bytes) throw new Error('Source byte count mismatch'); diff --git a/docs/site/dependencies.html b/docs/site/dependencies.html index 070c88882..da9ce9406 100644 --- a/docs/site/dependencies.html +++ b/docs/site/dependencies.html @@ -7,11 +7,11 @@ Claim dependency viewer · Universal Law - - - - - + + + + + diff --git a/docs/site/dependencies.mjs b/docs/site/dependencies.mjs index 3b8e20bc3..fdb5c6ff1 100644 --- a/docs/site/dependencies.mjs +++ b/docs/site/dependencies.mjs @@ -7,7 +7,7 @@ import { parsePinnedGraph, searchNodes, unresolvedTargets, -} from './dependency-model.mjs'; +} from './dependency-model.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; const byId = id => document.getElementById(id); @@ -120,8 +120,8 @@ function renderPath(path) { async function load() { const [graphResponse, provenanceResponse] = await Promise.all([ - fetch('./dependency-source/GRAPH.json'), - fetch('./dependency-source/PROVENANCE.json'), + fetch('./dependency-source/GRAPH.json',{cache:'no-store'}), + fetch('./dependency-source/PROVENANCE.json',{cache:'no-store'}), ]); if (!graphResponse.ok || !provenanceResponse.ok) throw new Error('A pinned source file could not be loaded.'); diff --git a/docs/site/explore-models.mjs b/docs/site/explore-models.mjs index 523a1a722..a00bc3cf0 100644 --- a/docs/site/explore-models.mjs +++ b/docs/site/explore-models.mjs @@ -1,6 +1,6 @@ // NON-CERTIFYING educational arithmetic. These functions illustrate source // definitions; they do not simulate a field or estimate a theorem's constants. -import { annulusModel, p15Model, remoteModel } from './geometry.mjs'; +import { annulusModel, p15Model, remoteModel } from './geometry.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; function finite(value, name) { if (!Number.isFinite(value)) throw new RangeError(`${name} must be finite`); diff --git a/docs/site/explore.html b/docs/site/explore.html index 243f1762e..b30666a1f 100644 --- a/docs/site/explore.html +++ b/docs/site/explore.html @@ -7,11 +7,11 @@ Explore the mathematics · Universal Law - - - - - + + + + + diff --git a/docs/site/explore.mjs b/docs/site/explore.mjs index b9b535393..d21a2dfdb 100644 --- a/docs/site/explore.mjs +++ b/docs/site/explore.mjs @@ -1,4 +1,4 @@ -import { coneModel, pinModel, paletteModel } from './explore-models.mjs'; +import { coneModel, pinModel, paletteModel } from './explore-models.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; const ns = 'http://www.w3.org/2000/svg'; const byId = id => document.getElementById(id); diff --git a/docs/site/formal.html b/docs/site/formal.html index 0572599ee..a62c6cd9f 100644 --- a/docs/site/formal.html +++ b/docs/site/formal.html @@ -4,9 +4,9 @@ Formal verification · Universal Law - - - + + + diff --git a/docs/site/index.html b/docs/site/index.html index ee0bec725..73e4156aa 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -4,8 +4,8 @@ Universal Law · The shape of randomness - - + +
UNIVERSAL LAW MATHEMATICS IN THE OPEN
diff --git a/docs/site/measure.html b/docs/site/measure.html index 999649af5..b96da512b 100644 --- a/docs/site/measure.html +++ b/docs/site/measure.html @@ -7,11 +7,11 @@ From counts to density · Universal Law - - - - - + + + + + diff --git a/docs/site/measure.mjs b/docs/site/measure.mjs index d6ce1d4c7..f6dfd31ea 100644 --- a/docs/site/measure.mjs +++ b/docs/site/measure.mjs @@ -1,4 +1,4 @@ -import { measurementModel, parseMeasurementInputs } from './measurement-model.mjs'; +import { measurementModel, parseMeasurementInputs } from './measurement-model.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; const byId = id => document.getElementById(id); const fields = Object.fromEntries(['count', 'realizations', 'lower', 'upper'].map(name => [name, byId(`measure-${name}`)])); diff --git a/docs/site/museum.html b/docs/site/museum.html index 8811e84fd..06a0b67f9 100644 --- a/docs/site/museum.html +++ b/docs/site/museum.html @@ -4,11 +4,11 @@ Source records & exhibits · Universal Law - + - - + + diff --git a/docs/site/museum.mjs b/docs/site/museum.mjs index fdf85da7c..6bc0222f9 100644 --- a/docs/site/museum.mjs +++ b/docs/site/museum.mjs @@ -1,5 +1,5 @@ -import {renderSourceQuote} from './source-quote.mjs'; -import {verifiedBytes, hex40, hex64} from './core.mjs'; +import {renderSourceQuote} from './source-quote.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; +import {verifiedBytes, hex40, hex64} from './core.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'; export const DISCLAIMER='This canvas explains the pinned source. It is not a proof and does not change status.'; const REVIEWED_IDS=['d2-lifetime-remainder','d3-side24-coefficient','d4-fixed-remote-rn','d5-all-height-annulus','d5-height-window-annulus','d5-two-scale','d5-inner-belt-density','d5-fixed-transverse','cumulative-transfer-correction','p15-demand-one-counterexample','d6-p15-full-price']; @@ -247,7 +247,7 @@ function prepareClaimFragment(document,window,currentHash) { return true; }; } -export async function startMuseum({document=globalThis.document,window=globalThis.window,fetcher=globalThis.fetch,search=globalThis.location?.search||'',geometryLoader=()=>import('./geometry.mjs'),currentHash=()=>globalThis.location?.hash||''}={}){ +export async function startMuseum({document=globalThis.document,window=globalThis.window,fetcher=globalThis.fetch,search=globalThis.location?.search||'',geometryLoader=()=>import('./geometry.mjs?site-release=dc3b8a3d50e06b183520769b998318b774231b7fc56eda438e4a4878b963d1a3'),currentHash=()=>globalThis.location?.hash||''}={}){ const ids=['museum-state','claim-cards','lifetime-fixture','packet-cards','active-exhibit']; const containers=Object.fromEntries(ids.map(id=>{const node=document.getElementById(id);if(!node)throw Error(`Missing museum container: ${id}`);return [id,node];})); const finishFragment=prepareClaimFragment(document,window,currentHash); diff --git a/docs/site/reproduce.html b/docs/site/reproduce.html index 3a6fd8162..43a4cb665 100644 --- a/docs/site/reproduce.html +++ b/docs/site/reproduce.html @@ -4,7 +4,7 @@ Reproduce · Universal Law - +
UNIVERSAL LAW MATHEMATICS IN THE OPEN
diff --git a/docs/site/research.html b/docs/site/research.html index a3ce8fd1c..4b31257f3 100644 --- a/docs/site/research.html +++ b/docs/site/research.html @@ -4,7 +4,7 @@ Research · Universal Law - +
UNIVERSAL LAW THE RESEARCH
diff --git a/docs/site/workspace.html b/docs/site/workspace.html index e483cbd64..323b7f366 100644 --- a/docs/site/workspace.html +++ b/docs/site/workspace.html @@ -4,9 +4,9 @@ Research workspace · Universal Law - - - + + + diff --git a/tests/test_brand_identity.mjs b/tests/test_brand_identity.mjs index 612925f18..76a74ac6b 100644 --- a/tests/test_brand_identity.mjs +++ b/tests/test_brand_identity.mjs @@ -31,9 +31,9 @@ test('palette tokens are actually applied, not decorative metadata',()=>{ test('all public pages load local branding after legacy styles with no CSP relaxation',()=>{ for(const name of ['index','explore','research','workspace','museum','formal']){ const h=read(`docs/site/${name}.html`); - assert.match(h,//); + assert.match(h,//); assert.ok(h.indexOf('brand.css')>h.indexOf('style.css')); - assert.match(h,/href="brand\/mark\.svg"/); + assert.match(h,/href="brand\/mark\.svg\?site-release=[0-9a-f]{64}"/); assert.match(h,/class="skip-link" href="#main-content"/); assert.match(h,/
new Response(bytes); test('valid source preserves exact strings',async()=>assert.equal((await verifiedJSON(pin,fetcher)).value,'0.04177593184059834334')); +test('local pinned data bypasses an older response while still verifying current bytes',async()=>{ + const old=new TextEncoder().encode('{"value":"older"}'); + const cached=async(url,options)=>new Response(options.cache==='no-store'?bytes:old); + assert.equal((await verifiedJSON(pin,cached)).value,'0.04177593184059834334'); +}); test('digest mismatch refuses data',async()=>assert.rejects(()=>verifiedBytes({...pin,sha256:'0'.repeat(64)},fetcher),/SHA-256/)); test('byte count mismatch refuses data',async()=>assert.rejects(()=>verifiedBytes({...pin,bytes:pin.bytes+1},fetcher),/byte count/)); test('mutable branch URL refused before request',async()=>assert.rejects(()=>verifiedBytes({...pin,url:'https://raw.githubusercontent.com/d6g8k5htny-coder/main/main/STATUS.md'},()=>{throw Error('must not fetch');}),/pinned public/)); diff --git a/tests/test_site_asset_release.py b/tests/test_site_asset_release.py new file mode 100644 index 000000000..d432ae839 --- /dev/null +++ b/tests/test_site_asset_release.py @@ -0,0 +1,83 @@ +"""Release URLs must select fresh entry and transitive assets, without editing data.""" +from html.parser import HTMLParser +from pathlib import Path +from tempfile import TemporaryDirectory +from urllib.parse import urlsplit, parse_qs +import subprocess +import sys +import unittest + +ROOT = Path(__file__).resolve().parents[1] +TOOL = ROOT / 'tools/site_asset_release.py' + +class Assets(HTMLParser): + def __init__(self, text): + super().__init__(); self.urls = []; self.feed(text) + def handle_starttag(self, tag, attrs): + a = dict(attrs) + if tag == 'script' and 'src' in a: self.urls.append(a['src']) + if tag == 'link' and a.get('rel') in ('stylesheet', 'icon'): self.urls.append(a['href']) + +class AssetRelease(unittest.TestCase): + def run_tool(self, site, *args): + return subprocess.run([sys.executable, str(TOOL), '--site', str(site), *args], text=True, capture_output=True) + + def fixture(self, root): + site = root/'site'; site.mkdir() + (site/'index.html').write_text('Read') + (site/'app.mjs').write_text("import {x} from './core.mjs'; const later=()=>import('./lazy.mjs'); const external=()=>import('https://example.test/tool.mjs');") + (site/'core.mjs').write_text('export const x=1;') + (site/'lazy.mjs').write_text("import './core.mjs';") + (site/'style.css').write_text('body{background:url("mark.svg")}') + (site/'mark.svg').write_text('') + (site/'config.json').write_bytes(b'{"pin":"unchanged"}\n') + (site/'proof.md').write_bytes(b'Exact research source.\n') + return site + + def test_current_entry_assets_select_a_release(self): + for path in (ROOT/'docs/site').glob('*.html'): + for asset in Assets(path.read_text()).urls: + if urlsplit(asset).scheme: continue + with self.subTest(page=path.name, asset=asset): + release = parse_qs(urlsplit(asset).query).get('site-release', []) + self.assertEqual(len(release), 1, 'Unversioned entry can reuse an older script/style') + self.assertRegex(release[0], r'^[0-9a-f]{64}$') + + def test_transitive_imports_and_css_share_the_release(self): + with TemporaryDirectory() as tmp: + site = self.fixture(Path(tmp)); result = self.run_tool(site) + self.assertEqual(result.returncode, 0, result.stderr) + release = result.stdout.strip() + self.assertRegex(release, r'^[0-9a-f]{64}$') + for file, target in [('app.mjs','./core.mjs'),('app.mjs','./lazy.mjs'),('lazy.mjs','./core.mjs'),('style.css','mark.svg')]: + self.assertIn(target+'?site-release='+release, (site/file).read_text()) + self.assertIn("import('https://example.test/tool.mjs')", (site/'app.mjs').read_text()) + self.assertIn('href="other.html#reading"', (site/'index.html').read_text()) + self.assertEqual((site/'config.json').read_bytes(), b'{"pin":"unchanged"}\n') + self.assertEqual((site/'proof.md').read_bytes(), b'Exact research source.\n') + + def test_changed_transitive_asset_and_config_invalidate_every_entry(self): + with TemporaryDirectory() as tmp: + site = self.fixture(Path(tmp)); first = self.run_tool(site) + self.assertEqual(first.returncode, 0, first.stderr) + (site/'core.mjs').write_text('export const x=2;') + stale = self.run_tool(site, '--check'); self.assertNotEqual(stale.returncode, 0) + second = self.run_tool(site); self.assertEqual(second.returncode, 0, second.stderr) + self.assertNotEqual(first.stdout, second.stdout) + (site/'config.json').write_text('{"pin":"new"}\n') + third = self.run_tool(site); self.assertEqual(third.returncode, 0, third.stderr) + self.assertNotEqual(second.stdout, third.stdout) + + def test_generation_is_idempotent_and_check_does_not_repair(self): + with TemporaryDirectory() as tmp: + site = self.fixture(Path(tmp)); first = self.run_tool(site) + self.assertEqual(first.returncode, 0, first.stderr) + before = {p.name:p.read_bytes() for p in site.iterdir()} + second = self.run_tool(site); self.assertEqual(second.stdout, first.stdout) + self.assertEqual(before, {p.name:p.read_bytes() for p in site.iterdir()}) + (site/'app.mjs').write_text("import './core.mjs';") + broken = {p.name:p.read_bytes() for p in site.iterdir()} + self.assertNotEqual(self.run_tool(site, '--check').returncode, 0) + self.assertEqual(broken, {p.name:p.read_bytes() for p in site.iterdir()}) + +if __name__ == '__main__': unittest.main() diff --git a/tests/test_workspace_navigation.mjs b/tests/test_workspace_navigation.mjs index 99c26b11a..4a6de584d 100644 --- a/tests/test_workspace_navigation.mjs +++ b/tests/test_workspace_navigation.mjs @@ -53,7 +53,9 @@ function page(hash='#inventory',{configFailure=false,importSuccess=false,querySu ]); const saved=new Map(['window','document','fetch'].map(name=>[name,Object.getOwnPropertyDescriptor(globalThis,name)])); globalThis.window=window;globalThis.document=document; - globalThis.fetch=async url=>{ + const requests=[]; + globalThis.fetch=async (url,options)=>{ + requests.push({url,options}); if(url==='config.json'){requested.resolve();await configuration.promise;return configFailure?new Response('',{status:503}):new Response(JSON.stringify(config));} if(url===config.status.url){statusRequested.resolve();await status.promise;} if(url===config.imports.url){custodyRequested.resolve();await custody.promise;return importSuccess?new Response(importBytes):new Response('',{status:503});} @@ -65,7 +67,7 @@ function page(hash='#inventory',{configFailure=false,importSuccess=false,querySu const loading=import(`../docs/site/app.js?workspace-navigation-test=${++run}`).finally(()=>{ for(const [name,descriptor] of saved)if(descriptor)Object.defineProperty(globalThis,name,descriptor);else delete globalThis[name]; }); - return {window,document,nodes,events,listeners,frames,flushFrames,loading,requested,configuration,statusRequested,status,statusRendered,custodyRequested,custody}; + return {window,document,nodes,events,listeners,frames,flushFrames,loading,requested,configuration,statusRequested,status,statusRendered,custodyRequested,custody,requests}; } async function complete(page) { @@ -74,6 +76,12 @@ async function complete(page) { page.flushFrames(); } +test('workspace refreshes configuration before validating current source pins',async()=>{ + const p=page();await complete(p); + assert.equal(p.requests.find(row=>row.url==='config.json').options.cache,'no-store'); + assert.match(p.nodes.get('inventory-state').textContent,/2,138 matches/); +}); + test('initial Library navigation is restored only after delayed layout and failed sources settle',async()=>{ const p=page(); await p.requested.promise; diff --git a/tools/public_shop_browser_check.py b/tools/public_shop_browser_check.py index 1b069b4bf..efeae61e2 100644 --- a/tools/public_shop_browser_check.py +++ b/tools/public_shop_browser_check.py @@ -11,7 +11,9 @@ import importlib.metadata import json import os +import mimetypes from pathlib import Path +import re import subprocess import threading import time @@ -21,15 +23,36 @@ ROOT=Path(__file__).resolve().parents[1] @contextmanager -def local_docs(): +def local_docs(warm_release=False): + requests=[] class Handler(SimpleHTTPRequestHandler): def log_message(self, *_args): pass + def do_GET(self): + requests.append(self.path) + url=urlsplit(self.path) + path=Path(self.translate_path(url.path)) + if warm_release and url.path == '/site/predecessor.html': + data=re.sub(r'[?&]site-release=[0-9a-f]{64}', '', (ROOT/'docs/site/dependencies.html').read_text()).encode() + self.send_response(200);self.send_header('Content-Type','text/html');self.send_header('Cache-Control','no-store') + self.send_header('Content-Length',str(len(data)));self.end_headers();self.wfile.write(data);return + if warm_release and not url.query and path.suffix in ('.mjs','.js','.css') and path.is_file(): + # Controlled predecessor reproduces the actual former 30-result cap. + # No routing interception: Chromium's HTTP cache remains enabled. + text=re.sub(r'[?&]site-release=[0-9a-f]{64}', '', path.read_text()) + if path.name == 'dependencies.mjs': + text=text.replace('searchResults.replaceChildren(...results.map(', 'searchResults.replaceChildren(...results.slice(0,30).map(') + data=text.encode();self.send_response(200) + self.send_header('Content-Type',mimetypes.guess_type(path.name)[0] or 'application/javascript') + self.send_header('Cache-Control','public, max-age=31536000, immutable') + self.send_header('Content-Length',str(len(data)));self.end_headers();self.wfile.write(data);return + super().do_GET() server=ThreadingHTTPServer(("127.0.0.1", 0), partial(Handler,directory=str(ROOT/"docs"))) thread=threading.Thread(target=server.serve_forever,daemon=True) thread.start() try: - yield f"http://127.0.0.1:{server.server_port}/site/" + origin=f"http://127.0.0.1:{server.server_port}/site/" + yield (origin,requests) if warm_release else origin finally: server.shutdown();server.server_close();thread.join() @@ -38,6 +61,29 @@ def require(condition, message): if not condition: raise ValueError(message) +def check_warm_asset_release(browser, expect, result, output): + with local_docs(warm_release=True) as (origin, requests): + context=browser.new_context(viewport={"width":1200,"height":900},color_scheme="light") + page=context.new_page();page.set_default_timeout(45000);errors=[] + page.on('pageerror', lambda error:errors.append(str(error))) + try: + for _ in range(2): + page.goto(origin+'predecessor.html') + page.locator('#dependency-search').fill('math') + expect(page.locator('#search-results > li')).to_have_count(30) + require(requests.count('/site/dependencies.mjs')==1,'Predecessor was not reused from Chromium HTTP cache') + page.goto(origin+'dependencies.html') + page.locator('#dependency-search').fill('math') + expect(page.locator('#search-results > li')).to_have_count(39) + for name in ('dependencies.mjs','dependency-model.mjs','dependencies.css','brand.css'): + require(any(urlsplit(url).path=='/site/'+name and re.fullmatch('[0-9a-f]{64}',parse_qs(urlsplit(url).query).get('site-release',[''])[0]) for url in requests), 'Missing versioned request: '+name) + require(not errors, 'Warm-release page errors: '+str(errors)) + result['page_errors']=errors + result['steps'].extend(['controlled predecessor shows 30 entries with HTTP cache enabled', 'second predecessor visit reuses cached module', 'new entry, transitive module and styles select release URLs', 'same browser then renders all 39 entries']) + shot=output/'warm-asset-release.png';page.screenshot(path=str(shot)) + result['screenshot']={'path':shot.name,'sha256':sha256(shot.read_bytes()).hexdigest()} + finally: context.close() + def check_flow(page, origin, expect, result): def ready(): @@ -361,6 +407,10 @@ def main(): browser=playwright.chromium.launch(channel="chrome",chromium_sandbox=True) try: report["browser_run_started"]=True;report["browser"]=browser.version + warm={"case":"warm-asset-release","steps":[],"passed":False};report["cases"].append(warm) + try: + check_warm_asset_release(browser,expect,warm,output);warm["passed"]=True + except Exception: warm["error"]=traceback.format_exc() for size in [{"width":1200,"height":900},{"width":390,"height":844}]: for scheme in ["light","dark"]: label=f'{size["width"]}-{scheme}' @@ -476,7 +526,7 @@ def refuse_inventory(route): context.close() finally: browser.close() - report["passed"]=len(report["cases"])==15 and all(case["passed"] for case in report["cases"]) + report["passed"]=len(report["cases"])==16 and all(case["passed"] for case in report["cases"]) except Exception: report["passed"]=False;report["error"]=traceback.format_exc() finally: diff --git a/tools/site_asset_release.py b/tools/site_asset_release.py new file mode 100644 index 000000000..a6590d433 --- /dev/null +++ b/tools/site_asset_release.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +"""Refresh local asset URLs after presentation/data changes; CI uses --check. + +Run `python -B tools/site_asset_release.py` before committing a site release. +The token selects a new cache key, not immutable historical hosting. Frozen data +and proof bytes are hashed as inputs but never rewritten. Existing HTML routes +and external source identities are preserved. +""" +import argparse +import hashlib +from pathlib import Path +import re +from urllib.parse import urlsplit, urlunsplit + +ROOT = Path(__file__).resolve().parents[1] +TOKEN = re.compile(r'[?&]site-release=[0-9a-f]{64}') +HTML = re.compile(r'(<(?:script|link)\b[^>]*?\b(?:src|href)\s*=\s*)([\"\'])([^\"\']+)(\2)', re.I) +IMPORT = re.compile(r'(\bfrom\s*|\bimport\s*\(\s*|\bimport\s*)([\"\'])([^\"\']+)(\2)') +CSS = re.compile(r'(url\(\s*)([\"\']?)([^\"\'\s)]+)(\2\s*\))') +EDITABLE = {'.html', '.js', '.mjs', '.css'} +ASSETS = {'.js', '.mjs', '.css', '.svg', '.png', '.jpg', '.jpeg', '.webp', '.ico', '.woff', '.woff2'} + +def release(site): + """Hash the complete local site and sibling catalog, with tokens removed.""" + digest = hashlib.sha256(b'public-site-asset-release-v1\0') + roots = [site] + catalog = site.parent/'public-math' + if catalog.is_dir(): roots.append(catalog) + for root in roots: + for path in sorted(p for p in root.rglob('*') if p.is_file()): + data = path.read_bytes() + if path.suffix in EDITABLE: + data = TOKEN.sub('', data.decode('utf-8')).encode('utf-8') + name = path.relative_to(site.parent).as_posix().encode('utf-8') + for part in (name, data): + digest.update(len(part).to_bytes(8, 'big')); digest.update(part) + return digest.hexdigest() + +def version(value, path, site, token): + clean = TOKEN.sub('', value) + url = urlsplit(clean) + if url.scheme or url.netloc or not url.path or Path(url.path).suffix not in ASSETS: + return value + target = (path.parent/url.path).resolve() + if not target.is_relative_to(site.resolve()) or not target.is_file(): + raise ValueError(f'{path.name}: missing/outside local asset {value}') + query = url.query + ('&' if url.query else '') + 'site-release=' + token + return urlunsplit((url.scheme, url.netloc, url.path, query, url.fragment)) + +def updates(site, token): + for path in sorted(p for p in site.rglob('*') if p.is_file() and p.suffix in EDITABLE): + text = path.read_text(encoding='utf-8') + pattern = HTML if path.suffix == '.html' else CSS if path.suffix == '.css' else IMPORT + amended = pattern.sub(lambda m: m[1]+m[2]+version(m[3], path, site, token)+m[4], text) + if amended != text: yield path, amended + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--site', type=Path, default=ROOT/'docs/site') + parser.add_argument('--check', action='store_true') + args = parser.parse_args() + if not args.site.is_dir(): parser.error('site must be an existing directory') + try: + token = release(args.site) + pending = list(updates(args.site, token)) + except (ValueError, UnicodeError) as error: + parser.error(str(error)) + if args.check and pending: + print('Asset URLs are stale; run python -B tools/site_asset_release.py') + for path, _ in pending: print(path.relative_to(args.site)) + return 1 + for path, text in pending: path.write_text(text, encoding='utf-8', newline='') + print(token) + return 0 + +if __name__ == '__main__': raise SystemExit(main()) From e539afcd791577486131e2c26e9ad3e8a9d16431 Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Sat, 3 Oct 2026 10:11:21 -0700 Subject: [PATCH 2/3] Load released museum entries in conditional startup regression --- tests/test_museum_conditionals_cli.mjs | 3 ++- tests/test_museum_conditionals_startup.mjs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_museum_conditionals_cli.mjs b/tests/test_museum_conditionals_cli.mjs index 85eff3948..3f4c1fb78 100644 --- a/tests/test_museum_conditionals_cli.mjs +++ b/tests/test_museum_conditionals_cli.mjs @@ -33,7 +33,8 @@ test('museum HTML has the route host, navigation and module without replacing ex const htmlURL=new URL('../docs/site/museum.html',import.meta.url); assert.ok(fs.existsSync(htmlURL),'updated museum HTML is absent'); const html=fs.readFileSync(htmlURL,'utf8'); - for(const text of ['id="conditional-route"','href="#conditionals"','src="conditionals.mjs"','src="museum.mjs"','id="claim-cards"','id="packet-cards"'])assert.ok(html.includes(text),text); + for(const text of ['id="conditional-route"','href="#conditionals"','id="claim-cards"','id="packet-cards"'])assert.ok(html.includes(text),text); + for(const module of ['conditionals','museum'])assert.match(html,new RegExp(`src="${module}\\.mjs\\?site-release=[0-9a-f]{64}"`)); assert.equal((html.match(/id="conditional-route"/g)||[]).length,1); }); test('CLI projects the exact source and produces deterministic JSON',()=>{ diff --git a/tests/test_museum_conditionals_startup.mjs b/tests/test_museum_conditionals_startup.mjs index efdb6e374..2836cc974 100644 --- a/tests/test_museum_conditionals_startup.mjs +++ b/tests/test_museum_conditionals_startup.mjs @@ -5,8 +5,16 @@ import assert from 'node:assert/strict'; import fs from 'node:fs'; import {digest,pin,fixture,documentFromHTML} from './fixtures/museum_fixture.mjs'; -const museum=await import(new URL('../docs/site/museum.mjs',import.meta.url)); -const conditionals=await import(new URL('../docs/site/conditionals.mjs',import.meta.url)); +// Load the same entry URLs as the browser; a bare test import would create a +// second module instance beside the release-qualified transitive import. +const htmlURL=new URL('../docs/site/museum.html',import.meta.url); +const html=fs.readFileSync(htmlURL,'utf8'); +const entry=name=>{ + const src=[...html.matchAll(/]*src="([^"]+)"/g)].map(m=>m[1]).find(src=>new URL(src,htmlURL).pathname.endsWith('/'+name)); + assert.ok(src,`Missing entry ${name}`);return new URL(src,htmlURL); +}; +const museum=await import(entry('museum.mjs')); +const conditionals=await import(entry('conditionals.mjs')); const raw=new Uint8Array(fs.readFileSync(new URL('./fixtures/cumulative_transfer_source.txt',import.meta.url))); const repo='d6g8k5htny-coder/Math-',commit='d6628da09384728992dcbe6e921cc28ba85aebb0'; const path='reviews/collision_mechanism_20260925/CUMULATIVE_TRANSFER_CORRECTION.md'; From 655a22dc60b81eb6ff6aa44bf1d110a7ec86da2c Mon Sep 17 00:00:00 2001 From: Dylan Roy <249851642+d6g8k5htny-coder@users.noreply.github.com> Date: Sat, 3 Oct 2026 10:12:11 -0700 Subject: [PATCH 3/3] Version quoted CSS imports and reject missing stylesheet targets --- tests/test_site_asset_release.py | 13 +++++++++++++ tools/site_asset_release.py | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test_site_asset_release.py b/tests/test_site_asset_release.py index d432ae839..90ff5d5c9 100644 --- a/tests/test_site_asset_release.py +++ b/tests/test_site_asset_release.py @@ -68,6 +68,19 @@ def test_changed_transitive_asset_and_config_invalidate_every_entry(self): third = self.run_tool(site); self.assertEqual(third.returncode, 0, third.stderr) self.assertNotEqual(second.stdout, third.stdout) + def test_quoted_css_import_is_versioned_and_missing_import_is_refused(self): + with TemporaryDirectory() as tmp: + site = self.fixture(Path(tmp)) + (site/'style.css').write_text('@import "theme.css" screen;\nbody{color:navy}') + (site/'theme.css').write_text('h1{color:gold}') + result = self.run_tool(site) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn('theme.css?site-release='+result.stdout.strip(), (site/'style.css').read_text()) + (site/'theme.css').unlink() + missing = self.run_tool(site, '--check') + self.assertNotEqual(missing.returncode, 0) + self.assertIn('missing/outside local asset', missing.stderr) + def test_generation_is_idempotent_and_check_does_not_repair(self): with TemporaryDirectory() as tmp: site = self.fixture(Path(tmp)); first = self.run_tool(site) diff --git a/tools/site_asset_release.py b/tools/site_asset_release.py index a6590d433..059b2d99f 100644 --- a/tools/site_asset_release.py +++ b/tools/site_asset_release.py @@ -17,6 +17,7 @@ HTML = re.compile(r'(<(?:script|link)\b[^>]*?\b(?:src|href)\s*=\s*)([\"\'])([^\"\']+)(\2)', re.I) IMPORT = re.compile(r'(\bfrom\s*|\bimport\s*\(\s*|\bimport\s*)([\"\'])([^\"\']+)(\2)') CSS = re.compile(r'(url\(\s*)([\"\']?)([^\"\'\s)]+)(\2\s*\))') +CSS_IMPORT = re.compile(r'(@import\s+)([\"\'])([^\"\']+)(\2)', re.I) EDITABLE = {'.html', '.js', '.mjs', '.css'} ASSETS = {'.js', '.mjs', '.css', '.svg', '.png', '.jpg', '.jpeg', '.webp', '.ico', '.woff', '.woff2'} @@ -50,8 +51,10 @@ def version(value, path, site, token): def updates(site, token): for path in sorted(p for p in site.rglob('*') if p.is_file() and p.suffix in EDITABLE): text = path.read_text(encoding='utf-8') - pattern = HTML if path.suffix == '.html' else CSS if path.suffix == '.css' else IMPORT - amended = pattern.sub(lambda m: m[1]+m[2]+version(m[3], path, site, token)+m[4], text) + patterns = [HTML] if path.suffix == '.html' else [CSS, CSS_IMPORT] if path.suffix == '.css' else [IMPORT] + amended = text + for pattern in patterns: + amended = pattern.sub(lambda m: m[1]+m[2]+version(m[3], path, site, token)+m[4], amended) if amended != text: yield path, amended def main():