dsh-uitest 2.1.3 → 2.2.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.
@@ -21,7 +21,32 @@
21
21
 
22
22
  `cases` 的 JSON 输出里有 `sheets` 数组,可用于确认实际表名。
23
23
 
24
- ### 1.2 主表列(M006 实测,11 列)
24
+ ### 1.2 主表列:两种实际列结构
25
+
26
+ 解析器按**表头名**映射列,不依赖列位置;下面两种是实际遇到的形态,列顺序可以不同。
27
+
28
+ #### 1.2.1 OMS 二期风格(12 列,**导出模板以此为准**)
29
+
30
+ `OMS二期订单管理模块测试用例.xlsx` 的「测试用例」表:表头 1 行 + 用例 311 行,列 A–L。
31
+
32
+ | 列 | 表头 | 映射字段 |
33
+ | --- | --- | --- |
34
+ | A | 编号 | `seq` |
35
+ | B | 优先级 | `priority` |
36
+ | C | 模块 | `module` |
37
+ | D | 一级功能 | `l1` |
38
+ | E | 二级功能 | `l2` |
39
+ | F | 测试类型 | `type` |
40
+ | G | 测试内容 | `functionPoint`(用例名称) |
41
+ | H | 前提条件 | `precondition` |
42
+ | I | 测试步骤 | `steps` |
43
+ | J | 预期结果 | `expected` |
44
+ | K | 实际结果 | `testResult` |
45
+ | L | 备注 | `remark` |
46
+
47
+ 导出(`studio` 的用例/结果 xlsx)沿用这套列,并在末尾追加 `是否可自动化`、`用例编号`,结果表再追加 `执行批次`、`耗时`、`执行说明`。因此**导出的用例表可以直接再导入**,内容摘要不变。
48
+
49
+ #### 1.2.2 M006 风格(11 列)
25
50
 
26
51
  `PRD/履约管理/M006履约管理模块-测试用例.xlsx` 的「履约管理」表:表头 1 行 + 用例 249 行,列 A–K。
27
52
 
@@ -44,6 +69,7 @@
44
69
  1. **E 列是合并单元格**:`E2:E29`、`E30:E47`… 共 15 个合并区,只有左上角有值。解析时引擎会先把合并区向下填充(`fillMergedCells`),所以 `cases[].l2` 能取到分组名;如果直接读原始 XML 会得到大量空值。
45
70
  2. **主表没有独立 TC 编号列**:TC 编号在 K 列备注第一段(如 `TC-FP001-01;功能-正向`)。配套的「上下游影响」表虽有 `用例编号` 列且与主表逐行对应,但它不是主表列,不参与主表解析。
46
71
  3. **表头行不写死在第 1 行**:引擎在前 10 行内找「命中列最多且包含测试功能点/序号/用例编号」的行作为表头,因此带标题行、说明行的其他模块工作簿也能解析。
72
+ 4. **「测试功能点」不是必须列**:没有该列(或 `测试内容`/`用例名称` 等别名)时,用「一级功能/二级功能」拼出功能点(如 `选择报价单/列表展示`);两者都没有才报「表头缺失」。OMS 二期表里的 `测试内容` 是长句用例描述,导入后就是 `functionPoint`。
47
73
 
48
74
  补充:工作簿无 `sharedStrings.xml`,字符串以 `inlineStr` 存储;J/K 两列部分单元格为 `t="str"`(生成后二次写入),两种读法一致。无公式、无批注。
49
75
 
@@ -251,16 +277,16 @@ node bin/uitest.mjs result add \
251
277
  - 模块:模块 / 所属模块 / 业务模块
252
278
  - 一级功能:一级功能 / 场景 / 一级模块 / 功能模块
253
279
  - 二级功能:二级功能 / 子功能 / 功能点分组
254
- - 测试功能点:测试功能点 / 用例名称 / 测试点 / 用例标题 / 标题 / 测试功能
280
+ - 测试功能点(用例名称):测试功能点 / 用例名称 / 测试点 / 用例标题 / 标题 / 测试功能 / 测试内容 / 用例描述 / 测试描述
255
281
  - 前提条件:前提条件 / 前置条件 / 预置条件
256
- - 操作步骤:操作步骤 / 执行步骤 / 步骤
282
+ - 操作步骤:操作步骤 / 执行步骤 / 步骤 / 测试步骤
257
283
  - 预期结果:预期结果 / 期望结果 / 预期
258
- - 测试结果:测试结果 / 执行结果 / 结果
284
+ - 测试结果:测试结果 / 执行结果 / 结果 / 实际结果
259
285
  - 备注:备注 / 说明 / 备注说明
260
- - 可自动化:可自动化 / 自动化分类 / 自动化等级 / 自动化
261
- - 用例类型:用例类型 / 类型
286
+ - 可自动化:可自动化 / 是否可自动化 / 自动化分类 / 自动化等级 / 自动化
287
+ - 用例类型:用例类型 / 类型 / 测试类型
262
288
  - 页面:页面 / 关联页面 / 所在页面
263
- 2. **必须有「测试功能点」列**(或别名);否则报「表头缺失」并列出实际表头。序号列可缺省。
289
+ 2. **功能点列不是必需的**:「测试功能点/测试内容/用例名称」任一别名存在即可;都没有时退回「一级功能/二级功能」。两者都缺失才报「表头缺失」并列出实际表头。序号列可缺省。
264
290
  3. **合并单元格按左上角值向下填充**;前提是合并区信息存在(xlsx 内建),无需人工拆表。
265
291
  4. **多工作表**:一次只解析一张;工作簿里其他表当作说明材料,不影响用例数。
266
292
  5. **历史报告/CSV 兼容**:`report` 生成的 `用例执行结果明细.csv` 表头为
@@ -0,0 +1,262 @@
1
+ // 文档对象策略层:归属视图、来源/用例文件状态、分组与回写目标。
2
+ // 文档身份存 docs.json;用例是否存在仍以用例库为准,caseIds 只是拥有关系账本。
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ import { normalizeDocumentRecord } from '../lib/cases-import.mjs';
7
+ import { UitestError, formatDate, normalizeDocKey, nowIso, slug } from '../lib/util.mjs';
8
+ import { readDocs, updateDocs } from './store.mjs';
9
+
10
+ function asArray(value) {
11
+ return Array.isArray(value) ? value : [];
12
+ }
13
+
14
+ function caseDocId(caseItem) {
15
+ return String(caseItem?.docId || caseItem?.source?.docId || '');
16
+ }
17
+
18
+ function caseIdOf(caseItem) {
19
+ return String(caseItem?.tcId || caseItem?.id || '');
20
+ }
21
+
22
+ function caseKey(value) {
23
+ return String(value || '').toLowerCase();
24
+ }
25
+
26
+ export function documentRegistry(config) {
27
+ const store = readDocs(config);
28
+ return {
29
+ version: Number(store.version) || 1,
30
+ updatedAt: store.updatedAt || '',
31
+ docs: asArray(store.docs).map(normalizeDocumentRecord),
32
+ };
33
+ }
34
+
35
+ export function findDocument(config, { docId = '', docKey = '', sourcePath = '' } = {}) {
36
+ const { docs } = documentRegistry(config);
37
+ if (docId) return docs.find((doc) => doc.id === String(docId)) || null;
38
+ const key = normalizeDocKey(docKey);
39
+ if (key) {
40
+ const hit = docs.find((doc) => doc.docKey === key || normalizeDocKey(doc.name) === key);
41
+ if (hit) return hit;
42
+ }
43
+ if (sourcePath) {
44
+ const abs = path.resolve(config.projectDir, String(sourcePath));
45
+ return docs.find((doc) => [doc.sourcePath, doc.generatedPath]
46
+ .filter(Boolean)
47
+ .some((value) => path.resolve(config.projectDir, value) === abs)) || null;
48
+ }
49
+ return null;
50
+ }
51
+
52
+ /**
53
+ * 按 id → docKey → sourcePath 的顺序 upsert 一条文档记录,并去重。
54
+ * 命中旧记录时保留它的 id,改名不会换身份。
55
+ * reconcile 在锁内拿到磁盘上的旧记录,供调用方决定哪些字段以磁盘为准。
56
+ */
57
+ export function saveDocumentRecord(config, record, { reconcile = null } = {}) {
58
+ const input = normalizeDocumentRecord(record);
59
+ return updateDocs(config, (store) => {
60
+ const docs = asArray(store.docs).map(normalizeDocumentRecord);
61
+ const byId = docs.find((doc) => doc.id === input.id) || null;
62
+ const byKey = input.docKey ? docs.find((doc) => doc.docKey === input.docKey) || null : null;
63
+ const byPath = input.sourcePath
64
+ ? docs.find((doc) => doc.sourcePath && path.resolve(doc.sourcePath) === path.resolve(input.sourcePath)) || null
65
+ : null;
66
+ const existing = byId || byKey || byPath;
67
+ const base = reconcile ? reconcile(existing, input) : { ...(existing || {}), ...input };
68
+ const saved = normalizeDocumentRecord({
69
+ ...base,
70
+ id: existing?.id || input.id,
71
+ importedAt: existing?.importedAt || input.importedAt || nowIso(),
72
+ updatedAt: nowIso(),
73
+ });
74
+ store.docs = [saved, ...docs.filter((doc) => {
75
+ if (doc.id === saved.id) return false;
76
+ if (saved.docKey && doc.docKey === saved.docKey) return false;
77
+ if (saved.sourcePath && doc.sourcePath && path.resolve(doc.sourcePath) === path.resolve(saved.sourcePath)) return false;
78
+ return true;
79
+ })];
80
+ return saved;
81
+ });
82
+ }
83
+
84
+ export function documentSourceState(doc) {
85
+ const sourcePath = String(doc?.sourcePath || '');
86
+ if (!sourcePath) return 'missing';
87
+ try {
88
+ return fs.existsSync(sourcePath) && fs.statSync(sourcePath).isFile() ? 'ready' : 'missing';
89
+ } catch {
90
+ return 'missing';
91
+ }
92
+ }
93
+
94
+ export function documentWritebackPath(config, doc, date = formatDate(new Date())) {
95
+ const dir = path.join(config.paths.uitestDir, 'studio', 'writeback', doc.id);
96
+ const name = slug(doc.name || doc.id, 60) + '-执行结果-' + String(date || '').replace(/-/g, '') + '.xlsx';
97
+ return path.join(dir, name);
98
+ }
99
+
100
+ export function documentCaseFile(config, doc) {
101
+ if (!doc) return '';
102
+ if (doc.kind === 'xlsx') {
103
+ return doc.writeback?.targetPath || documentWritebackPath(config, doc);
104
+ }
105
+ return doc.generatedPath || '';
106
+ }
107
+
108
+ export function documentCaseFileState(config, doc) {
109
+ if (!doc) return 'missing';
110
+ if (doc.kind === 'xlsx') {
111
+ if (!doc.writeback?.targetPath) return 'pending';
112
+ return fs.existsSync(doc.writeback.targetPath) ? 'ready' : 'missing';
113
+ }
114
+ const file = documentCaseFile(config, doc);
115
+ if (!file) return 'missing';
116
+ const abs = path.isAbsolute(file) ? file : path.resolve(config.projectDir, file);
117
+ try {
118
+ return fs.existsSync(abs) && fs.statSync(abs).isFile() ? 'ready' : 'missing';
119
+ } catch {
120
+ return 'missing';
121
+ }
122
+ }
123
+
124
+ export function documentCounts(doc, cases, { deletedCaseIds = [] } = {}) {
125
+ const linked = asArray(cases).filter((item) => caseDocId(item) === doc.id);
126
+ const visible = new Set(linked.map((item) => caseKey(caseIdOf(item))));
127
+ const deleted = new Set(asArray(deletedCaseIds).map(caseKey));
128
+ let tombstoned = 0;
129
+ let stale = 0;
130
+ for (const id of doc.caseIds || []) {
131
+ const key = caseKey(id);
132
+ if (!key || visible.has(key)) continue;
133
+ if (deleted.has(key)) tombstoned += 1;
134
+ else stale += 1;
135
+ }
136
+ return {
137
+ visibleCount: linked.length,
138
+ tombstonedCount: tombstoned,
139
+ staleCount: stale,
140
+ ownedCount: linked.length + tombstoned,
141
+ cases: linked,
142
+ };
143
+ }
144
+
145
+ function statusCountsOf(cases) {
146
+ const counts = { total: cases.length, passed: 0, partial: 0, failed: 0, blocked: 0, untested: 0, running: 0 };
147
+ for (const item of cases) {
148
+ const key = Object.hasOwn(counts, item?.status) && item.status !== 'total' ? item.status : 'untested';
149
+ counts[key] += 1;
150
+ }
151
+ return counts;
152
+ }
153
+
154
+ function lastRunOf(cases) {
155
+ let last = null;
156
+ for (const item of cases) {
157
+ const run = item?.lastRun;
158
+ if (!run) continue;
159
+ if (!last || String(run.at || '') > String(last.at || '')) {
160
+ last = {
161
+ caseId: caseIdOf(item),
162
+ status: run.status || '',
163
+ at: run.at || '',
164
+ batchId: run.batchId || '',
165
+ };
166
+ }
167
+ }
168
+ return last;
169
+ }
170
+
171
+ export function documentView(config, doc, cases, { deletedCaseIds = [] } = {}) {
172
+ const record = normalizeDocumentRecord(doc);
173
+ const counts = documentCounts(record, cases, { deletedCaseIds });
174
+ return {
175
+ id: record.id,
176
+ docKey: record.docKey,
177
+ name: record.name,
178
+ kind: record.kind,
179
+ sourcePath: record.sourcePath,
180
+ generatedPath: record.generatedPath,
181
+ caseFile: documentCaseFile(config, record),
182
+ sourceState: documentSourceState(record),
183
+ caseFileState: documentCaseFileState(config, record),
184
+ visibleCount: counts.visibleCount,
185
+ ownedCount: counts.ownedCount,
186
+ tombstonedCount: counts.tombstonedCount,
187
+ staleCount: counts.staleCount,
188
+ version: record.version,
189
+ mode: record.mode,
190
+ importedAt: record.importedAt,
191
+ updatedAt: record.updatedAt,
192
+ lastRead: record.lastRead,
193
+ writeback: record.writeback,
194
+ diff: record.diff,
195
+ statusCounts: statusCountsOf(counts.cases),
196
+ lastRun: lastRunOf(counts.cases),
197
+ };
198
+ }
199
+
200
+ export function groupCasesByDocument(docs, cases) {
201
+ const groups = asArray(docs).map((doc) => {
202
+ const record = normalizeDocumentRecord(doc);
203
+ return { doc: record, cases: [] };
204
+ });
205
+ const byId = new Map(groups.map((group) => [group.doc.id, group]));
206
+ const unassigned = [];
207
+ for (const item of asArray(cases)) {
208
+ const group = byId.get(caseDocId(item));
209
+ if (group) group.cases.push(item);
210
+ else unassigned.push(item);
211
+ }
212
+ return { groups, unassigned };
213
+ }
214
+
215
+ export function documentWriteTarget(config, doc, date = formatDate(new Date())) {
216
+ if (!doc) return { kind: 'none', reason: 'DOC_NOT_FOUND' };
217
+ if (doc.kind === 'markdown' || doc.kind === 'json') {
218
+ const file = doc.generatedPath || '';
219
+ if (!file) return { kind: 'none', path: '', reason: 'DOC_CASE_FILE_MISSING' };
220
+ return { kind: doc.kind, path: file, sourcePath: doc.sourcePath || '', sourceState: documentSourceState(doc) };
221
+ }
222
+ if (doc.kind === 'xlsx') {
223
+ const target = documentWritebackPath(config, doc, date);
224
+ const sourceState = documentSourceState(doc);
225
+ return {
226
+ kind: 'xlsx',
227
+ path: target,
228
+ sourcePath: doc.sourcePath || '',
229
+ sourceState,
230
+ reason: sourceState === 'ready' ? '' : 'DOC_SOURCE_MISSING',
231
+ };
232
+ }
233
+ return { kind: 'none', path: '', reason: 'DOC_KIND_UNSUPPORTED' };
234
+ }
235
+
236
+ /** 锁内按 id 修改单条文档记录;回调拿到的是磁盘上的最新记录。 */
237
+ export function updateDocumentRecord(config, docId, mutate) {
238
+ const id = String(docId || '');
239
+ return updateDocs(config, (store) => {
240
+ const docs = asArray(store.docs).map(normalizeDocumentRecord);
241
+ const index = docs.findIndex((doc) => doc.id === id);
242
+ if (index < 0) throw new UitestError('文档不存在:' + id, { code: 'DOC_NOT_FOUND', detail: { docId: id } });
243
+ const current = { ...docs[index] };
244
+ const next = mutate(current) || current;
245
+ const saved = normalizeDocumentRecord({ ...next, id: docs[index].id, updatedAt: nowIso() });
246
+ docs[index] = saved;
247
+ store.docs = docs;
248
+ return saved;
249
+ });
250
+ }
251
+
252
+ /**
253
+ * 回写只能做锁内读改写。调用方手里的文档快照可能已经落后于并发的
254
+ * 重新导读/导入,整条覆盖会回滚 version、lastRead 与 caseIds。
255
+ */
256
+ export function recordDocumentWriteback(config, doc, summary) {
257
+ const docId = typeof doc === 'string' ? doc : doc?.id;
258
+ return updateDocumentRecord(config, docId, (current) => ({
259
+ ...current,
260
+ writeback: { ...summary, at: summary?.at || nowIso() },
261
+ }));
262
+ }
package/studio/export.mjs CHANGED
@@ -1,4 +1,5 @@
1
- // 用例/测试结果 xlsx 导出:列结构与 M006 用例模板一致,并用「用例编号」列保证再次导入时编号稳定。
1
+ // 用例/测试结果 xlsx 导出:列结构以 OMS二期订单用例表为参考(编号/模块/一级功能/二级功能/
2
+ // 测试类型/测试内容/前提条件/测试步骤/预期结果/实际结果/备注),并用「用例编号」列保证再次导入时编号稳定。
2
3
  // 只读用例库与结果库;写文件前用临时文件再原子替换。
3
4
  import fs from 'node:fs';
4
5
  import path from 'node:path';
@@ -10,9 +11,9 @@ import { latestByCase, readResults } from '../lib/results.mjs';
10
11
  import { ensureDir, formatDuration, nowIso, slug, timeStamp } from '../lib/util.mjs';
11
12
  import { mergeBatchRuns, readBatch, readCaseRuns } from './store.mjs';
12
13
 
13
- const CASE_HEADERS = ['序号', '优先级', '模块', '一级功能', '二级功能', '测试功能点', '前提条件', '操作步骤', '预期结果', '测试结果', '备注'];
14
+ const CASE_HEADERS = ['编号', '优先级', '模块', '一级功能', '二级功能', '测试类型', '测试内容', '前提条件', '测试步骤', '预期结果', '实际结果', '备注'];
14
15
  const RESULT_HEADERS = [...CASE_HEADERS, '是否可自动化', '用例编号', '执行批次', '耗时', '执行说明'];
15
- const CASE_WIDTHS = [5, 7, 12, 14, 30, 40, 30, 55, 55, 12, 26, 14, 16];
16
+ const CASE_WIDTHS = [6, 8, 14, 16, 20, 12, 40, 32, 55, 55, 14, 26, 18, 10];
16
17
  const RESULT_WIDTHS = [...CASE_WIDTHS, 18, 10, 40];
17
18
  const FONT_NAME = '微软雅黑';
18
19
  const BORDER = Object.fromEntries(['top', 'left', 'bottom', 'right'].map((side) => [side, { style: 'thin', color: { argb: 'FF000000' } }]));
@@ -184,7 +185,7 @@ function addCoverSheet(workbook, { kind, title, config, summary, scope, batch })
184
185
  const note = ws.getCell(`A${rowNumber}`);
185
186
  note.value = kind === 'results'
186
187
  ? '测试结果来自批次执行记录或结果库;未执行用例保留在文档中,便于再次导入后继续执行。'
187
- : '列结构与 M006 用例模板一致;末尾「用例编号」列用于再次导入时保持编号稳定。';
188
+ : '列结构沿用 OMS二期订单用例表;末尾「用例编号」列用于再次导入时保持编号稳定。';
188
189
  styleCoverCell(note);
189
190
  return ws;
190
191
  }
@@ -233,6 +234,7 @@ function caseValues(item, { result, run, includeResultDetail = false, defaultSta
233
234
  moduleOf(item),
234
235
  l1Of(item),
235
236
  item.l2 || '',
237
+ item.type || '',
236
238
  item.functionPoint || item.title || '',
237
239
  item.precondition || '',
238
240
  item.steps || '',
@@ -249,7 +251,7 @@ function caseValues(item, { result, run, includeResultDetail = false, defaultSta
249
251
  }
250
252
 
251
253
  function caseAligns(includeResultDetail) {
252
- const aligns = ['center', 'center', 'center', 'left', 'center', 'left', 'left', 'left', 'left', 'center', 'center', 'center', 'center'];
254
+ const aligns = ['center', 'center', 'center', 'left', 'center', 'center', 'left', 'left', 'left', 'left', 'center', 'center', 'center', 'center'];
253
255
  if (includeResultDetail) aligns.push('center', 'center', 'left');
254
256
  return aligns;
255
257
  }
package/studio/host.mjs CHANGED
@@ -9,7 +9,7 @@ import { normalizeEvidenceFile } from '../lib/results.mjs';
9
9
  import { resolveRequestProject, listWorkspaces, defaultProjectPath, HostError, hostError, readFlows } from '../host/state.mjs';
10
10
  import { ensureDir, writeFileAtomic, nowIso } from '../lib/util.mjs';
11
11
  import { pickPath } from '../host/pick-path.mjs';
12
- import { centralBackfillCategories, centralBrowse, centralDeleteEpisode, centralEpisode, centralExtract, centralExtractions, centralSearch, centralSemanticIndex, centralStatus } from '../lib/knowledge-central.mjs';
12
+ import { centralBackfillCategories, centralBrowse, centralDeleteEpisode, centralEpisode, centralExtract, centralExtractions, centralPipelineStatus, centralSearch, centralSemanticIndex, centralStatus } from '../lib/knowledge-central.mjs';
13
13
  import { importKnowledgeToCentral } from '../lib/knowledge-central-import.mjs';
14
14
  import {
15
15
  deleteKnowledgeDocumentLocal,
@@ -26,10 +26,10 @@ import { buildStudioPlan, compactPlan } from './plan.mjs';
26
26
  import { accountsPayload, deleteAccount, importAccountsText, saveAccount, setDefaultAccount } from './accounts.mjs';
27
27
  import { readLiveInfo } from './live.mjs';
28
28
  import { readAgentLive } from './agent-live.mjs';
29
- import { importDocument } from './import.mjs';
29
+ import { importDocument, reReadDocument } from './import.mjs';
30
30
  import { defaultExportDir, exportCasesWorkbook, exportResultsWorkbook } from './export.mjs';
31
31
  import { buildStudioSnapshot, batchSummary } from './snapshot.mjs';
32
- import { createBatch, deleteBatch, listBatches, mergeBatchRuns, patchBatch, readBatch, readCaseRuns, readDocs, readEvents, refreshBatchSummary, saveBatch, withBatchLock } from './store.mjs';
32
+ import { createBatch, deleteBatch, listBatches, mergeBatchRuns, patchBatch, readBatch, readCaseRuns, readEvents, refreshBatchSummary, saveBatch, withBatchLock } from './store.mjs';
33
33
  import { finishEntry, queueForBatch, stopAllQueued } from './queue.mjs';
34
34
  import { summarizeCaseRuns } from './model.mjs';
35
35
  import { requestBatchStop, requestCasePrioritize, requestCaseStopInBatch, requeueCase, runBatch } from './runner.mjs';
@@ -86,9 +86,11 @@ function errorResponse(error) {
86
86
  const code = error?.code || 'INTERNAL';
87
87
  let status = error instanceof HostError ? error.status || 400 : 500;
88
88
  if (code === 'BATCH_NOT_FOUND' || code === 'CASE_NOT_FOUND' || code === 'IMPORT_PATH_NOT_FOUND' || code === 'FLOW_NOT_FOUND') status = 404;
89
+ else if (code === 'DOC_NOT_FOUND') status = 404;
89
90
  else if (code === 'PROJECT_NOT_FOUND') status = 404;
90
91
  else if (code === 'FLOW_FORBIDDEN') status = 403;
91
92
  else if (code === 'WRITEBACK_BUSY' || code === 'JOB_CONFLICT' || code === 'ACCOUNT_EXISTS') status = 409;
93
+ else if (code === 'DOC_SOURCE_MISSING' || code === 'DOC_CASE_FILE_MISSING' || code === 'DOC_KIND_UNSUPPORTED') status = 409;
92
94
  else if (code === 'CASE_NOT_ACTIVE' || code === 'CASE_NOT_QUEUED') status = 409;
93
95
  else if (code === 'ACCOUNT_NOT_FOUND' || code === 'ACCOUNT_DOC_NOT_FOUND') status = 404;
94
96
  else if (code === 'NO_PICKER' || code === 'PICKER_UNAVAILABLE') status = 501;
@@ -100,7 +102,11 @@ function errorResponse(error) {
100
102
  else if (String(code).startsWith('EXPORT_')) status = 400;
101
103
  else if (String(code).startsWith('IMPORT_') || String(code).startsWith('ACCOUNT') || code === 'FLOW_REQUIRED' || code === 'FLOW_NOT_CASE' || code === 'BATCH_ID_INVALID' || code === 'CASE_REQUIRED' || code === 'BATCH_REQUIRED' || code === 'CASE_NOT_IN_BATCH' || code === 'NO_RUNNABLE_CASES') status = 400;
102
104
  const message = String(error?.message || error || '未知错误');
103
- return jsonResponse(status, { ok: false, error: { code, message } });
105
+ const payload = { ok: false, error: { code, message } };
106
+ if (error?.detail && typeof error.detail === 'object' && Object.keys(error.detail).length) {
107
+ payload.error.detail = error.detail;
108
+ }
109
+ return jsonResponse(status, payload);
104
110
  }
105
111
 
106
112
  async function readBody(request, { maxBytes = MAX_BODY } = {}) {
@@ -760,6 +766,13 @@ async function handleCentralExtractions(ctx, request) {
760
766
  return centralRouteResponse(result, 'KNOWLEDGE_EXTRACTIONS_FAILED');
761
767
  }
762
768
 
769
+ async function handleCentralPipeline(ctx, request) {
770
+ const url = new URL(request.url, 'http://localhost');
771
+ const { config } = projectFor(ctx, url.searchParams.get('project') || '');
772
+ const result = await centralPipelineStatus(config, { groupId: url.searchParams.get('groupId') || '' });
773
+ return centralRouteResponse(result, 'KNOWLEDGE_PIPELINE_FAILED');
774
+ }
775
+
763
776
  async function handleCentralEpisode(ctx, request) {
764
777
  const url = new URL(request.url, 'http://localhost');
765
778
  const { config } = projectFor(ctx, url.searchParams.get('project') || '');
@@ -1290,7 +1303,27 @@ async function handleCasePrioritize(ctx, request) {
1290
1303
  function handleDocs(ctx, request) {
1291
1304
  const url = new URL(request.url, 'http://localhost');
1292
1305
  const { config } = projectFor(ctx, url.searchParams.get('project') || '');
1293
- return ok({ docs: readDocs(config).docs || [] });
1306
+ return ok({ docs: buildStudioSnapshot(config).docs });
1307
+ }
1308
+
1309
+ async function handleDocsReRead(ctx, request) {
1310
+ const body = await readBody(request);
1311
+ const { config } = projectFor(ctx, body.project || '');
1312
+ const busy = activeBatchResponse(config);
1313
+ if (busy) return busy;
1314
+ const mode = body.mode === 'overwrite' ? 'overwrite' : body.mode === 'merge' ? 'merge' : '';
1315
+ const result = await reReadDocument(config, { docId: String(body.docId || ''), mode });
1316
+ return ok({
1317
+ doc: result.doc,
1318
+ docs: result.docs || (result.doc ? [result.doc] : []),
1319
+ diff: result.diff || null,
1320
+ diffSummary: result.diffSummary || null,
1321
+ caseCount: (result.cases || []).length,
1322
+ cases: result.cases || [],
1323
+ warnings: result.warnings || [],
1324
+ resultReapplied: result.resultReapplied === true,
1325
+ snapshot: buildStudioSnapshot(config),
1326
+ });
1294
1327
  }
1295
1328
 
1296
1329
  export function registerStudioRoutes({ ctx, panel }) {
@@ -1337,6 +1370,7 @@ export function registerStudioRoutes({ ctx, panel }) {
1337
1370
  ['/knowledge/central/categories', ['POST'], (request) => handleCentralCategories(ctx, request)],
1338
1371
  ['/knowledge/central/extract', ['POST'], (request) => handleCentralExtract(ctx, request)],
1339
1372
  ['/knowledge/central/extractions', ['GET'], (request) => handleCentralExtractions(ctx, request)],
1373
+ ['/knowledge/central/pipeline', ['GET'], (request) => handleCentralPipeline(ctx, request)],
1340
1374
  ['/knowledge/central/semantic-index', ['POST'], (request) => handleCentralSemanticIndex(ctx, request)],
1341
1375
  ['/knowledge/central/episode', ['GET'], (request) => handleCentralEpisode(ctx, request)],
1342
1376
  ['/knowledge/central/import', ['POST'], (request) => handleCentralImport(ctx, request)],
@@ -1349,6 +1383,7 @@ export function registerStudioRoutes({ ctx, panel }) {
1349
1383
  ['/doctor', ['GET', 'POST'], (request) => handleDoctor(ctx, request)],
1350
1384
  ['/shot', ['GET', 'HEAD'], (request) => handleShot(ctx, request)],
1351
1385
  ['/docs', ['GET'], (request) => handleDocs(ctx, request)],
1386
+ ['/docs/re-read', ['POST'], (request) => handleDocsReRead(ctx, request)],
1352
1387
  ];
1353
1388
  const disposers = [];
1354
1389
  for (const [suffix, methods, handler] of routes) {