chore(deploy): deploy PWA shell and backend to production
This commit is contained in:
1 parent
b0d58396b9
commit
63b4456080
11 files changed
+411
-4
No files matched your search
@@ -26,3 +26,4 @@ dist-ssr
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
.vercel
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"task": "57. Deploy the PWA shell + minimal backend to a free-tier host",
|
||||
"qa": "failure - backend unreachable, frontend must degrade gracefully",
|
||||
"timestamp": "2026-11-18T03:34:36.386Z",
|
||||
"tool": "Playwright (chromium) against the live deployed URL, context.route('**/api/**') aborting every request with 'connectionrefused' to simulate the backend being fully unreachable",
|
||||
"ranAgainst": "https://agile-citrine-45o1qv9.tmp.now",
|
||||
"description": "With every /api/* request forced to fail at the network layer, asserts: (1) the shell still loads and renders, (2) the admin seed panel's 'Load Hollow demo' still succeeds (it is pure local IndexedDB + Ed25519 signing, never touches /api/*), (3) the Fair Share mini-app (local-first replay over the signed Event Log) still shows a real, non-zero allocation, (4) the home grid still renders all its tiles, and (5) no uncaught page error occurs anywhere in the flow.",
|
||||
"result": {
|
||||
"steps": {
|
||||
"rootLoadedWithBackendDown": {
|
||||
"url": "https://agile-citrine-45o1qv9.tmp.now/",
|
||||
"title": "wave-1-foundation"
|
||||
},
|
||||
"demoStillLoadsLocally": {
|
||||
"demoStatus": "Demo data loaded into the Event Log."
|
||||
},
|
||||
"localFirstMiniappStillWorks": {
|
||||
"powerAllocation": "850"
|
||||
},
|
||||
"homeGridStillRenders": {
|
||||
"tileCount": 13,
|
||||
"hasAtLeastOneTile": true
|
||||
}
|
||||
},
|
||||
"noUncaughtPageErrors": true,
|
||||
"pageErrors": [],
|
||||
"pass": true
|
||||
},
|
||||
"pass": true,
|
||||
"conclusion": "The frontend degrades gracefully: every local-first mini-app and the demo-seed flow keep working with zero uncaught errors when the backend is completely unreachable. Only todo 55's cross-device install-QR sharing feature (the one feature that genuinely needs /api/blob) would be the feature actually affected by a real backend outage; that is expected and is the only backend this app has."
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"task": "57. Deploy the PWA shell + minimal backend to a free-tier host",
|
||||
"timestamp": "2026-11-18T03:34:27.584Z",
|
||||
"deployment": {
|
||||
"provider": "Vercel",
|
||||
"method": "vercel deploy --temporary --yes (anonymous, no login/account/token required - a real Vercel CLI feature, confirmed via `vercel deploy --help`)",
|
||||
"url": "https://agile-citrine-45o1qv9.tmp.now",
|
||||
"deploymentId": "dpl_2JznG25qJZ7PGvsEzzWgUGXarULD",
|
||||
"isRealLiveDeployment": true,
|
||||
"caveat": "This is an ANONYMOUS TEMPORARY deployment. It expires ~1 hour after the last `vercel deploy --temporary` call (last redeploy was during this task run). By the time this artifact is read, the URL will very likely be dead (404/DNS failure) unless someone runs `vercel login` and claims it via the claimUrl below before expiry, or redeploys with `vercel deploy --temporary --yes` again from this worktree. No persistent/claimed production deployment exists - that requires a human to create/authenticate a real Vercel account (`vercel login`), which this sandbox has no credential for.",
|
||||
"claimUrl": "https://vercel.com/claim-deployment?code=3b757144-7cd7-4cda-9ca2-65f7b8ebae97",
|
||||
"howToMakePermanent": "A human runs `vercel login` (interactive OAuth/email flow this sandbox cannot complete), then `vercel link` + `vercel --prod` from /home/athapa/patriothacks-wt/wave-7-deploy, or visits the claimUrl above before the temporary deployment expires."
|
||||
},
|
||||
"buildGate": {
|
||||
"command": "npm run build (tsc -b && vite build)",
|
||||
"exitCode": 0
|
||||
},
|
||||
"testGate": {
|
||||
"command": "npx vitest run",
|
||||
"testFilesPassed": "69/69",
|
||||
"testsPassed": "394/394",
|
||||
"baselineAtHeadWas": 389,
|
||||
"countGrew": true,
|
||||
"note": "+5 tests added alongside the fairshare-need fix below. 5 pre-existing unhandled-rejection warnings (fake-indexeddb ConstraintError in AppRoutes.test.tsx) are unrelated to this change and were present before this task started."
|
||||
},
|
||||
"realBugsFoundAndFixedDuringDeployQA": [
|
||||
{
|
||||
"bug": "api/_lib/blobStore.ts defaulted to writing under process.cwd()/.data/blobs. Vercel's serverless function filesystem is read-only except /tmp, so every POST /api/blob returned HTTP 500 'failed to store blob' on the real deployment.",
|
||||
"fix": "Changed the default STORE_DIR to os.tmpdir()-based path (api/_lib/blobStore.ts). Writes now succeed (201) instead of crashing (500).",
|
||||
"residualLimitation": "Vercel serverless instances do not share /tmp across invocations/containers. Verified empirically: 3 immediate write-then-read round trips against the live deployment all returned 404 on the GET despite a successful 201 on the POST. This confirms the pre-existing code comment in blobStore.ts: real cross-request persistence requires @vercel/blob or @vercel/kv bound to a real Vercel project with a live credential, which this sandbox does not have (no account). The endpoint is reachable and responds correctly per-request (matches todo 57's 'reachable' requirement); it is NOT yet backed by durable storage in production."
|
||||
},
|
||||
{
|
||||
"bug": "No vercel.json existed. Direct navigation to any client-side route other than '/' (e.g. '/admin', '/miniapp/fair-share') returned a raw Vercel 404, because there was no rewrite telling Vercel to fall back to index.html for React Router's client-side routes.",
|
||||
"fix": "Added vercel.json with a rewrite rule sending every non-/api/* path to /index.html."
|
||||
},
|
||||
{
|
||||
"bug": "Loading the bundled demo seed (todo 9) never produced a non-empty Fair Share allocation bar. The demo fixture only ever appended seed.population/seed.resource.*/seed.baseline events - never a fairshare.need for any agent - so computeFairshareAllocation always saw zero registered agents (insufficientData: true) and every ResourceTiles bar rendered 'No allocation yet' / 0% width forever, regardless of who loaded the demo. This directly violated todo 57's acceptance criterion ('a judge must never land on an empty app').",
|
||||
"fix": "Added buildDemoNeedPayloads() (src/admin/seedEvents.ts) and wired it into AdminSeedPanel.handleLoadDemo: loading the demo now also registers the loading identity's own account as a fairshare participant (one fairshare.need per resource, positive weight), so the CEEI engine has a real agent to solve for and the bars render real, non-zero allocations."
|
||||
},
|
||||
{
|
||||
"bug": "AdminSeedPanel (the /admin route) called eventlog.append() without ever guaranteeing a local identity existed first. A judge who navigates straight to /admin (never visiting the shell, whose WalletCard is what normally triggers identity.init()) hit an uncaught IdentityMissingError and the demo/manual-seed flow crashed silently (pageerror, no UI feedback).",
|
||||
"fix": "AdminSeedPanel now calls identity.init() (idempotent) itself before any append, in both handleLoadDemo and handleSubmit, so the panel works standalone regardless of navigation order."
|
||||
}
|
||||
],
|
||||
"acceptance": {
|
||||
"httpCheck": {
|
||||
"description": "curl against the live deployed URL",
|
||||
"rootStatus": 200,
|
||||
"manifestStatus": 200,
|
||||
"serviceWorkerStatus": 200,
|
||||
"manifestContentType": "application/manifest+json-equivalent JSON body served correctly (name: 'The Commons', start_url '/', standalone display, icons present)"
|
||||
},
|
||||
"coldPlaywrightSession": {
|
||||
"tool": "Playwright (chromium), fresh BrowserContext (cleared IndexedDB/storage, simulating a first-time judge)",
|
||||
"flow": "goto deployed root URL -> goto /admin -> click 'Load Hollow demo' -> goto /miniapp/fair-share -> read all 4 resource tile bars",
|
||||
"result": {
|
||||
"steps": {
|
||||
"rootLoaded": {
|
||||
"url": "https://agile-citrine-45o1qv9.tmp.now/",
|
||||
"title": "wave-1-foundation"
|
||||
},
|
||||
"adminLoaded": {
|
||||
"url": "https://agile-citrine-45o1qv9.tmp.now/admin",
|
||||
"title": "wave-1-foundation"
|
||||
},
|
||||
"demoLoaded": {
|
||||
"demoStatus": "Demo data loaded into the Event Log."
|
||||
},
|
||||
"fairShareBars": {
|
||||
"power": {
|
||||
"barStyle": "width: 100%;",
|
||||
"allocationText": "850"
|
||||
},
|
||||
"water": {
|
||||
"barStyle": "width: 100%;",
|
||||
"allocationText": "620"
|
||||
},
|
||||
"food": {
|
||||
"barStyle": "width: 100%;",
|
||||
"allocationText": "410"
|
||||
},
|
||||
"cooling": {
|
||||
"barStyle": "width: 100%;",
|
||||
"allocationText": "300"
|
||||
}
|
||||
}
|
||||
},
|
||||
"anyNonZeroBar": true,
|
||||
"pass": true
|
||||
},
|
||||
"pass": true
|
||||
},
|
||||
"lighthouse": {
|
||||
"note": "Recorded for information only, per acceptance criteria - non-blocking.",
|
||||
"categoryScores": {
|
||||
"performance": 0.99,
|
||||
"accessibility": 0.87,
|
||||
"best-practices": 1,
|
||||
"seo": 0.82,
|
||||
"agentic-browsing": 0.25
|
||||
},
|
||||
"ranAgainst": "https://agile-citrine-45o1qv9.tmp.now"
|
||||
}
|
||||
},
|
||||
"backendReachability": {
|
||||
"description": "todo 55's /api/blob endpoint, reached from the deployed frontend's own origin (same-origin, no proxy needed at deploy time per vite.config.ts's dev-only proxy comment)",
|
||||
"postReturnsValidResponse": true,
|
||||
"postStatus": 201,
|
||||
"getAfterPostStatus": 404,
|
||||
"honestAssessment": "Reachable and functioning per-request (no crash, correct status codes). NOT durable across requests without real @vercel/blob/kv credentials - see realBugsFoundAndFixedDuringDeployQA above."
|
||||
},
|
||||
"devOnlySecretsOrMocksCheck": {
|
||||
"searched": "grep across api/ and src/ for dev-only secrets, hardcoded API keys, mock endpoints",
|
||||
"result": "None found. The only env-var reads in api/ are BLOB_STORE_DIR/PORT, both legitimate runtime config (no secret value, no mock). vite.config.ts's dev server proxy is explicitly commented as dev-only and is not used at deploy time (Vercel serves api/*.ts from the same origin automatically)."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { chromium } from "playwright";
|
||||
|
||||
const URL_BASE = process.argv[2];
|
||||
if (!URL_BASE) {
|
||||
console.error("usage: node task57-cold-check.mjs <deployed-url>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const browser = await chromium.launch({ headless: true, args: ["--no-sandbox"] });
|
||||
const context = await browser.newContext(); // fresh storage, simulates cold IndexedDB
|
||||
const page = await context.newPage();
|
||||
const consoleMsgs = [];
|
||||
const pageErrors = [];
|
||||
page.on("console", (msg) => consoleMsgs.push(`[${msg.type()}] ${msg.text()}`));
|
||||
page.on("pageerror", (err) => pageErrors.push(String(err)));
|
||||
const evidence = { steps: {} };
|
||||
try {
|
||||
// A cold judge loads the deployed root URL first - this is where the
|
||||
// shell (WalletCard) triggers identity.init() so a local ed25519
|
||||
// identity exists before anything is signed.
|
||||
await page.goto(`${URL_BASE}/`, { waitUntil: "networkidle" });
|
||||
evidence.steps.rootLoaded = { url: page.url(), title: await page.title() };
|
||||
|
||||
await page.goto(`${URL_BASE}/admin`, { waitUntil: "networkidle" });
|
||||
evidence.steps.adminLoaded = { url: page.url(), title: await page.title() };
|
||||
|
||||
await page.getByRole("button", { name: "Load Hollow demo" }).click();
|
||||
await page.getByTestId("demo-load-status").waitFor({ timeout: 10000 });
|
||||
const demoStatus = await page.getByTestId("demo-load-status").innerText();
|
||||
evidence.steps.demoLoaded = { demoStatus };
|
||||
|
||||
await page.goto(`${URL_BASE}/miniapp/fair-share`, { waitUntil: "networkidle" });
|
||||
await page.getByTestId("tile-power").waitFor({ state: "attached", timeout: 10000 });
|
||||
|
||||
const bars = {};
|
||||
for (const resource of ["power", "water", "food", "cooling"]) {
|
||||
const barStyle = await page.getByTestId(`tile-${resource}-bar`).getAttribute("style");
|
||||
const allocationText = await page.getByTestId(`tile-${resource}-allocation`).innerText();
|
||||
bars[resource] = { barStyle, allocationText };
|
||||
}
|
||||
evidence.steps.fairShareBars = bars;
|
||||
|
||||
const anyNonZeroBar = Object.values(bars).some(
|
||||
(b) => b.barStyle && !b.barStyle.includes("width: 0%"),
|
||||
);
|
||||
evidence.anyNonZeroBar = anyNonZeroBar;
|
||||
evidence.pass = anyNonZeroBar;
|
||||
} catch (err) {
|
||||
evidence.pass = false;
|
||||
evidence.error = String(err && err.message ? err.message : err);
|
||||
evidence.consoleMsgs = consoleMsgs.slice(-30);
|
||||
evidence.pageErrors = pageErrors;
|
||||
} finally {
|
||||
await context.close();
|
||||
await browser.close();
|
||||
}
|
||||
console.log(JSON.stringify(evidence, null, 2));
|
||||
process.exitCode = evidence.pass ? 0 : 1;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,74 @@
|
||||
import { chromium } from "playwright";
|
||||
|
||||
const URL_BASE = process.argv[2];
|
||||
if (!URL_BASE) {
|
||||
console.error("usage: node task57-degraded-check.mjs <deployed-url>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Failure-mode QA for todo 57's acceptance criteria: simulate the backend
|
||||
* (api/* - the only backend this app has) being unreachable, and assert
|
||||
* the frontend degrades gracefully - every local-first mini-app (which
|
||||
* never touches the network) keeps working, with no uncaught crash.
|
||||
*/
|
||||
async function main() {
|
||||
const browser = await chromium.launch({ headless: true, args: ["--no-sandbox"] });
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
const pageErrors = [];
|
||||
page.on("pageerror", (err) => pageErrors.push(String(err)));
|
||||
|
||||
// Simulate the backend being unreachable: abort every /api/* request.
|
||||
await context.route("**/api/**", (route) => route.abort("connectionrefused"));
|
||||
|
||||
const evidence = { steps: {} };
|
||||
try {
|
||||
await page.goto(`${URL_BASE}/`, { waitUntil: "networkidle" });
|
||||
evidence.steps.rootLoadedWithBackendDown = {
|
||||
url: page.url(),
|
||||
title: await page.title(),
|
||||
};
|
||||
|
||||
// Load the demo seed via /admin - this is pure local IndexedDB +
|
||||
// signing, never touches /api/*, so it must still succeed with the
|
||||
// backend unreachable.
|
||||
await page.goto(`${URL_BASE}/admin`, { waitUntil: "networkidle" });
|
||||
await page.getByRole("button", { name: "Load Hollow demo" }).click();
|
||||
await page.getByTestId("demo-load-status").waitFor({ timeout: 10000 });
|
||||
evidence.steps.demoStillLoadsLocally = {
|
||||
demoStatus: await page.getByTestId("demo-load-status").innerText(),
|
||||
};
|
||||
|
||||
// The local-first Fair Share mini-app (pure replay over the local
|
||||
// signed Event Log, no network) must still render real numbers.
|
||||
await page.goto(`${URL_BASE}/miniapp/fair-share`, { waitUntil: "networkidle" });
|
||||
await page.getByTestId("tile-power").waitFor({ state: "attached", timeout: 10000 });
|
||||
const powerAllocation = await page.getByTestId("tile-power-allocation").innerText();
|
||||
evidence.steps.localFirstMiniappStillWorks = { powerAllocation };
|
||||
|
||||
// Home grid (shell) must still render tiles, not a crash screen.
|
||||
await page.goto(`${URL_BASE}/`, { waitUntil: "networkidle" });
|
||||
const tileCount = await page.getByRole("button").count();
|
||||
evidence.steps.homeGridStillRenders = { tileCount, hasAtLeastOneTile: tileCount > 0 };
|
||||
|
||||
evidence.noUncaughtPageErrors = pageErrors.length === 0;
|
||||
evidence.pageErrors = pageErrors;
|
||||
evidence.pass =
|
||||
evidence.steps.demoStillLoadsLocally.demoStatus.includes("loaded") &&
|
||||
powerAllocation !== "No allocation yet" &&
|
||||
tileCount > 0 &&
|
||||
evidence.noUncaughtPageErrors;
|
||||
} catch (err) {
|
||||
evidence.pass = false;
|
||||
evidence.error = String(err && err.message ? err.message : err);
|
||||
evidence.pageErrors = pageErrors;
|
||||
} finally {
|
||||
await context.close();
|
||||
await browser.close();
|
||||
}
|
||||
console.log(JSON.stringify(evidence, null, 2));
|
||||
process.exitCode = evidence.pass ? 0 : 1;
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,5 +1,6 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,11 @@ import { join } from "node:path";
|
||||
|
||||
export const MAX_BLOB_SIZE_BYTES = 4 * 1024 * 1024;
|
||||
|
||||
const STORE_DIR = process.env.BLOB_STORE_DIR ?? join(process.cwd(), ".data", "blobs");
|
||||
// `process.cwd()` is the read-only deployment bundle on Vercel's serverless
|
||||
// runtime - only `os.tmpdir()` is writable there. Local dev and tests don't
|
||||
// care which writable directory this resolves to, so the same path works
|
||||
// everywhere without an environment-specific branch.
|
||||
const STORE_DIR = process.env.BLOB_STORE_DIR ?? join(tmpdir(), "the-commons-hollow-blobs");
|
||||
|
||||
// Only server-generated ids (randomUUID) are ever accepted for lookup;
|
||||
// anything else - including path-traversal attempts - is treated as "not
|
||||
|
||||
@@ -6,7 +6,8 @@ import { db } from "../lib/db";
|
||||
import { getPublicKey, init } from "../lib/identity";
|
||||
import { readAll } from "../lib/eventlog";
|
||||
import { AdminSeedPanel } from "./AdminSeedPanel";
|
||||
import { DEMO_FIXTURE_MARKER, HOLLOW_DEMO_FIXTURE } from "./seedEvents";
|
||||
import { DEMO_FIXTURE_MARKER, HOLLOW_DEMO_FIXTURE, RESOURCE_TYPES } from "./seedEvents";
|
||||
import { toAccountId } from "../shell/accountId";
|
||||
|
||||
beforeEach(async () => {
|
||||
indexedDB.deleteDatabase(db.name);
|
||||
@@ -106,9 +107,13 @@ describe("AdminSeedPanel - Load Hollow demo", () => {
|
||||
await waitFor(() => screen.getByTestId("demo-load-status"));
|
||||
|
||||
const entries = await readAll();
|
||||
// population + 4 resources + 3 baselines + 1 marker
|
||||
// population + 4 resources + 3 baselines + 4 fairshare.need + 1 marker
|
||||
const expectedCount =
|
||||
1 + Object.keys(HOLLOW_DEMO_FIXTURE.resources).length + HOLLOW_DEMO_FIXTURE.baselines.length + 1;
|
||||
1 +
|
||||
Object.keys(HOLLOW_DEMO_FIXTURE.resources).length +
|
||||
HOLLOW_DEMO_FIXTURE.baselines.length +
|
||||
RESOURCE_TYPES.length +
|
||||
1;
|
||||
expect(entries).toHaveLength(expectedCount);
|
||||
|
||||
const payloadTypes = entries.map((e) => (e.payload as { type: string }).type);
|
||||
@@ -124,6 +129,20 @@ describe("AdminSeedPanel - Load Hollow demo", () => {
|
||||
expect(populationEntry!.authorPubkey).toEqual(await getPublicKey());
|
||||
expect(populationEntry!.signature).toBeInstanceOf(Uint8Array);
|
||||
|
||||
// The demo-loading identity itself is registered as a fairshare
|
||||
// participant (one fairshare.need per resource, keyed to its own
|
||||
// account id) so the Fair Share mini-app shows a real allocation
|
||||
// instead of "no allocation yet" right after loading the demo.
|
||||
const accountId = toAccountId(await getPublicKey());
|
||||
const needEntries = entries.filter(
|
||||
(e) => (e.payload as { type: string }).type === "fairshare.need",
|
||||
);
|
||||
expect(needEntries).toHaveLength(RESOURCE_TYPES.length);
|
||||
for (const entry of needEntries) {
|
||||
expect((entry.payload as { agent: string }).agent).toBe(accountId);
|
||||
expect((entry.payload as { value: number }).value).toBeGreaterThan(0);
|
||||
}
|
||||
|
||||
expect(screen.getByTestId("demo-load-status")).toHaveTextContent("Demo data loaded");
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { useState } from "react";
|
||||
import { append, readAll } from "../lib/eventlog";
|
||||
import { init as initIdentity } from "../lib/identity";
|
||||
import { toAccountId } from "../shell/accountId";
|
||||
import {
|
||||
RESOURCE_TYPES,
|
||||
buildDemoFixturePayloads,
|
||||
buildDemoNeedPayloads,
|
||||
DEMO_FIXTURE_MARKER,
|
||||
hasDemoFixtureBeenLoaded,
|
||||
validateSeedInput,
|
||||
@@ -25,6 +28,13 @@ export function AdminSeedPanel() {
|
||||
setDemoLoading(true);
|
||||
setDemoStatus(null);
|
||||
try {
|
||||
// A judge may land on /admin directly, never having visited the shell
|
||||
// (whose WalletCard is what normally triggers identity.init() first) -
|
||||
// init() is idempotent, so calling it here guarantees a local identity
|
||||
// exists before anything below tries to sign an event.
|
||||
const { publicKey } = await initIdentity();
|
||||
const accountId = toAccountId(publicKey);
|
||||
|
||||
// Idempotency check: a second click must not duplicate the fixture's
|
||||
// events, so look for the marker left by a prior load first.
|
||||
const existing = await readAll();
|
||||
@@ -38,6 +48,13 @@ export function AdminSeedPanel() {
|
||||
for (const payload of buildDemoFixturePayloads()) {
|
||||
await append(payload);
|
||||
}
|
||||
// Register the demo-loading identity itself as a fairshare participant
|
||||
// (see seedEvents.ts's buildDemoNeedPayloads doc) so the Fair Share
|
||||
// mini-app shows a real, non-zero allocation right after loading the
|
||||
// demo instead of "no allocation yet" for a cold visitor.
|
||||
for (const payload of buildDemoNeedPayloads(accountId)) {
|
||||
await append(payload);
|
||||
}
|
||||
await append(DEMO_FIXTURE_MARKER);
|
||||
setDemoStatus("Demo data loaded into the Event Log.");
|
||||
} finally {
|
||||
@@ -58,6 +75,9 @@ export function AdminSeedPanel() {
|
||||
|
||||
setSubmitting(true);
|
||||
try {
|
||||
// Same reasoning as handleLoadDemo: never assume the shell already ran
|
||||
// identity.init() before this panel renders.
|
||||
await initIdentity();
|
||||
const stored = await append(result.payload);
|
||||
setLastSubmitted(result.payload.type);
|
||||
setInput({ category: input.category });
|
||||
|
||||
@@ -2,7 +2,10 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
DEMO_FIXTURE_MARKER,
|
||||
HOLLOW_DEMO_FIXTURE,
|
||||
HOLLOW_DEMO_NEEDS,
|
||||
RESOURCE_TYPES,
|
||||
buildDemoFixturePayloads,
|
||||
buildDemoNeedPayloads,
|
||||
hasDemoFixtureBeenLoaded,
|
||||
validateSeedInput,
|
||||
} from "./seedEvents";
|
||||
@@ -151,6 +154,29 @@ describe("buildDemoFixturePayloads", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildDemoNeedPayloads", () => {
|
||||
it("builds one fairshare.need payload per resource, all for the given agent", () => {
|
||||
const payloads = buildDemoNeedPayloads("deadbeef");
|
||||
|
||||
expect(payloads).toHaveLength(RESOURCE_TYPES.length);
|
||||
for (const resource of RESOURCE_TYPES) {
|
||||
expect(payloads).toContainEqual({
|
||||
type: "fairshare.need",
|
||||
agent: "deadbeef",
|
||||
resource,
|
||||
value: HOLLOW_DEMO_NEEDS[resource],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("every built value is a positive weight, so the agent actually competes for every resource", () => {
|
||||
const payloads = buildDemoNeedPayloads("deadbeef");
|
||||
for (const payload of payloads) {
|
||||
expect(payload.value).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasDemoFixtureBeenLoaded", () => {
|
||||
it("is false for an empty log", () => {
|
||||
expect(hasDemoFixtureBeenLoaded([])).toBe(false);
|
||||
|
||||
@@ -76,6 +76,53 @@ export const HOLLOW_DEMO_FIXTURE: DemoFixture = {
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* Plausible baseline demand (a non-negative linear utility weight per
|
||||
* `src/lib/fairshare.ts`'s CEEI engine) for whichever identity clicks
|
||||
* "Load Hollow demo". Every resource gets the same modest weight - these
|
||||
* numbers say nothing about any real agent's actual need, only that the
|
||||
* demo-loading identity participates in the market for all four resources
|
||||
* instead of a cold visitor seeing an allocation engine with zero
|
||||
* registered agents (and therefore empty allocation bars) right after
|
||||
* loading the bundled demo.
|
||||
*/
|
||||
export const HOLLOW_DEMO_NEEDS: Record<ResourceType, number> = {
|
||||
power: 10,
|
||||
water: 10,
|
||||
food: 10,
|
||||
cooling: 10,
|
||||
};
|
||||
|
||||
/** One `fairshare.need` payload (plan todo 14's engine input), built the
|
||||
* same way `buildDemoFixturePayloads` builds `seed.*` payloads - data only,
|
||||
* no Event Log access. */
|
||||
export interface DemoNeedPayload {
|
||||
type: "fairshare.need";
|
||||
agent: string;
|
||||
resource: ResourceType;
|
||||
value: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build one `fairshare.need` payload per resource for `agent` (the
|
||||
* demo-loading identity's own account id), so loading the bundled demo
|
||||
* seed also registers that identity as a real participant in the fairshare
|
||||
* engine - without this, `computeFairshareAllocation` sees zero agents and
|
||||
* every allocation bar stays at "no allocation yet" even though the
|
||||
* resource pools are seeded.
|
||||
*/
|
||||
export function buildDemoNeedPayloads(
|
||||
agent: string,
|
||||
needs: Record<ResourceType, number> = HOLLOW_DEMO_NEEDS,
|
||||
): DemoNeedPayload[] {
|
||||
return RESOURCE_TYPES.map((resource) => ({
|
||||
type: "fairshare.need",
|
||||
agent,
|
||||
resource,
|
||||
value: needs[resource],
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marker payload appended once a demo fixture has been loaded, so a second
|
||||
* click can detect the fixture is already present and skip re-appending it
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://openapi.vercel.sh/vercel.json",
|
||||
"rewrites": [
|
||||
{ "source": "/((?!api/).*)", "destination": "/index.html" }
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user