226 lines
9.8 KiB
JavaScript
226 lines
9.8 KiB
JavaScript
// Housing assignment-cycle trigger + Mentor skill-holder seed + Housing
|
|
// wallet-credit wiring acceptance test (plan todo 15). Self-contained
|
|
// Playwright runner, same shape as e2e/fairDrawWalletCredit.e2e.mjs: starts
|
|
// a real Vite dev server, opens a real browser page, and drives the real
|
|
// app UI through its real routes - no mocks of the ledger/eventlog/solver.
|
|
//
|
|
// HAPPY: loads the real "/admin" route, clicks the real "Load Hollow demo"
|
|
// button (which now also runs one real `recordHousingAssignmentCycle()`
|
|
// cycle and seeds `seed.skillHolder` data as part of the same click - see
|
|
// `AdminSeedPanel.handleLoadDemo`), then visits the real "/miniapp/housing"
|
|
// and "/miniapp/mentor" routes and asserts:
|
|
// - Housing shows a real assigned room slot (not the "Not yet assigned"
|
|
// empty state) for the device's own identity.
|
|
// - Mentor shows at least one real at-risk skill card (not the
|
|
// "No at-risk skills to show yet" empty state).
|
|
// - The home route's WalletCard transaction history shows a real,
|
|
// signed "Issued +<HOUSING_ASSIGNMENT_CREDIT_AMOUNT>" row distinct from
|
|
// the demo fixture's own welcome-grant/commons-fund rows - proving the
|
|
// housing assignment cycle's wallet-credit wiring actually fired for
|
|
// the device's own real identity.
|
|
import { chromium } from "playwright";
|
|
import { createServer as createViteServer } from "vite";
|
|
import * as ed from "@noble/ed25519";
|
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = resolve(__dirname, "..");
|
|
const VITE_PORT = 48000 + Math.floor(Math.random() * 10000);
|
|
const APP_URL = `http://127.0.0.1:${VITE_PORT}`;
|
|
|
|
/**
|
|
* Pre-seeds the real local-identity record directly into IndexedDB (same
|
|
* schema `src/lib/db.ts` defines) via `page.addInitScript`, BEFORE the
|
|
* page's own React tree ever mounts - same known, pre-existing,
|
|
* out-of-scope StrictMode double-invoke race workaround documented in
|
|
* transactionHistorySignature.e2e.mjs, not touched here.
|
|
*/
|
|
async function seedIdentity(context) {
|
|
const { secretKey, publicKey } = await ed.keygenAsync();
|
|
await context.addInitScript(
|
|
({ secretKey, publicKey }) => {
|
|
const openReq = indexedDB.open("the-commons-hollow", 4);
|
|
openReq.onupgradeneeded = () => {
|
|
const db = openReq.result;
|
|
if (!db.objectStoreNames.contains("identity")) db.createObjectStore("identity", { keyPath: "id" });
|
|
if (!db.objectStoreNames.contains("eventLog")) {
|
|
const store = db.createObjectStore("eventLog", { keyPath: "id", autoIncrement: true });
|
|
store.createIndex("lamportTs", "lamportTs", { unique: false });
|
|
}
|
|
if (!db.objectStoreNames.contains("miniappPackages")) {
|
|
const store = db.createObjectStore("miniappPackages", { keyPath: "id" });
|
|
store.createIndex("sourceBlobId", "sourceBlobId", { unique: true });
|
|
}
|
|
};
|
|
openReq.onsuccess = () => {
|
|
const db = openReq.result;
|
|
const tx = db.transaction("identity", "readwrite");
|
|
tx.objectStore("identity").put({
|
|
id: "local",
|
|
publicKey: new Uint8Array(publicKey),
|
|
secretKey: new Uint8Array(secretKey),
|
|
createdAt: Date.now(),
|
|
});
|
|
};
|
|
},
|
|
{ secretKey: Array.from(secretKey), publicKey: Array.from(publicKey) },
|
|
);
|
|
}
|
|
|
|
async function runHappyPath(browser) {
|
|
const context = await browser.newContext();
|
|
const evidence = { scenario: "happy", steps: {} };
|
|
try {
|
|
await seedIdentity(context);
|
|
const page = await context.newPage();
|
|
|
|
await page.goto(`${APP_URL}/admin`);
|
|
const loadDemoButton = page.getByRole("button", { name: "Load Hollow demo" });
|
|
await loadDemoButton.waitFor();
|
|
await loadDemoButton.click();
|
|
const demoStatus = page.getByTestId("demo-load-status");
|
|
await demoStatus.waitFor();
|
|
const demoStatusText = await demoStatus.innerText();
|
|
evidence.steps.demoLoaded = { demoStatusText };
|
|
if (!demoStatusText.includes("Demo data loaded")) {
|
|
throw new Error(`happy: expected the demo to load, got status "${demoStatusText}"`);
|
|
}
|
|
|
|
// Housing: real assigned slot, not the permanent "Not yet assigned"
|
|
// empty state GAP-11 described.
|
|
await page.goto(`${APP_URL}/miniapp/housing`);
|
|
const assignedSlot = page.getByTestId("housing-assigned-slot");
|
|
await assignedSlot.waitFor();
|
|
const assignedSlotText = await assignedSlot.innerText();
|
|
const emptyStateVisible = await page.getByTestId("housing-assignment-empty").isVisible().catch(() => false);
|
|
evidence.steps.housingShowsRealAssignment = {
|
|
assignedSlotText,
|
|
emptyStateVisible,
|
|
isRealAssignment: assignedSlotText !== "--" && !emptyStateVisible,
|
|
};
|
|
if (assignedSlotText === "--" || emptyStateVisible) {
|
|
throw new Error(
|
|
`happy: expected Housing to show a real assigned slot, got slotText="${assignedSlotText}" emptyStateVisible=${emptyStateVisible}`,
|
|
);
|
|
}
|
|
|
|
// Mentor: at least one real at-risk skill card, not the permanent
|
|
// "No at-risk skills to show yet" empty state GAP-11 described.
|
|
await page.goto(`${APP_URL}/miniapp/mentor`);
|
|
const mentorFeed = page.getByTestId("mentor-feed");
|
|
await mentorFeed.waitFor();
|
|
const mentorEmptyVisible = await page.getByTestId("mentor-feed-empty").isVisible().catch(() => false);
|
|
const atRiskCardText = await page.getByTestId("mentor-card-well-repair").innerText();
|
|
evidence.steps.mentorShowsRealAtRiskSkill = {
|
|
mentorEmptyVisible,
|
|
atRiskCardText,
|
|
isRealAtRiskSkill: !mentorEmptyVisible && atRiskCardText.length > 0,
|
|
};
|
|
if (mentorEmptyVisible) {
|
|
throw new Error("happy: expected Mentor to show a real at-risk skill, got the empty state instead");
|
|
}
|
|
|
|
// Wallet: a real, signed "Issued +10" row distinct from the demo
|
|
// fixture's own "+50"/"-10" rows, proving the housing assignment
|
|
// cycle's wallet-credit wiring fired for the device's own identity.
|
|
await page.goto(`${APP_URL}/`);
|
|
const historyEntries = page.getByTestId("history-entry");
|
|
await historyEntries.first().waitFor();
|
|
const rowTexts = await historyEntries.allInnerTexts();
|
|
const balance = await page.getByTestId("wallet-balance").innerText();
|
|
const housingCreditRow = rowTexts.find((t) => t.includes("Issued") && t.includes("+10"));
|
|
evidence.steps.walletReflectsHousingCredit = {
|
|
balance,
|
|
historyRowCount: rowTexts.length,
|
|
allRows: rowTexts,
|
|
housingCreditRowFound: Boolean(housingCreditRow),
|
|
};
|
|
if (!housingCreditRow) {
|
|
throw new Error(`happy: expected a real "Issued +10" housing-credit row, got rows: ${JSON.stringify(rowTexts)}`);
|
|
}
|
|
|
|
evidence.pass = true;
|
|
return evidence;
|
|
} catch (err) {
|
|
evidence.pass = false;
|
|
evidence.error = String(err && err.message ? err.message : err);
|
|
throw Object.assign(err, { evidence });
|
|
} finally {
|
|
await context.close();
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const vite = await createViteServer({
|
|
root: ROOT,
|
|
configFile: resolve(ROOT, "vite.config.ts"),
|
|
logLevel: "warn",
|
|
server: { host: "127.0.0.1", port: VITE_PORT, strictPort: true },
|
|
});
|
|
await vite.listen();
|
|
|
|
const browser = await chromium.launch({ headless: true, args: ["--no-sandbox"] });
|
|
|
|
let result;
|
|
let failed = false;
|
|
try {
|
|
try {
|
|
result = await runHappyPath(browser);
|
|
} catch (e) {
|
|
failed = true;
|
|
result = e.evidence ?? { scenario: "happy", pass: false, error: String(e) };
|
|
}
|
|
} finally {
|
|
await browser.close();
|
|
await vite.close();
|
|
}
|
|
|
|
const evDir = resolve(ROOT, ".omo/evidence/the-commons-hollow-polish");
|
|
mkdirSync(evDir, { recursive: true });
|
|
const now = new Date().toISOString();
|
|
|
|
writeFileSync(
|
|
resolve(evDir, "task-15-the-commons-hollow-polish.json"),
|
|
JSON.stringify(
|
|
{
|
|
task:
|
|
"15. Add a Housing assignment-cycle trigger; fix Mentor's dependents double-counting; seed Mentor skill-holder data",
|
|
qa: "happy",
|
|
description:
|
|
"The real '/admin' route's 'Load Hollow demo' button now also runs one real recordHousingAssignmentCycle() cycle and seeds real seed.skillHolder data as part of the same click. Loading the demo fixture is asserted to leave Housing ('/miniapp/housing') showing a real assigned room slot for the device's own identity (not the permanent 'Not yet assigned' empty state), Mentor ('/miniapp/mentor') showing a real at-risk 'Well Repair' skill card (not the permanent 'No at-risk skills to show yet' empty state), and the home route's WalletCard transaction history showing a real, signed 'Issued +10' row distinct from the demo fixture's own welcome-grant/commons-fund rows - proving the housing assignment cycle's wallet-credit wiring (mirroring RevealDraw.tsx's pattern) actually fired for the device's own real identity.",
|
|
tool: "Playwright (chromium), real Vite dev server, real app UI ('/admin' -> AdminSeedPanel, '/miniapp/housing' -> FloorPlanScreen, '/miniapp/mentor' -> MentorScreen, '/' -> WalletCard/TransactionHistory)",
|
|
run_command: "node e2e/housingMentorWalletDemo.e2e.mjs",
|
|
selectors_used: [
|
|
"demo-load-status",
|
|
"housing-assigned-slot",
|
|
"housing-assignment-empty",
|
|
"mentor-feed",
|
|
"mentor-feed-empty",
|
|
"mentor-card-well-repair",
|
|
"wallet-balance",
|
|
"history-entry",
|
|
],
|
|
timestamp: now,
|
|
result,
|
|
pass: Boolean(result && result.pass),
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
|
|
console.log("\n===== e2e RESULTS =====");
|
|
console.log(JSON.stringify(result, null, 2));
|
|
console.log(`\nSUMMARY: happy=${result && result.pass ? "PASS" : "FAIL"}`);
|
|
if (failed || !(result && result.pass)) {
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error("FATAL", e);
|
|
process.exitCode = 1;
|
|
});
|