P4-1 转换器线:扩 EDITFORM/主子表/树/选择窗/<report> 段 + 全量 1516 模板批量转换双闸分级
转换器扩展(platform-converter,PoC crud 三段种子上): - 按 XML 根元素分派 crud/form/tree/report/group;ConversionResult+Grade 三级分级 - EDITFORM:form pageid 解析 view_page 取字段;主子表 EditGrid/FormEditGrid→input-table(子列取自 editgridtemplate) - 树:type=3 声明式→input-tree、type=4 引用式→flex(tree+crud) - 选择窗 SelectDialog/MultiSelectDialog→select+source(非 amis picker:picker 不在 6.13 schema 表单项 oneOf,闸一会拒) - <report> A 类:crud+合计行(issummer→summaryFields)+金额列(ismoney→number);selectservice→/api/flow;JOR/图表降级标注 - UiTypeMapper 统一 uitype 映射;每决策登记映射台账(全量约 1.6 万条) - 孤儿模板(entityid 非法/空 xml)旁路标记不崩(手册 §7.4) 批量+双闸(BatchConvertCli,可独立 CLI 跑批,只读连库+5435 ceshi 库硬守门): - 闸一 SchemaGate(宽松语义预处理抽出,与 AmisSchemaController 共享):通过 98.2%(1489/1516) - 闸二 playwright+本地 amis SDK 渲染冒烟,每类型抽≥5:25/25 全过 - 产物 转换产物/(schema/*.json + 分级清单.csv + 闸二结果.json) - 失败 27 个全为空 xml 孤儿模板(库内数据问题,非转换器缺陷) 新坑进手册 §8.3(picker 不在表单项 oneOf,用 select+source) §8.4(闸二大 schema 经端点拉避 HTTP 431) 单测 24 个;全 reactor mvn test+ArchUnit 绿 报告 platform-converter/P4批量转换报告.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2
platform-converter/gate2-smoke/.gitignore
vendored
Normal file
2
platform-converter/gate2-smoke/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
package-lock.json
|
||||
43
platform-converter/gate2-smoke/host.html
Normal file
43
platform-converter/gate2-smoke/host.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>P4 闸二 · amis 渲染冒烟(本地 SDK 6.13.0)</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<!-- amis SDK 6.13.0 本地构建产物(不依赖 CDN);路径经静态服务器映射到 /sdk-local -->
|
||||
<link rel="stylesheet" href="/sdk-local/sdk.css"/>
|
||||
<link rel="stylesheet" href="/sdk-local/helper.css"/>
|
||||
<link rel="stylesheet" href="/sdk-local/iconfont.css"/>
|
||||
<script src="/sdk-local/sdk.js"></script>
|
||||
<style>html,body,#root{height:100%;margin:0}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script>
|
||||
// schema 经查询参数 ?schema=<urlencoded-json> 注入(冒烟脚本逐个填)
|
||||
window.__amisRenderError = null;
|
||||
window.addEventListener('error', function (e) {
|
||||
window.__amisRenderError = String(e.message || e.error || e);
|
||||
});
|
||||
// schema 经 /schema?id=<模板id> 拉取(避免大 schema 撑爆 URL header,HTTP 431)
|
||||
(function () {
|
||||
const id = new URLSearchParams(location.search).get('id');
|
||||
fetch('/schema?id=' + encodeURIComponent(id))
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (schema) {
|
||||
const amis = amisRequire('amis/embed');
|
||||
amis.embed('#root', schema, {}, {
|
||||
// 数据接口全部桩成空响应:冒烟只验「能渲染根组件」,不验数据
|
||||
fetcher: function () {
|
||||
return Promise.resolve({ status: 200, data: { status: 0, msg: '', data: { items: [], total: 0 } } });
|
||||
}
|
||||
});
|
||||
window.__amisEmbedded = true;
|
||||
})
|
||||
.catch(function (err) {
|
||||
window.__amisRenderError = 'embed 异常: ' + (err && err.stack || err);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
7
platform-converter/gate2-smoke/package.json
Normal file
7
platform-converter/gate2-smoke/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "p4-gate2-smoke",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "P4 闸二 amis 渲染冒烟(抽样自动化)",
|
||||
"dependencies": { "playwright": "1.60.0" }
|
||||
}
|
||||
142
platform-converter/gate2-smoke/smoke.mjs
Normal file
142
platform-converter/gate2-smoke/smoke.mjs
Normal file
@@ -0,0 +1,142 @@
|
||||
// P4 闸二:amis 渲染冒烟(抽样自动化)。
|
||||
//
|
||||
// 口径:对每个模板类型(crud/form/tree/report/group)从闸一通过的 schema 中抽 ≥N(默认 5)个,
|
||||
// 用本地 amis SDK 6.13.0 + 无头 chromium(playwright)逐个渲染,判定:
|
||||
// ① 无未捕获 JS 错误(window.__amisRenderError 为空);
|
||||
// ② 根组件渲染出 DOM(#root 有子节点)。
|
||||
// 全量渲染不要求——本脚本是抽样冒烟,样本与判定写进 闸二结果.json。
|
||||
//
|
||||
// 用法:node smoke.mjs [产物目录=../转换产物] [每类型样本数=5]
|
||||
|
||||
import http from 'node:http';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { chromium } from 'playwright';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const OUT_DIR = path.resolve(__dirname, process.argv[2] || '../转换产物');
|
||||
const PER_TYPE = parseInt(process.argv[3] || '5', 10);
|
||||
const SDK_DIR = path.resolve(__dirname,
|
||||
'../../../eip4-poc/src/main/resources/static/sdk-local');
|
||||
const SCHEMA_DIR = path.join(OUT_DIR, 'schema');
|
||||
const CSV = path.join(OUT_DIR, '分级清单.csv');
|
||||
|
||||
// ── 从 CSV 选样:每个 root 抽 PER_TYPE 个闸一通过(gate1=true)的模板 ──────────
|
||||
function pickSamples() {
|
||||
const lines = fs.readFileSync(CSV, 'utf8').replace(/^/, '').split('\n').filter(Boolean);
|
||||
lines.shift(); // 表头
|
||||
const byRoot = {};
|
||||
for (const line of lines) {
|
||||
// CSV 首列 id、4 列 root、5 列 grade、6 列 gate1;用简易解析(前 6 列无逗号转义风险)
|
||||
const cols = line.split(',');
|
||||
const id = cols[0], root = cols[3], gate1 = cols[5];
|
||||
if (gate1 !== 'true') continue;
|
||||
if (!byRoot[root]) byRoot[root] = [];
|
||||
if (byRoot[root].length < PER_TYPE) byRoot[root].push(id);
|
||||
}
|
||||
return byRoot;
|
||||
}
|
||||
|
||||
// ── 最小静态服务器:/host.html + /sdk-local/* ────────────────────────────────
|
||||
function startServer() {
|
||||
const types = {
|
||||
'.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css',
|
||||
'.woff': 'font/woff', '.woff2': 'font/woff2', '.ttf': 'font/ttf',
|
||||
'.eot': 'application/vnd.ms-fontobject', '.svg': 'image/svg+xml',
|
||||
'.png': 'image/png', '.json': 'application/json'
|
||||
};
|
||||
const server = http.createServer((req, res) => {
|
||||
const [urlPathRaw, query] = req.url.split('?');
|
||||
const urlPath = decodeURIComponent(urlPathRaw);
|
||||
// schema 经独立端点拉取(避免大 schema 进 URL header 触发 HTTP 431)
|
||||
if (urlPath === '/schema') {
|
||||
const id = new URLSearchParams(query || '').get('id');
|
||||
const file = path.join(SCHEMA_DIR, id + '.json');
|
||||
fs.readFile(file, (err, buf) => {
|
||||
if (err) { res.writeHead(404); res.end('{}'); return; }
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(buf);
|
||||
});
|
||||
return;
|
||||
}
|
||||
let file;
|
||||
if (urlPath === '/host.html' || urlPath === '/') {
|
||||
file = path.join(__dirname, 'host.html');
|
||||
} else if (urlPath.startsWith('/sdk-local/')) {
|
||||
file = path.join(SDK_DIR, urlPath.replace('/sdk-local/', ''));
|
||||
} else {
|
||||
res.writeHead(404); res.end('not found'); return;
|
||||
}
|
||||
fs.readFile(file, (err, buf) => {
|
||||
if (err) { res.writeHead(404); res.end('not found: ' + file); return; }
|
||||
res.writeHead(200, { 'Content-Type': types[path.extname(file)] || 'application/octet-stream' });
|
||||
res.end(buf);
|
||||
});
|
||||
});
|
||||
return new Promise(resolve => server.listen(0, () => resolve(server)));
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const samples = pickSamples();
|
||||
const server = await startServer();
|
||||
const port = server.address().port;
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
|
||||
const results = { perType: {}, samples: [], generatedAt: new Date().toISOString(), perTypeTarget: PER_TYPE };
|
||||
|
||||
for (const [root, ids] of Object.entries(samples)) {
|
||||
if (root === '(null-xml)') continue;
|
||||
results.perType[root] = { sampled: 0, pass: 0, fail: 0 };
|
||||
for (const id of ids) {
|
||||
const schemaPath = path.join(SCHEMA_DIR, id + '.json');
|
||||
if (!fs.existsSync(schemaPath)) continue;
|
||||
const url = `http://127.0.0.1:${port}/host.html?id=${encodeURIComponent(id)}`;
|
||||
|
||||
const page = await browser.newPage();
|
||||
const consoleErrors = [];
|
||||
page.on('console', m => { if (m.type() === 'error') consoleErrors.push(m.text()); });
|
||||
page.on('pageerror', e => consoleErrors.push(String(e)));
|
||||
|
||||
let pass = false, reason = '';
|
||||
try {
|
||||
await page.goto(url, { waitUntil: 'networkidle', timeout: 20000 });
|
||||
// 等根组件渲染出 DOM
|
||||
await page.waitForFunction(
|
||||
() => document.querySelector('#root') && document.querySelector('#root').children.length > 0,
|
||||
{ timeout: 8000 }
|
||||
).catch(() => {});
|
||||
const state = await page.evaluate(() => ({
|
||||
err: window.__amisRenderError,
|
||||
rootChildren: document.querySelector('#root') ? document.querySelector('#root').children.length : 0
|
||||
}));
|
||||
// 过滤已知无害噪声(字体 404、桩接口告警不算渲染错误)
|
||||
const fatal = consoleErrors.filter(e =>
|
||||
!/iconfont|\.woff|\.ttf|favicon|Failed to load resource/i.test(e));
|
||||
if (state.err) { reason = 'JS错误:' + state.err; }
|
||||
else if (state.rootChildren === 0) { reason = '根组件未渲染出 DOM'; }
|
||||
else if (fatal.length) { reason = 'console错误:' + fatal[0].slice(0, 120); }
|
||||
else { pass = true; }
|
||||
} catch (e) {
|
||||
reason = '导航/渲染超时: ' + String(e).slice(0, 100);
|
||||
}
|
||||
await page.close();
|
||||
|
||||
results.perType[root].sampled++;
|
||||
results.perType[root][pass ? 'pass' : 'fail']++;
|
||||
results.samples.push({ root, id, pass, reason });
|
||||
process.stdout.write(`${root} ${id}: ${pass ? 'PASS' : 'FAIL ' + reason}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
server.close();
|
||||
|
||||
fs.writeFileSync(path.join(OUT_DIR, '闸二结果.json'), JSON.stringify(results, null, 2), 'utf8');
|
||||
console.log('\n=== 闸二渲染冒烟汇总(抽样)===');
|
||||
for (const [root, r] of Object.entries(results.perType)) {
|
||||
console.log(` ${root}: 抽样 ${r.sampled},通过 ${r.pass},失败 ${r.fail}`);
|
||||
}
|
||||
}
|
||||
|
||||
run().catch(e => { console.error(e); process.exit(1); });
|
||||
Reference in New Issue
Block a user