dsh-uitest 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -11
- package/bin/uitest.mjs +189 -11
- package/client.js +222 -25
- package/host/agent-bridge.mjs +9 -2
- package/host/agent-test.mjs +1 -1
- package/host/context-budget.mjs +1 -1
- package/index.js +14 -2
- package/lib/agent-session.mjs +81 -3
- package/lib/agent-tasks.mjs +212 -0
- package/lib/batch.mjs +204 -13
- package/lib/browser-ab.mjs +21 -6
- package/lib/browser.mjs +5 -5
- package/lib/config.mjs +1 -0
- package/lib/convert.mjs +178 -40
- package/lib/doc-structure.mjs +316 -0
- package/lib/flow.mjs +49 -14
- package/lib/knowledge-central-episodes.mjs +120 -0
- package/lib/knowledge-central-import.mjs +16 -1
- package/lib/knowledge-central.mjs +176 -25
- package/lib/knowledge-clean.mjs +749 -0
- package/lib/knowledge-consolidate.mjs +1271 -0
- package/lib/knowledge-coverage.mjs +150 -0
- package/lib/knowledge-docs.mjs +3 -3
- package/lib/knowledge-effect.mjs +148 -0
- package/lib/knowledge-facts.mjs +1008 -0
- package/lib/knowledge-maintain.mjs +185 -0
- package/lib/knowledge-permission.mjs +447 -0
- package/lib/knowledge-query.mjs +304 -26
- package/lib/knowledge-store.mjs +169 -14
- package/lib/knowledge-summarize.mjs +332 -0
- package/lib/knowledge.mjs +944 -47
- package/lib/learn-run.mjs +157 -51
- package/lib/run-learn.mjs +34 -0
- package/lib/run-observe.mjs +95 -27
- package/lib/run-stats.mjs +71 -0
- package/package.json +12 -2
- package/scripts/knowledge-central-purge.mjs +248 -0
- package/scripts/knowledge-central-sync.mjs +102 -20
- package/scripts/knowledge-consolidate.mjs +158 -0
- package/scripts/knowledge-coverage.mjs +94 -0
- package/scripts/knowledge-effect.mjs +82 -0
- package/scripts/knowledge-permission-probe.mjs +196 -0
- package/scripts/knowledge-permission-report.mjs +140 -0
- package/scripts/knowledge-report.mjs +492 -0
- package/scripts/knowledge-summarize.mjs +200 -0
- package/skills/uitest/SKILL.md +4 -2
- package/skills/uitest/references/convert-knowledge.md +66 -13
- package/studio/host.mjs +143 -6
- package/studio/knowledge.mjs +279 -42
- package/studio/snapshot.mjs +6 -1
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
// 正典知识清洗:识别用例/单据实例引用、运行产物与标题噪声,并提供稳定的去重键。
|
|
2
|
+
// 正典只保留可复用的系统事实;带实例引用的内容属于执行证据,由调用方分流。
|
|
3
|
+
|
|
4
|
+
export const CASE_ID_RE = /\b(?:TC-[A-Z0-9]+-\d+|auto-tc-[A-Z0-9-]+|agent-TC-[A-Z0-9-]+|studio-TC-[A-Z0-9-]+)\b/i;
|
|
5
|
+
export const DOC_NUMBER_RE = /\b(?:OFP|SOF|OD|SQ|FP|FT|CR|PO|SO)\d{8,}\b/i;
|
|
6
|
+
export const LOOSE_REF_RE = /\b(?:case|batch|process|run):[A-Za-z0-9_-]+/i;
|
|
7
|
+
|
|
8
|
+
const CASE_ID_ALL = new RegExp(CASE_ID_RE.source, 'gi');
|
|
9
|
+
const DOC_NUMBER_ALL = new RegExp(DOC_NUMBER_RE.source, 'gi');
|
|
10
|
+
const LOOSE_REF_ALL = new RegExp(LOOSE_REF_RE.source, 'gi');
|
|
11
|
+
const ANY_INSTANCE_REF = new RegExp(`(?:${CASE_ID_RE.source}|${DOC_NUMBER_RE.source}|${LOOSE_REF_RE.source})`, 'i');
|
|
12
|
+
|
|
13
|
+
const GENERIC_SECTION_RE =
|
|
14
|
+
/^(?:说明|概述|简介|背景|背景与目标|目标|范围|术语|术语和定义|名词解释|附录|变更|版本|注意事项|问题|确认|需求|功能|接口|数据|字段|状态|规则|权限|角色|流程|步骤|分页规则|导出规则|保存规则|表单字段|列表字段|弹窗说明|页面说明|页面清单|功能清单|校验规则|业务规则|异常处理|性能|安全|日志|消息|通知|配置|参数|枚举|字典|目的|编写目的|读者对象|参考资料|参考文档|相关文档|总体设计|详细设计|数据库设计|表结构|数据模型|接口设计|进度日志|数据模拟进度日志|拆单自动执行的核心要素)$/;
|
|
15
|
+
|
|
16
|
+
const ACTION_VERB_RE =
|
|
17
|
+
/^(?:打开|进入|点击|选择|填写|输入|提交|查询|搜索|核对|确认|保存|加载|等待|登录|切换|上传|下载|勾选|取消|返回|新增|编辑|删除|复制|查看|跳转|滚动|关闭|刷新)/;
|
|
18
|
+
|
|
19
|
+
const UI_ACTION_RE =
|
|
20
|
+
/^(?:在|从|于|先|再).{0,16}(?:打开|进入|点击|选择|填写|输入|提交|查询|搜索|核对|确认|保存|加载|等待|登录|切换|上传|下载|勾选|取消|返回|新增|编辑|删除|复制|查看|跳转|滚动|关闭|刷新)/;
|
|
21
|
+
|
|
22
|
+
const RULE_SIGNAL_RE =
|
|
23
|
+
/应|需|必须|不得|不能|只能|只允许|默认|状态为|状态包含|校验|限制|不允许|支持|禁止|超时|上限|下限|权限|自动生成|自动|手动/;
|
|
24
|
+
|
|
25
|
+
// 典型的执行记录陈述:日期开头,或「测试/验证/复现」的结果描述。
|
|
26
|
+
const EVIDENCE_STATEMENT_RE =
|
|
27
|
+
/^(?:\d{4}[-/年]\d{1,2}|\d{1,2}[-/月]\d{1,2})|(?:测试|验证|复现)(?:通过|失败|结果|记录|时|中|发现)|本次|该用例|执行结果|实际结果|预期结果/;
|
|
28
|
+
|
|
29
|
+
/** 文本是否含用例/单据实例引用。 */
|
|
30
|
+
export function isCaseReferenced(text) {
|
|
31
|
+
return ANY_INSTANCE_REF.test(String(text || ''));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 列出文本中的实例引用,供分流与报告使用。 */
|
|
35
|
+
export function instanceRefs(text) {
|
|
36
|
+
const value = String(text || '');
|
|
37
|
+
return {
|
|
38
|
+
caseIds: [...value.matchAll(CASE_ID_ALL)].map((match) => match[0]),
|
|
39
|
+
docNumbers: [...value.matchAll(DOC_NUMBER_ALL)].map((match) => match[0]),
|
|
40
|
+
loose: [...value.matchAll(LOOSE_REF_ALL)].map((match) => match[0]),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 去掉句中的实例引用,保留可复用的陈述。
|
|
46
|
+
* 末尾引用列表(如「… | TC-FP012A-01、TC-FP012A-12」)整段删除;
|
|
47
|
+
* 句中的单号替换为空,调用方需自行判断剩余文本是否仍有意义。
|
|
48
|
+
*/
|
|
49
|
+
export function stripInstanceRefs(text) {
|
|
50
|
+
let value = String(text || '');
|
|
51
|
+
value = value.replace(
|
|
52
|
+
/\s*[||]\s*(?:(?:TC-[A-Z0-9-]+|auto-tc-[A-Z0-9-]+|agent-TC-[A-Z0-9-]+|studio-TC-[A-Z0-9-]+)(?:\s*[、,,;;]\s*)?)+\s*$/gi,
|
|
53
|
+
'',
|
|
54
|
+
);
|
|
55
|
+
value = value.replace(
|
|
56
|
+
/[((][^()()]*?(?:TC-|auto-tc|agent-TC|studio-TC|OFP\d|SOF\d|OD\d|SQ\d|FP\d|FT\d|CR\d|PO\d|SO\d)[^()()]*?[))]/gi,
|
|
57
|
+
'',
|
|
58
|
+
);
|
|
59
|
+
// 先删宽松引用(case:/run:),再删裸编号,避免只剩一个空的 "case:" 前缀。
|
|
60
|
+
value = value.replace(/\b(?:case|batch|process|run):[A-Za-z0-9_-]+/gi, '');
|
|
61
|
+
value = value.replace(CASE_ID_ALL, '').replace(DOC_NUMBER_ALL, '');
|
|
62
|
+
return value
|
|
63
|
+
.replace(/\s{2,}/g, ' ')
|
|
64
|
+
.replace(/\s*[||]\s*$/, '')
|
|
65
|
+
.replace(/[,,、;;]\s*$/, '')
|
|
66
|
+
.trim();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 去重键:忽略大小写、标点、空白与用例编号片段。 */
|
|
70
|
+
export function normalizeKey(text) {
|
|
71
|
+
return String(text || '')
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.replace(/[((]\s*(?:tc|auto|agent|studio)[-A-Z0-9]*\s*[))]/gi, '')
|
|
74
|
+
.replace(/流程\s*\d+\s*$/g, '')
|
|
75
|
+
.replace(/[\s\p{P}]/gu, '')
|
|
76
|
+
.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 页面是否具备可复用结构:有入口、动作、表头或历史观察之一。 */
|
|
80
|
+
export function isStructuredPage(page) {
|
|
81
|
+
return Boolean(
|
|
82
|
+
page?.url ||
|
|
83
|
+
(page?.actions || []).length ||
|
|
84
|
+
(page?.table?.headers || []).length ||
|
|
85
|
+
(page?.observations || []).length,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 按标题/别名匹配唯一的占位页(status=stub 且没有 URL)。
|
|
91
|
+
* 运行学习遇到文档派生的占位页时沿用其 id,避免同一页面另建一份;
|
|
92
|
+
* 同名候选不唯一时返回 null,交给调用方按 URL 新建。
|
|
93
|
+
*/
|
|
94
|
+
export function findStubPageForTitle(pages, title) {
|
|
95
|
+
const key = normalizeKey(stripPageCodePrefix(title));
|
|
96
|
+
if (!key || key.length < 2) return null;
|
|
97
|
+
const candidates = [];
|
|
98
|
+
for (const page of Array.isArray(pages) ? pages : []) {
|
|
99
|
+
if (page?.status !== 'stub' || page?.url) continue;
|
|
100
|
+
const names = [page.title, ...(Array.isArray(page.aliases) ? page.aliases : [])];
|
|
101
|
+
if (names.some((value) => normalizeKey(stripPageCodePrefix(value)) === key)) candidates.push(page);
|
|
102
|
+
}
|
|
103
|
+
return candidates.length === 1 ? candidates[0] : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 从 URL 中提取长度 ≥10 的页面/菜单数字 ID,用于识别同一页面的不同路由。 */
|
|
107
|
+
export function longNumericTokens(value) {
|
|
108
|
+
return new Set(String(value || '').match(/\d{10,}/g) || []);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 弹窗正文里的实例值:纯数字、数量、分页、日期时间。正典只留结构,不留数据行。
|
|
112
|
+
const INSTANCE_VALUE_RE =
|
|
113
|
+
/^(?:[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?\s*(?:箱|件|个|条|吨|千克|kg|KG|克|元|块|%|%)?|共\s*\d+\s*条|\d+\s*\/\s*\d+|\d+\s*条\s*\/\s*页|第\s*\d+\s*页|\d{4}[-/年]\d{1,2}(?:[-/月]\d{1,2}日?)?(?:[T\s]\d{1,2}:\d{2}(?::\d{2})?)?|\d{1,2}:\d{2}(?::\d{2})?)$/u;
|
|
114
|
+
|
|
115
|
+
/** 是否是单条数据值(而非字段名、表头或规则文本)。 */
|
|
116
|
+
export function isInstanceValueText(value) {
|
|
117
|
+
const text = String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
118
|
+
return !text || INSTANCE_VALUE_RE.test(text);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 文档派生的占位页标题是否只是句子片段/动作短语,而不是可复用页面名。
|
|
123
|
+
* 只用于没有 URL/urlName/结构的存根;带页面名词后缀的「新增/编辑…弹窗」仍视为页面名。
|
|
124
|
+
*/
|
|
125
|
+
export function looksLikeStubTitleNoise(value) {
|
|
126
|
+
const text = stripPageCodePrefix(value).replace(/\s+/g, ' ').trim();
|
|
127
|
+
if (!text) return false;
|
|
128
|
+
if (/[,。;、:]/.test(text)) return true;
|
|
129
|
+
// 页面名后的布局说明(如「(详情页·独立全屏)」)不改变页面名本身;括号里的类型也算页面名。
|
|
130
|
+
const base = text.replace(/[((][^))]*[))]\s*$/u, '').trim() || text;
|
|
131
|
+
const trailingParenthetical = /[((]\s*([^()()]*?)\s*[))]\s*$/u.exec(text);
|
|
132
|
+
const pageNounRe = /(?:弹窗|对话框|页|列表|详情|工作台|界面|配置|设置)$/u;
|
|
133
|
+
const pageName = pageNounRe.test(base)
|
|
134
|
+
|| Boolean(trailingParenthetical && pageNounRe.test(trailingParenthetical[1].trim()));
|
|
135
|
+
if (/^(?:跳转|返回|直达|前往|去往|打开|进入|点击|选择|查看)/.test(base)) return true;
|
|
136
|
+
if (/(?:跳转(?:至|到)|而非|同样在|同样可|需从|需在|应(?:从|在|先|按|与)|不能|不可|是否|直达)/.test(base)) return true;
|
|
137
|
+
if (/^(?:同|除|而非|该|其|此|以上|如下)/.test(base)) return true;
|
|
138
|
+
if (/^(?:新增|编辑|删除|查询|导出|导入|下载|上传)/.test(base) && !pageName) return true;
|
|
139
|
+
// 「用户在…」「操作人员在…」是文档叙述;「财务在途…」「管理员在线…」是页面名。
|
|
140
|
+
if (/^(?:用户|商务人员|操作人员|客服|财务|管理员|采购员|销售员|仓管员|审批人)(?:在|于)(?!途|线|售|建|办|编|读|库|职|场)/.test(base)) return true;
|
|
141
|
+
if (/^(?:依附于|按照|字段参考|适用于|位于|可返回|请返回|重构)/.test(base)) return true;
|
|
142
|
+
// 取消/移除/补充/删除既可能是动作短语,也可能是「删除确认弹窗」这类页面名。
|
|
143
|
+
if (/^(?:取消|移除|补充|删除)/.test(base)) {
|
|
144
|
+
if (/返回|跳转|进入|打开|点击/.test(base)) return true;
|
|
145
|
+
if (!pageName) return true;
|
|
146
|
+
}
|
|
147
|
+
if (/^(?:所有列表|全模块列表|列表|列表页|详情|详情页|页面|页|列表页和详情)$/.test(base)) return true;
|
|
148
|
+
if (/(?:改为|不设独立|无独立|和详情$|与详情$|与P\d|和P\d|及P\d)/.test(base)) return true;
|
|
149
|
+
if (/页面原型|通用展示|展示规范|布局规范|设计详情/.test(base)) return true;
|
|
150
|
+
if (/^[①②③④⑤⑥⑦⑧⑨⑩]/.test(base)) return true;
|
|
151
|
+
// 文档用「在/到/见 + 详情」描述位置或入口(「数量见详情」「需到详情」),不是页面名。
|
|
152
|
+
if (/(?:在|到|至|于|见)详情页?$/u.test(base)) return true;
|
|
153
|
+
// 「记录在/可在/明细在……详情」这类带宾语的位置叙述。
|
|
154
|
+
if (/(?:可在|可于|记录在|保存在|展示在|显示在|明细在|判断在|标记在)[^,。;]{0,12}详情$/u.test(base)) return true;
|
|
155
|
+
if (/(?:跳转|进入|嵌入|参照|归档|导致|区别于|请到|直接在)/u.test(base)) return true;
|
|
156
|
+
if (/^(?:本页面|全系统|统一|按钮|顶部|中缺失|而是)/u.test(base)) return true;
|
|
157
|
+
if (base.length > 22) return true;
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function sharesLongNumericToken(a, b) {
|
|
162
|
+
for (const token of a) if (b.has(token)) return true;
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 只读探索默认白名单:详情类入口与单据号行链接;保存/提交/审核等写操作不在其中。
|
|
167
|
+
const READONLY_CLICK_RE = /^(?:查看|详情|明细|记录|日志|展开|收起|预览|更多)/u;
|
|
168
|
+
const ROW_LINK_CLICK_RE = /^[A-Za-z]{1,6}\d{6,}$/;
|
|
169
|
+
|
|
170
|
+
/** 点击文本是否属于只读入口(查看/详情…或单据号行链接)。 */
|
|
171
|
+
export function isReadOnlyClickText(value) {
|
|
172
|
+
const text = String(value || '').replace(/\s+/g, ' ').trim();
|
|
173
|
+
if (!text) return false;
|
|
174
|
+
return READONLY_CLICK_RE.test(text) || ROW_LINK_CLICK_RE.test(text);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 解析 --click 步骤:css=/xpath= 前缀是选择器步骤,其余按可见文本点击。
|
|
179
|
+
* 选择器步骤在定位到元素后再按元素文本做只读校验。
|
|
180
|
+
*/
|
|
181
|
+
export function parseClickStep(value) {
|
|
182
|
+
const raw = String(value || '').trim();
|
|
183
|
+
if (!raw) return null;
|
|
184
|
+
if (/^(?:css|xpath)=/i.test(raw)) return { kind: 'selector', value: raw, selector: raw, label: '' };
|
|
185
|
+
return { kind: 'text', value: raw, text: raw, label: raw };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** 弹窗标题去掉实例后缀(— FP2026…)、动态计数括注与用例/单据引用,只留可复用页面名。 */
|
|
189
|
+
export function dialogPageTitle(value) {
|
|
190
|
+
let text = String(value || '').replace(/\s+/g, ' ').trim();
|
|
191
|
+
if (!text) return '';
|
|
192
|
+
text = text.replace(/\s*[—–-]\s*[A-Za-z]{1,6}\d{6,}.*$/u, '');
|
|
193
|
+
text = text.replace(/[((]\s*(?:共\s*)?\d+\s*(?:箱|条|项|个|行|页)?\s*[))]/gu, '');
|
|
194
|
+
text = text.replace(/[((][^()()]*\d{6,}[^()()]*[))]/gu, '');
|
|
195
|
+
text = stripInstanceRefs(text);
|
|
196
|
+
return text.replace(/[((]\s*[))]/gu, '').replace(/\s{2,}/g, ' ').trim();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** 弹窗页识别:新数据有 type=dialog,旧数据靠 id 后缀或标题里的「弹窗/对话框」。 */
|
|
200
|
+
export function isDialogPageRecord(page) {
|
|
201
|
+
return Boolean(
|
|
202
|
+
page?.type === 'dialog'
|
|
203
|
+
|| /(?:^|[-_:])(?:dialog|modal)(?:$|[-_:])/i.test(String(page?.id || ''))
|
|
204
|
+
|| /弹窗|对话框/.test(String(page?.title || '')),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** 登录页不是业务页面,不进入页面/权限覆盖统计。 */
|
|
209
|
+
export function isLoginPageRecord(page) {
|
|
210
|
+
const id = String(page?.id || '');
|
|
211
|
+
const title = String(page?.title || '');
|
|
212
|
+
const url = String(page?.url || '');
|
|
213
|
+
return /^login(?:$|[-_])/i.test(id) || /登录页/.test(title) || /\/login(?:[?#/]|$)/i.test(url);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** 弹窗的基础页:优先结构化字段,兼容旧数据的「基础页面:<id>」备注。 */
|
|
217
|
+
export function dialogBaseIdOf(page) {
|
|
218
|
+
if (page?.basePageId) return String(page.basePageId);
|
|
219
|
+
for (const note of page?.notes || []) {
|
|
220
|
+
const match = /^基础页面[::]\s*(.+)$/.exec(String(note));
|
|
221
|
+
if (match) return match[1].trim();
|
|
222
|
+
}
|
|
223
|
+
return '';
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function dialogTitleMatches(page, title) {
|
|
227
|
+
const key = normalizeKey(title);
|
|
228
|
+
if (!key || key.length < 2) return false;
|
|
229
|
+
const titles = [page?.title, ...(page?.aliases || [])].filter(Boolean).map((item) => normalizeKey(item));
|
|
230
|
+
return titles.some(
|
|
231
|
+
(item) => item === key || item.startsWith(`${key}弹窗`) || item.startsWith(`${key}(`) || item.startsWith(`${key}(`),
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 基础页 id 不一致时,用 URL 证明是同一基础页(运行观察与文档页可能用不同 id 形式)。 */
|
|
236
|
+
export function dialogBaseMatches(page, { pages = [], basePageId = '', url = '' } = {}) {
|
|
237
|
+
const candidateBaseId = dialogBaseIdOf(page);
|
|
238
|
+
if (!candidateBaseId) return true;
|
|
239
|
+
if (basePageId && candidateBaseId === basePageId) return true;
|
|
240
|
+
const base = pages.find((item) => String(item.id) === candidateBaseId);
|
|
241
|
+
const candidateKey = pageUrlKey(page?.url || base?.url || '');
|
|
242
|
+
const observedKey = pageUrlKey(url);
|
|
243
|
+
return Boolean(candidateKey) && candidateKey === observedKey;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 按「标题 + 基础页」找唯一已有弹窗页。弹窗与基础页共享 URL,
|
|
248
|
+
* 不能用 URL 直接认页;标题唯一且基础页对得上才认领,避免把不同页面的同名弹窗并掉。
|
|
249
|
+
*/
|
|
250
|
+
export function findDialogPageForLearn(pages = [], { title = '', basePageId = '', url = '' } = {}) {
|
|
251
|
+
const matches = (pages || []).filter(
|
|
252
|
+
(page) =>
|
|
253
|
+
isDialogPageRecord(page)
|
|
254
|
+
&& dialogTitleMatches(page, title)
|
|
255
|
+
&& dialogBaseMatches(page, { pages, basePageId, url }),
|
|
256
|
+
);
|
|
257
|
+
return matches.length === 1 ? matches[0] : null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const STUB_PAGE_TYPE_RE = /(列表页|列表|详情页|详情|页面|页|弹窗|对话框|表单|编辑|配置|设置|工作台|界面)/u;
|
|
261
|
+
const STUB_BASE_TYPE_RE = /(列表页|列表|详情页|详情|页面|页|弹窗|对话框|表单|编辑|配置|设置|工作台|界面)$/u;
|
|
262
|
+
|
|
263
|
+
function stubPageType(token) {
|
|
264
|
+
if (token === '列表页' || token === '列表') return '列表';
|
|
265
|
+
if (token === '详情页' || token === '详情') return '详情';
|
|
266
|
+
if (token === '页面' || token === '页') return '页面';
|
|
267
|
+
return token;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function trailingStubPageType(value) {
|
|
271
|
+
const match = STUB_BASE_TYPE_RE.exec(String(value || ''));
|
|
272
|
+
return match ? { token: match[1], type: stubPageType(match[1]) } : null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function lastStubPageType(value) {
|
|
276
|
+
const matches = [...String(value || '').matchAll(new RegExp(STUB_PAGE_TYPE_RE.source, 'gu'))];
|
|
277
|
+
const token = matches.at(-1)?.[1] || '';
|
|
278
|
+
return token ? { token, type: stubPageType(token) } : null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** 把重复/叠写的页面类型后缀折成一种:`列表页列表` → `列表`,`页面` → 去掉。 */
|
|
282
|
+
function foldStubPageTypes(value) {
|
|
283
|
+
let text = String(value || '');
|
|
284
|
+
text = text.replace(/(列表页|详情页)(?=(?:列表|详情)$)/u, (match) => (match === '列表页' ? '列表' : '详情'));
|
|
285
|
+
text = text.replace(/(列表|详情)\1+$/u, '$1');
|
|
286
|
+
const trailing = trailingStubPageType(text);
|
|
287
|
+
if (!trailing) return text;
|
|
288
|
+
if (trailing.type === '列表') return text.slice(0, -trailing.token.length) + '列表';
|
|
289
|
+
if (trailing.type === '详情') return text.slice(0, -trailing.token.length) + '详情';
|
|
290
|
+
if (trailing.type === '页面') return text.slice(0, -trailing.token.length);
|
|
291
|
+
return text;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 存根页标题归一化:去编号与布局说明,把「列表页/详情页」折成「列表/详情」。
|
|
296
|
+
* 文档里同一页面常同时写成「P1-服务定义列表页(列表页)」和「服务定义列表」,
|
|
297
|
+
* 只有两者都还没有 URL/结构时才可合并;括号里的类型说明参与区分,列表/详情不会互相折叠。
|
|
298
|
+
*/
|
|
299
|
+
export function stubPageTitleKey(value) {
|
|
300
|
+
let text = stripPageCodePrefix(value).replace(/\s+/g, ' ').trim();
|
|
301
|
+
if (!text) return '';
|
|
302
|
+
let parenthetical = '';
|
|
303
|
+
const trailing = /[((]\s*([^()()]*?)\s*[))]\s*$/u.exec(text);
|
|
304
|
+
if (trailing) {
|
|
305
|
+
parenthetical = trailing[1].trim();
|
|
306
|
+
text = text.slice(0, trailing.index).trim() || text;
|
|
307
|
+
}
|
|
308
|
+
const baseType = trailingStubPageType(text);
|
|
309
|
+
const parenType = parenthetical ? lastStubPageType(parenthetical) : null;
|
|
310
|
+
let extra = '';
|
|
311
|
+
if (parenType) {
|
|
312
|
+
if (!baseType) {
|
|
313
|
+
// 括号就是页面类型时补回类型;弹窗等保留完整说明,避免不同弹窗混在一起。
|
|
314
|
+
if (parenType.type === '列表' || parenType.type === '详情') extra = parenType.type;
|
|
315
|
+
else if (parenType.type !== '页面') extra = parenthetical;
|
|
316
|
+
} else if (parenType.type !== baseType.type) {
|
|
317
|
+
extra = parenthetical;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return normalizeKey(foldStubPageTypes(text + extra));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* 按标题/别名 + URL 共享长页面 ID 匹配唯一页面(同一页面经不同路由观察)。
|
|
325
|
+
* 标题相同但 ID 无交集、或候选不唯一时返回 null。
|
|
326
|
+
*/
|
|
327
|
+
export function findPageForTitleAndUrlToken(pages, title, url) {
|
|
328
|
+
const key = normalizeKey(stripPageCodePrefix(title));
|
|
329
|
+
if (!key || key.length < 3) return null;
|
|
330
|
+
const tokens = longNumericTokens(url);
|
|
331
|
+
if (!tokens.size) return null;
|
|
332
|
+
const candidates = [];
|
|
333
|
+
for (const page of Array.isArray(pages) ? pages : []) {
|
|
334
|
+
const names = [page.title, ...(Array.isArray(page.aliases) ? page.aliases : [])];
|
|
335
|
+
if (!names.some((value) => normalizeKey(stripPageCodePrefix(value)) === key)) continue;
|
|
336
|
+
if (!sharesLongNumericToken(tokens, longNumericTokens(page.url))) continue;
|
|
337
|
+
candidates.push(page);
|
|
338
|
+
}
|
|
339
|
+
return candidates.length === 1 ? candidates[0] : null;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** 页面/流程是否来自一次运行(运行目录、探测记录、用例编号前缀)。 */
|
|
343
|
+
export function looksLikeRunArtifact({ id = '', title = '' } = {}) {
|
|
344
|
+
const key = String(id || '');
|
|
345
|
+
const name = String(title || '');
|
|
346
|
+
if (/^(?:runs?[-/]|auto-tc-|agent-tc-|studio-tc-|tc-)/i.test(key)) return true;
|
|
347
|
+
if (/^runs?\//i.test(name)) return true;
|
|
348
|
+
if (/\bruns\/[A-Za-z0-9_.-]+/i.test(name)) return true;
|
|
349
|
+
if (/(探测[::]/.test(name) && isCaseReferenced(name)) return true;
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const STABLE_QUERY_NAMES = new Set([
|
|
354
|
+
'cusmenuid',
|
|
355
|
+
'menuid',
|
|
356
|
+
'pageid',
|
|
357
|
+
'urlpagetitle',
|
|
358
|
+
'pagecode',
|
|
359
|
+
'moduleid',
|
|
360
|
+
'appid',
|
|
361
|
+
]);
|
|
362
|
+
const CONTEXT_QUERY_NAMES = new Set(['opensource', 'referrer', 'entry', 'from']);
|
|
363
|
+
const INSTANCE_QUERY_NAME_RE =
|
|
364
|
+
/(?:^|_)(?:order|plan|case|bill|invoice|apply|task|shipment|receipt|payment|settle|contract|record|batch|run|job)(?:_|$)/i;
|
|
365
|
+
const INSTANCE_QUERY_SUFFIX_RE = /(?:code|no|id|uuid|key|token|time|date|sn|seq)$/i;
|
|
366
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
367
|
+
const BUSINESS_CODE_RE = /^(?:[A-Z]{2,}\d{6,}|[A-Z]+\d{6,})$/i;
|
|
368
|
+
|
|
369
|
+
function instanceQueryValue(value) {
|
|
370
|
+
const text = String(value || '').trim();
|
|
371
|
+
if (!text) return true;
|
|
372
|
+
if (isCaseReferenced(text)) return true;
|
|
373
|
+
if (UUID_RE.test(text)) return true;
|
|
374
|
+
if (/^\d{8,}$/.test(text)) return true;
|
|
375
|
+
return BUSINESS_CODE_RE.test(text);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function shouldDropQueryParam(name, value) {
|
|
379
|
+
const key = String(name || '').toLowerCase();
|
|
380
|
+
if (!key) return true;
|
|
381
|
+
if (STABLE_QUERY_NAMES.has(key)) return false;
|
|
382
|
+
if (CONTEXT_QUERY_NAMES.has(key)) return true;
|
|
383
|
+
if (String(value ?? '') === '') return true;
|
|
384
|
+
if (isCaseReferenced(value)) return true;
|
|
385
|
+
const instance = instanceQueryValue(value);
|
|
386
|
+
if (INSTANCE_QUERY_NAME_RE.test(key)) return instance;
|
|
387
|
+
return INSTANCE_QUERY_SUFFIX_RE.test(key) && instance;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function cleanPathname(pathname) {
|
|
391
|
+
return String(pathname || '')
|
|
392
|
+
.split('/')
|
|
393
|
+
.map((segment) => (isCaseReferenced(segment) || BUSINESS_CODE_RE.test(segment) ? ':code' : segment))
|
|
394
|
+
.join('/');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function cleanHash(hash) {
|
|
398
|
+
const raw = String(hash || '').replace(/^#/, '');
|
|
399
|
+
if (!raw) return '';
|
|
400
|
+
const [route, query = ''] = raw.split('?');
|
|
401
|
+
const params = new URLSearchParams(query);
|
|
402
|
+
for (const [name, value] of [...params.entries()]) {
|
|
403
|
+
if (shouldDropQueryParam(name, value)) params.delete(name);
|
|
404
|
+
}
|
|
405
|
+
const nextQuery = params.toString();
|
|
406
|
+
return '#' + cleanPathname(route) + (nextQuery ? '?' + nextQuery : '');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 正典页面 URL:保留稳定的页面/菜单标识,去掉一次运行或一张单据的实例参数。
|
|
411
|
+
* 这样同一页面的不同实例观察会合并,而不是各自生成一个“页面”。
|
|
412
|
+
*/
|
|
413
|
+
export function canonicalPageUrl(value) {
|
|
414
|
+
const raw = String(value || '').trim();
|
|
415
|
+
if (!raw) return '';
|
|
416
|
+
const hasOrigin = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw);
|
|
417
|
+
try {
|
|
418
|
+
const parsed = new URL(raw, 'http://local.invalid');
|
|
419
|
+
const params = new URLSearchParams(parsed.search);
|
|
420
|
+
for (const [name, value] of [...params.entries()]) {
|
|
421
|
+
if (shouldDropQueryParam(name, value)) params.delete(name);
|
|
422
|
+
}
|
|
423
|
+
const search = params.toString();
|
|
424
|
+
const pathname = cleanPathname(parsed.pathname).replace(/\/+$/, '') || '/';
|
|
425
|
+
const hash = cleanHash(parsed.hash);
|
|
426
|
+
const stableQuery = search ? '?' + search : '';
|
|
427
|
+
return hasOrigin ? parsed.origin + pathname + stableQuery + hash : pathname + stableQuery + hash;
|
|
428
|
+
} catch {
|
|
429
|
+
return raw
|
|
430
|
+
.replace(/([?&])([^=&#]+)=([^&#]*)/g, (match, prefix, name, value) =>
|
|
431
|
+
shouldDropQueryParam(name, value) ? '' : match,
|
|
432
|
+
)
|
|
433
|
+
.replace(/[?&]$/, '');
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** 页面去重键:忽略 host、标题参数与视图上下文,只保留路径和稳定查询参数。 */
|
|
438
|
+
export function pageUrlKey(value) {
|
|
439
|
+
const canonical = canonicalPageUrl(value);
|
|
440
|
+
if (!canonical) return '';
|
|
441
|
+
try {
|
|
442
|
+
const parsed = new URL(canonical, 'http://local.invalid');
|
|
443
|
+
for (const name of [...parsed.searchParams.keys()]) {
|
|
444
|
+
const key = name.toLowerCase();
|
|
445
|
+
if (key === 'urlpagetitle' || key === 'cusview' || key === 'viewmode' || key === 'viewtype' || /^appid_/.test(key)) {
|
|
446
|
+
parsed.searchParams.delete(name);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const search = parsed.searchParams.toString();
|
|
450
|
+
return (parsed.pathname.replace(/\/+$/, '') || '/') + (search ? '?' + search : '') + parsed.hash;
|
|
451
|
+
} catch {
|
|
452
|
+
return canonical;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** 页面标题是否只是 URL/path 的机械转写。 */
|
|
457
|
+
export function looksLikeUrlTitle(value) {
|
|
458
|
+
const text = String(value || '').trim();
|
|
459
|
+
if (!text) return true;
|
|
460
|
+
if (/^(?:https?:\/\/|\/)/i.test(text)) return true;
|
|
461
|
+
if (/^[a-z0-9_-]+-(?:view|viewport|workflow|page)-/i.test(text)) return true;
|
|
462
|
+
if (/^ebdapp-/i.test(text)) return true;
|
|
463
|
+
if (!/[一-鿿]/.test(text) && /\d{6,}/.test(text) && /^[a-z0-9_\-/.]+$/i.test(text)) return true;
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function decodeTitleParam(raw) {
|
|
468
|
+
const value = String(raw || '').trim().replace(/-/g, '+').replace(/_/g, '/');
|
|
469
|
+
if (!value) return '';
|
|
470
|
+
try {
|
|
471
|
+
const decoded = Buffer.from(value, 'base64').toString('utf8').replace(/\u0000/g, '').trim();
|
|
472
|
+
if (!decoded || decoded.length < 2 || decoded.length > 80) return '';
|
|
473
|
+
if (/[\u0000-\u001f]/.test(decoded)) return '';
|
|
474
|
+
if (!/[一-鿿A-Za-z]/.test(decoded)) return '';
|
|
475
|
+
if (looksLikeUrlTitle(decoded)) return '';
|
|
476
|
+
return decoded.slice(0, 80);
|
|
477
|
+
} catch {
|
|
478
|
+
return '';
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** 从 urlPageTitle 等 base64 参数还原人类可读标题;取不到返回空串。 */
|
|
483
|
+
export function pageTitleFromUrl(value) {
|
|
484
|
+
const raw = String(value || '').trim();
|
|
485
|
+
if (!raw) return '';
|
|
486
|
+
try {
|
|
487
|
+
const parsed = new URL(raw, 'http://local.invalid');
|
|
488
|
+
for (const name of ['urlPageTitle', 'pageTitle']) {
|
|
489
|
+
const title = decodeTitleParam(parsed.searchParams.get(name));
|
|
490
|
+
if (title) return title;
|
|
491
|
+
}
|
|
492
|
+
} catch {
|
|
493
|
+
/* 非法 URL 不还原标题 */
|
|
494
|
+
}
|
|
495
|
+
return '';
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** 去掉页面/文档编号前缀(如 `QM-P001-报价单列表`、`P1-服务定义列表`、`PS-P001 应付计费单`、`p-bc-02--详情`),保留业务名称。 */
|
|
499
|
+
export function stripPageCodePrefix(value) {
|
|
500
|
+
return String(value || '')
|
|
501
|
+
.replace(
|
|
502
|
+
/^(?:[A-Z]{1,4}(?:\d{1,3}[a-z]?|(?:-[A-Za-z0-9]+)+)(?:\s*[-—]{1,2}\s*|\s+|(?=[一-鿿]))|[A-Za-z]{1,4}(?:-[A-Za-z0-9]+)+(?:\s*[-—]{1,2}\s*|(?=[一-鿿])))/,
|
|
503
|
+
'',
|
|
504
|
+
)
|
|
505
|
+
.trim();
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** 去掉实例引用并压缩空白;返回空串表示该值已没有可复用内容。 */
|
|
509
|
+
export function cleanCanonicalText(value) {
|
|
510
|
+
const text = String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
511
|
+
if (!text) return '';
|
|
512
|
+
const cleaned = isCaseReferenced(text) ? stripInstanceRefs(text) : text;
|
|
513
|
+
return cleaned
|
|
514
|
+
.replace(/\s{2,}/g, ' ')
|
|
515
|
+
.replace(/^[\s,,、;;::|]+|[\s,,、;;::|]+$/g, '')
|
|
516
|
+
.trim();
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** 文档章节标题被误当成页面/流程名:冒号结尾、编号开头、通用章节名。 */
|
|
520
|
+
export function looksLikeHeadingNoise(name) {
|
|
521
|
+
const value = String(name || '').trim();
|
|
522
|
+
if (!value) return true;
|
|
523
|
+
if (/[::]\s*$/.test(value)) return true;
|
|
524
|
+
if (/^\d+(?:\.\d+)*[\s、..]/.test(value)) return true;
|
|
525
|
+
if (/^[一二三四五六七八九十百]+[、..]\s*/.test(value)) return true;
|
|
526
|
+
if (/^第[一二三四五六七八九十百]+[章节部分]/.test(value)) return true;
|
|
527
|
+
return GENERIC_SECTION_RE.test(value.replace(/[::]\s*$/, '').trim());
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* 文档章节式“流程”名(如「XX PRD 流程 6」「二、背景与目标」「cases-dump 流程 1」)。
|
|
532
|
+
* 这些名字来自标题切分,不是可复用的业务动作;真正的流程名应描述业务目标。
|
|
533
|
+
*/
|
|
534
|
+
export function looksLikeProcessHeading(name) {
|
|
535
|
+
const value = String(name || '').trim();
|
|
536
|
+
if (!value) return true;
|
|
537
|
+
if (/^cases?-dump\b/i.test(value)) return true;
|
|
538
|
+
if (/^PRD模板|(?:^|[-—\s])模板(?:$|[-—\s])/i.test(value)) return true;
|
|
539
|
+
if (/(?:进度日志|执行记录|测试记录|过程日志|测试报告|复盘|迁移状态|造数状态)/.test(value)) return true;
|
|
540
|
+
const base = value
|
|
541
|
+
.replace(/[((][^()()]*[))]\s*$/, '')
|
|
542
|
+
.replace(/\s*流程\s*\d+\s*$/i, '')
|
|
543
|
+
.trim();
|
|
544
|
+
if (looksLikeHeadingNoise(value) || looksLikeHeadingNoise(base)) return true;
|
|
545
|
+
if (/^(?:[a-z0-9_-]+\s+)?流程\s*\d+$/i.test(value)) return true;
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** 步骤更像规则陈述(应/需/默认/支持…),而不是要执行的动作。 */
|
|
550
|
+
export function looksLikeRule(text) {
|
|
551
|
+
return RULE_SIGNAL_RE.test(String(text || ''));
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** 步骤描述了一次界面操作,可以被复跑。 */
|
|
555
|
+
export function looksLikeActionStep(text) {
|
|
556
|
+
const value = String(text || '').trim();
|
|
557
|
+
return ACTION_VERB_RE.test(value) || UI_ACTION_RE.test(value);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** 句子更像一次执行记录(日期、测试结果、实际/预期),而不是系统规则。 */
|
|
561
|
+
export function looksLikeEvidenceStatement(text) {
|
|
562
|
+
return EVIDENCE_STATEMENT_RE.test(String(text || '').trim());
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* 执行经验的 kind 集合。生产方(批次沉淀、合并清洗)与消费方(中心同步、运行查询)
|
|
567
|
+
* 必须共用这一份,否则部分证据会既不同步也查不到。
|
|
568
|
+
*/
|
|
569
|
+
export const EXPERIENCE_KINDS = Object.freeze([
|
|
570
|
+
'case-process',
|
|
571
|
+
'case-experience',
|
|
572
|
+
'process-experience',
|
|
573
|
+
'page-note',
|
|
574
|
+
'page-feedback',
|
|
575
|
+
'page-observation',
|
|
576
|
+
]);
|
|
577
|
+
|
|
578
|
+
export function isExperienceKind(kind) {
|
|
579
|
+
return EXPERIENCE_KINDS.includes(String(kind || ''));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const SYSTEM_LABEL_NOISE_RE =
|
|
583
|
+
/^(?:前置|前置条件|预期|预期结果|实际结果|备注|说明|注|步骤|操作|结果|状态|字段|权限|角色|序号|编号|名称|描述|类型|是否|必填|来源|文档|测试|验证|用例|场景|页面|按钮|菜单|功能|模块|其他|无)$/;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* 系统维度(角色/术语)的噪声判定:章节词、表格表头、带实例引用或标点的长句
|
|
587
|
+
* 都不是可复用的系统事实。
|
|
588
|
+
*/
|
|
589
|
+
export function looksLikeSystemLabel(value, { max = 24 } = {}) {
|
|
590
|
+
const text = String(value || '').replace(/\s+/g, ' ').trim();
|
|
591
|
+
if (!text || text.length > max) return true;
|
|
592
|
+
if (SYSTEM_LABEL_NOISE_RE.test(text)) return true;
|
|
593
|
+
if (/[,,;;::|、<>]/.test(text)) return true;
|
|
594
|
+
if (/^(?:见图|如下|其中|包括|例如)/.test(text)) return true;
|
|
595
|
+
return isCaseReferenced(text);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// 文档抽取片段(「分两类」「取值构成」「同步范围」「待确认项收口」)没有角色后缀,
|
|
599
|
+
// 用「噪声开头 + 噪声结尾」双条件识别;单独的首字/尾字会误杀「值班经理」「项目经理」。
|
|
600
|
+
const ROLE_NAME_NOISE_HEAD_RE = /^(?:分|取|确|同|待|选|时|类|值|项)/u;
|
|
601
|
+
const ROLE_NAME_NOISE_TAIL_RE = /(?:类|构成|范围|收口|项)$/u;
|
|
602
|
+
const ROLE_NAME_NOISE_EXACT = new Set(['确定', '确认', '无', '暂无', '其他']);
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* 规范化角色名:去掉中文名后的英文别名与模块编号,丢弃「分两类」「确定」这类文档片段。
|
|
606
|
+
* 返回空串表示不是可复用角色。
|
|
607
|
+
*/
|
|
608
|
+
export function cleanRoleName(value) {
|
|
609
|
+
let text = String(value ?? '').replace(/\s+/g, ' ').trim();
|
|
610
|
+
if (!text) return '';
|
|
611
|
+
// 引用块/表头残留(「> 注」「> 查询入口相同」)不是角色。
|
|
612
|
+
if (/[>《》<>]/u.test(text)) return '';
|
|
613
|
+
// 「销售主体 saleEntity」这类中文名后跟英文别名,保留中文名。
|
|
614
|
+
text = text.replace(/\s+[A-Za-z][A-Za-z0-9_./-]*$/u, '').trim();
|
|
615
|
+
if (!text) return '';
|
|
616
|
+
if (/[A-Za-z0-9]/.test(text) && !/^OMS\s*[一-鿿/]+$/u.test(text)) return '';
|
|
617
|
+
// 中文角色名里残余空格多半是权限表片段(「业务线 用户只」);「OMS 采购」这类系统角色名除外。
|
|
618
|
+
if (/\s/u.test(text) && !/^OMS\s*[一-鿿/]+$/u.test(text)) return '';
|
|
619
|
+
if (/[,。;、:,;:]/u.test(text)) return '';
|
|
620
|
+
const length = [...text].length;
|
|
621
|
+
if (length < 2 || length > 12) return '';
|
|
622
|
+
if (ROLE_NAME_NOISE_EXACT.has(text)) return '';
|
|
623
|
+
if (length <= 6 && ROLE_NAME_NOISE_HEAD_RE.test(text) && ROLE_NAME_NOISE_TAIL_RE.test(text)) return '';
|
|
624
|
+
return text;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const DOC_KIND_SIGNALS = {
|
|
628
|
+
'test-report':
|
|
629
|
+
/测试执行|测试报告|执行报告|测试记录|回归|问题分析|过程日志|重跑说明|缺陷|复盘|测试过程|校验报告|迁移报告|相似度分析|分析报告|问题与阻塞|阻塞说明|验收报告|测试总结|测试方案|测试用例设计|用例设计|用例导出|cases?[-_ ]?dump/,
|
|
630
|
+
notes: /会议纪要|会议记录|讨论记录|周报|日报|排期/,
|
|
631
|
+
reference: /术语|名词|主数据|枚举|字典/,
|
|
632
|
+
prd: /\bPRD\b|需求|设计|方案|规格|产品|原型|功能说明|详细设计|概要设计|操作手册|用户手册|使用说明|指南/i,
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* 文档类型决定它能否喂养正典知识:
|
|
637
|
+
* 测试报告、过程日志、会议纪要都是证据;设计/手册/术语表才是正典来源。
|
|
638
|
+
*/
|
|
639
|
+
export function classifyDocumentKind({ title = '', content = '' } = {}) {
|
|
640
|
+
const name = String(title || '');
|
|
641
|
+
const body = String(content || '').slice(0, 6000);
|
|
642
|
+
if (DOC_KIND_SIGNALS['test-report'].test(name)) return 'test-report';
|
|
643
|
+
if (DOC_KIND_SIGNALS.notes.test(name)) return 'notes';
|
|
644
|
+
if (DOC_KIND_SIGNALS.reference.test(name)) return 'reference';
|
|
645
|
+
if (DOC_KIND_SIGNALS.prd.test(name)) return 'prd';
|
|
646
|
+
const head = body.slice(0, 1500);
|
|
647
|
+
if (DOC_KIND_SIGNALS['test-report'].test(head)) return 'test-report';
|
|
648
|
+
if (DOC_KIND_SIGNALS.reference.test(head)) return 'reference';
|
|
649
|
+
if (/(?:操作步骤|使用指南|操作手册)/.test(head)) return 'manual';
|
|
650
|
+
if (/(?:功能需求|需求说明|页面原型|字段说明|状态流转)/.test(head)) return 'prd';
|
|
651
|
+
return 'other';
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export function isLearnableDocument(kind) {
|
|
655
|
+
// 只有明确的执行证据(测试报告、会议纪要)被挡在正典之外;无法分类的文档按设计资料处理。
|
|
656
|
+
return !isEvidenceDocument(kind);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export function isEvidenceDocument(kind) {
|
|
660
|
+
return ['test-report', 'notes'].includes(String(kind || ''));
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/** 从 `doc-<slug>-process-N` / `doc-<slug>-rules-N` 取回文档 slug。 */
|
|
664
|
+
export function documentSlugFromKnowledgeId(id) {
|
|
665
|
+
const match = /^doc-(.+?)-(?:rules|process)-\d+$/.exec(String(id || ''));
|
|
666
|
+
return match ? match[1] : '';
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** 知识条目 notes 里的「来源文档:X」。 */
|
|
670
|
+
export function sourceDocumentTitles(record) {
|
|
671
|
+
const notes = Array.isArray(record?.notes) ? record.notes : record?.notes ? [record.notes] : [];
|
|
672
|
+
const titles = [];
|
|
673
|
+
for (const note of notes) {
|
|
674
|
+
const match = /^来源文档[::]\s*(.+)$/.exec(String(note).trim());
|
|
675
|
+
if (match) titles.push(match[1].trim());
|
|
676
|
+
}
|
|
677
|
+
return [...new Set(titles)];
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* 学习事件的持久化去重键,与 knowledge.appendLearning 的写入规则一致。
|
|
682
|
+
* 空串表示这条事件没有可跨次重放的身份,不能参与去重。
|
|
683
|
+
*/
|
|
684
|
+
export function learningDedupeKey(learning = {}) {
|
|
685
|
+
if (learning?.dedupeKey) return String(learning.dedupeKey);
|
|
686
|
+
if (!learning?.kind || !learning?.runDir) return '';
|
|
687
|
+
const stepId = learning?.detail?.stepId ? String(learning.detail.stepId) : '';
|
|
688
|
+
return [learning.kind, learning.runDir, stepId].filter(Boolean).join('|');
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* 学习事件的报告身份:优先持久化去重键,其次 run 内事件,最后按页面与时间。
|
|
693
|
+
* 与体检脚本的重复统计共用,避免两边对「同一条证据」判断不一致。
|
|
694
|
+
*/
|
|
695
|
+
export function learningIdentity(learning = {}) {
|
|
696
|
+
const sticky = learningDedupeKey(learning);
|
|
697
|
+
if (sticky) return sticky;
|
|
698
|
+
return [learning?.kind, learning?.pageId, learning?.at].filter(Boolean).join('|')
|
|
699
|
+
|| String(learning?.id || '');
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* 证据学习去重:同一 run 的同一步骤被重复 learn 时只保留最新一条。
|
|
704
|
+
* 旧库里的重复事件没有 dedupeKey,后续 appendLearning 无法命中;这里补写,
|
|
705
|
+
* 让下一次重放同样幂等。返回的记录保持原有时间顺序。
|
|
706
|
+
*/
|
|
707
|
+
export function compactLearnings(learnings = []) {
|
|
708
|
+
const list = Array.isArray(learnings) ? learnings : [];
|
|
709
|
+
const latest = new Map();
|
|
710
|
+
list.forEach((record, index) => {
|
|
711
|
+
const identity = learningIdentity(record);
|
|
712
|
+
if (!identity) return;
|
|
713
|
+
const previous = latest.get(identity);
|
|
714
|
+
if (previous === undefined) {
|
|
715
|
+
latest.set(identity, index);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
const previousAt = String(list[previous]?.at || '');
|
|
719
|
+
const candidateAt = String(record?.at || '');
|
|
720
|
+
if (!previousAt || (candidateAt && candidateAt >= previousAt)) latest.set(identity, index);
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
const records = [];
|
|
724
|
+
let duplicates = 0;
|
|
725
|
+
let keyed = 0;
|
|
726
|
+
list.forEach((record, index) => {
|
|
727
|
+
const identity = learningIdentity(record);
|
|
728
|
+
if (!identity) {
|
|
729
|
+
records.push(record);
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
if (latest.get(identity) !== index) {
|
|
733
|
+
duplicates += 1;
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
const dedupeKey = learningDedupeKey(record);
|
|
737
|
+
if (dedupeKey && record?.dedupeKey !== dedupeKey) {
|
|
738
|
+
records.push({ ...record, dedupeKey });
|
|
739
|
+
keyed += 1;
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
records.push(record);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
return {
|
|
746
|
+
records,
|
|
747
|
+
stats: { before: list.length, after: records.length, duplicates, keyed },
|
|
748
|
+
};
|
|
749
|
+
}
|