// Harness for the admin panel's GUESTS list (guest accounts), run through the // skill's checker alongside the chart harness: // ~/.hermes/skills/research/inference-cooperative/scripts/check-page-js.sh \ // app/main.py admin-panel-guests-harness.js // Exercises load() against both payload shapes — the portal's split payload // (guests[]) and an older payload that still tags rows account_type='guest' // inside members[] — and asserts the invariants that matter: // * guests NEVER count as members, in either shape; // * guests never render in the members table; // * the guests list shows recipient, inviter, credits remaining, expiry // and status, and hides entirely when there are no guests; // * the Members-view switch rule keeps the section's visibility handled // in switchView (the trap that stranded the Admin section on Models). // The checker evals in CommonJS (no top-level await), so the body is wrapped. const assert = (cond, msg) => { if (!cond) { console.error("FAIL: " + msg); process.exit(1); } }; const count = (s, re) => (String(s).match(re) || []).length; const txt = (id) => String(document.getElementById(id).textContent); // stub keeps raw types; the DOM stringifies const memberRow = (email, spend) => ({ email, username: email.split("@")[0], active: true, activated: true, account_type: "member", spend, all_time_spend: spend * 10, balance: 15, credit_balance: 0, credits_remaining: 0, remaining: 15 - spend, }); async function runLoad(overview) { globalThis.fetch = async (url) => ({ status: 200, json: async () => (String(url).indexOf("/api/overview") !== -1 ? overview : { models: [] }), }); await load(); } (async () => { // ---- Shape 1: the portal splits guests into their own list ---- await runLoad({ members: [memberRow("alice@example.com", 2), memberRow("bob@example.com", 1)], guests: [{ email: "friend@example.com", username: "friend", active: true, account_type: "guest", guest_inviter: "alice@example.com", credit_balance: 5, credits_remaining: 3.5, guest_expires_at: "2027-01-07T02:00:00", guest_status: "active", spend: 1.5, all_time_spend: 1.5, }], totals: { members: 2, total_spend: 4.5, total_all_time_spend: 45, operator_spend: 1, operator_all_time_spend: 10 }, }); assert(txt("tot-members") === "2", "split payload: member count is 2 (got " + txt("tot-members") + ")"); assert(txt("tot-guests") === "1", "split payload: guests count is 1"); assert(txt("tot-spend-cycle") === "$4.50", "split payload: spend total unchanged by the guests split"); { const rowsHtml = document.getElementById("rows").innerHTML; assert(count(rowsHtml, //g) === 2, "members table holds only the 2 members"); assert(rowsHtml.indexOf("friend@example.com") === -1, "guest never renders in the members table"); const g = document.getElementById("guest-rows").innerHTML; assert(count(g, //g) === 1, "guests list holds exactly the 1 guest"); assert(g.indexOf("friend@example.com") !== -1, "recipient email shown"); assert(g.indexOf("alice@example.com") !== -1, "inviting member shown from the ledger"); assert(g.indexOf("$3.50") !== -1, "credits remaining shown"); assert(g.indexOf("2027-01-07") !== -1, "time-box expiry date shown"); assert(/pill active[^>]*>active]*>expired]*>converted]*>invited]*>expiredactive { console.error("FAIL: " + (e && e.stack || e)); process.exit(1); });