-
-${head}${body}${footer(r)}
+${preview}
+
+
+|
+${head}${details}${footer(r)}
|
+
|
`;
}
@@ -535,55 +572,55 @@ function textItem(i: Item): string[] {
return [...out, ""];
}
-/** The plain-text body. Pure. */
+/** The plain-text body: the same lead first, then every section with its prompts in full. Pure. */
export function textOf(r: Report): string {
const adj = ADJ[r.every] || "daily";
- const c = counts(counted(r));
- const out: string[] = [
- r.kind === "alert" ? "GenClass: something critical on your app" : `GenClass ${adj} report${r.kind === "test" ? " (test)" : ""}`,
- headlineOf(r).text,
- `${day(r.generated)}, ${clock(r.generated)} · ${plural(r.apps.length, "app", "apps")} · ${r.apps[0]?.period ?? ""}`,
- `${c[0]} critical · ${c[1]} important · ${c[2]} worth a look`,
- "",
- ];
- if (r.summary && r.kind !== "alert") {
- out.push("GENCLASS SUMMARY", r.summary.headline, r.summary.text, "");
- r.summary.actions.forEach((x, k) => out.push(`${k + 1}. ${x.title}${x.why ? `. ${x.why}` : ""}`, ...(x.prompt ? [` Prompt: ${x.prompt}`] : []), ""));
+ const l = leadOf(r);
+ const cl = r.kind === "alert" || !measured(r).length ? "" : countLine(counts(counted(r)));
+ const out: string[] = [`${r.kind === "alert" ? "GenClass alert" : `GenClass ${adj} report${r.kind === "test" ? " (test)" : ""}`} · ${day(r.generated)}, ${clock(r.generated)}`, "", l.headline, ""];
+ if (l.text) out.push(l.text, "");
+ if (cl) out.push(cl, "");
+ l.steps.forEach((x, k) => out.push(`${k + 1}. ${x.title}${x.why ? `. ${x.why}` : ""}`, ...(x.prompt ? [` Prompt: ${x.prompt}`] : []), ""));
+ if (l.model && r.actionsHidden) out.push(`${plural(r.actionsHidden, "next step", "next steps")} with prompts: in the other half, with ${r.upgrade?.plan ?? "Pro"}.`, "");
+ // a prompt's link is long and its text is printed in full below
+ if (l.button && !l.button.prompt) out.push(`${l.button.label}: ${l.button.href}`, "");
+ if (r.upgrade && r.apps.length && r.kind !== "alert") {
+ const lo = leftOut(r);
+ out.push(`You're seeing half of this report on Free.${lo.length ? ` ${r.upgrade.plan} shows the other half: ${lo.join(", ")}.` : ""} ${r.upgrade.price}${r.upgrade.trialDays ? `, ${r.upgrade.trialDays} days free to start` : ""}: ${r.upgrade.url}`, "");
}
+ out.push("----", "");
const now = problemItems(r).filter((i) => i.p <= 1);
- out.push("WHAT NEEDS DOING", ...(now.length ? now.flatMap(textItem) : ["Nothing critical or important in this period.", ""]));
+ if (now.length) out.push("FIX THESE FIRST", "", ...now.flatMap(textItem));
for (const x of r.problemsHidden) out.push(`Locked: ${plural(x.counts[0] + x.counts[1] + x.counts[2], "more problem", "more problems")} on ${x.app} (${byP(x.counts)}): in the other half, with ${r.upgrade?.plan ?? "Pro"}.`, "");
+ const setup = setupItems(r);
if (r.kind !== "alert") {
- out.push("YOUR APPS");
- for (const x of r.apps) {
- const t = x.totals;
- if (x.demo) { out.push(`- ${x.name} (${x.pro ? "Pro" : "Free"}): sample data until real visits arrive. ${x.dashboard}`); continue; }
- if (!x.lastEvent) { out.push(`- ${x.name} (${x.pro ? "Pro" : "Free"}): not connected yet. ${x.dashboard}`); continue; }
- out.push(`- ${x.name} (${x.pro ? "Pro" : "Free"}): ${fmt(t.loads)} page loads, ${fmt(t.problems)} problems, ${fmt(t.checks)} checks, ${fmt(t.fixed)} fixed live. ${x.dashboard}`);
+ if (r.apps.length) {
+ out.push("YOUR APPS");
+ for (const x of r.apps) {
+ const t = x.totals;
+ if (x.demo) { out.push(`- ${x.name} (${x.pro ? "Pro" : "Free"}): sample data until real visits arrive. ${x.dashboard}`); continue; }
+ if (!x.lastEvent) { out.push(`- ${x.name} (${x.pro ? "Pro" : "Free"}): not connected yet. ${x.dashboard}`); continue; }
+ out.push(`- ${x.name} (${x.pro ? "Pro" : "Free"}): ${fmt(t.loads)} page loads, ${fmt(t.problems)} problems, ${fmt(t.checks)} checks, ${fmt(t.fixed)} fixed live. ${x.dashboard}`);
+ }
+ out.push("");
}
- out.push("");
const prs = r.apps.flatMap((x) => x.prs);
if (prs.length) out.push("CODE CHANGES GENCLASS REVIEWED", ...prs.map((pr) => `- ${pr.repo}#${pr.number}: ${pr.flagged ? `${pr.flagged} races flagged` : "nothing flagged"} ${pr.url}`), "");
const sec = r.items.filter((i) => i.section === "security");
out.push("SECURITY", ...(sec.length ? sec.flatMap(textItem) : ["Nothing unusual.", ""]));
}
- const setup = r.items.filter((i) => i.section === "setup");
- out.push("SETUP", ...(setup.length ? setup.flatMap(textItem) : ["Everything is connected.", ""]));
+ if (setup.length) out.push("SETUP", "", ...setup.flatMap(textItem));
if (r.kind !== "alert") {
const p2 = problemItems(r).filter((i) => i.p === 2);
- if (p2.length) out.push("WORTH A LOOK", ...p2.flatMap(textItem));
+ if (p2.length) out.push("WORTH A LOOK", "", ...p2.flatMap(textItem));
if (r.suggestions.length) out.push("SUGGESTIONS", ...r.suggestions.flatMap((s) => [`- ${s.title}${s.why ? `: ${s.why}` : ""}`, ...(s.prompt ? [` Prompt: ${s.prompt}`] : [])]), "");
if (knowsSites(r)) {
- out.push("UPGRADE YOUR WEBSITE DESIGN");
+ out.push("WEBSITE DESIGN");
for (const d of r.designs) out.push(`- ${d.title} (inspired by ${d.inspired_by})`, ` Prompt: ${d.prompt}`);
for (const s of r.showcase) out.push(`- ${s.name} ${s.site}${s.three ? " (3D)" : ""}: ${s.take}`);
- } else {
- out.push("WHAT THIS REPORT WILL SHOW", `Once ${appsName(r)} sends its first page load: what breaks there and on which pages, and contrast and layout problems on your visitors' screens.`, "For ideas now, run npx genclass suggest in the app's folder.");
- }
- out.push("");
- if (r.upgrade && r.apps.length) {
- const lo = leftOut(r);
- out.push(`You're seeing half of this report on Free.${lo.length ? ` ${r.upgrade.plan} shows the other half: ${lo.join(", ")}.` : ""} ${r.upgrade.price}${r.upgrade.trialDays ? `, ${r.upgrade.trialDays} days free to start` : ""}: ${r.upgrade.url}`, "");
+ out.push("");
+ } else if (r.apps.length) {
+ out.push("IDEAS BEFORE THE DATA", "Run npx genclass suggest in the app's folder: it suggests what to fix and website designs from sites in your field.", "");
}
}
out.push("--", `Sent to ${r.account.email} for your GenClass account.`, r.links.settings ? `Change how often, or stop these emails: ${r.links.settings}` : `Change how often: ${r.links.account}`, "Reply to reach a person at GenClass.");
diff --git a/telemetry-worker/test/report.test.ts b/telemetry-worker/test/report.test.ts
index 1897f205..413684c0 100644
--- a/telemetry-worker/test/report.test.ts
+++ b/telemetry-worker/test/report.test.ts
@@ -238,7 +238,7 @@ describe("reports: one account's report", () => {
expect(mail.html).not.toContain("");
expect(mail.html).toContain("Shop <script>");
expect(mail.html).toContain("/checkout");
- expect(mail.html).toContain("Upgrade your website design");
+ expect(mail.html).toContain("Website design");
expect(mail.text).toContain("Prompt for your coding agent:");
// every prompt has a signed link to the prompt page
const prompt = r.items.find((i) => i.prompt)!.prompt!;
@@ -275,15 +275,15 @@ describe("reports: one account's report", () => {
const { subject, html, text } = renderReport(r);
expect(subject).toBe("GenClass daily report, Glyco site: finish setting up");
expect(html).toContain("Glyco site isn't sending data yet");
- expect(html).toContain("What this report will show");
+ expect(html).toContain("Ideas before the data");
expect(html).toContain("Once Glyco site sends its first page load");
- for (const generic of ["Sites to learn from today", "Upgrade your website design", "Suggestions for your app"]) expect(html).not.toContain(generic);
- expect(text).not.toContain("UPGRADE YOUR WEBSITE DESIGN");
+ for (const generic of ["Sites to learn from", "Website design", "Suggestions for your app"]) expect(html).not.toContain(generic);
+ expect(text).not.toContain("WEBSITE DESIGN");
// once it has measured data, the ideas and the showcase come back
await sendBatch(env, (sql.db.prepare("SELECT token FROM projects WHERE name = 'Glyco site'").get() as { token: string }).token, [page("/")]);
const later = renderReport((await buildReport(env, accountRow(sql, account.id), { kind: "report", now: now(), model: false, fetch: noModel }))!.report);
- expect(later.html).toContain("Sites to learn from today");
- expect(later.html).not.toContain("What this report will show");
+ expect(later.html).toContain("Sites to learn from");
+ expect(later.html).not.toContain("Ideas before the data");
});
it("without signed links a short prompt is printed and a long one is left to the text part", async () => {
@@ -319,7 +319,7 @@ describe("reports: one account's report", () => {
const mail = renderReport(r);
expect(mail.html).toContain("/api/pay");
expect(mail.html).not.toContain("/secret-admin");
- expect(mail.html).toContain("You're seeing half of this report on Free");
+ expect(mail.html).toContain(esc("You're seeing half of this report on Free"));
expect(mail.html).toContain("1 more problem on {
expect(asked[0]).toContain("/cart");
for (const secret of ["owner@example.com", "sk-test-secret", account.id, app.token]) expect(asked[0]).not.toContain(secret);
expect(r.summary?.headline).toBe("Stale responses on /cart need a fix");
- expect(renderReport(r).html.indexOf("GenClass summary")).toBeLessThan(renderReport(r).html.indexOf("Your apps"));
+ const { html } = renderReport(r);
+ expect(html.indexOf("Stale responses on /cart need a fix")).toBeGreaterThan(-1);
+ expect(html.indexOf("Stale responses on /cart need a fix")).toBeLessThan(html.indexOf("Your apps"));
+ expect(html).toContain("Summary written by a model");
});
it("keeps only the summary's own fields, cleaned and cut", () => {
@@ -396,6 +399,100 @@ describe("reports: one account's report", () => {
});
});
+describe("reports: the email's layout, summary first (the owner, 2026-11-15)", () => {
+ /** A headline's place in the HTML, and a section title's (an ). */
+ const at = (html: string, t: string) => html.indexOf(t);
+ const h2 = (html: string, t: string) => html.indexOf(`>${esc(t)}`);
+
+ it("square corners, no pills, dots or emoji, in every kind of email", async () => {
+ const { env, sql } = world({ OPENAI_API_KEY: "sk-test" });
+ const { cookie, account } = await signedIn(env);
+ const shop = await createApp(env, cookie, "Shop");
+ grantPro(sql, shop.id);
+ await createApp(env, cookie, "Blog");
+ await sendBatch(env, shop.token, [page("/checkout"), ...detection("duplicate", "/checkout"), ...detection("slow", "/search")]);
+ const f = (async (url: string) => (url === MODEL_URL ? Response.json({ choices: [{ message: { content: JSON.stringify({ headline: "Fix the checkout", summary: "One double submit.", actions: [{ title: "Disable the button", why: "Two charges.", prompt: "Disable it." }] }) } }] }) : new Response("", { status: 404 }))) as typeof fetch;
+ for (const kind of ["report", "alert", "test"] as const) {
+ const { html } = renderReport((await buildReport(env, accountRow(sql, account.id), { kind, now: now(), model: kind !== "alert", fetch: f }))!.report);
+ expect(html).not.toMatch(/border-radius/);
+ for (const bad of ["●", "🔒", "→", "999px", "text-transform:uppercase"]) expect(html, `${kind}: ${bad}`).not.toContain(bad);
+ // dark mode for the clients that read it, Outlook's fixed column, the main button a table cell
+ expect(html).toContain("@media (prefers-color-scheme:dark)");
+ expect(html).toContain("[data-ogsc] .gc-i1");
+ expect(html).toContain(" |
|