OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git-v3 / test / identity-passthrough.test.js

29 lines · javascript ref:
// #52 Phase 1.4 — identity address pass-through. Under PGV3_USE_RAW_IDENTITY
// the daemon loads <storage>/identity.json via tryLoadLegacy. This proves the
// experimental loader reads PROD's real identity.json byte-for-byte and yields
// the SAME publicKey (= same punch:// serverKey address) — so a cutover keeps
// prod's address. Read-only: copies ONLY identity.json to a tmp dir, never
// touches ~/pgv3-storage. Skips if prod identity.json is absent.

import test from 'brittle'
import { mkdtempSync, existsSync, copyFileSync, readFileSync } from '#node:fs'
import { join } from '#node:path'
import { tmpdir } from '#node:os'
import { loadOrCreateIdentity } from '../lib/identity.js'

const PROD = '/home/fleeky/pgv3-storage/identity.json'

test('experimental loader reads prod identity.json → same address (publicKey)', async (t) => {
  if (!existsSync(PROD)) { t.pass('skipped — prod identity.json absent'); return }
  const expected = JSON.parse(readFileSync(PROD, 'utf8'))
  t.is(expected.publicKey.length, 64, 'prod identity has a 32-byte pubkey')

  const dir = mkdtempSync(join(tmpdir(), 'id-passthrough-'))
  copyFileSync(PROD, join(dir, 'identity.json'))

  const id = await loadOrCreateIdentity(dir, { useRawIdentity: true })
  t.is(id.source, 'legacy', 'loaded the existing identity.json (not a fresh keypair)')
  t.is(id.publicKeyHex, expected.publicKey, 'SAME publicKey — punch:// address preserved')
  t.is(id.createdAt, expected.createdAt, 'createdAt preserved')
})