1// Global setup: provision the tenant under test with the tiny CLI so the2// conformance suite writes as its owner. Set TINY_PREPROVISIONED=1 to skip.3import { execFileSync } from "node:child_process";4import { getPublicKey } from "nostr-tools/pure";5import { sha256 } from "@noble/hashes/sha2.js";6import { hexToBytes } from "@noble/hashes/utils.js";78const relayURL = process.env.RELAY_URL ?? "ws://127.0.0.1:7447";9const httpURL = relayURL.replace(/^ws/, "http").replace(/\/$/, "") + "/";10const owner = process.env.CLAIM_SK11 ? hexToBytes(process.env.CLAIM_SK)12 : sha256(new TextEncoder().encode("tiny conformance owner"));1314function provision() {15 const bin = process.env.TINY_BIN ?? "tiny";16 const name = process.env.TINY_TENANT ?? new URL(httpURL).hostname.split(".")[0];17 const template = process.env.TINY_TEMPLATE ?? "default";18 const args = ["tenant", "create", "--name", name, "--owner", getPublicKey(owner), "--template", template];19 if (process.env.TINY_DATA_DIR) args.push("--data-dir", process.env.TINY_DATA_DIR);20 execFileSync(bin, args, { stdio: "inherit" });21}2223export default async function setup() {24 if (process.env.TINY_PREPROVISIONED !== "1") provision();25 const response = await fetch(httpURL, { headers: { accept: "application/nostr+json" } });26 if (!response.ok) throw new Error(`relay did not become ready at ${httpURL}: ${response.status}`);27 console.log(`conformance tenant ready at ${relayURL} as ${getPublicKey(owner)}`);28}