In this section
- Particles Check ingest · globalgrid2050 / testcode/202609160224/proof/particles.check.mjs lines 1–458
- Wafer render · globalgrid2050 / testcode/202609160321/wafer.mjs lines 1–217
Particles Check
A JavaScript module in the proof folder of GlobalGrid2050 that reads lines meta, using haversine and SHA-256. Served with the page at https://globalgrid2050.com/testcode/202609160224/proof/.
ingestglobalgrid2050 / testcode/202609160224/proof/particles.check.mjs · lines 1–458 of 458 · version 2026-09-16 02:24 · Not reached from any entry point (candidate for review)
- What it does
- It loads lines meta. Defines check, sizeAt. Uses libraries node:crypto, node:fs, node:path. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Inputs & outputs
- In: JSON file particles.json; JSON file all-lines.meta.json; command-line arguments.
- What it achieves
- It is built from the check step (`check`) and the size at helper (`sizeAt`). The checks the code wafer must pass.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · testcode/202609160224/proof · JavaScript module
- Uses
- Derive (import), node:crypto, node:fs, node:path
- Used by
- none found
- Produces
- check, sizeAt
- Defines here
- check, sizeAt
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609160224/proof/particles.check.mjs:1-458 · blob 948522bd26995690f2f35167e6f7ed9b645a1696 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: ingest · effects: filesystem, process · domain stage: experimental · users: none · canonical: unreached_review
/* particles.check.mjs — the checks the code wafer must pass.
*
* The wafer claims three things that are easy to assert and easy to get wrong:
* that every band named in the head exists and holds what it says, that a key
* resolves to the line the numbered database actually recorded, and that the
* derived state is a pure function of the key. Each check below is a way for
* those claims to be false.
*
* --mutate corrupts the head in memory and checks 1-3 must fail. Check 4 cannot
* be falsified that way — a pure function is not made impure by a bad manifest —
* and that is stated rather than papered over with an artificial mutation.
*
* Run: node proof/particles.check.mjs
* node proof/particles.check.mjs --mutate
*/
import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import { derive, nature, radiation, NATURE_NAME, NOISE } from '../derive.mjs';
const HERE = path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1'));
const SURF = path.resolve(HERE, '..');
const PACK = path.resolve(SURF, '..', '202609142202', 'data');
const MUTATE = process.argv.includes('--mutate');
const head = JSON.parse(fs.readFileSync(path.join(SURF, 'particles.json'), 'utf8'));
const meta = JSON.parse(fs.readFileSync(path.join(PACK, 'all-lines.meta.json'), 'utf8'));
const buckets = head.buckets.map(([b, n]) => [b, n]);
if (MUTATE) {
buckets.push([999999, 7]); /* a band that does not exist -> 1 */
if (buckets[2]) buckets[2][1] += 5; /* a band with a wrong count -> 2 */
/* This lie was wrong the first time it was written: it replaced a place with
'Ventusltd/not-a-repo' and forty zeros, which IS well formed — a repository
that does not exist is not a malformed place, and check 3 correctly passed.
The check tests shape, so the lie must break shape: a truncated commit is
what actually reaches a browser as a silent 404. */
head.places[0] = ['Ventusltd/globalgrid2050', 'deadbeef', 'engine/geo-core.js']; /* -> 3 */
}
const results = [];
const check = (name, ok, detail) => results.push({ name, ok: !!ok, detail });
/* 1. Every band the head names exists on disk. */
const missing = buckets.filter(([b]) => !fs.existsSync(path.join(SURF, 'p', b + '.json'))).map(([b]) => b);
check('every band named in the head exists', missing.length === 0,
missing.length ? 'absent: ' + missing.join(', ') : buckets.length + ' bands, all present');
/* 2. Every band holds exactly the number of keys the head promises, and its keys
fall inside the band's own range. A band whose keys stray is a band the
page will fetch for the wrong ring. */
let wrong = [];
for (const [b, n] of buckets) {
const f = path.join(SURF, 'p', b + '.json');
if (!fs.existsSync(f)) continue;
const d = JSON.parse(fs.readFileSync(f, 'utf8'));
if (d.key.length !== n) { wrong.push(b + ' says ' + n + ' holds ' + d.key.length); continue; }
const lo = b * head.span, hi = lo + head.span;
if (d.key.some((k) => k < lo || k >= hi)) wrong.push(b + ' holds a key outside its range');
}
check('every band holds what the head promises', wrong.length === 0,
wrong.length ? wrong.slice(0, 3).join(' · ') : buckets.length + ' bands agree with the head');
/* 3. A resolution points at a real repository and a full commit. The page builds
a raw.githubusercontent URL from these; a malformed one fails silently in a
browser, which is the worst way for it to fail. */
const badPlace = head.places.filter(
([repo, commit, p]) => !/^[\w.-]+\/[\w.-]+$/.test(repo) || !/^[0-9a-f]{40}$/.test(commit) || !p
);
check('every place is a real repo and a full commit', badPlace.length === 0,
badPlace.length ? badPlace.length + ' malformed, first: ' + JSON.stringify(badPlace[0]).slice(0, 90)
: head.places.length + ' places, all well formed');
/* 4. The derived state is a pure function of the key. Same input, same output,
and a key that has not been issued yet already has one. NOT covered by
--mutate: corrupting a manifest cannot make a pure function impure. */
const a = derive(4242, 60, 1, 3), b2 = derive(4242, 60, 1, 3);
const future = derive(meta.max + 100000, 60, 1);
check('derived state is pure and unbounded',
a.nature === b2.nature && a.radiation === b2.radiation && a.field === b2.field &&
Number.isFinite(future.radiation),
'key 4242 -> ' + NATURE_NAME[a.nature] + ', radiation ' + a.radiation.toFixed(3) +
' ; unissued key ' + (meta.max + 100000) + ' already derives ' + NATURE_NAME[future.nature]);
/* 5. Radiation means "has this code been used somewhere" — so a line used in more
places must radiate more, and noise must radiate nothing at all. */
check('radiation rises with use, and noise radiates nothing',
radiation(60, 1, 2) < radiation(60, 1, 90) && radiation(2, 0) === 0 && nature(2, 0) === NOISE,
'2 places ' + radiation(60, 1, 2).toFixed(3) + ' < 90 places ' + radiation(60, 1, 90).toFixed(3) +
' ; a 2-character line in no family is ' + NATURE_NAME[nature(2, 0)] + ' at radiation 0');
/* 6. The particle count matches the pack's own in_a_family. If these disagree the
wafer is resolving lines the numbering does not think are resolvable. */
check('particles equal the pack\'s in_a_family', head.particles === meta.in_a_family,
head.particles.toLocaleString() + ' particles vs pack in_a_family ' +
meta.in_a_family.toLocaleString() + ' (pack built ' + meta.built_utc + ')');
/* 7. THE RASTER REACHES THE CANVAS.
*
* This file passed 6/6 honest and 3/6 mutated on a surface that drew NOTHING.
* Every check above describes the data; none asked whether a pixel ever reached
* the canvas. The pixel path wrote 250,174 particles into an ImageData buffer
* and never blitted it, so the page was black at its default zoom while its own
* counters reported every particle on screen — and it rendered correctly at
* dpr 2, so it worked on a phone and failed on a desktop.
*
* Node has no canvas, so this cannot count pixels the way vikra-ac did in a
* browser. It checks the invariant that actually broke instead: the default zoom
* takes the pixel path, and the pixel path must end in a blit, positioned after
* the buffer is written and before anything is composited over it.
*/
{
const src = fs.readFileSync(path.join(SURF, 'nest.mjs'), 'utf8');
const sizeAt = (zoom, dpr) => Math.max(1, 1.1 * dpr * Math.min(zoom, 2.4));
const defaultIsPixelPath = sizeAt(1, 1) <= 1.5;
const iWrite = src.lastIndexOf('buf32[o] =');
const iBlit = MUTATE ? -1 : src.indexOf('putImageData');
/* The blit overwrites rather than composites, so it must never run in a frame
that also draws labels. Rather than guess that from where the calls sit in
the file — the first version of this check did, and got the comparison
backwards — assert the numeric invariant: at every zoom where labels are
drawn, the pixel path must be off. LOD_NAMES is 8 in nest.mjs. */
const LOD_NAMES = 8;
let overlap = null;
for (let z = LOD_NAMES; z <= 600; z += 0.5) {
for (const dpr of [1, 2]) {
if (sizeAt(z, dpr) <= 1.5) { overlap = 'zoom ' + z + ' dpr ' + dpr; break; }
}
if (overlap) break;
}
const ok = defaultIsPixelPath && iWrite >= 0 && iBlit > iWrite && overlap === null;
check('the pixel path ends in a blit, and the default zoom uses it', ok,
'default zoom size ' + sizeAt(1, 1).toFixed(2) + ' -> pixel path ' + defaultIsPixelPath +
' ; buffer written at ' + iWrite + ' ; putImageData at ' + iBlit +
(iBlit < 0 ? ' <-- NOTHING REACHES THE CANVAS' : '') +
' ; labels never co-occur with the pixel path: ' + (overlap === null ? 'yes' : 'NO at ' + overlap));
}
/* 8. NO LOOP COUNTER IS SHADOWED INSIDE ITS OWN BODY.
*
* cdbade4c rewrote the particle loop to `for (let c = 0; ...)` so the render proof
* could drive it in reverse. The body already held `const c = COLOUR[nat[i]]`, which
* put the counter in that const's temporal dead zone — so the FIRST iteration threw
* ReferenceError and draw() never drew anything. `node --check` passes it: it is
* valid syntax and a runtime error.
*
* The irony is the point and it is recorded rather than tidied away: the commit that
* added a proof of the picture broke the picture. vikra-2e wrote the charter line an
* hour earlier — "the instrumentation I added to make a safety property observable
* briefly broke the thing it was observing" — and the chair then did it independently.
* Observing a thing means touching it, and touching it is the hazard.
*
* This is a pattern check, not a parser, and says so. It catches the exact shape that
* shipped: a `for (let X …)` whose body redeclares X.
*/
{
const src = fs.readFileSync(path.join(SURF, 'nest.mjs'), 'utf8');
const shadowed = [];
const loop = /for\s*\(\s*let\s+([A-Za-z_$][\w$]*)\s*=/g;
let m;
while ((m = loop.exec(src)) !== null) {
const name = m[1];
/* the block this loop opens: from its `{` to the matching depth-0 `}` */
const open = src.indexOf('{', loop.lastIndex);
if (open < 0) continue;
let depth = 0, end = open;
for (let i = open; i < src.length; i++) {
if (src[i] === '{') depth++;
else if (src[i] === '}') { depth--; if (depth === 0) { end = i; break; } }
}
const body = src.slice(open, end);
if (new RegExp('\\b(const|let)\\s+' + name + '\\b').test(body)) {
shadowed.push(name + ' at offset ' + m.index);
}
}
const injected = MUTATE ? ['c at offset 0 (injected by --mutate)'] : [];
const all = shadowed.concat(injected);
check('no loop counter is shadowed inside its own body', all.length === 0,
all.length ? 'temporal dead zone, throws on the first iteration: ' + all.join(' · ')
: 'checked every `for (let X …)` in nest.mjs; none redeclares its counter');
}
/* 9. A STARTING DOOR MUST NOT BE DUST.
*
* The first attempt at "where to begin" ranked every resolvable line by how many
* places record it and crowned KEY 2 — 142,863 places — which is the EMPTY LINE.
* derive.mjs calls it dust; 1339's README said it plainly months ago: "the most-
* shared line in the estate is line 2, an empty line". Technically the most-used
* line in the estate, and the worst possible first click for the exact audience the
* title names.
*
* It also won two categories at once, offering the visitor the same door twice.
*
* So: every door must resolve, must carry a statement rather than be dust, and must
* be distinct. The threshold is derive.mjs's own SHORT_MAX, not one invented here.
*/
{
const notable = head.notable || [];
const packDir = path.resolve(SURF, '..', '202609142202', 'data');
let lenOf = null;
try {
const kb = fs.readFileSync(path.join(packDir, 'all-lines.bin'));
const lb = fs.readFileSync(path.join(packDir, 'all-lines.len.bin'));
const ka = new Uint32Array(kb.buffer, kb.byteOffset, kb.byteLength / 4);
const la = new Uint16Array(lb.buffer, lb.byteOffset, lb.byteLength / 2);
lenOf = new Map();
for (let i = 0; i < ka.length; i++) lenOf.set(ka[i], la[i]);
} catch { /* no pack: the length half of this check cannot run, and says so */ }
const SHORT_MAX = 24;
const injected = MUTATE ? [{ key: 2, name: '(dust)', why: 'injected by --mutate', places: 142863 }] : [];
const doors = notable.concat(injected);
const dust = lenOf ? doors.filter((n) => (lenOf.get(n.key) || 0) <= SHORT_MAX) : [];
const dupes = doors.filter((n, i, a) => a.findIndex((m) => m.key === n.key) !== i);
check('every starting door is a line that carries a statement',
doors.length >= 3 && dust.length === 0 && dupes.length === 0,
dust.length ? 'DUST offered as a door: ' + dust.map((n) => 'key ' + n.key).join(', ')
: dupes.length ? 'the same door twice: key ' + dupes[0].key
: doors.length + ' doors, all operational, all distinct' +
(lenOf ? '' : ' (length pack absent — only distinctness was checked)'));
}
/* 10. A FAMILY CLAIM NAMES THE BUILD IT IS TRUE OF.
*
* vikra-ac measured two packs 23.3 hours apart and the chair reproduced it exactly:
*
* of pack 202609142202's 250,174 keys, measured against 202609152203
* absent entirely ............ 0 the permanence promise, OBSERVED
* lost their family ........ 198 0.154% in 23.3 hours
* gained a family ........... 49
*
* Zero keys vanished. Not one of 250,174 — so a set, a notation line, a composition
* and an annotation are all safe for ever in the only sense that matters.
*
* But 198 lines stopped being part of any function in a day, and NOTHING SAID SO. The
* key still resolves, the text still reads, and the thing it described is gone. A
* proposal from last month that is 95% live looks byte-identical to one made this
* morning, and the one thing that changed is the only thing a non-coder cannot check.
*
* So a family claim must name its build. Stated as measured, never as "still live":
* carried-by-a-family is the estate's own proxy and a line can be in a file and in no
* function. And no expiry, no warning colour, no threshold — at 0.15% a day any
* threshold is arbitrary and would train a reader to ignore it.
*/
{
const src = fs.readFileSync(path.join(SURF, 'nest.mjs'), 'utf8')
.replace(/\/\*[\s\S]*?\*\//g, ' '); /* code, not the prose about it */
const namesBuild = /in pack.*built_utc|built_utc.*in pack|' · in pack '/.test(src) ||
/in pack/.test(src) && /built_utc/.test(src);
const overclaims = /still live|currently live/i.test(src);
const hedged = /not the same as not being in a file/.test(src);
check('a family claim names the build it is true of',
!MUTATE && namesBuild && !overclaims && hedged,
overclaims ? 'the card says "still live" — carried-by-a-family is a proxy, not liveness'
: !namesBuild ? 'a family claim with no build named; 198 lines lost their family in a day'
: !hedged ? 'the card does not distinguish "in no function" from "not in a file"'
: 'the card names the pack’s built_utc and says what carried-by-a-family is not');
}
/* 11. A FAMILY CLAIM MAY NOT BRANCH ON THE BAND.
*
* Sites branched on `r`, the resolved place, which needs p/N.json fetched. So `r` is
* falsy in TWO situations — the line has no family, and the band has not loaded — and the
* card said the first in both. On the published page, key 192,067 (haversine's first line,
* in_a_family = 1 in the pack the card names) read "in no function family" while its own
* next sentence read "Reading this band."
*
* fams[i] answers it with zero fetches and is in memory from startup. The rule: any
* sentence asserting the ABSENCE of a family must be reached only through fams[i].
*
* WIDENED. The first version of this check found TWO of FOUR sites and reported green.
* Its pattern held exactly the two phrasings the fix in hand had just touched — "no
* function family" and "in no family" — so it read straight over " RADIATION: the pack
* knows only that no family claims it" and over "belongs to no function" in the dust
* branch. A check that finds two of four is worse than one that finds none, because it is
* then trusted. vikra-ac found the third by reading the published card. The fourth was
* found by widening THIS, and no reader had ever reported it.
*
* So the detector is a list of SHAPES rather than the sentences in hand, its guard window
* is eight lines, and its mutation removes the GUARD rather than injecting a finding the
* check never made. What it still cannot do is notice a shape nobody has thought of —
* that is check 12's job, and the two are only honest together.
*
* It reads the source with comments stripped: the fourth time tonight that mattered,
* after siblings, why, and the chair's own live grep, which returned 0 for a phrase the
* source splits across two concatenated lines. Test what is written.
*/
{
const raw = fs.readFileSync(path.join(SURF, 'nest.mjs'), 'utf8');
const code = raw.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:])\/\/[^\n]*/g, '$1 ');
/* Shapes, not sentences. Each is a way of telling a reader that no family carries this
line, and all of them must sit under fams[]. */
const DENIAL = [
/no function family/i,
/in no family/i,
/no famil\w* claims?/i,
/records? no family/i,
/no named function/i,
/belongs to no function/i,
/relates to nothing/i,
];
/* THE MUTATION REMOVES THE GUARD — the defect this check exists for — rather than
appending a finding the check never made. Every denial then stands unguarded, and all
of them must be reported. */
const scan = MUTATE ? code.split('fams[').join('FAMS_REMOVED(') : code;
const lines = scan.split('\n');
const denials = [];
lines.forEach((l, i) => {
if (!DENIAL.some((re) => re.test(l))) return;
/* A GUARD, NOT A MENTION. The first window asked only whether `fams[` appeared in the
eight lines above, and `const d = derive(key, len, fams[i]);` — a plain statement
two lines up — answered yes for the dust denial. Retro-run against the shipped file
it therefore reported ONE of the two live sites and would have been believed about
the other. A guard is a fams[] read inside a conditional, so a line that completes
a statement does not count as one. */
const guarded = lines.slice(Math.max(0, i - 8), i + 1)
.some((w) => /fams\[/.test(w) && !/;\s*$/.test(w));
if (!guarded) denials.push('line ' + (i + 1) + ' "' + l.trim().replace(/\s+/g, ' ').slice(0, 52) + '"');
});
check('no family denial is reached without consulting fams[]',
denials.length === 0,
denials.length
? denials.length + ' denial(s) not guarded by fams[]: ' + denials.slice(0, 4).join(' · ') +
' — these assert about the estate what is true of what has downloaded'
: 'every denial shape sits under a fams[] guard · ' + DENIAL.length + ' shapes searched · ' +
(code.match(/fams\[/g) || []).length + ' fams[] reads in the code');
}
/* 12. THE CARD'S PROSE IS THE PROSE A PERSON CLASSIFIED.
*
* Check 11 can only find shapes it has been told about, and three of the four defects it
* was written for were phrasings nobody had anticipated. This one makes no judgement about
* prose at all: it pins every sentence the card can say about a line and fails when the set
* changes.
*
* BOUNDARY, stated rather than implied: it cannot tell a true sentence from a false one.
* It guarantees only that no sentence reaches a reader without a person having re-read it
* against the fams[] rule and re-pinned it. That is the whole claim.
*
* Its mutation adds a sentence — not an artificial failure, but exactly the event it
* exists to catch.
*/
{
const raw = fs.readFileSync(path.join(SURF, 'nest.mjs'), 'utf8');
/* Comments FIRST, and this bit on the very first run: an apostrophe inside a comment
("true of this page's downloads") opens a string literal, and the extractor returned
28 fragments of COMMENT PROSE as though they were the card's sentences. Pinning that
would have pinned the wrong text and called it classified. The fifth time tonight a
check read a comment as evidence. */
const src = raw.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:])\/\/[^\n]*/g, '$1 ');
const from = src.indexOf('function english(');
const to = src.indexOf('\n}', from);
const body = from >= 0 && to > from ? src.slice(from, to) : '';
const lits = (body.match(/'(?:[^'\\]|\\.)*'/g) || [])
.map((t) => t.slice(1, -1))
.filter((t) => /[A-Za-z]{3}/.test(t) && /\s/.test(t)); /* prose, not property names */
const SEP = String.fromCharCode(1);
const joined = lits.join(SEP) + (MUTATE ? SEP + ' an added sentence' : '');
const h = crypto.createHash('sha256').update(joined).digest('hex').slice(0, 16);
const PINNED = '59758bd034b8a62b';
check("the card's prose is the prose a person classified",
h === PINNED && lits.length > 0,
h === PINNED
? lits.length + ' sentences in english(), unchanged since classification · ' + h
: 'english() prose changed: ' + h + ' is not the pinned ' + PINNED +
' — re-read each of the ' + lits.length + ' sentences against the fams[] rule, then re-pin');
}
/* 13. NO SURFACE DOOR MAY LEAD TO A 404.
*
* Vikram's rule, in his own words: never give the user a broken journey, leave no dead
* ends, the universe is endless. The card offered "OPEN THE SURFACE" for any place whose
* path matched testcode/<stamp>/, and four of the 68 stamps the places reach hold code
* and no index.html — 9 places, 9 doors straight to a 404.
*
* The manifest had been classifying those correctly as fragments for hours, and the FRONT
* DOOR was fixed for exactly this defect at 05:37Z. The card was not. Twice in one night,
* the same shape: a page offering what a manifest it does not consult already knows is
* unopenable.
*
* This check measures the doors the card can actually build, from the head it actually
* ships, against the directories that actually exist. Its mutation makes one openable
* stamp unopenable, which is the event: a surface loses its page and the card keeps
* linking to it.
*/
{
const head = JSON.parse(fs.readFileSync(path.join(SURF, 'particles.json'), 'utf8'));
const stamps = [...new Set(head.places
.map((p) => (/testcode\/(\d{10,14})\//.exec(p[2]) || [])[1])
.filter(Boolean))];
const openable = new Set(head.openable || []);
if (MUTATE && head.openable && head.openable.length) openable.add('202609110242');
/* A door is offered only for a stamp the head calls openable. So the failure is a
stamp the head calls openable that has no index.html on disk. */
/* WHAT THE CARD WOULD OFFER, not what this check would prefer. With no openable list
in the head the card falls back to offering EVERY stamp — which is the shipped
behaviour, and the retro-run has to say so rather than report a tidy zero. */
const carries = Array.isArray(head.openable) && head.openable.length > 0;
const offered = carries ? [...openable] : stamps;
const broken = offered.filter((st) => !fs.existsSync(path.join(SURF, '..', st, 'index.html')));
const unlisted = stamps.filter((st) => !offered.includes(st));
check('every surface door the card can offer actually opens',
broken.length === 0 && carries,
broken.length
? broken.length + ' door(s) lead to a 404: ' + broken.slice(0, 4).join(', ') +
(carries ? '' : ' — the head carries no openability, so the card offers every stamp it sees') +
' — a dead end, and the estate’s one rule against them'
: carries
? offered.length + ' of ' + stamps.length + ' stamps open · ' +
unlisted.length + ' named without a door (code, no page) · no door 404s'
: 'the head carries no openability list, so the card cannot tell a page from a fragment');
}
/* 14. NO LABEL MAY CARRY A TYPED COUNT.
*
* This file already argues it, six lines above the pack loader: a label typed twice is a
* label that drifts. It was written after derive.mjs renamed NOISE's display to 'dust'
* and one page went on saying 'noise', so the same page said both.
*
* The law strip then typed the estate's size anyway — "ALL 250,174 LINES" — and it was
* correct tonight and could not have known when it stopped being. It is the same defect
* as the front door that claimed ninety-seven surfaces when there were 119, and the front
* door was hand-typed twice before it was generated. A number a page cannot check is a
* claim it cannot retract.
*
* So: no textContent may contain a grouped number. Measured values arrive through
* toLocaleString() on something the page read.
*/
{
const raw = fs.readFileSync(path.join(SURF, 'nest.mjs'), 'utf8');
const code = raw.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:])\/\/[^\n]*/g, '$1 ');
/* The mutation RESTORES THE DEFECT rather than injecting a finding: the label goes back
to the typed count it shipped with, and the check must report it. */
const scan = MUTATE
? code.replace("textContent = 'ALL LINES'", "textContent = 'ALL 250,174 LINES'")
: code;
const all = (scan.match(/textContent = '[^']*\d{1,3},\d{3}[^']*'/g) || []);
check('no label carries a typed count',
all.length === 0,
all.length
? all.length + ' typed count(s) in labels: ' + all.slice(0, 3).join(' · ') +
' — correct until the estate changes, and unable to know when it has'
: 'every count in a label is read from the pack or the head · ' +
(code.match(/toLocaleString\(\)/g) || []).length + ' measured numbers rendered');
}
let failed = 0;
for (const r of results) {
if (!r.ok) failed++;
console.log((r.ok ? 'PASS ' : 'FAIL ') + r.name + '\n ' + r.detail);
}
console.log('\n' + (results.length - failed) + '/' + results.length + ' passed' +
(MUTATE ? ' (--mutate: checks 1-3 must be among the failures)' : ''));
process.exit(MUTATE ? 0 : failed ? 1 : 0);Wafer
A JavaScript module in the testcode folder of GlobalGrid2050 that draws lines meta and laws.
renderglobalgrid2050 / testcode/202609160321/wafer.mjs · lines 1–217 of 217 · version 2026-09-16 03:21 · Entry point · pattern shell (shared by 5 files)
- What it does
- It draws lines meta and laws. Defines 8 functions or classes, including shell, place, u8, build, layout. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Inputs & outputs
- In: JSON file all-lines.meta.json; JSON file laws-index.json. Out: canvas drawing.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 — Testcode Page (globalgrid2050, https://globalgrid2050.com/testcode/202609160319/). Reached from 6 other entry points, including Iterations — 42 Counts That Say Themselves (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/42-counts-that-say-themselves/); Iterations — 42 Counts That Say Themselves Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/42-counts-that-say-themselves/); GlobalGrid2050 — Testcode Page (globalgrid2050, https://globalgrid2050.com/testcode/).
- What it achieves
- It is built from the shell step (`shell`), the place step (`place`) and the build step (`build`). The bands-by-usage law, generated. Variation bands-by-usage-lit. It responds to resize events.
- Why it matters
- Loaded by the Testcode page at https://globalgrid2050.com/testcode/202609160319/.
- Application
- globalgrid2050 · testcode/202609160321 · JavaScript module
- Uses
- none found
- Used by
- loaded by GlobalGrid2050 — Testcode Page (script src)
- Produces
- place
- Defines here
- shell, place, u8, build, layout, draw, of, put
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609160321/wafer.mjs:1-217 · blob 7c2c19d67061789d91ec6c333e7766798fa493eb · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
/* wafer.mjs - the bands-by-usage law, generated. Variation bands-by-usage-lit.
*
* Usage quantised into eight shells, so the population at each level of reuse is visible.
*
* THE RULE EVERY LAW OBEYS, and this one is checked by proof/law.check.mjs:
* a position is a pure function of the entity's own permanent key and of published
* facts about it. No randomness, no simulation state, no memory between frames. The
* same key under the same law lands on the same point on every device, for ever - which
* is what makes a key that does not exist yet already have a place.
*
* Identity is the KEY, never the coordinate. Laws that place by measured usage move a
* point when the usage sharpens; the line it names does not move.
*/
const PACK = '../202609142202/data/';
const TAU = Math.PI * 2, GOLDEN = Math.PI * (3 - Math.sqrt(5));
const R = 585.5, B = 30, LAT = 597;
const POINT = 1.3, COLOUR = 'radiation';
let ORDER = 'descending'; /* let, not const: drawWith(order) re-renders the same camera */
/* key-derived spread: deterministic, so equal-valued lines form a shell not a wire */
const shell = (key) => ((key * 2654435761) >>> 0) % 1000 / 1000;
export function place(key, rad, len, fam, maxKey) {
const r = R*(1-Math.floor(rad*8)/8) + shell(key)*B*1.5;
const a = key * GOLDEN;
return [Math.cos(a) * r, Math.sin(a) * r];
}
const stage = document.getElementById('stage');
const ctx = stage.getContext('2d', { alpha: false });
const countEl = document.getElementById('count');
const footEl = document.getElementById('foot');
let keys, lens, fams, meta, px, py, lit, dpr = 1, scale = 1, cx = 0, cy = 0;
const u8 = (b) => new Uint8Array(b);
Promise.all([
fetch(PACK + 'all-lines.bin').then(r => r.arrayBuffer()),
fetch(PACK + 'all-lines.len.bin').then(r => r.arrayBuffer()),
fetch(PACK + 'all-lines.family.bin').then(r => r.arrayBuffer()),
fetch(PACK + 'all-lines.meta.json').then(r => r.json()),
]).then(([k, l, f, m]) => {
keys = new Uint32Array(k); lens = new Uint16Array(l); fams = u8(f); meta = m;
build(); layout(); draw();
countEl.textContent = keys.length.toLocaleString() + ' numbered lines';
countEl.classList.remove('dim');
}).catch(() => { footEl.textContent = 'expected the numbered pack at ' + PACK; });
function build() {
const n = keys.length;
px = new Float32Array(n); py = new Float32Array(n); lit = new Float32Array(n);
for (let i = 0; i < n; i++) {
const key = keys[i], len = lens[i], fam = fams[i];
/* radiation: the pack's own floor, since this surface draws rather than resolves */
const rad = len <= 3 ? 0 : (fam ? 0.42 : 0.12);
lit[i] = rad;
const p = place(key, rad, len, fam, meta.max);
px[i] = p[0]; py[i] = p[1];
}
}
function layout() {
dpr = Math.min(devicePixelRatio || 1, 2);
stage.width = Math.floor(innerWidth * dpr); stage.height = Math.floor(innerHeight * dpr);
scale = (Math.min(stage.width, stage.height) / 2 - 18 * dpr) / R;
cx = stage.width / 2; cy = stage.height / 2;
}
function draw() {
const img = ctx.createImageData(stage.width, stage.height), d = img.data;
/* SEED THE GROUND INTO THE BUFFER. draw() used to fillRect the ground and then
putImageData a fresh all-zero buffer straight over it, so the ground a surface
declared was never on the canvas: 74% of it was pure black. Two of the render
proof's three levels compare pixels against the declared ground, so with no pixel
ever matching it, every pixel counted as lit and both levels passed on any input -
they would have passed on a blank page. Seat B found it in the contract I exposed
so that it could be tested. */
for (let i = 0; i < d.length; i += 4) {
d[i] = 5; d[i + 1] = 7; d[i + 2] = 11; d[i + 3] = 255;
}
const step = ORDER === 'descending' ? -1 : 1;
const from = step > 0 ? 0 : keys.length - 1, to = step > 0 ? keys.length : -1;
let shown = 0;
const wide = POINT >= 1.15; /* bolder: a 2x2 footprint */
const fine = POINT <= 0.85; /* finer: same footprint, less light */
/* BRIGHTER WINS. These surfaces used last-write-wins, so where two keys landed on one
pixel the one drawn last took it - and the picture changed when the iteration order
reversed. Seat B measured 19 of 24 surfaces differing under drawWith('descending'),
with the size of the difference tracking how much each law overlaps its points.
That is not cosmetic: this universe's whole premise is that position is derived from
the key, and a raster that depends on loop order means two renderings of one estate
can disagree with neither being wrong. Brighter-wins makes the picture a pure
function of the SET of keys, independent of the order they arrive in. */
for (let i = from; i !== to; i += step) {
const x = (cx + px[i] * scale) | 0, y = (cy + py[i] * scale) | 0;
if (x < 0 || y < 0 || x >= stage.width || y >= stage.height) continue;
let a = COLOUR === 'radiation' ? 0.18 + lit[i] * 0.82 : (fams[i] ? 0.85 : 0.3);
if (fine) a *= 0.62;
const r = 90 + a * 165, g = 110 + a * 145, b = 140 + a * 115;
const put = (xx, yy) => {
if (xx < 0 || yy < 0 || xx >= stage.width || yy >= stage.height) return;
const o = (yy * stage.width + xx) * 4;
if (r + g + b <= d[o] + d[o + 1] + d[o + 2]) return; /* brighter wins */
d[o] = r; d[o + 1] = g; d[o + 2] = b; d[o + 3] = 255;
};
put(x, y);
if (wide) { put(x + 1, y); put(x, y + 1); put(x + 1, y + 1); }
shown++;
}
ctx.putImageData(img, 0, 0);
footEl.textContent = 'law: bands-by-usage - Usage bands. ' + shown.toLocaleString() +
' of ' + keys.length.toLocaleString() + ' on screen - pack ' + meta.built_utc +
' - identity is the key, not the coordinate' +
' - across plain/fine/lit this law varies in placement and weight';
}
addEventListener('resize', () => { layout(); draw(); });
/* ---- the strip: this surface is not a dead end ---------------------------
* Every generated surface once carried exactly ONE href - its own stylesheet - so a
* visitor arriving from the homepage could look and then had nowhere to go. That is
* against the rule that the universe is endless.
*
* It is NAVIGATION, NOT CONTENT: it is fetched after the wafer has drawn, it never
* blocks the picture, and if the index cannot be read the strip stays hidden and the
* page is exactly as it was. Absent navigation is survivable; wrong navigation is not,
* because it promises a journey and then 404s.
*
* The index is GENERATED from each surface's own declared law, never typed - six of
* these law ids were renamed after the surfaces existed, and a hand-written strip
* would still be pointing at the old ones.
*/
const LAWS_INDEX = '../202609160224/laws-index.json';
fetch(LAWS_INDEX).then(r => r.ok ? r.json() : null).then(ix => {
if (!ix || !Array.isArray(ix.laws) || !ix.laws.length) return;
const nav = document.getElementById('laws');
const home = document.createElement('a');
home.href = '../202609160224/'; home.className = 'home';
home.textContent = '◀ the galaxy';
nav.append(home);
for (const law of ix.laws) {
if (!law.open || !law.id) continue;
const a = document.createElement('a');
a.href = '../' + law.open + '/';
a.textContent = law.id;
a.title = law.title || law.id;
if (law.id === 'bands-by-usage') a.setAttribute('aria-current', 'page');
nav.append(a);
}
nav.hidden = false;
}).catch(() => { /* the picture stands on its own */ });
/* ---- the hook the render proof drives ------------------------------------
* Seat B could run only liveness, distinctness and reload-determinism against these
* surfaces, because they exposed place() and nothing else. The render proof's real
* levels need a camera to compute the expected picture, a sample to compute it FOR, and
* a way to redraw the same camera in a different order.
*
* Reversing the iteration order is the stronger determinism claim and the reason this
* matters: reloading proves the PAGE is deterministic; reversing proves the PICTURE is a
* pure function of the keys. For a universe whose whole premise is derived position,
* that is the claim worth proving.
*/
window.__wafer = {
law: 'bands-by-usage', variant: 'bands-by-usage-lit', place, lawsIndex: LAWS_INDEX,
ready: () => keys !== null && keys !== undefined,
camera: () => ({ cx, cy, scale, zoom: 1, panX: 0, panY: 0, dpr,
w: stage.width, h: stage.height }),
ground: [5, 7, 11], /* #05070b, what draw() fills with */
keyCount: () => (keys ? keys.length : 0),
allKeys: () => keys,
sampleKeys: (n) => {
if (!keys) return [];
const out = [];
for (let i = 0; i < n; i++) out.push(keys[Math.floor((i + 0.5) * keys.length / n)]);
return out;
},
drawWith: (order) => { const was = ORDER; ORDER = order; draw(); ORDER = was; },
/* PLACE BY INDEX, NEVER BY GUESSED ARGUMENTS.
*
* __wafer exposed place(key, rad, len, fam, maxKey) and none of the per-key inputs it
* needs, so an external caller had exactly two options: guess the arguments, or
* recompute rad/len/fam from the pack - which is reimplementing the derivation, the one
* thing a proof must not do. The contract made the honest path unavailable.
*
* Seat B guessed zeros and four laws failed 12 of 24 projections. Worse, ONE law with
* the same wrong argument PASSED 20 of 20: rings-by-membership reads fam, about half
* the sampled keys were projected to the wrong ring, and a dense canvas with a 1px
* tolerance absorbed it. The failures sent someone to look; the false pass did not.
*
* placeIndex(i) supplies the page's own arrays, so there is no argument to get wrong.
* That is the structural form of the same rule the charter applies to prose: remove the
* opportunity rather than document the hazard. */
placeIndex: (i) => {
if (!keys || i < 0 || i >= keys.length) return null;
const key = keys[i], len = lens[i], fam = fams[i];
const rad = len <= 3 ? 0 : (fam ? 0.42 : 0.12);
return place(key, rad, len, fam, meta.max);
},
/* If a caller genuinely needs the inputs, it gets the REAL ones rather than inventing
them. Exposing place() without these is what produced the false pass. */
inputsFor: (i) => {
if (!keys || i < 0 || i >= keys.length) return null;
const key = keys[i], len = lens[i], fam = fams[i];
return { key, len, fam, rad: len <= 3 ? 0 : (fam ? 0.42 : 0.12), maxKey: meta.max };
},
indexOfKey: (k) => {
if (!keys) return -1;
let lo = 0, hi = keys.length - 1;
while (lo <= hi) { const mid = (lo + hi) >> 1;
if (keys[mid] === k) return mid;
if (keys[mid] < k) lo = mid + 1; else hi = mid - 1; }
return -1;
},
/* What the parameter sets actually change ON THIS LAW. Derived from the law's own
radius expression, never typed: a law with no shell term cannot move a point when
the band changes, so its variants differ in WEIGHT rather than in PLACEMENT. */
varies: 'placement and weight',
};