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.
- package/.antigravity-plugin/plugin.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +2 -2
- package/package.json +1 -1
- package/skills/merge/SKILL.md +1 -1
- package/skills/modular/SKILL.md +6 -6
- package/skills/setup/SKILL.md +2 -2
- package/skills/setup-codekeep/SKILL.md +61 -17
- package/skills/setup-codekeep/frontend.eslint.mjs +285 -0
- package/skills/setup-modwall/SKILL.md +10 -11
- package/skills/setup-testcraft/SKILL.md +9 -3
- package/skills/setup-testcraft/checklist/dev-login.md +3 -3
- package/skills/setup-testcraft/checklist/same-number.md +26 -0
- package/skills/write-tests/SKILL.md +13 -12
- package/src/base/baseline.ts +2 -2
- package/src/base/commands.ts +2 -40
- package/src/base/execute.ts +1 -11
- package/src/base/exit.ts +1 -1
- package/src/base/full.ts +15 -11
- package/src/base/git.ts +34 -3
- package/src/base/hook.ts +71 -17
- package/src/base/hookformat.ts +16 -6
- package/src/base/module.ts +9 -7
- package/src/base/repo.ts +8 -34
- package/src/base/sessions.ts +45 -13
- package/src/base/shell.ts +18 -10
- package/src/base/stop.ts +20 -6
- package/src/base/store.ts +15 -30
- package/src/cli.ts +3 -16
- package/src/craft/commands.ts +7 -1
- package/src/craft/defaults.ts +59 -0
- package/src/craft/session.ts +8 -4
- package/src/keep/check.ts +78 -39
- package/src/keep/config.ts +56 -26
- package/src/keep/eslint.ts +130 -5
- package/src/keep/loosen.ts +11 -61
- package/src/keep/session.ts +19 -5
- package/src/keep/styles.ts +72 -0
- package/src/pace/commands.ts +9 -3
- package/src/pace/full.ts +16 -6
- package/src/pace/index.ts +3 -0
- package/src/pace/record.ts +12 -6
- package/src/pace/results.ts +43 -2
- package/src/pace/run/playwright-reporter.mjs +5 -4
- package/src/pace/run/runner.ts +13 -7
- package/src/pace/run/targets.ts +3 -2
- package/src/pace/session.ts +3 -3
- package/src/pace/unfinished.ts +87 -0
- package/src/pace/unmerged.ts +87 -0
- package/src/pace/verify.ts +2 -2
- package/src/wall/commands.ts +94 -26
- package/src/wall/database.ts +12 -1
- package/src/wall/dbcheck.ts +2 -2
- package/src/wall/dbrules.ts +60 -19
- package/src/wall/full.ts +6 -1
- package/src/wall/literals.ts +162 -0
- package/src/wall/migrate.ts +248 -0
- package/src/wall/project.ts +29 -9
- package/src/wall/receipt.ts +74 -0
- package/src/wall/session.ts +5 -5
- package/src/wall/store.ts +3 -1
package/src/base/store.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 结果记录:放在仓库共用的 .git/testpace/ 下,不进版本库,也不影响工作区内容哈希。
|
|
2
2
|
// runs.jsonl 每次运行一行,只追加
|
|
3
|
-
// running/
|
|
3
|
+
// running/ 每个工作区正在跑的命令一份,结束时删掉;等着用整组结果的会话另记一份
|
|
4
4
|
// logs/ 每次运行的完整输出
|
|
5
5
|
// flaky/ 时好时坏的测试的名单,一个测试一份(所有工作区共用)
|
|
6
6
|
// rounds/ 每个工作区里各测试连着几轮没过
|
|
@@ -53,7 +53,7 @@ export interface RunStep {
|
|
|
53
53
|
/** testpace 跑项目命令时占着工作区的登记。 */
|
|
54
54
|
export interface RunMarker {
|
|
55
55
|
id: string
|
|
56
|
-
/** 跑的什么:整组是 full
|
|
56
|
+
/** 跑的什么:整组是 full,别的由模块定。 */
|
|
57
57
|
kind: string
|
|
58
58
|
/** testpace 进程。 */
|
|
59
59
|
pid: number
|
|
@@ -67,25 +67,6 @@ export interface RunMarker {
|
|
|
67
67
|
log: string
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/** 别的工具借用工作区时的登记(testpace hold),比如 testcraft 建副本:占着时不跑测试。 */
|
|
71
|
-
export interface HoldMarker {
|
|
72
|
-
id: string
|
|
73
|
-
kind: 'hold'
|
|
74
|
-
/** 谁、为什么占着,比如"testcraft 建副本"。 */
|
|
75
|
-
by: string
|
|
76
|
-
/** 借用工作区的那个进程:它不在了,占用就作废。 */
|
|
77
|
-
pid: number
|
|
78
|
-
worktree: string
|
|
79
|
-
startedAt: number
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type RunningMarker = RunMarker | HoldMarker
|
|
83
|
-
|
|
84
|
-
/** 这份登记是借用工作区的(testpace hold),不是在跑命令。 */
|
|
85
|
-
export function isHold(marker: RunningMarker): marker is HoldMarker {
|
|
86
|
-
return marker.kind === 'hold'
|
|
87
|
-
}
|
|
88
|
-
|
|
89
70
|
export interface SessionState {
|
|
90
71
|
startedAt: number
|
|
91
72
|
/** 会话开始时本地和远程默认分支(引用 → 提交):之后变了才检查落地的代码有没有整组通过记录。 */
|
|
@@ -101,6 +82,10 @@ export interface SessionState {
|
|
|
101
82
|
* 只在命令里 cd 进去看过的工作区不算,那里后来的改动是别的会话的。
|
|
102
83
|
*/
|
|
103
84
|
worked?: string[]
|
|
85
|
+
/** 这个会话在各工作区动过几次手:用改文件的工具改了那里的文件,或在那里跑了不只是 gatelight 检查的命令(hook.ts 的 noteActing)。 */
|
|
86
|
+
acted?: Record<string, number>
|
|
87
|
+
/** 停止门上次为各项拦下时(工作区 + 项,见 stop.ts)这个会话在那个工作区动过几次手:之后没再动手,同一项不再拦。 */
|
|
88
|
+
blockedActs?: Record<string, number>
|
|
104
89
|
/** 停止门拦过的:running:<运行 id>(还在跑时拦过)、unread:<运行 id>(跑完没看结果时拦过)、flaky:<testKey>(认出的时好时坏测试)。每种只拦一次。 */
|
|
105
90
|
blocked?: string[]
|
|
106
91
|
/** 执行命令之前只能拒绝、不能只加一句话的 agent(Antigravity):为了说这几段提示已经拦过一次命令,同样的不再拦(hook.ts)。 */
|
|
@@ -169,7 +154,7 @@ export class Store {
|
|
|
169
154
|
* 占住这个工作区来跑 marker 这次命令:原子地创建这个工作区唯一的一份登记。
|
|
170
155
|
* 已经有在跑的,返回它,不占;登记的进程都不在了的(被强杀、机器重启)清掉再占。
|
|
171
156
|
*/
|
|
172
|
-
claim(marker:
|
|
157
|
+
claim(marker: RunMarker): RunMarker | undefined {
|
|
173
158
|
mkdirSync(this.runningDir, { recursive: true })
|
|
174
159
|
const path = this.markerPath(marker.worktree)
|
|
175
160
|
// 先写好一份完整的,再用 link 原子地放到位:别人看到的登记总是完整的,不会把写了一半的当成坏了清掉
|
|
@@ -245,7 +230,7 @@ export class Store {
|
|
|
245
230
|
}
|
|
246
231
|
|
|
247
232
|
/** 正在等这次运行结果的会话。 */
|
|
248
|
-
waiting(marker:
|
|
233
|
+
waiting(marker: RunMarker): string[] {
|
|
249
234
|
const path = this.waitingPath(marker.worktree)
|
|
250
235
|
if (!existsSync(path)) return []
|
|
251
236
|
return readFileSync(path, 'utf8')
|
|
@@ -295,12 +280,12 @@ export class Store {
|
|
|
295
280
|
}
|
|
296
281
|
|
|
297
282
|
/** 各工作区正在跑的命令。进程都不在了的登记不算,留给下一次 claim 清掉。 */
|
|
298
|
-
running():
|
|
283
|
+
running(): RunMarker[] {
|
|
299
284
|
if (!existsSync(this.runningDir)) return []
|
|
300
285
|
return readdirSync(this.runningDir)
|
|
301
286
|
.filter(name => name.endsWith('.json'))
|
|
302
287
|
.map(name => readMarker(join(this.runningDir, name)))
|
|
303
|
-
.filter((marker): marker is
|
|
288
|
+
.filter((marker): marker is RunMarker => marker !== undefined && markerAlive(marker))
|
|
304
289
|
}
|
|
305
290
|
}
|
|
306
291
|
|
|
@@ -319,17 +304,17 @@ export function writeWhole(path: string, text: string): void {
|
|
|
319
304
|
renameSync(next, path)
|
|
320
305
|
}
|
|
321
306
|
|
|
322
|
-
function readMarker(path: string):
|
|
307
|
+
function readMarker(path: string): RunMarker | undefined {
|
|
323
308
|
try {
|
|
324
|
-
return JSON.parse(readFileSync(path, 'utf8')) as
|
|
309
|
+
return JSON.parse(readFileSync(path, 'utf8')) as RunMarker
|
|
325
310
|
} catch {
|
|
326
311
|
return undefined
|
|
327
312
|
}
|
|
328
313
|
}
|
|
329
314
|
|
|
330
|
-
/**
|
|
331
|
-
function markerAlive(marker:
|
|
332
|
-
return processAlive(marker.pid) || (
|
|
315
|
+
/** 登记的 testpace 进程或测试的进程组还有一个在。 */
|
|
316
|
+
function markerAlive(marker: RunMarker): boolean {
|
|
317
|
+
return processAlive(marker.pid) || (marker.group !== undefined && processAlive(-marker.group))
|
|
333
318
|
}
|
|
334
319
|
|
|
335
320
|
/** 进程(pid 为负时是进程组)还在。 */
|
package/src/cli.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// testpace 命令行入口:focused、files、full、status、
|
|
1
|
+
// testpace 命令行入口:focused、files、full、status、report、verify、install、run,以及 git 钩子调用的 gate。
|
|
2
2
|
// 这里只做装配和分发:底座的命令在 base/commands.ts、base/full.ts,"跑测试"的命令在 pace/commands.ts;
|
|
3
3
|
// status 把底座和各模块的情况合在一起说,也放在这里。这个文件的路径不能变:bin/testpace 和固定入口都按它找。
|
|
4
4
|
|
|
5
5
|
import './modules.ts'
|
|
6
6
|
import { AGENT, runCommandLine } from './base/commandline.ts'
|
|
7
|
-
import { context, gate,
|
|
7
|
+
import { context, gate, install } from './base/commands.ts'
|
|
8
8
|
import { CONTRACT_FILE, joined } from './base/contract.ts'
|
|
9
9
|
import { ENTRY_COMMANDS, type EntryState, entryDir, entryState } from './base/entry.ts'
|
|
10
10
|
import { EXIT } from './base/exit.ts'
|
|
@@ -12,8 +12,7 @@ import { duration, short, when } from './base/format.ts'
|
|
|
12
12
|
import { full } from './base/full.ts'
|
|
13
13
|
import { danglingNote, gateProblem } from './base/gate.ts'
|
|
14
14
|
import { workTreeId } from './base/git.ts'
|
|
15
|
-
import { coverageOf, defaultTips, describeCoverage,
|
|
16
|
-
import { isHold } from './base/store.ts'
|
|
15
|
+
import { coverageOf, defaultTips, describeCoverage, started } from './base/repo.ts'
|
|
17
16
|
import { files, focused, report, run, verify } from './pace/commands.ts'
|
|
18
17
|
import { commandExists, COMMAND_KEYS, loadConfig } from './pace/config.ts'
|
|
19
18
|
import { LAYERMAP_HINT } from './pace/focused.ts'
|
|
@@ -32,10 +31,6 @@ const USAGE = `用法:
|
|
|
32
31
|
testpace full 跑整组:接入了的检查(modwall check、testcraft checklist、codekeep check)、full(测试以外的检查),再把 tests 规则找到的全部测试交给 files,
|
|
33
32
|
一段没过就停,按当前工作区完整内容记录结果。要跑几分钟,能放到后台的就放后台
|
|
34
33
|
testpace status 当前代码有没有整组通过记录、有没有正在跑的整组、最近一次结果、配置检查
|
|
35
|
-
testpace hold PID 说明 借用这个工作区(比如要复制一份工作区的工具):占着时别的 testpace 命令不跑,说明是谁占着。
|
|
36
|
-
PID 是借用的那个进程,它不在了占用就作废。占上时输出这次的 id,退出码 0;有在跑的、占着的,说明是谁,退出码 3。
|
|
37
|
-
整组里要建副本的检查带着这一轮的 TESTPACE_RUN,工作区已经是这一轮的,不另占、什么也不输出,退出码 0
|
|
38
|
-
testpace release ID 放开 hold 占的工作区
|
|
39
34
|
testpace report [--days N] 计时诊断,默认最近 28 天
|
|
40
35
|
testpace verify [测试文件...] 核对接入守不守约定:三条命令找得到、合并门在把关、files 对不存在的文件报失败、认 文件:行号;每种测试各给一个文件
|
|
41
36
|
testpace install 这台机器配一次:在全局 git 配置里配上合并门(agent 移动默认分支时,要求落地的代码有整组通过记录),
|
|
@@ -59,10 +54,6 @@ function status(): number {
|
|
|
59
54
|
lines.push(`当前代码(${short(tree)}):${describeCoverage(coverageOf(ctx, config.ignore, tree, runs))}`)
|
|
60
55
|
|
|
61
56
|
for (const marker of ctx.store.running().filter(m => m.worktree === ctx.root)) {
|
|
62
|
-
if (isHold(marker)) {
|
|
63
|
-
lines.push(`${runningText(marker)},已 ${duration(Date.now() - marker.startedAt)}`)
|
|
64
|
-
continue
|
|
65
|
-
}
|
|
66
57
|
const changed = marker.tree === tree ? '开始后代码没改过' : '开始后代码改过,跑完的结果不算当前代码的记录'
|
|
67
58
|
lines.push(`正在跑:${marker.kind},${started(marker)}(已 ${duration(Date.now() - marker.startedAt)}),${changed}`)
|
|
68
59
|
}
|
|
@@ -150,10 +141,6 @@ async function dispatch([command, ...rest]: string[]): Promise<number> {
|
|
|
150
141
|
return runFull()
|
|
151
142
|
case 'status':
|
|
152
143
|
return status()
|
|
153
|
-
case 'hold':
|
|
154
|
-
return hold(rest, USAGE)
|
|
155
|
-
case 'release':
|
|
156
|
-
return release(rest, USAGE)
|
|
157
144
|
case 'report':
|
|
158
145
|
return report(rest)
|
|
159
146
|
case 'verify':
|
package/src/craft/commands.ts
CHANGED
|
@@ -5,9 +5,11 @@ import { readdirSync, readFileSync } from 'node:fs'
|
|
|
5
5
|
import { join } from 'node:path'
|
|
6
6
|
import { EXIT } from '../base/exit.ts'
|
|
7
7
|
import { openRepo } from '../base/repo.ts'
|
|
8
|
+
import { VERSION } from '../base/version.ts'
|
|
8
9
|
import { open, type Snapshot } from './change.ts'
|
|
9
10
|
import { baseChecklist, changedChecklist, hitsOf } from './checklist.ts'
|
|
10
11
|
import { CHECKLIST_DIR, RULES_DIR } from './config.ts'
|
|
12
|
+
import { missingText } from './defaults.ts'
|
|
11
13
|
|
|
12
14
|
const USAGE = `用法:
|
|
13
15
|
testcraft checklist 清单(.testcraft/checklist/)里这次改动命中的条目和各条怎么查:按条目查一遍。
|
|
@@ -58,17 +60,21 @@ function checklist(s: Snapshot): number {
|
|
|
58
60
|
}
|
|
59
61
|
if (base.problems.length) lines.push('', '分叉点上这几条写得不对,这次没按它们提醒(不拦这次改动,另找时间修好):', ...base.problems.map(problem => ` · ${problem}`))
|
|
60
62
|
if (changed.problems.length) lines.push('', '这次加、改的条目写得不对(合并后要用得上):', ...changed.problems.map(problem => ` ✗ ${problem}`))
|
|
63
|
+
const missing = missingText(s.root)
|
|
64
|
+
if (missing) lines.push('', missing)
|
|
61
65
|
console.log(lines.join('\n'))
|
|
62
66
|
return changed.problems.length ? EXIT.fail : EXIT.ok
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
function status(s: Snapshot): number {
|
|
66
|
-
const lines: string[] = [
|
|
70
|
+
const lines: string[] = [`gatelight ${VERSION}。和 ${s.branch} 的分叉点 ${s.base.slice(0, 8)} 比,这次改了 ${s.changes.length} 个文件。`]
|
|
67
71
|
const base = baseChecklist(s)
|
|
68
72
|
if (base.items.length) {
|
|
69
73
|
const hits = hitsOf(s, base.items)
|
|
70
74
|
lines.push(`清单(${CHECKLIST_DIR}/):${base.items.length} 条,这次命中 ${hits.length} 条${hits.length ? `:${hits.map(hit => hit.item.id).join('、')}(testcraft checklist 列出怎么查)` : ''}`)
|
|
71
75
|
} else lines.push('清单:没有条目')
|
|
76
|
+
const missing = missingText(s.root)
|
|
77
|
+
if (missing) lines.push(missing)
|
|
72
78
|
const rules = listRules(s.root)
|
|
73
79
|
lines.push(rules.length ? `暂定的规则和记过的 bug(${RULES_DIR}/):\n${rules.map(rule => ` - ${rule}`).join('\n')}` : '暂定的规则和记过的 bug:没有')
|
|
74
80
|
console.log(lines.join('\n'))
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// gatelight 自带的默认清单条目(skills/setup-testcraft/checklist/):已接入的项目还没有的新条目,提醒补上。
|
|
2
|
+
// 项目在 .testcraft/defaults 里记一行版本号:补到了 gatelight 哪一版的默认条目(setup-testcraft 接入、补条目时写)。
|
|
3
|
+
// 只提醒比它新、项目清单里又没有同名文件的条目:项目不要的条目,不复制、照样把版本号改到这一版,就不再提醒。
|
|
4
|
+
// 没有这个文件的(这个机制之前接入的)当作一条都没补过:没有的默认条目都提醒。
|
|
5
|
+
|
|
6
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import { compareVersions, VERSION } from '../base/version.ts'
|
|
10
|
+
import { CHECKLIST_DIR, TESTCRAFT_DIR } from './config.ts'
|
|
11
|
+
|
|
12
|
+
/** 默认条目放在哪(插件里)。 */
|
|
13
|
+
export const DEFAULTS_DIR = fileURLToPath(new URL('../../skills/setup-testcraft/checklist', import.meta.url))
|
|
14
|
+
|
|
15
|
+
/** 项目补到了哪一版的默认条目。 */
|
|
16
|
+
export const SYNCED_FILE = `${TESTCRAFT_DIR}/defaults`
|
|
17
|
+
|
|
18
|
+
/** 每条默认条目是 gatelight 哪一版加的。加新的默认条目时在这里写上(测试核对和目录里的文件一一对应)。 */
|
|
19
|
+
export const DEFAULT_SINCE: Readonly<Record<string, string>> = {
|
|
20
|
+
'dev-login.md': '0.16.1',
|
|
21
|
+
'same-number.md': '0.22.2',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MissingDefault {
|
|
25
|
+
file: string
|
|
26
|
+
title: string
|
|
27
|
+
since: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 项目记的版本号;没有文件、写的不是版本号的当作 0.0.0(一条都没补过)。 */
|
|
31
|
+
function syncedVersion(root: string): string {
|
|
32
|
+
try {
|
|
33
|
+
const text = readFileSync(join(root, SYNCED_FILE), 'utf8').trim()
|
|
34
|
+
return /^\d+\.\d+\.\d+$/.test(text) ? text : '0.0.0'
|
|
35
|
+
} catch {
|
|
36
|
+
return '0.0.0'
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 比项目记的版本新、项目清单(工作区里的)又没有同名文件的默认条目。 */
|
|
41
|
+
export function missingDefaults(root: string): MissingDefault[] {
|
|
42
|
+
const synced = syncedVersion(root)
|
|
43
|
+
const have = new Set(existsSync(join(root, CHECKLIST_DIR)) ? readdirSync(join(root, CHECKLIST_DIR)) : [])
|
|
44
|
+
return Object.entries(DEFAULT_SINCE)
|
|
45
|
+
.filter(([file, since]) => compareVersions(since, synced) > 0 && !have.has(file))
|
|
46
|
+
.map(([file, since]) => ({ file, since, title: /^#\s+(.+?)\s*$/m.exec(readFileSync(join(DEFAULTS_DIR, file), 'utf8'))?.[1] ?? file }))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 说给 agent 的一段:哪几条没补、怎么补、不要的怎么记。没有要补的返回 undefined。 */
|
|
50
|
+
export function missingText(root: string): string | undefined {
|
|
51
|
+
const missing = missingDefaults(root)
|
|
52
|
+
if (missing.length === 0) return undefined
|
|
53
|
+
const named = missing.map(entry => `${entry.file.replace(/\.md$/, '')}(${entry.title})`).join('、')
|
|
54
|
+
return (
|
|
55
|
+
`gatelight 有 ${missing.length} 条默认清单条目这个仓库还没有:${named}。` +
|
|
56
|
+
`下次在这个仓库的分支上做事时顺手补上,照 gatelight:setup-testcraft 技能"已接入的项目补默认条目"一节,和那个分支一起合;` +
|
|
57
|
+
`补完(或用户说哪条不要)把 ${SYNCED_FILE} 写成 ${VERSION},就不再提醒。`
|
|
58
|
+
)
|
|
59
|
+
}
|
package/src/craft/session.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
// "测试写法"说给 agent 的话,经底座的钩子送出去(base/module.ts 的 brief):会话开始时说几句写测试的约定。
|
|
2
|
-
//
|
|
2
|
+
// 停止门里没有这个模块的项:加测试、删测试、改到清单条目,收尾时都不拦。清单在落地前的整组里提醒(见 full.ts),平时用 testcraft checklist 看。
|
|
3
|
+
// 也不查仓库里留没留记录类的 .md:程序只看得出有没有 .md,分不出过时的方案和文档站、博客、CHANGELOG 这类内容,拦了会误伤,提示里叫删还会让 agent 删掉真内容。
|
|
3
4
|
// 这里没有"证明测试管用""复查测试"这类检查:测试写得好不好靠写测试的约定,不靠再起一轮核对。
|
|
4
5
|
|
|
5
6
|
import type { Repo } from '../base/repo.ts'
|
|
6
7
|
import { joined } from './config.ts'
|
|
8
|
+
import { missingText } from './defaults.ts'
|
|
7
9
|
|
|
8
10
|
export function guide(label = '这个仓库'): string[] {
|
|
9
11
|
return [
|
|
10
12
|
`${label}用 testcraft 管测试的写法(.testcraft/):`,
|
|
11
13
|
'1. 什么时候写:分支上开发时不写新测试、不改已有的测试(需求还在试),做完告诉用户做完了、测试还没写。用户说要合并这个分支时才写:把这次定下来的规则用白话一条条列出来,交给一个子代理照 gatelight:write-tests 技能写新测试、改掉因为需求变了而不过的旧测试(没有起子代理的工具就自己写),跑通、提交,再合。例外,当场做:修已合进默认分支的规则的 bug,先写能重现它的测试再修。',
|
|
12
|
-
'2.
|
|
13
|
-
'3.
|
|
14
|
+
'2. 写哪些:小改动(文字、样式、注释、显示用的配置)不写。必跑层:钱、权限、状态与数据(什么状态下能做、数据会不会错)写在边界层(接口、命令这类从外面调用的地方,连真实的依赖)、测透,每个功能留一条主流程的端到端测试(有页面的走页面)。细节层:界面细节、样式、提示文字这类人容易漏看的,也值得写。修过的 bug 留一条能重现它的测试。在端到端测试里重复验证边界层守着的规则不写。',
|
|
15
|
+
'3. 已定的业务规则(合进默认分支的)以测试名为准。要改已定的业务规则(包括为此删测试、让测试不跑、改期望值),先用白话问用户,用户同意了再改;用户这次自己提出要改的不用再问。测试上别的调整(跟着代码改接法、换写法、挪位置、删重复的)自己定,不问用户,也不用写说明。.md 和注释都只给 AI 看,过时的说法 AI 会照着做,所以不留记录(方案、设计、说明):规则在测试里;为什么这样定、否掉的做法、用户拍板的、还没定的写进做这件事的提交说明;AI 很可能好心改掉、测试又守不住的地方,在那段代码旁边留一句为什么,别的注释不复述规则、不写代码在做什么(改到哪个文件,就把那个文件的注释收成这样)。方案只在分支上讨论时写,合并时写进提交说明、删掉文件。要改一段看不出为什么这样写的代码,先看那几行的提交说明(git log -L、git blame)。',
|
|
14
16
|
'4. 改动命中 .testcraft/checklist/ 里条目的触发条件时(testcraft checklist 列出,落地前的整组里也会说一遍),按条目查一遍,查出问题就改好。修 bug 时,写不成测试、又能从改动看出来的坑,加一条清单。',
|
|
15
17
|
]
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
/** 会话说明:接入了"测试写法"的仓库才说。 */
|
|
19
21
|
export function brief(label: string, repo?: Repo): string[] {
|
|
20
|
-
|
|
22
|
+
if (!repo || !joined(repo.root)) return []
|
|
23
|
+
const missing = missingText(repo.root)
|
|
24
|
+
return missing ? [...guide(label), missing] : guide(label)
|
|
21
25
|
}
|
package/src/keep/check.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
// codekeep check:整组里"代码规范"的那一段(见 full.ts
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// codekeep check:整组里"代码规范"的那一段(见 full.ts),也可以单独跑。依次做下面几件事:1、2 没过就停(配置不对、放松没同意,后面查了也不算);
|
|
2
|
+
// 3–5 互不依赖,一项没过也接着查,最后一起列出没过的。
|
|
3
|
+
// 1. 配置写得对不对(.codekeep/config.json),写到的文件在不在;现在这一版 eslint、prettier、tsconfig 生效的配置算不算得出来;
|
|
4
|
+
// 2. 和分叉点比,规范改松了哪些(loosen.ts、eslint.ts、prettier.ts、tsconfig.ts;biome 只看配置文件改没改),主题、组件层的样式改了哪些(styles.ts)。放松的条目交给底座的用户确认(askUser),
|
|
4
5
|
// 还没同意的这一段不过,照底座给的话让 agent 调确认工具。分叉点上还没有配置(首次接入)的不比、不问。
|
|
5
6
|
// 分叉点那一版算不出来的(工具在那一版上跑不起来),不当成没放松,列成"程序看不出"的一项,问。
|
|
6
|
-
// 3.
|
|
7
|
-
//
|
|
7
|
+
// 3. 配了 eslint 的,用项目自己的 eslint 程序接口跑一遍 lint,有错误就不过(警告不拦);eslint 起不来时停(环境问题)。不跑项目写的 lint 命令:
|
|
8
|
+
// 命令行会读批量豁免文件(放在哪、叫什么、写成目录都行),从外面猜不全;程序接口不读,查出来的就是代码按规则过没过。
|
|
9
|
+
// 4. 依次跑 checks 里的每条命令(从仓库根目录用 sh 跑)。
|
|
10
|
+
// 5. secrets 开着时用 gitleaks 扫这次改动(secrets.ts)。
|
|
8
11
|
// 退出码用底座的:0 通过;1 没通过;2 配置、环境问题(配置写错、工具没装、算不出分叉点)。
|
|
9
12
|
|
|
10
13
|
import { spawnSync } from 'node:child_process'
|
|
@@ -18,11 +21,12 @@ import { judgingFile } from '../base/judging.ts'
|
|
|
18
21
|
import { hash } from '../base/records.ts'
|
|
19
22
|
import type { Repo } from '../base/repo.ts'
|
|
20
23
|
import { type Config, CONFIG_PATH, joined, KEEP_DIR, missingFiles, parseConfig } from './config.ts'
|
|
21
|
-
import { eslintItems, type FileRules, fileRules, isCode, loadEslint, stable } from './eslint.ts'
|
|
24
|
+
import { eslintItems, type FileRules, fileRules, isCode, lint, type Linted, loadEslint, stable } from './eslint.ts'
|
|
22
25
|
import { withForkTree } from './forktree.ts'
|
|
23
|
-
import { BIOME_CONFIGS, biomeItem, configItems, GITLEAKS_CONFIG, GITLEAKS_IGNORE, gitleaksItems, removedItem
|
|
26
|
+
import { BIOME_CONFIGS, biomeItem, configItems, GITLEAKS_CONFIG, GITLEAKS_IGNORE, gitleaksItems, removedItem } from './loosen.ts'
|
|
24
27
|
import { checkedFiles, loadPrettier, prettierItem } from './prettier.ts'
|
|
25
28
|
import { scanSecrets } from './secrets.ts'
|
|
29
|
+
import { stylesItems } from './styles.ts'
|
|
26
30
|
import { findTsc, type TsSettings, tsconfigItem, tsSettings } from './tsconfig.ts'
|
|
27
31
|
|
|
28
32
|
/** 弹窗开头说这是什么的半句。 */
|
|
@@ -146,24 +150,32 @@ async function toolItems(root: string, fork: string, before: Config, now: Config
|
|
|
146
150
|
/** 和分叉点那一版比,放松了哪些。beforeText 是分叉点上的配置文件(没有就是首次接入,不比)。 */
|
|
147
151
|
async function loosened(root: string, fork: string, beforeText: string | undefined, now: Config, side: NowSide): Promise<Loosened> {
|
|
148
152
|
if (beforeText === undefined) return { items: [], reasons: [] }
|
|
149
|
-
|
|
153
|
+
// 分叉点那一版跳过现在不认的字段读:升级后去掉的字段不让整份比较落空,跳过的单列一项问
|
|
154
|
+
const parsed = parseConfig(beforeText, true)
|
|
155
|
+
const before = parsed.config
|
|
150
156
|
if (!before) {
|
|
151
157
|
return {
|
|
152
158
|
items: [{ before: stable(['config-unknown', beforeText]), after: stable(['config-unknown', now]), text: `分叉点上的 ${CONFIG_PATH} 写得不对、读不出来,程序看不出这次规范是改松还是改紧` }],
|
|
153
|
-
reasons: [`分叉点上的 ${CONFIG_PATH} 读不出来:${
|
|
159
|
+
reasons: [`分叉点上的 ${CONFIG_PATH} 读不出来:${parsed.problems.join(';')}`],
|
|
154
160
|
}
|
|
155
161
|
}
|
|
162
|
+
const skipped: ConfirmItem[] = parsed.skipped.length
|
|
163
|
+
? [
|
|
164
|
+
{
|
|
165
|
+
before: stable(['config-skipped', beforeText]),
|
|
166
|
+
after: stable(['config-skipped', now]),
|
|
167
|
+
text: [`分叉点上的 ${CONFIG_PATH} 有现在不认的字段,这几处程序看不出是改松还是改紧(别的照常比了):`, ...parsed.skipped].join('\n'),
|
|
168
|
+
},
|
|
169
|
+
]
|
|
170
|
+
: []
|
|
156
171
|
const tools = await toolItems(root, fork, before, now, side)
|
|
157
|
-
const items = [...configItems(before, now), ...tools.items]
|
|
158
|
-
if (before.eslint && now.eslint) {
|
|
159
|
-
const item = suppressionsItem(now.eslint.suppressions, judgingFile(root, fork, now.eslint.suppressions))
|
|
160
|
-
if (item) items.push(item)
|
|
161
|
-
}
|
|
172
|
+
const items = [...skipped, ...configItems(before, now), ...tools.items]
|
|
162
173
|
if (before.secrets) items.push(...gitleaksItems(judgingFile(root, fork, GITLEAKS_IGNORE), judgingFile(root, fork, GITLEAKS_CONFIG)))
|
|
163
174
|
for (const path of BIOME_CONFIGS) {
|
|
164
175
|
const item = biomeItem(path, judgingFile(root, fork, path))
|
|
165
176
|
if (item) items.push(item)
|
|
166
177
|
}
|
|
178
|
+
if (before.styles && now.styles) items.push(...stylesItems(root, fork, before.styles, now.styles))
|
|
167
179
|
return { items, reasons: tools.reasons }
|
|
168
180
|
}
|
|
169
181
|
|
|
@@ -184,16 +196,16 @@ function askLines(items: ConfirmItem[], ask: string[], reasons: string[]): strin
|
|
|
184
196
|
]
|
|
185
197
|
}
|
|
186
198
|
|
|
187
|
-
/**
|
|
188
|
-
function runChecks(root: string, config: Config): { name: string; cause: string }
|
|
199
|
+
/** 依次跑 checks 里的每条命令,一条没过也接着跑。返回没过的那几条和原因。 */
|
|
200
|
+
function runChecks(root: string, config: Config): Array<{ name: string; cause: string }> {
|
|
201
|
+
const failed: Array<{ name: string; cause: string }> = []
|
|
189
202
|
for (const check of config.checks) {
|
|
190
203
|
console.log(`== 规范检查:${check.name}(${check.command})`)
|
|
191
204
|
const r = spawnSync('/bin/sh', ['-c', check.command], { cwd: root, env: PROJECT_ENV, stdio: ['ignore', 'inherit', 'inherit'] })
|
|
192
205
|
if (r.status === 0) continue
|
|
193
|
-
|
|
194
|
-
return { name: check.name, cause }
|
|
206
|
+
failed.push({ name: check.name, cause: r.status !== null ? `退出码 ${r.status}` : r.signal ? `被信号 ${r.signal} 终止` : `没能启动:${r.error?.message ?? ''}` })
|
|
195
207
|
}
|
|
196
|
-
return
|
|
208
|
+
return failed
|
|
197
209
|
}
|
|
198
210
|
|
|
199
211
|
export async function check(repo: Repo): Promise<number> {
|
|
@@ -211,7 +223,7 @@ export async function check(repo: Repo): Promise<number> {
|
|
|
211
223
|
|
|
212
224
|
// 配置删掉了:分叉点上有能用的配置的,删掉算放松,用户同意过就退出 codekeep
|
|
213
225
|
if (judging.now === undefined) {
|
|
214
|
-
const before = judging.before === undefined ? undefined : parseConfig(judging.before).config
|
|
226
|
+
const before = judging.before === undefined ? undefined : parseConfig(judging.before, true).config
|
|
215
227
|
if (!before) {
|
|
216
228
|
const hasDir = existsSync(join(root, KEEP_DIR))
|
|
217
229
|
console.error(
|
|
@@ -254,43 +266,70 @@ export async function check(repo: Repo): Promise<number> {
|
|
|
254
266
|
}
|
|
255
267
|
const loosenedLine = found.items.length ? `规范改松 ${found.items.length} 项,用户都同意过` : '规范配置没有改松(和分叉点上的比)'
|
|
256
268
|
|
|
257
|
-
// 3
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
269
|
+
// 3–5 互不依赖:一项没过也接着查后面的,最后一起说。只说第一项的话,接入时 lint 要分很多批改,这期间格式、类型、密钥都没人查
|
|
270
|
+
const failures: string[] = []
|
|
271
|
+
let blocked = false
|
|
272
|
+
|
|
273
|
+
// 3. lint
|
|
274
|
+
let linted: Linted | undefined
|
|
275
|
+
if (config.eslint) {
|
|
276
|
+
console.log(`== lint:codekeep 用项目的 eslint 查(${config.eslint.config})`)
|
|
277
|
+
try {
|
|
278
|
+
const files = [...side.eslint!].filter(([, rules]) => rules).map(([file]) => file)
|
|
279
|
+
linted = await lint(await loadEslint(root, config.eslint.config), root, config.eslint.config, files)
|
|
280
|
+
} catch (error) {
|
|
281
|
+
console.error(`\ncodekeep check:lint 没跑成(${config.eslint.config}):${firstLine(error)}`)
|
|
282
|
+
return EXIT.usage
|
|
283
|
+
}
|
|
284
|
+
if (linted.errors > 0) {
|
|
285
|
+
console.log(linted.report)
|
|
286
|
+
failures.push(`lint 有 ${linted.errors} 个错误(上面列出;批量豁免文件在这里不起作用)`)
|
|
287
|
+
}
|
|
264
288
|
}
|
|
265
289
|
|
|
266
|
-
// 4.
|
|
290
|
+
// 4. 规范检查
|
|
291
|
+
for (const failed of runChecks(root, config)) failures.push(`规范检查"${failed.name}"没过(${failed.cause})`)
|
|
292
|
+
|
|
293
|
+
// 5. 密钥
|
|
267
294
|
if (config.secrets) {
|
|
268
295
|
const secrets = scanSecrets(root, fork.commit)
|
|
269
296
|
if ('missing' in secrets) {
|
|
270
297
|
console.error(
|
|
271
|
-
`\
|
|
298
|
+
`\n找不到 gitleaks(${CONFIG_PATH} 开着 secrets,要用它扫密钥)。这是装在这台机器上的工具,先问用户;同意后装:brew install gitleaks(没有 Homebrew 的见 https://github.com/gitleaks/gitleaks#installing)。`,
|
|
272
299
|
)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if ('problem' in secrets) {
|
|
276
|
-
console.error(`\
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if ('leaks' in secrets) {
|
|
300
|
+
failures.push('密钥没扫:找不到 gitleaks')
|
|
301
|
+
blocked = true
|
|
302
|
+
} else if ('problem' in secrets) {
|
|
303
|
+
console.error(`\n密钥没扫成:${secrets.problem}`)
|
|
304
|
+
failures.push('密钥没扫成(上面说了原因)')
|
|
305
|
+
blocked = true
|
|
306
|
+
} else if ('leaks' in secrets) {
|
|
280
307
|
console.log(
|
|
281
308
|
[
|
|
282
309
|
'',
|
|
283
|
-
'
|
|
310
|
+
'gitleaks 在这次改动里扫出了疑似密钥(上面列出,已打码)。改法:',
|
|
284
311
|
' · 真的密钥、密码:从代码里拿掉,改成从环境变量或不进版本库的本地配置读,并告诉用户这个密钥可能已经泄露、要换掉。已经提交了的,要改写这个分支上的那几个提交才去得掉,先问用户。',
|
|
285
312
|
' · 测试用的假值:改成一眼看得出是假的写法(比如 test-password-not-real)。',
|
|
286
313
|
` · 确实不是密钥的:把那一条的 Fingerprint 加进 ${GITLEAKS_IGNORE}(算放松,整组会要用户确认)。`,
|
|
287
314
|
].join('\n'),
|
|
288
315
|
)
|
|
289
|
-
|
|
316
|
+
failures.push('gitleaks 扫出了疑似密钥(上面列出)')
|
|
290
317
|
}
|
|
291
318
|
}
|
|
292
319
|
|
|
293
|
-
|
|
320
|
+
if (failures.length > 0) {
|
|
321
|
+
console.log(
|
|
322
|
+
[
|
|
323
|
+
'',
|
|
324
|
+
`codekeep check:没通过,${failures.length} 项:`,
|
|
325
|
+
...failures.map(text => ` ✗ ${text}`),
|
|
326
|
+
'按上面的输出改;不要为了过关改松规范(关规则、降级、调高上限、加忽略),确实要改的先用白话跟用户讲清。',
|
|
327
|
+
].join('\n'),
|
|
328
|
+
)
|
|
329
|
+
return blocked ? EXIT.usage : EXIT.fail
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const names = [...(linted ? [`lint${linted.warnings ? `,${linted.warnings} 条警告` : ''}`] : []), ...config.checks.map(item => item.name)].join('、')
|
|
294
333
|
console.log(`\ncodekeep check:通过。${loosenedLine};规范检查都过了(${names})${config.secrets ? ';这次改动里没扫出密钥' : ''}。`)
|
|
295
334
|
return EXIT.ok
|
|
296
335
|
}
|