Files
loki/scripts/test/fleet-map.ts
CatoandClaude bf1753a485 feat(register): client work stays private until the client agrees (#1171)
Work built for a real person or organisation, paid or not, is theirs before
it is ours to show. It now reaches a public surface only once consent is
recorded on the project, with how it was given.

- user_projects.client_work / portfolio_consent_at / portfolio_consent_note
  (migration 0097)
- src/lib/register/client-work.ts: the one rule. Explicit answer wins, else
  apps.conf (client kind or third-party owner), else ours
- buildFleetRegister defaults to audience "public" (fails closed) and drops
  unconsented client work; operator views pass "operator". The map carries
  client: { consentedAt } so the bitbaum portfolio can show it apart
- /u/<owner>, the /fleet listing and the landing showcase filter through
  withoutPrivateClientWork
- The static footer lists our own products only: it cannot read consent
- Project page: a Client work entry to mark it, record consent with a note,
  or withdraw it (PATCH clientWork / portfolioConsent)
- Prospect previews are created as client work


Claude-Session: https://claude.ai/code/session_01XpakL9C3TESU4H45fXMFfc

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-12 09:39:41 -07:00

192 lines
6.2 KiB
TypeScript

/**
* Unit tests for the fleet map (pure half, src/lib/register/map.ts).
*
* Contract: the map is the register plus purpose/layer/state/activity, sorted
* pillars-first, and its overview text names every project once with its
* facts in a fixed order so the assistant can answer "what do we have?".
*
* Run: npx tsx scripts/test/fleet-map.ts
*/
import assert from "node:assert/strict";
import { buildFleetMap, layerFor, renderFleetMapOverview, PILLARS } from "@/lib/register/map";
import type { RegisterRow } from "@/lib/register/build";
let pass = 0;
function check(name: string, fn: () => void) {
fn();
pass++;
console.log(` ✓ ${name}`);
}
const site = (over: Partial<NonNullable<RegisterRow["site"]>> = {}): RegisterRow["site"] => ({
url: "https://x.orangecat.ch",
host: "x.orangecat.ch",
kind: "product",
status: "live",
owner: "bitbaum",
since: "2026-06-01",
...over,
});
const rows: RegisterRow[] = [
{
slug: "kivvi",
name: "Kivvi",
description: "Nanny booking",
repo: "kivvi",
site: site({ kind: "client-app", owner: "kivvi" }),
loki: { id: "1", liveUrl: null },
orangecat: null,
solon: null,
client: { work: true, consentedAt: "2026-09-01T00:00:00.000Z" },
},
{
slug: "loki",
name: "Loki",
description: "A captain over a fleet of agents",
repo: "loki",
site: site({ url: "https://loki.orangecat.ch", host: "loki.orangecat.ch" }),
loki: { id: "2", liveUrl: "https://loki.orangecat.ch" },
orangecat: { projectId: "oc-1" },
solon: null,
client: { work: false, consentedAt: null },
},
{
slug: "aoz-demo",
name: "AOZ demo",
description: null,
repo: "aoz-begleitung",
site: site({ kind: "demo", status: "demo" }),
loki: null,
orangecat: null,
solon: null,
client: { work: false, consentedAt: null },
},
{
slug: "next-idea",
name: "Next Idea",
description: "Not built yet",
repo: null,
site: null,
loki: { id: "3", liveUrl: null },
orangecat: null,
solon: null,
client: { work: false, consentedAt: null },
},
{
slug: "orangecat",
name: "OrangeCat",
description: "The economy",
repo: "orangecat",
site: site({ url: "https://orangecat.ch", host: "orangecat.ch" }),
loki: { id: "4", liveUrl: "https://orangecat.ch" },
orangecat: null,
solon: { slug: "orangecat" },
client: { work: false, consentedAt: null },
},
];
check("layers: pillars by name, clients by owner, demos by kind, no site = next", () => {
assert.equal(layerFor(rows[1]), "execution");
assert.equal(layerFor(rows[4]), "economic");
assert.equal(layerFor(rows[0]), "client");
assert.equal(layerFor(rows[2]), "demo");
assert.equal(layerFor(rows[3]), "next");
});
check("pillars come first, then products, clients, demos, the rest", () => {
const map = buildFleetMap(rows, new Map(), new Map(), new Date("2026-09-14T00:00:00Z"));
assert.deepEqual(
map.projects.map((p) => p.slug),
["loki", "orangecat", "kivvi", "aoz-demo", "next-idea"],
);
assert.equal(map.pillars.length, PILLARS.length);
assert.equal(map.generatedAt, "2026-09-14T00:00:00.000Z");
});
check("activity and the dev log land on the right project", () => {
const map = buildFleetMap(
rows,
new Map([
[
"loki",
{
stack: "Next.js",
devLog: [
{ date: "2026-09-10", done: "old", next: "older next" },
{ date: "2026-09-13", done: "Renamed the product", next: "Close the chat loop" },
],
},
],
]),
new Map([
[
"loki",
{ openRuns: 2, lastRun: { outcome: "success", at: new Date("2026-09-13T22:00:00Z") } },
],
]),
);
const loki = map.projects.find((p) => p.slug === "loki")!;
assert.equal(loki.stack, "Next.js");
assert.equal(loki.now.openRuns, 2);
assert.equal(loki.now.lastRun?.outcome, "success");
assert.equal(loki.now.lastLog?.done, "Renamed the product");
assert.equal(loki.next, "Close the chat loop");
assert.equal(loki.urls.repo, "https://github.com/bitbaum/loki");
assert.equal(loki.urls.orangecat, "https://orangecat.ch/projects/oc-1");
assert.equal(map.summary.inFlight, 2);
});
check("summary counts live, clients and in-flight honestly", () => {
const map = buildFleetMap(rows, new Map(), new Map());
assert.deepEqual(map.summary, { projects: 5, live: 3, clients: 1, inFlight: 0 });
});
check("a client site is owned by the client, not by us", () => {
const map = buildFleetMap(rows, new Map(), new Map());
assert.equal(map.projects.find((p) => p.slug === "kivvi")!.owner, "kivvi");
assert.equal(map.projects.find((p) => p.slug === "next-idea")!.status, "not live");
});
check("no hosting row but a live URL counts as live; a timestamped dev log speaks in days", () => {
const hostless: RegisterRow = {
...rows[1],
slug: "orangecat-hostless",
site: null,
loki: { id: "9", liveUrl: "https://orangecat.ch" },
};
const map = buildFleetMap(
[hostless],
new Map([
["orangecat-hostless", { devLog: [{ date: "2026-09-12T19:59:17.000Z", done: "x" }] }],
]),
new Map(),
);
assert.equal(map.projects[0]!.status, "live");
assert.equal(map.projects[0]!.urls.live, "https://orangecat.ch");
assert.equal(map.projects[0]!.now.lastLog?.date, "2026-09-12");
assert.equal(map.summary.live, 1);
});
check("the overview names every project once, with facts in a fixed order", () => {
const map = buildFleetMap(
rows,
new Map([
["loki", { devLog: [{ date: "2026-09-13", done: "Renamed", next: "Close the loop" }] }],
]),
new Map(),
);
const text = renderFleetMapOverview(map);
for (const r of rows)
assert.equal(text.split(`\n${r.slug} — `).length, 2, `${r.slug} appears once`);
assert.match(text, /^Fleet map \(5 projects, 3 live, 1 client systems\)/);
assert.match(
text,
/loki — A captain over a fleet of agents; execution, live; live at https:\/\/loki\.orangecat\.ch; code https:\/\/github\.com\/bitbaum\/loki; last log 2026-09-13: Renamed; next: Close the loop/,
);
assert.match(text, /kivvi — Nanny booking; client, live, for kivvi/);
assert.match(text, /aoz-demo — \(no description yet\)/);
});
console.log(`\nfleet-map: ${pass} passed`);