Files
openteam/web/scripts/verify.cjs
T
Sakurasan 360c6b33a6 M0+M1: 基建 + 用户/密钥/核心代理
后端 (Go/Gin/GORM):
- 配置(viper+env)、SQLite/Postgres 迁移、argon2id、AES-GCM 渠道密钥、JWT+refresh cookie
- 用户注册/登录/刷新/登出、API Key CRUD(仅存哈希、明文一次展示)
- 代理网关: /v1/chat/completions、/v1/responses、/v1/models 直通 OpenAI 渠道
  非流式+流式(SSE 零缓冲转发), 用量捕获(chat 末块/responses completed 嵌套),
  OpenAI 错误格式(401/402/404/502), 余额检查
- 异步批量记账 + 余额流水 + 日聚合, admin 用户/余额/配置 API
- 单测: crypto/jwt/apikey/流式 usage 提取

前端 (Vue3+TS+Vite+Tailwind v4):
- taste-skill 设计 tokens: 深色仪表盘, 石墨+信号铜色, Outfit+JetBrains Mono
- Landing/登录/注册, 控制台(仪表盘图表/密钥管理/用量明细)
- 基础组件 Button/Input/Badge/Modal, ECharts 用量图

部署: docker-compose(nginx+api+postgres), 双 Dockerfile, nginx SSE 反代
联调: scripts/mockupstream 本地 mock 上游, 端到端验证通过
2026-08-15 13:10:47 +08:00

81 lines
2.9 KiB
JavaScript

// 前端渲染断言:检查关键元素与 console 错误
const { chromium } = require('playwright')
async function main() {
const browser = await chromium.launch()
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
const errors = []
page.on('console', (m) => { if (m.type() === 'error') errors.push(page.url() + ' :: ' + m.text()) })
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message))
async function check(name, url, selectors) {
await page.goto(url, { waitUntil: 'networkidle' })
await page.waitForTimeout(800)
const results = []
for (const [label, sel] of Object.entries(selectors)) {
const n = await page.locator(sel).count()
results.push(`${label}:${n}`)
}
console.log(`${name}: ${results.join(' ')}`)
}
await check('landing', 'http://localhost:5173/', {
nav: 'header nav',
hero: 'h1',
protocols: '#protocols .grid > div',
footer: 'footer',
})
await check('login', 'http://localhost:5173/login', {
username: 'input[autocomplete="username"]',
password: 'input[autocomplete="current-password"]',
submit: 'button[type="submit"]',
})
// 注册一个测试用户并进控制台
const uname = 'verify' + Date.now().toString().slice(-6)
await page.goto('http://localhost:5173/register', { waitUntil: 'networkidle' })
await page.fill('input[autocomplete="username"]', uname)
await page.fill('input[autocomplete="email"]', uname + '@test.com')
await page.fill('input[autocomplete="new-password"]', 'password123')
await page.locator('input[autocomplete="new-password"]').nth(1).fill('password123')
await page.click('button[type="submit"]')
await page.waitForURL('**/console/dashboard', { timeout: 10000 })
await page.waitForTimeout(1200)
await check('dashboard', 'http://localhost:5173/console/dashboard', {
sidebar: 'aside',
cards: '.mt-6.grid .rounded-lg',
chart: '.divide-y, canvas',
recent: '.divide-y',
navKeys: 'a[href="/console/keys"]',
balance: 'aside .text-mint-400',
})
await check('keys', 'http://localhost:5173/console/keys', {
table: 'table',
createBtn: 'button:has-text("新建密钥")',
})
await check('usage', 'http://localhost:5173/console/usage', {
table: 'table',
filter: 'select',
pagination: 'button:has-text("下一页")',
})
// 创建密钥弹窗
await page.goto('http://localhost:5173/console/keys', { waitUntil: 'networkidle' })
await page.click('button:has-text("新建密钥")')
await page.waitForTimeout(300)
await page.fill('input[placeholder*="本地开发"]', 'verify-key')
await page.click('button:has-text("创建")')
await page.waitForTimeout(600)
const created = await page.locator('code.text-mint-300').count()
console.log(`key-created-modal: oneTimeKey:${created}`)
console.log('console-errors:', errors.length ? errors.slice(0, 5) : 'none')
await browser.close()
}
main().catch((e) => { console.error(e); process.exit(1) })