Files
routstrd/tests/wallet/test-env.ts
T
redshift 66b5f6ac59 feat: ensure wallet exists before deriving auth identity in remote flow
routstrd remote now runs the same ensure-wallet sequence as init (stop
legacy cocod, migrate a legacy cocod wallet so its mnemonic wins, then
initialize a fresh wallet) before deriving the NIP-98 identity, so the
operator nsec is mnemonic-derived and recoverable from the wallet backup
regardless of which command runs first. This avoids shadowing a legacy
wallet with a fresh mnemonic, which would have made later migration fail
on divergent wallets. An already-configured nsec is never replaced.

- extract ensureLocalWallet() shared by init and remote
- move initializeWallet into wallet-config.ts, return created status,
  handle concurrent-initializer EEXIST races
- warn (but still derive) when the wallet mnemonic fails BIP-39 checksum
  validation, keeping auth/NPC/wallet identities self-consistent
- relocate initializeWallet tests next to wallet-config, add
  ensure-wallet integration tests (fresh, idempotent, legacy migration,
  divergent-wallets refusal)
2026-08-17 08:24:33 +01:00

13 lines
495 B
TypeScript

import { mkdtempSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
/**
* Test-wide environment root. Must be imported before any src module that
* captures env vars at load time (src/utils/logger reads ROUTSTRD_DIR when
* the module is first evaluated), so log output lands in a temp directory
* instead of the real ~/.routstrd.
*/
export const TEST_ROOT = mkdtempSync(join(tmpdir(), "routstrd-test-env-"));
process.env.ROUTSTRD_DIR = join(TEST_ROOT, "routstrd");