diff --git a/style-source/tools/harness.mjs b/style-source/tools/harness.mjs index 19a8d6e..72ec10d 100644 --- a/style-source/tools/harness.mjs +++ b/style-source/tools/harness.mjs @@ -65,10 +65,37 @@ const PAGE_HTML = `
` async function main() { - const stylesRaw = readFileSync(STYLES_JSON, 'utf8') - const stylesCount = JSON.parse(stylesRaw).styles.length + const stylesParsed = JSON.parse(readFileSync(STYLES_JSON, 'utf8')) + const stylesCount = stylesParsed.styles.length console.log('· 本地 styles.json:' + stylesCount + ' 条') + // 线上数据已经 100% 声明变量,真实风格里再没有「有占位符但没声明」的样本。 + // 那条降级分支仍然必须覆盖(宿主可能拿到旧版 / 第三方数据),所以克隆一条探针风格注入, + // 只改 id/name/prompt/variables —— 其余字段沿用真实数据,卡片渲染逻辑不特殊化。 + const probe = JSON.parse(JSON.stringify(stylesParsed.styles[0])) + probe.id = '__probe_undeclared' + probe.code = '' + probe.number = '' + probe.name = '探针:未声明占位符' + probe.summary = 'harness 注入的探针风格,用来覆盖「有占位符但没声明」的降级分支' + probe.prompt = 'probe {alpha_desc} / {beta_desc} / {gamma_desc}' + probe.variables = [] + delete probe.variable_descs + + // 第二个探针:一半变量有 desc、一半没有。整改后线上数据已经「有就全有、没就全没」, + // 拿真实风格测不到「没 desc 降级成占位符名」这条分支。 + const probe2 = JSON.parse(JSON.stringify(stylesParsed.styles[0])) + probe2.id = '__probe_desc_mix' + probe2.code = '' + probe2.number = '' + probe2.name = '探针:desc 混合' + probe2.summary = 'harness 注入的探针风格,一半变量带 desc、一半不带' + probe2.prompt = 'probe2 {主体} {标题}' + // 注意:styles.json 里 variables 是 {kv_var: style_var} 的字典,不是数组 + probe2.variables = { 主体: '{主体}', 标题: '{标题}' } + probe2.variable_descs = { 主体: '如:一只猫、一台相机' } + const stylesRaw = JSON.stringify({ ...stylesParsed, styles: [...stylesParsed.styles, probe, probe2] }) + const server = createServer((req, res) => { if (req.url === '/' || req.url.startsWith('/?')) { res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }) @@ -440,18 +467,22 @@ async function main() { }) } - const undeclared = await openBySearch('婚礼喜字影像画报') + const undeclared = await openBySearch('探针:未声明占位符') check('提示词有占位符、数据没声明的风格也有输入框', undeclared.names.length === 3 && undeclared.dead === 0, undeclared.name + ' → ' + undeclared.names.join(',')) check('每个输入框都有可读标签(不是空串/裸花括号)', undeclared.pairs.length === 3 && undeclared.pairs.every((p) => p.label.trim().length > 0 && !/[{}]/.test(p.label)), undeclared.pairs.map((p) => p.label + '→{' + p.name + '}').join(', ')) + check('没声明的槽位按「未声明」处理(标签回退成占位符名)', + undeclared.pairs.every((p) => p.implicit && p.label === p.name.replace(/[_-]+/g, ' ')), + undeclared.pairs.map((p) => p.label + (p.implicit ? '(implicit)' : '') ).join(', ')) + // 线上 1411 条声明已全部中文化,{SUBJECT} 这类脏 key 现在能认得中文标签「画面主体」 const vigo = await openBySearch('黄黑漫画食品小志广告风格') const subj = vigo.pairs.find((p) => p.name === 'SUBJECT') - check('脏 key 的反引号被剥掉,占位符 {SUBJECT} 认回声明过的标签', - Boolean(subj) && subj.label === 'SUBJECT' && !subj.implicit, + check('脏 key 的反引号被剥掉,占位符 {SUBJECT} 认回声明过的中文标签', + Boolean(subj) && subj.label === '画面主体' && !subj.implicit, subj ? subj.label + ' → {' + subj.name + '}' + (subj.implicit ? '(按未声明处理)' : '') : '没有 SUBJECT 输入框') check('声明表不会凭空造输入框(每个输入框都能在提示词里找到)', vigo.dead === 0, 'inputs=' + vigo.names.length + ' dead=' + vigo.dead) @@ -471,7 +502,11 @@ async function main() { // desc(variable_descs):有说明的变量用中文说明当灰色提示,没有的降级成占位符名 const withDesc = await openBySearch('东方花茶香氛海报') const hasDesc = withDesc.pairs.filter((p) => p.placeholder && p.placeholder !== p.name) - const noDesc = withDesc.pairs.filter((p) => p.placeholder === p.name) + check('desc 全覆盖的风格:每个输入框都拿到了说明', + hasDesc.length === withDesc.pairs.length && hasDesc.length > 0, + 'inputs=' + withDesc.pairs.length + ' 带 desc=' + hasDesc.length) + const descMix = await openBySearch('探针:desc 混合') + const noDesc = descMix.pairs.filter((p) => p.placeholder === p.name) check('带 desc 的变量用 desc 做 placeholder,而不是英文占位符名', hasDesc.length > 0 && hasDesc.every((p) => /[\u4e00-\u9fa5]/.test(p.placeholder)), hasDesc.slice(0, 3).map((p) => p.label + ' → 「' + p.placeholder.slice(0, 22) + '」').join(' | ')) @@ -479,8 +514,8 @@ async function main() { hasDesc.length > 0 && hasDesc.every((p) => p.title === p.placeholder), hasDesc[0] ? '样例:' + hasDesc[0].title : '没有带 desc 的变量') check('没有 desc 的变量降级成占位符名,不留空 placeholder', - noDesc.length > 0 && noDesc.every((p) => p.placeholder === p.name), - noDesc.slice(0, 3).map((p) => p.label + '→' + p.placeholder).join(', ')) + noDesc.length === 1 && noDesc[0].placeholder === '标题' && descMix.pairs.length === 2, + descMix.pairs.map((p) => p.label + '→' + p.placeholder).join(', ')) check('加了 desc 后仍能正确算出未填数量(不把提示文字当成已填内容)', withDesc.names.length === withDesc.pairs.length && withDesc.dead === 0, 'inputs=' + withDesc.names.length + ' dead=' + withDesc.dead)