Files
CatoandClaude c83c8f473e feat(starter): kickoff and new-site.sh both produce the fleet starter (#1138)
scripts/site-template is now bitbaum/fleet templates/app — Next.js 16,
better-auth accounts (password, link, passkey, 2FA, OrangeCat/bitbaum sign-in
as env-gated OIDC), en/de/fr, nonce CSP, ai-kit/mail-kit/limitkit/bip-kit,
tests and CI — copied at a pinned fleet commit by
scripts/templates/sync-starter.sh. CI proves the copy is exact
(sync-starter.sh --check), and starter-sync.yml opens the PR when fleet's
starter moves. Never edited here.

The kickoff's "nextjs-tailwind" starter seeds the same app from
src/lib/starter-app.generated.ts (generated from the directory, pinned by
scripts/test/starter-app.ts), minus the workflows register-site.sh adds with
the site's CD. The repo is seeded in one Trees API call with inline contents
instead of a blob POST per file (~85 for this starter). The widget token rides
in .env.production; the starter's .gitleaks.toml allows NEXT_PUBLIC_* values.
The new-from-scratch picker reads the light template list, so the starter's
file bodies never reach a client bundle.

Both paths give the site its database and auth/seal secrets ON THE BOX
(scripts/hetzner/provision-db-on-box.sh: role + database, ~/.db-credentials,
/opt/<slug>/shared/.env; existing secrets never replaced; nothing printed), and
record the db in the register row so every deploy applies drizzle/.
register-site.sh seeds the starter's full workflow set to starter repos and
the golden CI floor to anything else, never overwriting another repo's ci.yml.

test-site-template.sh follows the starter (verify SSOT, design tokens instead
of a local palette) and its comment stripper is fixed: the sed range deleted
the page from the doc comment to EOF, so every day-zero check had been passing
against an empty string. check-template-contrast.mjs and the starter-lock
generator are retired with the files they checked.


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

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-11 13:39:14 -07:00

51 lines
2.0 KiB
TypeScript

import { slidingWindow } from "limitkit";
import { describe, expect, it } from "vitest";
import { authBucket, callerKey, recipientKey, tooMany } from "./limits";
describe("authBucket", () => {
it.each([
["/sign-up/email", "mail"],
["/sign-in/magic-link", "mail"],
["/request-password-reset", "mail"],
["/send-verification-email", "mail"],
["/sign-in/email", "credential"],
["/sign-in/social", "credential"],
["/two-factor/verify-totp", "credential"],
["/two-factor/verify-backup-code", "credential"],
["/passkey/verify-authentication", "credential"],
["/reset-password", "credential"],
["/get-session", "auth"],
["/sign-out", "auth"],
])("%s spends from %s", (path, bucket) => {
expect(authBucket(path)).toBe(bucket);
});
});
describe("callerKey", () => {
it("keys on the hop the proxy appended, not on what the client typed", () => {
const forged = (first: string) => new Headers({ "x-forwarded-for": `${first}, 203.0.113.7` });
expect(callerKey(forged("1.1.1.1"), "s")).toBe("s:203.0.113.7");
// A fresh forged value per request is still the same bucket.
expect(callerKey(forged("9.9.9.9"), "s")).toBe(callerKey(forged("1.1.1.1"), "s"));
});
it("a hammered key is refused, and the refusal is a 429 that says when", () => {
const limiter = slidingWindow({ limit: 2, windowMs: 60_000 });
const key = callerKey(new Headers({ "x-forwarded-for": "203.0.113.9" }), "t");
expect(limiter.check(key, 0).allowed).toBe(true);
expect(limiter.check(key, 1).allowed).toBe(true);
const refused = limiter.check(key, 2);
expect(refused.allowed).toBe(false);
const response = tooMany(refused);
expect(response.status).toBe(429);
expect(response.headers.get("retry-after")).toBe("60");
});
});
describe("recipientKey", () => {
it("is the same for one address however it is typed, and holds no address", () => {
expect(recipientKey(" Person@Example.ch ")).toBe(recipientKey("person@example.ch"));
expect(recipientKey("person@example.ch")).not.toContain("example");
});
});