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/keep/config.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
// "代码规范"在项目里的配置:.codekeep/config.json。没有 .codekeep/ 目录的仓库没接入,它不出声、不加检查。
|
|
2
|
-
// checks
|
|
3
|
-
// eslint
|
|
4
|
-
// suppressions 是批量豁免文件(eslint --suppress-all 生成的,不写就是仓库根目录的 eslint-suppressions.json)
|
|
2
|
+
// checks 规范检查的命令(类型检查、格式),直接写工具命令,不经过项目的脚本;整组里依次跑。lint 不写在这里
|
|
3
|
+
// eslint 项目的 eslint:config 是配置文件。codekeep 按它对每个代码文件算生效的规则来比,也用它直接跑 lint(check.ts)
|
|
5
4
|
// prettier 开着时比格式检查查哪些文件(prettier 在仓库根目录跑,查 git 收的文件)
|
|
6
5
|
// tsconfig 拿来比严格选项的 tsconfig 文件
|
|
7
6
|
// secrets 开着时整组里用 gitleaks 扫这次的提交和没提交的改动
|
|
7
|
+
// styles 前端只准写在这里的具体外观:theme 是主题文件,ui 是组件层目录(只看里面的样式文件);改了要用户同意(styles.ts)
|
|
8
8
|
// 这份配置是评判用的配置(base/judging.ts),走"用户同意后生效":改松的地方见 loosen.ts。
|
|
9
9
|
|
|
10
|
-
import { existsSync } from 'node:fs'
|
|
10
|
+
import { existsSync, statSync } from 'node:fs'
|
|
11
11
|
import { join, posix } from 'node:path'
|
|
12
12
|
import { fileNow, hasFile } from '../base/git.ts'
|
|
13
13
|
|
|
14
14
|
export const KEEP_DIR = '.codekeep'
|
|
15
15
|
export const CONFIG_PATH = `${KEEP_DIR}/config.json`
|
|
16
|
-
/** eslint 批量豁免文件的默认位置(eslint 自己的默认名字,相对仓库根目录)。 */
|
|
17
|
-
export const DEFAULT_SUPPRESSIONS = 'eslint-suppressions.json'
|
|
18
16
|
|
|
19
17
|
export interface Check {
|
|
20
18
|
name: string
|
|
@@ -23,7 +21,12 @@ export interface Check {
|
|
|
23
21
|
|
|
24
22
|
export interface EslintConfig {
|
|
25
23
|
config: string
|
|
26
|
-
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 主题文件和组件层目录:前端代码里具体的颜色、尺寸只准写在这两处。 */
|
|
27
|
+
export interface StylesConfig {
|
|
28
|
+
theme: string[]
|
|
29
|
+
ui: string[]
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export interface Config {
|
|
@@ -32,11 +35,14 @@ export interface Config {
|
|
|
32
35
|
tsconfig: string[]
|
|
33
36
|
prettier: boolean
|
|
34
37
|
secrets: boolean
|
|
38
|
+
styles?: StylesConfig
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export interface Parsed {
|
|
38
42
|
config?: Config
|
|
39
43
|
problems: string[]
|
|
44
|
+
/** 读的时候跳过的未知字段(只有 lenient 时有)。 */
|
|
45
|
+
skipped: string[]
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
/** 接入了:分叉点或工作区里有 .codekeep/。 */
|
|
@@ -44,8 +50,9 @@ export function joined(root: string, fork?: string): boolean {
|
|
|
44
50
|
return existsSync(join(root, KEEP_DIR)) || (fork !== undefined && hasFile(root, fork, KEEP_DIR))
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
const KEYS = ['checks', 'eslint', 'tsconfig', 'prettier', 'secrets']
|
|
48
|
-
const ESLINT_KEYS = ['config'
|
|
53
|
+
const KEYS = ['checks', 'eslint', 'tsconfig', 'prettier', 'secrets', 'styles']
|
|
54
|
+
const ESLINT_KEYS = ['config']
|
|
55
|
+
const STYLES_KEYS = ['theme', 'ui']
|
|
49
56
|
|
|
50
57
|
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
51
58
|
|
|
@@ -61,28 +68,31 @@ function relativePath(value: unknown): string | undefined {
|
|
|
61
68
|
/**
|
|
62
69
|
* 读配置的文字,只看写法(字段、类型、路径的写法),不看文件在不在:分叉点那一版也用它读。
|
|
63
70
|
* 工作区这一版另用 missingFiles 查写到的文件在不在。
|
|
71
|
+
* lenient:未知字段跳过、记在 skipped 里,不算写错。分叉点那一版用它:配置去掉过的字段(比如升级后不认的)不让整份读不出来。
|
|
64
72
|
*/
|
|
65
|
-
export function parseConfig(text: string): Parsed {
|
|
73
|
+
export function parseConfig(text: string, lenient = false): Parsed {
|
|
66
74
|
let raw: unknown
|
|
67
75
|
try {
|
|
68
76
|
raw = JSON.parse(text)
|
|
69
77
|
} catch (error) {
|
|
70
|
-
return { problems: [`${CONFIG_PATH} 不是合法的 JSON:${(error as Error).message}`] }
|
|
78
|
+
return { problems: [`${CONFIG_PATH} 不是合法的 JSON:${(error as Error).message}`], skipped: [] }
|
|
71
79
|
}
|
|
72
|
-
if (!isRecord(raw)) return { problems: [`${CONFIG_PATH} 应该是一个对象`] }
|
|
80
|
+
if (!isRecord(raw)) return { problems: [`${CONFIG_PATH} 应该是一个对象`], skipped: [] }
|
|
73
81
|
const problems: string[] = []
|
|
82
|
+
const skipped: string[] = []
|
|
83
|
+
const unknownField = (text: string): void => void (lenient ? skipped : problems).push(text)
|
|
74
84
|
const extra = Object.keys(raw).filter(key => !KEYS.includes(key))
|
|
75
|
-
if (extra.length)
|
|
85
|
+
if (extra.length) unknownField(`${CONFIG_PATH} 有未知字段 ${extra.map(key => `"${key}"`).join('、')}(认得的有 ${KEYS.join('、')})`)
|
|
76
86
|
|
|
77
87
|
const checks: Check[] = []
|
|
78
|
-
if (!Array.isArray(raw.checks) || raw.checks.length === 0) {
|
|
79
|
-
problems.push(`${CONFIG_PATH} 的 "checks"
|
|
88
|
+
if (!Array.isArray(raw.checks) || (raw.checks.length === 0 && raw.eslint === undefined)) {
|
|
89
|
+
problems.push(`${CONFIG_PATH} 的 "checks" 要写成数组,每条 { "name": 名字, "command": 命令 };没配 eslint 的不能是空的`)
|
|
80
90
|
} else {
|
|
81
91
|
raw.checks.forEach((item: unknown, index) => {
|
|
82
92
|
const where = `checks 的第 ${index + 1} 条`
|
|
83
93
|
if (!isRecord(item)) return void problems.push(`${where} 应该是 { "name": 名字, "command": 命令 }`)
|
|
84
94
|
const unknown = Object.keys(item).filter(key => key !== 'name' && key !== 'command')
|
|
85
|
-
if (unknown.length)
|
|
95
|
+
if (unknown.length) unknownField(`${where} 有未知字段 ${unknown.map(key => `"${key}"`).join('、')}`)
|
|
86
96
|
const { name, command } = item
|
|
87
97
|
if (typeof name !== 'string' || name.trim() === '' || /[\n\r]/.test(name)) return void problems.push(`${where} 要写名字(name,一行)`)
|
|
88
98
|
if (typeof command !== 'string' || command.trim() === '') return void problems.push(`${where}(${name})要写命令(command)`)
|
|
@@ -94,15 +104,13 @@ export function parseConfig(text: string): Parsed {
|
|
|
94
104
|
let eslint: EslintConfig | undefined
|
|
95
105
|
if (raw.eslint !== undefined) {
|
|
96
106
|
const value = raw.eslint
|
|
97
|
-
if (!isRecord(value)) problems.push(`${CONFIG_PATH} 的 "eslint" 应该是 { "config":
|
|
107
|
+
if (!isRecord(value)) problems.push(`${CONFIG_PATH} 的 "eslint" 应该是 { "config": 配置文件 }`)
|
|
98
108
|
else {
|
|
99
109
|
const unknown = Object.keys(value).filter(key => !ESLINT_KEYS.includes(key))
|
|
100
|
-
if (unknown.length)
|
|
110
|
+
if (unknown.length) unknownField(`${CONFIG_PATH} 的 "eslint" 有未知字段 ${unknown.map(key => `"${key}"`).join('、')}`)
|
|
101
111
|
const config = relativePath(value.config)
|
|
102
112
|
if (config === undefined) problems.push(`${CONFIG_PATH} 的 "eslint.config" 要写 eslint 配置文件(仓库里的相对路径,比如 "eslint.config.mjs")`)
|
|
103
|
-
|
|
104
|
-
if (suppressions === undefined) problems.push(`${CONFIG_PATH} 的 "eslint.suppressions" 要写批量豁免文件(仓库里的相对路径)`)
|
|
105
|
-
if (config !== undefined && suppressions !== undefined) eslint = { config, suppressions }
|
|
113
|
+
if (config !== undefined) eslint = { config }
|
|
106
114
|
}
|
|
107
115
|
}
|
|
108
116
|
|
|
@@ -111,8 +119,26 @@ export function parseConfig(text: string): Parsed {
|
|
|
111
119
|
if (raw[key] !== undefined && typeof raw[key] !== 'boolean') problems.push(`${CONFIG_PATH} 的 "${key}" 要写 true 或 false`)
|
|
112
120
|
}
|
|
113
121
|
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
const styles = raw.styles === undefined ? undefined : stylesOf(raw.styles, problems, unknownField)
|
|
123
|
+
|
|
124
|
+
if (problems.length || tsconfig === undefined) return { problems, skipped }
|
|
125
|
+
return {
|
|
126
|
+
config: { checks, ...(eslint ? { eslint } : {}), tsconfig, prettier: raw.prettier === true, secrets: raw.secrets === true, ...(styles ? { styles } : {}) },
|
|
127
|
+
problems,
|
|
128
|
+
skipped,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** "styles":theme、ui 各是一组路径,至少写一组。 */
|
|
133
|
+
function stylesOf(value: unknown, problems: string[], unknownField: (text: string) => void): StylesConfig | undefined {
|
|
134
|
+
const shape = `{ "theme": [主题文件], "ui": [组件层目录] }`
|
|
135
|
+
if (!isRecord(value)) return void problems.push(`${CONFIG_PATH} 的 "styles" 应该是 ${shape}`)
|
|
136
|
+
const unknown = Object.keys(value).filter(key => !STYLES_KEYS.includes(key))
|
|
137
|
+
if (unknown.length) unknownField(`${CONFIG_PATH} 的 "styles" 有未知字段 ${unknown.map(key => `"${key}"`).join('、')}`)
|
|
138
|
+
if (value.theme === undefined && value.ui === undefined) return void problems.push(`${CONFIG_PATH} 的 "styles" 要写 theme、ui 里的至少一项:${shape}`)
|
|
139
|
+
const theme = value.theme === undefined ? [] : paths(value.theme, 'styles.theme', '主题文件', problems)
|
|
140
|
+
const ui = value.ui === undefined ? [] : paths(value.ui, 'styles.ui', '组件层目录', problems)
|
|
141
|
+
return theme && ui ? { theme, ui } : undefined
|
|
116
142
|
}
|
|
117
143
|
|
|
118
144
|
/** 一组仓库里的文件:非空数组,不重复。 */
|
|
@@ -132,8 +158,12 @@ function paths(value: unknown, name: string, what: string, problems: string[]):
|
|
|
132
158
|
return problems.length > found ? undefined : result
|
|
133
159
|
}
|
|
134
160
|
|
|
135
|
-
/**
|
|
161
|
+
/** 工作区这一版配置里写到、却不在的文件和目录。 */
|
|
136
162
|
export function missingFiles(root: string, config: Config): string[] {
|
|
137
|
-
const listed = [...(config.eslint ? [config.eslint.config] : []), ...config.tsconfig]
|
|
138
|
-
|
|
163
|
+
const listed = [...(config.eslint ? [config.eslint.config] : []), ...config.tsconfig, ...(config.styles?.theme ?? [])]
|
|
164
|
+
const dirs = config.styles?.ui ?? []
|
|
165
|
+
return [
|
|
166
|
+
...listed.filter(path => fileNow(root, path) === undefined).map(path => `${CONFIG_PATH} 里写的 ${path} 不在(要写仓库里现有的文件)`),
|
|
167
|
+
...dirs.filter(dir => !statSync(join(root, dir), { throwIfNoEntry: false })?.isDirectory()).map(dir => `${CONFIG_PATH} 里写的 ${dir} 不在(要写仓库里现有的目录)`),
|
|
168
|
+
]
|
|
139
169
|
}
|
package/src/keep/eslint.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// 算它实际用的规则,分叉点那一版和现在比(eslint 的配置是代码,读文件读不出规则)。路径都传绝对路径:相对路径会被当成忽略。
|
|
3
3
|
// 每个文件都算,不挑代表文件:按目录加的覆盖、忽略,挑代表文件会漏。实测 1500 个文件 0.3 秒。
|
|
4
4
|
// 算放松的:规则没了、关了、error 降成 warn;上限类规则(行数、复杂度、嵌套、参数)数字调大;别的规则改了参数(判断不了方向);
|
|
5
|
-
// 文件变成不被 lint(被忽略、配置不再覆盖它);reportUnusedDisableDirectives
|
|
5
|
+
// 文件变成不被 lint(被忽略、配置不再覆盖它);reportUnusedDisableDirectives 降级或关掉;noInlineConfig 关掉(代码里的注释又能就地关规则)。
|
|
6
|
+
// 新加规则、调严的不算。
|
|
6
7
|
// 只比两边都有的文件:这次新加的文件没有"原来"。
|
|
7
8
|
|
|
8
9
|
import { createRequire } from 'node:module'
|
|
@@ -16,6 +17,8 @@ export interface Effective {
|
|
|
16
17
|
rules: Record<string, unknown[]>
|
|
17
18
|
/** 没用的 eslint-disable 注释报不报:0 关、1 警告、2 报错。 */
|
|
18
19
|
unusedDirectives: number
|
|
20
|
+
/** 代码里就地关规则、改配置的注释(eslint-disable 和 eslint 规则: off 这类)不起作用。 */
|
|
21
|
+
noInlineConfig: boolean
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
/** 文件(相对仓库根目录)→ 生效的规则。 */
|
|
@@ -24,9 +27,19 @@ export type FileRules = Map<string, Effective | undefined>
|
|
|
24
27
|
/** eslint 查的代码文件。 */
|
|
25
28
|
export const isCode = (path: string): boolean => /\.[cm]?[jt]sx?$/.test(path)
|
|
26
29
|
|
|
30
|
+
interface LintMessage {
|
|
31
|
+
severity: number
|
|
32
|
+
}
|
|
33
|
+
interface LintResult {
|
|
34
|
+
errorCount: number
|
|
35
|
+
warningCount: number
|
|
36
|
+
messages: LintMessage[]
|
|
37
|
+
}
|
|
27
38
|
interface EslintInstance {
|
|
28
39
|
isPathIgnored(path: string): Promise<boolean>
|
|
29
|
-
|
|
40
|
+
lintFiles(paths: string[]): Promise<LintResult[]>
|
|
41
|
+
loadFormatter(name: string): Promise<{ format(results: LintResult[]): string | Promise<string> }>
|
|
42
|
+
calculateConfigForFile(path: string): Promise<{ rules?: Record<string, unknown>; linterOptions?: { reportUnusedDisableDirectives?: unknown; noInlineConfig?: unknown } } | undefined>
|
|
30
43
|
}
|
|
31
44
|
type EslintClass = new (options: { cwd: string; overrideConfigFile: string }) => EslintInstance
|
|
32
45
|
|
|
@@ -72,11 +85,36 @@ export async function fileRules(eslint: EslintClass, tree: string, config: strin
|
|
|
72
85
|
const [severity, ...options] = Array.isArray(setting) ? setting : [setting]
|
|
73
86
|
rules[name] = [level(severity), ...options]
|
|
74
87
|
}
|
|
75
|
-
|
|
88
|
+
const options = computed.linterOptions
|
|
89
|
+
result.set(file, { rules, unusedDirectives: level(options?.reportUnusedDisableDirectives), noInlineConfig: options?.noInlineConfig === true })
|
|
76
90
|
}
|
|
77
91
|
return result
|
|
78
92
|
}
|
|
79
93
|
|
|
94
|
+
/** lint 的结果:错误、警告各几条,有错误时是只列错误的报告。 */
|
|
95
|
+
export interface Linted {
|
|
96
|
+
errors: number
|
|
97
|
+
warnings: number
|
|
98
|
+
report: string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 用项目自己的 eslint 程序接口跑一遍 lint,查 files(相对 root、被 lint 的代码文件)。程序接口不读批量豁免文件
|
|
103
|
+
* (eslint-suppressions.json 只在 eslint 命令行里起作用),所以豁免文件放在哪、叫什么都不影响结果。跑不起来时抛错。
|
|
104
|
+
*/
|
|
105
|
+
export async function lint(eslint: EslintClass, root: string, config: string, files: string[]): Promise<Linted> {
|
|
106
|
+
const instance = new eslint({ cwd: root, overrideConfigFile: join(root, config) })
|
|
107
|
+
const results = await instance.lintFiles(files.map(file => join(root, file)))
|
|
108
|
+
const errors = results.reduce((sum, result) => sum + result.errorCount, 0)
|
|
109
|
+
const warnings = results.reduce((sum, result) => sum + result.warningCount, 0)
|
|
110
|
+
if (errors === 0) return { errors, warnings, report: '' }
|
|
111
|
+
const onlyErrors = results
|
|
112
|
+
.filter(result => result.errorCount > 0)
|
|
113
|
+
.map(result => ({ ...result, warningCount: 0, fixableWarningCount: 0, messages: result.messages.filter(message => message.severity === 2) }))
|
|
114
|
+
const formatter = await instance.loadFormatter('stylish')
|
|
115
|
+
return { errors, warnings, report: await formatter.format(onlyErrors) }
|
|
116
|
+
}
|
|
117
|
+
|
|
80
118
|
/** 键按字母排的 JSON:参数一样、写的顺序不同算一样。 */
|
|
81
119
|
export function stable(value: unknown): string {
|
|
82
120
|
return JSON.stringify(value, (_key, item: unknown) =>
|
|
@@ -113,7 +151,7 @@ const RULE_PLAIN: Record<string, string> = {
|
|
|
113
151
|
}
|
|
114
152
|
|
|
115
153
|
/** 规则在弹窗里的叫法:白话(规则名),没有白话的只写规则名。 */
|
|
116
|
-
|
|
154
|
+
function ruleName(rule: string): string {
|
|
117
155
|
const plain = RULE_PLAIN[rule] ?? LIMITS[rule]?.what
|
|
118
156
|
return plain ? `${plain}(${rule})` : rule
|
|
119
157
|
}
|
|
@@ -176,11 +214,98 @@ function changesOf(before: Effective, now: Effective): Change[] {
|
|
|
176
214
|
text: `没用了的"这里不查"注释(eslint-disable)从${LEVEL_NAMES[before.unusedDirectives]}改成${LEVEL_NAMES[now.unusedDirectives]}(reportUnusedDisableDirectives):以后用不上的这类注释可以留在代码里`,
|
|
177
215
|
})
|
|
178
216
|
}
|
|
217
|
+
if (before.noInlineConfig && !now.noInlineConfig) {
|
|
218
|
+
changes.push({
|
|
219
|
+
before: stable(['noInlineConfig', true]),
|
|
220
|
+
after: stable(['noInlineConfig', false]),
|
|
221
|
+
text: '代码里就地关规则的注释(eslint-disable、/* eslint 规则: off */)从不起作用改成起作用(关掉了 noInlineConfig):以后在代码里写一句注释就能关掉规则,不用改配置',
|
|
222
|
+
})
|
|
223
|
+
}
|
|
179
224
|
return changes
|
|
180
225
|
}
|
|
181
226
|
|
|
227
|
+
/** 参数整段列出来的长度上限:再长的只列改了的几处,整段列出来人看不出改了什么。 */
|
|
228
|
+
const WHOLE = 300
|
|
229
|
+
/** 改了的地方前后各带几个字。 */
|
|
230
|
+
const AROUND = 30
|
|
231
|
+
|
|
232
|
+
/** 两段只差一部分的文字:从第一处不同到最后一处不同,前后各带几个字。按字算,不切坏 emoji。 */
|
|
233
|
+
function around(was: string, is: string): [string, string] {
|
|
234
|
+
const [a, b] = [[...was], [...is]]
|
|
235
|
+
let start = 0
|
|
236
|
+
while (start < a.length && start < b.length && a[start] === b[start]) start++
|
|
237
|
+
let end = 0
|
|
238
|
+
while (end < a.length - start && end < b.length - start && a[a.length - 1 - end] === b[b.length - 1 - end]) end++
|
|
239
|
+
const cut = (chars: string[]): string => {
|
|
240
|
+
const from = Math.max(0, start - AROUND)
|
|
241
|
+
const to = Math.min(chars.length, chars.length - end + AROUND)
|
|
242
|
+
return `${from > 0 ? '…' : ''}${chars.slice(from, to).join('')}${to < chars.length ? '…' : ''}`
|
|
243
|
+
}
|
|
244
|
+
return [cut(a), cut(b)]
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** 两串逐项对齐(最长公共子序列):没变的项对上,剩下的是删掉的和加上的。 */
|
|
248
|
+
function align(was: string[], is: string[]): { kind: 'same' | 'gone' | 'new'; text: string; at: number }[] {
|
|
249
|
+
const longest = was.map(() => new Array<number>(is.length + 1).fill(0))
|
|
250
|
+
longest.push(new Array<number>(is.length + 1).fill(0))
|
|
251
|
+
for (let i = was.length - 1; i >= 0; i--) {
|
|
252
|
+
for (let j = is.length - 1; j >= 0; j--) {
|
|
253
|
+
longest[i]![j] = was[i] === is[j] ? longest[i + 1]![j + 1]! + 1 : Math.max(longest[i + 1]![j]!, longest[i]![j + 1]!)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const steps: { kind: 'same' | 'gone' | 'new'; text: string; at: number }[] = []
|
|
257
|
+
let [i, j] = [0, 0]
|
|
258
|
+
while (i < was.length || j < is.length) {
|
|
259
|
+
if (i < was.length && j < is.length && was[i] === is[j]) {
|
|
260
|
+
steps.push({ kind: 'same', text: was[i]!, at: j })
|
|
261
|
+
i++
|
|
262
|
+
j++
|
|
263
|
+
} else if (j < is.length && (i === was.length || longest[i + 1]![j]! < longest[i]![j + 1]!)) {
|
|
264
|
+
steps.push({ kind: 'new', text: is[j]!, at: j })
|
|
265
|
+
j++
|
|
266
|
+
} else {
|
|
267
|
+
steps.push({ kind: 'gone', text: was[i]!, at: i })
|
|
268
|
+
i++
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return steps
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 参数很长(比如一长串选择器)时只列改了的地方,一处不漏:两版逐项对齐,没变的不列;
|
|
276
|
+
* 同一段里删一项、加一项的配成"改了",只列改了的那段,前后带几个字;多出来的整项列出来。
|
|
277
|
+
*/
|
|
278
|
+
function placesChanged(was: unknown[], is: unknown[]): string[] {
|
|
279
|
+
const lines: string[] = []
|
|
280
|
+
const steps = align(was.map(item => stable(item)), is.map(item => stable(item)))
|
|
281
|
+
let index = 0
|
|
282
|
+
while (index < steps.length) {
|
|
283
|
+
if (steps[index]!.kind === 'same') {
|
|
284
|
+
index++
|
|
285
|
+
continue
|
|
286
|
+
}
|
|
287
|
+
const gone: { text: string; at: number }[] = []
|
|
288
|
+
const added: { text: string; at: number }[] = []
|
|
289
|
+
while (index < steps.length && steps[index]!.kind !== 'same') {
|
|
290
|
+
const step = steps[index++]!
|
|
291
|
+
;(step.kind === 'gone' ? gone : added).push(step)
|
|
292
|
+
}
|
|
293
|
+
const pairs = Math.min(gone.length, added.length)
|
|
294
|
+
for (let k = 0; k < pairs; k++) {
|
|
295
|
+
const [shortBefore, shortAfter] = around(gone[k]!.text, added[k]!.text)
|
|
296
|
+
lines.push(`第 ${added[k]!.at + 1} 项 原来:${shortBefore}`, `第 ${added[k]!.at + 1} 项 现在:${shortAfter}`)
|
|
297
|
+
}
|
|
298
|
+
for (const item of gone.slice(pairs)) lines.push(`少了原来的第 ${item.at + 1} 项:${item.text}`)
|
|
299
|
+
for (const item of added.slice(pairs)) lines.push(`多了现在的第 ${item.at + 1} 项:${item.text}`)
|
|
300
|
+
}
|
|
301
|
+
return lines
|
|
302
|
+
}
|
|
303
|
+
|
|
182
304
|
function changedText(rule: string, was: unknown[], is: unknown[]): string {
|
|
183
|
-
|
|
305
|
+
const title = `lint 规则 ${ruleName(rule)} 的参数改了,程序看不出是改松还是改紧`
|
|
306
|
+
const [before, after] = [stable(was), stable(is)]
|
|
307
|
+
if (before.length + after.length <= WHOLE) return [title, `原来:${before}`, `现在:${after}`].join('\n')
|
|
308
|
+
return [title, ...placesChanged(was, is)].join('\n')
|
|
184
309
|
}
|
|
185
310
|
|
|
186
311
|
/** 列出来的文件最多几个。 */
|
package/src/keep/loosen.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// 读文件就能比的放松:.codekeep/config.json、
|
|
2
|
-
// 放松的列成条目交给底座的用户确认(base/confirm.ts
|
|
1
|
+
// 读文件就能比的放松:.codekeep/config.json、gitleaks 的忽略文件和配置、biome 的配置。和分叉点那一版比,
|
|
2
|
+
// 放松的列成条目交给底座的用户确认(base/confirm.ts);收紧的(加检查)不问。
|
|
3
3
|
// eslint、tsconfig 生效的配置要跑工具才算得出来,见 eslint.ts、tsconfig.ts。
|
|
4
4
|
//
|
|
5
5
|
// 每一项的改之前、改成什么写成能区分同一项改动的内容:同一条检查的同一次改命令在哪个分支上都是同一项,共用一次同意;
|
|
@@ -9,7 +9,7 @@ import type { ConfirmItem } from '../base/confirm.ts'
|
|
|
9
9
|
import type { Judging } from '../base/judging.ts'
|
|
10
10
|
import { hash } from '../base/records.ts'
|
|
11
11
|
import { CONFIG_PATH, type Config, KEEP_DIR } from './config.ts'
|
|
12
|
-
import {
|
|
12
|
+
import { stable } from './eslint.ts'
|
|
13
13
|
|
|
14
14
|
/** gitleaks 的忽略文件和配置(仓库根目录;gitleaks 在仓库根目录跑时用的就是这两个)。 */
|
|
15
15
|
export const GITLEAKS_IGNORE = '.gitleaksignore'
|
|
@@ -58,13 +58,6 @@ export function configItems(before: Config, now: Config): ConfirmItem[] {
|
|
|
58
58
|
text: `拿来比规则的 eslint 配置文件从 ${before.eslint.config} 换成了 ${now.eslint.config}:程序看不出两份是不是一回事,lint 实际用的可能不是这一份`,
|
|
59
59
|
})
|
|
60
60
|
}
|
|
61
|
-
if (now.eslint.suppressions !== before.eslint.suppressions) {
|
|
62
|
-
items.push({
|
|
63
|
-
before: stable(['eslint.suppressions', before.eslint.suppressions]),
|
|
64
|
-
after: stable(['eslint.suppressions', now.eslint.suppressions]),
|
|
65
|
-
text: `eslint 的批量豁免文件从 ${before.eslint.suppressions} 换成了 ${now.eslint.suppressions}:换过去的那份里豁免了什么没和原来的比`,
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
61
|
}
|
|
69
62
|
}
|
|
70
63
|
for (const tsconfig of before.tsconfig.filter(path => !now.tsconfig.includes(path))) {
|
|
@@ -74,59 +67,13 @@ export function configItems(before: Config, now: Config): ConfirmItem[] {
|
|
|
74
67
|
items.push({ before: stable(['prettier', true]), after: stable(['prettier', false]), text: '不再比格式检查查哪些文件(关掉了 prettier 一项):以后往忽略文件里加路径、躲开格式检查,程序看不出来' })
|
|
75
68
|
}
|
|
76
69
|
if (before.secrets && !now.secrets) items.push({ before: stable(['secrets', true]), after: stable(['secrets', false]), text: '关掉了密钥扫描(secrets):以后提交里带了密钥、密码,整组不再拦' })
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** 批量豁免文件:文件 → 规则 → 豁免了几处。读不出来时是 undefined。 */
|
|
81
|
-
type Suppressions = Map<string, number>
|
|
82
|
-
|
|
83
|
-
function suppressionsOf(text: string): Suppressions | undefined {
|
|
84
|
-
try {
|
|
85
|
-
const raw = JSON.parse(text) as unknown
|
|
86
|
-
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return undefined
|
|
87
|
-
const counts: Suppressions = new Map()
|
|
88
|
-
for (const [file, rules] of Object.entries(raw as Record<string, unknown>)) {
|
|
89
|
-
if (typeof rules !== 'object' || rules === null) return undefined
|
|
90
|
-
for (const [rule, entry] of Object.entries(rules as Record<string, unknown>)) {
|
|
91
|
-
const count = (entry as { count?: unknown } | null)?.count
|
|
92
|
-
if (typeof count !== 'number') return undefined
|
|
93
|
-
counts.set(`${file}\0${rule}`, count)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return counts
|
|
97
|
-
} catch {
|
|
98
|
-
return undefined
|
|
70
|
+
for (const path of before.styles?.theme.filter(item => !now.styles?.theme.includes(item)) ?? []) {
|
|
71
|
+
items.push({ before: stable(['styles.theme', path]), after: '', text: `不再管主题文件 ${path}(从 styles 里去掉了):以后改它不再问你` })
|
|
99
72
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/** 列出来的最多几处。 */
|
|
103
|
-
const SHOWN = 20
|
|
104
|
-
|
|
105
|
-
/** eslint 的批量豁免文件里,哪条规则、哪个文件豁免的数量变多了:合成一项。 */
|
|
106
|
-
export function suppressionsItem(path: string, judging: Judging): ConfirmItem | undefined {
|
|
107
|
-
if (judging.now === undefined) return undefined
|
|
108
|
-
const now = suppressionsOf(judging.now)
|
|
109
|
-
const before = judging.before === undefined ? new Map<string, number>() : suppressionsOf(judging.before)
|
|
110
|
-
if (!now || !before) {
|
|
111
|
-
if (judging.before === judging.now) return undefined
|
|
112
|
-
return {
|
|
113
|
-
before: hash(judging.before),
|
|
114
|
-
after: hash(judging.now),
|
|
115
|
-
text: `eslint 的批量豁免文件 ${path} 改了,${!now ? '现在这一版' : '分叉点那一版'}读不出来,程序看不出是不是多豁免了`,
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const more = [...now].filter(([key, count]) => count > (before.get(key) ?? 0)).sort(([a], [b]) => (a < b ? -1 : 1))
|
|
119
|
-
if (more.length === 0) return undefined
|
|
120
|
-
const lines = more.slice(0, SHOWN).map(([key, count]) => {
|
|
121
|
-
const [file, rule] = key.split('\0')
|
|
122
|
-
return `${file}:${ruleName(rule ?? '')} 从 ${before.get(key) ?? 0} 处变成 ${count} 处`
|
|
123
|
-
})
|
|
124
|
-
if (more.length > SHOWN) lines.push(`……还有 ${more.length - SHOWN} 处`)
|
|
125
|
-
return {
|
|
126
|
-
before: stable(more.map(([key]) => [key, before.get(key) ?? 0])),
|
|
127
|
-
after: stable(more),
|
|
128
|
-
text: [`eslint 的批量豁免文件 ${path} 多豁免了 ${more.length} 处:这些地方违反了规则也照样通过`, ...lines].join('\n'),
|
|
73
|
+
for (const dir of before.styles?.ui.filter(item => !now.styles?.ui.includes(item)) ?? []) {
|
|
74
|
+
items.push({ before: stable(['styles.ui', dir]), after: '', text: `不再管组件层目录 ${dir} 里的样式文件(从 styles 里去掉了):以后改这些样式不再问你` })
|
|
129
75
|
}
|
|
76
|
+
return items
|
|
130
77
|
}
|
|
131
78
|
|
|
132
79
|
/** .gitleaksignore 的条目(每行一条,# 开头的是注释)。 */
|
|
@@ -136,6 +83,9 @@ const entries = (text: string | undefined): string[] =>
|
|
|
136
83
|
.map(line => line.trim())
|
|
137
84
|
.filter(line => line !== '' && !line.startsWith('#'))
|
|
138
85
|
|
|
86
|
+
/** 列出来的最多几条。 */
|
|
87
|
+
const SHOWN = 20
|
|
88
|
+
|
|
139
89
|
/** gitleaks 的忽略文件多了条目、配置改了(配置是 TOML,程序看不出方向,改了就问)。 */
|
|
140
90
|
export function gitleaksItems(ignore: Judging, config: Judging): ConfirmItem[] {
|
|
141
91
|
const items: ConfirmItem[] = []
|
package/src/keep/session.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
// "代码规范"说给 agent 的话,经底座的钩子送出去(base/module.ts 的 brief):会话开始时说几句规范的约定。
|
|
2
|
+
// 配置里写了 styles(配了前端规则)的,多说一条前端的约定。
|
|
2
3
|
// 没有改文件前的拦截和停止门:lint 自己会报,规范检查在落地前的整组里跑(见 full.ts)。
|
|
3
4
|
|
|
4
5
|
import { existsSync } from 'node:fs'
|
|
5
6
|
import { join } from 'node:path'
|
|
6
7
|
import type { Repo } from '../base/repo.ts'
|
|
7
|
-
import {
|
|
8
|
+
import { fileNow } from '../base/git.ts'
|
|
9
|
+
import { CONFIG_PATH, KEEP_DIR, parseConfig, type StylesConfig } from './config.ts'
|
|
8
10
|
|
|
9
|
-
export function guide(label = '这个仓库'): string[] {
|
|
11
|
+
export function guide(label = '这个仓库', styles?: StylesConfig): string[] {
|
|
10
12
|
return [
|
|
11
13
|
`${label}用 codekeep 管代码规范(${KEEP_DIR}/):`,
|
|
12
|
-
`1. 类型检查、lint、格式检查由 codekeep 在整组(testpace full
|
|
13
|
-
'2. 不改松规范:不关规则、不把 error 降成 warn
|
|
14
|
+
`1. 类型检查、lint、格式检查由 codekeep 在整组(testpace full)里跑:lint 由它用项目的 eslint 直接查,别的命令和要比的配置写在 ${CONFIG_PATH}。`,
|
|
15
|
+
'2. 不改松规范:不关规则、不把 error 降成 warn、不调高长度和复杂度上限、不加忽略的路径、不关严格类型选项;eslint 的批量豁免(eslint-suppressions.json)在整组里不起作用,超标的改代码。确实要改,整组会要用户确认:先在对话里用白话讲清改了哪条、为什么只能这样。',
|
|
14
16
|
'3. 代码里"这里不查"的注释(eslint-disable、@ts-expect-error 这类)必须写理由,比如 // eslint-disable-next-line 规则名 -- 理由;能改代码就改代码,不加这种注释。',
|
|
15
17
|
'4. 提交里不放密钥、密码;测试用的假值写得一眼能看出是假的(比如 test-password-not-real)。',
|
|
18
|
+
...(styles ? [frontend(styles)] : []),
|
|
16
19
|
]
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
function frontend(styles: StylesConfig): string {
|
|
23
|
+
const places = [...styles.theme.map(path => `主题 ${path}`), ...styles.ui.map(dir => `组件层 ${dir} 里的样式文件`)].join('、')
|
|
24
|
+
return [
|
|
25
|
+
'5. 前端:页面上不加说明文字;组件不合适时不写样式、不写具体的值去补,告诉用户。',
|
|
26
|
+
`具体的颜色、尺寸只写在${places};要改先在对话里讲清楚改什么、为什么,整组会要用户确认。`,
|
|
27
|
+
'前端文件里"这里不查"的注释不起作用,lint 报了就改代码。',
|
|
28
|
+
].join('')
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
/** 会话说明:接入了"代码规范"的仓库(工作区里有 .codekeep/)才说。 */
|
|
20
32
|
export function brief(label: string, repo?: Repo): string[] {
|
|
21
|
-
|
|
33
|
+
if (!repo || !existsSync(join(repo.root, KEEP_DIR))) return []
|
|
34
|
+
const text = fileNow(repo.root, CONFIG_PATH)
|
|
35
|
+
return guide(label, text === undefined ? undefined : parseConfig(text).config?.styles)
|
|
22
36
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// 前端具体的外观只准写在主题文件和组件层目录的样式文件里,这两处改了要用户同意。
|
|
2
|
+
// 读文件就能比:和分叉点那一版比,主题文件、组件层目录里的样式文件(.css、.less、.scss 这类)新加、删掉、改了内容的,
|
|
3
|
+
// 一个文件列一项,按行列出原来和现在。只是空白、空行变了的不问。组件层目录里别的文件(组件代码、取数)不管。
|
|
4
|
+
// 只比两边配置里都写着的路径:这次新写进配置的(首次接入、新加的目录)不比。
|
|
5
|
+
|
|
6
|
+
import type { ConfirmItem } from '../base/confirm.ts'
|
|
7
|
+
import { type Judging, judgingDir, judgingFile } from '../base/judging.ts'
|
|
8
|
+
import { hash } from '../base/records.ts'
|
|
9
|
+
import type { StylesConfig } from './config.ts'
|
|
10
|
+
import { stable } from './eslint.ts'
|
|
11
|
+
|
|
12
|
+
/** 组件层目录里算样式文件的。 */
|
|
13
|
+
export const isStyle = (path: string): boolean => /\.(css|less|s[ac]ss|styl)$/.test(path)
|
|
14
|
+
|
|
15
|
+
/** 一项里最多列几行。 */
|
|
16
|
+
const SHOWN = 10
|
|
17
|
+
|
|
18
|
+
const linesOf = (text: string | undefined): string[] =>
|
|
19
|
+
(text ?? '')
|
|
20
|
+
.split('\n')
|
|
21
|
+
.map(line => line.trim())
|
|
22
|
+
.filter(line => line !== '')
|
|
23
|
+
|
|
24
|
+
/** a 里有、b 里没有的行,按 a 的顺序;同样的行按次数算。 */
|
|
25
|
+
function minus(a: string[], b: string[]): string[] {
|
|
26
|
+
const left = new Map<string, number>()
|
|
27
|
+
for (const line of b) left.set(line, (left.get(line) ?? 0) + 1)
|
|
28
|
+
return a.filter(line => {
|
|
29
|
+
const count = left.get(line) ?? 0
|
|
30
|
+
if (count > 0) left.set(line, count - 1)
|
|
31
|
+
return count === 0
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 一个文件两版之间的一项:只是空白、空行变了的没有。what 是这个文件在弹窗里的叫法,then 是改了以后会怎样。 */
|
|
36
|
+
function fileItem(path: string, judging: Judging, what: string, then: string): ConfirmItem | undefined {
|
|
37
|
+
const before = linesOf(judging.before)
|
|
38
|
+
const now = linesOf(judging.now)
|
|
39
|
+
const removed = minus(before, now)
|
|
40
|
+
const added = minus(now, before)
|
|
41
|
+
if (removed.length === 0 && added.length === 0 && (judging.before === undefined) === (judging.now === undefined)) return undefined
|
|
42
|
+
const head =
|
|
43
|
+
judging.before === undefined
|
|
44
|
+
? `新加了${what} ${path}(${now.length} 行):${then}`
|
|
45
|
+
: judging.now === undefined
|
|
46
|
+
? `删掉了${what} ${path}:${then}`
|
|
47
|
+
: `${what} ${path} 改了(删掉 ${removed.length} 行、新加 ${added.length} 行):${then}`
|
|
48
|
+
const lines = [...removed.map(line => `原来:${line}`), ...added.map(line => `现在:${line}`)]
|
|
49
|
+
const shown = judging.now === undefined ? [] : lines.slice(0, SHOWN)
|
|
50
|
+
if (judging.now !== undefined && lines.length > SHOWN) shown.push(`……还有 ${lines.length - SHOWN} 行`)
|
|
51
|
+
return { before: stable(['style', path, hash(judging.before)]), after: stable(['style', path, hash(judging.now)]), text: [head, ...shown].join('\n') }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 主题文件、组件层的样式文件改了的:一个文件一项。 */
|
|
55
|
+
export function stylesItems(root: string, fork: string, before: StylesConfig, now: StylesConfig): ConfirmItem[] {
|
|
56
|
+
const items: ConfirmItem[] = []
|
|
57
|
+
const themes = before.theme.filter(path => now.theme.includes(path))
|
|
58
|
+
for (const path of themes) {
|
|
59
|
+
const item = fileItem(path, judgingFile(root, fork, path), '主题文件', '页面上用到这些颜色、尺寸的地方都会跟着变')
|
|
60
|
+
if (item) items.push(item)
|
|
61
|
+
}
|
|
62
|
+
const seen = new Set(themes)
|
|
63
|
+
for (const dir of before.ui.filter(path => now.ui.includes(path))) {
|
|
64
|
+
for (const [path, judging] of judgingDir(root, fork, dir)) {
|
|
65
|
+
if (!isStyle(path) || seen.has(path)) continue
|
|
66
|
+
seen.add(path)
|
|
67
|
+
const item = fileItem(path, judging, '组件层的样式文件', '用到它的组件在页面上的样子会变,要到页面上看')
|
|
68
|
+
if (item) items.push(item)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return items
|
|
72
|
+
}
|
package/src/pace/commands.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { currentBranch, defaultBranch, forkPoint, landings, workTreeId } from '.
|
|
|
11
11
|
import { busyText, failureText, ignoredBy } from '../base/repo.ts'
|
|
12
12
|
import { commandExists, COMMAND_KEYS, loadConfig } from './config.ts'
|
|
13
13
|
import { askLayermap, BRANCH_CAP, fullReasons, INDIRECT_RANK, LAYERMAP_HINT, NEARBY_RANK, outsideNote } from './focused.ts'
|
|
14
|
-
import { paceRuns, runRecorded } from './record.ts'
|
|
14
|
+
import { paceRuns, type Recorded, runRecorded } from './record.ts'
|
|
15
15
|
import { renderReport } from './report.ts'
|
|
16
16
|
import { PROVE_RUNS, provenFixed, type TestResult } from './results.ts'
|
|
17
17
|
import { nodeTest } from './run/node-test.ts'
|
|
@@ -78,7 +78,7 @@ export async function focused(args: string[], usage: string): Promise<number> {
|
|
|
78
78
|
}
|
|
79
79
|
if (related.execution.interrupted) return EXIT.interrupted
|
|
80
80
|
if (related.record.result === 'fail') {
|
|
81
|
-
console.log([...lines,
|
|
81
|
+
console.log([...lines, failedText('相关测试', related), ...related.notes].join('\n'))
|
|
82
82
|
return EXIT.fail
|
|
83
83
|
}
|
|
84
84
|
lines.push(`相关测试通过 · 用时 ${duration(related.execution.durationMs)}`, ...related.notes)
|
|
@@ -96,6 +96,12 @@ export async function focused(args: string[], usage: string): Promise<number> {
|
|
|
96
96
|
return code
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/** files 没过的说法。命令自己通过、只是跑完核对出有文件没跑到的(notes 里点名),不贴输出节选。 */
|
|
100
|
+
function failedText(what: string, run: Recorded): string {
|
|
101
|
+
if (run.execution.exitCode !== 0) return failureText(`${what}失败`, run.record.log, run.execution)
|
|
102
|
+
return `${what}没通过:命令通过了,跑完核对出有测试文件没跑到(见下)· 用时 ${duration(run.execution.durationMs)}\n完整日志:${run.record.log}`
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
export async function files(argv: string[], usage: string): Promise<number> {
|
|
100
106
|
// --repeat N:连跑 N 次,没过就停。造出时好时坏的测试的失败,或证明修好了(见 results.ts 的 PROVE_RUNS)
|
|
101
107
|
let times = 1
|
|
@@ -157,7 +163,7 @@ export async function files(argv: string[], usage: string): Promise<number> {
|
|
|
157
163
|
took += run.execution.durationMs
|
|
158
164
|
if (run.record.result === 'fail') {
|
|
159
165
|
const which = times > 1 ? `连跑第 ${index} 次(共 ${times} 次)` : ''
|
|
160
|
-
console.log([
|
|
166
|
+
console.log([failedText(`${what}${which}`, run), ...notes].join('\n'))
|
|
161
167
|
return EXIT.fail
|
|
162
168
|
}
|
|
163
169
|
passes.push(run.results)
|