gatelight 0.0.0-stage → 0.18.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 (109) hide show
  1. package/.antigravity-plugin/plugin.json +9 -0
  2. package/.claude-plugin/plugin.json +11 -0
  3. package/.codex-plugin/plugin.json +18 -0
  4. package/.mcp.json +8 -0
  5. package/LICENSE +21 -0
  6. package/README.md +29 -2
  7. package/bin/modwall +8 -0
  8. package/bin/node.sh +14 -0
  9. package/bin/testcraft +8 -0
  10. package/bin/testpace +8 -0
  11. package/entry/command +44 -0
  12. package/hooks/antigravity.sh +24 -0
  13. package/hooks/codex.json +50 -0
  14. package/hooks/codex.sh +7 -0
  15. package/hooks/hooks.json +43 -0
  16. package/hooks/testpace.ts +25 -0
  17. package/hooks.json +16 -0
  18. package/mcp_config.json +8 -0
  19. package/package.json +23 -4
  20. package/setup.mjs +99 -0
  21. package/skills/merge/SKILL.md +42 -0
  22. package/skills/modular/SKILL.md +75 -0
  23. package/skills/setup/SKILL.md +101 -0
  24. package/skills/setup-modwall/SKILL.md +112 -0
  25. package/skills/setup-testcraft/SKILL.md +23 -0
  26. package/skills/setup-testcraft/checklist/dev-login.md +20 -0
  27. package/skills/write-tests/SKILL.md +153 -0
  28. package/src/base/agent.ts +100 -0
  29. package/src/base/baseline.ts +54 -0
  30. package/src/base/commandline.ts +40 -0
  31. package/src/base/commands.ts +94 -0
  32. package/src/base/confirm.ts +161 -0
  33. package/src/base/contract.ts +94 -0
  34. package/src/base/coverage.ts +46 -0
  35. package/src/base/entry.ts +90 -0
  36. package/src/base/excerpt.ts +46 -0
  37. package/src/base/execute.ts +70 -0
  38. package/src/base/exit.ts +6 -0
  39. package/src/base/format.ts +27 -0
  40. package/src/base/full.ts +160 -0
  41. package/src/base/gate.ts +251 -0
  42. package/src/base/git.ts +361 -0
  43. package/src/base/glob.ts +38 -0
  44. package/src/base/hook.ts +297 -0
  45. package/src/base/hookformat.ts +257 -0
  46. package/src/base/judging.ts +27 -0
  47. package/src/base/layermap.ts +69 -0
  48. package/src/base/module.ts +88 -0
  49. package/src/base/process-group.ts +101 -0
  50. package/src/base/records.ts +66 -0
  51. package/src/base/repo.ts +155 -0
  52. package/src/base/sessions.ts +55 -0
  53. package/src/base/shell.ts +176 -0
  54. package/src/base/stop.ts +100 -0
  55. package/src/base/store.ts +348 -0
  56. package/src/base/version.ts +24 -0
  57. package/src/cli.ts +186 -0
  58. package/src/craft/change.ts +24 -0
  59. package/src/craft/checklist.ts +157 -0
  60. package/src/craft/commands.ts +111 -0
  61. package/src/craft/config.ts +15 -0
  62. package/src/craft/full.ts +30 -0
  63. package/src/craft/index.ts +12 -0
  64. package/src/craft/session.ts +21 -0
  65. package/src/mcp.ts +79 -0
  66. package/src/modules.ts +10 -0
  67. package/src/modwall.ts +8 -0
  68. package/src/pace/commands.ts +281 -0
  69. package/src/pace/config.ts +103 -0
  70. package/src/pace/consent.ts +81 -0
  71. package/src/pace/focused.ts +208 -0
  72. package/src/pace/full.ts +38 -0
  73. package/src/pace/index.ts +16 -0
  74. package/src/pace/record.ts +84 -0
  75. package/src/pace/report.ts +335 -0
  76. package/src/pace/results.ts +243 -0
  77. package/src/pace/run/node-test-reporter.mjs +34 -0
  78. package/src/pace/run/node-test.ts +26 -0
  79. package/src/pace/run/playwright-reporter.mjs +48 -0
  80. package/src/pace/run/playwright.ts +34 -0
  81. package/src/pace/run/runner.ts +157 -0
  82. package/src/pace/run/targets.ts +130 -0
  83. package/src/pace/run/vitest-launcher.mjs +101 -0
  84. package/src/pace/run/vitest.ts +22 -0
  85. package/src/pace/session.ts +35 -0
  86. package/src/pace/testlist.ts +91 -0
  87. package/src/pace/tests.ts +22 -0
  88. package/src/pace/verify.ts +95 -0
  89. package/src/testcraft.ts +9 -0
  90. package/src/wall/check.ts +258 -0
  91. package/src/wall/commands.ts +279 -0
  92. package/src/wall/config.ts +394 -0
  93. package/src/wall/database.ts +136 -0
  94. package/src/wall/dbcheck.ts +389 -0
  95. package/src/wall/dbrules.ts +213 -0
  96. package/src/wall/edit.ts +64 -0
  97. package/src/wall/files.ts +35 -0
  98. package/src/wall/full.ts +30 -0
  99. package/src/wall/index.ts +15 -0
  100. package/src/wall/init.ts +149 -0
  101. package/src/wall/layermap.ts +124 -0
  102. package/src/wall/layout.ts +231 -0
  103. package/src/wall/loosen.ts +157 -0
  104. package/src/wall/miniprogram.ts +80 -0
  105. package/src/wall/project.ts +88 -0
  106. package/src/wall/rules.ts +400 -0
  107. package/src/wall/session.ts +198 -0
  108. package/src/wall/sql.ts +510 -0
  109. package/src/wall/store.ts +39 -0
@@ -0,0 +1,208 @@
1
+ // testpace focused 的选测:问 layermap 这次改动的相关测试,只从整组的测试(tests 规则找到的)里选,
2
+ // 再问选出的测试跑不跑得到每处改动,判断选得靠不靠得住。靠不住的时候不假装选准了,提示跑整组。
3
+ // layermap 按命名惯例认测试,和项目的 tests 规则不一定一致:规则排除的、规则外的练习脚本它也会给,
4
+ // 规则里不按惯例命名的它认不出。哪些算测试以 tests 规则为准,和整组一致。
5
+
6
+ import { layermap, LAYERMAP_COMMAND, type LayermapFailure, tooOld } from '../base/layermap.ts'
7
+
8
+ /**
9
+ * layermap 的 rank:0 到 1 以下调用改动,1 是改动里的测试,2 直接导入改动,3 同模块或同目录,
10
+ * 3.5 可能通过测试支持文件或类型不明的对象用到,4 间接导入。
11
+ * 在默认分支上 4 以下都跑(INDIRECT_RANK)。在分支上只跑直接相关的,3 以下(NEARBY_RANK):同模块、同目录、
12
+ * 可能经支持文件用到的那些常常是小半个整组,留给合回默认分支时的整组——开发要轻,合并兜底。
13
+ * 在分支上还有个数上限(BRANCH_CAP):这次改到的测试都跑,其余相关的按 rank 从近到远最多再跑这么多个文件。
14
+ * 测试都经接口、页面去测的项目里,"请求了改动波及的接口"的测试很多只是拿那个接口造数据,一次能选中大半个整组,
15
+ * rank 分不出谁在专门测它。同一档里怎么取见 nearest:看每条理由被多少个测试共用,共用少的先取,共用太多的只留一个代表。
16
+ * 选得准不准不看 rank,看选出的测试跑不跑得到每处改动(untested)。
17
+ */
18
+ export const INDIRECT_RANK = 4
19
+ export const NEARBY_RANK = 3
20
+ export const BRANCH_CAP = 8
21
+ /** rank 在这以下的是调用改动的测试:一定跑得到改动,不看它的理由被多少个测试共用。 */
22
+ export const CALLS_RANK = 1
23
+
24
+ /** layermap check --json 里 testpace 用到的部分。 */
25
+ export interface LayermapCheck {
26
+ files: Array<{ path: string; status: string }>
27
+ tests: Array<{ path: string; rank: number; why: string }>
28
+ unmapped: Array<{ path: string; kind: string }>
29
+ /** 检查自己没做完的地方(追踪到上限、搜索超时、路径读不了等),漏掉的测试可能就在那里。layermap 0.1.41 起。 */
30
+ incomplete: string[]
31
+ }
32
+
33
+ /** layermap check --json 给了测试文件时:这些测试跑不到的改动。 */
34
+ export interface Untested {
35
+ changed: string[]
36
+ truncated: boolean
37
+ }
38
+
39
+ export type Selection =
40
+ /** missing:PATH 里没有 layermap 命令(不是它出错)。 */
41
+ | { kind: 'unavailable'; reason: string; missing?: true }
42
+ | {
43
+ kind: 'selected'
44
+ changed: string[]
45
+ /** 改动只涉及 ignore 路径和整组不跑的测试(规则外的、删掉的),也没有整组的测试和它们相关:不用跑测试。 */
46
+ nothingToTest: boolean
47
+ tests: string[]
48
+ /** 整组里和改动有关、却没选上的测试文件数(间接导入的;在分支上还有同模块、同目录的,超出个数上限的,和理由被太多测试共用、没当上代表的)。 */
49
+ indirect: number
50
+ /** layermap 认为相关、但不在 tests 规则里的测试文件,没选。 */
51
+ outside: string[]
52
+ unmapped: Array<{ path: string; kind: string }>
53
+ incomplete: string[]
54
+ /** 选出的测试跑不到的改动;没选出测试时为 null。 */
55
+ untested: Untested | null
56
+ }
57
+
58
+ const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value)
59
+
60
+ /** 从 layermap check --json 的输出里读选测要的部分;缺字段(layermap 版本太旧)返回 undefined。 */
61
+ export function parseCheck(value: unknown): LayermapCheck | undefined {
62
+ if (!isRecord(value)) return undefined
63
+ if (!Array.isArray(value.files) || !Array.isArray(value.tests) || !Array.isArray(value.unmapped) || !Array.isArray(value.incomplete)) return undefined
64
+ return value as unknown as LayermapCheck
65
+ }
66
+
67
+ /** 给了测试文件时输出里的 untested;没有(layermap 版本太旧)返回 undefined。 */
68
+ export function parseUntested(value: unknown): Untested | undefined {
69
+ const untested = isRecord(value) ? value.untested : undefined
70
+ if (!isRecord(untested) || !Array.isArray(untested.changed) || typeof untested.truncated !== 'boolean') return undefined
71
+ return { changed: untested.changed as string[], truncated: untested.truncated }
72
+ }
73
+
74
+ /**
75
+ * 从候选的相关测试里最多取 cap 个文件,按 rank 从近到远。同一档里看 layermap 给的理由(why)被多少个候选共用:
76
+ * 共用得少的,多半是专门测那处改动的;几十个测试共用的(比如都请求了"新建人员"),多半只是拿它造数据。
77
+ * 所以每条理由先各取一个(共用少的在前),保证每处改动都有测试碰到;再取各条理由的第二个、第三个。
78
+ * 共用的测试超过 cap 个的理由只留那一个代表:名额凑不满就不凑,不拿造数据的测试填。
79
+ * 调用改动的测试(CALLS_RANK 以下)不受这条限制。cap 不限时(默认分支上)候选全取。
80
+ * 这是推断:layermap 对每个测试只给最近的一条理由,真在测这处改动的测试被归到共用多的理由下,就可能取不到,留给整组。
81
+ */
82
+ function nearest(candidates: LayermapCheck['tests'], cap: number): string[] {
83
+ const shared = new Map<string, number>()
84
+ const picks = candidates.map(test => {
85
+ const turn = shared.get(test.why) ?? 0
86
+ shared.set(test.why, turn + 1)
87
+ return { ...test, turn }
88
+ })
89
+ const sharedBy = (why: string): number => shared.get(why) ?? 0
90
+ return picks
91
+ .filter(test => test.turn === 0 || test.rank < CALLS_RANK || sharedBy(test.why) <= cap)
92
+ .sort((a, b) => a.rank - b.rank || a.turn - b.turn || sharedBy(a.why) - sharedBy(b.why))
93
+ .slice(0, cap)
94
+ .map(test => test.path)
95
+ }
96
+
97
+ /**
98
+ * 从 layermap 的结果里选要跑的测试文件。suite 是整组的测试(tests 规则在工作区里找到的,和整组同一份),
99
+ * inRules 判断路径在不在 tests 规则里(删掉的文件不在 suite 里,用它认出删掉的是不是整组的测试)。
100
+ * 选 layermap 给的相关测试里在整组的,再加上这次改到、在整组里的测试文件(不按惯例命名的 layermap 认不出)。
101
+ * limit 是选到哪一档为止(不含):默认分支上是 INDIRECT_RANK,分支上是 NEARBY_RANK。
102
+ * cap 是这次改到的测试以外最多再选几个文件(怎么取见 nearest):默认分支上不限,分支上是 BRANCH_CAP。
103
+ */
104
+ export function select(
105
+ check: LayermapCheck,
106
+ isIgnored: (path: string) => boolean,
107
+ suite: ReadonlySet<string>,
108
+ inRules: (path: string) => boolean,
109
+ limit: number = INDIRECT_RANK,
110
+ cap: number = Infinity,
111
+ ): Selection {
112
+ const changed = check.files.map(file => file.path)
113
+ const related = check.tests.filter(test => test.rank < limit).map(test => test.path)
114
+ // 这次改到的测试都跑;其余相关的最多再取 cap 个
115
+ const mine = new Set(changed.filter(path => suite.has(path)))
116
+ const kept = new Set([...mine, ...nearest(check.tests.filter(test => test.rank < limit && suite.has(test.path) && !mine.has(test.path)), cap)])
117
+ const tests = [...new Set([...related, ...changed])].filter(path => kept.has(path))
118
+ const outside = [...new Set(related.filter(path => !suite.has(path)))]
119
+ // 整组不跑的测试的改动,和 ignore 路径一样不用测:layermap 当成测试、规则又不收的(规则排除的测试、练习脚本),
120
+ // 和删掉的整组测试(layermap 不列删掉的文件)
121
+ const notRun = new Set([
122
+ ...check.tests.filter(test => !suite.has(test.path)).map(test => test.path),
123
+ ...check.files.filter(file => file.status === 'DELETED' && inRules(file.path)).map(file => file.path),
124
+ ])
125
+ return {
126
+ kind: 'selected',
127
+ changed,
128
+ nothingToTest: tests.length === 0 && changed.every(path => isIgnored(path) || notRun.has(path)),
129
+ tests,
130
+ indirect: new Set(check.tests.filter(test => suite.has(test.path) && !kept.has(test.path)).map(test => test.path)).size,
131
+ outside,
132
+ // ignore 里的文件约定不影响测试,地图跟不到它们也无妨
133
+ unmapped: check.unmapped.filter(file => !isIgnored(file.path)),
134
+ incomplete: check.incomplete,
135
+ untested: null,
136
+ }
137
+ }
138
+
139
+ /**
140
+ * 找不到 layermap 时告诉 agent 怎么补上。只在命令输出里说:插件的 bin/ 只在 Bash 工具的 PATH 里,
141
+ * hook 进程查不到,会话开始时没法准确判断装没装。
142
+ */
143
+ export const LAYERMAP_HINT = `装上 layermap 插件并开新会话(${LAYERMAP_COMMAND}),focused 就会只跑和改动相关的测试。`
144
+
145
+ /** 列出前几个,多的说一共几个:a、b、c 等 5 个。 */
146
+ export function someOf(items: string[], unit: string, shown = 3): string {
147
+ const more = items.length > shown ? ` 等 ${items.length} ${unit}` : ''
148
+ return `${items.slice(0, shown).join('、')}${more}`
149
+ }
150
+
151
+ /** layermap 认为相关、但不在 tests 规则里的测试:点出是哪几个,让 agent 判断是不是规则漏了。没有时为 undefined。 */
152
+ export function outsideNote(selection: Selection): string | undefined {
153
+ if (selection.kind !== 'selected' || selection.outside.length === 0) return undefined
154
+ return `不在 tests 规则里、没选的:${someOf(selection.outside, '个')}。是测试的话整组永远跑不到它,该补进 tests 规则;练习脚本、有意排除的不用管。`
155
+ }
156
+
157
+ /** 选测靠不住、应当跑整组的原因;空数组表示选测可以信。 */
158
+ export function fullReasons(selection: Selection): string[] {
159
+ if (selection.kind === 'unavailable') return [selection.reason]
160
+ if (selection.nothingToTest) return []
161
+ const reasons: string[] = []
162
+ if (selection.unmapped.length > 0) {
163
+ reasons.push(`改了 ${someOf(selection.unmapped.map(file => `${file.path}(${file.kind})`), '个')},地图跟不到它们影响哪些测试`)
164
+ }
165
+ if (selection.incomplete.length > 0) reasons.push(`layermap 这次检查没做完,可能漏选测试:${selection.incomplete.join(';')}`)
166
+ if (selection.tests.length === 0) {
167
+ const outside = selection.outside.length ? `(它找到的 ${selection.outside.length} 个都不在 tests 规则里,见上)` : ''
168
+ reasons.push(`layermap 没找到和这次改动相关的测试${outside}`)
169
+ }
170
+ const untested = selection.untested
171
+ if (untested && untested.changed.length > 0) {
172
+ reasons.push(`选出的测试跑不到 ${someOf(untested.changed, '处')}`)
173
+ }
174
+ // 选测时已经没做完的,确认时多半也一样,不重复说
175
+ if (untested?.truncated && selection.incomplete.length === 0) reasons.push('确认选出的测试跑不跑得到改动时,layermap 追踪到上限就停了')
176
+ return reasons
177
+ }
178
+
179
+ /**
180
+ * 问 layermap 这次改动(相对 base)的相关测试;选出了测试,再把它们交给 layermap,问哪些改动它们跑不到。
181
+ * 调 layermap 走底座的那一处(base/layermap.ts)。拿不到事实(找不到命令、它出错、版本太旧)就是选不了,退回建议跑整组。
182
+ */
183
+ export function askLayermap(
184
+ root: string,
185
+ base: string,
186
+ isIgnored: (path: string) => boolean,
187
+ suite: ReadonlySet<string>,
188
+ inRules: (path: string) => boolean,
189
+ limit: number = INDIRECT_RANK,
190
+ cap: number = Infinity,
191
+ ): Selection {
192
+ const unavailable = (failure: LayermapFailure): Selection =>
193
+ failure.kind === 'missing' ? { kind: 'unavailable', reason: '找不到 layermap 命令,没法按改动选测试', missing: true } : { kind: 'unavailable', reason: failure.problem }
194
+ const args = ['check', '--json', '--base', base]
195
+ const first = layermap(root, args)
196
+ if (!first.ok) return unavailable(first)
197
+ const check = parseCheck(first.value)
198
+ if (!check) return unavailable(tooOld())
199
+ const selection = select(check, isIgnored, suite, inRules, limit, cap)
200
+ if (selection.kind === 'selected' && selection.tests.length > 0) {
201
+ const second = layermap(root, [...args, ...selection.tests])
202
+ if (!second.ok) return unavailable(second)
203
+ const untested = parseUntested(second.value)
204
+ if (!untested) return unavailable(tooOld())
205
+ selection.untested = untested
206
+ }
207
+ return selection
208
+ }
@@ -0,0 +1,38 @@
1
+ // 整组里"跑测试"的部分(base/module.ts 的 fullPart):测试以外的检查(full),再把 tests 规则找到的全部测试文件交给 files。
2
+ // 测试由这里按规则找出来,不靠谁记得把新测试加进整组。跑完读回每个测试的结果:记下没过的,认时好时坏和几轮没过的。
3
+
4
+ import type { FullPart } from '../base/module.ts'
5
+ import type { Repo } from '../base/repo.ts'
6
+ import { loadConfig } from './config.ts'
7
+ import { unconfirmedChanges } from './consent.ts'
8
+ import type { PaceRun } from './record.ts'
9
+ import { FULL_STEP, TESTS_STEP } from './report.ts'
10
+ import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile } from './results.ts'
11
+ import { findTests } from './tests.ts'
12
+
13
+ export function fullPart(repo: Repo): FullPart | { problem: string } {
14
+ const { config, problems } = loadConfig(repo.root)
15
+ if (!config?.full || !config.files || problems.length > 0) return { problem: problems.join(';') }
16
+ const tests = findTests(repo.root, config.tests)
17
+ if (tests.length === 0) return { problem: `按 tests 规则(${config.tests.join('、')})在工作区里没找到测试文件。` }
18
+ // 这次改动改了命令、缩小了找测试的范围:用户同意过才跑(不然通过记录是按放松过的办法得来的)
19
+ const unconfirmed = unconfirmedChanges(repo)
20
+ if (unconfirmed) return { problem: unconfirmed }
21
+ const resultsAt = resultsFile()
22
+ return {
23
+ steps: [
24
+ { kind: 'full', name: FULL_STEP, title: FULL_STEP, header: `${FULL_STEP}:${config.full}`, command: config.full, args: [] },
25
+ { kind: 'tests', name: TESTS_STEP, title: `${TESTS_STEP}(${tests.length} 个文件)`, header: `${TESTS_STEP}(${tests.length} 个文件):${config.files}`, command: config.files, args: tests },
26
+ ],
27
+ summary: `${tests.length} 个测试文件`,
28
+ env: { [RESULTS_ENV]: resultsAt.path },
29
+ finish() {
30
+ const results = readResults(resultsAt.path, repo.root)
31
+ return {
32
+ fields: { tests: tests.length, ...(results.length > 0 ? { failed: failedTests(results) } : {}) },
33
+ notes: (record, before) => noteResults(repo, { record: record as PaceRun, results, before: before as PaceRun[], whole: tests }),
34
+ }
35
+ },
36
+ dispose: () => resultsAt.dispose(),
37
+ }
38
+ }
@@ -0,0 +1,16 @@
1
+ // "跑测试"这个检查模块交给底座的入口(见 base/module.ts):底座只通过这里知道它。
2
+
3
+ import type { Module } from '../base/module.ts'
4
+ import { contractProblems, FIELDS } from './config.ts'
5
+ import { fullPart } from './full.ts'
6
+ import { alerts, fullCommandHint, rhythm } from './session.ts'
7
+
8
+ export const pace: Module = {
9
+ name: 'pace',
10
+ fields: FIELDS,
11
+ contractProblems,
12
+ brief: rhythm,
13
+ alerts,
14
+ beforeCommand: fullCommandHint,
15
+ fullPart,
16
+ }
@@ -0,0 +1,84 @@
1
+ // "跑测试"自己的运行记录:底座的记录(base/store.ts 的 RunRecord)加上这个模块的字段;跑 fast、files 并记一条。
2
+
3
+ import { type Repo, runClaimed, runner } from '../base/repo.ts'
4
+ import type { Execution } from '../base/execute.ts'
5
+ import { currentBranch, headCommit, workTreeId } from '../base/git.ts'
6
+ import type { RunningMarker, RunRecord, Store } from '../base/store.ts'
7
+ import type { CommandKey } from './config.ts'
8
+ import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile, type TestResult, wholeFiles } from './results.ts'
9
+ import type { TestId } from './testlist.ts'
10
+
11
+ /** 这个模块跑的命令的记录:fast、files,和整组(full,底座跑的,带着这个模块加的字段)。 */
12
+ export interface PaceRun extends RunRecord {
13
+ kind: CommandKey
14
+ /** files 命令的参数:测试文件,或 文件:行号。 */
15
+ files?: string[]
16
+ /** 整组:tests 规则找到、交给 files 跑的测试文件数。 */
17
+ tests?: number
18
+ /** 没过的测试(经 testpace run 跑、交回了每个测试结果的才有)。 */
19
+ failed?: TestId[]
20
+ /** testpace files --repeat 连跑的第几次(从 1 起)、共几次。 */
21
+ repeat?: { index: number; of: number }
22
+ }
23
+
24
+ /** 全部运行记录,按这个模块的字段读。 */
25
+ export function paceRuns(store: Store): PaceRun[] {
26
+ return store.readRuns() as PaceRun[]
27
+ }
28
+
29
+ export interface Recorded {
30
+ /** 这次运行的记录;被中断(execution.interrupted)的不写进记录。 */
31
+ record: PaceRun
32
+ execution: Execution
33
+ /** 命令里的 testpace run 交回的每个测试的结果;没经 testpace run 跑的为空。 */
34
+ results: TestResult[]
35
+ /** 看这些结果要说给 agent 的话:时好时坏、几轮没过(见 results.ts)。 */
36
+ notes: string[]
37
+ }
38
+
39
+ /**
40
+ * 跑 fast 或 files 并记一条记录(见 runClaimed),收回每个测试的结果、看有没有时好时坏和几轮没过的(见 results.ts)。
41
+ * 跑完重算一次代码(treeAtEnd):认时好时坏要"同一份代码",跑的过程中代码改过的不算。通过记录只认 full。
42
+ */
43
+ export async function runRecorded(
44
+ repo: Repo,
45
+ kind: Exclude<CommandKey, 'full'>,
46
+ command: string,
47
+ args: string[],
48
+ tree: string,
49
+ options: { repeat?: PaceRun['repeat']; passedEarlier?: Map<string, string> } = {},
50
+ ): Promise<Recorded | { busy: RunningMarker }> {
51
+ const file = resultsFile()
52
+ try {
53
+ const run = await runClaimed(repo, kind, command, args, tree, { [RESULTS_ENV]: file.path })
54
+ if ('busy' in run) return run
55
+ const { id, startedAt, log, execution } = run
56
+ const results = execution.interrupted ? [] : readResults(file.path, repo.root)
57
+ const failed = failedTests(results)
58
+ const record: PaceRun = {
59
+ id,
60
+ kind,
61
+ worktree: repo.root,
62
+ branch: currentBranch(repo.root),
63
+ head: headCommit(repo.root),
64
+ tree,
65
+ treeAtEnd: execution.interrupted ? tree : workTreeId(repo.root),
66
+ startedAt,
67
+ durationMs: execution.durationMs,
68
+ exitCode: execution.exitCode,
69
+ result: execution.exitCode === 0 ? 'pass' : 'fail',
70
+ ...(kind === 'files' ? { files: args } : {}),
71
+ ...(results.length > 0 ? { failed } : {}),
72
+ ...(options.repeat ? { repeat: options.repeat } : {}),
73
+ ...runner(),
74
+ log,
75
+ }
76
+ if (execution.interrupted) return { record, execution, results, notes: [] }
77
+ const before = paceRuns(repo.store)
78
+ repo.store.appendRun(record)
79
+ const notes = noteResults(repo, { record, results, before, whole: wholeFiles(args), ...(options.passedEarlier ? { passedEarlier: options.passedEarlier } : {}) })
80
+ return { record, execution, results, notes }
81
+ } finally {
82
+ file.dispose()
83
+ }
84
+ }