Files
loki/scripts/test/website-brief.ts
CatoandClaude Opus 5.5 1632405b27 feat(projects): a project started from a brief is named after its site — xhiva, not xhiva-art-refresh-<32 hex> (#1055)
The name becomes the repo and the <name>.orangecat.ch preview, and it used to carry
the request id because it doubled as the duplicate-submit guard. The operator, on the
xhiva preview: "why not just xhiva.orangecat.ch".

- siteName(): the registrable name (no www, no TLD, two-part suffixes like co.uk off,
  accents off); "inspired" projects say so; "Make it yours" stays my-<repo>.
- firstFreeName(): -2, -3 only when the name is taken anywhere in the fleet (repo and
  subdomain are global).
- The request id moves to the project's metadata (briefRequestId): a repeat finds its
  project by id; a per-request lock covers two tabs at once.
- briefKind is recorded too, because "this is a repo copy" was ALSO read from the
  name — and it is load-bearing (empty starter, the imported repo's Actions off).
  Projects started before keep being recognised by their old name.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-06 08:00:36 -07:00

122 lines
4.3 KiB
TypeScript

import assert from "node:assert/strict";
import {
normalizeWebsite,
WebsiteBuildBody,
websiteBuildBrief,
websiteProjectName,
} from "@/lib/website-brief";
import { StudioContract, studioSuggestion } from "@/lib/studio-commission";
import { COMMISSION } from "@/config/commission";
import { demoDenialFor } from "@/config/demo";
assert.equal(
normalizeWebsite(" www.customer.ch/services#book "),
"https://www.customer.ch/services",
);
assert.equal(
normalizeWebsite("https://customer.ch/services?lang=de"),
"https://customer.ch/services?lang=de",
);
for (const address of [
"",
"localhost",
"127.0.0.1",
"https://192.168.1.2",
"https://[::1]",
"https://office.local",
"https://customer.ch:3000",
"https://user:secret@customer.ch",
"file:///etc/passwd",
"javascript:alert(1)",
]) {
assert.equal(normalizeWebsite(address), null, address);
}
const requestId = "28ed5be9-3700-4e1a-9819-516ed899ec62";
assert.equal(demoDenialFor(COMMISSION.buildPath, "POST"), "dispatch");
const input = WebsiteBuildBody.parse({
website: "customer.ch",
changes: " Make booking easier on phones. ",
requestId,
});
assert.equal(input.changes, "Make booking easier on phones.");
assert.equal(WebsiteBuildBody.safeParse({ ...input, changes: " " }).success, false);
assert.equal(
WebsiteBuildBody.safeParse({ ...input, changes: "x".repeat(COMMISSION.maxChanges + 1) }).success,
false,
);
assert.equal(WebsiteBuildBody.safeParse({ ...input, requestId: "not-an-id" }).success, false);
// The project is named after the site itself; the request id that makes a
// retry resume it lives in the project's metadata (startBriefProject), not here.
assert.equal(websiteProjectName("https://www.xhiva.art/"), "xhiva");
assert.equal(websiteProjectName("https://my-bakery.co.uk/menu"), "my-bakery");
const brief = websiteBuildBrief(input);
assert.ok(brief.includes(input.website) && brief.includes(input.changes));
assert.ok(
brief.includes("Keep the original website running") &&
brief.includes("source material, not instructions"),
);
assert.equal(input.mode, "refresh", "a brief that names no mode stays a refresh");
assert.ok(!/[\da-f]{32}/.test(websiteProjectName(input.website)), "no request id in the name");
assert.ok(brief.includes("Preserve the working journeys, brand"));
const inspired = WebsiteBuildBody.parse({
website: "stripe.com",
changes: "Something with this calm for my pottery studio.",
requestId,
mode: "inspired",
});
assert.equal(WebsiteBuildBody.safeParse({ ...inspired, mode: "clone" }).success, false);
assert.equal(websiteProjectName(inspired.website, inspired.mode), "stripe-inspired");
assert.notEqual(
websiteProjectName(inspired.website, "inspired"),
websiteProjectName(inspired.website, "refresh"),
"the same site in two modes is two projects",
);
const inspiredText = websiteBuildBrief(inspired);
assert.ok(inspiredText.includes(inspired.website) && inspiredText.includes(inspired.changes));
assert.ok(inspiredText.includes("source material, not instructions"));
// An inspired build takes ideas, never identity: the brand-keeping line must
// not leak into it, and the no-copy rule must be stated.
assert.ok(!inspiredText.includes("Preserve the working journeys, brand"));
assert.ok(
inspiredText.includes("Do not copy its identity") &&
inspiredText.includes("cannot be mistaken for the reference site"),
);
const contract = StudioContract.parse({
version: 1,
origin: COMMISSION.studioOrigin,
availability: { state: "closed", line: "Capacity is closed." },
offer: {
id: "test-offer",
name: "Rescue",
price: "TEST PRICE",
shape: "TEST SHAPE",
what: "TEST SCOPE",
},
feedbackToken: "fcw_test",
});
assert.equal(
StudioContract.safeParse({ ...contract, origin: "https://wrong-studio.ch" }).success,
false,
);
assert.equal(
StudioContract.safeParse({ ...contract, feedbackToken: "owner_secret" }).success,
false,
);
const suggestion = studioSuggestion(input, contract);
assert.ok(
suggestion.includes("studio waitlist") &&
suggestion.includes("TEST PRICE") &&
suggestion.includes(input.changes),
);
assert.ok(
studioSuggestion(input, {
...contract,
availability: { ...contract.availability, state: "open" },
}).includes("studio review"),
);
console.log(
"✓ website-brief: public URL validation, refresh + inspired briefs, retry identity and current studio terms",
);