Files
ssw-bot 535bee2477 feat(sswflow+e2e): 真实数据+真实计算 e2e 体系与 TEE 引擎合并
# 一、SSWFlow 真数据建模(TC-FLOW-006 端到端跑通)
- 前端 flowTransform.ts 修复多端口丢失(prep.intersect left/right、model.predict model)—— 关键 bug:浏览器 FlowEditor auto-save 把所有 targetPort 改成 inputs[0].key,导致 Start 时报「端口未连线」
- 后端 FlowRunServiceImpl.start 改走 getAliveWithCanvas,与 detail/Validate 共用同一读路径
- 后端 FlowService 新增 getAliveWithCanvas() 方法

# 二、TEE 安全管理配置合并
- application.yml:去重 security 段(YAML 顶级键冲突),新增 sswflow.nax 配置(Python 解释器、镜像、FISCO 节点)

# 三、E2E 真实业务链路 + 真实计算引擎标记补强
- 新增 docs/e2e/{run_one,probe_flow006_api,riskctrl}.mjs 和 6 条 TC-FLOW-001~006 用例
- 新增 fixtures/ 真实数据集(银行信用特征、征信评分、生成器)
- dsl.mjs 新增 6 个真实链路 helper:parseEngineChain / assertRealEngineEngaged / parseChainEvidence / assertChainEvidence / fetchTeeEvidence / assertTeeEvidence / assertExecCost / sha256Hex
- 5 条用例(001~005)全部 6~8 步 PASS,真 K8S 引擎命中,真实 SHA-256 业务指纹

# 四、其他
- .gitignore 增加 node_modules、_diag_*、dacli/_*、scard audit data 等临时产物排除
- 删除废弃 docs/e2e.zip(25MB)
- 删除 docs/tds/流程图20260313.pptx 入库
- .workbuddy/memory 2026-08-06/07 入库
- scard audit jsonl 跟 SEV-SNP TEE 实跑同步更新
2026-08-07 19:49:01 +08:00

212 lines
7.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import http from 'node:http'
import fs from 'node:fs'
import path from 'node:path'
import { DOCS_DIR, RUNNER_PORT, SHOTS_DIR, RESULTS_FILE, E2E_DIR } from './lib/config.mjs'
import { loadCases, loadResults, mergeResult, runCase, saveResults } from './lib/exec.mjs'
import { probe, startBackend, startFrontend } from './lib/env.mjs'
import { closeBrowser } from './lib/browser.mjs'
import { selfTest } from './lib/cipher.mjs'
/**
* 测试执行服务 —— 核对页面的后台。
*
* 页面本身是个静态 HTML,用 file:// 打开时既起不了进程也调不动浏览器,
* 所以由这个进程把它托管起来(同源,省掉 CORS),并对外提供:
* GET / 核对页面(就是 docs/尚数网测评_测试用例核对.html)
* GET /api/status 环境探测 + 用例清单 + 上次结果
* POST /api/env/start 按需拉起后端 30000 / 前端 5173
* GET /api/run?tc=A,B 执行用例,SSE 实时回传日志与结果
* POST /api/stop 中断当前批次
* GET /api/results 历史结果
* POST /api/results/clear 清空历史
* GET /shots/xxx.png 失败/关键步骤截图
*/
const HTML_FILE = path.join(E2E_DIR, 'index.html')
let running = false
let abort = false
function json(res, code, data) {
const body = JSON.stringify(data)
res.writeHead(code, {
'Content-Type': 'application/json; charset=utf-8',
'Cache-Control': 'no-store',
'Access-Control-Allow-Origin': '*'
})
res.end(body)
}
function readBody(req) {
return new Promise((resolve) => {
let b = ''
req.on('data', (c) => (b += c))
req.on('end', () => {
try {
resolve(JSON.parse(b || '{}'))
} catch {
resolve({})
}
})
})
}
const server = http.createServer(async (req, res) => {
const url = new URL(req.url, `http://localhost:${RUNNER_PORT}`)
const p = url.pathname
if (req.method === 'OPTIONS') {
res.writeHead(204, {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST',
'Access-Control-Allow-Headers': 'Content-Type'
})
return res.end()
}
// ---- 核对页面 ----
if (p === '/' || p === '/index.html') {
if (!fs.existsSync(HTML_FILE)) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' })
return res.end('找不到核对页面:' + HTML_FILE)
}
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' })
return res.end(fs.readFileSync(HTML_FILE))
}
// ---- 截图 ----
if (p.startsWith('/shots/')) {
const f = path.join(SHOTS_DIR, path.basename(decodeURIComponent(p.slice(7))))
if (!fs.existsSync(f)) {
res.writeHead(404)
return res.end()
}
const ext = path.extname(f).toLowerCase()
const ctype = ext === '.webm' ? 'video/webm' : (ext === '.jpg' || ext === '.jpeg') ? 'image/jpeg' : 'image/png'
res.writeHead(200, { 'Content-Type': ctype })
return res.end(fs.readFileSync(f))
}
// ---- 状态 ----
if (p === '/api/status') {
const [env, cases] = await Promise.all([probe(), loadCases()])
return json(res, 200, {
ok: true,
running,
env,
results: loadResults(),
cases: cases.map(({ _run, ...m }) => m)
})
}
if (p === '/api/results') return json(res, 200, loadResults())
if (p === '/api/results/clear' && req.method === 'POST') {
saveResults({ updatedAt: new Date().toISOString(), cases: {} })
return json(res, 200, { ok: true })
}
// ---- 拉起服务 ----
if (p === '/api/env/start' && req.method === 'POST') {
const { be = true, fe = true } = await readBody(req)
res.writeHead(200, {
'Content-Type': 'text/event-stream; charset=utf-8',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
'Access-Control-Allow-Origin': '*'
})
const send = (event, data) => res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`)
const log = (m) => send('log', { msg: m })
try {
if (fe) await startFrontend(log)
if (be) await startBackend(log)
send('done', { ok: true, env: await probe() })
} catch (e) {
send('done', { ok: false, error: e.message, env: await probe() })
}
return res.end()
}
if (p === '/api/stop' && req.method === 'POST') {
abort = true
return json(res, 200, { ok: true })
}
// ---- 执行用例 ----
if (p === '/api/run') {
if (running) return json(res, 409, { ok: false, error: '已有批次在执行中' })
const want = (url.searchParams.get('tc') || '').split(',').map((s) => s.trim()).filter(Boolean)
// 默认无头(不打扰);ob=1 开可见浏览器;headless=0 兼容旧用法(显式可见)
const ob = url.searchParams.get('ob') === '1'
const explicitHeadless = url.searchParams.get('headless')
const headless = ob ? false : (explicitHeadless !== null ? explicitHeadless === '1' : true)
const all = await loadCases()
const byTc = new Map(all.map((c) => [c.tc, c]))
const queue = want.length ? want.map((tc) => byTc.get(tc) || { tc, broken: '没有对应的脚本文件' }) : all
res.writeHead(200, {
'Content-Type': 'text/event-stream; charset=utf-8',
'Cache-Control': 'no-cache',
Connection: 'keep-alive',
'Access-Control-Allow-Origin': '*'
})
const send = (event, data) => res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`)
running = true
abort = false
send('start', { total: queue.length })
const summary = { pass: 0, fail: 0, skip: 0, manual: 0, error: 0 }
try {
for (let i = 0; i < queue.length; i++) {
if (abort) {
send('aborted', { done: i, total: queue.length })
break
}
const c = queue[i]
send('case-start', { tc: c.tc, index: i, total: queue.length, title: c.title || '' })
const rec = await runCase(c, {
headless,
onLog: (msg) => send('log', { tc: c.tc, msg })
})
summary[rec.status] = (summary[rec.status] || 0) + 1
mergeResult(rec)
send('case-done', rec)
}
send('done', { summary, aborted: abort })
} catch (e) {
send('done', { summary, error: e.message })
} finally {
running = false
abort = false
await closeBrowser()
}
return res.end()
}
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' })
res.end('not found')
})
selfTest()
server.listen(RUNNER_PORT, () => {
const cases = fs.existsSync(path.join(E2E_DIR, 'cases'))
? fs.readdirSync(path.join(E2E_DIR, 'cases')).filter((f) => f.endsWith('.mjs')).length
: 0
console.log('')
console.log(' 尚数网测评 · 测试用例执行台')
console.log(' ────────────────────────────────────────')
console.log(` 控制台 http://localhost:${RUNNER_PORT}/`)
console.log(` 用例脚本 ${cases} 个(docs/e2e/cases/)`)
console.log(` 结果存档 ${path.relative(process.cwd(), RESULTS_FILE)}`)
console.log(' ────────────────────────────────────────')
console.log(' Ctrl+C 退出')
console.log('')
})
process.on('SIGINT', async () => {
await closeBrowser()
process.exit(0)
})