GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / globalgrid2050 / kuiper-grid/i0073/cartridges

Kuiper Tests (part 3)

A JavaScript file in the cartridges folder of GlobalGrid2050 that tests link contract, cables, solar and battery storage (BESS), and uses data from the GridAtlas repository.

480 lines of JavaScript from globalgrid2050, in 1 file. Topic: Kuiper, cosmos and drawing engines. Section 1245 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Kuiper Tests test · globalgrid2050 / kuiper-grid/i0073/cartridges/004100000000-kuiper-tests.js lines 418–897

Kuiper Tests

A JavaScript file in the cartridges folder of GlobalGrid2050 that tests link contract, cables, solar and battery storage (BESS), and uses data from the GridAtlas repository.

Set aside from the main view: 92% of its lines are the same as kuiper-grid/i0073/releases/003100000000-kuiper-shell/kuiper-tests.js (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 91% of lines shared with Kuiper Tests; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.9194 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0073/releases/003100000000-kuiper-shell/kuiper-tests.js:1-844 ad24a37445c54d4bffe4fa63a649d1f4292a151c
  • sha256 fefa0a309b92da778bc2c92fcc837ecf2521826d189a666019b8c2a470f82693
  • target sha256 23f4df7ece0aa08ce698b7293a74719acca1ccb7f0c22f00a0f41686763337a4
  • group of 7 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

testglobalgrid2050 / kuiper-grid/i0073/cartridges/004100000000-kuiper-tests.js · lines 418–897 of 897 (continued from section 1244) · Not reached from any entry point (candidate for review) · pattern buttonsSelftest (shared by 8 files)

What it does
It tests link contract, cables, solar and battery storage (BESS). Defines 28 functions or classes, including finishSelftest, pathSelftest, inWindow, on, buttonsSelftest. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage agent_infra (path word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: cables, solar, battery storage (BESS).
Inputs & outputs
In: data source: gridatlas data; JSON file link-contract.json.
What it achieves
It is built from the finish selftest helper (`finishSelftest`), the path selftest helper (`pathSelftest`) and the in window helper (`inWindow`). A cartridge of the Kuiper shell. It reads `cosmos/link-contract.json`. It responds to pointerdown and pointermove events.
Why it matters
No other file in the estate was found to import it.
Application
globalgrid2050 · kuiper-grid/i0073/cartridges · script
VEDIC
PERIOD (GG2050-VEDIC-000042): Kuiper / Code navigation · Computer science / Interactive visualisation. year, month_optional, day_optional, ordered_commits → commit_period_summary_or_null
Uses
Cable Geometry Visualiser V5 (estate URL), GridAtlas — Atlas Page (estate URL), GlobalGrid2050 — Cable Geometry Page (estate URL)
Used by
none found
Produces
finishSelftest, pathSelftest, inWindow, on, buttonsSelftest, settle, litPixels, isolateSelftest, onScreen, census, ring, ev
Defines here
same, named, repoSelftest, strip, check, phoneSelftest, ev, seen, walk, lightTime, pinchNow, pointerGone
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0073/cartridges/004100000000-kuiper-tests.js:418-897 · blob 1311e354804310ceb4fe6738baf3d828e54ef121 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: agent_infra · users: ai_agent · canonical: duplicate_candidate
    const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
    const wrong = [];
    for (const ex of ct.examples) {
      const built = buildLink(ex.asked);
      const want = {}; for (const k of Object.keys(LINK.params)) {
        const v = ex.asked[k]; want[k] = (v === undefined || v === null || v === '') ? null : v; }
      if (built !== ex.built) wrong.push({ asked:ex.asked, this_page:built, the_table:ex.built });
      else if (!same(parseLink(built), want)) wrong.push({ asked:ex.asked, came_back:parseLink(built) });
    }
    T.examples_checked = ct.examples.length;
    T.links_that_disagree = wrong;
    T.T15_a_link_this_page_built_parses_back_to_what_it_asked_for = ct.examples.length > 0 && wrong.length === 0;
  } catch (e) {
    // A TEST THAT CANNOT RUN MUST FAIL, NOT GO QUIET.
    T.T15_a_link_this_page_built_parses_back_to_what_it_asked_for = false;
    T.links_that_disagree = 'the published table could not be read: ' + (e && e.message || e);
  }
  // AND NOBODY TYPES AN ADDRESS. One function makes them; a hand written one is how the two halves
  // of a link stop agreeing without anybody noticing.
  try {
    // THE PAGE IS SEVERAL FILES NOW, and under the composer the address bar is not where they live
    const parts = [new URL('index.html', document.baseURI).href].concat(Array.from(document.querySelectorAll('script[src]')).map(x => x.src));
    const src = (await Promise.all(parts.map(u => fetch(u).then(r => r.text())))).join('\n');
    const typed = [];
    for (const k of Object.keys(LINK.params)) {
      const needle = '?' + k + '=';
      let at = -1;
      while ((at = src.indexOf(needle, at + 1)) >= 0) {
        // A SENTENCE THAT MENTIONS AN ADDRESS IS NOT AN ADDRESS. A typed one begins a string, so
        // the character before the question mark is a quote. This sentence may not show you an
        // example, because an example would be the very thing it is looking for, and this check
        // failed on its own explanation the first time it ran.
        const before = at > 0 ? src[at - 1] : ' ';
        if (before === '"' || before === "'" || before === '`') typed.push(src.slice(Math.max(0, at - 30), at + 14));
      }
    }
    T.addresses_typed_by_hand = typed;
    T.T16_no_address_is_typed_by_hand_in_this_page = typed.length === 0;
  } catch (e) {
    T.T16_no_address_is_typed_by_hand_in_this_page = false;
    T.addresses_typed_by_hand = 'the page could not read its own source: ' + (e && e.message || e);
  }
  // ARRIVING BY A LINK. The view flies, an arrow is shot from the centre of the record to the work
  // the address names, and only then does the card open. The arrow must END ON THE DOT the card
  // describes: an arrow that points near the answer is worse than none, because it is believed.
  { const ka = c.k0 + Math.floor(c.lines / 3);
    home(); card.style.display = 'none'; target = null; arrow = null; arrowTip = null; draw();
    arriveAt(ka);
    // THE CLOCK IS NOT WHAT IS BEING CHECKED. Under a headless time budget this page gets about seven
    // animation frames in eight seconds, so waiting for the flight to finish measures the browser's
    // throttle. Put the camera where the flight was going, tell the arrow its time is up, draw once.
    for (let i = 0; i < 60 && !arrow; i++) await new Promise(r => setTimeout(r, 100));
    if (tween) { cx = tween.x1; cy = tween.y1; zoom = tween.z1; tween = null; }
    if (arrow) arrow.t0 = performance.now() - ARROW_MS;
    draw();
    const p = keyPlace(ka);
    const wx = (p[0] - cx) * zoom + ov.width / 2, wy = ov.height / 2 - (p[1] - cy) * zoom;
    T.arrow_tip = arrowTip ? [Math.round(arrowTip.x), Math.round(arrowTip.y)] : null;
    T.arrow_still_flying = !!arrow;
    T.camera = [Math.round(cx), Math.round(cy), +zoom.toFixed(3)];
    T.draws_seen = drawCount;
    T.the_dot_it_should_end_on = [Math.round(wx), Math.round(wy)];
    T.T17_the_arrow_ends_on_the_dot = !!arrowTip && arrowTip.done
      && Math.hypot(arrowTip.x - wx, arrowTip.y - wy) < 2;
    // and it is shot from the centre of the record, not from wherever the camera happened to be
    // IT COMES ALONG THE LINE FROM THE BEGINNING OF THE RECORD. After the camera flies, that point
    // is far off the screen, so what can be checked is not where the drawing starts but that the
    // drawing lies on the line: the direction is the meaning.
    { const c0x = (0 - cx) * zoom + ov.width / 2, c0y = ov.height / 2 + cy * zoom;
      const ux = wx - c0x, uy = wy - c0y, vx = (arrowTip ? arrowTip.x0 : 0) - c0x, vy = (arrowTip ? arrowTip.y0 : 0) - c0y;
      const cross = Math.abs(ux * vy - uy * vx) / Math.max(1, Math.hypot(ux, uy));
      T.arrow_starts_at = arrowTip ? [Math.round(arrowTip.x0), Math.round(arrowTip.y0)] : null;
      T.the_centre_of_the_record_is_at = [Math.round(c0x), Math.round(c0y)];
      T.how_far_the_arrow_is_off_that_line_px = arrowTip ? +cross.toFixed(2) : null;
      T.T18_it_is_shot_from_the_centre_of_the_record = !!arrowTip && cross < 2
        && arrowTip.x0 >= -1 && arrowTip.x0 <= ov.width + 1 && arrowTip.y0 >= -1 && arrowTip.y0 <= ov.height + 1; }
    for (let i = 0; i < 40 && card.style.display === 'none'; i++) await new Promise(r => setTimeout(r, 100));
    T.T19_and_then_the_card_opens = card.style.display !== 'none'
      && card.textContent.replace(/\s+/g, ' ').length > 20;
    T.the_card_after_arriving = card.textContent.replace(/\s+/g, ' ').slice(0, 90); }
  // AN ADDRESS THIS PAGE CANNOT ANSWER MUST SAY SO. The note claimed it already did; building such
  // a link was refused, but ARRIVING with one said nothing at all, which is the half a reader meets.
  { const A = window.__arrival || { said:[], shown:null };
    T.what_the_address_asked_for_that_this_page_cannot_answer = A.said;
    T.what_the_page_said_about_it = A.shown ? A.shown.replace(/\s+/g, ' ').slice(0, 150) : null;
    const said_it = A.said.length === 0 || (!!A.shown && A.said.every(x => A.shown.indexOf(x) >= 0));
    // and the sentences themselves, on addresses chosen here rather than on whatever this one was
    const one = complaints('https://x/?colour=red'), two = complaints('https://x/?key=abc'),
          none = complaints('https://x/?key=12&path=a');
    T.T20_an_address_it_cannot_answer_is_answered_in_words =
         said_it && one.length === 1 && one[0].indexOf('colour') >= 0
      && two.length === 1 && two[0].indexOf('whole number') >= 0 && none.length === 0; }
  // WHAT A LINE LEADS TO. The photographed line must say CABLES and open it; every carried file must
  // be given the application its folder proves and no other; a repository that is one application
  // must be proved by the repository alone; and where nothing is proved there must be no door at all.
  { codeOpen = false;                    // the door is met before the code is ever opened
    const withApp = cards.find(x => (appFor(x.owner, x.repo, x.path) || {}).app) || c;
    const noApp = cards.find(x => !(appFor(x.owner, x.repo, x.path) || {}).app);
    if (noApp) { show(address(noApp.k0 + 3)); await new Promise(r => setTimeout(r, 200));
      const r0 = card.querySelector('.cc-app');
      T.a_carried_file_no_application_claims = [noApp.path, r0 ? r0.textContent.slice(0, 40) : null];
      T.T26_a_carried_file_no_application_claims_gets_no_door = !!r0 && r0.tagName !== 'A' && !r0.querySelector('a:not(.cc-home):not(.cc-gh)'); }
    else T.T26_a_carried_file_no_application_claims_gets_no_door = true;
    show(address(withApp.k0 + Math.floor(withApp.lines / 2))); await new Promise(r => setTimeout(r, 200));
    const row = card.querySelector('.cc-app'), door = row && (row.tagName === 'A' ? row : row.querySelector('a:not(.cc-home):not(.cc-gh)'));
    T.the_app_row = row ? row.textContent.replace(/\s+/g, ' ') : null;
    const want_app = (appFor(withApp.owner, withApp.repo, withApp.path) || {}).app || null;
    T.T22_the_card_says_which_application_and_opens_it = !!row && !!want_app
      && row.getAttribute('data-app') === want_app.app && !!door && on(door)
      && door.href === (withApp.page && withApp.page.address !== want_app.live ? withApp.page.address : want_app.live);
    const wrong = [];
    for (const x of cards) { const f = appFor(x.owner, x.repo, x.path), got = f && f.app ? f.app.app : null;
      const byHand = apps.filter(a => a.repo === (x.owner + '/' + x.repo).toLowerCase()
        && a.prefixes.some(p => x.path === p || x.path.indexOf(p + '/') === 0)).map(a => a.app);
      if ((got || null) !== (byHand[0] || null) && !(byHand.length > 1 && byHand.indexOf(got) >= 0)) wrong.push([x.path, got, byHand]); }
    T.carried_files_and_their_applications = cards.map(x => [x.path.split('/').pop(), ((appFor(x.owner, x.repo, x.path) || {}).app || {}).app || 'none']);
    T.T23_every_carried_file_gets_the_application_its_folder_proves = apps.length > 0 && wrong.length === 0;
    // TWO WORKINGS OF ONE RULE MUST AGREE. The tool that carries a file works out its application by
    // folder and writes it down; this page works it out again for itself. File by file, and in the
    // number of lines that end up with a door, the two must come to the same answer.
    const differ = [], tally = { page:{}, tool:{} };
    for (const x of cards) { const pg = ((appFor(x.owner, x.repo, x.path) || {}).app || {}).app || '';
      if (pg !== x.toolApp) differ.push([x.path, 'page: ' + (pg || 'none'), 'tool: ' + (x.toolApp || 'none')]);
      if (pg) tally.page[pg] = (tally.page[pg] || 0) + x.lines;
      if (x.toolApp) tally.tool[x.toolApp] = (tally.tool[x.toolApp] || 0) + x.lines; }
    T.lines_with_a_door_by_application = tally; T.files_where_the_two_workings_differ = differ;
    T.T27_the_page_and_the_tool_agree_on_every_file_and_every_count = cards.length > 0 && differ.length === 0
      && JSON.stringify(tally.page) === JSON.stringify(tally.tool);
    // AND THE TWO EXAMPLES THE ORDER NAMES, asked for by name.
    const named = async (path, button, live) => { const x = cards.find(q => q.path === path);
      if (!x) return [false, 'the file ' + path + ' is not carried'];
      show(address(x.k0 + Math.floor(x.lines / 2))); await new Promise(r => setTimeout(r, 200));
      const rw = card.querySelector('.cc-app'), dr = rw && (rw.tagName === 'A' ? rw : null), pre = card.querySelector('details.cc-q');
      const above = !!dr && !!pre && dr.getBoundingClientRect().bottom <= pre.getBoundingClientRect().top + 0.5;
      return [!!rw && rw.textContent.indexOf(button) >= 0 && !!dr && dr.href === live && on(dr) && above,
              rw ? rw.textContent : null]; };
    const ca = await named('solar-bess-topology-v5/cable-geometry-visualiser-v5.html', 'CABLES',
      'https://globalgrid2050.com/solar-bess-topology-v5/cable-geometry-visualiser-v5.html');
    const ga = await named('atlas/index.html', 'GRIDATLAS', 'https://ventusltd.github.io/gridatlas/atlas/');
    T.the_cables_line_says = ca[1]; T.the_gridatlas_line_says = ga[1];
    T.T28_the_cables_line_opens_cables_above_the_code_without_scrolling = ca[0];
    T.T29_a_gridatlas_line_opens_gridatlas_above_the_code_without_scrolling = ga[0];
    // a line whose file is NOT known, in a repository that holds several applications: no door
    const other = commits.find(q => { const rp = repos[q.repo]; return rp.pub && !cardFor(q.k0)
      && (appFor(rp.owner, rp.name, null) || {}).unproved; });
    if (other) { show(address(other.k0)); await new Promise(r => setTimeout(r, 150));
      const r2 = card.querySelector('.cc-app');
      T.an_unproved_line_says = r2 ? r2.textContent.slice(0, 90) : null;
      // a page its files prove is a door; what must NOT appear is an application nobody proved
      T.T24_where_nothing_is_proved_there_is_no_door = !!r2 && (r2.classList.contains('cc-page')
        ? r2.getAttribute('data-app') === '' && !r2.querySelector('.cc-tile-part')
        : r2.tagName !== 'A' && !r2.querySelector('a:not(.cc-home):not(.cc-gh)')); }
    else T.T24_where_nothing_is_proved_there_is_no_door = true;
    // and a repository that IS one application is proved by the repository alone
    const wholeApp = apps.find(a => !a.prefixes.length);
    const oneOf = wholeApp && commits.find(q => { const rp = repos[q.repo];
      return rp.pub && (rp.owner + '/' + rp.name).toLowerCase() === wholeApp.repo; });
    if (oneOf) { show(address(oneOf.k0)); await new Promise(r => setTimeout(r, 150));
      const r3 = card.querySelector('.cc-app'), d3 = r3 && r3.tagName === 'A' ? r3 : null;
      T.a_whole_repository_application_says = r3 ? r3.textContent.slice(0, 70) : null;
      T.T25_a_repository_that_is_one_application_is_proved_by_the_repository = !!d3 && d3.href === wholeApp.live; }
    else T.T25_a_repository_that_is_one_application_is_proved_by_the_repository = true; }
  // THE CARD AS THE PERSON WHO SIGNS FIRST MEETS IT: the code closed. The application is the first
  // and biggest thing and the whole of it is the door; the brand block is GridAtlas's own; one plain
  // line says what was done and when; and above the closed code there is not one word a banker would
  // not use.
  { codeOpen = false;
    const x = cards.find(q => { const ap = (appFor(q.owner, q.repo, q.path) || {}).app; return ap && q.page && q.page.address === ap.live; })
           || cards.find(q => (appFor(q.owner, q.repo, q.path) || {}).app) || c;
    show(address(x.k0 + Math.floor(x.lines / 2))); await new Promise(r => setTimeout(r, 250));
    const tile = card.querySelector('a.cc-tile'), det = card.querySelector('details.cc-q');
    const name = tile && tile.querySelector('.cc-tile-name'), open = tile && tile.querySelector('.cc-tile-open');
    const first = Array.from(card.children).filter(k => !k.classList.contains('cc-x'))[0];
    const biggest = name ? parseFloat(getComputedStyle(name).fontSize) : 0;
    let others = 0; for (const e of card.querySelectorAll('*')) if (e !== name && !e.contains(name) && e.getClientRects().length && e.textContent.trim())
      others = Math.max(others, parseFloat(getComputedStyle(e).fontSize) || 0);
    T.the_tile_says = tile ? tile.textContent.replace(/\s+/g, ' ').slice(0, 140) : null;
    // the tile is the first thing in the head, and the head is the first thing in the card
    T.T30_the_application_is_the_first_and_biggest_thing_and_the_whole_tile_opens_it = !!tile && (first === tile || (first.classList.contains('cc-head') && first.firstElementChild === tile))
      && on(tile) && on(open) && biggest > others && /^OPEN /.test(open.textContent)
      && tile.href === ((appFor(x.owner, x.repo, x.path) || {}).app || {}).live;
    T.T31_the_application_says_what_it_does_for_a_project = !!tile && !!tile.querySelector('.cc-tile-what')
      && tile.querySelector('.cc-tile-what').textContent.length > 20;
    const b = card.querySelector('.scada-brand');
    T.T32_the_brand_block_is_gridatlas_own = !!b && b.querySelector('.scada-brand-main').textContent === 'Ventus'
      && b.querySelector('.scada-brand-sub').textContent === 'Cables & Connectivity\u00ae' && on(b);
    T.T33_the_code_is_closed_until_asked_for = !!det && det.open === false && !on(card.querySelector('.cc-code'))
      && det.querySelector('summary').textContent === 'See the code behind this';
    // every word above the closed code, as a reader sees it
    let above = ''; for (const k of card.children) { if (k === det) break; above += ' ' + k.textContent; }
    T.words_above_the_code = above.replace(/\s+/g, ' ').trim().slice(0, 200);
    T.coder_words_above_the_code = ['commit', 'key', 'repository', 'path', 'line ', 'piece of work'].filter(w => above.toLowerCase().indexOf(w) >= 0);
    T.T34_no_word_above_the_code_that_a_banker_would_not_use = T.coder_words_above_the_code.length === 0
      && /(?<!\d)\d{1,2} [A-Z][a-z]{2} \d{4}(?!\d)/.test(above);
    det.open = true; await new Promise(r => setTimeout(r, 200));
    T.T35_one_tap_opens_the_code_with_the_line_marked = on(card.querySelector('.cc-code'))
      && !!cardShown && !!cardShown.window && Math.abs(parseFloat(cardShown.window.bar.style.top) || -1) >= 0; }
  // NO CARD IS A DEAD END, AND NO LINK IS A SENTENCE. With an application: its tile, and GitHub as one
  // word. Without one: the site itself, and GitHub as one word. Never a link that reads like a paragraph.
  { codeOpen = false;
    const noApp = commits.find(q => { const rp = repos[q.repo]; return rp.pub && !appFor(rp.owner, rp.name, null) && !pageOfWork[q.sha]; });
    if (noApp) { show(address(noApp.k0)); await new Promise(r => setTimeout(r, 150));
      const hm = card.querySelector('.cc-links a.cc-home');
      T.a_card_with_no_application_offers = Array.from(card.querySelectorAll('.cc-links a')).map(x => x.textContent);
      const wantDoor = frontOfWork[noApp.sha] || 'https://www.globalgrid2050.com/';
      T.T36_a_card_with_nothing_else_offers_the_site = !!hm && hm.href === wantDoor && on(hm)
        && card.textContent.indexOf('This work has no page of its own yet.') >= 0; }
    else T.T36_a_card_with_nothing_else_offers_the_site = true;
    const longest = Array.from(card.querySelectorAll('a:not(.cc-tile)')).reduce((m, x) => Math.max(m, x.textContent.trim().split(/\s+/).length), 0);
    T.T37_no_link_reads_like_a_sentence = longest <= 3;
    // and the drawing engine's work leads to the London Underground, the example that was missed
    const ug = apps.find(q => q.app === 'underground'), uc = ug && commits.find(q => { const rp = repos[q.repo];
      return (rp.owner + '/' + rp.name).toLowerCase() === ug.repo; });
    if (uc) { show(address(uc.k0)); await new Promise(r => setTimeout(r, 150));
      const t2 = card.querySelector('a.cc-tile');
      T.the_drawing_engine_leads_to = t2 ? t2.textContent.slice(0, 60) : null;
      T.T38_the_drawing_engine_leads_to_the_london_underground = !!t2 && t2.href === ug.live && on(t2); }
    else T.T38_the_drawing_engine_leads_to_the_london_underground = false; }
  // THE NEAREST PAGE. A program opens the page of its own folder, named by that page's own title; a
  // page that still stands opens ITSELF and not its application's front door; GitHub is one grey word
  // at the very bottom of the fold; and the honest count of where the whole record lands is kept.
  { codeOpen = false;
    const prog = cards.find(q => q.path === 'cable_geometry/app.js');
    if (prog) { show(address(prog.k0 + 609)); await new Promise(r => setTimeout(r, 200));
      const t = card.querySelector('a.cc-tile'), nm = t && t.querySelector('.cc-tile-name'), pt = t && t.querySelector('.cc-tile-part');
      T.a_program_leads_to = t ? [t.href, nm && nm.textContent, pt && pt.textContent] : null;
      T.T39_a_program_opens_the_page_of_its_own_folder_by_its_title = !!t && t.href === 'https://globalgrid2050.com/cable_geometry/'
        && !!nm && nm.textContent === prog.page.title && nm.textContent.length > 3 && !!pt && pt.textContent === 'part of CABLES'
        && t.querySelector('.cc-tile-open').textContent === 'OPEN THIS PAGE' && on(t); }
    else T.T39_a_program_opens_the_page_of_its_own_folder_by_its_title = false;
    // a piece of work whose code is NOT carried still lands on a page, by the agreement of its files
    const plain = commits.find(q => pageOfWork[q.sha] && !cardFor(q.k0) && repos[q.repo].pub);
    if (plain) { show(address(plain.k0)); await new Promise(r => setTimeout(r, 150));
      const t = card.querySelector('a.cc-tile');
      T.an_uncarried_piece_of_work_leads_to = t ? t.href : null;
      T.T40_work_whose_code_is_not_carried_still_lands_on_a_page = !!t && t.href === pageOfWork[plain.sha].address && on(t); }
    else T.T40_work_whose_code_is_not_carried_still_lands_on_a_page = false;
    // GitHub, humble
    const det = card.querySelector('details.cc-q'); let outside = '';
    for (const k of card.children) if (k !== det) outside += ' ' + k.textContent;
    const last = det && det.lastElementChild, sa = last && last.querySelector('a');
    T.T41_github_is_one_grey_word_at_the_bottom_of_the_fold = !/github/i.test(outside) && !!last
      && last.classList.contains('cc-source') && !!sa && sa.textContent === 'source' && /github\.com/.test(sa.href);
    // where the whole record lands, counted here and not claimed
    const lands = { a_page_of_its_own:0, an_application:0, a_front_door:0, not_public:0 };
    for (const q of commits) { const rp = repos[q.repo];
      if (!rp.pub) lands.not_public++; else if (pageOfWork[q.sha]) lands.a_page_of_its_own++;
      else if ((appFor(rp.owner, rp.name, null) || {}).app) lands.an_application++; else lands.a_front_door++; }
    T.where_the_whole_record_lands = lands;
    // THE PARTS MUST MAKE THE WHOLE, AND A PAGE OF ONE'S OWN IS NEVER THE TOP OF A SITE. The last
    // version's note said three quarters; the true figure is about a fifth, because a walk that ends
    // at the top of a site had been counted as finding a page.
    const tops = Object.keys(pageById).map(i => pageById[i].address).filter(u => /^https?:\/\/[^/]+\/?$/.test(u)
      || /^https?:\/\/ventusltd\.github\.io\/[^/]+\/?$/.test(u) || Object.keys(frontOfWork).some(k => frontOfWork[k] === u));
    T.pages_of_their_own_that_are_really_a_site_top = tops.slice(0, 5);
    T.T42_the_parts_make_the_whole_and_no_own_page_is_a_site_top = tops.length === 0 && lands.a_page_of_its_own > 0
      && lands.a_page_of_its_own + lands.an_application + lands.a_front_door + lands.not_public === commits.length; }
  // THE HEADER IS THE HEADER. With the code OPEN, the application tile is still at the top of the card and can
  // still be pressed, the code window begins BELOW it, and the marked line is in view. Asked at this size.
  { codeOpen = true; const x = cards.find(q => (appFor(q.owner, q.repo, q.path) || {}).app) || c;
    show(address(x.k0 + Math.floor(x.lines / 2)));
    for (let i = 0; i < 60 && !(cardShown && cardShown.window); i++) await new Promise(r => setTimeout(r, 100));
    await new Promise(r => setTimeout(r, 250));
    const tile = card.querySelector('a.cc-tile'), pre = card.querySelector('.cc-code'), op = tile && tile.querySelector('.cc-tile-open');
    const tr = tile && tile.getBoundingClientRect(), pr = pre && pre.getBoundingClientRect(), cr = card.getBoundingClientRect();
    T.with_the_code_open = { card:[Math.round(cr.top), Math.round(cr.bottom)], tile:tr && [Math.round(tr.top), Math.round(tr.bottom)], code:pr && [Math.round(pr.top), Math.round(pr.bottom)] };
    const w = cardShown && cardShown.window, lh = pre ? parseFloat(getComputedStyle(pre).lineHeight) || 16 : 16;
    const markY = pre && w ? pr.top + (w.at - w.first) * lh - pre.scrollTop : -1;
    T.T33_with_the_code_open_the_application_tile_is_still_there_to_press = !!tile && on(op) && tr.top >= cr.top - 1;
    T.T34_the_code_begins_below_the_head_and_the_marked_line_is_in_view = !!pre && pr.top >= tr.bottom - 1 && pr.bottom <= cr.bottom + 1
      && markY >= pr.top - 1 && markY <= pr.bottom - lh + 2; }
  // HOW MUCH OF THE RECORD NOW SHOWS REAL CODE, MEASURED AND NOT CLAIMED: 200 taps chosen by a fixed seed,
  // uniform over every line ever written, as RANDOM LINE chooses; a tap shows code when its file is carried
  // here or its piece of work changed code the table names. And RANDOM LINE itself must show code, or say why.
  { let seed = 20260920; const rnd = () => (seed = (seed * 1664525 + 1013904223) >>> 0) / 4294967296; let yes = 0, carried = 0, notPublic = 0;
    for (let i = 0; i < 200; i++) { const j = Math.floor(rnd() * N), cc = commits[findBy('cum', j)], k = cc.k0 + (j - cc.cum);
      if (!repos[cc.repo].pub) { notPublic++; continue; } if (cardFor(k)) { carried++; yes++; } else if (table && table[cc.sha]) yes++; }
    T.of_200_seeded_taps = { show_code:yes, of_which_carried_here:carried, not_public:notPublic };
    T.T32_most_taps_show_real_code = yes >= 120; }
  T.sample_line = want === null ? null : String(want).slice(0, 80);
  T.PASS = T.T1_the_card_opened_for_that_key && T.T2_the_line_shown_is_the_line_that_file_holds
        && T.T3_that_exact_text_is_on_the_screen && T.T4_it_is_the_marked_line
        && T.T5_the_card_is_on_the_screen && T.T6_a_dot_with_no_carried_file_shows_the_code_its_work_changed && T.T32_most_taps_show_real_code
        && T.T33_with_the_code_open_the_application_tile_is_still_there_to_press && T.T34_the_code_begins_below_the_head_and_the_marked_line_is_in_view
        && T.T7_the_github_link_is_on_the_screen && T.T8_ten_lines_below_are_there_and_five_are_on_the_screen
        && T.T9_no_code_line_runs_off_the_right_edge && T.T10_the_header_says_what_day_the_work_was_done
        && T.T11_it_says_the_work_the_day_and_where_to_see_it
        && T.T12_no_arithmetic_and_no_command_anywhere_on_the_page
        && T.T13_a_gap_leads_to_the_next_work && T.T14_an_empty_readout_draws_no_box
        && T.T15_a_link_this_page_built_parses_back_to_what_it_asked_for
        && T.T16_no_address_is_typed_by_hand_in_this_page
        && T.T17_the_arrow_ends_on_the_dot && T.T18_it_is_shot_from_the_centre_of_the_record
        && T.T19_and_then_the_card_opens && T.T20_an_address_it_cannot_answer_is_answered_in_words
        && T.T21_the_state_chip_says_OK_and_only_one_thing
        && T.T22_the_card_says_which_application_and_opens_it
        && T.T23_every_carried_file_gets_the_application_its_folder_proves
        && T.T24_where_nothing_is_proved_there_is_no_door
        && T.T25_a_repository_that_is_one_application_is_proved_by_the_repository
        && T.T26_a_carried_file_no_application_claims_gets_no_door
        && T.T27_the_page_and_the_tool_agree_on_every_file_and_every_count
        && T.T28_the_cables_line_opens_cables_above_the_code_without_scrolling
        && T.T29_a_gridatlas_line_opens_gridatlas_above_the_code_without_scrolling
        && T.T30_the_application_is_the_first_and_biggest_thing_and_the_whole_tile_opens_it
        && T.T31_the_application_says_what_it_does_for_a_project && T.T32_the_brand_block_is_gridatlas_own
        && T.T33_the_code_is_closed_until_asked_for && T.T34_no_word_above_the_code_that_a_banker_would_not_use
        && T.T35_one_tap_opens_the_code_with_the_line_marked
        && T.T36_a_card_with_nothing_else_offers_the_site && T.T37_no_link_reads_like_a_sentence
        && T.T38_the_drawing_engine_leads_to_the_london_underground
        && T.T39_a_program_opens_the_page_of_its_own_folder_by_its_title
        && T.T40_work_whose_code_is_not_carried_still_lands_on_a_page
        && T.T41_github_is_one_grey_word_at_the_bottom_of_the_fold
        && T.T42_the_parts_make_the_whole_and_no_own_page_is_a_site_top;
  window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}

// LIGHT A REPOSITORY, TESTED. ?selftest=repo:<name>, or repo:* for the largest one. Two questions.
// ONE, the picture: walking outward from the centre, a pixel is green if and only if the key at
// that pixel's centre belongs to that repository. A pixel whose radial span straddles a change of
// owner is excluded and counted separately, because at this zoom one pixel covers hundreds of
// millions of addresses and the shader and this loop need not agree on which side of the line it
// falls. Every other pixel must agree exactly.
// TWO, the number: the repository's line total added up through the running totals, which is the
// arithmetic the shading itself is made of, must equal the direct sum of its commits, and both
// must equal what cosmos/repos.tsv declared before any of this was drawn. Three sources, one
// number, or the test fails.
function repoSelftest(name){
  const rp = (name === '*') ? repos.reduce((a, b) => b.lines > a.lines ? b : a)
                            : repos.find(x => x.name.toLowerCase() === name.toLowerCase());
  if (!rp) { window.__selftest = { PASS:false, asked_for:name, error:'no repository of that name is on this wafer' };
    document.title = 'selftest FAIL'; return; }
  let byRunning = 0, directly = 0, n = 0;
  for (const c of commits) if (c.repo === rp.i) { byRunning += issuedBelow(c.k1) - issuedBelow(c.k0); directly += c.lines; n++; }
  litRepo = rp.i; litK = [-1,-1]; litCi = null; newFrom = -1; flash = 0; pulse = -1; target = null; card.style.display = 'none';
  tween = null; { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; } draw();
  const W = cv.width, H = cv.height, Rpx = Math.sqrt(SPACE)*zoom;
  const col0 = Math.round(W/2 - cx*zoom), row0 = Math.round(H/2 - cy*zoom);   // the wafer's own centre, in GL pixels
  const span = Math.max(4, Math.floor(Rpx) - 1);
  const strip = (x, y, w, h) => { const b = new Uint8Array(w*h*4); gl.readPixels(x, y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, b); return b; };
  const east = strip(col0, row0, span, 1), north = strip(col0, row0, 1, span);
  let lit = 0, dark = 0, wrong = 0, straddled = 0; const wrongAt = [];
  function check(buf, i, wx, wy, hx, hy, where){
    const own = ownerAt(Math.hypot(wx, wy));
    if (ownerAt(Math.hypot(wx-hx, wy-hy)) !== own || ownerAt(Math.hypot(wx+hx, wy+hy)) !== own) { straddled++; return; }
    const r0 = buf[i*4], g0 = buf[i*4+1], b0 = buf[i*4+2];
    const green = g0 > 120 && g0 > r0 + 40 && g0 > b0 + 30;
    if (green === (own === rp.i)) { green ? lit++ : dark++; }
    else { wrong++; if (wrongAt.length < 8) wrongAt.push({ strip:where, pixel_from_centre:i,
      key_belongs_to: own === -1 ? 'silence' : (own === -2 ? 'beyond the rim' : repos[own].name),
      drawn: green ? 'green' : 'not green', rgb:[r0, g0, b0] }); }
  }
  const hudWhenLit = hud.textContent;                 // what the page told the reader while it was lit
  const wy0 = cy + (row0 + 0.5 - H/2)/zoom, wx0 = cx + (col0 + 0.5 - W/2)/zoom, h = 0.5/zoom;
  for (let i = 0; i < span; i++) check(east, i, cx + (col0 + i + 0.5 - W/2)/zoom, wy0, h, 0, 'east');
  for (let i = 0; i < span; i++) check(north, i, wx0, cy + (row0 + i + 0.5 - H/2)/zoom, 0, h, 'north');
  { const hm = homeCamera(); cx = hm.x; cy = hm.y; zoom = hm.z; litRepo = -1; dirty = true; draw(); }
  const wpx = widestRunPx(rp.i, Rpx/Math.sqrt(SPACE));
  const tooSmall = wpx < 1;
  const said = /FINER THAN ONE PIXEL/.test(hudWhenLit);
  const T = { repository: rp.name, commits: n, viewport:[W, H], wafer_radius_px: Math.round(Rpx), pixels_walked: 2*span,
    // A pixel is green if and only if the key at its centre belongs to this repository. Nothing
    // else is asserted: a repository under a pixel wide lights nothing, and the second test is
    // that the page says that out loud instead of showing an empty wafer and letting it pass.
    T1_no_pixel_disagrees_with_the_keys: wrong === 0,
    T2_it_lights_pixels_or_the_page_says_it_is_too_small: lit > 0 || (tooSmall && said),
    widest_unbroken_run_px_at_this_zoom: +wpx.toFixed(4), finer_than_one_pixel: tooSmall, the_page_said_so: said,
    pixels: { green_and_owned_by_it: lit, not_green_and_not_owned_by_it: dark, disagreed: wrong, straddled_a_boundary_and_excluded: straddled },
    first_disagreements: wrongAt,
    T3_running_totals_equal_the_direct_sum: byRunning === directly,
    T4_and_equal_what_the_belt_declared: directly === rp.lines,
    lines_by_running_totals: byRunning, lines_added_directly: directly, lines_declared_by_the_belt: rp.lines };
  T.PASS = T.T1_no_pixel_disagrees_with_the_keys && T.T2_it_lights_pixels_or_the_page_says_it_is_too_small
        && T.T3_running_totals_equal_the_direct_sum && T.T4_and_equal_what_the_belt_declared;
  window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// THE PHONE TEST, run by the page on itself with ?selftest=phone at whatever size the window is.
// It states that size, so the verdict is about a real viewport and not about a claim. Three
// mechanical questions: does any permanent panel cover the wafer, does the card fit on the screen,
// and do a drag and a two finger pinch actually move the camera when the events are dispatched.
function phoneSelftest(){
  tween = null; { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; } draw();
  const W = innerWidth, H = innerHeight, Rpx = Math.sqrt(SPACE)*zoom;
  const scx = (0 - cx)*zoom + W/2, scy = H/2 + cy*zoom;          // where the wafer's centre really is on screen
  const panels = []; let worst = 1e9;
  for (const id of ['top','hud','foot']) { const r = document.getElementById(id).getBoundingClientRect();
    const qx = Math.max(r.left, Math.min(scx, r.right)), qy = Math.max(r.top, Math.min(scy, r.bottom));
    const clear = Math.hypot(qx - scx, qy - scy) - Rpx;          // nearest point of the panel, less the rim radius
    panels.push({ panel:id, rect:[r.left, r.top, r.right, r.bottom].map(Math.round), clear_of_the_rim_px:Math.round(clear) });
    worst = Math.min(worst, clear); }
  const onScreen = scx - Rpx >= -0.5 && scx + Rpx <= W + 0.5 && scy - Rpx >= -0.5 && scy + Rpx <= H + 0.5;
  show(address(Math.floor(N/2))); layout();
  const cr = card.getBoundingClientRect();
  const cardFits = cr.left >= -0.5 && cr.top >= -0.5 && cr.right <= W + 0.5 && cr.bottom <= H + 0.5 && cr.width > 40 && cr.height > 20;
  const ev = (t, id, x, y) => cv.dispatchEvent(new PointerEvent(t, { pointerId:id, clientX:x, clientY:y, bubbles:true, pointerType:'touch' }));
  const z0 = zoom, cx0 = cx;                                     // one finger: the world must follow it
  ev('pointerdown', 11, Math.round(W*0.5), Math.round(H*0.5)); ev('pointermove', 11, Math.round(W*0.5) + 60, Math.round(H*0.5));
  const dragged = cx0 - cx; ev('pointerup', 11, Math.round(W*0.5) + 60, Math.round(H*0.5));
  const zA = zoom;                                               // two fingers: the distance between them must set the zoom
  ev('pointerdown', 21, Math.round(W*0.35), Math.round(H*0.5)); ev('pointerdown', 22, Math.round(W*0.65), Math.round(H*0.5));
  const spread = Math.round(W*0.65) - Math.round(W*0.35);
  ev('pointermove', 22, Math.round(W*0.35) + 2*spread, Math.round(H*0.5));
  const zB = zoom; ev('pointerup', 21, 0, 0); ev('pointerup', 22, 0, 0);
  // put the wafer back the way it was found: the test's own light is not part of the record
  { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; atHome = true; litRepo = -1; target = null;
    card.style.display = 'none'; dirty = true; draw(); }
  // THE PUBLIC FACE, CHECKED ON THE FACE ITSELF. Functions, use cases and disclaimers: what a person
  // can do here, what it is for, and what it is not. The placement law, the angle and the unresolved
  // pixels are engineering notes and belong in the repository, not in front of a reader.
  // PRESENT IS NOT THE SAME AS VISIBLE. textContent returns words that are set to display:none as
  // happily as words on the screen, so every check passed while a phone showed no disclaimer at all.
  // Ask the layout instead: a node with no client rectangles is not in front of anybody.
  const seen = el => { if (!el) return ''; let out = '';
    const walk = n => { if (n.nodeType === 3) { const r = document.createRange(); r.selectNodeContents(n);
        if (r.getClientRects().length) out += ' ' + n.nodeValue; return; }
      if (n.nodeType !== 1 || !n.getClientRects().length) return;
      for (const c of n.childNodes) walk(c); };
    walk(el); return out.replace(/\s+/g, ' ').trim().toLowerCase(); };
  const faceSeen = seen(document.getElementById('foot')) + ' ' + seen(document.getElementById('top'));
  // NOTHING MAY RUN OFF THE RIGHT EDGE. A box whose content is wider than the box itself is a box
  // with words hidden in it, which is how a cut disclaimer looks to everyone except a test.
  const overflows = [];
  for (const id of ['top','hud','foot','card']) { const el = document.getElementById(id);
    if (el && el.getClientRects().length && el.scrollWidth > el.clientWidth + 1)
      overflows.push({ panel:id, content_px:el.scrollWidth, box_px:el.clientWidth }); }
  const face = (document.getElementById('foot').textContent + ' ' + document.getElementById('top').textContent).toLowerCase();
  const T = { viewport:[W, H], narrow_layout:narrow(), wafer_centre_on_screen:[Math.round(scx), Math.round(scy)], wafer_radius_px:Math.round(Rpx),
    T7_the_face_carries_the_disclaimer: face.indexOf('without warranty of any kind') >= 0,
    T9_the_disclaimer_is_actually_on_the_screen: faceSeen.indexOf('without warranty of any kind') >= 0,
    T10_nothing_is_cut_off_at_the_right_edge: overflows.length === 0, panels_that_overflow: overflows,
    visible_face_words: faceSeen.length,
    T8_the_face_explains_no_machinery: !/golden|one law|√|sqrt|unresolved pixel/.test(face),
    T1_no_permanent_panel_covers_the_wafer: worst >= 0, panels,
    T2_the_whole_wafer_is_on_the_screen: onScreen,
    T3_the_card_fits: cardFits, card_rect:[cr.left, cr.top, cr.right, cr.bottom].map(Math.round),
    T4_one_finger_drags: Math.abs(dragged - 60/z0) < 1e-6, dragged_world_units:+dragged.toFixed(6), expected_world_units:+(60/z0).toFixed(6),
    T5_two_fingers_pinch: zB > zA*1.8 && zB <= ZMAX + 1e-9, zoom_before_pinch:+zA.toFixed(6), zoom_after_pinch:+zB.toFixed(6) };
  T.PASS = T.T1_no_permanent_panel_covers_the_wafer && T.T2_the_whole_wafer_is_on_the_screen && T.T3_the_card_fits
        && T.T4_one_finger_drags && T.T5_two_fingers_pinch;
  T.PASS = T.PASS && T.T7_the_face_carries_the_disclaimer && T.T8_the_face_explains_no_machinery
        && T.T9_the_disclaimer_is_actually_on_the_screen && T.T10_nothing_is_cut_off_at_the_right_edge;
  window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// LIGHT A PERIOD. "2026-07" or "2026-07-14". Time order makes it one band, so the count is a
// difference of two running totals and the light is one annulus.
function lightTime(y, m, d){
  endIsolate();
  const t0 = Date.UTC(y, m ? m-1 : 0, d || 1)/1000, t1 = d ? t0 + 86400 : Date.UTC(m ? y : y+1, m ? m : 0, 1)/1000;
  const i0 = (commits[0].unix >= t0) ? 0 : findBy('unix', t0 - 1) + 1, i1 = (commits[0].unix >= t1) ? 0 : findBy('unix', t1 - 1) + 1;
  const label = y + (m ? '-' + String(m).padStart(2,'0') : '') + (d ? '-' + String(d).padStart(2,'0') : '');
  litRepo = -1; newFrom = -1; flash = 0; target = null; card.style.display = 'block';
  if (i1 <= i0) { litK = [-1,-1]; litCi = null; card.classList.remove('sheet'), card.innerHTML = label + '\nsilence: no commit carries that date'; home(); dirty = true; return null; }
  const last = commits[i1-1], lines = last.cum + last.lines - commits[i0].cum, rs = new Set(); for (let i = i0; i < i1; i++) rs.add(commits[i].repo);
  litK = [Math.sqrt(commits[i0].k0), Math.sqrt(last.k1)]; litCi = [i0, i1];
  card.classList.remove('sheet'), card.innerHTML = 'ENERGISED · ' + label + '\n<b>' + fmt(lines) + '</b> lines in <b>' + fmt(i1 - i0) + '</b> commits across ' + rs.size + ' repositories'
    + '\nkeys ' + fmt(commits[i0].k0) + ' to ' + fmt(last.k1) + ' · one band, because keys run in time order';
  home(); dirty = true; return { i0, i1, lines };
}
// TOUCH. Every pointer that is down is held in one map, so one finger drags and two pinch, and a
// mouse is just a pointer with one finger. The pinch keeps the world point between the fingers
// under the fingers, which is the same rule the wheel already obeys, so zooming in on a phone and
// on a desktop land on the same key.
const ZMAX = 60;
let drag = null, moved = 0, pinch = null;
const pts = new Map();
function pinchNow(){ const v = [...pts.values()], a = v[0], b = v[1];
  return { d:Math.hypot(a.x-b.x, a.y-b.y), mx:(a.x+b.x)/2, my:(a.y+b.y)/2 }; }
cv.addEventListener('pointerdown', e => {
  pts.set(e.pointerId, { x:e.clientX, y:e.clientY });
  if (pts.size === 2) { const s = pinchNow(), w = toWorld(s.mx, s.my); pinch = { d0:s.d, z0:zoom, wx:w[0], wy:w[1] }; drag = null; moved = 99; }
  else if (pts.size === 1) { drag = [e.clientX, e.clientY]; moved = 0; }
});
addEventListener('pointermove', e => {
  if (pts.has(e.pointerId)) pts.set(e.pointerId, { x:e.clientX, y:e.clientY });
  if (pinch && pts.size >= 2) { const s = pinchNow(); if (pinch.d0 > 1) {
      zoom = Math.max(1e-4, Math.min(ZMAX, pinch.z0 * s.d / pinch.d0));
      cx = pinch.wx - (s.mx - innerWidth/2)/zoom; cy = pinch.wy + (s.my - innerHeight/2)/zoom;
      atHome = false; tween = null; dirty = true; } return; }
  if (!drag) return; moved += Math.abs(e.clientX-drag[0]) + Math.abs(e.clientY-drag[1]);
  cx -= (e.clientX-drag[0])/zoom; cy += (e.clientY-drag[1])/zoom; drag = [e.clientX, e.clientY];
  atHome = false; tween = null; dirty = true; });
function pointerGone(e){ pts.delete(e.pointerId); if (pts.size < 2) pinch = null; if (pts.size === 0) drag = null; }