Add the account area and account-synced Appearance preferences
CI / verify (pull_request) Successful in 1m10s
CI / infrastructure-smoke (pull_request) Successful in 34s
CI / package-release (pull_request) Successful in 50s
CI / migration-smoke (pull_request) Successful in 2m26s
CI / image-build (pull_request) Successful in 1m12s
CI / deploy-smoke (same-origin) (pull_request) Successful in 42s
CI / package-publication (pull_request) Successful in 54s
CI / deploy-smoke (split) (pull_request) Successful in 3m17s

Stage 1 PR 6 (ADR 0062). /account shows who is signed in; /account/appearance
chooses System, Light, or Dark and reduced motion (System, Reduce, Allow).

- Core: ekklesia_core_user_preference, one typed, CHECK-constrained,
  nullable column per preference (null = never chosen), migration
  0008_user_preferences (additive), @ekklesia/core/account store, and the
  authenticated-baseline permission core.account.self.manage.
- API: GET /api/v1/account (name, email, preferences) and partial
  PATCH /api/v1/account/preferences, self-only by construction: no user id
  is accepted anywhere; trusted Origin and body limit on the mutation.
- Shell: the account control shows name, email, and initials (never the
  unvetted image URL) and offers Account, Appearance, Sign out; native
  radio groups apply a choice at once through the ADR 0060 controller and
  save it; the server's answer wins and a failed save reverts.
- First paint: a classic, same-origin, render-blocking appearance.js in
  <head> applies a two-word localStorage cache before paint (no inline
  script, CSP unchanged). The account replaces the cache on every load,
  sign-out clears it, and other tabs follow via the storage event.
- Deploy smoke: real-Chromium checks for light/dark, OS emulation,
  overrides, reload persistence, pre-paint, Shadow DOM modules, reduced
  motion, the display staying light, and phone width; the browser
  container gets a 512 MiB /dev/shm so a long session no longer fails
  requests with ERR_INSUFFICIENT_RESOURCES.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ekklesia
2026-10-14 23:56:50 -05:00
co-authored by Claude Opus 5.5
parent 8571e6854c
commit cd0287537e
88 changed files with 6404 additions and 158 deletions
+256
View File
@@ -102,10 +102,27 @@ const send = (method, params) => cdp.send(method, params, sessionId);
* `loadingFailed` here, never a response. */
const responses = [];
const failed = [];
/** Requests the page has started and not finished, by id: what a timed-out wait was stuck behind.
* Only paths are ever printed, never a query, header, or body. */
const inflight = new Map();
/** Every request's URL by id, so a failure can be named after the request it ended. */
const inflightUrls = new Map();
cdp.on((message) => {
if (message.sessionId !== sessionId) {
return;
}
if (message.method === "Network.requestWillBeSent") {
inflightUrls.set(message.params.requestId, message.params.request.url);
inflight.set(message.params.requestId, {
type: message.params.type,
url: message.params.request.url,
});
} else if (
message.method === "Network.loadingFinished" ||
message.method === "Network.loadingFailed"
) {
inflight.delete(message.params.requestId);
}
if (message.method === "Network.responseReceived") {
const { response, type } = message.params;
responses.push({ status: response.status, type, url: response.url });
@@ -145,6 +162,37 @@ async function waitFor(expression, description) {
await new Promise((resolve) => setTimeout(resolve, 250));
}
console.log(`FAIL timed out waiting for ${description}`);
const page = await evaluate(
`({ path: location.pathname, ready: document.readyState, shell: Boolean(document.querySelector('[data-testid="host-shell"]')), loading: Boolean(document.querySelector('[data-testid="host-loading"]')), error: Boolean(document.querySelector('[data-testid="host-error"], [data-testid="module-error"]')) })`,
).catch(() => "unavailable");
const pending = [...inflight.values()].map((request) => {
try {
const url = new URL(request.url);
return `${request.type} ${url.origin === apiOrigin ? "api" : url.origin === dashboardOrigin ? "dashboard" : "other"}${url.pathname}`;
} catch {
return request.type;
}
});
const shortPath = (value) => {
try {
const url = new URL(value);
return `${url.origin === apiOrigin ? "api" : url.origin === dashboardOrigin ? "dashboard" : "other"}${url.pathname}`;
} catch {
return "unparseable";
}
};
// The last few refused or failed requests: which one broke the page, and how.
const refusedRecently = responses
.filter((response) => response.status >= 400)
.slice(-6)
.map((response) => `${response.status} ${shortPath(response.url)}`);
const failedRecently = failed
.slice(-6)
.map(
(failure) =>
`${failure.errorText}${failure.corsErrorStatus ? ` cors:${failure.corsErrorStatus.corsError}` : ""} ${shortPath(inflightUrls.get(failure.requestId) ?? "")}`,
);
console.log(`info ${JSON.stringify({ failedRecently, page, pending, refusedRecently })}`);
failures += 1;
return false;
}
@@ -421,6 +469,208 @@ check(
"leaving Settings returns to the normal Dashboard navigation",
);
// --- Account and Appearance (ADR 0062): identity, live switching, persistence, first paint ------
const emulate = (colorScheme, reducedMotion) =>
send("Emulation.setEmulatedMedia", {
features: [
{ name: "prefers-color-scheme", value: colorScheme },
{ name: "prefers-reduced-motion", value: reducedMotion },
],
});
const rootScheme = "getComputedStyle(document.documentElement).colorScheme";
const rootToken = (name) =>
`getComputedStyle(document.documentElement).getPropertyValue("--ekklesia-${name}").trim()`;
const option = (group, value) =>
`document.querySelector('[data-testid="appearance-${group}-${value}"] input')`;
const savedPreferences = () =>
responses.filter(
(response) =>
response.url === `${apiOrigin}/api/v1/account/preferences` && response.status === 200,
).length;
/**
* Chooses one option on the Appearance page and waits until the account has saved it. An option
* already chosen needs no save: a radio that is already checked does not change.
*/
async function choose(group, value) {
if (await evaluate(`Boolean(${option(group, value)}?.checked)`)) {
return true;
}
const before = savedPreferences();
await evaluate(`${option(group, value)}.click()`);
const deadline = Date.now() + timeoutMs;
while (savedPreferences() <= before && Date.now() < deadline) {
await new Promise((resolve) => setTimeout(resolve, 100));
}
return (
savedPreferences() > before &&
(await waitFor(
`${option(group, value)}?.checked && ${selector("appearance-status")}?.textContent.includes("Saved")`,
`${group} ${value} to be saved`,
))
);
}
await emulate("light", "no-preference");
await navigate(`${dashboardOrigin}/`);
await waitFor(selector("host-account-menu"), "the account control");
check(
await waitFor(
`${selector("host-account-menu")}.textContent.includes(${JSON.stringify(required("SMOKE_OWNER_EMAIL"))}) && ${selector("host-account-menu")}.querySelector('[data-testid="account-avatar"]')`,
"the account control to name the signed-in person",
),
"the account control shows who is signed in, with their initials",
);
await evaluate(`${selector("host-account-menu")}.click()`);
await waitFor(selector("host-appearance-link"), "Appearance in the account menu");
await evaluate(`${selector("host-appearance-link")}.click()`);
check(
await waitFor(
`location.pathname === "/account/appearance" && ${selector("account-appearance")}`,
"the Appearance page",
),
"Appearance opens from the account menu at /account/appearance",
);
// Start from System for both, whatever an earlier pass left on this account.
check(
(await choose("appearance", "system")) && (await choose("motion", "system")),
"System appearance and System motion save to the account",
);
const lightBackground = await evaluate(`getComputedStyle(document.body).backgroundColor`);
await emulate("dark", "no-preference");
check(
await waitFor(`${rootScheme} === "dark"`, "System to follow a dark operating system"),
"with System chosen, an operating system switching to dark restyles the page live",
);
await emulate("light", "no-preference");
check(
await waitFor(`${rootScheme} === "light"`, "System to follow a light operating system"),
"and switching back to light restyles it again, with no reload",
);
check(await choose("appearance", "dark"), "choosing Dark saves it to the account");
check(
await waitFor(
`${rootScheme} === "dark" && getComputedStyle(document.body).backgroundColor !== ${JSON.stringify(lightBackground)}`,
"Dark to take effect under a light operating system",
),
"Dark takes effect at once, overriding a light operating system",
);
await navigate(`${dashboardOrigin}/account/appearance`);
check(
await waitFor(
`${selector("account-appearance")} && ${option("appearance", "dark")}?.checked && ${rootScheme} === "dark" && localStorage.getItem("ekklesia.dashboard.appearance") === "dark system"`,
"Dark after a reload",
),
"a reload keeps Dark: the account holds it, and this browser cached two words for first paint",
);
// First paint without the application: only the pre-paint script runs, and it already applies Dark.
await send("Network.setBlockedURLs", { urls: ["*/assets/ekklesia-dashboard/app.js"] });
await navigate(`${dashboardOrigin}/`);
check(
await waitFor(
`document.readyState === "complete" && !${selector("host-shell")} && document.documentElement.getAttribute("data-ekklesia-appearance") === "dark" && document.querySelector('meta[name="color-scheme"]').content === "dark"`,
"the pre-paint script alone to apply Dark",
),
"before the application script runs at all, the pre-paint script has applied Dark",
);
await send("Network.setBlockedURLs", { urls: [] });
if (openedModuleId) {
const moduleScheme = `(() => {
const host = document.querySelector("[data-ekklesia-module-ui]");
const inner = host?.shadowRoot?.querySelector("[data-ekklesia-module-ui-root]");
if (!inner) return null;
const style = getComputedStyle(inner);
return { page: style.getPropertyValue("--ekklesia-background-page").trim(), scheme: style.colorScheme };
})()`;
await navigate(`${dashboardOrigin}/${openedModuleId}`);
await waitFor(
`${selector("module-container")}?.childElementCount > 0 && (${moduleScheme})?.scheme === "dark"`,
"the module's isolated root in Dark",
);
const darkModule = await evaluate(moduleScheme);
check(
darkModule?.scheme === "dark" &&
darkModule.page === (await evaluate(rootToken("background-page"))),
`the ${openedModuleId} module's Shadow DOM root follows Dark through the tokens`,
);
await navigate(`${dashboardOrigin}/account/appearance`);
await waitFor(selector("account-appearance"), "the Appearance page");
await emulate("dark", "no-preference");
check(await choose("appearance", "light"), "choosing Light saves it to the account");
check(
await waitFor(`${rootScheme} === "light"`, "Light under a dark operating system"),
"Light takes effect at once, overriding a dark operating system",
);
await navigate(`${dashboardOrigin}/${openedModuleId}`);
await waitFor(
`${selector("module-container")}?.childElementCount > 0 && (${moduleScheme})?.scheme === "light"`,
"the module's isolated root in Light",
);
const lightModule = await evaluate(moduleScheme);
check(
lightModule?.scheme === "light" && lightModule.page !== darkModule?.page,
`the ${openedModuleId} module's Shadow DOM root follows Light too`,
);
await navigate(`${dashboardOrigin}/account/appearance`);
await waitFor(selector("account-appearance"), "the Appearance page");
}
// Reduced motion: System follows the operating system; Allow and Reduce override it.
const shortDuration = rootToken("motion-duration-short");
await emulate("light", "reduce");
check(
await waitFor(`${shortDuration} === "0ms"`, "System motion to follow a reduce request"),
"with System motion, an operating system asking for less motion zeroes durations",
);
check(await choose("motion", "allow"), "choosing Allow saves it to the account");
check(
await waitFor(`${shortDuration} !== "0ms"`, "Allow under a reduce request"),
"Allow keeps the platform's subtle motion even when the system asks for less",
);
await emulate("light", "no-preference");
check(await choose("motion", "reduce"), "choosing Reduce saves it to the account");
check(
await waitFor(`${shortDuration} === "0ms"`, "Reduce with no system request"),
"Reduce zeroes motion even when the system asks for none",
);
if (displayPath !== null) {
// The display host is a lobby screen, not a person: it stays Light whatever the OS or the account.
check(await choose("appearance", "dark"), "Dark is chosen again before visiting a display");
await emulate("dark", "no-preference");
await navigate(`${apiOrigin}${displayPath}`);
check(
await waitFor(
`${selector("display-module-container")}?.childElementCount > 0 && ${rootScheme} === "light"`,
"the display to stay Light",
),
"the display page stays Light under a dark operating system and a Dark account choice",
);
await emulate("light", "no-preference");
}
await send("Emulation.setDeviceMetricsOverride", {
deviceScaleFactor: 2,
height: 844,
mobile: true,
width: 390,
});
await navigate(`${dashboardOrigin}/account/appearance`);
check(
await waitFor(
`${selector("account-appearance")} && document.documentElement.scrollWidth <= window.innerWidth && [...document.querySelectorAll(".ek-shell-choice")].length === 6 && [...document.querySelectorAll(".ek-shell-choice")].every((element) => element.getBoundingClientRect().height >= 44)`,
"the Appearance page at phone width",
),
"at phone width the Appearance page fits without sideways scrolling, every option a 44px+ target",
);
check(
(await choose("appearance", "system")) && (await choose("motion", "system")),
"the account is put back to System for both",
);
await send("Emulation.setDeviceMetricsOverride", {
deviceScaleFactor: 1,
height: 1080,
mobile: false,
width: 1920,
});
await send("Emulation.setEmulatedMedia", { features: [] });
// --- Sign out on the Dashboard, from the account menu at the bottom of the sidebar ---------------
await navigate(`${dashboardOrigin}/`);
await waitFor(selector("host-account-menu"), "the account control");
@@ -435,6 +685,12 @@ const principal = await evaluate(`fetch(${JSON.stringify(`${apiOrigin}/api/v1/pr
credentials: "include",
}).then((response) => response.json()).then((body) => body.kind)`);
check(principal === "anonymous", "after sign-out, the API answers anonymous to the same browser");
check(
await evaluate(
`localStorage.getItem("ekklesia.dashboard.appearance") === null && document.documentElement.getAttribute("data-ekklesia-appearance") === "system"`,
),
"sign-out forgets this browser's cached appearance, and the page follows the system",
);
await cdp.send("Target.closeTarget", { targetId });
cdp.close();