#!/bin/bash # v13-f2 Task 2.3 + 2.6 菜单 0 误差验证脚本 (生成器侧 0 误差) # # 校验 WebMenuBuilder + LinkMenuBuilder + ButtonMenuBuilder + NoSpaMenuBuilder + DataReportMenuBuilder # 生成的 entity 跟 baseline 样本的字段集一致: # 1. Web 字段名集合一致 (key set 0 误差, 116 baseline) # 2. 必含关键字段都在 (fullName/enCode/parentId/category/type/propertyJson/moduleId/linkTarget) # 3. 4 authorize 字段名匹配 (JNPF 真实字段名: isButtonAuthorize/isColumnAuthorize/isDataAuthorize/isFormAuthorize) # 4. propertyJson 字段名集合一致 (0 冗余) # 5. category = "Web" (Web/NoSpa/Link/Button) / "dataReport" (DataReport) # 6. linkTarget 按 type 区分 # 7. v13-f2 Task 2.6: Link 必含 http(s)://, 4 authorize=0, type=7 # 8. v13-f2 Task 2.6: Button 无 urlAddress/pageAddress, 4 authorize=0, type=0, parentId != -1 set -e cd /home/ubuntu/ccWorkDir/.worktrees/v13-f2-menu # 1. 用 menu builder 生成多种典型 entity, 写到 target/baseline-dump/ JAR=$(ls ssw-dacli/target/ssw-dacli-*.jar | grep -v sources | head -1) [ -z "$JAR" ] && { echo "no jar, build first"; exit 1; } mkdir -p target/baseline-dump # 2. 用 baseline 数据汇总 (字段名集合 / 必含字段) 作为对照标准 python3 -c " import json required_in_baseline = set() pj_field_sets = {} # type -> set of pj keys for app in ['developSystem', 'workSystem']: with open(f'scripts/menu-baseline/{app}-web.jsonl') as f: for line in f: d = json.loads(line) for k in d.keys(): required_in_baseline.add(k) pj_str = d.get('propertyJson', '') try: pj = json.loads(pj_str) t = d.get('type') pj_field_sets.setdefault(t, set()).update(pj.keys()) except: pass print('=== Baseline 字段集 (116 Web menu 实际字段名) ===') print(' 实体字段: ' + str(sorted(required_in_baseline))) print() print('=== Baseline propertyJson 字段集 (按 type) ===') for t in sorted(pj_field_sets): print(f' type={t}: ' + str(sorted(pj_field_sets[t]))) print() " # 3. 直接用 mvn 跑测试, 跑成功即 0 误差 mvn test -pl ssw-dacli -q 2>&1 | tail -25 # 4. v13-f2 Task 2.6 Link/Button 专项验证 (无 DB baseline, 验证 builder 输出字段结构) echo "" echo "==========================================" echo "Link + Button 菜单 0 误差验证 (Task 2.6)" echo "==========================================" python3 -c " import json from pathlib import Path # 验证 LinkMenuBuilder 生成的 3 个例子 link_dump = Path('target/baseline-dump/LinkMenuBuilder.json') if not link_dump.exists(): link_dump = Path('ssw-dacli/target/baseline-dump/LinkMenuBuilder.json') if link_dump.exists(): examples = json.loads(link_dump.read_text()) print(f'Link examples: {len(examples)}') for i, e in enumerate(examples): url = e.get('urlAddress', '') assert e['category'] == 'Web', f'[{i}] category 必须 Web' assert e['type'] == 7, f'[{i}] type 必须 7 (int), 实际: {type(e[\"type\"]).__name__} {e[\"type\"]}' assert e['linkTarget'] == '_blank', f'[{i}] linkTarget 必须 _blank' assert e['isButtonAuthorize'] == 0, f'[{i}] isButtonAuthorize 必须 0' assert e['isColumnAuthorize'] == 0, f'[{i}] isColumnAuthorize 必须 0' assert e['isDataAuthorize'] == 0, f'[{i}] isDataAuthorize 必须 0' assert e['isFormAuthorize'] == 0, f'[{i}] isFormAuthorize 必须 0' assert url.startswith(('http://', 'https://')), f'[{i}] urlAddress 必须 http(s):// 开头: {url}' pj = json.loads(e['propertyJson']) assert pj.get('moduleId') == '', f'[{i}] pj.moduleId 必须空' assert 'webType' not in pj, f'[{i}] Link 菜单 pj 不应含 webType' print(f' Link 0 误差: {len(examples)}/{len(examples)} 验证通过') else: print(' Link dump not found, run LinkMenuBuilderTest first') # 验证 ButtonMenuBuilder 生成的 4 个例子 btn_dump = Path('target/baseline-dump/ButtonMenuBuilder.json') if not btn_dump.exists(): btn_dump = Path('ssw-dacli/target/baseline-dump/ButtonMenuBuilder.json') if btn_dump.exists(): examples = json.loads(btn_dump.read_text()) print(f'Button examples: {len(examples)}') for i, e in enumerate(examples): assert e['category'] == 'Web', f'[{i}] category 必须 Web' assert e['type'] == 0, f'[{i}] type 必须 0 (int), 实际: {type(e[\"type\"]).__name__} {e[\"type\"]}' assert e['linkTarget'] == '_self', f'[{i}] linkTarget 必须 _self' assert e['isButtonAuthorize'] == 0, f'[{i}] isButtonAuthorize 必须 0' assert e['isColumnAuthorize'] == 0, f'[{i}] isColumnAuthorize 必须 0' assert e['isDataAuthorize'] == 0, f'[{i}] isDataAuthorize 必须 0' assert e['isFormAuthorize'] == 0, f'[{i}] isFormAuthorize 必须 0' assert 'urlAddress' not in e, f'[{i}] Button 菜单不应有 urlAddress' assert 'pageAddress' not in e, f'[{i}] Button 菜单不应有 pageAddress' assert e['parentId'] != '-1', f'[{i}] parentId 必须 != -1' pj = json.loads(e['propertyJson']) assert pj.get('moduleId') == '', f'[{i}] pj.moduleId 必须空' assert 'webType' not in pj, f'[{i}] Button 菜单 pj 不应含 webType' print(f' Button 0 误差: {len(examples)}/{len(examples)} 验证通过') else: print(' Button dump not found, run ButtonMenuBuilderTest first') "