~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

7
59 lines · 2.9 KB Raw History
// Before the flows: a world seeded as the shots' is, then knotless-serve
// over it again as a gateway, behind the https front the PDS sends logins
// back to (harness/tls-proxy.mjs). Where the pages are and who is in the
// world go to the flows in E2E_WORLD. Returns the teardown.

import { execFileSync, spawn } from 'node:child_process'
import { mkdirSync, writeFileSync } from 'node:fs'
import { createInterface } from 'node:readline'
import { join } from 'node:path'
import { create, environment, port, root, serve } from '../shots/world.mjs'

export default async function setup() {
  const world = await create()
  // A tag on bob's fork, which its workflow run only when asked asks for:
  // pushed here, as the shots' world, which shows the fork's tags, has none.
  const bob = { cwd: join(world.dir, 'bob/tally'), env: environment(world.net, world.dir, 'bob') }
  execFileSync('git', ['tag', 'v0.1.0', 'main'], bob)
  execFileSync('git', ['push', '-q', 'origin', 'v0.1.0'], bob)
  // On the spaces alpha, a private repository of alice's for the private
  // flows: a main and a branch off it to pull, pushed from the command
  // line as no page pushes.
  if (world.net.spaces) {
    const vault = join(world.dir, 'alice/vault')
    const alice = { cwd: vault, env: environment(world.net, world.dir, 'alice') }
    mkdirSync(vault, { recursive: true })
    execFileSync(join(root, 'target/debug/knotless'), ['create', 'knotless://alice.test/vault', '--private', '--description', 'What we keep to ourselves'], alice)
    execFileSync('git', ['init', '-q', '-b', 'main'], alice)
    writeFileSync(join(vault, 'README.md'), '# Vault\n\nPlans not yet for anyone else.\n')
    execFileSync('git', ['add', '-A'], alice)
    execFileSync('git', ['commit', '-q', '-m', 'Start the vault'], alice)
    execFileSync('git', ['push', '-q', 'knotless://alice.test/vault', 'main'], alice)
    execFileSync('git', ['switch', '-q', '-c', 'plans'], alice)
    writeFileSync(join(vault, 'PLANS.md'), '# Plans\n\nShip tally 1.0.\n')
    execFileSync('git', ['add', '-A'], alice)
    execFileSync('git', ['commit', '-q', '-m', 'Write down the plans'], alice)
    execFileSync('git', ['push', '-q', 'knotless://alice.test/vault', 'plans'], alice)
  }
  world.server.kill()
  const { cert, key, host } = world.net.gateway
  const proxy = spawn('node', [join(root, 'harness/tls-proxy.mjs'), cert, key, String(port)], {
    stdio: ['pipe', 'pipe', 'inherit'],
  })
  const [line] = await createInterface({ input: proxy.stdout })[Symbol.asyncIterator]().next().then((r) => [r.value])
  const base = `https://${host}:${line.trim()}`
  let server
  try {
    server = await serve(world, { gateway: base })
  } catch (e) {
    proxy.kill()
    world.stop()
    throw e
  }
  process.env.E2E_WORLD = JSON.stringify({ base, pds: world.net.pds, plc: world.net.plc, dir: world.dir, accounts: world.net.accounts, views: world.views })
  return () => {
    server.kill()
    proxy.kill()
    world.stop()
  }
}