Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { test } from "@playwright/test";
import { accounts, getOk, repos } from "../harness/api";import { config, seeded } from "../harness/config";import { partsOf, stampedAt, xrpc } from "../harness/net";
const AGE_MINUTES = Number(process.env.E2E_SWEEP_MINUTES ?? 30);if (!(AGE_MINUTES >= 0)) { throw new Error( `E2E_SWEEP_MINUTES is a number of minutes, saw ${process.env.E2E_SWEEP_MINUTES}` );}
// stopping at the first page would silently miss the restconst listAll = async (nsid: string, params: Record<string, string>, key: string) => { const all: any[] = []; let cursor: string | undefined; do { const page = await getOk( xrpc(config.pdsUrl, nsid, { ...params, limit: "100", ...(cursor ? { cursor } : {}) }) ); all.push(...page[key]); cursor = page.cursor; } while (cursor); return all;};
test("sweep leaked accounts", async () => { test.setTimeout(300_000); const keep = new Set(Object.values(seeded).map((account) => account.did)); const failed: string[] = []; for (const { did } of await listAll("com.atproto.sync.listRepos", {}, "repos")) { if (keep.has(did)) continue; const info = await getOk( xrpc(config.pdsUrl, "com.atproto.repo.describeRepo", { repo: did }) ); const name = info.handle.split(".")[0]; const made = stampedAt(name); if (!made || Date.now() - made < AGE_MINUTES * 60_000) continue;
const account = { name, handle: info.handle, did }; const declared = await listAll( "com.atproto.repo.listRecords", { repo: did, collection: "org.tangled.repo.declaration" }, "records" ); let stuck = false; for (const record of declared) { await repos .remove(account, { did: record.value.repo, name: partsOf(record.uri).rkey }) .catch((cause) => { stuck = true; failed.push(`repo of ${name}: ${String(cause).slice(0, 200)}`); }); } // the account is the only way back to its repos, so keep it while one fails if (stuck) continue; await accounts.removeMember(account).catch(() => {}); await accounts.remove(account); console.log("swept", info.handle); } if (failed.length) throw new Error(`could not sweep:\n ${failed.join("\n ")}`);});