Files

57 lines
5.4 KiB
JavaScript
Raw Permalink Normal View History

const assert = require('node:assert/strict')
const fs = require('node:fs')
const { execFileSync } = require('node:child_process')
const { chromium } = require('/Users/macclaw/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
const directory = '/Volumes/Extreme SSD/yawan-storage/weknora/acceptance'
const base = 'http://127.0.0.1:18080/api/v1'
const checks = [], failures = []
let auth, browser
const sql = query => execFileSync('docker', ['--context', 'colima-yawan', 'exec', 'WeKnora-postgres',
'psql', '-X', '-U', 'postgres', '-d', 'yawan_native_acceptance_20260915', '-Atc', query],
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim()
const check = (name, value) => { checks.push({ name, passed: !!value }); assert.ok(value, name) }
async function api(route, method = 'GET', body) {
const response = await fetch(base + route, { method, headers: { 'Content-Type': 'application/json',
...(auth ? { Authorization: `Bearer ${auth.token}`, 'X-Tenant-ID': '10059' } : {}) },
body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(15000) })
assert.equal(response.status, 200, `${route}: ${response.status}`)
return response.json()
}
async function main() {
const credentials = JSON.parse(fs.readFileSync(`${directory}/super-admin-login.json`, 'utf8'))
auth = await api('/auth/login', 'POST', { email: credentials.email, password: credentials.password })
const provenance = JSON.parse(sql(`SELECT row_to_json(p) FROM yawan_legacy_agent_persona_mappings p WHERE tenant_id=10059 AND source_id=2`))
const human = (await api(`/digital-humans/${provenance.digital_human_id}`)).data
const agent = (await api(`/agents/${provenance.agent_id}`)).data
const version = human.versions.find(version => version.number === 1)
check('native_api_imported_active_no_false_review', human.status === 'active' && human.active_version === 1 && version.status === 'imported' && !version.reviewed_at && !version.review_note)
check('native_api_exact_six_original_fields', Object.keys(version.persona).length === 6 && Object.entries(provenance.source_persona).every(([key, value]) => version.persona[key] === value))
check('native_api_existing_same_name_agent_owner_and_binding', human.primary_agent_id === agent.id && human.name === agent.name && human.owner_id === agent.created_by && human.bindings.length === 1 && human.bindings[0].agent_id === agent.id && human.bindings[0].applied_version === 1)
check('runtime_prompt_contains_all_original_fields_and_imported_label', agent.config.system_prompt.includes('旧配置迁入数字人(未重新蒸馏)') && Object.values(provenance.source_persona).every(value => agent.config.system_prompt.includes(value)))
check('current_base_rules_retained', sql(`SELECT config->>'system_prompt' LIKE b.base_prompt || '%' FROM custom_agents a JOIN digital_human_bindings b ON b.tenant_id=a.tenant_id AND b.agent_id=a.id WHERE a.id='${agent.id}' AND a.tenant_id=10059`) === 't')
check('global_visibility_and_no_generated_distillation_job', sql(`SELECT p.global AND NOT EXISTS(SELECT 1 FROM digital_human_jobs j WHERE j.digital_human_id=p.resource_id) FROM workbench_access_publications p WHERE p.tenant_id=10059 AND p.kind='digital-humans' AND p.resource_id='${human.id}'`) === 't')
browser = await chromium.launch({ headless: true, channel: 'chrome' })
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } })
await context.addInitScript(auth => {
for (const [key, value] of Object.entries({ weknora_user: JSON.stringify({ ...auth.user, tenant_id: String(auth.user.tenant_id) }), weknora_tenant: JSON.stringify({ ...auth.active_tenant, id: '10059' }), weknora_token: auth.token, weknora_refresh_token: auth.refresh_token, weknora_memberships: JSON.stringify(auth.memberships), 'weknora:new-user-guide-done:v1': '1' })) localStorage.setItem(key, value)
}, auth)
const page = await context.newPage(), errors = []
page.on('pageerror', error => errors.push(error.message))
await page.goto('http://127.0.0.1:15173/platform/digital-humans')
await page.locator('.human-row').filter({ has: page.getByRole('button', { name: human.name, exact: true }) }).getByRole('button', { name: human.name, exact: true }).click()
await page.getByText('版本审核', { exact: true }).click()
await page.getByText('旧配置迁入生效(未重新蒸馏)。保留原 Agent 的表达风格;新增蒸馏版本须审核后生效。', { exact: true }).waitFor()
check('browser_displays_import_source_without_approval_controls', await page.getByRole('button', { name: '审核通过并生效', exact: true }).count() === 0)
await page.screenshot({ path: `${directory}/legacy-persona-desktop.png`, animations: 'disabled' })
await page.setViewportSize({ width: 390, height: 844 })
await page.screenshot({ path: `${directory}/legacy-persona-mobile.png`, animations: 'disabled' })
check('mobile_no_horizontal_overflow', await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 2))
check('browser_no_runtime_errors', errors.length === 0)
}
main().catch(error => { failures.push(error.message); process.exitCode = 1 }).finally(async () => {
await browser?.close()
const report = { time: new Date().toISOString(), checks, failures, passed: failures.length === 0 }
fs.writeFileSync(`${directory}/legacy-persona-live.json`, JSON.stringify(report, null, 2))
console.log(JSON.stringify(report, null, 2))
})