Something went wrong. Try again.
atproto Thingiverse but good
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import { defineConfig, devices } from "@playwright/test";import { createServer } from "node:net";import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";import { resolve } from "node:path";
async function findFreePort(): Promise<number> { const server = createServer(); await new Promise<void>((resolve, reject) => { server.once("error", reject); server.listen(0, "127.0.0.1", () => resolve()); }); const address = server.address(); if (!address || typeof address === "string") throw new Error("failed to reserve a port"); const port = address.port; await new Promise<void>((resolve, reject) => server.close((error) => error ? reject(error) : resolve())); return port;}
const appPort = 60000;const fixturePort = await findFreePort();const repositoryRoot = resolve(process.cwd(), "..");const e2eDatabaseUrl = `sqlite:${resolve(repositoryRoot, "data/polymodel-e2e.db")}`;const dxTargetDir = "/tmp/pm80-runtime/dx-target-e2e";const cargoTargetDir = "/tmp/pm80-runtime/cargo-target-e2e";const hydrantDatabasePath = "/tmp/pm80-runtime/hydrant-e2e";const shellQuote = (value: string) => `'${value.replaceAll("'", "'\\''")}'`;const fixtureScript = ` import { createServer } from "node:http"; const did = "did:plc:aaaaaaaaaaaaaaaaaaaaaaaa"; const primaryCid = "bafkreiblomfprrld3bjvf5ktjw2trnjl2tbxg6rx5uvzaive4f35iob5ja"; const childCid = "bafkreih5euurby4kkq76q5dlezn5qdleeqb2w4gm5zx2la6hl6o7pxporu"; const companionCid = "bafkreie42luggp5uta6nylexcnrnpoimoa255trbl75pmp7v6bxnrdlrtu"; const blobs = new Map([ [primaryCid, Buffer.from("0 BFC CERTIFY CCW\\n1 16 -35 0 0 1 0 0 0 1 0 0 0 1 models/child.dat\\n1 16 35 0 0 0 0 -1 0 1 0 1 0 0 models/child.dat\\n1 16 0 0 35 1 0 0 0 1 0 0 0 1 models/companion.dat\\n", "utf8")], [childCid, Buffer.from("0 BFC CERTIFY CCW\\n4 4 -20 0 -20 20 0 -20 20 0 20 -20 0 20\\n4 1 -20 0 -20 -20 30 -20 20 30 -20 20 0 -20\\n4 2 20 0 -20 20 30 -20 20 30 20 20 0 20\\n4 14 20 0 20 20 30 20 -20 30 20 -20 0 20\\n4 15 -20 0 20 -20 30 20 -20 30 -20 -20 0 -20\\n2 24 -20 30 -20 20 30 -20\\n2 24 20 30 -20 20 30 20\\n2 24 20 30 20 -20 30 20\\n2 24 -20 30 20 -20 30 -20\\n", "utf8")], [companionCid, Buffer.from("0 BFC CERTIFY CCW\\n3 5 -25 0 -25 25 0 -25 0 40 0\\n3 5 25 0 -25 25 0 25 0 40 0\\n3 5 25 0 25 -25 0 25 0 40 0\\n3 5 -25 0 25 -25 0 -25 0 40 0\\n5 24 -25 0 -25 25 0 -25 0 40 0 0 -20 0\\n", "utf8")], ]); const server = createServer((request, response) => { const url = new URL(request.url ?? "/", "http://127.0.0.1"); if (url.pathname === "/xrpc/com.atproto.identity.resolveDid") { response.setHeader("content-type", "application/json"); response.end(JSON.stringify({ didDoc: { "@context": ["https://www.w3.org/ns/did/v1"], id: did, service: [{ id: "#atproto_pds", type: "AtprotoPersonalDataServer", serviceEndpoint: "http://127.0.0.1:${fixturePort}" }] } })); } else if (url.pathname === "/xrpc/com.atproto.sync.getBlob" && blobs.has(url.searchParams.get("cid") ?? "")) { response.writeHead(200, { "content-type": "application/octet-stream" }).end(blobs.get(url.searchParams.get("cid") ?? "")); } else { response.writeHead(404).end("not found"); } }); server.listen(${fixturePort}, "127.0.0.1"); process.once("SIGTERM", () => server.close(() => process.exit(0)));`;const fixtureCommand = `node --input-type=module -e ${shellQuote(fixtureScript)} & pds_pid=$!; trap 'kill "$pds_pid" 2>/dev/null || true' EXIT INT TERM; export DIOXUS_TARGET_DIR=${shellQuote(dxTargetDir)} CARGO_TARGET_DIR=${shellQuote(cargoTargetDir)} CARGO_INCREMENTAL=0 SQLX_OFFLINE=true DATABASE_URL=${shellQuote(e2eDatabaseUrl)} HYDRANT_DATABASE_PATH=${shellQuote(hydrantDatabasePath)} POLYMODEL_INDEXING=off POLYMODEL_SAMPLE_DATA=auto POLYMODEL_RESOLVER_BASE_URL=http://127.0.0.1:${fixturePort}; dx run --port ${appPort}`;function findNixChromiumHeadlessShell(): string | undefined { const browsersPath = process.env.PLAYWRIGHT_BROWSERS_PATH; if (!browsersPath || !existsSync(browsersPath)) return undefined; const findExecutable = (root: string): string | undefined => { for (const entry of readdirSync(root)) { const candidate = `${root}/${entry}`; const stat = statSync(candidate); if (stat.isFile() && entry === "chrome-headless-shell") return candidate; if (stat.isDirectory()) { const found = findExecutable(candidate); if (found) return found; } } return undefined; }; for (const entry of readdirSync(browsersPath)) { if (entry.startsWith("chromium_headless_shell-")) { const found = findExecutable(realpathSync(`${browsersPath}/${entry}`)); if (found) return found; } } return undefined;}const chromiumExecutablePath = findNixChromiumHeadlessShell();export default defineConfig({ testDir: "./tests", timeout: 30_000, expect: { timeout: 5_000 }, use: { baseURL: `http://127.0.0.1:${appPort}`, trace: "on-first-retry", }, projects: [ { name: "chromium", use: { ...devices["Desktop Chrome"], launchOptions: chromiumExecutablePath ? { executablePath: chromiumExecutablePath } : undefined, }, }, ], webServer: { command: `(fuser -TERM -k -n tcp ${appPort} >/dev/null 2>&1 || true; for attempt in $(seq 1 20); do fuser -n tcp ${appPort} >/dev/null 2>&1 || break; sleep 0.5; done; if fuser -n tcp ${appPort} >/dev/null 2>&1; then fuser -KILL -k -n tcp ${appPort} >/dev/null 2>&1 || true; for attempt in $(seq 1 20); do fuser -n tcp ${appPort} >/dev/null 2>&1 || break; sleep 0.5; done; fi; if fuser -n tcp ${appPort} >/dev/null 2>&1; then echo "port ${appPort} still has a live server" >&2; exit 1; fi ) && mkdir -p data && rm -f data/polymodel-e2e.db data/polymodel-e2e.db-wal data/polymodel-e2e.db-shm && ( ${fixtureCommand} )`, cwd: repositoryRoot, url: `http://127.0.0.1:${appPort}`, reuseExistingServer: false, stderr: "pipe", timeout: 600_000, },});