You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.4 KiB

3 days ago
# -*- coding: utf-8 -*-
"""_splice_core.py — 把 _tail_core.py.txt 拼进 e2e-core.py,并修既有小错。
1. f05 oplog/page POSTGETcontroller @GetMappingPOST 405
2. f04/f05 字典码动态化'gov'/'customer_type_01' 硬编码 CTYPE/GOV/GOV_CHILD
3. 框架区插入 dict_one + CTYPE/GOV/GOV_CHILD 常量
4. _capture 路径 id 归一化/750844.../ /{id}/ 06 Bruno 按端点归档
5. 'def main():' 起整体替换为 tailF-07..F-12 + 完整 main
"""
import io, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
TARGET = '.scratch/customer-e2e/e2e-core.py'
TAIL = '.scratch/customer-e2e/_tail_core.py.txt'
txt = open(TARGET, encoding='utf-8').read()
tail = open(TAIL, encoding='utf-8').read()
# --- 1. f05 oplog POST→GET ---
old6 = "d = data_of(api(S, 'POST', f'/api/customer/{fid}/oplog/page', form={'current': 1, 'size': 20}))"
new6 = "d = data_of(api(S, 'GET', f'/api/customer/{fid}/oplog/page', params={'current': 1, 'size': 20}))"
assert old6 in txt, 'f05 oplog anchor missing'
txt = txt.replace(old6, new6, 1)
# --- 2. 字典码动态化 ---
old1 = "customerType=IDS['_dict']['customerType'] if '_dict' in IDS else 'customer_type_01',"
assert old1 in txt, 'f04 customerType anchor missing'
txt = txt.replace(old1, 'customerType=CTYPE,', 1)
old5 = "industryCode='gov', customerStarLevel=3, relationStarLevel=3,"
assert old5 in txt, 'f04 industryCode anchor missing'
txt = txt.replace(old5, 'industryCode=GOV, customerStarLevel=3, relationStarLevel=3,', 1)
old2 = "form={'customerName': 'e2c-全字段-科技', 'customerType': 'customer_type_01',"
assert txt.count(old2) == 2, f'f05 PUT x2 expected, got {txt.count(old2)}'
txt = txt.replace(old2, "form={'customerName': 'e2c-全字段-科技', 'customerType': CTYPE,")
old3 = "'industryCode': 'gov', 'industryChildCode': 'gov_1',"
assert old3 in txt, 'f05 industryChildCode anchor missing'
txt = txt.replace(old3, "'industryCode': GOV, 'industryChildCode': GOV_CHILD,", 1)
old4 = "'industryCode': 'gov', 'customerStarLevel': 3, 'relationStarLevel': 3,"
assert old4 in txt, 'f05 industryCode-2 anchor missing'
txt = txt.replace(old4, "'industryCode': GOV, 'customerStarLevel': 3, 'relationStarLevel': 3,", 1)
# --- 3. 框架区插入 dict_one + 常量 ---
anchor_f = 'F = lambda: None # noqa'
assert anchor_f in txt, 'framework anchor missing'
dict_block = (
"def dict_one(group, parent_id=None):\n"
" # 字典组首个活跃码值(动态契约,防字典码硬编码漂移;失败回退 None)。\n"
" try:\n"
" if parent_id:\n"
" rows = dbq(\"SELECT i.code c FROM dict_item i JOIN dict_group g ON i.group_id=g.id \"\n"
" \"WHERE g.code=%s AND i.deleted=0 AND i.parent_id=%s ORDER BY i.sort_no LIMIT 1\",\n"
" (group, parent_id))\n"
" else:\n"
" rows = dbq(\"SELECT i.code c FROM dict_item i JOIN dict_group g ON i.group_id=g.id \"\n"
" \"WHERE g.code=%s AND i.deleted=0 AND i.parent_id IS NULL ORDER BY i.sort_no LIMIT 1\",\n"
" (group,))\n"
" return rows[0]['c'] if rows else None\n"
" except Exception:\n"
" return None\n"
"\n"
"\n"
"CTYPE = dict_one('customer_type') or 'customer_type_01'\n"
"GOV = dict_one('industry') or 'gov'\n"
"GOV_CHILD = ''\n"
"try:\n"
" _p = dbq(\"SELECT i.id FROM dict_item i JOIN dict_group g ON i.group_id=g.id \"\n"
" \"WHERE g.code='industry' AND i.deleted=0 AND i.parent_id IS NULL ORDER BY i.sort_no LIMIT 1\")\n"
" if _p:\n"
" GOV_CHILD = dict_one('industry', _p[0]['id']) or ''\n"
"except Exception:\n"
" GOV_CHILD = ''\n"
"\n"
"\n"
)
txt = txt.replace(anchor_f, dict_block + anchor_f, 1)
# --- 4. _capture 路径 id 归一化 ---
old7 = "def _capture(method, path, req, resp_body):\n key = f'{method} {path}'"
assert old7 in txt, '_capture anchor missing'
txt = txt.replace(old7,
"def _capture(method, path, req, resp_body):\n"
" path = re.sub(r'/\\d{15,}', '/{id}', path) # 路径 id 归一化:票 06 按端点归档\n"
" key = f'{method} {path}'", 1)
# --- 5. 尾部拼接 ---
idx = txt.index('def main():')
txt = txt[:idx] + tail
open(TARGET, 'w', encoding='utf-8', newline='\n').write(txt)
n = len(txt.splitlines())
bom = open(TARGET, 'rb').read(3) == b'\xef\xbb\xbf'
print(f'OK {n} lines BOM={bom}')