SPB Git

Repository Public

global-setup.ts 6.8 KB 95 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : e2e/global-setup.ts9 * Module           : e2e10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { createHash } from "node:crypto";44import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";45import { join, resolve } from "node:path";4647/**48 * Builds the throw-away database: the real catalog seed, plus two FIXTURE applications that exist only here,49 * to exercise the states production does not have yet — a published macOS image and an open public TestFlight beta.50 */51export default async function setup() {52  const data = resolve("e2e/.tmp/data");53  rmSync(resolve("e2e/.tmp"), { recursive: true, force: true });54  mkdirSync(data, { recursive: true });55  Object.assign(process.env, { ORIX_DATA_DIR: data, APP_URL: "http://localhost:8841" });56  const { upsertSeed } = await import("../src/lib/catalog");57  const { db, now } = await import("../src/lib/database/db");58  const { issueEnrollToken } = await import("../src/lib/auth/enroll");59  for (const f of readdirSync("content/apps").filter((x) => x.endsWith(".json"))) upsertSeed(JSON.parse(readFileSync(join("content/apps", f), "utf8")));6061  const l = (s: string) => ({ en: s, fr: s });62  const base = { accent: "#4C8DFF", icon: null, bundleId: null, build: "1", architectures: ["arm64"], downloadSize: null, features: [{ title: l("Fixture feature"), body: l("Exists only in the end-to-end database.") }], deepDives: [],63    specs: { offline: l("Yes"), permissions: [], languages: ["en"] }, privacy: { summary: l("Fixture."), points: [] }, faq: [], screenshots: [], verification: { testedOnDevice: true, notes: l("Fixture.") }, releases: [] };64  upsertSeed({ ...base, slug: "fixture-mac", name: "ORIX Fixture Mac", order: 90, category: "system", platforms: ["macos"], status: "available", repo: { name: "orix-fixture", visibility: "public" }, version: "1.2.0", minOS: { macos: "15.0" },65    tagline: l("Fixture download"), summary: l("A fixture with a published image."), description: l("Fixture."), distribution: [{ channel: "dmg", state: "public", url: null }] });66  upsertSeed({ ...base, slug: "fixture-ios", name: "ORIX Fixture iOS", order: 91, category: "utilities", platforms: ["ios", "ipados"], status: "beta", repo: { name: null, visibility: "none" }, version: "1.0.0", minOS: { ios: "18.0" },67    tagline: l("Fixture beta"), summary: l("A fixture with an open public beta."), description: l("Fixture."),68    distribution: [{ channel: "testflight", state: "public", url: "https://testflight.apple.com/join/E2Efixt1", check: { at: now(), result: "open" } }] });6970  const dmg = Buffer.from("ORIX e2e fixture image\n" + "0123456789abcdef".repeat(4096));71  const sha = createHash("sha256").update(dmg).digest("hex");72  const r = db().prepare(`INSERT INTO releases (slug, repo, tag, version, tag_date, subject, asset_name, asset_size, sha256_declared, sha256_computed, source_url, state, signature, discovered_at, published_at)73    VALUES ('fixture-mac', 'orix-fixture', 'v1.2.0', '1.2.0', ?, 'Fixture 1.2.0', 'ORIXFixture.dmg', ?, ?, ?, 'http://127.0.0.1:9/releases/orix-fixture/v1.2.0/ORIXFixture.dmg', 'published', ?, ?, ?)`)74    .run(now(), dmg.length, sha, sha, JSON.stringify({ platform: "darwin", notarized: true }), now(), now());75  const dir = join(data, "artifacts/fixture-mac", String(r.lastInsertRowid));76  mkdirSync(dir, { recursive: true });77  writeFileSync(join(dir, "ORIXFixture.dmg"), dmg);78  db().prepare("UPDATE releases SET artifact = ? WHERE id = ?").run(join(dir, "ORIXFixture.dmg"), r.lastInsertRowid);79  db().prepare("INSERT INTO releases (slug, repo, tag, version, asset_name, asset_size, sha256_declared, source_url, state, discovered_at) VALUES ('fixture-review', 'orix-review', 'v2.1.0', '2.1.0', 'ORIXReview.dmg', 10, ?, 'http://127.0.0.1:9/releases/orix-review/v2.1.0/ORIXReview.dmg', 'validated', ?)").run("a".repeat(64), now());8081  // A second Mac fixture, owned by the admin tests (they withdraw its release).82  upsertSeed({ ...base, slug: "fixture-review", name: "ORIX Fixture Review", order: 92, category: "system", platforms: ["macos"], status: "available", repo: { name: "orix-review", visibility: "public" }, version: "2.0.0", minOS: { macos: "15.0" },83    tagline: l("Fixture review"), summary: l("A fixture for release review."), description: l("Fixture."), distribution: [{ channel: "dmg", state: "public", url: null }] });84  const r2 = db().prepare(`INSERT INTO releases (slug, repo, tag, version, tag_date, subject, asset_name, asset_size, sha256_declared, sha256_computed, source_url, state, signature, discovered_at, published_at)85    VALUES ('fixture-review', 'orix-review', 'v2.0.0', '2.0.0', ?, 'Review 2.0.0', 'ORIXReview.dmg', ?, ?, ?, 'http://127.0.0.1:9/releases/orix-review/v2.0.0/ORIXReview.dmg', 'published', ?, ?, ?)`)86    .run(now(), dmg.length, sha, sha, JSON.stringify({ platform: "darwin", notarized: true }), now(), now());87  const dir2 = join(data, "artifacts/fixture-review", String(r2.lastInsertRowid));88  mkdirSync(dir2, { recursive: true });89  writeFileSync(join(dir2, "ORIXReview.dmg"), dmg);90  db().prepare("UPDATE releases SET artifact = ? WHERE id = ?").run(join(dir2, "ORIXReview.dmg"), r2.lastInsertRowid);9192  writeFileSync(resolve("e2e/.tmp/state.json"), JSON.stringify({ enroll: issueEnrollToken("setup", 60).raw, sha, size: dmg.length }));93  (await import("../src/lib/database/db")).closeDb();94}95
Files main
Menu

Theme