Files
doubao-clone/scripts/verify-var-pins.py

43 lines
2.1 KiB
Python
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.

"""守"界面和引擎对写变量的规则必须一致"这条。
为什么单独一个脚本而不是塞进 verify-meeting.mjs:
那个套件的图会被 withDataEdges 补数据线,而 Node 侧引擎又没实现
var/readvar —— 这条用例在那儿既容易被框架改写,又过不了对拍。
单独测反而干净:只关心"这条边留不留得住"。
"""
import os, sys
WS = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(WS, 'android', 'kernel'))
import meeting as M
bad = 0
# ① 写变量的入口类型必须和界面的规则一致
# 界面 inputPins:"var" -> 变量是 list 时入口是 str(要追加的文本),否则按变量类型
want = {'str': 'str', 'num': 'num', 'bool': 'bool', 'list': 'str'}
for vt, exp in want.items():
nodes = [{'id': 'w', 'type': 'var', 'varName': 'x'}]
M._set_type_context(nodes, [{'name': 'x', 'type': vt, 'initial': '', 'note': ''}], [])
got = M._data_in_type('w')
ok = got == (exp,)
bad += 0 if ok else 1
print(' %s 变量 %-5s -> 写变量入口 %-12s(界面显示 %s)' % ('v' if ok else 'X', vt, got, exp))
# ② 列表变量:接一段**文本**要留得住(这是用户报的"连不上")
nodes = [
{'id': 'w', 'type': 'var', 'varName': '要点'},
{'id': 's', 'type': 'value', 'text': '一条', 'valueType': 'str'},
{'id': 'l', 'type': 'value', 'text': '["a"]', 'valueType': 'list'},
]
M._set_type_context(nodes, [{'name': '要点', 'type': 'list', 'initial': '[]', 'note': ''}], [])
kept = M._sanitize_edges([
{'from': 's', 'to': 'w', 'kind': 'str'},
{'from': 'l', 'to': 'w', 'kind': 'list'},
], nodes)
keep_str = any(e['from'] == 's' for e in kept)
drop_list = not any(e['from'] == 'l' for e in kept)
bad += 0 if (keep_str and drop_list) else 1
print(' %s 文本 -> 列表变量: %s' % ('v' if keep_str else 'X', '保留' if keep_str else '被丢(用户会看到"连不上")'))
print(' %s 列表 -> 列表变量: %s' % ('v' if drop_list else 'X', '被丢(对的)' if drop_list else '保留(应该丢)'))
sys.exit(1 if bad else 0)