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 上游, 端到端验证通过
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
const { chromium } = require('playwright')
|
||||
async function main() {
|
||||
const browser = await chromium.launch()
|
||||
const page = await browser.newPage()
|
||||
const uname = 'probe' + 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(500)
|
||||
const results = await page.evaluate(async () => {
|
||||
const out = {}
|
||||
for (const [name, url] of Object.entries({
|
||||
balance: '/api/v1/user/balance',
|
||||
stats: '/api/v1/usage/stats?group=day',
|
||||
logs: '/api/v1/usage/logs?page_size=8',
|
||||
})) {
|
||||
try {
|
||||
const r = await fetch(url, { headers: { Authorization: 'Bearer ' + localStorage.getItem('ot_access') } })
|
||||
const j = await r.json()
|
||||
out[name] = { status: r.status, body: JSON.stringify(j).slice(0, 220) }
|
||||
} catch (e) { out[name] = { err: String(e) } }
|
||||
}
|
||||
return out
|
||||
})
|
||||
console.log(JSON.stringify(results, null, 1))
|
||||
await browser.close()
|
||||
}
|
||||
main().catch(e => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,29 @@
|
||||
// 定位 pageerror 来源
|
||||
const { chromium } = require('playwright')
|
||||
|
||||
async function main() {
|
||||
const browser = await chromium.launch()
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
|
||||
page.on('console', (m) => { if (m.type() === 'error') console.log('CONSOLE ERR @', page.url(), '→', m.text().slice(0, 200)) })
|
||||
page.on('pageerror', (e) => console.log('PAGE ERR @', page.url(), '→', e.stack?.split('\n').slice(0, 3).join(' | ')))
|
||||
|
||||
const uname = 'dbg' + 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(2500)
|
||||
console.log('URL now:', page.url())
|
||||
// 检查页面内容
|
||||
const cards = await page.locator('.mt-6.grid .rounded-lg').count()
|
||||
const chart = await page.locator('canvas').count()
|
||||
const empty = await page.locator('text=暂无数据').count()
|
||||
console.log('cards:', cards, 'canvas:', chart, 'emptyState:', empty)
|
||||
const bodyText = (await page.locator('body').innerText()).slice(0, 300)
|
||||
console.log('body:', bodyText.replace(/\n+/g, ' | '))
|
||||
await browser.close()
|
||||
}
|
||||
main().catch((e) => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,52 @@
|
||||
// 前端截图验证脚本:登录 → 仪表盘 → 密钥页
|
||||
const { chromium } = require('playwright')
|
||||
|
||||
async function main() {
|
||||
const browser = await chromium.launch()
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
|
||||
const shots = process.argv[2] || '/tmp/shots'
|
||||
const fs = require('fs')
|
||||
fs.mkdirSync(shots, { recursive: true })
|
||||
|
||||
// 1. Landing
|
||||
await page.goto('http://localhost:5173/', { waitUntil: 'networkidle' })
|
||||
await page.screenshot({ path: `${shots}/01-landing.png` })
|
||||
|
||||
// 2. 注册
|
||||
await page.goto('http://localhost:5173/register', { waitUntil: 'networkidle' })
|
||||
const uname = 'dave' + Date.now().toString().slice(-6)
|
||||
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.screenshot({ path: `${shots}/02-register.png` })
|
||||
await page.click('button[type="submit"]')
|
||||
await page.waitForURL('**/console/dashboard', { timeout: 10000 })
|
||||
await page.waitForTimeout(1200)
|
||||
|
||||
// 3. 跳过登录(注册后已自动登录)—— 直接看仪表盘
|
||||
await page.goto('http://localhost:5173/console/dashboard', { waitUntil: 'networkidle' })
|
||||
await page.waitForTimeout(1500)
|
||||
await page.screenshot({ path: `${shots}/03-dashboard.png` })
|
||||
|
||||
// 4. 密钥页
|
||||
await page.goto('http://localhost:5173/console/keys', { waitUntil: 'networkidle' })
|
||||
await page.screenshot({ path: `${shots}/04-keys.png` })
|
||||
await page.click('text=新建密钥')
|
||||
await page.waitForTimeout(400)
|
||||
await page.fill('input[placeholder*="本地开发"]', 'playwright-test')
|
||||
await page.screenshot({ path: `${shots}/05-key-modal.png` })
|
||||
await page.click('button:has-text("创建")')
|
||||
await page.waitForTimeout(600)
|
||||
await page.screenshot({ path: `${shots}/06-key-created.png` })
|
||||
|
||||
// 5. 用量页
|
||||
await page.goto('http://localhost:5173/console/usage', { waitUntil: 'networkidle' })
|
||||
await page.waitForTimeout(800)
|
||||
await page.screenshot({ path: `${shots}/07-usage.png` })
|
||||
|
||||
await browser.close()
|
||||
console.log('done')
|
||||
}
|
||||
|
||||
main().catch((e) => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,80 @@
|
||||
// 前端渲染断言:检查关键元素与 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) })
|
||||
Reference in New Issue
Block a user