/** * FIRST SYNC FAST (coordinator, 26 Nov 2026): an invented dev account the size of the owner's Post (280,062 rows), for * timing a new phone's first sync. Mail-shaped rows are planted through the dev Worker's /v1/admin/dev/plant-rows: * sealed-shaped (a random sealed block of the given size), so a phone pulls, parks and counts them as it would his; * they never open (no key seals them), so the fold after a key is timed on a really sealed account instead * (pnpm dev:big-account with COTTON_BIG_APPS=mail). * * pnpm -s exec tsx scripts/first-sync-plant.ts --number +1555019xxxx [--emails 200000] [--threads 80000] [--bytes 4000] * * Invented data only, dev only; nothing secret is printed. */ import { readFileSync } from "node:fs"; import { homedir } from "node:os"; import { signIn } from "./dev-seed/client.ts"; import { devBase } from "./dev-server"; const arg = (name: string, fallback?: string) => { const i = process.argv.indexOf(`--${name}`); return i > 0 ? process.argv[i + 1]! : fallback; }; const BASE = devBase(); const NUMBER = arg("number")!; if (!/^\+1555\d{7}$/.test(NUMBER ?? "")) throw new Error("--number is an invented +1555 number"); const CODE = readFileSync(`${homedir()}/.cotton-credentials/cotton/dev-otp`, "utf8").replace(/\D/g, ""); const plan: [string, number, number, string | null][] = [ ["email_thread", Number(arg("threads", "80000")), Math.round(Number(arg("bytes", "4000")) / 5), "last_at"], ["email", Number(arg("emails", "200000")), Number(arg("bytes", "4000")), "sent_at"], ]; async function main(): Promise { const s = await signIn(BASE, NUMBER, CODE); console.log(`[plant] signed in ${NUMBER} (database ${s.databaseId.slice(0, 8)}…)`); for (const [table, count, bytes, dated] of plan) { for (let from = 0; from < count; from += 20_000) { const n = Math.min(20_000, count - from); const started = Date.now(); const r = await fetch(`${BASE}/v1/admin/dev/plant-rows`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${s.token}` }, body: JSON.stringify({ table, from, count: n, bytes, dated }), }); const text = await r.text(); console.log(`[plant] ${table} ${from}..${from + n} (${bytes} B): ${r.status} in ${Date.now() - started} ms${r.ok ? "" : ` ${text.slice(0, 160)}`}`); if (!r.ok) process.exit(1); } } console.log("[plant] done"); } main().catch((e: unknown) => { console.log(`[plant] FAILED: ${e instanceof Error ? e.message : String(e)}`); process.exit(1); });