// e2e 辅助:从仓库根 .env 读种子管理员凭据(global-setup 已跑过幂等 seed)。 import { existsSync, readFileSync } from 'node:fs' import { join } from 'node:path' import { fileURLToPath } from 'node:url' const repoRoot = fileURLToPath(new URL('../../..', import.meta.url)) export interface AdminCredentials { account: string password: string } export function adminCredentials(): AdminCredentials { const envPath = join(repoRoot, '.env') if (!existsSync(envPath)) { throw new Error(`[admin e2e] 仓库根 .env 不存在(${envPath})`) } const vars = new Map() for (const line of readFileSync(envPath, 'utf-8').split(/\r?\n/)) { const match = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim()) if (match) vars.set(match[1], match[2]) } const account = vars.get('ADMIN_ACCOUNT') ?? 'admin' const password = vars.get('ADMIN_PASSWORD') ?? 'admin-secret-change-me' return { account, password } }