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.

38 lines
1.3 KiB

2 days ago
# -*- coding: utf-8 -*-
r"""票 08 前置:扫 demo/index.html 全部 api() 调用,与 defs_a4.py 57 端点对账(找路径偏差)。"""
import io, sys, re, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.path.insert(0, r'd:\code\crm-backend-matt\.scratch\customer-e2e')
from defs_a4 import DEFS
DEMO = r'd:\code\crm-backend-matt\.scratch\customer-e2e\demo\index.html'
txt = open(DEMO, encoding='utf-8').read()
# 源 keys(占位形态)+ 允许的演示实例形态
src_paths = {d['path'] for d in DEFS}
src_methods = {}
for d in DEFS:
src_methods.setdefault(d['path'], set()).add(d['method'])
# demo 里 api('...') 字面串 + api(`...`) 模板串
calls = []
for m in re.finditer(r"""api\(\s*(['\"`])(.+?)\1""", txt):
calls.append(m.group(2))
def to_tpl(u):
"""把演示 url(数字 id/mine 等实例)归一回 {id}/{workspace} 占位形态再对账。"""
u = re.sub(r'(?<=/)(mine|overview|pool)(?=/|\\?|$)', '{workspace}', u)
u = re.sub(r'(?<=/)\d{5,}(?=/|\\?|$)', '{id}', u)
return u.split('?')[0]
print(f'demo api() 调用 {len(calls)} 处,去重归一后:')
bad = 0
for c in sorted(set(calls)):
tpl = to_tpl(c)
hit = tpl in src_paths
mark = 'OK ' if hit else '?? '
if not hit:
bad += 1
print(f' {mark} {c} -> {tpl}')
print(f'\nunmatched: {bad}')