dsh-uitest 2.1.4 → 2.3.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.
@@ -1,11 +1,13 @@
1
1
  // 导入 xlsx 用例到项目 .uitest/cases/imported.json:多 sheet 自动解析、按 tcId 合并、目录批量、原子写。
2
2
  // 不修改 config.cases.xlsx;Host 读取时再把 imported 用例合并到 config 用例之上。
3
+ import crypto from 'node:crypto';
3
4
  import fs from 'node:fs';
4
5
  import path from 'node:path';
5
6
 
6
7
  import { UitestError, ensureDir, normalizeDocKey, nowIso, timeStamp, writeFileAtomic } from './util.mjs';
7
8
  import { deriveTcId, listSheets, loadCases } from './xlsx.mjs';
8
- import { loadMarkdownCases } from './cases-md.mjs';
9
+ import { loadCsvCases } from './csv.mjs';
10
+ import { isMarkdownCaseId, loadMarkdownCases } from './cases-md.mjs';
9
11
 
10
12
  export class CasesImportError extends UitestError {
11
13
  constructor(message, { code = 'CASES_IMPORT_ERROR', detail = {} } = {}) {
@@ -16,7 +18,7 @@ export class CasesImportError extends UitestError {
16
18
 
17
19
  const IMPORT_LIMIT_FILES = 50;
18
20
  const IMPORT_LIMIT_BYTES = 50 * 1024 * 1024;
19
- const XLSX_EXT = '.xlsx';
21
+ const TABLE_EXTS = new Set(['.xlsx', '.csv']);
20
22
  const NON_CASE_SHEETS = /^(发行控制|结果汇总|测试计划)$/;
21
23
 
22
24
  export const CASE_EDIT_FIELDS = [
@@ -150,13 +152,15 @@ export function loadProjectCases(config) {
150
152
  deletedCaseIds: importedStore.deletedCaseIds || [],
151
153
  });
152
154
  const docs = readDocsIndex(config?.projectDir || process.cwd());
155
+ const linkIndex = documentLinkIndex(docs, config?.projectDir || process.cwd());
153
156
  return {
154
- cases: merged.cases.map((item) => enrichDocKey(item, docs, config?.projectDir || process.cwd())),
157
+ cases: merged.cases.map((item) => linkCaseToDocument(item, linkIndex)),
155
158
  configCount: configCases.length,
156
159
  markdownCount: markdown.cases.length,
157
160
  markdownFiles: markdown.files.length,
158
161
  importedCount: merged.importedCount,
159
162
  deletedCount: merged.deletedCount,
163
+ deletedCaseIds: importedStore.deletedCaseIds || [],
160
164
  file,
161
165
  warnings,
162
166
  };
@@ -173,52 +177,133 @@ function readDocsIndex(projectDir) {
173
177
  }
174
178
  }
175
179
 
176
- /** 旧 imported 条目可能没有 docKey;用 docs.json 的 importId/文件路径补出归属。 */
177
- function docOwnerIndex(projectDir) {
178
- const byImportId = new Map();
179
- const byFile = new Map();
180
- for (const doc of readDocsIndex(projectDir)) {
181
- const key = doc.docKey || normalizeDocKey(doc.name);
182
- if (!key) continue;
183
- for (const importId of doc.importIds || []) if (importId) byImportId.set(importId, key);
184
- for (const value of [doc.sourcePath, doc.generatedPath]) {
180
+ /** 文档 identity 只由首次导入的 docKey 决定,改名不重算。 */
181
+ export function docIdForKey(docKey) {
182
+ return 'doc-' + crypto.createHash('sha1').update(String(docKey || '')).digest('hex').slice(0, 10);
183
+ }
184
+
185
+ function uniqueStrings(values) {
186
+ return [...new Set((Array.isArray(values) ? values : []).map((item) => String(item || '').trim()).filter(Boolean))];
187
+ }
188
+
189
+ /** 旧记录缺少 id/caseIds 等字段时在内存补齐,旧文件不需要迁移。 */
190
+ export function normalizeDocumentRecord(raw = {}) {
191
+ const docKey = raw.docKey || normalizeDocKey(raw.name || '');
192
+ const caseIds = uniqueStrings(raw.caseIds);
193
+ return {
194
+ ...raw,
195
+ id: raw.id || docIdForKey(docKey || raw.sourcePath || raw.name || 'document'),
196
+ docKey,
197
+ name: raw.name || docKey,
198
+ kind: raw.kind || '',
199
+ sourcePath: raw.sourcePath || '',
200
+ originalName: raw.originalName || '',
201
+ generatedPath: raw.generatedPath || '',
202
+ caseIds,
203
+ importIds: uniqueStrings(raw.importIds),
204
+ count: caseIds.length || Number(raw.count) || 0,
205
+ lastCount: Number.isFinite(Number(raw.lastCount)) ? Number(raw.lastCount) : caseIds.length,
206
+ mode: raw.mode === 'overwrite' ? 'overwrite' : 'merge',
207
+ version: Number(raw.version) || 1,
208
+ diff: raw.diff || null,
209
+ digests: raw.digests && typeof raw.digests === 'object' ? raw.digests : {},
210
+ importedAt: raw.importedAt || '',
211
+ updatedAt: raw.updatedAt || raw.importedAt || '',
212
+ warnings: Array.isArray(raw.warnings) ? raw.warnings : [],
213
+ lastRead: raw.lastRead || null,
214
+ writeback: raw.writeback || null,
215
+ };
216
+ }
217
+
218
+ function pushIndex(map, key, doc) {
219
+ if (!key) return;
220
+ const list = map.get(key) || [];
221
+ if (!list.includes(doc)) list.push(doc);
222
+ map.set(key, list);
223
+ }
224
+
225
+ /** 一次导入/加载共用的文档解析索引;一个 key 命中多个文档时视为歧义。 */
226
+ export function documentLinkIndex(docs = [], projectDir = process.cwd()) {
227
+ const index = {
228
+ docs: [],
229
+ byId: new Map(),
230
+ byKey: new Map(),
231
+ byImportId: new Map(),
232
+ byFile: new Map(),
233
+ projectDir,
234
+ };
235
+ for (const raw of Array.isArray(docs) ? docs : []) {
236
+ const doc = normalizeDocumentRecord(raw);
237
+ index.docs.push(doc);
238
+ if (doc.id) index.byId.set(doc.id, doc);
239
+ pushIndex(index.byKey, doc.docKey, doc);
240
+ pushIndex(index.byKey, normalizeDocKey(doc.name), doc);
241
+ for (const importId of doc.importIds) pushIndex(index.byImportId, importId, doc);
242
+ for (const value of [doc.generatedPath, doc.sourcePath]) {
185
243
  if (!value) continue;
186
- byFile.set(path.isAbsolute(value) ? path.resolve(value) : path.resolve(projectDir, value), key);
244
+ pushIndex(index.byFile, path.isAbsolute(value) ? path.resolve(value) : path.resolve(projectDir, value), doc);
187
245
  }
188
246
  }
189
- return { byImportId, byFile, projectDir };
190
- }
191
-
192
- function docKeyForSource(source, index) {
193
- if (!source || !index) return '';
194
- const importId = source.importId || source.original?.importId;
195
- if (importId && index.byImportId.has(importId)) return index.byImportId.get(importId);
196
- const raw = source.file || source.original?.file;
197
- if (!raw) return '';
198
- const file = path.isAbsolute(raw) ? path.resolve(raw) : path.resolve(index.projectDir, raw);
199
- return index.byFile.get(file) || '';
200
- }
201
-
202
- /** Markdown/json 生成的用例来源只带文件路径;按 docs.json 补回 docKey,保证手工修改可追溯。 */
203
- function enrichDocKey(item, docs, projectDir) {
204
- const source = item?.source;
205
- if (!source?.file || source.docKey || !docs.length) return item;
206
- const file = path.resolve(source.file);
207
- const resolvePath = (value) => (path.isAbsolute(value) ? value : path.resolve(projectDir, value));
208
- const doc = docs.find((entry) => {
209
- const generated = entry.generatedPath ? resolvePath(entry.generatedPath) : '';
210
- const original = entry.sourcePath ? resolvePath(entry.sourcePath) : '';
211
- return (generated && path.resolve(generated) === file) || (original && path.resolve(original) === file);
212
- });
213
- if (!doc) return item;
214
- return {
215
- ...item,
216
- source: {
217
- ...source,
218
- docKey: doc.docKey || normalizeDocKey(doc.name),
219
- docName: doc.name || doc.docName || '',
247
+ return index;
248
+ }
249
+
250
+ function sourceChain(source) {
251
+ const chain = [];
252
+ let current = source || null;
253
+ for (let depth = 0; depth < 3 && current; depth += 1) {
254
+ chain.push(current);
255
+ current = current.original || null;
256
+ }
257
+ return chain;
258
+ }
259
+
260
+ function resolveIndexLevel(chain, resolve) {
261
+ const found = [];
262
+ for (const source of chain) {
263
+ for (const doc of resolve(source) || []) if (!found.includes(doc)) found.push(doc);
264
+ }
265
+ if (found.length > 1) return { doc: null, ambiguous: true };
266
+ return { doc: found[0] || null, ambiguous: false };
267
+ }
268
+
269
+ /**
270
+ * 按持久 id → importId → 文件路径 → docKey 的顺序解析归属。
271
+ * 任一层命中多个文档都判为未归属,绝不猜一个文档。
272
+ */
273
+ export function linkCaseToDocument(caseItem, index) {
274
+ const source = caseItem?.source;
275
+ if (!source || !index) return caseItem;
276
+ const chain = sourceChain(source);
277
+ const levels = [
278
+ (item) => (item.docId ? [index.byId.get(String(item.docId))].filter(Boolean) : []),
279
+ (item) => index.byImportId.get(String(item.importId || '')) || [],
280
+ (item) => {
281
+ if (!item.file) return [];
282
+ const file = path.isAbsolute(item.file) ? path.resolve(item.file) : path.resolve(index.projectDir, item.file);
283
+ return index.byFile.get(file) || [];
220
284
  },
221
- };
285
+ (item) => {
286
+ const key = normalizeDocKey(item.docKey || item.docName);
287
+ return key ? index.byKey.get(key) || [] : [];
288
+ },
289
+ ];
290
+ for (const resolve of levels) {
291
+ const hit = resolveIndexLevel(chain, resolve);
292
+ if (hit.ambiguous) return caseItem;
293
+ if (!hit.doc) continue;
294
+ const doc = hit.doc;
295
+ return {
296
+ ...caseItem,
297
+ source: {
298
+ ...source,
299
+ docId: doc.id,
300
+ docKey: doc.docKey || normalizeDocKey(doc.name),
301
+ docName: doc.name || '',
302
+ docKind: doc.kind || '',
303
+ },
304
+ };
305
+ }
306
+ return caseItem;
222
307
  }
223
308
 
224
309
  export function importedCasesFile(project) {
@@ -586,7 +671,7 @@ function lstatOrNull(target) {
586
671
  }
587
672
  }
588
673
 
589
- function scanXlsxDirectory(dir) {
674
+ function scanTableDirectory(dir) {
590
675
  const files = [];
591
676
  let totalBytes = 0;
592
677
  const walk = (current) => {
@@ -607,19 +692,19 @@ function scanXlsxDirectory(dir) {
607
692
  walk(absolute);
608
693
  continue;
609
694
  }
610
- if (!entry.isFile() || path.extname(entry.name).toLowerCase() !== XLSX_EXT) continue;
695
+ if (!entry.isFile() || !TABLE_EXTS.has(path.extname(entry.name).toLowerCase())) continue;
611
696
  const stat = lstatOrNull(absolute);
612
697
  if (!stat) continue;
613
698
  totalBytes += stat.size;
614
699
  files.push({ path: absolute, size: stat.size });
615
700
  if (files.length > IMPORT_LIMIT_FILES) {
616
- throw new CasesImportError(`目录内 xlsx 文件超过上限(最多 ${IMPORT_LIMIT_FILES} 个)`, {
701
+ throw new CasesImportError(`目录内表格文件超过上限(最多 ${IMPORT_LIMIT_FILES} 个)`, {
617
702
  code: 'CASES_IMPORT_LIMIT',
618
703
  detail: { dir, maxFiles: IMPORT_LIMIT_FILES },
619
704
  });
620
705
  }
621
706
  if (totalBytes > IMPORT_LIMIT_BYTES) {
622
- throw new CasesImportError('目录内 xlsx 总大小超过 50MB 上限', {
707
+ throw new CasesImportError('目录内表格文件总大小超过 50MB 上限', {
623
708
  code: 'CASES_IMPORT_LIMIT',
624
709
  detail: { dir, maxBytes: IMPORT_LIMIT_BYTES },
625
710
  });
@@ -637,10 +722,26 @@ function normalizeSheetCases(result, sheet, file) {
637
722
  }));
638
723
  }
639
724
 
640
- /** 导入一个 xlsx;sheet 指定时只导该 sheet,否则逐 sheet 自动尝试。 */
641
- function parseWorkbookFile(file, { sheet } = {}) {
725
+ /** 导入一个 xlsx 或 CSV;xlsx 的 sheet 指定时只导该 sheet,否则逐 sheet 自动尝试。 */
726
+ function parseTableFile(file, { sheet } = {}) {
642
727
  const warnings = [];
643
728
  const parsedSheets = [];
729
+ if (path.extname(file).toLowerCase() === '.csv') {
730
+ if (sheet) {
731
+ return { parsedSheets, warnings, fatal: new CasesImportError('CSV 不支持选择工作表:' + file, { code: 'CSV_NO_SHEET', detail: { file, sheet } }) };
732
+ }
733
+ try {
734
+ const loaded = loadCsvCases({ file });
735
+ if (!loaded.cases.length) {
736
+ warnings.push({ sheet: loaded.sheet, code: 'CSV_EMPTY', message: 'CSV 中没有用例' });
737
+ return { parsedSheets, warnings };
738
+ }
739
+ parsedSheets.push({ sheet: loaded.sheet, headerRow: loaded.headerRow, cases: loaded.cases });
740
+ return { parsedSheets, warnings };
741
+ } catch (err) {
742
+ return { parsedSheets, warnings, fatal: err };
743
+ }
744
+ }
644
745
  if (sheet) {
645
746
  try {
646
747
  const loaded = loadCases({ file, sheet });
@@ -672,20 +773,20 @@ function parseWorkbookFile(file, { sheet } = {}) {
672
773
  }
673
774
 
674
775
  /**
675
- * 导入 xlsx 用例(单文件或目录)。
776
+ * 导入 xlsx / CSV 用例(单文件或目录)。
676
777
  * @returns {Promise<object>} 同步实现(保留 async 兼容 Host await)
677
778
  */
678
- export function importCases(project, { file, files, dir, sheet, name, docKey = '', docName = '', mode = 'merge', replacesDocKeys = [] } = {}) {
779
+ export function importCases(project, { file, files, dir, sheet, name, docKey = '', docName = '', mode = 'merge', replacesDocKeys = [], requireMarkdownIds = false } = {}) {
679
780
  const projectDir = typeof project === 'string' ? path.resolve(project) : project.projectDir;
680
781
  const requested = file || dir || (Array.isArray(files) ? files[0] : undefined);
681
782
  if (!requested && !Array.isArray(files)) {
682
- throw new CasesImportError('cases import 需要 <xlsx|目录>', { code: 'PATH_NOT_FOUND' });
783
+ throw new CasesImportError('cases import 需要 <xlsx|csv|目录>', { code: 'PATH_NOT_FOUND' });
683
784
  }
684
785
  const sourcePath = path.resolve(projectDir, String(requested));
685
- let xlsxFiles;
786
+ let tableFiles;
686
787
  let isDirectory = false;
687
788
  if (Array.isArray(files) && files.length) {
688
- xlsxFiles = [];
789
+ tableFiles = [];
689
790
  let totalBytes = 0;
690
791
  for (const item of files) {
691
792
  const absolute = path.resolve(projectDir, String(item));
@@ -693,13 +794,13 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
693
794
  if (!stat || !stat.isFile()) {
694
795
  throw new CasesImportError(`路径不存在:${absolute}`, { code: 'PATH_NOT_FOUND', detail: { path: absolute } });
695
796
  }
696
- if (path.extname(absolute).toLowerCase() !== XLSX_EXT) {
697
- throw new CasesImportError(`不是 xlsx 文件:${absolute}`, { code: 'XLSX_NO_CASES', detail: { file: absolute } });
797
+ if (!TABLE_EXTS.has(path.extname(absolute).toLowerCase())) {
798
+ throw new CasesImportError(`不是 xlsx/CSV 文件:${absolute}`, { code: 'XLSX_NO_CASES', detail: { file: absolute } });
698
799
  }
699
800
  totalBytes += stat.size;
700
- xlsxFiles.push(absolute);
801
+ tableFiles.push(absolute);
701
802
  }
702
- if (xlsxFiles.length > IMPORT_LIMIT_FILES || totalBytes > IMPORT_LIMIT_BYTES) {
803
+ if (tableFiles.length > IMPORT_LIMIT_FILES || totalBytes > IMPORT_LIMIT_BYTES) {
703
804
  throw new CasesImportError('files 超过 50 个 / 50MB 上限', { code: 'CASES_IMPORT_LIMIT' });
704
805
  }
705
806
  } else {
@@ -709,26 +810,26 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
709
810
  }
710
811
  if (stat.isDirectory()) {
711
812
  isDirectory = true;
712
- xlsxFiles = scanXlsxDirectory(sourcePath).map((item) => item.path);
713
- if (!xlsxFiles.length) {
714
- throw new CasesImportError(`目录内没有 xlsx 文件:${sourcePath}`, {
813
+ tableFiles = scanTableDirectory(sourcePath).map((item) => item.path);
814
+ if (!tableFiles.length) {
815
+ throw new CasesImportError(`目录内没有 xlsx/CSV 文件:${sourcePath}`, {
715
816
  code: 'XLSX_NO_CASES',
716
817
  detail: { dir: sourcePath },
717
818
  });
718
819
  }
719
820
  } else if (stat.isFile()) {
720
- if (path.extname(sourcePath).toLowerCase() !== XLSX_EXT) {
721
- throw new CasesImportError(`不是 xlsx 文件:${sourcePath}`, { code: 'XLSX_NO_CASES', detail: { file: sourcePath } });
821
+ if (!TABLE_EXTS.has(path.extname(sourcePath).toLowerCase())) {
822
+ throw new CasesImportError(`不是 xlsx/CSV 文件:${sourcePath}`, { code: 'XLSX_NO_CASES', detail: { file: sourcePath } });
722
823
  }
723
- xlsxFiles = [sourcePath];
824
+ tableFiles = [sourcePath];
724
825
  } else {
725
826
  throw new CasesImportError(`不是文件或目录:${sourcePath}`, { code: 'PATH_NOT_FOUND', detail: { path: sourcePath } });
726
827
  }
727
828
  }
728
829
 
729
830
  const store = loadImportedCases(project);
730
- const ownerIndex = docOwnerIndex(projectDir);
731
- const casesById = new Map(store.cases.map((item) => [String(item.tcId), item]));
831
+ const linkIndex = documentLinkIndex(readDocsIndex(projectDir), projectDir);
832
+ const casesById = new Map(store.cases.map((item) => [caseKey(item.tcId), item]));
732
833
  const seenBatch = new Set();
733
834
  const imports = [];
734
835
  const allWarnings = [];
@@ -739,15 +840,15 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
739
840
  let successfulFiles = 0;
740
841
  const replaceKeys = new Set(replacesDocKeys.filter(Boolean));
741
842
 
742
- for (const xlsxFile of xlsxFiles) {
843
+ for (const tableFile of tableFiles) {
743
844
  const importId = newImportId();
744
845
  const sourceName = name
745
- ? xlsxFiles.length === 1
846
+ ? tableFiles.length === 1
746
847
  ? String(name)
747
- : `${name}-${path.basename(xlsxFile, path.extname(xlsxFile))}`
748
- : path.basename(xlsxFile, path.extname(xlsxFile));
848
+ : `${name}-${path.basename(tableFile, path.extname(tableFile))}`
849
+ : path.basename(tableFile, path.extname(tableFile));
749
850
  const importRecord = {
750
- file: xlsxFile,
851
+ file: tableFile,
751
852
  name: sourceName,
752
853
  id: importId,
753
854
  docKey: docKey || '',
@@ -762,15 +863,15 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
762
863
  };
763
864
  let parsed;
764
865
  try {
765
- parsed = parseWorkbookFile(xlsxFile, { sheet });
866
+ parsed = parseTableFile(tableFile, { sheet });
766
867
  } catch (err) {
767
868
  parsed = { parsedSheets: [], warnings: [], fatal: err };
768
869
  }
769
870
  if (parsed.fatal) {
770
871
  if (!isDirectory) {
771
- throw new CasesImportError(`xlsx 解析失败:${xlsxFile}:${parsed.fatal.message}`, {
872
+ throw new CasesImportError(`表格解析失败:${tableFile}:${parsed.fatal.message}`, {
772
873
  code: 'XLSX_NO_CASES',
773
- detail: { file: xlsxFile },
874
+ detail: { file: tableFile },
774
875
  });
775
876
  }
776
877
  importRecord.warnings.push({ sheet: null, code: 'XLSX_FILE_SKIPPED', message: `文件解析失败,已跳过:${parsed.fatal.message}` });
@@ -781,37 +882,45 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
781
882
  }
782
883
  for (const warning of parsed.warnings) {
783
884
  importRecord.warnings.push(warning);
784
- allWarnings.push({ file: xlsxFile, ...warning });
885
+ allWarnings.push({ file: tableFile, ...warning });
785
886
  }
786
887
  let fileCases = 0;
787
888
  for (const parsedSheet of parsed.parsedSheets) {
788
889
  const sheetStat = { sheet: parsedSheet.sheet, headerRow: parsedSheet.headerRow, added: 0, replaced: 0, skipped: 0, warnings: [] };
789
890
  for (const rawCase of parsedSheet.cases) {
790
891
  const tcId = String(rawCase.tcId || deriveTcId(rawCase));
892
+ if (requireMarkdownIds && !isMarkdownCaseId(tcId)) {
893
+ throw new CasesImportError('用例编号无法用于 Markdown 回写:' + tcId, {
894
+ code: 'IMPORT_BAD_CASE_ID',
895
+ detail: { file: tableFile, sheet: parsedSheet.sheet, id: tcId },
896
+ });
897
+ }
791
898
  const caseItem = {
792
899
  ...rawCase,
793
900
  tcId,
794
901
  source: {
795
902
  kind: 'import',
796
- file: xlsxFile,
903
+ file: tableFile,
797
904
  sheet: parsedSheet.sheet,
798
905
  importId,
799
906
  ...(docKey ? { docKey } : {}),
800
907
  ...(docName ? { docName } : {}),
801
908
  },
802
909
  };
803
- if (seenBatch.has(tcId)) {
910
+ const key = caseKey(tcId);
911
+ if (seenBatch.has(key)) {
804
912
  sheetStat.skipped += 1;
805
913
  totalSkipped += 1;
806
914
  continue;
807
915
  }
808
- seenBatch.add(tcId);
809
- if (casesById.has(tcId)) {
810
- const existing = casesById.get(tcId);
811
- const existingDocKey = existing?.source?.docKey
916
+ seenBatch.add(key);
917
+ if (casesById.has(key)) {
918
+ const existing = casesById.get(key);
919
+ const linkedExisting = linkCaseToDocument(existing, linkIndex);
920
+ const existingDocKey = linkedExisting?.source?.docKey
921
+ || existing?.source?.docKey
812
922
  || existing?.source?.original?.docKey
813
923
  || existing?.source?.original?.original?.docKey
814
- || docKeyForSource(existing?.source, ownerIndex)
815
924
  || '';
816
925
  if (docKey && existingDocKey && existingDocKey !== docKey && !replaceKeys.has(existingDocKey)) {
817
926
  importRecord.conflicts += 1;
@@ -825,15 +934,15 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
825
934
  message: `用例编号 ${tcId} 已属于文档 ${existingDocKey},本次跳过;请改用唯一编号或先删除旧文档`,
826
935
  };
827
936
  importRecord.warnings.push(warning);
828
- allWarnings.push({ file: xlsxFile, ...warning });
937
+ allWarnings.push({ file: tableFile, ...warning });
829
938
  }
830
939
  continue;
831
940
  }
832
- casesById.set(tcId, caseItem);
941
+ casesById.set(key, caseItem);
833
942
  sheetStat.replaced += 1;
834
943
  totalReplaced += 1;
835
944
  } else {
836
- casesById.set(tcId, caseItem);
945
+ casesById.set(key, caseItem);
837
946
  sheetStat.added += 1;
838
947
  totalAdded += 1;
839
948
  }
@@ -850,7 +959,7 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
850
959
  store.sources.push({
851
960
  id: importId,
852
961
  name: sourceName,
853
- file: xlsxFile,
962
+ file: tableFile,
854
963
  docKey: docKey || '',
855
964
  docName: docName || sourceName,
856
965
  mode: mode === 'overwrite' ? 'overwrite' : 'merge',
@@ -873,7 +982,7 @@ export function importCases(project, { file, files, dir, sheet, name, docKey = '
873
982
  detail: { path: sourcePath, conflicts: totalConflicts, imports },
874
983
  });
875
984
  }
876
- throw new CasesImportError(`没有可解析的 xlsx 用例:${sourcePath}`, {
985
+ throw new CasesImportError(`没有可解析的 xlsx/CSV 用例:${sourcePath}`, {
877
986
  code: 'XLSX_NO_CASES',
878
987
  detail: { path: sourcePath, imports },
879
988
  });
package/lib/cases-md.mjs CHANGED
@@ -10,6 +10,11 @@ const HEADING_RE = /^(#{2,4})\s+(\S+)\s*(.*)$/;
10
10
  const TABLE_ROW_RE = /^\s*\|(.+)\|\s*$/;
11
11
  const MD_MAX_FILES = 200;
12
12
 
13
+ /** 写入 case 文件前用它校验编号,保证导入结果能被同一个读取器读回。 */
14
+ export function isMarkdownCaseId(value) {
15
+ return CASE_ID_RE.test(String(value || ''));
16
+ }
17
+
13
18
  const FIELD_ALIASES = new Map([
14
19
  ['优先级', 'priority'],
15
20
  ['前置', 'precondition'],
package/lib/config.mjs CHANGED
@@ -13,7 +13,7 @@ export const DEFAULT_CONFIG = {
13
13
  browser: {
14
14
  executablePath: '',
15
15
  headless: true,
16
- viewport: { width: 1600, height: 1000 },
16
+ viewport: { width: 1920, height: 1280 },
17
17
  args: ['--no-sandbox', '--disable-dev-shm-usage'],
18
18
  locale: 'zh-CN',
19
19
  timezoneId: 'Asia/Shanghai',
@@ -58,7 +58,7 @@ export function configTemplate(overrides = {}) {
58
58
  browser: {
59
59
  executablePath: '/usr/bin/chromium',
60
60
  headless: true,
61
- viewport: { width: 1600, height: 1000 },
61
+ viewport: { width: 1920, height: 1280 },
62
62
  args: ['--no-sandbox', '--disable-dev-shm-usage'],
63
63
  locale: 'zh-CN',
64
64
  timezoneId: 'Asia/Shanghai',