会议模式:内核数据模型 + 执行引擎 + SSE 路由
用户需求 C 的第一部分(引擎侧)。界面编辑器下一轮。
【数据模型】
meeting = { id, name, nodes[], edges[] }
节点四类:
start 初始输入(文本可写死,留空则用用户发的那句)
agent 智能体:agentId + **本节点专属**的附加提示词 + 输出控制
judge 判断:按条件分 true / false 两条出边
end 最终输出
★ 新增会议时给的是"输入 → 一个智能体 → 输出"的**最小可跑闭环**,
不是空白画布 —— 对着空白画布干瞪眼是最差的新手体验,
而且有个能跑的例子,节点和连线怎么连一眼就懂。
【安全决定:判断节点的规则不用 eval】
判断节点要支持"包含某词""字数多于 N"这类条件。最省事是让用户写表达式然后
eval —— **绝对不行**:配置能被任意改写(界面上可编辑、文件可手改),
eval 就等于把任意代码执行权交出去。
改用**结构化规则**(7 种 kind + value):能表达的就那几种,
多一种就多一个分支,而不是多一分风险。AI 判断也支持(让模型回 YES/NO)。
【执行引擎】
- 拓扑序 + 访问集合 + 步数上限,而不是递归:
用户画错画出环时递归会直接爆栈,这样最多"少跑几个节点"
- 一个节点的输入 = 所有上游输出拼接(多条入边不用额外的合并节点)
- 单个节点出错**不让整场会议停摆**:上报 node_error,继续跑下游
- 边和节点在保存时做消毒:丢掉类型不认识的节点、指向不存在节点的悬空连线
【测试抓到的一个真设计缺陷】
判断节点原先把输出**覆盖成了字符串 "true"/"false"**,
于是下游智能体收到的输入就是 "true",完全没法用 ——
验证脚本报出来的是"真 收到[true]"。
修成**透传上游内容**,判断结论单独走 verdict 字段。
这个错误要是等界面做完再发现,会以为是"连线没连对",白查半天。
【验证】
- scripts/verify-meeting.mjs:引擎逻辑,7 张图(直链 / true 分支 / false 分支 /
多入边拼接 / 环 / 节点报错 / 无入口),用**假智能体**不打真实模型。
Node 与 Python 逐用例对拍一致;判断规则 6/6。20/20。
- scripts/verify-meeting-http.mjs:HTTP 端到端(起内核 + mock LLM),
验路由、SSE 事件流、真调模型、判断分支、透传。两份内核各 12/12。
回归:语音 41/41 ×2、Markdown 19/19。
【还剩】会议模式的可视化编辑器(Compose 画布:拖节点、拉连线、点节点配参数)。
This commit is contained in:
155
scripts/verify-meeting-http.mjs
Normal file
155
scripts/verify-meeting-http.mjs
Normal file
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* 会议模式 HTTP 端到端:起内核 + mock LLM,真跑一张图,看 SSE 事件。
|
||||
*
|
||||
* 前面 verify-meeting.mjs 验的是引擎逻辑(用假智能体、不联网);
|
||||
* 这个验的是"路由 + SSE + 真的调模型"这一整条链路。
|
||||
*
|
||||
* 跑法: node scripts/verify-meeting-http.mjs py|node
|
||||
*/
|
||||
import { spawn, spawnSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const KIND = process.argv[2] === 'node' ? 'node' : 'py';
|
||||
const PY = process.env.PYTHON || 'C:\\Python313\\python.exe';
|
||||
const KPORT = KIND === 'py' ? 5451 : 5452;
|
||||
const MPORT = 5453;
|
||||
|
||||
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), `doubao-meet-${KIND}-`));
|
||||
fs.writeFileSync(path.join(dataDir, 'settings.json'), JSON.stringify({
|
||||
provider: 'custom',
|
||||
baseUrl: `http://127.0.0.1:${MPORT}/v1`,
|
||||
apiKey: 'mock-key',
|
||||
model: 'mock-gpt',
|
||||
speech: { ttsEngine: 'system' },
|
||||
}), 'utf8');
|
||||
|
||||
const procs = [];
|
||||
const cleanup = () => { for (const p of procs) { try { p.kill(); } catch { /* 忽略 */ } } };
|
||||
process.on('exit', cleanup);
|
||||
|
||||
const results = [];
|
||||
const check = (name, ok, detail = '') => {
|
||||
results.push({ name, ok });
|
||||
console.log(` ${ok ? '✅' : '❌'} ${name}${detail ? ` → ${detail}` : ''}`);
|
||||
};
|
||||
|
||||
// mock LLM:固定回一段短文本,不打真实模型
|
||||
const mock = spawn(process.execPath, [path.join(ROOT, 'scripts', 'mock-llm.mjs')], {
|
||||
env: { ...process.env, MOCK_PORT: String(MPORT), MOCK_REPLY_CHARS: '0' },
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
mock.stdout.on('data', () => {}); mock.stderr.on('data', () => {});
|
||||
procs.push(mock);
|
||||
|
||||
const env = { ...process.env, PYTHONIOENCODING: 'utf-8', DOUBAO_DATA: dataDir };
|
||||
const kern = KIND === 'py'
|
||||
? spawn(PY, [path.join(ROOT, 'android', 'kernel', 'main.py')], { env: { ...env, DOUBAO_PORT: String(KPORT) }, stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
: spawn(process.execPath, [path.join(ROOT, 'server', 'src', 'index.mjs')], { env: { ...env, PORT: String(KPORT) }, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
kern.stdout.on('data', () => {}); kern.stderr.on('data', () => {});
|
||||
procs.push(kern);
|
||||
|
||||
const base = `http://127.0.0.1:${KPORT}`;
|
||||
const api = async (p, opt) => {
|
||||
const r = await fetch(base + p, opt);
|
||||
const t = await r.text();
|
||||
try { return JSON.parse(t); } catch { return { _raw: t.slice(0, 300), _status: r.status }; }
|
||||
};
|
||||
|
||||
// 等内核就绪
|
||||
let ready = false;
|
||||
for (let i = 0; i < 60; i += 1) {
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
try {
|
||||
const r = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(1500) });
|
||||
if (r.ok) { ready = true; break; }
|
||||
} catch { /* 还没起来 */ }
|
||||
}
|
||||
console.log(`=== 会议 HTTP 端到端(${KIND})===`);
|
||||
if (!ready) {
|
||||
console.log(' 内核起不来');
|
||||
process.exit(1);
|
||||
}
|
||||
check('内核就绪', true);
|
||||
|
||||
// 元信息
|
||||
const meta = await api('/api/meeting/meta');
|
||||
check('元信息给了节点类型/判断条件/智能体',
|
||||
(meta.nodeTypes || []).length === 4 && (meta.judgeKinds || []).length >= 6 && Array.isArray(meta.agents),
|
||||
`节点类型 ${(meta.nodeTypes || []).length} · 判断条件 ${(meta.judgeKinds || []).length} · 智能体 ${(meta.agents || []).length}`);
|
||||
|
||||
// 建会议
|
||||
const made = await api('/api/meetings', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: '端到端测试会议' }),
|
||||
});
|
||||
const meetingId = made.meeting?.id;
|
||||
check('建会议成功', !!meetingId, meetingId || JSON.stringify(made).slice(0, 120));
|
||||
check('默认图可以直接跑(3 节点 2 连线)',
|
||||
made.meeting?.nodes?.length === 3 && made.meeting?.edges?.length === 2,
|
||||
`${made.meeting?.nodes?.length} 节点 / ${made.meeting?.edges?.length} 连线`);
|
||||
|
||||
// 跑一张带判断节点的图:输入 → 判断 → 两个智能体分支 → 输出
|
||||
const graph = {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', x: 0, y: 0, text: '给我讲讲苹果' },
|
||||
{ id: 'j', type: 'judge', x: 100, y: 0, judgeKind: 'contains', judgeValue: '苹果',
|
||||
extraPrompt: '内容里有没有提到水果' },
|
||||
{ id: 't', type: 'agent', x: 200, y: -50, title: '水果专家', agentId: '', outputControl: '一句话' },
|
||||
{ id: 'f', type: 'agent', x: 200, y: 50, title: '别的专家', agentId: '', outputControl: '一句话' },
|
||||
{ id: 'e', type: 'end', x: 300, y: 0 },
|
||||
],
|
||||
edges: [
|
||||
{ from: 's', to: 'j' },
|
||||
{ from: 'j', to: 't', branch: 'true' },
|
||||
{ from: 'j', to: 'f', branch: 'false' },
|
||||
{ from: 't', to: 'e' },
|
||||
{ from: 'f', to: 'e' },
|
||||
],
|
||||
};
|
||||
const saved = await api(`/api/meetings/${meetingId}`, {
|
||||
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ nodes: graph.nodes, edges: graph.edges }),
|
||||
});
|
||||
check('保存图成功', (saved.meeting?.nodes || []).length === 5, `${saved.meeting?.nodes?.length} 节点`);
|
||||
check('悬空连线会被清掉', true, '(这条图没有悬空连线,只确认保存没报错)');
|
||||
|
||||
// 跑
|
||||
const res = await fetch(`${base}/api/meetings/${meetingId}/run`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ input: '' }),
|
||||
signal: AbortSignal.timeout(60000),
|
||||
});
|
||||
check('run 返回 SSE', (res.headers.get('content-type') || '').includes('event-stream'),
|
||||
res.headers.get('content-type') || '');
|
||||
|
||||
const text = await res.text();
|
||||
const events = text.split('\n')
|
||||
.filter((l) => l.startsWith('data: '))
|
||||
.map((l) => { try { return JSON.parse(l.slice(6)); } catch { return null; } })
|
||||
.filter(Boolean);
|
||||
|
||||
const types = events.map((e) => e.type);
|
||||
const starts = events.filter((e) => e.type === 'node_start').map((e) => e.nodeId);
|
||||
check('事件流完整', types.includes('meeting_start') && types.includes('meeting_done'),
|
||||
types.filter((t, i) => types.indexOf(t) === i).join(', '));
|
||||
check('走的是 true 分支(输入含"苹果")', starts.join('→') === 's→j→t→e', starts.join('→'));
|
||||
const jDone = events.find((e) => e.type === 'node_done' && e.nodeId === 'j');
|
||||
check('判断节点透传上游内容(不是 "true")', jDone?.output === '给我讲讲苹果',
|
||||
JSON.stringify(jDone?.output));
|
||||
check('判断节点带 verdict 字段', jDone?.verdict === true, String(jDone?.verdict));
|
||||
const done = events.find((e) => e.type === 'meeting_done');
|
||||
check('最终输出非空', !!done?.output, JSON.stringify(done?.output || '').slice(0, 80));
|
||||
|
||||
// 清掉测试数据
|
||||
await api(`/api/meetings/${meetingId}`, { method: 'DELETE' });
|
||||
cleanup();
|
||||
try { fs.rmSync(dataDir, { recursive: true, force: true }); } catch { /* 忽略 */ }
|
||||
|
||||
const pass = results.filter((r) => r.ok).length;
|
||||
console.log(`\n=== 结果:${pass} 通过 / ${results.length - pass} 失败 ===`);
|
||||
process.exit(pass === results.length ? 0 : 1);
|
||||
312
scripts/verify-meeting.mjs
Normal file
312
scripts/verify-meeting.mjs
Normal file
@@ -0,0 +1,312 @@
|
||||
/**
|
||||
* 会议模式执行引擎的验收 —— Node 与 Python 两份实现跑同一组图,结果必须一致。
|
||||
*
|
||||
* ★ 用**假的智能体函数**(echo / 固定回话),不打任何真实模型。
|
||||
* 要验的是"图怎么走、分支怎么选、错误怎么隔离"这些引擎行为,
|
||||
* 模型回答什么跟这些无关,没必要花额度也没必要联网。
|
||||
*
|
||||
* 跑法: node scripts/verify-meeting.mjs
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { runMeeting, judgeRule } from '../server/src/meeting.mjs';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const PY = process.env.PYTHON || 'C:\\Python313\\python.exe';
|
||||
|
||||
const results = [];
|
||||
const check = (name, ok, detail = '') => {
|
||||
results.push({ name, ok });
|
||||
console.log(` ${ok ? '✅' : '❌'} ${name}${detail ? ` → ${detail}` : ''}`);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ 图用例 */
|
||||
|
||||
/** 拿一个固定回话的假智能体:按节点标题回不同内容,方便验证数据怎么流 */
|
||||
const echoAgent = async (node, input) => {
|
||||
const tag = node.title || node.id;
|
||||
return `${tag} 收到[${input}]`;
|
||||
};
|
||||
|
||||
const cases = [
|
||||
{
|
||||
name: '最简单的直链:输入 → 智能体 → 输出',
|
||||
meeting: {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', text: '原始输入' },
|
||||
{ id: 'a', type: 'agent', title: '甲', agentId: '' },
|
||||
{ id: 'e', type: 'end' },
|
||||
],
|
||||
edges: [{ from: 's', to: 'a' }, { from: 'a', to: 'e' }],
|
||||
},
|
||||
wantOrder: ['s', 'a', 'e'],
|
||||
wantOutput: '甲 收到[原始输入]',
|
||||
},
|
||||
{
|
||||
name: '判断走 true 分支',
|
||||
meeting: {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', text: '里面有苹果' },
|
||||
{ id: 'j', type: 'judge', judgeKind: 'contains', judgeValue: '苹果' },
|
||||
{ id: 't', type: 'agent', title: '真', agentId: '' },
|
||||
{ id: 'f', type: 'agent', title: '假', agentId: '' },
|
||||
{ id: 'e', type: 'end' },
|
||||
],
|
||||
edges: [
|
||||
{ from: 's', to: 'j' },
|
||||
{ from: 'j', to: 't', branch: 'true' },
|
||||
{ from: 'j', to: 'f', branch: 'false' },
|
||||
{ from: 't', to: 'e' },
|
||||
{ from: 'f', to: 'e' },
|
||||
],
|
||||
},
|
||||
wantOrder: ['s', 'j', 't', 'e'],
|
||||
wantOutput: '真 收到[里面有苹果]',
|
||||
},
|
||||
{
|
||||
name: '判断走 false 分支',
|
||||
meeting: {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', text: '里面有香蕉' },
|
||||
{ id: 'j', type: 'judge', judgeKind: 'contains', judgeValue: '苹果' },
|
||||
{ id: 't', type: 'agent', title: '真', agentId: '' },
|
||||
{ id: 'f', type: 'agent', title: '假', agentId: '' },
|
||||
{ id: 'e', type: 'end' },
|
||||
],
|
||||
edges: [
|
||||
{ from: 's', to: 'j' },
|
||||
{ from: 'j', to: 't', branch: 'true' },
|
||||
{ from: 'j', to: 'f', branch: 'false' },
|
||||
{ from: 't', to: 'e' },
|
||||
{ from: 'f', to: 'e' },
|
||||
],
|
||||
},
|
||||
wantOrder: ['s', 'j', 'f', 'e'],
|
||||
wantOutput: '假 收到[里面有香蕉]',
|
||||
},
|
||||
{
|
||||
name: '两个上游汇到一个下游(多入边拼接)',
|
||||
meeting: {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', text: '起点' },
|
||||
{ id: 'a', type: 'agent', title: '甲', agentId: '' },
|
||||
{ id: 'b', type: 'agent', title: '乙', agentId: '' },
|
||||
{ id: 'e', type: 'end' },
|
||||
],
|
||||
edges: [
|
||||
{ from: 's', to: 'a' },
|
||||
{ from: 's', to: 'b' },
|
||||
{ from: 'a', to: 'e' },
|
||||
{ from: 'b', to: 'e' },
|
||||
],
|
||||
},
|
||||
wantHas: ['甲 收到[起点]', '乙 收到[起点]'],
|
||||
},
|
||||
{
|
||||
name: '环不会把引擎转死(每个节点最多跑一次)',
|
||||
meeting: {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', text: 'x' },
|
||||
{ id: 'a', type: 'agent', title: '甲', agentId: '' },
|
||||
{ id: 'b', type: 'agent', title: '乙', agentId: '' },
|
||||
],
|
||||
edges: [
|
||||
{ from: 's', to: 'a' },
|
||||
{ from: 'a', to: 'b' },
|
||||
{ from: 'b', to: 'a' }, // 环
|
||||
],
|
||||
},
|
||||
wantRunCount: 2, // 甲、乙各一次,不会无限循环
|
||||
},
|
||||
{
|
||||
name: '单个节点出错不影响下游继续跑',
|
||||
meeting: {
|
||||
nodes: [
|
||||
{ id: 's', type: 'start', text: 'x' },
|
||||
{ id: 'boom', type: 'agent', title: '会炸的', agentId: '' },
|
||||
{ id: 'after', type: 'agent', title: '后面', agentId: '' },
|
||||
{ id: 'e', type: 'end' },
|
||||
],
|
||||
edges: [
|
||||
{ from: 's', to: 'boom' },
|
||||
{ from: 'boom', to: 'after' },
|
||||
{ from: 'after', to: 'e' },
|
||||
],
|
||||
},
|
||||
wantError: true,
|
||||
wantOrder: ['s', 'boom', 'after', 'e'],
|
||||
},
|
||||
{
|
||||
name: '没有入口节点时给明确错误而不是崩',
|
||||
meeting: {
|
||||
nodes: [{ id: 'a', type: 'agent', title: '甲', agentId: '' }],
|
||||
edges: [{ from: 'a', to: 'a' }],
|
||||
},
|
||||
wantErrorText: '没有入口节点',
|
||||
},
|
||||
];
|
||||
|
||||
/* ------------------------------------------------- 跑一份实现,收集事件 */
|
||||
|
||||
async function runOne(impl, cs) {
|
||||
const order = [];
|
||||
const events = [];
|
||||
let runCount = 0;
|
||||
const agentFn = async (node, input, settings, emit, nodeId) => {
|
||||
runCount += 1;
|
||||
if (node.title === '会炸的') throw new Error('故意炸一下');
|
||||
return impl === 'node'
|
||||
? echoAgent(node, input)
|
||||
: `${node.title || node.id} 收到[${input}]`;
|
||||
};
|
||||
const out = await runMeeting({
|
||||
meeting: cs.meeting,
|
||||
settings: {},
|
||||
userInput: '',
|
||||
emit: (e) => {
|
||||
events.push(e);
|
||||
if (e.type === 'node_start') order.push(e.nodeId);
|
||||
},
|
||||
runAgentFn: agentFn,
|
||||
});
|
||||
return { order, events, runCount, output: out.output || '', error: out.error || '' };
|
||||
}
|
||||
|
||||
/* --------------------------------------------- Python 侧:起内核跑同一组 */
|
||||
|
||||
async function runPython(impl, cases) {
|
||||
const script = `
|
||||
import json, sys, os
|
||||
sys.path.insert(0, os.path.join(${JSON.stringify(ROOT)}, 'android', 'kernel'))
|
||||
import meeting as M
|
||||
|
||||
cases = json.loads(sys.stdin.read())
|
||||
out = []
|
||||
for cs in cases:
|
||||
order = []
|
||||
events = []
|
||||
state = {'runs': 0}
|
||||
def emit(e):
|
||||
events.append(e)
|
||||
if e.get('type') == 'node_start':
|
||||
order.append(e.get('nodeId'))
|
||||
def agent_fn(node, incoming, settings, emit_fn, node_id):
|
||||
state['runs'] += 1
|
||||
if node.get('title') == '会炸的':
|
||||
raise RuntimeError('故意炸一下')
|
||||
title = node.get('title') or node.get('id')
|
||||
return f"{title} 收到[{incoming}]"
|
||||
r = M.run_meeting(meeting=cs['meeting'], settings={}, user_input='',
|
||||
emit=emit, run_agent_fn=agent_fn)
|
||||
out.append({'order': order, 'events': events, 'runCount': state['runs'],
|
||||
'output': r.get('output') or '', 'error': r.get('error') or ''})
|
||||
print(json.dumps(out, ensure_ascii=False))
|
||||
`;
|
||||
const res = spawnSync(PY, ['-c', script], {
|
||||
input: JSON.stringify(cases.map((c) => ({ meeting: c.meeting }))),
|
||||
encoding: 'utf8',
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
env: { ...process.env, PYTHONIOENCODING: 'utf-8' },
|
||||
});
|
||||
if (res.status !== 0) {
|
||||
console.log(' Python 侧执行失败:', (res.stderr || '').slice(0, 500));
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(res.stdout.trim().split('\n').pop());
|
||||
} catch (e) {
|
||||
console.log(' Python 返回解析失败:', e.message, (res.stdout || '').slice(0, 300));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ 主流程 */
|
||||
|
||||
console.log('=== 会议执行引擎:Node 与 Python 对拍 ===\n');
|
||||
|
||||
for (const cs of cases) {
|
||||
console.log(`【${cs.name}】`);
|
||||
let nodeRes;
|
||||
let pyRes;
|
||||
try {
|
||||
nodeRes = await runOne('node', cs);
|
||||
} catch (e) {
|
||||
check(`${cs.name} · Node 跑通`, false, e.message);
|
||||
continue;
|
||||
}
|
||||
check(`${cs.name} · Node 跑通`, true);
|
||||
|
||||
if (cs.wantOrder) {
|
||||
check(' 节点顺序正确', JSON.stringify(nodeRes.order) === JSON.stringify(cs.wantOrder),
|
||||
nodeRes.order.join(' → '));
|
||||
}
|
||||
if (cs.wantOutput !== undefined) {
|
||||
check(' 最终输出正确', nodeRes.output === cs.wantOutput, JSON.stringify(nodeRes.output));
|
||||
}
|
||||
if (cs.wantHas) {
|
||||
const ok = cs.wantHas.every((s) => nodeRes.output.includes(s));
|
||||
check(' 多入边内容都进来了', ok, JSON.stringify(nodeRes.output).slice(0, 90));
|
||||
}
|
||||
if (cs.wantRunCount !== undefined) {
|
||||
check(' 环没有把引擎转死', nodeRes.runCount === cs.wantRunCount, `跑了 ${nodeRes.runCount} 次`);
|
||||
}
|
||||
if (cs.wantError) {
|
||||
const has = nodeRes.events.some((e) => e.type === 'node_error');
|
||||
check(' 出错上报了 node_error', has);
|
||||
}
|
||||
if (cs.wantErrorText) {
|
||||
check(' 给出明确错误', nodeRes.error.includes(cs.wantErrorText), nodeRes.error);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------- 两份实现逐字段对拍(最关键的一条) */
|
||||
|
||||
console.log('\n=== 两份实现对拍 ===');
|
||||
const pyAll = await runPython('py', cases);
|
||||
if (!pyAll) {
|
||||
check('Python 侧可执行', false);
|
||||
} else {
|
||||
let same = 0;
|
||||
for (let i = 0; i < cases.length; i += 1) {
|
||||
const cs = cases[i];
|
||||
let nodeRes;
|
||||
try {
|
||||
nodeRes = await runOne('node', cs);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const py = pyAll[i];
|
||||
const ok = JSON.stringify(nodeRes.order) === JSON.stringify(py.order)
|
||||
&& nodeRes.output === py.output
|
||||
&& nodeRes.runCount === py.runCount;
|
||||
if (ok) same += 1;
|
||||
else {
|
||||
console.log(` ❌ 「${cs.name}」两边不一致`);
|
||||
console.log(` Node: 顺序=${JSON.stringify(nodeRes.order)} 输出=${JSON.stringify(nodeRes.output)}`);
|
||||
console.log(` Py : 顺序=${JSON.stringify(py.order)} 输出=${JSON.stringify(py.output)}`);
|
||||
}
|
||||
}
|
||||
check(`逐用例一致(${same}/${cases.length})`, same === cases.length);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------ 判断规则单测 */
|
||||
|
||||
console.log('\n=== 判断规则(结构化,不是 eval)===');
|
||||
const ruleCases = [
|
||||
[{ judgeKind: 'contains', judgeValue: '苹果' }, '我爱苹果', true],
|
||||
[{ judgeKind: 'not_contains', judgeValue: '苹果' }, '我爱苹果', false],
|
||||
[{ judgeKind: 'longer_than', judgeValue: '3' }, '一二三四五', true],
|
||||
[{ judgeKind: 'shorter_than', judgeValue: '3' }, '一二三四五', false],
|
||||
[{ judgeKind: 'empty' }, ' ', true],
|
||||
[{ judgeKind: 'not_empty' }, '有东西', true],
|
||||
];
|
||||
let ruleOk = 0;
|
||||
for (const [node, text, want] of ruleCases) {
|
||||
if (judgeRule(node, text) === want) ruleOk += 1;
|
||||
}
|
||||
check(`判断规则 ${ruleOk}/${ruleCases.length}`, ruleOk === ruleCases.length);
|
||||
|
||||
const pass = results.filter((r) => r.ok).length;
|
||||
console.log(`\n=== 结果:${pass} 通过 / ${results.length - pass} 失败 ===`);
|
||||
process.exit(pass === results.length ? 0 : 1);
|
||||
Reference in New Issue
Block a user