diff --git a/landing/admin.html b/landing/admin.html
index 64bd125..bdd6a16 100644
--- a/landing/admin.html
+++ b/landing/admin.html
@@ -50,6 +50,18 @@
.tr.up { color: var(--mint); } .tr.down { color: #ff9d9d; } .tr.flat { color: var(--ink-faint); }
.qline { font-size: 15px; color: var(--ink-2); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.qline b { color: var(--ink); }
+ .sum li { margin: 0 0 6px 18px; font-size: 15px; color: var(--ink-2); }
+ .funnel { display: grid; gap: 8px; }
+ .frow { display: grid; grid-template-columns: 210px 1fr 56px; gap: 12px; align-items: center; font-size: 13.5px; color: var(--ink-2); }
+ .fbar { height: 14px; border-radius: 7px; background: rgba(255,255,255,.06); overflow: hidden; }
+ .fbar i { display: block; height: 100%; background: var(--mint); border-radius: 7px; min-width: 2px; }
+ .frow b { text-align: right; color: var(--ink); font-family: var(--font-mono); }
+ .vchip { font-family: var(--font-mono); font-size: 11px; border-radius: 100px; padding: 2px 9px; }
+ .vchip.nailed { background: rgba(61,242,199,.14); color: var(--mint); }
+ .vchip.close { background: rgba(255,200,100,.14); color: #ffc978; }
+ .vchip.missed { background: rgba(255,110,110,.14); color: #ff9d9d; }
+ .adm-toggle { font-size: 13px; color: var(--ink-dim); margin: 0 0 8px; display: block; }
+ @media (max-width: 860px) { .frow { grid-template-columns: 1fr 1fr 48px; } .frow span { grid-column: 1 / -1; } }
@media (max-width: 860px) { .tiles { grid-template-columns: 1fr 1fr; } }
@@ -71,6 +83,29 @@
+
Is this helping people?
+
+
+
+
+
The funnel, last 14 days
+
+
Your own test builds are left out from now on (older ones cannot be told apart). Readers are never required to rate, so the last step is always small.
+
+
+
+
Our score vs the reader’s
+
+
+
+
+
+
What every new build is told
+
+
This is the reader feedback passed into each build’s brief (as quoted opinion, never as instructions) and saved to RuVector when a build runs on this Mac.
+
+
+
@@ -105,6 +140,7 @@
Reach — stars, forks, downloads
@@ -161,7 +197,32 @@
People (email ledger)
return Math.round(h / 24) + 'd ago';
}
+ var showTest = false;
+ var lastData = null;
+ function renderInsights(ins) {
+ if (!ins) return;
+ $('[data-summary]').innerHTML = ins.summary.map(function (l) { return '
' + esc(l) + ''; }).join('');
+ var top = Math.max.apply(null, ins.funnel.map(function (f) { return f.n; }).concat([1]));
+ $('[data-funnel]').innerHTML = ins.funnel.map(function (f) {
+ return '
' + esc(f.label) + '
' + esc(f.n) + ' ';
+ }).join('');
+ var rows = ins.ratings.compared;
+ $('[data-compare]').innerHTML = '
| page | our grader | reader says | comment | when |
|---|
'
+ + (rows.length ? rows.map(function (c) {
+ return '
| ' + esc(c.repo) + ' | ' + (c.ours != null ? esc(c.ours) : 'not matched') + ' | ' + esc(c.verdict) + ' ~' + esc(c.theirs) + ' | ' + (c.comment ? esc(c.comment) : 'no comment') + ' | ' + day(c.at) + ' |
';
+ }).join('') : '
| No reader ratings yet. |
');
+ var o = ins.owner;
+ $('[data-compare-note]').textContent = 'A one-tap verdict is shown as ~92 (nailed), ~70 (close), ~35 (missed). Reader ratings of the operator\'s own selftest repos are excluded.'
+ + (o.markedTestBuilds || o.unmarkedEstimate ? ' Your own test builds: ' + o.markedTestBuilds + ' tagged and hidden' + (o.unmarkedEstimate ? '; about ' + o.unmarkedEstimate + ' older ones from before tagging cannot be told apart and still count in the totals.' : '.') : '');
+ var L = ins.learned;
+ $('[data-learned]').innerHTML = (L.fix.length || L.keep.length)
+ ? (L.fix.length ? '
Fix: ' + L.fix.map(function (l) { return esc(l.repo) + ' — “' + esc(l.text) + '”'; }).join(' · ') : '')
+ + (L.keep.length ? (L.fix.length ? '
' : '') + '
Keep doing: ' + L.keep.map(function (l) { return esc(l.repo) + ' — “' + esc(l.text) + '”'; }).join(' · ') : '')
+ : 'Nothing yet: a rating only becomes a lesson when the reader leaves a comment.';
+ }
+
function render(d) {
+ lastData = d;
$('[data-gate]').hidden = true;
$('[data-dash]').hidden = false;
$('[data-stamp]').textContent = 'generated ' + d.generatedAt;
@@ -178,6 +239,8 @@
People (email ledger)
(ds.mostRecentAttempt ? ' Most recent attempt: ' + esc(ds.mostRecentAttempt.repo) + ' (' + esc(ds.mostRecentAttempt.status) + ', ' + timeAgo(ds.mostRecentAttempt.at) + ').' : '') + '';
}
+ renderInsights(d.insights);
+
$('[data-pulse]').innerHTML = [
ptile(d.deltas.siteViews, 'website views'),
ptile(d.deltas.newVisitors, 'first-time visitors'),
@@ -275,18 +338,18 @@
People (email ledger)
$('[data-builds]').innerHTML =
'
| repo | status | why | score | theirs | worst axis | cost | page | submitted |
|---|
' +
- d.builds.map((b) => {
+ d.builds.filter((b) => showTest || !b.ownerTest).map((b) => {
const cls = b.status === 'done' ? 'done' : b.status === 'failed' ? 'failed' : 'other';
const rr = ratingFor(b);
const g = b.grades;
// A build superseded by a later queue submission isn't a distinct failure โ it's
// bookkeeping. Mute it so the eye lands on failures that actually need attention.
const superseded = /superseded|replaced in the queue/i.test(b.error || '');
- return '
| ' + esc(b.repo) + ' | ' +
+ return '
| ' + esc(b.repo) + (b.ownerTest ? ' my test' : '') + ' | ' +
'' + esc(b.status) + '' + (g && g.exemplary ? ' exemplary' : '') + ' | ' +
'' + (b.error ? esc(b.error) : 'โ') + ' | ' +
'' + (g && g.overall != null ? esc(g.overall) : 'โ') + ' | ' +
- '' + (rr && rr.score != null ? '' + esc(rr.score) + (rr.thoughts ? ' ๐ฌ' : '') + '' : 'โ') + ' | ' +
+ '' + (rr ? '' + (rr.score != null ? esc(rr.score) : '') + (rr.verdict ? ' ' + esc(rr.verdict) + '' : '') + (rr.thoughts ? ' ๐ฌ' : '') + '' : 'โ') + ' | ' +
'' + (g && g.headline != null ? esc(g.headline) : 'โ') + ' | ' +
'' + (b.costUsd != null ? '$' + esc(b.costUsd) : 'โ') + ' | ' +
'' + (b.liveUrl ? '' + esc(b.liveUrl.replace('https://','')) + '' : 'โ') + ' | ' +
@@ -300,8 +363,8 @@ People (email ledger)
$('[data-reach]').innerHTML = [
tile(d.repo ? d.repo.stars : null, 'GitHub stars'),
tile(d.repo ? d.repo.forks : null, 'forks'),
- tile(d.traffic.views14d ? d.traffic.views14d.total + ' (' + d.traffic.views14d.uniques + ' uniq)' : null, 'repo views, 14d'),
- tile(d.traffic.clones14d ? d.traffic.clones14d.total + ' (' + d.traffic.clones14d.uniques + ' uniq)' : null, 'repo clones, 14d'),
+ tile(d.traffic.repoViews14d ? d.traffic.repoViews14d.total + ' (' + d.traffic.repoViews14d.uniques + ' uniq)' : null, 'repo views, 14d'),
+ tile(d.traffic.repoClones14d ? d.traffic.repoClones14d.total + ' (' + d.traffic.repoClones14d.uniques + ' uniq)' : null, 'repo clones, 14d'),
tile(d.npm.lastWeek, 'npm downloads, week'),
tile(d.npm.lastMonth, 'npm downloads, month'),
tile(d.repo ? d.repo.openIssues : null, 'open issues'),
@@ -309,6 +372,7 @@ People (email ledger)
].join('');
}
+ $('[data-show-test]').addEventListener('change', function (e) { showTest = e.target.checked; if (lastData) render(lastData); });
$('[data-key-go]').addEventListener('click', () => load($('[data-key-input]').value.trim()));
$('[data-key-input]').addEventListener('keydown', (e) => { if (e.key === 'Enter') load($('[data-key-input]').value.trim()); });
const saved = localStorage.getItem(KEY_STORE);
diff --git a/landing/netlify/functions/admin-stats.js b/landing/netlify/functions/admin-stats.js
index ad8c1c2..530d701 100644
--- a/landing/netlify/functions/admin-stats.js
+++ b/landing/netlify/functions/admin-stats.js
@@ -9,10 +9,13 @@
const { getStore, connectLambda } = require("@netlify/blobs");
const crypto = require("node:crypto");
+const { buildInsights, parseRepo } = require("../lib/admin-insights.js");
const REPO = "stuinfla/Repo-Explainer";
const SITE_ID = "df4e3cd8-a71e-4668-8da7-c8d168edd341";
const FEEDBACK_FORM_ID = "6a456c9b29c67900095b060f";
+// Emails whose builds are the owner's own tests (build.js tags those gists "[owner-test]").
+const OWNER_EMAILS = (process.env.OWNER_EMAILS || "sikerr@gmail.com,stuart@isovision.ai").split(",").map((e) => e.trim().toLowerCase()).filter(Boolean);
function json(status, body) {
return {
@@ -88,8 +91,10 @@ async function listBuilds(token) {
if (gists.length < 100) break;
}
const builds = await Promise.all(out.map(async (g) => {
+ const parsed = parseRepo(g.description);
const base = {
- repo: (g.description || "").replace("explainmyrepo build: ", ""),
+ repo: parsed.repo,
+ ownerTest: parsed.ownerTest,
createdAt: g.created_at,
updatedAt: g.updated_at,
gistUrl: g.html_url,
@@ -169,7 +174,8 @@ async function readBuildRatings() {
id: s.id,
repo: s.data?.repo || null,
buildId: s.data?.build_id || null,
- score: s.data?.score != null ? Number(s.data.score) : null,
+ score: s.data?.score != null && s.data.score !== "" ? Number(s.data.score) : null,
+ verdict: s.data?.verdict || null,
thoughts: s.data?.thoughts || null,
email: s.data?.email || null,
at: s.created_at,
@@ -279,8 +285,13 @@ exports.handler = async function (event) {
mostRecentAttempt: newestBuild ? { repo: newestBuild.repo, status: newestBuild.status, at: newestBuild.createdAt } : null,
};
+ const insights = buildInsights({
+ builds, ratings: buildRatings.ratings || [], traffic: trafficArr, doors: doors || {}, ledger: ledger || {}, ownerEmails: OWNER_EMAILS,
+ });
+
return json(200, {
generatedAt: new Date().toISOString(),
+ insights,
doorStatus,
feedback,
buildRatings,
diff --git a/landing/netlify/functions/build.js b/landing/netlify/functions/build.js
index c2f040d..fdc2780 100644
--- a/landing/netlify/functions/build.js
+++ b/landing/netlify/functions/build.js
@@ -15,6 +15,8 @@
========================================================================== */
const FREE_PER_EMAIL = 5;
+// The owner's own test builds are tagged in the status-gist description so the admin page can keep them out of real numbers.
+const OWNER_EMAILS = (process.env.OWNER_EMAILS || "sikerr@gmail.com,stuart@isovision.ai").split(",").map((e) => e.trim().toLowerCase()).filter(Boolean);
const REPO = "stuinfla/Repo-Explainer"; // where build-explainer.yml lives
function json(statusCode, obj) {
@@ -180,7 +182,7 @@ exports.handler = async function (event) {
try {
const r = await fetch("https://api.github.com/gists", {
method: "POST", headers: gh(token),
- body: JSON.stringify({ description: "explainmyrepo build: " + fullName, public: true, files: { "status.json": { content: JSON.stringify(initial, null, 2) } } }),
+ body: JSON.stringify({ description: "explainmyrepo build: " + fullName + (OWNER_EMAILS.includes(email) ? " [owner-test]" : ""), public: true, files: { "status.json": { content: JSON.stringify(initial, null, 2) } } }),
});
if (!r.ok) { console.error("gist create failed", r.status, await r.text()); return json(502, { error: "Couldn't start the build tracker โ try again." }); }
gistId = (await r.json()).id;
diff --git a/landing/netlify/lib/admin-insights.js b/landing/netlify/lib/admin-insights.js
new file mode 100644
index 0000000..7108315
--- /dev/null
+++ b/landing/netlify/lib/admin-insights.js
@@ -0,0 +1,143 @@
+// admin-insights.js โ pure, dependency-free computation behind the admin page's "is this helping
+// people?" view. Kept out of admin-stats.js so it can be unit-tested with plain objects.
+//
+// our score vs theirs ยท a funnel (views -> accepted -> built -> rated) ยท owner test builds
+// separated from real ones ยท a plain-English summary ยท what the next build is told (lessons)
+
+const OWNER_TAG = " [owner-test]"; // appended to the status-gist description by build.js
+const WINDOW_DAYS = 14;
+
+// Same mapping the build-time lessons use (tools/feedback-lessons.mjs classify): the one-tap
+// verdict wins; older ratings fall back to the numeric score (85 / 55).
+function classify(r) {
+ const v = r.verdict;
+ if (v === "nailed" || v === "close" || v === "missed") return v;
+ if (r.score == null || !Number.isFinite(r.score)) return null;
+ return r.score >= 85 ? "nailed" : r.score >= 55 ? "close" : "missed";
+}
+// A one-tap verdict has no number; this is the same midpoint the rate page's slider uses.
+const VERDICT_SCORE = { nailed: 92, close: 70, missed: 35 };
+
+// Reader comments are untrusted text that this page renders (it always escapes) and that the
+// builder reads (it sanitizes with the same rules in tools/feedback-lessons.mjs). Cap here too.
+function clean(t) {
+ return String(t || "")
+ .replace(/```[\s\S]*?```/g, " ")
+ .replace(/https?:\/\/\S+/gi, "[link]")
+ .replace(/<[^>]*>/g, " ")
+ .replace(/\s+/g, " ")
+ .trim()
+ .slice(0, 260);
+}
+
+function isTestRating(r) {
+ return /^selftest\//i.test(String(r.repo || ""));
+}
+
+function parseRepo(description) {
+ const raw = String(description || "").replace("explainmyrepo build: ", "");
+ const owner = raw.endsWith(OWNER_TAG);
+ return { repo: owner ? raw.slice(0, -OWNER_TAG.length) : raw, ownerTest: owner };
+}
+
+function mean(xs) {
+ return xs.length ? Math.round(xs.reduce((a, b) => a + b, 0) / xs.length) : null;
+}
+
+function buildInsights({ builds, ratings, traffic, doors, ledger, ownerEmails, now }) {
+ const nowMs = (now ? new Date(now) : new Date()).getTime();
+ const since = nowMs - WINDOW_DAYS * 86400000;
+ const inWindow = (iso) => iso && new Date(iso).getTime() >= since;
+
+ const real = builds.filter((b) => !b.ownerTest);
+ const test = builds.filter((b) => b.ownerTest);
+
+ // The ledger counts every build per email, including ours; builds made before the marker
+ // existed cannot be told apart, so say how many are probably unmarked instead of guessing which.
+ const owners = new Set((ownerEmails || []).map((e) => e.toLowerCase()));
+ const ledgerOwnerBuilds = Object.entries(ledger || {})
+ .filter(([email]) => owners.has(email.toLowerCase()))
+ .reduce((a, [, v]) => a + (v.count || 0), 0);
+ const unmarkedOwnerEstimate = Math.max(0, ledgerOwnerBuilds - test.length);
+
+ const reader = (ratings || []).filter((r) => !isTestRating(r)).map((r) => ({ ...r, kind: classify(r) })).filter((r) => r.kind);
+ const tally = { nailed: 0, close: 0, missed: 0 };
+ for (const r of reader) tally[r.kind]++;
+
+ // Our score vs theirs, per page: our synthesized score against the reader's verdict.
+ const compared = [];
+ for (const r of reader) {
+ const b = real.find((x) => r.buildId && x.buildId && x.buildId === r.buildId) || real.find((x) => x.repo && x.repo === r.repo);
+ const ours = b && b.grades ? b.grades.overall : null;
+ compared.push({
+ repo: r.repo || (b && b.repo) || "unknown",
+ ours,
+ theirs: r.score != null ? r.score : VERDICT_SCORE[r.kind],
+ verdict: r.kind,
+ comment: clean(r.thoughts) || null,
+ at: r.at,
+ matched: !!b,
+ });
+ }
+ const withOurs = compared.filter((c) => c.ours != null);
+ const ourMean = mean(withOurs.map((c) => c.ours));
+ const theirMean = mean(withOurs.map((c) => c.theirs));
+ const gap = ourMean != null && theirMean != null ? ourMean - theirMean : null;
+
+ // Funnel over the last 14 days.
+ const siteDays = Array.isArray(traffic) ? traffic : [];
+ const views = siteDays.reduce((a, t) => a + (t.views || 0), 0);
+ const accepted = Object.entries(doors || {})
+ .filter(([day]) => new Date(day + "T23:59:59Z").getTime() >= since)
+ .reduce((a, [, v]) => a + ((v && v.accepted) || 0), 0);
+ const built = real.filter((b) => b.status === "done" && inWindow(b.createdAt)).length;
+ const rated = reader.filter((r) => inWindow(r.at)).length;
+ const funnel = [
+ { key: "views", label: "Visited the site", n: views },
+ { key: "accepted", label: "Asked for a page (accepted)", n: accepted },
+ { key: "built", label: "Got a finished page", n: built },
+ { key: "rated", label: "Told us how it went", n: rated },
+ ];
+
+ // What the next build is told (mirrors tools/feedback-lessons.mjs: negatives with comments
+ // first, newest first, capped).
+ const byRecent = (a, b) => String(b.at).localeCompare(String(a.at));
+ const learned = {
+ fix: reader.filter((r) => r.thoughts && (r.kind === "close" || r.kind === "missed")).sort(byRecent).slice(0, 8)
+ .map((r) => ({ repo: r.repo || "?", verdict: r.kind, text: clean(r.thoughts) })).filter((l) => l.text),
+ keep: reader.filter((r) => r.thoughts && r.kind === "nailed").sort(byRecent).slice(0, 3)
+ .map((r) => ({ repo: r.repo || "?", verdict: r.kind, text: clean(r.thoughts) })).filter((l) => l.text),
+ };
+
+ // Plain English, no jargon.
+ const lines = [];
+ lines.push(built + " finished page" + (built === 1 ? "" : "s") + " in the last " + WINDOW_DAYS + " days"
+ + (views ? ", from " + views + " site visit" + (views === 1 ? "" : "s") : "")
+ + (unmarkedOwnerEstimate > 0 ? " (some of these are your own older test builds, which could not be tagged after the fact: about " + unmarkedOwnerEstimate + " in all time)" : "") + ".");
+ if (reader.length) {
+ lines.push(reader.length + " reader" + (reader.length === 1 ? " has" : "s have") + " rated a page: "
+ + tally.nailed + " nailed it, " + tally.close + " close, " + tally.missed + " missed.");
+ } else {
+ lines.push("No reader has rated a page yet.");
+ }
+ if (gap != null && withOurs.length >= 2) {
+ lines.push("Our own grader averages " + ourMean + " on those pages; readers imply about " + theirMean + "."
+ + (gap >= 15 ? " The grader is more generous than readers: trust readers." : gap <= -15 ? " Readers like pages more than our grader does." : " They roughly agree."));
+ } else if (withOurs.length === 1) {
+ lines.push("Only one rated page has a grader score to compare with, so no agreement figure yet.");
+ }
+ if (learned.fix.length) lines.push(learned.fix.length + " reader complaint" + (learned.fix.length === 1 ? " is" : "s are") + " being passed to every new build.");
+ if (built > 0 && rated === 0) lines.push("Nobody rated in this window: the email ask is optional, so low volume is normal.");
+
+ return {
+ windowDays: WINDOW_DAYS,
+ summary: lines,
+ funnel,
+ ratings: { total: reader.length, tally, compared: compared.sort(byRecent), ourMean, theirMean, gap },
+ learned,
+ owner: { markedTestBuilds: test.length, ledgerBuilds: ledgerOwnerBuilds, unmarkedEstimate: unmarkedOwnerEstimate },
+ realBuilds: real.length,
+ };
+}
+
+module.exports = { buildInsights, classify, parseRepo, clean, OWNER_TAG, VERDICT_SCORE };
diff --git a/tests/admin-insights.test.mjs b/tests/admin-insights.test.mjs
new file mode 100644
index 0000000..56ff5eb
--- /dev/null
+++ b/tests/admin-insights.test.mjs
@@ -0,0 +1,112 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import { createRequire } from 'node:module';
+const require = createRequire(import.meta.url);
+const { buildInsights, classify, parseRepo, clean, OWNER_TAG } = require('../landing/netlify/lib/admin-insights.js');
+
+const NOW = '2026-11-09T20:00:00Z';
+const b = (o) => ({ repo: 'a/b', status: 'done', createdAt: '2026-11-08T10:00:00Z', buildId: 'id-' + Math.random(), grades: { overall: 90 }, ownerTest: false, ...o });
+const base = (o = {}) => buildInsights({ builds: [], ratings: [], traffic: [], doors: {}, ledger: {}, ownerEmails: ['me@x.com'], now: NOW, ...o });
+
+test('parseRepo strips the owner-test tag and flags it', () => {
+ assert.deepEqual(parseRepo('explainmyrepo build: a/b' + OWNER_TAG), { repo: 'a/b', ownerTest: true });
+ assert.deepEqual(parseRepo('explainmyrepo build: a/b'), { repo: 'a/b', ownerTest: false });
+});
+
+test('classify: verdict wins, numeric fallback thresholds 85/55, junk is null', () => {
+ assert.equal(classify({ verdict: 'missed', score: 99 }), 'missed');
+ assert.equal(classify({ score: 85 }), 'nailed');
+ assert.equal(classify({ score: 84 }), 'close');
+ assert.equal(classify({ score: 54 }), 'missed');
+ assert.equal(classify({ score: null }), null);
+ assert.equal(classify({ verdict: 'bogus', score: NaN }), null);
+});
+
+test('owner test builds are kept out of funnel and real-build counts', () => {
+ const r = base({ builds: [b({}), b({ ownerTest: true }), b({ ownerTest: true })] });
+ assert.equal(r.realBuilds, 1);
+ assert.equal(r.funnel.find((f) => f.key === 'built').n, 1);
+ assert.equal(r.owner.markedTestBuilds, 2);
+});
+
+test('unmarked owner builds are estimated from the ledger, never guessed per-build', () => {
+ const r = base({ builds: [b({ ownerTest: true })], ledger: { 'ME@x.com': { count: 11 }, 'other@y.com': { count: 3 } } });
+ assert.equal(r.owner.ledgerBuilds, 11);
+ assert.equal(r.owner.unmarkedEstimate, 10);
+});
+
+test('funnel respects the 14-day window and sums views and accepted door tallies', () => {
+ const r = base({
+ traffic: [{ date: '2026-11-09', views: 40 }, { date: '2026-11-08', views: 10 }],
+ doors: { '2026-11-09': { accepted: 3 }, '2026-10-01': { accepted: 99 } },
+ builds: [b({}), b({ createdAt: '2026-09-01T00:00:00Z' }), b({ status: 'failed' })],
+ });
+ const f = Object.fromEntries(r.funnel.map((x) => [x.key, x.n]));
+ assert.deepEqual(f, { views: 50, accepted: 3, built: 1, rated: 0 });
+});
+
+test('our score vs theirs: matches by build id, then repo; one-tap verdict maps to a number', () => {
+ const bd = b({ buildId: 'B1', repo: 'o/r', grades: { overall: 96 } });
+ const r = base({ builds: [bd], ratings: [{ repo: 'o/r', buildId: 'B1', verdict: 'missed', score: null, thoughts: 'diagram was wrong', at: '2026-11-09T01:00:00Z' }] });
+ const c = r.ratings.compared[0];
+ assert.equal(c.ours, 96); assert.equal(c.theirs, 35); assert.equal(c.matched, true);
+ assert.equal(r.ratings.ourMean, 96); assert.equal(r.ratings.theirMean, 35); assert.equal(r.ratings.gap, 61);
+});
+
+test('operator selftest ratings and unclassifiable rows never count as reader evidence', () => {
+ const r = base({ ratings: [
+ { repo: 'selftest/loop-check', verdict: 'missed', thoughts: 'x', at: 'a' },
+ { repo: 'a/b', score: null, verdict: null, thoughts: 'no signal', at: 'b' },
+ { repo: 'a/b', verdict: 'nailed', thoughts: 'great', at: 'c' },
+ ] });
+ assert.equal(r.ratings.total, 1);
+ assert.deepEqual(r.ratings.tally, { nailed: 1, close: 0, missed: 0 });
+});
+
+test('learned lessons: negatives first (max 8), positives (max 3), only with comments, hostile text neutralised', () => {
+ const ratings = [];
+ for (let i = 0; i < 12; i++) ratings.push({ repo: 'r/' + i, verdict: 'close', thoughts: 'c' + i, at: '2026-11-0' + (1 + (i % 9)) });
+ for (let i = 0; i < 5; i++) ratings.push({ repo: 'p/' + i, verdict: 'nailed', thoughts: 'p' + i, at: '2026-11-0' + (1 + i) });
+ ratings.push({ repo: 'h/x', verdict: 'missed', thoughts: '
```rm -rf``` https://evil.test/a ' + 'z'.repeat(400), at: '2026-11-09' });
+ ratings.push({ repo: 'n/c', verdict: 'missed', thoughts: '', at: '2026-11-09' });
+ const r = base({ ratings });
+ assert.equal(r.learned.fix.length, 8);
+ assert.equal(r.learned.keep.length, 3);
+ const hostile = r.learned.fix.find((l) => l.repo === 'h/x');
+ assert.ok(hostile, 'newest negative is kept');
+ assert.ok(hostile.text.length <= 260);
+ assert.doesNotMatch(hostile.text, /<|```|https?:/);
+ assert.ok(!r.learned.fix.some((l) => l.repo === 'n/c'), 'a rating without a comment is not a lesson');
+});
+
+test('clean() caps, strips markup, urls and fences', () => {
+ assert.equal(clean('a b https://x.y/z ```c``` d'), 'a b [link] d');
+ assert.equal(clean('x'.repeat(999)).length, 260);
+ assert.equal(clean(null), '');
+});
+
+test('summary is plain English and handles the empty state', () => {
+ const r = base();
+ assert.ok(r.summary.some((l) => /No reader has rated/.test(l)));
+ const r2 = base({ builds: [b({})], ratings: [] });
+ assert.ok(r2.summary.some((l) => /optional, so low volume is normal/.test(l)));
+});
+
+test('summary admits older untagged owner builds instead of claiming everything is real traffic', () => {
+ const r = base({ builds: [b({})], ledger: { 'me@x.com': { count: 4 } } });
+ assert.match(r.summary[0], /your own older test builds/);
+ assert.doesNotMatch(base({ builds: [b({})] }).summary[0], /older test builds/);
+});
+
+test('source shape: build.js tags owner gists and the admin consumes insights + fixed traffic keys', () => {
+ const build = fs.readFileSync(new URL('../landing/netlify/functions/build.js', import.meta.url), 'utf8');
+ const stats = fs.readFileSync(new URL('../landing/netlify/functions/admin-stats.js', import.meta.url), 'utf8');
+ const html = fs.readFileSync(new URL('../landing/admin.html', import.meta.url), 'utf8');
+ assert.match(build, /\[owner-test\]/);
+ assert.match(stats, /buildInsights\(/);
+ assert.match(stats, /verdict: s\.data\?\.verdict/);
+ assert.match(html, /d\.traffic\.repoViews14d/);
+ assert.doesNotMatch(html, /d\.traffic\.views14d/);
+ assert.match(html, /data-show-test/);
+});