Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 6b10129f9ede6d79565e996ce280a8dcf18c0b92
parent 963067a91691834050a71cc2e94c035e8ca790a2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 22:19:55 -0500

Merge fix/posts-embed: the posts preview plans again in a built umtool -- the page's embedded planner takes the first-frame fold as a parameter, a test holds every embedded function to its own body, and three specs follow the code

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mumtool/e2e/inbox.spec.ts | 10+++++++++-
Mumtool/e2e/instruments.spec.ts | 5++++-
Mumtool/e2e/takes.spec.ts | 5+++--
Mumtool/report-to-video/README.md | 7+++++--
Mumtool/report-to-video/chrome-posts.mjs | 42+++++++++++++++++++++++++++++++++---------
Mumtool/report-to-video/chrome-posts.test.mjs | 8++++----
Mumtool/report-to-video/cue-start.mjs | 4++--
Aumtool/report-to-video/embedded-source.test.mjs | 173+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 233 insertions(+), 21 deletions(-)

diff --git a/umtool/e2e/inbox.spec.ts b/umtool/e2e/inbox.spec.ts @@ -46,7 +46,15 @@ test("the big count is the cards in the five call groups; the groups come in the // cards too; on the fixture with nothing probed there are none to count on. const machine = await page.locator("[data-card^='machine-']").count(); await expect(page.locator("[data-inbox-count]")).toHaveAttribute("data-inbox-count", String(calls + machine)); - await expect(page.locator("[data-rail-count=inbox]")).toHaveText(String(calls + machine)); + // The rail's count is memoised for a few seconds (lib/rail.ts) and asked once per page load: one + // filled before the fixture's last write (the warm-up asks /api/rail) is that much behind, so a + // rail that disagrees is asked again once the memo has lapsed. + const rail = page.locator("[data-rail-count=inbox]"); + await expect(async () => { + await expect(rail).toHaveText(/^\d+$/); + if ((await rail.textContent()) !== String(calls + machine)) await page.reload(); + await expect(rail).toHaveText(String(calls + machine), { timeout: 2_000 }); + }).toPass({ timeout: 25_000 }); await expect(page.locator("[data-inbox-note]")).toContainText("quiet"); const shown = await page.locator("[data-lit-list] [data-group]").evaluateAll((els) => els.map((e) => e.getAttribute("data-group"))); diff --git a/umtool/e2e/instruments.spec.ts b/umtool/e2e/instruments.spec.ts @@ -158,7 +158,10 @@ test("the odometer and the trail post ready and seek: the wheels only roll up, t await trail.seek(0.3); await expect.poll(shown).toBe(0); await trail.seek(tEnd()); - await expect.poll(shown).toBe(3); + // Every weight said so far: the three stated (>240, <300, 291.5) and the remembered ≈390, hollow, at its as-of date. + await expect.poll(shown).toBe(4); + const remembered = () => trail.frame.locator(".pt.rem").evaluateAll((ps) => ps.filter((p) => Number(getComputedStyle(p).opacity) > 0.5).length); + await expect.poll(remembered).toBe(1); await expect(trail.frame.locator('[data-k="uc1"]')).toContainText("UNDER 300 · SAID 2×"); await expect(trail.frame.locator('[data-k="uc1"]')).toBeVisible(); }); diff --git a/umtool/e2e/takes.spec.ts b/umtool/e2e/takes.spec.ts @@ -278,8 +278,9 @@ test("Give renders the machine: the take runs with --priority, holds the lane it await expect .poll(async () => ((await (await request.get(`/api/report/takes/make?job=${job.id}`)).json()) as { state: string }).state, { timeout: 180_000 }) .toBe("done"); - // The stub's download lane was held already: left alone, never released. - expect(laneAsks().slice(before)).toEqual(["transcription:true", "transcription:false"]); + // The stub's download lane was held already: left alone, never released. Transcription and the + // Speakers (backfill) lane were free: held for the take, and let go (RENDER_MODE_LANES). + expect(laneAsks().slice(before)).toEqual(["transcription:true", "backfill:true", "transcription:false", "backfill:false"]); expect(existsSync(STATE)).toBe(false); // While a render holds it, the panel says so (this process is the holder: alive). diff --git a/umtool/report-to-video/README.md b/umtool/report-to-video/README.md @@ -2601,8 +2601,11 @@ node umtool/report-to-video/compose-chrome.mjs <manifest.json> --region posts -- - **The stack is planned in the page.** Whether the next card overflows the column depends on how its words wrap in the deck's face, so the page measures the cards once the fonts are in and hands the heights to - `postsCues` — the module's own function, carried in by its source text, so - the tests run the exact plan the page runs. The timeline is built and + `postsPlan` — the module's own function, carried in by its source text, so + the tests run the exact plan the page runs. An embedded function reaches + nothing outside its own body (a built umtool minifies every module-scope + name), so the first-frame fold is handed to it as a parameter; + `embedded-source.test.mjs` holds every function a page carries to that. The timeline is built and registered in that callback; the renderer awaits `document.fonts.ready` before its first seek. - **The overlay:** each window is an input with `-itsoffset <from>` (negative diff --git a/umtool/report-to-video/chrome-posts.mjs b/umtool/report-to-video/chrome-posts.mjs @@ -22,8 +22,9 @@ // and whether one would overflow depends on how tall each card is, which is // how its words wrap in the deck's own face. Only the browser knows that, and // only once the faces are in. So the page measures every card after the fonts -// load and hands the heights to `postsCues` -- THIS module's function, written -// into the page by its source text. The plan (every cue, its from, its time) +// load and hands the heights to `postsPlan` -- THIS module's function, written +// into the page by its source text (`postsCues` here is the same function, with +// the first-frame fold handed in). The plan (every cue, its from, its time) // is the same function the tests call with heights of their choosing; the // browser holds no logic a test cannot see. The timeline is built, and then // registered, inside that fonts-loaded callback: the renderer awaits @@ -80,6 +81,16 @@ export function windowPosts(schedule, segment) { * production build turned `postsCues` into `d`, and the page then threw a * ReferenceError and drew nothing). As a named const of a parenthesised * function expression, the page's name never depends on the module's. + * + * The name is half of it. The text is the function's BODY as the bundler left + * it, so a module-scope name the body uses (an import, a constant, a helper) + * is the minified one there too, and nothing in the page is called that: 11 + * Nov, `postsCues` called `settleFirstFrame` and the built app's page threw + * `h is not defined`, though it embedded `settleFirstFrame` under its own + * name. An embedded function reaches NOTHING outside its own body but the + * language's globals (and, a page function, the DOM's); what it needs of the + * module is a PARAMETER, handed over by the page under the embedded name. + * embedded-source.test.mjs holds every embedded function to that. */ export function embedFn(name, fn) { return `const ${name} = (${fn.toString()});`; @@ -88,7 +99,10 @@ export function embedFn(name, fn) { /** * Everything the posts timeline does, as data. PURE and SELF-CONTAINED: the * page carries this function's own source text and calls it with the heights - * it measured, so it may reference nothing outside its own body. + * it measured, so it may reference nothing outside its own body -- which is + * why the first-frame fold (cue-start.mjs settleFirstFrame) is its second + * PARAMETER, `settle`, and not the import (embedFn). Module callers use + * `postsCues`, which hands it in. * * `posts` are `[{ id, appear, out: [a, b] }]` in slot order (oldest first), * times in the CUT's clock; `heights` are the cards' heights in px; `column` @@ -110,10 +124,10 @@ export function embedFn(name, fn) { * @returns {{ tops: number[], init: Record<string, object>, * cues: Array<{ k: string, at: number, dur: number, from: object, to: object, ease: string, why: string }> }} */ -export function postsCues({ +export function postsPlan({ posts, heights, column, gap = 14, enter = 0.55, slide = 0.35, enterX = 624, glowAt = 0.3, glowUp = 0.18, glowDown = 1.1, glowRest = 0.3, pans = [], panHold = 1.2, -}) { +}, settle) { const R = (v) => Math.round(v * 10000) / 10000; const MIN = 0.001; const tops = []; @@ -196,7 +210,17 @@ export function postsCues({ // keeps every element's own order (and so every from). cues.sort((x, y) => x.at - y.at || x.n - y.n); for (const c of cues) delete c.n; - return { tops, init, cues: settleFirstFrame(init, cues) }; + return { tops, init, cues: settle(init, cues) }; +} + +/** + * `postsPlan` with the first-frame fold handed in: the posts timeline as the + * page plans it. Never embedded -- it names an import. + * + * @param {Parameters<typeof postsPlan>[0]} args + */ +export function postsCues(args) { + return postsPlan(args, settleFirstFrame); } /** A card's head: `@handle · Bluesky`, the separator in the deck's accent. */ @@ -430,7 +454,7 @@ export function postsHtml(schedule, render, window, opts = {}) { const byK = {}; for (const el of document.querySelectorAll("[data-k]")) byK[el.dataset.k] = el; ${embedFn("settleFirstFrame", settleFirstFrame)} - ${embedFn("postsCues", postsCues)} + ${embedFn("postsPlan", postsPlan)} const params = new URLSearchParams(location.search); const local = (t) => Math.max(0, Math.min(P.dur, (Number(t) || 0) - P.from)); @@ -480,9 +504,9 @@ export function postsHtml(schedule, render, window, opts = {}) { return img && !view.hasAttribute("data-crop") ? Math.max(0, Math.round(img.offsetHeight - view.clientHeight)) : 0; }); document.documentElement.dataset.pans = pans.join(","); - const plan = postsCues({ posts: P.posts, heights, pans, column: P.column, gap: P.gap, + const plan = postsPlan({ posts: P.posts, heights, pans, column: P.column, gap: P.gap, enter: P.enter, slide: P.slide, enterX: P.enterX, glowAt: P.glowAt, - glowUp: P.glowUp, glowDown: P.glowDown, glowRest: P.glowRest }); + glowUp: P.glowUp, glowDown: P.glowDown, glowRest: P.glowRest }, settleFirstFrame); cards.forEach((c, j) => { c.style.top = plan.tops[j] + "px"; }); for (const k of Object.keys(plan.init)) if (byK[k]) gsap.set(byK[k], plan.init[k]); // The cues are in the cut's clock; the window plays [from, from + dur] of it. diff --git a/umtool/report-to-video/chrome-posts.test.mjs b/umtool/report-to-video/chrome-posts.test.mjs @@ -13,7 +13,7 @@ import test from "node:test"; import { fileURLToPath } from "node:url"; import { - postDate, postParagraphs, postsCues, postsHtml, postWho, snapWindow, windowPosts, + postDate, postParagraphs, postsCues, postsHtml, postsPlan, postWho, snapWindow, windowPosts, } from "./chrome-posts.mjs"; import { postSchedule, postsGeometry, postWindows, threadShotOf, validatePosts } from "./deck.mjs"; import { postThreadFile } from "./compose-chrome.mjs"; @@ -176,7 +176,8 @@ test("the page's times are postSchedule's: data, enter and leave cues", () => { near(leave.at + leave.dur, p.out[1], `${p.id} gone`); }); // The page runs this very function, by its source. - assert.ok(html.includes(postsCues.toString())); + assert.ok(html.includes(postsPlan.toString())); + assert.match(html, /const plan = postsPlan\(\{[^;]*\}, settleFirstFrame\);/); }); test("postsCues: cards stack top-down; when the next would overflow, the oldest slide up and out", () => { @@ -454,8 +455,7 @@ test("embedFn: the page declares the planner under its own name, whatever the bu const src = embedFn("postsCues", renamed); assert.equal(new Function(`${src}; return postsCues(21);`)(), 42); // And the page the module writes uses it, not a bare toString(). - const { postsCues } = await import("./chrome-posts.mjs"); - assert.match(embedFn("postsCues", postsCues), /^const postsCues = \(function postsCues\(/); + assert.match(embedFn("postsPlan", postsPlan), /^const postsPlan = \(function postsPlan\(/); }); test("a post with a screenshot draws it in place of its text card, its QR cell kept; the page waits for it", () => { diff --git a/umtool/report-to-video/cue-start.mjs b/umtool/report-to-video/cue-start.mjs @@ -10,8 +10,8 @@ // the intro: their root is up in init and hidden by an instant cue at 0. // // LEAF: no imports, so every cue compiler can call it -- and SELF-CONTAINED -// (no module constant): the posts' page embeds postsCues, and this with it, in -// the browser (chrome-posts.mjs embedFn). +// (no module constant): the posts' page embeds postsPlan, and this with it, in +// the browser, and hands this to it as a parameter (chrome-posts.mjs embedFn). /** * Fold every cue that has finished before frame 1 and starts at the cut's diff --git a/umtool/report-to-video/embedded-source.test.mjs b/umtool/report-to-video/embedded-source.test.mjs @@ -0,0 +1,173 @@ +// A function a page carries by its SOURCE TEXT reaches nothing outside itself. +// +// Three places send a module function into a browser as text: `embedFn` +// (chrome-posts.mjs: the posts' and the feed's planners), shoot-page.mjs's +// `pageExpression`, and every `page.evaluate(fn)` (playwright sends +// `fn.toString()`). The text is the function's body as it is in the running +// process -- and in a built umtool that is the bundler's: every module-scope +// name (an import, a constant, a helper) is minified, and the page has nothing +// called that. 11 Nov: `postsCues` called `settleFirstFrame`, the built app's +// posts preview threw `ReferenceError: h is not defined`, and no unit test saw +// it, because here the name is its own. +// +// So: each embedded function's text is parsed alone and every name it does not +// declare itself must be a global of the language (or, for a page function, +// of the DOM). And the sources are scanned, so a function embedded tomorrow is +// held to it too -- or the scan fails and says to list it here. +// +// Run: node --test umtool/report-to-video/embedded-source.test.mjs + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { readdirSync, readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import ts from "typescript"; + +import { embedFn, postsCues, postsPlan } from "./chrome-posts.mjs"; +import { settleFirstFrame } from "./cue-start.mjs"; +import { pageExpression } from "./shoot-page.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); + +/** The language's own. */ +const ES = ["Array", "Boolean", "Infinity", "JSON", "Map", "Math", "NaN", "Number", "Object", "Set", "String", "isFinite", "parseFloat", "parseInt"]; +/** What a page has besides. */ +const DOM = ["document", "getComputedStyle", "window"]; + +/** + * Every function sent to a page by name: module -> its functions, and whether + * they run on a document (`dom`) or are pure. `embedFn` and `page.evaluate` + * arguments found in the sources must all be here (the scan below). + */ +const EMBEDDED = { + "chrome-posts.mjs": { fns: ["postsPlan"] }, + "cue-start.mjs": { fns: ["settleFirstFrame"] }, + "chrome-feed.mjs": { fns: ["feedCues", "feedShotRoom", "feedShotLone", "feedShotWhole"] }, + "post-clock.mjs": { dom: true, fns: ["mountClock", "setClockState", "measureClockPlace"] }, + "read-follow.mjs": { dom: true, fns: ["measureFollow", "applyFollowState"] }, + "post-link-visit.mjs": { dom: true, fns: ["applyVisitState"] }, + "post-join.mjs": { dom: true, fns: ["applyJoinState"] }, + "post-branch-map.mjs": { dom: true, fns: ["applyMapState"] }, + "post-caption.mjs": { dom: true, fns: ["mountCaptions", "measureCaptionWords", "setCaptionState"] }, + "post-slam.mjs": { dom: true, fns: ["mountSlams", "setSlamState"] }, + "post-progress.mjs": { dom: true, fns: ["mountProgress", "measureProgressPlace", "setProgressState"] }, +}; +const LISTED = new Set(Object.values(EMBEDDED).flatMap((m) => m.fns)); + +/** + * The names an expression's text uses and does not declare, by the compiler's + * own name resolution with no library at all (so `Math` is one of them). + */ +function freeNames(expr) { + const file = "/embedded.ts"; + const sf = ts.createSourceFile(file, `const __embedded = (${expr});\nexport {};\n`, ts.ScriptTarget.ES2022, true, ts.ScriptKind.TS); + const host = { + getSourceFile: (f) => (f === file ? sf : undefined), + getDefaultLibFileName: () => "lib.d.ts", + writeFile() {}, + getCurrentDirectory: () => "/", + getCanonicalFileName: (f) => f, + useCaseSensitiveFileNames: () => true, + getNewLine: () => "\n", + fileExists: (f) => f === file, + readFile: () => undefined, + }; + const program = ts.createProgram([file], { noLib: true, noEmit: true, types: [], target: ts.ScriptTarget.ES2022 }, host); + assert.deepEqual(program.getSyntacticDiagnostics(sf).map((d) => ts.flattenDiagnosticMessageText(d.messageText, "\n")), [], "the text parses"); + const names = new Set(); + for (const d of program.getSemanticDiagnostics(sf)) { + const m = /^Cannot find name '([^']+)'/.exec(ts.flattenDiagnosticMessageText(d.messageText, "\n")); + if (m) names.add(m[1]); + } + return [...names].sort(); +} + +const outside = (expr, allowed) => freeNames(expr).filter((n) => !allowed.includes(n)); + +test("freeNames: a name the text does not declare is found; its parameters, locals and own name are not", () => { + assert.deepEqual(freeNames("function f(a, { b = 1 }) { const c = a + b; return f(c) + outer + Math.max(1, helper(a)); }"), ["Math", "helper", "outer"]); + assert.deepEqual(freeNames("(a) => { for (const k of Object.keys(a)) if (typeof gone === 'undefined') return k; }"), ["Object", "gone"]); + // What the bundler makes of a module function that calls an import. + assert.deepEqual(outside("function d(a){return{cues:h(a)}}", ES), ["h"]); +}); + +for (const [mod, { fns, dom }] of Object.entries(EMBEDDED)) { + test(`${mod}: ${fns.join(", ")} -- nothing outside the function's own body but ${dom ? "the language's and the DOM's" : "the language's"} globals`, async () => { + const m = await import(`./${mod}`); + for (const name of fns) { + assert.equal(typeof m[name], "function", `${mod} exports ${name}`); + assert.deepEqual(outside(m[name].toString(), dom ? [...ES, ...DOM] : ES), [], + `${name} is sent to a page as its source text: a module-scope name in it is minified in a built umtool and undefined in the page -- hand it in as a parameter`); + } + }); +} + +test("shoot-page: the expression it sends declares every function it calls", () => { + assert.deepEqual(outside(pageExpression({ quote: "q" }), [...ES, ...DOM, "CSS"]), []); +}); + +test("the posts' page: its planner runs on its text alone, under names no module has, and is the module's plan", () => { + // The page's own lines, in a scope with nothing of this module in it. + const run = new Function("args", `${embedFn("settleFirstFrame", settleFirstFrame)}\n${embedFn("postsPlan", postsPlan)}\nreturn postsPlan(args, settleFirstFrame);`); + const args = { + posts: [{ id: "a", appear: 0, out: [8, 8.5] }, { id: "b", appear: 3, out: [8, 8.5] }, { id: "c", appear: 5, out: [8, 8.5] }], + heights: [300, 300, 300], pans: [0, 120, 0], column: 700, + }; + const plan = run(structuredClone(args)); + assert.deepEqual(plan, postsCues(structuredClone(args))); + assert.ok(plan.cues.length > 6); + // The first card's entrance starts at the cut's first instant and is a real move: it stays a cue. + assert.ok(plan.cues.some((c) => c.k === "c0" && c.at === 0)); +}); + +/** Every call in a source file, with its callee's last name. */ +function callsIn(file) { + const sf = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.ES2022, true, ts.ScriptKind.JS); + const out = []; + const walk = (node) => { + if (ts.isCallExpression(node)) { + const callee = ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : ts.isIdentifier(node.expression) ? node.expression.text : null; + if (callee) out.push({ callee, node, sf }); + } + ts.forEachChild(node, walk); + }; + walk(sf); + return out; +} + +const SOURCES = [HERE, path.join(HERE, "modules")] + .flatMap((dir) => readdirSync(dir).filter((f) => f.endsWith(".mjs") && !f.endsWith(".test.mjs")).map((f) => path.join(dir, f))); + +test("the scan: every function a source embeds (embedFn, page.evaluate) is listed above, and an inline one is self-contained", () => { + let embeds = 0; + let evaluates = 0; + for (const file of SOURCES) { + const rel = path.relative(HERE, file); + for (const { callee, node, sf } of callsIn(file)) { + const at = () => `${rel}:${sf.getLineAndCharacterOfPosition(node.getStart()).line + 1}`; + if (callee === "embedFn" && node.arguments.length === 2) { + const fn = node.arguments[1]; + assert.ok(ts.isIdentifier(fn), `${at()}: embedFn takes a module function by name`); + assert.ok(LISTED.has(fn.text), `${at()}: ${fn.text} is embedded in a page -- list it in EMBEDDED (embedded-source.test.mjs)`); + embeds += 1; + } + if (callee === "evaluate" && node.arguments.length) { + const fn = node.arguments[0]; + evaluates += 1; + if (ts.isIdentifier(fn)) { + assert.ok(LISTED.has(fn.text), `${at()}: ${fn.text} is sent to a page -- list it in EMBEDDED (embedded-source.test.mjs)`); + } else if (ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)) { + assert.deepEqual(outside(fn.getText(sf), [...ES, ...DOM]), [], `${at()}: the function sent to the page uses a name from outside itself`); + } else { + // Text built here: a literal, or shoot-page's expression (its own test above). + const text = fn.getText(sf); + assert.ok(ts.isStringLiteralLike(fn) || /^pageExpression\(/.test(text), `${at()}: page.evaluate(${text.slice(0, 40)}) -- neither a function nor a known expression`); + } + } + } + } + // The scan found what is there today (a regex that stopped matching would pass on nothing). + assert.ok(embeds >= 5, `embedFn calls found: ${embeds}`); + assert.ok(evaluates >= 40, `page.evaluate calls found: ${evaluates}`); +});