Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bootstrap/frame-sync.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const FRAME = [
"bootstrap/precache.mjs",
"bootstrap/register.mjs",
"bootstrap/screens.mjs",
"bootstrap/weight.mjs",
"bootstrap/worker-runtime.mjs",
"lighthouserc.json",
"site/app.mjs",
"site/guest-worker.mjs",
Expand Down
60 changes: 13 additions & 47 deletions bootstrap/page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { access, readdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { DEFAULT_REGISTRY } from "./register.mjs";
import { prepareWorkerRuntime } from "./worker-runtime.mjs";

const site = process.argv[2] ?? "site";
await prepareWorkerRuntime(site, fileURLToPath(new URL("../try/vendor", import.meta.url)));
const read = (path) => readFile(join(site, path), "utf8");

const escape = (text) =>
Expand All @@ -36,7 +38,10 @@ const cardModule = await access(join(site, "card.mjs")).then(() => true, () => f
// brand/hologram-warm.css and brand/fonts.css, both pinned by brand.lock.
// Comments and indentation out: the stylesheet travels inside every page.
const minify = (text) => text.replace(/\/\*[\s\S]*?\*\//g, "").replace(/^[ \t]+/gm, "").replace(/\n{2,}/g, "\n").trim();
const css = minify([await read("brand/hologram-warm.css"), await read("brand/fonts.css"), await read("prism-page.css"), card.css]
// The display sizes its type to what it holds; its first size is set here,
// from the placeholder, so the type does not shrink when the script arrives.
const startChars = `#input{--chars:${Math.max(String(meta.placeholder ?? "").length, 4)}}`;
const css = minify([await read("brand/hologram-warm.css"), await read("brand/fonts.css"), await read("prism-page.css"), card.html ? "" : startChars, card.css]
.join("\n")
.replace(/url\("\.\.\/fonts\//g, 'url("./fonts/'));
const theme = (await read("theme.js")).trim();
Expand Down Expand Up @@ -312,57 +317,18 @@ const promise = (() => {
})();

// The surface: an app with its own (card.html) fills it from the slot script;
// any other gets a form a visitor can read at a glance: what to type, a button
// that runs it (Enter does too), examples that run on a tap, and the answer
// under them, with a state for every moment (nothing yet, verifying, an answer,
// a refusal, an error). The words come from app.json: inputLabel, submitLabel,
// outputLabel, placeholder, hint.
const submitLabel = meta.submitLabel ?? "Run";
const outputLabel = meta.outputLabel ?? "Answer";
const inputLabel = meta.inputLabel ?? "Request";
const lower = (s) => s.charAt(0).toLowerCase() + s.slice(1);
const idleText = `Type a ${lower(inputLabel)} and press ${submitLabel}, or pick an example.`;
const hint = meta.hint ?? `Press Enter or ${submitLabel}. It runs in your browser, on the app this page verifies.`;
// Try: a few of the holo's own short examples, at most two per answer, in
// words a visitor could type in one line (raw hex requests and requests with
// line breaks stay in the spec).
// any other gets the display, its input as the largest thing on screen.
const surface = card.html ? "" : ` <label class="display" for="input"><span class="k">${escape(meta.inputLabel ?? "Request")}</span><input id="input" autocomplete="off" spellcheck="false" enterkeyhint="go" inputmode="${escape(meta.inputMode ?? "numeric")}" placeholder="${escape(meta.placeholder ?? "")}" /><span class="rule" aria-hidden="true"></span></label>`;
// Try: a few of the holo's own short examples, at most two per answer.
const tries = card.html ? "" : (() => {
const seen = new Map();
const asked = new Set();
return vectors.filter((v) => {
const k = kind(v.res);
if (k === "refuse" || v.req === "" || v.req.length > 24 || v.req.startsWith("hex:") || /[\u0000-\u001f]/.test(v.req) || asked.has(v.req) || (seen.get(k) ?? 0) >= 2) return false;
if (k === "refuse" || v.req === "" || v.req.length > 24 || (seen.get(k) ?? 0) >= 2) return false;
seen.set(k, (seen.get(k) ?? 0) + 1);
asked.add(v.req);
return true;
}).map((v) => `<button type="button" data-request="${escape(v.req)}">${escape(v.req)}</button>`).join("");
})();
const surface = card.html ? "" : ` <div class="ask">
<form id="ask" class="ask-form" novalidate>
<label class="k" for="input">${escape(inputLabel)}</label>
<div class="ask-row"><input id="input" name="request" autocomplete="off" spellcheck="false" enterkeyhint="go" inputmode="${escape(meta.inputMode ?? "numeric")}" placeholder="${escape(meta.placeholder ?? "")}" aria-describedby="hint" /><button id="go" class="primary" type="submit">${escape(submitLabel)}</button></div>
<p class="hint" id="hint">${escape(hint)}</p>
</form>
<div class="actions"${tries ? "" : " hidden"}><p class="k" id="actions-k">Examples</p><div class="tries" id="tries">${tries}</div></div>
<section class="answer" id="result" aria-labelledby="answer-k">
<div class="answer-head"><h2 class="k" id="answer-k">${escape(outputLabel)}</h2><span id="state" class="tag" hidden></span></div>
<output id="out" for="input" class="idle" aria-live="polite">${escape(idleText)}</output>
</section>
</div>`;
// Where to go next: app.json "links", [{ label, href }], a row under the
// description, the first one the main way on. A link is to this site (a
// relative path) or to https.
const nav = (meta.links ?? []).map((l) => {
if (!l?.label || !/^(https:\/\/|\.?\/?[\w-])/.test(String(l.href ?? ""))) throw new Error(`app.json links: ${JSON.stringify(l)} needs a label and a relative or https href`);
return `<a class="go-link" href="${escape(l.href)}">${escape(l.label)}</a>`;
}).join("");
// The rail: for an app with its own surface, its result and controls; for any
// other, what the app does in full, beside the form.
const about = sentences(meta.purpose).filter((x) => x !== tagline).join(" ");
const rail = card.html
? ` <div class="result" id="result" aria-live="polite"><output id="out" class="idle">—</output></div>
<div class="actions"><p class="k" id="actions-k">Controls</p><div class="tries" id="tries"></div></div>`
: about ? ` <div class="about"><p class="k">What it does</p><p class="about-text">${escape(about)}</p></div>` : "";
// The slot script: before first paint, it moves the parts of the app's own
// surface into the workspace (data-slot names the place; the ids are the
// first card's, read when an app has not marked its parts yet), so nothing
Expand Down Expand Up @@ -474,13 +440,13 @@ const fill = {
HOLO_NAME: escape(meta.name.toLowerCase().normalize("NFKD").replace(/\p{M}/gu, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "app"),
PURPOSE: escape(meta.purpose),
TAGLINE: escape(tagline),
NAV: nav ? `<nav class="head-nav" aria-label="Where to go">${nav}</nav>` : "",
PROMISE_HEADLINE: escape(promise.headline),
ATT_PROOF_URL: escape(meta.attestations?.proof?.url ?? ""),
ICON_DOC: ICON.doc,
ICON_X: ICON.x,
SURFACE: surface,
RAIL: rail,
ACTIONS_LABEL: card.html ? "Controls" : "Try",
TRIES: tries,
CARD: cardBlock,
VERSION: escape(model.cargo_version ? `v${model.cargo_version}` : ""),
REPO: escape(meta.repository),
Expand All @@ -489,7 +455,7 @@ const fill = {
IMPORTMAP: importmap,
SPECULATION_RULES: speculationRules,
FRAME_CONNECT: frameConnect,
APP_DATA: JSON.stringify({ answers: meta.answers, frame: frameHost.href, card: cardModule, inputLabel, idle: idleText, answerLinks: meta.answerLinks ?? {} }).replace(/</g, "\\u003c"),
APP_DATA: JSON.stringify({ answers: meta.answers, frame: frameHost.href, card: cardModule, inputLabel: meta.inputLabel ?? "" }).replace(/</g, "\\u003c"),
CSP_SCRIPT_HASHES: [theme, importmap, speculationRules, ...(cardBlock ? [SLOT_SCRIPT] : [])].map(sha).join(" "),
CSP_STYLE_HASHES: sha(css),
};
Expand Down
61 changes: 3 additions & 58 deletions bootstrap/screens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// screen), any touch target under 48 px on a coarse pointer, a margin other
// than the class's, a missing workspace split from 840 px (the surface and
// its rail), a clipped line at 200 percent text, a spec that does not open
// beside the window, a page that never verifies, or a control that does
// nothing a visitor can see: every example, Enter, the button and an empty
// request must each put an answer on screen, under the form. Screenshots go to
// beside the window, or a page that never verifies. Screenshots go to
// screens/ for the run's artifact, so every app's screens are on record.
// node bootstrap/screens.mjs site screens
// Needs playwright with Chromium: npm install -g playwright && playwright install chromium
Expand Down Expand Up @@ -84,9 +82,6 @@ for (const c of classes) {
} catch {
fail(where, "the canonical frame never loaded");
}
// The holo verifies on a visitor's first start (app.mjs firstIntent); a
// key that types nothing is that start.
await page.keyboard.press("Shift");
try {
// The shield's replay, "passed/total", once every example has held.
await page.waitForFunction(() => /^(\d+)\/\1$/.test(document.getElementById("frame")?.getAttribute("examples") ?? ""), null, { timeout: 20000 });
Expand All @@ -103,7 +98,7 @@ for (const c of classes) {
const small = [];
// The frame draws in its own shadow root; its controls count too.
const roots = [document, ...[...document.querySelectorAll("*")].map((el) => el.shadowRoot).filter(Boolean)];
for (const el of roots.flatMap((root) => [...root.querySelectorAll("button, input, a.ghost, a.spec-link, .head-nav a, summary")])) {
for (const el of roots.flatMap((root) => [...root.querySelectorAll("button, input, a.ghost, a.spec-link, summary")])) {
if (el.hidden || el.closest("[hidden]") || el.classList.contains("use") || el.classList.contains("bare")) continue;
// The spec, closed, is off screen; it is checked open, below.
if (getComputedStyle(el).visibility === "hidden") continue;
Expand All @@ -112,9 +107,7 @@ for (const c of classes) {
if (coarse && (r.height < 48 || (el.tagName === "BUTTON" && r.width < 48))) small.push(`${el.tagName.toLowerCase()}#${el.id || el.className} ${Math.round(r.width)}x${Math.round(r.height)}`);
}
return {
// Main clips too, so content wider than it is hidden, not scrolled:
// that counts as overflow.
overflow: doc.scrollWidth > doc.clientWidth || document.querySelector("main").scrollWidth > document.querySelector("main").clientWidth + 1,
overflow: doc.scrollWidth > doc.clientWidth,
// The page clips rather than scrolls (html and body hide overflow), so
// the check is that the workspace ends inside the screen and holds
// everything it has: a planted 4 rem passed a scroll check alone.
Expand All @@ -139,54 +132,6 @@ for (const c of classes) {
if (c.touch && !facts.coarse) fail(where, "the emulated device is not a coarse pointer");
for (const s of facts.small) fail(where, `touch target under 48 px: ${s}`);
if (facts.verified !== "verified") fail(where, `status is "${facts.verified}"`);
// Every way on from the header lands on a page.
if (theme === "dark") {
for (const href of await page.locator(".head-nav a").evaluateAll((links) => links.map((a) => a.href))) {
if (!href.startsWith(origin)) continue;
const status = (await page.request.get(href)).status();
if (status !== 200) fail(where, `the header link ${href.slice(origin.length - 1)} lands nowhere (${status})`);
}
}
// The journey, as a visitor takes it: each example, then a request typed
// and sent with Enter, then with the button, then the button with
// nothing typed. Each must show an answer, in words, on screen.
if (theme === "dark" && await page.locator("#ask").count()) {
// An answer counts once the page has shown a new one (app.mjs counts them).
let seen = 0;
const answered = async (what, states) => {
await page.waitForFunction((n) => Number(document.getElementById("out").dataset.answers ?? 0) > n, seen, { timeout: 10000 }).catch(() => {});
seen = Number(await page.locator("#out").getAttribute("data-answers") ?? 0);
const r = await page.evaluate(() => {
const o = document.getElementById("out");
const box = o.getBoundingClientRect();
return { state: o.className, text: o.textContent.trim(), tag: document.getElementById("state").textContent.trim(), onScreen: box.height > 0 && box.top >= 0 && box.top < innerHeight - 16 };
});
if (!states.includes(r.state) || !r.text || !r.tag) fail(where, `${what} showed no answer (state "${r.state}", "${r.text.slice(0, 60)}")`);
else if (!r.onScreen) fail(where, `${what} answered off screen`);
return r;
};
const examples = await page.locator("#tries button[data-request]").all();
if (!examples.length) fail(where, "the page offers no examples to try");
for (const button of examples) {
const request = await button.getAttribute("data-request");
await button.click();
await answered(`the example "${request}"`, ["good", "bad"]);
if (await page.inputValue("#input") !== request) fail(where, `the example "${request}" did not fill the field`);
}
const first = examples.length ? await examples[0].getAttribute("data-request") : "0";
await page.fill("#input", first);
const left = await page.locator("#out").getAttribute("class");
if (left !== "idle") fail(where, `typing a new request left the old answer up (${left})`);
await page.press("#input", "Enter");
await answered("Enter", ["good", "bad"]);
await page.fill("#input", first);
await page.click("#go");
await answered("the submit button", ["good", "bad"]);
await page.fill("#input", "");
await page.click("#go");
await answered("the submit button with nothing typed", ["refuse"]);
await page.fill("#input", "");
}
await page.screenshot({ path: join(out, `${c.name}-${theme}.png`), fullPage: true });
// The spec opens beside the window from 840 px (the window narrows by
// the spec's width) and over it below; either way it is on screen,
Expand Down
Loading
Loading