gatelight 0.19.2 → 0.39.1

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 (62) hide show
  1. package/.antigravity-plugin/plugin.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/README.md +2 -2
  5. package/package.json +1 -1
  6. package/skills/merge/SKILL.md +1 -1
  7. package/skills/modular/SKILL.md +6 -6
  8. package/skills/setup/SKILL.md +2 -2
  9. package/skills/setup-codekeep/SKILL.md +61 -17
  10. package/skills/setup-codekeep/frontend.eslint.mjs +285 -0
  11. package/skills/setup-modwall/SKILL.md +10 -11
  12. package/skills/setup-testcraft/SKILL.md +9 -3
  13. package/skills/setup-testcraft/checklist/dev-login.md +3 -3
  14. package/skills/setup-testcraft/checklist/same-number.md +26 -0
  15. package/skills/write-tests/SKILL.md +13 -12
  16. package/src/base/baseline.ts +2 -2
  17. package/src/base/commands.ts +2 -40
  18. package/src/base/execute.ts +1 -11
  19. package/src/base/exit.ts +1 -1
  20. package/src/base/full.ts +15 -11
  21. package/src/base/git.ts +34 -3
  22. package/src/base/hook.ts +71 -17
  23. package/src/base/hookformat.ts +16 -6
  24. package/src/base/module.ts +9 -7
  25. package/src/base/repo.ts +8 -34
  26. package/src/base/sessions.ts +45 -13
  27. package/src/base/shell.ts +18 -10
  28. package/src/base/stop.ts +20 -6
  29. package/src/base/store.ts +15 -30
  30. package/src/cli.ts +3 -16
  31. package/src/craft/commands.ts +7 -1
  32. package/src/craft/defaults.ts +59 -0
  33. package/src/craft/session.ts +8 -4
  34. package/src/keep/check.ts +78 -39
  35. package/src/keep/config.ts +56 -26
  36. package/src/keep/eslint.ts +130 -5
  37. package/src/keep/loosen.ts +11 -61
  38. package/src/keep/session.ts +19 -5
  39. package/src/keep/styles.ts +72 -0
  40. package/src/pace/commands.ts +9 -3
  41. package/src/pace/full.ts +16 -6
  42. package/src/pace/index.ts +3 -0
  43. package/src/pace/record.ts +12 -6
  44. package/src/pace/results.ts +43 -2
  45. package/src/pace/run/playwright-reporter.mjs +5 -4
  46. package/src/pace/run/runner.ts +13 -7
  47. package/src/pace/run/targets.ts +3 -2
  48. package/src/pace/session.ts +3 -3
  49. package/src/pace/unfinished.ts +87 -0
  50. package/src/pace/unmerged.ts +87 -0
  51. package/src/pace/verify.ts +2 -2
  52. package/src/wall/commands.ts +94 -26
  53. package/src/wall/database.ts +12 -1
  54. package/src/wall/dbcheck.ts +2 -2
  55. package/src/wall/dbrules.ts +60 -19
  56. package/src/wall/full.ts +6 -1
  57. package/src/wall/literals.ts +162 -0
  58. package/src/wall/migrate.ts +248 -0
  59. package/src/wall/project.ts +29 -9
  60. package/src/wall/receipt.ts +74 -0
  61. package/src/wall/session.ts +5 -5
  62. package/src/wall/store.ts +3 -1
package/src/pace/full.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // 整组里"跑测试"的部分(base/module.ts 的 fullPart):测试以外的检查(full),再把 tests 规则找到的全部测试文件交给 files。
2
- // 测试由这里按规则找出来,不靠谁记得把新测试加进整组。跑完读回每个测试的结果:记下没过的,认时好时坏和几轮没过的。
2
+ // 测试由这里按规则找出来,不靠谁记得把新测试加进整组。跑完读回每个测试的结果:记下没过的,认时好时坏和几轮没过的;
3
+ // 交给 files 的文件有没交回结果的(results.ts 的 unreported),各段都过了的整组算没过,全部测试那一段没过的照样点名。
3
4
 
4
5
  import type { FullPart } from '../base/module.ts'
5
6
  import type { Repo } from '../base/repo.ts'
@@ -7,7 +8,7 @@ import { loadConfig } from './config.ts'
7
8
  import { unconfirmedChanges } from './consent.ts'
8
9
  import type { PaceRun } from './record.ts'
9
10
  import { FULL_STEP, TESTS_STEP } from './report.ts'
10
- import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile } from './results.ts'
11
+ import { failedTests, noteResults, reached, readResults, RESULTS_ENV, resultsFile, unreported, unreportedText } from './results.ts'
11
12
  import { findTests } from './tests.ts'
12
13
 
13
14
  export function fullPart(repo: Repo): FullPart | { problem: string } {
@@ -19,18 +20,27 @@ export function fullPart(repo: Repo): FullPart | { problem: string } {
19
20
  const unconfirmed = unconfirmedChanges(repo)
20
21
  if (unconfirmed) return { problem: unconfirmed }
21
22
  const resultsAt = resultsFile()
23
+ const files = config.files
22
24
  return {
23
25
  steps: [
24
26
  { 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 },
27
+ { kind: 'tests', name: TESTS_STEP, title: `${TESTS_STEP}(${tests.length} 个文件)`, header: `${TESTS_STEP}(${tests.length} 个文件):${files}`, command: files, args: tests },
26
28
  ],
27
29
  summary: `${tests.length} 个测试文件`,
28
30
  env: { [RESULTS_ENV]: resultsAt.path },
29
- finish() {
31
+ finish(failedStep) {
30
32
  const results = readResults(resultsAt.path, repo.root)
33
+ // 全部测试那一段跑了(过了,或它自己没过)才核对;前面的段没过,测试没跑,核对不出什么
34
+ const ran = failedStep === undefined || failedStep === TESTS_STEP
35
+ const silent = ran ? unreported(tests, results) : []
36
+ const text = unreportedText(files, silent, reached(results).length, failedStep !== undefined)
31
37
  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 }),
38
+ fields: { tests: tests.length, ...(results.length > 0 ? { failed: failedTests(results) } : {}), ...(silent.length > 0 ? { notRun: silent } : {}) },
39
+ problems: failedStep === undefined && text ? [text] : [],
40
+ notes: (record, before) => [
41
+ ...(failedStep !== undefined && text ? [text] : []),
42
+ ...noteResults(repo, { record: record as PaceRun, results, before: before as PaceRun[], whole: tests }),
43
+ ],
34
44
  }
35
45
  },
36
46
  dispose: () => resultsAt.dispose(),
package/src/pace/index.ts CHANGED
@@ -4,6 +4,7 @@ import type { Module } from '../base/module.ts'
4
4
  import { contractProblems, FIELDS } from './config.ts'
5
5
  import { fullPart } from './full.ts'
6
6
  import { alerts, fullCommandHint, rhythm } from './session.ts'
7
+ import { onSession, unfinished } from './unfinished.ts'
7
8
 
8
9
  export const pace: Module = {
9
10
  name: 'pace',
@@ -12,5 +13,7 @@ export const pace: Module = {
12
13
  brief: rhythm,
13
14
  alerts,
14
15
  beforeCommand: fullCommandHint,
16
+ onSession,
17
+ unfinished,
15
18
  fullPart,
16
19
  }
@@ -3,9 +3,9 @@
3
3
  import { type Repo, runClaimed, runner } from '../base/repo.ts'
4
4
  import type { Execution } from '../base/execute.ts'
5
5
  import { currentBranch, headCommit, workTreeId } from '../base/git.ts'
6
- import type { RunningMarker, RunRecord, Store } from '../base/store.ts'
6
+ import type { RunMarker, RunRecord, Store } from '../base/store.ts'
7
7
  import type { CommandKey } from './config.ts'
8
- import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile, type TestResult, wholeFiles } from './results.ts'
8
+ import { failedTests, noteResults, reached, readResults, RESULTS_ENV, resultsFile, type TestResult, unreported, unreportedText, wholeFiles } from './results.ts'
9
9
  import type { TestId } from './testlist.ts'
10
10
 
11
11
  /** 这个模块跑的命令的记录:fast、files,和整组(full,底座跑的,带着这个模块加的字段)。 */
@@ -17,6 +17,8 @@ export interface PaceRun extends RunRecord {
17
17
  tests?: number
18
18
  /** 没过的测试(经 testpace run 跑、交回了每个测试结果的才有)。 */
19
19
  failed?: TestId[]
20
+ /** 交给 files 的测试文件里一条结果都没交回的(没跑到),见 results.ts 的 unreported。 */
21
+ notRun?: string[]
20
22
  /** testpace files --repeat 连跑的第几次(从 1 起)、共几次。 */
21
23
  repeat?: { index: number; of: number }
22
24
  }
@@ -32,12 +34,13 @@ export interface Recorded {
32
34
  execution: Execution
33
35
  /** 命令里的 testpace run 交回的每个测试的结果;没经 testpace run 跑的为空。 */
34
36
  results: TestResult[]
35
- /** 看这些结果要说给 agent 的话:时好时坏、几轮没过(见 results.ts)。 */
37
+ /** 看这些结果要说给 agent 的话:没跑到的、时好时坏、几轮没过(见 results.ts)。 */
36
38
  notes: string[]
37
39
  }
38
40
 
39
41
  /**
40
42
  * 跑 fast 或 files 并记一条记录(见 runClaimed),收回每个测试的结果、看有没有时好时坏和几轮没过的(见 results.ts)。
43
+ * files 还核对交给它的每个测试文件都交回了结果:命令通过、却有没跑到的,这次算没过;命令没过的,照样点名没跑到的。
41
44
  * 跑完重算一次代码(treeAtEnd):认时好时坏要"同一份代码",跑的过程中代码改过的不算。通过记录只认 full。
42
45
  */
43
46
  export async function runRecorded(
@@ -47,7 +50,7 @@ export async function runRecorded(
47
50
  args: string[],
48
51
  tree: string,
49
52
  options: { repeat?: PaceRun['repeat']; passedEarlier?: Map<string, string> } = {},
50
- ): Promise<Recorded | { busy: RunningMarker }> {
53
+ ): Promise<Recorded | { busy: RunMarker }> {
51
54
  const file = resultsFile()
52
55
  try {
53
56
  const run = await runClaimed(repo, kind, command, args, tree, { [RESULTS_ENV]: file.path })
@@ -55,6 +58,8 @@ export async function runRecorded(
55
58
  const { id, startedAt, log, execution } = run
56
59
  const results = execution.interrupted ? [] : readResults(file.path, repo.root)
57
60
  const failed = failedTests(results)
61
+ const silent = kind === 'files' && !execution.interrupted ? unreported(args, results) : []
62
+ const unreached = unreportedText(command, silent, reached(results).length, execution.exitCode !== 0)
58
63
  const record: PaceRun = {
59
64
  id,
60
65
  kind,
@@ -66,9 +71,10 @@ export async function runRecorded(
66
71
  startedAt,
67
72
  durationMs: execution.durationMs,
68
73
  exitCode: execution.exitCode,
69
- result: execution.exitCode === 0 ? 'pass' : 'fail',
74
+ result: execution.exitCode === 0 && !unreached ? 'pass' : 'fail',
70
75
  ...(kind === 'files' ? { files: args } : {}),
71
76
  ...(results.length > 0 ? { failed } : {}),
77
+ ...(silent.length > 0 ? { notRun: silent } : {}),
72
78
  ...(options.repeat ? { repeat: options.repeat } : {}),
73
79
  ...runner(),
74
80
  log,
@@ -76,7 +82,7 @@ export async function runRecorded(
76
82
  if (execution.interrupted) return { record, execution, results, notes: [] }
77
83
  const before = paceRuns(repo.store)
78
84
  repo.store.appendRun(record)
79
- const notes = noteResults(repo, { record, results, before, whole: wholeFiles(args), ...(options.passedEarlier ? { passedEarlier: options.passedEarlier } : {}) })
85
+ const notes = [...(unreached ? [unreached] : []), ...noteResults(repo, { record, results, before, whole: wholeFiles(args), ...(options.passedEarlier ? { passedEarlier: options.passedEarlier } : {}) })]
80
86
  return { record, execution, results, notes }
81
87
  } finally {
82
88
  file.dispose()
@@ -10,7 +10,7 @@ import { when } from '../base/format.ts'
10
10
  import type { Repo } from '../base/repo.ts'
11
11
  import type { Ran } from './run/targets.ts'
12
12
  import type { PaceRun } from './record.ts'
13
- import { addFlaky, type FlakyTest, flakyTests, LOCATED, readRounds, removeFlaky, saveRounds, type TestId, testKey } from './testlist.ts'
13
+ import { addFlaky, type FlakyTest, flakyTests, LOCATED, readRounds, removeFlaky, saveRounds, type TestId, testFile, testKey } from './testlist.ts'
14
14
 
15
15
  export const RESULTS_ENV = 'TESTPACE_RESULTS'
16
16
 
@@ -62,6 +62,9 @@ export function readResults(path: string, root: string): TestResult[] {
62
62
  * 一次运行里同一个名字既有过的又有没过的,分不清是哪个,不算(不记没过,不比时好时坏,不数轮数)。
63
63
  * 名字带 project 的(Vitest、Playwright 有多个 project 时)各算一个。
64
64
  */
65
+ /** 同名的几条里留哪条(没过的另算,见 distinct):过了的胜过跳过的,跳过的胜过没跑到的(Playwright repeatEach 的拷贝有的跑了、有的没跑到)。 */
66
+ const STRENGTH: Record<TestResult['status'], number> = { notrun: 0, skipped: 1, passed: 2, failed: 3 }
67
+
65
68
  function distinct(results: TestResult[]): TestResult[] {
66
69
  const byKey = new Map<string, TestResult>()
67
70
  const mixed = new Set<string>()
@@ -70,7 +73,7 @@ function distinct(results: TestResult[]): TestResult[] {
70
73
  const seen = byKey.get(key)
71
74
  if (!seen) byKey.set(key, test)
72
75
  else if (seen.status !== test.status && (seen.status === 'failed' || test.status === 'failed')) mixed.add(key)
73
- else if (test.status === 'failed' || (test.status === 'passed' && seen.status === 'skipped')) byKey.set(key, test)
76
+ else if (test.status === 'failed' || STRENGTH[test.status] > STRENGTH[seen.status]) byKey.set(key, test)
74
77
  }
75
78
  return [...byKey.values()].filter(test => !mixed.has(testKey(test)))
76
79
  }
@@ -92,6 +95,37 @@ export function wholeFiles(args: string[]): string[] {
92
95
  return args.filter(arg => !LOCATED.test(arg))
93
96
  }
94
97
 
98
+ /** 跑到了的测试(过、没过、跳过):去掉 Playwright 记的没跑到(notrun,见 run/targets.ts 的 Ran)。 */
99
+ export function reached<T extends TestResult>(results: readonly T[]): T[] {
100
+ return results.filter(test => test.status !== 'notrun')
101
+ }
102
+
103
+ /**
104
+ * 交给 files 的测试文件里一条结果都没交回的(过、没过、跳过都算交回;按行给的看那个文件)。不读脚本:脚本漏跑了哪一类测试、
105
+ * 跑到一半停了(比如分几批跑、一批没过后面的就不跑),结果里就少了那些文件。focused、files、整组都按这个核对。
106
+ */
107
+ export function unreported(handed: readonly string[], results: readonly TestResult[]): string[] {
108
+ const reported = new Set(reached(results).map(test => test.file))
109
+ return [...new Set(handed.map(testFile))].filter(file => !reported.has(file))
110
+ }
111
+
112
+ /** 一次最多点名几个没交回结果的文件。 */
113
+ const NAMED = 10
114
+
115
+ /**
116
+ * 说没交回结果的文件;没有要说的时为 undefined。命令没过、又一个结果都没交回的不说(多半是命令自己没起来,它的输出已经说了)。
117
+ * 命令没过的,提醒没过的修好后要和没跑到的一起再跑:只重跑没过的,没跑到的就一直没验证。
118
+ */
119
+ export function unreportedText(files: string, silent: readonly string[], results: number, failed: boolean): string | undefined {
120
+ if (silent.length === 0 || (failed && results === 0)) return undefined
121
+ const how = `node:test、Vitest、Playwright 的测试经 testpace run 跑(它会交回结果);别的跑法自己往环境变量 ${RESULTS_ENV} 给的文件里,每个测试追加一行 JSON:{"file":"文件的绝对路径","name":"测试名","status":"passed、failed 或 skipped"}`
122
+ if (results === 0) return `files 命令(${files})跑完,一个测试结果都没交回,核对不了跑到了哪些测试。${how}。`
123
+ const named = silent.slice(0, NAMED).join('、') + (silent.length > NAMED ? ` 等 ${silent.length} 个` : '')
124
+ const head = `交给 files 命令(${files})的测试文件里,这些一条结果都没交回:${named}。`
125
+ if (failed) return `${head}这次没验证到它们:上面的输出没说原因的,多半是跑到一半停了(比如分批跑,一批没过后面的就不跑)。修好后用 testpace files 把没过的和这些一起再跑一遍。`
126
+ return `${head}可能是 files 的脚本没把它们交给测试框架、被框架的配置排除了,或跑它们的那一路没交结果。${how}。`
127
+ }
128
+
95
129
  export interface ResultsInput {
96
130
  /** 这次运行的记录,已经写进 runs.jsonl。 */
97
131
  record: PaceRun
@@ -118,6 +152,13 @@ export function noteResults(repo: Repo, input: ResultsInput): string[] {
118
152
  if (input.results.length === 0) return []
119
153
  const results = distinct(input.results)
120
154
  const notes: string[] = []
155
+
156
+ // 选中了却没跑到的(Playwright 的 serial 模式里前面的没过,后面的不跑):只重跑没过的那一行,它们还是不跑
157
+ const unreached = results.filter(test => test.status === 'notrun')
158
+ if (unreached.length > 0) {
159
+ const named = unreached.slice(0, NAMED).map(describeTest).join('、') + (unreached.length > NAMED ? ` 等 ${unreached.length} 个` : '')
160
+ notes.push(`这些测试没跑到(同一组里前面有测试没过,框架没接着跑):${named}。这次没验证到它们:修好后用 testpace files 把没过的和它们(文件:行号)一起再跑一遍。`)
161
+ }
121
162
  const listed = new Map(flakyTests(repo.store).map(test => [testKey(test), test]))
122
163
  const session = currentAgent()?.session
123
164
 
@@ -5,6 +5,8 @@
5
5
  // 配置写错时 Playwright 不起报告器,不写报告,testpace 不核对;全局准备(globalSetup)出错时选好了测试、一个没跑,照样写。
6
6
  // 只算选中的测试(没被行选中的 Playwright 不放进来)。一个结果都没有的是没跑到(提前停下、依赖的准备项目没过);
7
7
  // 被跳过但本来要跑的(serial 模式里前面的没过,后面的就不跑了)也是没跑到,不算声明了跳过。
8
+ // 没跑到的记成 notrun:testpace 按文件核对时不把它们算交回了结果(targets.ts 的 tally、results.ts 的 unreported),
9
+ // 但点名是哪几个,重跑没过的测试时一起带上(只重跑没过的那一行,它们还是不跑)。
8
10
  // 多个 project 时同一个测试各算一次,名字前带上 project 的名字;重试的按最后一次算,重试后才过的记 retried。
9
11
  import { writeFileSync } from 'node:fs'
10
12
 
@@ -22,11 +24,10 @@ export default class TestpaceCount {
22
24
  const lines = []
23
25
  for (const test of this.suite.allTests()) {
24
26
  const last = test.results.at(-1)
25
- if (!last) continue
26
27
  let status
27
- if (last.status === 'skipped') {
28
- if (test.expectedStatus !== 'skipped') continue
29
- status = 'skipped'
28
+ if (!last) status = 'notrun'
29
+ else if (last.status === 'skipped') {
30
+ status = test.expectedStatus === 'skipped' ? 'skipped' : 'notrun'
30
31
  } else {
31
32
  status = last.status === test.expectedStatus ? 'passed' : 'failed'
32
33
  }
@@ -5,7 +5,6 @@ import { appendFileSync, mkdtempSync, readFileSync, rmSync, statSync } from 'nod
5
5
  import { createRequire } from 'node:module'
6
6
  import { tmpdir } from 'node:os'
7
7
  import { dirname, join, relative, resolve } from 'node:path'
8
- import { RUN_ENV } from '../../base/execute.ts'
9
8
  import { FRAMEWORK_KILL_AFTER_MS, type GroupRun, spawnGroup } from '../../base/process-group.ts'
10
9
  import { RESULTS_ENV } from '../results.ts'
11
10
  import { parseTargets, readRanLines, type Target, tally } from './targets.ts'
@@ -82,16 +81,24 @@ export async function runFramework(framework: Framework, argv: string[]): Promis
82
81
  // 被信号终止(不是 testpace 转过去的)算没过
83
82
  const code = run.exitCode ?? 1
84
83
 
85
- const ran = readRanLines(report)
84
+ const lines = readRanLines(report)
86
85
  // 没写报告:框架在选测试之前就停了,原因它已经说过,没有可核对的。退出码是 0 却没报告,什么都没验证到,不算通过
87
- if (ran === undefined) {
86
+ if (lines === undefined) {
88
87
  if (code !== 0) return code
89
88
  console.error('[testpace] 框架退出了,却没写出跑了哪些测试,什么都没验证到')
90
89
  return 1
91
90
  }
92
- // 由 testpace 的 files、focused、full 起的:每个测试的结果交给它,认时好时坏和几轮没过(见 results.ts)
91
+ // 由 testpace 的 files、focused、full 起的:每个测试的结果交给它(没跑到的也交,它点名),认时好时坏和几轮没过(见 results.ts)
93
92
  const results = process.env[RESULTS_ENV]
94
- if (results) appendFileSync(results, ran.map(test => `${JSON.stringify(test)}\n`).join(''))
93
+ if (results) appendFileSync(results, lines.map(test => `${JSON.stringify(test)}\n`).join(''))
94
+ const ran = lines.filter(test => test.status !== 'notrun')
95
+ // 同一个文件里同名的(Playwright repeatEach 的拷贝)有一份跑了就不点名:和 testpace 那层按名字认一个测试一致(results.ts 的 distinct)
96
+ const reachedNames = new Set(ran.map(test => `${test.file}\0${test.name}`))
97
+ const unreached = lines.filter(test => test.status === 'notrun' && !reachedNames.has(`${test.file}\0${test.name}`))
98
+ if (unreached.length > 0) {
99
+ const shown = unreached.slice(0, 10).map(test => `${relative(process.cwd(), test.file)}${test.line === undefined ? '' : `:${test.line}`}`)
100
+ console.error(`[testpace] 这些选中的测试没跑到(前面有测试没过,框架没接着跑,比如 serial 模式、max-failures):${shown.join('、')}${unreached.length > 10 ? ` 等 ${unreached.length} 个` : ''}。重跑没过的测试时把它们一起带上`)
101
+ }
95
102
  // 框架没过也照样核对:没跑到测试的文件和行一并说出来
96
103
  const { notRun, allSkipped, others, failed } = tally(targets, ran)
97
104
  if (others.length > 0) console.log(`[testpace] 框架还跑了这些没给的文件(名字片段匹配到的,或给的测试依赖的准备项目):${others.map(file => relative(process.cwd(), file)).join('、')}`)
@@ -145,8 +152,7 @@ function parseOptions(argv: string[], argOption: string): Options | string {
145
152
  */
146
153
  function spawnFramework({ program, args, env }: Command, cwd: string): Promise<GroupRun> {
147
154
  // 交结果的位置只给这一层:测试自己再起的 testpace run(比如测 testpace 的测试)不往里写。
148
- // 整组给检查的运行 id 也不给测试:检查直接跑项目的测试命令时(比如 testcraft check 在副本里跑),测试不是那一段检查
149
- const { [RESULTS_ENV]: _, [RUN_ENV]: _run, ...inherited } = process.env
155
+ const { [RESULTS_ENV]: _, ...inherited } = process.env
150
156
  return spawnGroup(program, args, {
151
157
  cwd,
152
158
  env: { ...inherited, ...env },
@@ -63,7 +63,8 @@ function isFile(path: string): boolean {
63
63
 
64
64
  /**
65
65
  * 一个测试的记录,三个框架的计数报告器都写成这样:哪个文件(真实的绝对路径)、声明在哪一行、外层各级分组(describe)声明在哪几行、名字、结果。
66
- * 只记跑过或被跳过的;没跑到的(框架提前停下、准备项目没过)不记。
66
+ * 记跑过或被跳过的;Playwright 还把选中了却没跑到的(serial 模式里前面的没过、框架提前停下)记成 notrun,
67
+ * 核对文件和行时不算跑到(runner 先去掉),只点名。别的框架没跑到的不记。
67
68
  * 没有行号的(Vitest 没打开 includeTaskLocation 时)只能按整个文件核对。
68
69
  */
69
70
  export interface Ran {
@@ -72,7 +73,7 @@ export interface Ran {
72
73
  ancestors: number[]
73
74
  /** 测试名,带上外层各级分组的名字,用 > 连起来(Vitest、Playwright 的 project 有名字时前面还有 [project 名])。认同一个测试靠它和文件。 */
74
75
  name: string
75
- status: 'passed' | 'failed' | 'skipped'
76
+ status: 'passed' | 'failed' | 'skipped' | 'notrun'
76
77
  /** 框架重试之后才过。 */
77
78
  retried?: boolean
78
79
  }
@@ -13,9 +13,9 @@ export function rhythm(repo: string): string[] {
13
13
  return [
14
14
  `${repo}用 testpace 管测试节奏(testpace.json):`,
15
15
  '1. 每个任务在自己的分支上做,最好是自己的 worktree,不和别的会话挤在同一个目录里。',
16
- '2. 每做完一轮、向用户汇报之前跑一次 testpace focused:fast 检查,加上这次改到的测试和最相关的几个(最多再跑 8 个文件)。一轮只跑一次;小改动(文字、样式、注释)不用跑。在分支上不跑整组,其余的留给合并时的整组兜底。',
17
- '3. 开发中有测试没过,只看不追。先分清是哪一种:因为用户这次改了需求才不过的,不管它,不改测试,留到合并时一起改;和这次需求无关的(这次的改动弄坏了别的功能),当场改这次自己写的代码,用 testpace files <文件:行号> 只重跑那几个测试(位置看失败输出)。不为了通过重跑,不改测试凑通过。fast 没过的照常当场修。',
18
- '4. 做完一个任务不要自己合回默认分支:告诉用户做完了,等用户说合。用户说合("合""可以合了""提 PR"),就照 gatelight:merge 技能合这个分支:合到一个临时的合并分支上跑一次 testpace full,通过了再落地。一个分支合一次,不用攒。整组要跑几分钟,能把命令放到后台的就放后台、接着做别的,不要干等;跑完用 testpace status 看结果。',
16
+ '2. 每做完一轮、向用户汇报之前跑一次 testpace focused:fast 检查,加上这次改到的测试和最相关的几个(最多再跑 8 个文件)。一轮只跑一次;小改动(文字、样式、注释)不用跑。在分支上不跑整组,其余的留给合并时的整组兜底。改了代码、当前内容没跑过 focused 就收尾,会被拦一次。',
17
+ '3. 开发中有测试没过,只看不追。先分清是哪一种:因为用户这次改了需求才不过的,不管它,不改测试,留到合并时一起改(留的是改这些测试,focused 照样每轮跑);和这次需求无关的(这次的改动弄坏了别的功能),当场改这次自己写的代码,用 testpace files <文件:行号> 只重跑没过的那几个(位置看失败输出),输出里点名了没跑到的文件和测试的,把它们一起跑上。不为了通过重跑,不改测试凑通过。fast 没过的照常当场修。',
18
+ '4. 做完一个任务不要自己合回默认分支:告诉用户做完了,等用户说合。用户说合("合""可以合了""提 PR"),就照 gatelight:merge 技能合这个分支:合到一个临时的合并分支上跑一次 testpace full,通过了再落地。一个分支合一次,不用攒:分支上已经有做完、提交了没合的事,用户又提了别的,先问要不要合了这个、在新分支上做下一件(提交了还有没合的,收尾时会被拦一次,Claude Code 里用户也会看到一行提示)。整组要跑几分钟,能把命令放到后台的就放后台、接着做别的,不要干等;跑完用 testpace status 看结果。',
19
19
  ]
20
20
  }
21
21
 
@@ -0,0 +1,87 @@
1
+ // 停止门里"跑测试"这一项(base/module.ts 的 onSession、unfinished;"该合了"那一项在 unmerged.ts):这个会话改了代码(和会话起点比,只改了 ignore 路径的不算),
2
+ // 当前内容却没跑过 testpace focused,拦一次。同一份内容只拦一次(记号里带着内容的样子),小改动 agent 说一句就能收尾。
3
+ // 认"跑过":当前内容有 fast 的记录(只有 focused 会跑 fast)、focused 跑的相关测试或整组的记录,过没过都算;相对那次只改了 ignore 路径的也算。
4
+ // 这道门只看跑没跑,不看过没过:开发中没过的测试照节奏只看不追。
5
+ //
6
+ // 只靠会话说明管不住:会话压缩后,摘要里更具体的转述(比如"测试都留到合并")会盖过说明,所以和 modwall check 一样在收尾时查一次。
7
+
8
+ import { SessionBaselines } from '../base/baseline.ts'
9
+ import { changedPaths, treeOf, workTreeId } from '../base/git.ts'
10
+ import { ignoredBy, type Repo } from '../base/repo.ts'
11
+ import { loadConfig } from './config.ts'
12
+ import { paceRuns } from './record.ts'
13
+ import { noteHead, unmerged } from './unmerged.ts'
14
+
15
+ const MODULE = 'pace'
16
+ /** 会话起点记的是什么:workTreeId 算出的整个工作区的树。算法变了要改它(见 base/baseline.ts)。 */
17
+ const TREE_FORMAT = 'worktree-1'
18
+ /** 只和最近这么多份跑过的内容比 ignore 路径,避免记录很多时逐个 diff。 */
19
+ const CANDIDATES = 20
20
+
21
+ function baselines(repo: Repo): SessionBaselines<string> {
22
+ return new SessionBaselines(repo, MODULE, TREE_FORMAT)
23
+ }
24
+
25
+ /** 会话碰到这个工作区时:记下这时整个工作区的样子(只记第一次)。没接入、配置写坏了的不记。 */
26
+ export function onSession(repo: Repo, sessionId: string): void {
27
+ const onboarded = (): boolean => loadConfig(repo.root).config !== undefined
28
+ baselines(repo).note(sessionId, () => (onboarded() ? workTreeId(repo.root) : undefined))
29
+ noteHead(repo, sessionId, onboarded)
30
+ }
31
+
32
+ /** 两份内容之间只改了 ignore 路径(或没改)。树对象被清理了、比不了的当作改了代码。 */
33
+ function onlyIgnored(repo: Repo, from: string, to: string, isIgnored: (path: string) => boolean): boolean {
34
+ if (from === to) return true
35
+ try {
36
+ return changedPaths(repo.root, from, to).every(isIgnored)
37
+ } catch {
38
+ return false
39
+ }
40
+ }
41
+
42
+ /** 停止门:先看跑没跑 focused,跑过了(或已经拦过)再看该不该合(unmerged.ts)。 */
43
+ export function unfinished(repo: Repo, sessionId: string, seen: (key: string) => boolean, named: boolean): { keys: string[]; text: string; notice?: string } | undefined {
44
+ const config = loadConfig(repo.root).config
45
+ if (!config) return undefined
46
+ const now = workTreeId(repo.root)
47
+ const isIgnored = ignoredBy(config.ignore)
48
+ const clean = (): boolean => {
49
+ const head = treeOf(repo.root, 'HEAD')
50
+ return head !== undefined && onlyIgnored(repo, head, now, isIgnored)
51
+ }
52
+ return notRun(repo, sessionId, seen, named, now, isIgnored) ?? unmerged(repo, sessionId, seen, named, clean, isIgnored)
53
+ }
54
+
55
+ /** 这个会话改了代码,当前内容没跑过 focused(也没跑过整组)。 */
56
+ function notRun(
57
+ repo: Repo,
58
+ sessionId: string,
59
+ seen: (key: string) => boolean,
60
+ named: boolean,
61
+ now: string,
62
+ isIgnored: (path: string) => boolean,
63
+ ): { keys: string[]; text: string } | undefined {
64
+ const key = `pace:focused:${now}`
65
+ if (seen(key)) return undefined
66
+ if (onlyIgnored(repo, baselines(repo).since(sessionId, now), now, isIgnored)) return undefined
67
+ // 跑过的内容:fast(focused 的第一步)和整组开始时的;跑完时的也算(测试自己写出没被 git 忽略的文件,内容会变)。
68
+ // focused 的相关测试和它的 fast 记的是同一个开始时的内容,靠这个认出哪些 files 是 focused 跑的,取它们跑完时的
69
+ const runs = paceRuns(repo.store).sort((a, b) => b.startedAt - a.startedAt)
70
+ const focusedTrees = new Set(runs.filter(run => run.kind === 'fast').map(run => run.tree))
71
+ const trees = [
72
+ ...new Set(
73
+ runs.flatMap(run => {
74
+ if (run.kind === 'fast' || run.kind === 'full') return [run.tree, run.treeAtEnd]
75
+ return run.kind === 'files' && focusedTrees.has(run.tree) ? [run.treeAtEnd] : []
76
+ }),
77
+ ),
78
+ ]
79
+ if (trees.includes(now) || trees.slice(0, CANDIDATES).some(tree => onlyIgnored(repo, tree, now, isIgnored))) return undefined
80
+ return {
81
+ keys: [key],
82
+ text:
83
+ `这个会话${named ? `在 ${repo.root} ` : ''}改了代码,当前内容还没跑过 testpace focused。向用户汇报之前跑一次。` +
84
+ '没过的测试照节奏分清是哪一种:因为这次改了需求才不过的留到合并时改,focused 照样每轮跑;"留到合并"说的是改那些没过的测试,不是不跑测试。' +
85
+ '只改了文字、样式、注释的小改动,或改动不是这个会话写的(拉取、合并进来的),说一句再收尾。',
86
+ }
87
+ }
@@ -0,0 +1,87 @@
1
+ // 停止门里"该合了"这一项:这个会话在功能分支上提交了,分支上还有没合进默认分支的提交,拦一次,同时直接给用户看一行。
2
+ // 不按攒了多少设门槛:多少算多没有依据,一件事分几次提交的,中间被提一次,agent 说一句还没做完就行。
3
+
4
+ import { SessionBaselines } from '../base/baseline.ts'
5
+ import { day } from '../base/format.ts'
6
+ import { commitsSince, currentBranch, findDefaultBranch, headCommit, refsUnder, refTip } from '../base/git.ts'
7
+ import type { Repo } from '../base/repo.ts'
8
+
9
+ const MODULE = 'pace'
10
+ /** 会话起点记的是什么:那时 HEAD 指的提交和记下的时间(毫秒)。 */
11
+ const HEAD_FORMAT = 'head-1'
12
+ /** 列出来的提交最多几个,再多的只说一共几个。 */
13
+ const LISTED = 8
14
+ /** 每个提交取说明开头一段,最多这么多个字。 */
15
+ const TITLE = 24
16
+
17
+ interface HeadStart {
18
+ head: string
19
+ at: number
20
+ }
21
+
22
+ function heads(repo: Repo): SessionBaselines<HeadStart> {
23
+ return new SessionBaselines(repo, MODULE, HEAD_FORMAT)
24
+ }
25
+
26
+ /** 会话碰到这个工作区时:记下这时 HEAD 指的提交(只记第一次)。onboarded 答接入了没有,还没记过才问。 */
27
+ export function noteHead(repo: Repo, sessionId: string, onboarded: () => boolean): void {
28
+ heads(repo).note(sessionId, () => {
29
+ const head = onboarded() ? headCommit(repo.root) : undefined
30
+ return head ? { head, at: Date.now() } : undefined
31
+ })
32
+ }
33
+
34
+ /** 提交说明开头一段:到第一个冒号、逗号、句号、分号为止,太长的截断。 */
35
+ function title(subject: string): string {
36
+ const head = subject.split(/[::,,。;;]/)[0]!.trim() || subject
37
+ const chars = [...head]
38
+ return chars.length > TITLE ? `${chars.slice(0, TITLE).join('')}…` : head
39
+ }
40
+
41
+ /**
42
+ * 停止门:这个会话提交了,分支上还有没合进默认分支、改了代码的提交。
43
+ * clean 答工作区相对 HEAD 是不是只改了 ignore 路径(或没改),用到时才算;isIgnored 按 testpace.json 的 ignore 认路径。
44
+ */
45
+ export function unmerged(
46
+ repo: Repo,
47
+ sessionId: string,
48
+ seen: (key: string) => boolean,
49
+ named: boolean,
50
+ clean: () => boolean,
51
+ isIgnored: (path: string) => boolean,
52
+ ): { keys: string[]; text: string; notice: string } | undefined {
53
+ const branch = currentBranch(repo.root)
54
+ if (!branch || branch.startsWith('merge/')) return undefined
55
+ const found = findDefaultBranch(repo.root)
56
+ if (!found.branch || branch === found.branch) return undefined
57
+ const head = headCommit(repo.root)
58
+ if (!head) return undefined
59
+ const key = `pace:unmerged:${head}`
60
+ if (seen(key)) return undefined
61
+ // 会话起点以来 HEAD 没动:这个会话没提交过
62
+ const start = heads(repo).since(sessionId, { head, at: Date.now() })
63
+ if (start.head === head || !clean()) return undefined
64
+ // 本地或 origin 上的默认分支有了的都算合了(推送到 origin 默认分支的,本地还没拉)
65
+ const landed = [`refs/heads/${found.branch}`, `refs/remotes/origin/${found.branch}`].filter(ref => refTip(repo.root, ref))
66
+ if (landed.length === 0) return undefined
67
+ const commits = commitsSince(repo.root, [...landed, ...refsUnder(repo.root, 'refs/heads/merge/')], head)
68
+ .filter(commit => commit.paths.some(path => !isIgnored(path)))
69
+ .reverse()
70
+ // 提交时间按秒记,起点按毫秒:同一秒里的算会话开始以后
71
+ if (!commits.some(commit => commit.time >= Math.floor(start.at / 1000) * 1000)) return undefined
72
+
73
+ const files = new Set(commits.flatMap(commit => commit.paths.filter(path => !isIgnored(path)))).size
74
+ const titles = commits.map(commit => title(commit.subject))
75
+ const list = titles.length > LISTED ? `${titles.slice(0, LISTED).join('、')} 等 ${titles.length} 个` : titles.join('、')
76
+ const where = named ? `${repo.root} 的` : ''
77
+ const facts = `${where}分支 ${branch} 攒了 ${commits.length} 个提交没合进 ${found.branch}(从 ${day(commits[0]!.time)} 起,改了 ${files} 个文件):${list}`
78
+ const tested = '这些改动都还没经过合并时的整组,接入了 testcraft 的,测试也要合并时才写'
79
+ return {
80
+ keys: [key],
81
+ notice: `gatelight:${facts}。${tested}。每件事做完就合。`,
82
+ text:
83
+ `这个会话提交了。${facts}。${tested}。` +
84
+ '向用户汇报时,第一行单独写这件事:攒了几个提交、从哪天起、还没有测试、建议现在先合(用户说合就照 gatelight:merge 合),下一件事在新分支上做;' +
85
+ '不要夹在段落里,也不要只说一句"可以合了"。这次的事还没做完的照样说,再说还差什么。用户说接着在这个分支上做的,照做,下次提交还会再提。',
86
+ }
87
+ }
@@ -2,7 +2,7 @@
2
2
  // 这几次运行不记进 runs.jsonl(不是开发中的测试,不该算进报告),但和别的测试一样占住工作区。
3
3
 
4
4
  import { failureCause, type Repo, runClaimed } from '../base/repo.ts'
5
- import type { RunningMarker } from '../base/store.ts'
5
+ import type { RunMarker } from '../base/store.ts'
6
6
 
7
7
  /** 核对时交给 files 的不存在的路径。 */
8
8
  export const MISSING = 'testpace-verify-no-such-file.test.js'
@@ -25,7 +25,7 @@ export function firstTest(text: string): { line: number; column: number } | unde
25
25
 
26
26
  export type VerifyResult =
27
27
  | { kind: 'done'; failed: number; skipped: number }
28
- | { kind: 'busy'; marker: RunningMarker }
28
+ | { kind: 'busy'; marker: RunMarker }
29
29
  | { kind: 'interrupted' }
30
30
 
31
31
  class Stopped {