mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-06 00:18:24 +01:00
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>
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
/**
|
|
* Brief projects get readable names (src/lib/brief-project-name.ts).
|
|
*
|
|
* The name becomes the repo and the <name>.orangecat.ch preview. It used to be
|
|
* xhiva-art-refresh-300d1519783b47d3ab1c7ddb77c5febf; the operator, on that
|
|
* preview: "why not just xhiva.orangecat.ch".
|
|
*
|
|
* Run: npx tsx scripts/test/brief-project-name.ts
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { firstFreeName, siteName } from "@/lib/brief-project-name";
|
|
|
|
let passed = 0;
|
|
const check = async (label: string, fn: () => void | Promise<void>) => {
|
|
await fn();
|
|
passed += 1;
|
|
console.log(` ✓ ${label}`);
|
|
};
|
|
|
|
async function main() {
|
|
console.log("\nsiteName");
|
|
await check("the site's own name: no www, no TLD", () => {
|
|
assert.equal(siteName("https://www.xhiva.art/"), "xhiva");
|
|
assert.equal(siteName("derhochhinhousepartyrenner.ch"), "derhochhinhousepartyrenner");
|
|
assert.equal(siteName("https://shop.example.com/a/b"), "example");
|
|
});
|
|
await check("a two-part public suffix is dropped too", () => {
|
|
assert.equal(siteName("https://my-bakery.co.uk/menu"), "my-bakery");
|
|
assert.equal(siteName("www.surf-school.com.au"), "surf-school");
|
|
});
|
|
await check("what is left is a valid project name", () => {
|
|
assert.equal(siteName("https://Café-Zürich.ch"), "cafe-zurich");
|
|
});
|
|
|
|
console.log("\nfirstFreeName");
|
|
await check("the base name when it is free", async () => {
|
|
assert.equal(await firstFreeName("xhiva", async () => false), "xhiva");
|
|
});
|
|
await check("-2, -3 only when taken", async () => {
|
|
const taken = new Set(["xhiva", "xhiva-2"]);
|
|
assert.equal(await firstFreeName("xhiva", async (n) => taken.has(n)), "xhiva-3");
|
|
});
|
|
|
|
console.log("\nstartBriefProject");
|
|
await check("a repeat is found by its request id, never by name", () => {
|
|
const src = readFileSync(
|
|
join(__dirname, "../../src/lib/kickoff/start-brief-project.ts"),
|
|
"utf8",
|
|
);
|
|
assert.ok(/findBriefProject\(userId, opts\.requestId\)/.test(src), "looks up by request id");
|
|
assert.ok(/markBriefProject\(/.test(src), "records the request id on the project");
|
|
assert.ok(/firstFreeName\(opts\.name, isProjectNameTaken\)/.test(src), "names it readably");
|
|
});
|
|
|
|
console.log(`\n${passed}/${passed} brief-project-name cases passed`);
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|