| 1 | // Global setup: provision the tenant under test with the tiny CLI so the |
| 2 | // conformance suite writes as its owner. Set TINY_PREPROVISIONED=1 to skip. |
| 3 | import { execFileSync } from "node:child_process" ; |
| 4 | import { getPublicKey } from "nostr-tools/pure" ; |
| 5 | import { sha256 } from "@noble/hashes/sha2.js" ; |
| 6 | import { hexToBytes } from "@noble/hashes/utils.js" ; |
| 7 | |
| 8 | const relayURL = process.env.RELAY_URL ?? "ws://127.0.0.1:7447" ; |
| 9 | const httpURL = relayURL.replace(/^ws/, "http" ).replace(/\/$/, "" ) + "/" ; |
| 10 | const owner = process.env.CLAIM_SK |
| 11 | ? hexToBytes(process.env.CLAIM_SK) |
| 12 | : sha256(new TextEncoder().encode("tiny conformance owner" )); |
| 13 | |
| 14 | function 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 | } |
| 22 | |
| 23 | export 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 | } |