@hamsterbase/evidra 0.4.0 → 0.6.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.
Files changed (162) hide show
  1. package/dist/sdk/conformance-rules.js +145 -17
  2. package/dist/sdk/index.d.ts +1 -1
  3. package/dist/sdk/main.d.ts +6 -0
  4. package/dist/sdk/main.js +11 -4
  5. package/dist/sdk/rules.d.ts +9 -2
  6. package/dist/sdk/{types-DHfARqti.d.ts → types--o0ku6ya.d.ts} +6 -0
  7. package/dist/service/cli.js +143 -46
  8. package/dist/web/assets/{cssMode-CT7qaTm_.js → cssMode-BQHpX9hf.js} +1 -1
  9. package/dist/web/assets/{editor.api-CsVhWQDt.js → editor.api-aTVJPcBz.js} +1 -1
  10. package/dist/web/assets/{freemarker2-Biydhqq4.js → freemarker2-C69zfyrS.js} +1 -1
  11. package/dist/web/assets/{handlebars-OLGn3O0q.js → handlebars-Bw1zaGO-.js} +1 -1
  12. package/dist/web/assets/{html-Cw5ATHyh.js → html-fMjDlgec.js} +1 -1
  13. package/dist/web/assets/{htmlMode-BI1zICew.js → htmlMode-DeWQtbEo.js} +1 -1
  14. package/dist/web/assets/{index-C49ToWrK.js → index-Dn6cBPut.js} +2 -2
  15. package/dist/web/assets/{javascript-BS1aYt5R.js → javascript-DGw6XfQa.js} +1 -1
  16. package/dist/web/assets/{jsonMode-DCJhJggA.js → jsonMode-DWLxiN48.js} +1 -1
  17. package/dist/web/assets/{liquid-DoQa4FNY.js → liquid-mVy7oRfH.js} +1 -1
  18. package/dist/web/assets/{lspLanguageFeatures-D9tA1yBW.js → lspLanguageFeatures-DHZ5ydHq.js} +1 -1
  19. package/dist/web/assets/main-CAvFOBUt.css +2 -0
  20. package/dist/web/assets/main-DNImWnRE.css +1 -0
  21. package/dist/web/assets/main-ELN7vuxW.js +18 -0
  22. package/dist/web/assets/main-iME7bfou.js +26 -0
  23. package/dist/web/assets/{mdx-CA3qWzFi.js → mdx-B4GGuoLa.js} +1 -1
  24. package/dist/web/assets/{monaco-BtL7JKYj.js → monaco-Dgn-_pxJ.js} +4 -4
  25. package/dist/web/assets/{python-BrQiqC89.js → python-CEoHsiCM.js} +1 -1
  26. package/dist/web/assets/{razor-08hjtCNT.js → razor-BOuSd6jI.js} +1 -1
  27. package/dist/web/assets/{tsMode-DC-2vqQt.js → tsMode-B_TRe0Su.js} +1 -1
  28. package/dist/web/assets/{typescript-9DOCFqrz.js → typescript-CZE3GYFR.js} +1 -1
  29. package/dist/web/assets/useDisplayPreference-DTZ1jElj.js +89 -0
  30. package/dist/web/assets/{workers-BcFJUhLI.js → workers-wfsBwNFd.js} +1 -1
  31. package/dist/web/assets/{xml-ZJo8Un2M.js → xml-BlMZHhHB.js} +1 -1
  32. package/dist/web/assets/{yaml-8EZC7v3K.js → yaml-B8E4SMPe.js} +1 -1
  33. package/dist/web/index.html +1 -1
  34. package/package.json +3 -2
  35. package/packages/conformance/rules/baseline-max-diff-pixels/RULE.md +21 -0
  36. package/packages/conformance/rules/index.md +1 -1
  37. package/skills/evidra/SKILL.md +7 -1
  38. package/dist/types/modules/core/contracts/comparison.d.ts +0 -41
  39. package/dist/types/modules/core/contracts/config.d.ts +0 -19
  40. package/dist/types/modules/core/contracts/context.d.ts +0 -6
  41. package/dist/types/modules/core/contracts/functions/addCase.d.ts +0 -128
  42. package/dist/types/modules/core/contracts/functions/addTask.d.ts +0 -14
  43. package/dist/types/modules/core/contracts/functions/approve.d.ts +0 -8
  44. package/dist/types/modules/core/contracts/functions/baselineChanges.d.ts +0 -14
  45. package/dist/types/modules/core/contracts/functions/compare.d.ts +0 -14
  46. package/dist/types/modules/core/contracts/functions/compareTask.d.ts +0 -6
  47. package/dist/types/modules/core/contracts/functions/compareTasks.d.ts +0 -18
  48. package/dist/types/modules/core/contracts/functions/deleteBaselineFile.d.ts +0 -8
  49. package/dist/types/modules/core/contracts/functions/finishTask.d.ts +0 -8
  50. package/dist/types/modules/core/contracts/functions/getBaseline.d.ts +0 -10
  51. package/dist/types/modules/core/contracts/functions/getBaselineChanges.d.ts +0 -6
  52. package/dist/types/modules/core/contracts/functions/getGitChanges.d.ts +0 -6
  53. package/dist/types/modules/core/contracts/functions/getGitDiff.d.ts +0 -8
  54. package/dist/types/modules/core/contracts/functions/getTaskCase.d.ts +0 -23
  55. package/dist/types/modules/core/contracts/functions/getTaskTree.d.ts +0 -21
  56. package/dist/types/modules/core/contracts/functions/gitChanges.d.ts +0 -25
  57. package/dist/types/modules/core/contracts/functions/index.d.ts +0 -18
  58. package/dist/types/modules/core/contracts/functions/listBaselines.d.ts +0 -5
  59. package/dist/types/modules/core/contracts/functions/listRuns.d.ts +0 -7
  60. package/dist/types/modules/core/contracts/functions/listTaskSummaries.d.ts +0 -15
  61. package/dist/types/modules/core/contracts/functions/listTasks.d.ts +0 -15
  62. package/dist/types/modules/core/contracts/functions/loadConfig.d.ts +0 -5
  63. package/dist/types/modules/core/contracts/functions/readProjectInfo.d.ts +0 -5
  64. package/dist/types/modules/core/contracts/functions/readTaskReport.d.ts +0 -6
  65. package/dist/types/modules/core/contracts/functions/resolveConfig.d.ts +0 -6
  66. package/dist/types/modules/core/contracts/functions/reviewBaselineChanges.d.ts +0 -9
  67. package/dist/types/modules/core/contracts/functions/reviewCodeChanges.d.ts +0 -9
  68. package/dist/types/modules/core/contracts/functions/taskRecords.d.ts +0 -6
  69. package/dist/types/modules/core/contracts/functions/updateBaseline.d.ts +0 -20
  70. package/dist/types/modules/core/contracts/git.d.ts +0 -14
  71. package/dist/types/modules/core/contracts/imageDiffPool.d.ts +0 -5
  72. package/dist/types/modules/core/contracts/index.d.ts +0 -30
  73. package/dist/types/modules/core/contracts/internal/compare.d.ts +0 -14
  74. package/dist/types/modules/core/contracts/internal/getBaseline.d.ts +0 -10
  75. package/dist/types/modules/core/contracts/internal/listTasks.d.ts +0 -12
  76. package/dist/types/modules/core/contracts/internal/taskRecords.d.ts +0 -6
  77. package/dist/types/modules/core/contracts/internal/updateBaseline.d.ts +0 -20
  78. package/dist/types/modules/core/contracts/model.d.ts +0 -80
  79. package/dist/types/modules/core/contracts/report.d.ts +0 -52
  80. package/dist/types/modules/core/contracts/repository.d.ts +0 -5
  81. package/dist/types/modules/core/contracts/requests.d.ts +0 -23
  82. package/dist/types/modules/core/contracts/scanCases.d.ts +0 -15
  83. package/dist/types/modules/core/contracts/shared.d.ts +0 -6
  84. package/dist/types/modules/core/contracts/snapshots.d.ts +0 -6
  85. package/dist/types/modules/core/contracts/taskRecord.d.ts +0 -76
  86. package/dist/types/modules/core/implementations/Functions/addCase.d.ts +0 -4
  87. package/dist/types/modules/core/implementations/Functions/addTask.d.ts +0 -4
  88. package/dist/types/modules/core/implementations/Functions/approve.d.ts +0 -6
  89. package/dist/types/modules/core/implementations/Functions/compare.d.ts +0 -15
  90. package/dist/types/modules/core/implementations/Functions/compareTask.d.ts +0 -3
  91. package/dist/types/modules/core/implementations/Functions/compareTasks.d.ts +0 -5
  92. package/dist/types/modules/core/implementations/Functions/deleteBaselineFile.d.ts +0 -4
  93. package/dist/types/modules/core/implementations/Functions/finishTask.d.ts +0 -4
  94. package/dist/types/modules/core/implementations/Functions/getBaseline.d.ts +0 -4
  95. package/dist/types/modules/core/implementations/Functions/getBaselineChanges.d.ts +0 -4
  96. package/dist/types/modules/core/implementations/Functions/getGitChanges.d.ts +0 -3
  97. package/dist/types/modules/core/implementations/Functions/getGitDiff.d.ts +0 -3
  98. package/dist/types/modules/core/implementations/Functions/getTaskCase.d.ts +0 -5
  99. package/dist/types/modules/core/implementations/Functions/getTaskTree.d.ts +0 -5
  100. package/dist/types/modules/core/implementations/Functions/listBaselines.d.ts +0 -3
  101. package/dist/types/modules/core/implementations/Functions/listTaskSummaries.d.ts +0 -2
  102. package/dist/types/modules/core/implementations/Functions/listTasks.d.ts +0 -4
  103. package/dist/types/modules/core/implementations/Functions/loadConfig.d.ts +0 -3
  104. package/dist/types/modules/core/implementations/Functions/readProjectInfo.d.ts +0 -3
  105. package/dist/types/modules/core/implementations/Functions/readTaskReport.d.ts +0 -3
  106. package/dist/types/modules/core/implementations/Functions/resolveConfig.d.ts +0 -9
  107. package/dist/types/modules/core/implementations/Functions/reviewBaselineChanges.d.ts +0 -4
  108. package/dist/types/modules/core/implementations/Functions/reviewCodeChanges.d.ts +0 -4
  109. package/dist/types/modules/core/implementations/Functions/taskRecords.d.ts +0 -4
  110. package/dist/types/modules/core/implementations/Functions/updateBaseline.d.ts +0 -5
  111. package/dist/types/modules/core/implementations/Utils/assertNamespace.d.ts +0 -1
  112. package/dist/types/modules/core/implementations/Utils/canonical.d.ts +0 -1
  113. package/dist/types/modules/core/implementations/Utils/createTaskId.d.ts +0 -1
  114. package/dist/types/modules/core/implementations/Utils/deletionAllowed.d.ts +0 -2
  115. package/dist/types/modules/core/implementations/Utils/download.d.ts +0 -3
  116. package/dist/types/modules/core/implementations/Utils/hash.d.ts +0 -1
  117. package/dist/types/modules/core/implementations/Utils/imageDiffPool.d.ts +0 -18
  118. package/dist/types/modules/core/implementations/Utils/imageKey.d.ts +0 -1
  119. package/dist/types/modules/core/implementations/Utils/loadBaseline.d.ts +0 -4
  120. package/dist/types/modules/core/implementations/Utils/mapLimit.d.ts +0 -1
  121. package/dist/types/modules/core/implementations/Utils/observationKey.d.ts +0 -1
  122. package/dist/types/modules/core/implementations/Utils/pngSize.d.ts +0 -4
  123. package/dist/types/modules/core/implementations/Utils/readJson.d.ts +0 -1
  124. package/dist/types/modules/core/implementations/Utils/readTaskRecord.d.ts +0 -2
  125. package/dist/types/modules/core/implementations/Utils/scanCases.d.ts +0 -9
  126. package/dist/types/modules/core/implementations/Utils/taskDirectory.d.ts +0 -1
  127. package/dist/types/modules/core/implementations/Utils/toCase.d.ts +0 -3
  128. package/dist/types/modules/core/implementations/Utils/toObservation.d.ts +0 -3
  129. package/dist/types/modules/core/implementations/Utils/toSnapshot.d.ts +0 -3
  130. package/dist/types/modules/core/implementations/Utils/writeBytesAtomic.d.ts +0 -1
  131. package/dist/types/modules/core/implementations/Utils/writeJsonAtomic.d.ts +0 -1
  132. package/dist/types/modules/core/implementations/Utils/writeTextAtomic.d.ts +0 -1
  133. package/dist/types/modules/core/implementations/baselineChanges.d.ts +0 -6
  134. package/dist/types/modules/core/implementations/config.d.ts +0 -6
  135. package/dist/types/modules/core/implementations/content.d.ts +0 -1
  136. package/dist/types/modules/core/implementations/evidra.d.ts +0 -31
  137. package/dist/types/modules/core/implementations/git.d.ts +0 -11
  138. package/dist/types/modules/core/implementations/gitChanges.d.ts +0 -29
  139. package/dist/types/modules/core/implementations/index.d.ts +0 -17
  140. package/dist/types/modules/core/implementations/internal/compare.d.ts +0 -15
  141. package/dist/types/modules/core/implementations/internal/getBaseline.d.ts +0 -4
  142. package/dist/types/modules/core/implementations/internal/listTasks.d.ts +0 -2
  143. package/dist/types/modules/core/implementations/internal/taskRecords.d.ts +0 -4
  144. package/dist/types/modules/core/implementations/internal/updateBaseline.d.ts +0 -5
  145. package/dist/types/modules/core/implementations/paths.d.ts +0 -48
  146. package/dist/types/modules/core/implementations/report.d.ts +0 -3
  147. package/dist/types/modules/core/implementations/reportResources.d.ts +0 -4
  148. package/dist/types/modules/core/implementations/reportStatus.d.ts +0 -10
  149. package/dist/types/modules/core/implementations/reportTree.d.ts +0 -5
  150. package/dist/types/modules/core/implementations/repository.d.ts +0 -10
  151. package/dist/types/modules/core/implementations/requests.d.ts +0 -13
  152. package/dist/types/modules/core/implementations/snapshots.d.ts +0 -11
  153. package/dist/types/modules/core/implementations/storage/local.d.ts +0 -3
  154. package/dist/types/modules/core/implementations/storage/objects.d.ts +0 -3
  155. package/dist/types/modules/core/index.d.ts +0 -21
  156. package/dist/types/packages/sdk/src/index.d.ts +0 -21
  157. package/dist/types/packages/sdk/src/types.d.ts +0 -9
  158. package/dist/web/assets/main-BO3J7gmH.css +0 -2
  159. package/dist/web/assets/main-Bpk1-JEL.css +0 -1
  160. package/dist/web/assets/main-DqSNHHTP.js +0 -13
  161. package/dist/web/assets/main-TbSjhXd2.js +0 -18
  162. package/dist/web/assets/useDisplayPreference-B-z8NzSv.js +0 -23
@@ -1,12 +1,107 @@
1
1
  import path from "node:path";
2
+ import { glob, readFile, stat } from "node:fs/promises";
2
3
  import { promisify } from "node:util";
3
4
  import { promises } from "node:fs";
4
5
  import { execFile } from "node:child_process";
5
6
  import { parseSync } from "oxc-parser";
7
+ // packages/conformance/builtinRules.ts
8
+ /** 内置规约的稳定 ID 同时对应随包发布的文档目录。 */
9
+ const builtinRules = {
10
+ baselineMaxDiffPixels: {
11
+ id: "baseline-max-diff-pixels",
12
+ displayName: "限制基线允许差异像素"
13
+ },
14
+ commitMessage: {
15
+ id: "commit-message",
16
+ displayName: "检查提交标题"
17
+ },
18
+ duplicateLocalization: {
19
+ id: "duplicate-localization",
20
+ displayName: "检查本地化键与默认文案"
21
+ },
22
+ e2eScenariosStructure: {
23
+ id: "e2e-scenarios-structure",
24
+ displayName: "检查端到端场景结构"
25
+ },
26
+ sameDirImportOnly: {
27
+ id: "same-dir-import-only",
28
+ displayName: "限制跨目录引用"
29
+ },
30
+ singleComponentFile: {
31
+ id: "single-component-file",
32
+ displayName: "单文件单组件"
33
+ },
34
+ sourceLocaleDefaults: {
35
+ id: "source-locale-defaults",
36
+ displayName: "检查源语言默认文案"
37
+ },
38
+ syncLocales: {
39
+ id: "sync-locales",
40
+ displayName: "同步本地化文件"
41
+ },
42
+ uiScenariosStructure: {
43
+ id: "ui-scenarios-structure",
44
+ displayName: "检查界面场景结构"
45
+ }
46
+ };
47
+ // packages/conformance/rules/baseline-max-diff-pixels/index.ts
48
+ function baselineMaxDiffPixels(options) {
49
+ const rule = builtinRules.baselineMaxDiffPixels;
50
+ const task = async ({ projectRoot }) => {
51
+ const { baselineDir, maxDiffPixels } = options;
52
+ if (typeof baselineDir !== "string" || !baselineDir.trim()) throw new Error("baselineDir 必须指定基线目录");
53
+ if (!Number.isSafeInteger(maxDiffPixels) || maxDiffPixels < 0) throw new Error("maxDiffPixels 必须是非负整数");
54
+ const root = path.resolve(projectRoot, baselineDir);
55
+ if (!(await stat(root)).isDirectory()) throw new Error(`基线路径必须是目录:${root}`);
56
+ const files = [];
57
+ for await (const file of glob("**/baseline*.json", {
58
+ cwd: root,
59
+ exclude: [
60
+ "**/node_modules/**",
61
+ "**/.git/**",
62
+ "**/cache/**"
63
+ ]
64
+ })) if (/^baseline(?:-[a-f0-9]{64})?\.json$/.test(path.basename(file))) files.push(file);
65
+ files.sort();
66
+ let imageCount = 0;
67
+ const findings = [];
68
+ for (const file of files) {
69
+ const baselinePath = path.join(root, file);
70
+ const relative = path.relative(projectRoot, baselinePath);
71
+ let baseline;
72
+ try {
73
+ baseline = JSON.parse(await readFile(baselinePath, "utf8"));
74
+ } catch (error) {
75
+ findings.push(`${relative} 无法读取基线:${String(error)}`);
76
+ continue;
77
+ }
78
+ if (!Array.isArray(baseline?.snapshots)) continue;
79
+ for (const snapshot of baseline.snapshots) {
80
+ if (snapshot?.type !== "image") continue;
81
+ imageCount++;
82
+ const tolerance = snapshot.maxDiffPixels ?? 0;
83
+ const label = `${relative} / ${baseline.name || baseline.id} / ${snapshot.name || snapshot.id}`;
84
+ if (!Number.isSafeInteger(tolerance) || tolerance < 0) findings.push(`${label} 的 maxDiffPixels 无效(${String(tolerance)})`);
85
+ else if (tolerance > maxDiffPixels) findings.push(`${label} 的 maxDiffPixels 为 ${tolerance},超过上限 ${maxDiffPixels}`);
86
+ }
87
+ }
88
+ return {
89
+ name: rule.id,
90
+ success: findings.length === 0,
91
+ messages: [`检查了 ${imageCount} 张基线图片,maxDiffPixels 上限为 ${maxDiffPixels}。`, ...findings].join("\n"),
92
+ howToFix: findings.length ? "检查报告中的文件和快照。需要调整阈值时,从测试上报配置设置 maxDiffPixels,重新上报后由用户审核基线。" : ""
93
+ };
94
+ };
95
+ return Object.assign(task, {
96
+ ...rule,
97
+ readme: { builtin: rule.id }
98
+ });
99
+ }
6
100
  // packages/conformance/rules/commit-message/index.ts
7
101
  const execFileAsync = promisify(execFile);
8
102
  function commitMessage(config = {}) {
9
- const ruleName = "commit-message";
103
+ const rule = builtinRules.commitMessage;
104
+ const ruleName = rule.id;
10
105
  const task = async (common) => {
11
106
  const { commits, scope } = await collectCommitSubjects(common.projectRoot, config.base);
12
107
  const violations = commits.filter((commit) => (config.forbiddenPrefixes ?? ["```"]).some((prefix) => commit.subject.startsWith(prefix)));
@@ -29,7 +124,10 @@ function commitMessage(config = {}) {
29
124
  howToFix: "修改对应提交 message,移除禁止的前缀。"
30
125
  };
31
126
  };
32
- return Object.assign(task, { displayName: ruleName });
127
+ return Object.assign(task, {
128
+ ...rule,
129
+ readme: { builtin: rule.id }
130
+ });
33
131
  }
34
132
  async function collectCommitSubjects(repoRoot, base) {
35
133
  const upstream = base ?? await readUpstream(repoRoot);
@@ -83,7 +181,8 @@ const SKIP_AST_KEYS$6 = /* @__PURE__ */ new Set([
83
181
  "trailingComments"
84
182
  ]);
85
183
  function duplicateLocalization(config) {
86
- const ruleName = "duplicate-localization";
184
+ const rule = builtinRules.duplicateLocalization;
185
+ const ruleName = rule.id;
87
186
  const task = async (common) => {
88
187
  const options = {
89
188
  ...config,
@@ -152,7 +251,10 @@ function duplicateLocalization(config) {
152
251
  howToFix: success ? "" : "Replace template literals with string literals, and unify duplicate keys to share a single default message."
153
252
  };
154
253
  };
155
- return Object.assign(task, { displayName: ruleName });
254
+ return Object.assign(task, {
255
+ ...rule,
256
+ readme: { builtin: rule.id }
257
+ });
156
258
  }
157
259
  async function collectSourceFiles$2(root, excludeDirs, skipDirNames = [
158
260
  "node_modules",
@@ -249,7 +351,8 @@ const SKIP_AST_KEYS$5 = /* @__PURE__ */ new Set([
249
351
  "trailingComments"
250
352
  ]);
251
353
  function syncLocales(config) {
252
- const ruleName = "sync-locales";
354
+ const rule = builtinRules.syncLocales;
355
+ const ruleName = rule.id;
253
356
  const task = async (common) => {
254
357
  const options = {
255
358
  ...config,
@@ -313,7 +416,10 @@ function syncLocales(config) {
313
416
  howToFix: howToFix.join(" ")
314
417
  };
315
418
  };
316
- return Object.assign(task, { displayName: ruleName });
419
+ return Object.assign(task, {
420
+ ...rule,
421
+ readme: { builtin: rule.id }
422
+ });
317
423
  }
318
424
  function mergeDefaultLocale(oldConfig, newLocale, metadataKey) {
319
425
  const result = {};
@@ -454,7 +560,8 @@ const ESM_SOURCE_EXTENSIONS = {
454
560
  ".jsx": [".tsx"]
455
561
  };
456
562
  function sameDirImportOnly(config) {
457
- const ruleName = "same-dir-import-only";
563
+ const rule = builtinRules.sameDirImportOnly;
564
+ const ruleName = rule.id;
458
565
  const task = async (common) => {
459
566
  const marker = config.marker ?? "@import-scope same-dir";
460
567
  const aliases = Object.entries(config.aliases ?? {}).sort(([a], [b]) => b.length - a.length).map(([prefix, target]) => [prefix, path.resolve(common.projectRoot, target)]);
@@ -503,7 +610,10 @@ function sameDirImportOnly(config) {
503
610
  howToFix: `Only import files marked with '${marker}' from files in the same directory, or move shared API into an unmarked file.`
504
611
  };
505
612
  };
506
- return Object.assign(task, { displayName: ruleName });
613
+ return Object.assign(task, {
614
+ ...rule,
615
+ readme: { builtin: rule.id }
616
+ });
507
617
  }
508
618
  async function collectSourceFiles(root, excludeDirs, skipDirNames = [
509
619
  "node_modules",
@@ -730,7 +840,8 @@ function formatLocation$3(repoRoot, file, line) {
730
840
  const CJK_PATTERN = /[\u4e00-\u9fff\u3400-\u4dbf\u3000-\u303f\uff00-\uffef]/;
731
841
  /** 本地化调用在代码中的默认文案必须使用源语言(不匹配 pattern),翻译放在语言文件中。 */
732
842
  function sourceLocaleDefaults(options) {
733
- const ruleName = "source-locale-defaults";
843
+ const rule = builtinRules.sourceLocaleDefaults;
844
+ const ruleName = rule.id;
734
845
  const task = async (context) => {
735
846
  const files = await collectFiles$3(context.projectRoot, options, [".ts", ".tsx"]);
736
847
  const findings = [];
@@ -764,7 +875,10 @@ function sourceLocaleDefaults(options) {
764
875
  howToFix: "默认文案改用源语言,其他语言的翻译写入语言文件。"
765
876
  };
766
877
  };
767
- return Object.assign(task, { displayName: ruleName });
878
+ return Object.assign(task, {
879
+ ...rule,
880
+ readme: { builtin: rule.id }
881
+ });
768
882
  }
769
883
  function matchCall(calls, callee) {
770
884
  if (!callee) return void 0;
@@ -885,7 +999,8 @@ function formatLocation$2(repoRoot, file, line) {
885
999
  // packages/conformance/rules/single-component-file/index.ts
886
1000
  /** 每个 TSX 文件只定义一个返回 JSX 的组件。 */
887
1001
  function singleComponentFile(options) {
888
- const ruleName = "single-component-file";
1002
+ const rule = builtinRules.singleComponentFile;
1003
+ const ruleName = rule.id;
889
1004
  const task = async (context) => {
890
1005
  const wrappers = new Set(options.componentWrappers ?? ["memo", "forwardRef"]);
891
1006
  const files = await collectFiles$2(context.projectRoot, options, [".tsx"]);
@@ -919,7 +1034,10 @@ function singleComponentFile(options) {
919
1034
  howToFix: "把多出的组件移到各自的 TSX 文件,每个文件只保留一个组件。"
920
1035
  };
921
1036
  };
922
- return Object.assign(task, { displayName: ruleName });
1037
+ return Object.assign(task, {
1038
+ ...rule,
1039
+ readme: { builtin: rule.id }
1040
+ });
923
1041
  }
924
1042
  function readComponentName(node, wrappers) {
925
1043
  if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") {
@@ -1064,7 +1182,8 @@ function formatLocation$1(repoRoot, file, line) {
1064
1182
  * 且 shared 与 utils 互不引用。
1065
1183
  */
1066
1184
  function e2eScenariosStructure(options) {
1067
- const ruleName = options.name ?? "e2e-scenarios-structure";
1185
+ const rule = builtinRules.e2eScenariosStructure;
1186
+ const ruleName = options.name ?? rule.id;
1068
1187
  const task = async (context) => {
1069
1188
  const repoRoot = context.projectRoot;
1070
1189
  const entrySuffix = options.entrySuffix ?? ".spec.ts";
@@ -1160,7 +1279,11 @@ function e2eScenariosStructure(options) {
1160
1279
  howToFix: success ? "" : `helper 移出入口文件:被 ${threshold} 个及以上入口使用的放到 ${sharedName},其余放到 ${utilsName}/<入口名>;${sharedName} 与 ${utilsName} 不要互相引用。`
1161
1280
  };
1162
1281
  };
1163
- return Object.assign(task, { displayName: ruleName });
1282
+ return Object.assign(task, {
1283
+ ...rule,
1284
+ displayName: options.name ?? rule.displayName,
1285
+ readme: { builtin: rule.id }
1286
+ });
1164
1287
  }
1165
1288
  function readFunctionName$1(node) {
1166
1289
  if (node.type === "FunctionDeclaration") return readName$1(node.id) ?? "匿名函数";
@@ -1300,7 +1423,8 @@ function formatLocation(repoRoot, file, line) {
1300
1423
  * 且 shared 与 utils 互不引用。
1301
1424
  */
1302
1425
  function uiScenariosStructure(options) {
1303
- const ruleName = options.name ?? "ui-scenarios-structure";
1426
+ const rule = builtinRules.uiScenariosStructure;
1427
+ const ruleName = options.name ?? rule.id;
1304
1428
  const task = async (context) => {
1305
1429
  const repoRoot = context.projectRoot;
1306
1430
  const entrySuffix = options.entrySuffix ?? ".ts";
@@ -1399,7 +1523,11 @@ function uiScenariosStructure(options) {
1399
1523
  howToFix: success ? "" : `helper 移出入口文件:被 ${threshold} 个及以上入口使用的放到 ${sharedName},其余放到 ${utilsName}/<入口名>;${sharedName} 与 ${utilsName} 不要互相引用。`
1400
1524
  };
1401
1525
  };
1402
- return Object.assign(task, { displayName: ruleName });
1526
+ return Object.assign(task, {
1527
+ ...rule,
1528
+ displayName: options.name ?? rule.displayName,
1529
+ readme: { builtin: rule.id }
1530
+ });
1403
1531
  }
1404
1532
  function readFunctionName(node) {
1405
1533
  if (node.type === "FunctionDeclaration") return readName(node.id) ?? "匿名函数";
@@ -1465,4 +1593,4 @@ function collectImports(source, prefix) {
1465
1593
  }
1466
1594
  return imports;
1467
1595
  }
1468
- export { CJK_PATTERN, commitMessage, duplicateLocalization, e2eScenariosStructure, sameDirImportOnly, singleComponentFile, sourceLocaleDefaults, syncLocales, uiScenariosStructure };
1596
+ export { CJK_PATTERN, baselineMaxDiffPixels, commitMessage, duplicateLocalization, e2eScenariosStructure, sameDirImportOnly, singleComponentFile, sourceLocaleDefaults, syncLocales, uiScenariosStructure };
@@ -1,4 +1,4 @@
1
- import { n as RuleResult, r as RuleTask, t as CommonConfig } from "./types-DHfARqti.js";
1
+ import { n as RuleResult, r as RuleTask, t as CommonConfig } from "./types--o0ku6ya.js";
2
2
  /** evidra.conformance.ts 的默认导出。 */
3
3
  interface Config {
4
4
  /** 默认配置文件所在目录;相对路径也基于配置文件所在目录。 */
@@ -22,6 +22,8 @@ interface Snapshot {
22
22
  contentType?: 'image/png';
23
23
  width?: number;
24
24
  height?: number;
25
+ /** PNG 像素与展示尺寸的倍率,默认 1。 */
26
+ scale?: number;
25
27
  /** 1–12,默认 4。 */
26
28
  col?: number;
27
29
  maxDiffPixels?: number;
@@ -39,6 +41,8 @@ interface Observation {
39
41
  contentType?: 'image/png';
40
42
  width?: number;
41
43
  height?: number;
44
+ /** PNG 像素与展示尺寸的倍率,默认 1。 */
45
+ scale?: number;
42
46
  /** 对象存储 key。 */
43
47
  key?: string;
44
48
  url?: string;
@@ -80,6 +84,7 @@ declare const CaseInputSchema: z.ZodObject<{
80
84
  type: z.ZodLiteral<"image">;
81
85
  body: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
82
86
  contentType: z.ZodLiteral<"image/png">;
87
+ scale: z.ZodOptional<z.ZodNumber>;
83
88
  maxDiffPixels: z.ZodOptional<z.ZodNumber>;
84
89
  }, z.core.$strip>], "type">>>;
85
90
  result: z.ZodObject<{
@@ -102,6 +107,7 @@ declare const CaseInputSchema: z.ZodObject<{
102
107
  type: z.ZodLiteral<"image">;
103
108
  body: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
104
109
  contentType: z.ZodLiteral<"image/png">;
110
+ scale: z.ZodOptional<z.ZodNumber>;
105
111
  }, z.core.$strip>], "type">>>;
106
112
  }, z.core.$strip>;
107
113
  type CaseInput = z.infer<typeof CaseInputSchema>;
package/dist/sdk/main.js CHANGED
@@ -133,6 +133,7 @@ const DateTimeSchema = z.iso.datetime({ offset: true });
133
133
  const TaskPathSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}\/\d{2}-\d{2}-\d{2}-[A-Za-z0-9-]+$/, "taskPath 必须是 <yyyy-MM-dd>/<HH-mm-ss>-<taskId>");
134
134
  // modules/core/contracts/functions/addCase.ts
135
135
  const BytesSchema = z.custom((value) => value instanceof Uint8Array, { message: "图片 body 必须是 Uint8Array" });
136
+ const ImageScaleSchema = z.number().min(1).optional();
136
137
  const TreeSegmentSchema = z.object({
137
138
  key: IdSchema,
138
139
  display: NameSchema
@@ -160,6 +161,7 @@ const SnapshotInputSchema = z.discriminatedUnion("type", [SnapshotMetaSchema.ext
160
161
  type: z.literal("image"),
161
162
  body: BytesSchema,
162
163
  contentType: z.literal("image/png"),
164
+ scale: ImageScaleSchema,
163
165
  maxDiffPixels: z.number({ error: "maxDiffPixels 仅支持图片,且必须是非负整数" }).int("maxDiffPixels 仅支持图片,且必须是非负整数").nonnegative("maxDiffPixels 仅支持图片,且必须是非负整数").optional()
164
166
  })]);
165
167
  const ObservationInputSchema = z.discriminatedUnion("type", [z.object({
@@ -171,7 +173,8 @@ const ObservationInputSchema = z.discriminatedUnion("type", [z.object({
171
173
  name: NameSchema,
172
174
  type: z.literal("image"),
173
175
  body: BytesSchema,
174
- contentType: z.literal("image/png")
176
+ contentType: z.literal("image/png"),
177
+ scale: ImageScaleSchema
175
178
  })]);
176
179
  const CaseInputSchema = z.object({
177
180
  id: IdSchema,
@@ -385,7 +388,8 @@ function toObservation(observation) {
385
388
  key: observation.key,
386
389
  contentType: observation.contentType,
387
390
  width: observation.width,
388
- height: observation.height
391
+ height: observation.height,
392
+ scale: observation.scale
389
393
  };
390
394
  }
391
395
  // modules/core/implementations/Utils/toSnapshot.ts
@@ -406,6 +410,7 @@ function toSnapshot(snapshot) {
406
410
  contentType: snapshot.contentType,
407
411
  width: snapshot.width,
408
412
  height: snapshot.height,
413
+ scale: snapshot.scale,
409
414
  maxDiffPixels: snapshot.maxDiffPixels,
410
415
  col: snapshot.col
411
416
  };
@@ -455,6 +460,7 @@ async function storeSnapshots(reportDir, namespace, caseId, inputs) {
455
460
  contentType: "image/png",
456
461
  width,
457
462
  height,
463
+ scale: input.scale,
458
464
  maxDiffPixels: input.maxDiffPixels,
459
465
  col: input.col
460
466
  });
@@ -491,7 +497,8 @@ async function storeObservations(reportDir, namespace, caseId, inputs) {
491
497
  key,
492
498
  contentType: "image/png",
493
499
  width,
494
- height
500
+ height,
501
+ scale: input.scale
495
502
  });
496
503
  }
497
504
  return observations;
@@ -1061,7 +1068,7 @@ async function compareSnapshot(cwd, storage, current, previous, diffPath, pool)
1061
1068
  result.contentSame = contentSame;
1062
1069
  if (tolerance !== (previous.maxDiffPixels ?? 0)) contentSame = false;
1063
1070
  } else if (current.type === "text" && previous.type === "text") result.contentSame = contentSame;
1064
- const metadataSame = currentSnapshot.name === previous.name && currentSnapshot.type === previous.type && currentSnapshot.language === previous.language && currentSnapshot.contentType === previous.contentType && (currentSnapshot.col ?? 4) === (previous.col ?? 4) && (currentSnapshot.maxDiffPixels ?? previous.maxDiffPixels ?? 0) === (previous.maxDiffPixels ?? 0);
1071
+ const metadataSame = currentSnapshot.name === previous.name && currentSnapshot.type === previous.type && currentSnapshot.language === previous.language && currentSnapshot.contentType === previous.contentType && (currentSnapshot.scale ?? 1) === (previous.scale ?? 1) && (currentSnapshot.col ?? 4) === (previous.col ?? 4) && (currentSnapshot.maxDiffPixels ?? previous.maxDiffPixels ?? 0) === (previous.maxDiffPixels ?? 0);
1065
1072
  result.change = contentSame && metadataSame ? "same" : "modified";
1066
1073
  return result;
1067
1074
  }
@@ -1,4 +1,11 @@
1
- import { r as RuleTask } from "./types-DHfARqti.js";
1
+ import { r as RuleTask } from "./types--o0ku6ya.js";
2
+ interface BaselineMaxDiffPixelsOptions {
3
+ /** 基线文件目录,支持绝对路径或相对 projectRoot 的路径。 */
4
+ baselineDir: string;
5
+ /** 每张基线图片允许配置的最大差异像素数。 */
6
+ maxDiffPixels: number;
7
+ }
8
+ export declare function baselineMaxDiffPixels(options: BaselineMaxDiffPixelsOptions): RuleTask;
2
9
  /** Git 提交标题检查配置。 */
3
10
  interface CommitMessageOptions {
4
11
  /** 禁止的提交标题前缀,默认 ["```"];传入空数组时不限制前缀。 */
@@ -146,4 +153,4 @@ interface UiScenariosStructureOptions {
146
153
  * 且 shared 与 utils 互不引用。
147
154
  */
148
155
  export declare function uiScenariosStructure(options: UiScenariosStructureOptions): RuleTask;
149
- export type { CommitMessageOptions, DuplicateLocalizationOptions, E2eScenariosStructureOptions, LocalizationCall, SameDirImportOnlyOptions, SingleComponentFileOptions, SourceLocaleDefaultsOptions, SyncLocalesOptions, UiScenariosStructureOptions };
156
+ export type { BaselineMaxDiffPixelsOptions, CommitMessageOptions, DuplicateLocalizationOptions, E2eScenariosStructureOptions, LocalizationCall, SameDirImportOnlyOptions, SingleComponentFileOptions, SourceLocaleDefaultsOptions, SyncLocalesOptions, UiScenariosStructureOptions };
@@ -9,7 +9,13 @@ interface CommonConfig {
9
9
  readonly projectRoot: string;
10
10
  }
11
11
  type RuleTask = ((commonConfig: CommonConfig) => Promise<RuleResult>) & {
12
+ /** 规约的稳定 ID,报告按此归并同一规约的配置。 */
13
+ readonly id?: string;
12
14
  /** 用于在执行前展示规则名称。 */
13
15
  readonly displayName?: string;
16
+ /** 相对于配置文件的 Markdown 路径,或内置规约文档的目录名。 */
17
+ readonly readme?: string | {
18
+ readonly builtin: string;
19
+ };
14
20
  };
15
21
  export { RuleResult as n, RuleTask as r, CommonConfig as t };