gatelight 0.19.2 → 0.19.3
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/package.json +1 -1
- package/skills/merge/SKILL.md +1 -1
- package/skills/setup/SKILL.md +1 -1
- package/skills/setup-modwall/SKILL.md +1 -1
- package/skills/write-tests/SKILL.md +2 -1
- package/src/base/full.ts +8 -1
- package/src/base/module.ts +3 -1
- package/src/craft/session.ts +1 -1
- package/src/pace/full.ts +23 -2
- package/src/wall/commands.ts +2 -0
- package/src/wall/full.ts +6 -1
- package/src/wall/receipt.ts +73 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
3
|
"displayName": "gatelight",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.3",
|
|
5
5
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "coffeecoproject"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
3
|
"displayName": "gatelight",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.3",
|
|
5
5
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "coffeecoproject"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "coffeecoproject"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatelight",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/coffeecoproject/gatelight#readme",
|
package/skills/merge/SKILL.md
CHANGED
|
@@ -22,7 +22,7 @@ description: 把做完的分支合回默认分支:先把测试写上(接入
|
|
|
22
22
|
- 这个会话没有自己的分支(比如在主目录里被叫来合),用户又没点名:列出还没合进去的分支(`git branch --no-merged main`)给用户挑。
|
|
23
23
|
2. **把测试补齐**,然后 `testpace focused` 通过,把这个分支提交干净。
|
|
24
24
|
- 开发中留着没过的旧测试(因为用户这次改了需求才不过的):照定下来的规则改掉。
|
|
25
|
-
- 仓库接入了 testcraft(有 `.testcraft/` 目录)的:照 gatelight:write-tests 技能"什么时候写"
|
|
25
|
+
- 仓库接入了 testcraft(有 `.testcraft/` 目录)的:照 gatelight:write-tests 技能"什么时候写"一节,把这次定下来的规则列出来,交给一个子代理写新测试,旧测试也交给它一起改。这次没改到规则的不用写。规则写进测试后,把设计文档、README 里写着这几条规则的段落删掉,只留为什么这样定、否掉的做法、还没定的(见 gatelight:write-tests 技能),和测试一起提交。
|
|
26
26
|
3. **找一个干净的地方合**。主目录在 `main` 上而且没有未提交改动,就在主目录里做;否则开一个新 worktree,按项目说明准备好环境(依赖、`.env`、服务)。不要在别的会话正在用的目录里做。
|
|
27
27
|
4. **建合并分支并合进来**:从最新的 `main` 建 `merge/<日期时间>`,把要合的分支合进去(`git merge --no-ff --no-edit <分支>`;有几个就一个个合)。
|
|
28
28
|
- 有冲突时,机械性的(比如两边各加了一段、只是位置挨着)可以解决;涉及逻辑取舍的,停下来告诉用户是哪些文件、和 `main` 上的哪次改动冲突,问怎么办。不要用 `-X ours`、`-X theirs` 这类办法一刀切。
|
package/skills/setup/SKILL.md
CHANGED
|
@@ -71,7 +71,7 @@ testpace 不管测试的写法风格(分几层、怎么组织、写多细)
|
|
|
71
71
|
## 步骤
|
|
72
72
|
|
|
73
73
|
1. **找项目已有的命令和测试**:看 `package.json` 的 scripts、Makefile、CI 配置、README、测试框架的配置。三条命令尽量直接用现成的,不另造一套;不是 JavaScript 项目(Go、Python、Swift 等)也一样写三条命令。`full` 放测试以外的全部检查;`tests` 照测试框架实际认的文件写(比如 Vitest 的 include、exclude),项目里有几种测试(单元、数据库、页面、端到端)就要都覆盖到。说不清某种测试怎么跑、或全部测试跑一遍太久要怎么取舍时,用大白话说明情况,请用户定;把整套系统起起来跑的测试排除出整组,不在可取舍的办法里。
|
|
74
|
-
2. **测试用 `node:test`、Vitest 或 Playwright 的,`files` 一律用 `testpace run node-test`、`testpace run vitest` 或 `testpace run playwright`**,不自己写包装、不自己数测试,接入前项目里已有的这类包装和计数报告器删掉:它检查文件都在、给的每个文件和每个 `文件:行号` 都跑到了测试(被项目配置排除、悄悄没跑的文件也查得出来;Playwright 只要别的行有测试,给的行上没有测试、文件里没有测试都照样通过,也查得出来),全被跳过时说一句;Vitest、Playwright 按行跑,node:test 不能按行跑,按行给的整个文件跑、跑完照样核对那一行。项目配置里的报告器(比如 Playwright 的断言检查、Vitest 的 junit)照常起作用。要先起环境、编译、按路径分给不同跑法的,脚本照旧做这些,到"用框架跑这几个文件"那一步调它(`--cwd` 换目录:node 的工作目录,或装着 Vitest、Playwright,放着它们配置的那个目录;`--node-arg`、`--vitest-arg`、`--playwright-arg` 原样交参数给框架,比如 `--node-arg=--import=tsx`、`--vitest-arg=--maxWorkers=2`),自己不再数测试。testpace 跑项目命令时 PATH
|
|
74
|
+
2. **测试用 `node:test`、Vitest 或 Playwright 的,`files` 一律用 `testpace run node-test`、`testpace run vitest` 或 `testpace run playwright`**,不自己写包装、不自己数测试,接入前项目里已有的这类包装和计数报告器删掉:它检查文件都在、给的每个文件和每个 `文件:行号` 都跑到了测试(被项目配置排除、悄悄没跑的文件也查得出来;Playwright 只要别的行有测试,给的行上没有测试、文件里没有测试都照样通过,也查得出来),全被跳过时说一句;Vitest、Playwright 按行跑,node:test 不能按行跑,按行给的整个文件跑、跑完照样核对那一行。项目配置里的报告器(比如 Playwright 的断言检查、Vitest 的 junit)照常起作用。要先起环境、编译、按路径分给不同跑法的,脚本照旧做这些,到"用框架跑这几个文件"那一步调它(`--cwd` 换目录:node 的工作目录,或装着 Vitest、Playwright,放着它们配置的那个目录;`--node-arg`、`--vitest-arg`、`--playwright-arg` 原样交参数给框架,比如 `--node-arg=--import=tsx`、`--vitest-arg=--maxWorkers=2`),自己不再数测试。testpace 跑项目命令时 PATH 上一定有它自己。整组跑完会核对:交给 `files` 的每个测试文件都要交回至少一条结果(经 `testpace run` 跑的自动交)。不是这三种框架、只能用别的办法跑的(比如一个脚本就是一条数据库契约),自己往环境变量 `TESTPACE_RESULTS` 给的文件里每个测试追加一行 JSON:`{"file":"文件的绝对路径","name":"测试名","status":"passed"}`(`status` 是 `passed`、`failed` 或 `skipped`);不交的,整组会点名这些文件、算没过。
|
|
75
75
|
**testpace 还没内置的测试框架**(目前是 node:test、Vitest、Playwright 以外的),写一个小脚本包一层(比如 `scripts/testpace.sh files a.test.ts b.test.ts:42`),把参数交给测试框架。测试框架能按行跑的(比如 Playwright、Vitest),按 `文件:行号` 交给它,带列号的先去掉列号;不能的,去掉行号和列号跑整个文件,在输出里说一句。很多测试框架把参数当成筛选条件:给了几个文件、其中一个不存在时,只跑找得到的那些,照样报通过。所以脚本要自己检查每个文件都存在、测试框架加载了它、里面有测试,否则返回非零。按条件跳过的测试(比如只在某个系统上跑)算有测试:整组里它们同样被跳过,`files` 不比整组更严;一个文件的测试全被跳过时,在输出里说一句,让人知道它这次什么都没验证。
|
|
76
76
|
3. **写 `testpace.json`**,放在仓库根目录,进版本库。然后跑 `testpace status` 看合并门那一行:
|
|
77
77
|
- 说合并门没配:会话开始时 testpace 会自动配上;用户自己删掉过的,问用户要不要跑 `testpace install` 配回去。
|
|
@@ -99,7 +99,7 @@ modwall 让 agent 默认按模块开发,越界由程序拦。它不自己解
|
|
|
99
99
|
- **认不出来的应用目录要手动补**:不是工作区包、又不在上面几个目录下的应用(比如放在仓库根目录 `miniprogram/` 下的小程序),`modwall init` 不起草,它下面的代码在输出里列为没有归属。照着这个应用的目录在 `apps` 里手动补一组(应用名取目录名,`roots`、`shared`、`app`、`entry`、`map` 按它搬好的目录写)。草稿是单应用写法的,先把它改成按应用分组的写法(原来那一组放进 `apps`,起个应用名),再补上这一组。补完重跑 `modwall check`,直到没有归属的代码文件都归了某个应用、外面一层的 `shared` 或 `outside`。
|
|
100
100
|
3. **改到清零**:`modwall check` 列出全部越界,当作待办逐条按改法改(R6 是迁移文件里的数据库越界)。每个模块可以补一个 `MODULE.md`(一句职责、一句不做什么)。用 Postgres 的,在临时库上跑完全部迁移后执行 `modwall db check --psql "<执行 SQL 的命令>"`(比如 `psql $DATABASE_URL`;用 napbox 的项目写 `napbox exec postgres --temp $ENV -- psql`),把它报的也改到清零:改迁移或跑迁移的工具,不直接改库。这条命令用哪个账号连库都行,它只读系统目录。
|
|
101
101
|
4. **整份配置让用户确认一次**:首次接入时 `modwall check` 会把整份配置列为放宽项。先用白话告诉用户:分了哪几个模块(有几个应用时按应用说,还有哪些代码是几个应用共用的)、共享层和装配层是哪些、哪些路径不管,再调用 `confirm_with_user` 工具(弹窗,用户同意才算;编号和文字照 `modwall check` 输出的填)。确认后 `modwall check` 应当通过。
|
|
102
|
-
5. **库的检查进整组**(用 Postgres 的项目):在项目整组(testpace 的 `full`)里,迁移跑完之后加一步 `modwall db check --psql "<执行 SQL 的命令>"`,用测试的临时库;它不通过时退出码非零,整组就不通过。怎么起库、怎么跑迁移仍归项目,modwall
|
|
102
|
+
5. **库的检查进整组**(用 Postgres 的项目):在项目整组(testpace 的 `full`)里,迁移跑完之后加一步 `modwall db check --psql "<执行 SQL 的命令>"`,用测试的临时库;它不通过时退出码非零,整组就不通过。怎么起库、怎么跑迁移仍归项目,modwall 只读系统目录。写在项目的脚本里、在测试里跑都行,但要在整组里跑到、退出码不能被忽略:整组给每段命令一个环境变量 `MODWALL_DB_RECEIPTS`,`modwall db check` 查完往里交一条凭据,整组跑完时写了 `database` 的应用(有几个应用的,每个用 `--app` 各查一次)没交凭据、或没通过却接着跑完了,整组算没过。所以起库、跑迁移的脚本要把环境变量原样传给它(在容器里跑的也要带进去)。
|
|
103
103
|
6. **核对**:`modwall status` 应当显示 LayerMap 能用、testpace 接入了、没有越界、放宽项都同意过。
|
|
104
104
|
7. 提交前先问用户;合回默认分支照 testpace 的节奏(`gatelight:merge`)。
|
|
105
105
|
|
|
@@ -19,6 +19,7 @@ description: 在接入了 testcraft 的仓库(有 .testcraft/ 目录)里写
|
|
|
19
19
|
- **测试没过、它认为是业务代码不对的,不改业务代码**:回来说明是哪条规则、实际结果是什么。
|
|
20
20
|
|
|
21
21
|
子代理回来后跑 `testpace focused`,通过了提交。它说业务代码不对的,照"写完"第 1 条办:先停下来告诉用户。
|
|
22
|
+
- **规则写进测试后,从文档里删掉**(这一步自己做,不交给子代理:哪几段写的是这次的规则,做这个分支的会话最清楚)。设计文档、README 里写着这几条规则的段落删掉,只留代码和测试装不下的:为什么这样定、否掉的做法、还没定的、怎么跑。这次定下来的"待确认"一起拿掉;改规则的经过(原来怎样、哪天改成怎样)不留,git 里有。同一条规则写在文档、测试、代码三处,改规则时文档总有漏改的地方,以后的 agent 照着旧说法做;只留在测试里,就只有一处要改。和测试一起提交。
|
|
22
23
|
- **一个例外,开发中当场做**:修已定规则(已经合进默认分支的)的 bug,先写能重现它的测试,确认它失败,再修。
|
|
23
24
|
|
|
24
25
|
## 先分档
|
|
@@ -88,7 +89,7 @@ description: 在接入了 testcraft 的仓库(有 .testcraft/ 目录)里写
|
|
|
88
89
|
- **还在试**:分支上还没合的都算。不写测试,自己临时跑通就行。
|
|
89
90
|
- **合并时用户说"这块还在试、先合进去"**:那一块先不写测试,合进去以后也还算在试。它之后修过的 bug 记进 `.testcraft/rules/<编号>.md`(一条一个文件,标题写规则,正文写修过的 bug);用户说定了的时候写测试,把记过的 bug 补成测试,然后删掉那条记录。
|
|
90
91
|
- 修已定规则的 bug:先写能重现它的测试,确认它失败,再修。
|
|
91
|
-
-
|
|
92
|
+
- 要改已定的规则(已定的规则以测试名为准,文档里的说法和它不一样时也是;包括为此删测试、让测试不跑、改期望值):先用白话问用户一次,用户同意了再改。用户这次自己提出要改的不用再问。不用另外写记录。
|
|
92
93
|
- 测试上别的调整(跟着代码改接法、换写法、挪位置、删重复的)自己定,不问用户,也不用写说明。
|
|
93
94
|
- 整块功能不要了:规则和测试一起删。
|
|
94
95
|
|
package/src/base/full.ts
CHANGED
|
@@ -110,8 +110,11 @@ async function run(ctx: Repo, sessionId: string | undefined, ignore: string[], p
|
|
|
110
110
|
|
|
111
111
|
// 各模块往记录里加自己的字段,记录写下之后再说它们要说的话
|
|
112
112
|
const finished = parts.map(part => part.finish?.() ?? {})
|
|
113
|
+
// 各段都过了,再按交回来的东西核对:该跑到的没跑到,整组也算没过
|
|
114
|
+
const problems = execution.exitCode === 0 ? finished.flatMap(done => done.problems ?? []) : []
|
|
115
|
+
if (problems.length) appendFileSync(log, `===== testpace 跑完核对没通过\n${problems.join('\n')}\n`)
|
|
113
116
|
const treeAtEnd = workTreeId(ctx.root)
|
|
114
|
-
const result = execution.exitCode === 0 ? 'pass' : 'fail'
|
|
117
|
+
const result = execution.exitCode === 0 && problems.length === 0 ? 'pass' : 'fail'
|
|
115
118
|
const before = ctx.store.readRuns()
|
|
116
119
|
const record: RunRecord = {
|
|
117
120
|
id,
|
|
@@ -153,6 +156,10 @@ async function run(ctx: Repo, sessionId: string | undefined, ignore: string[], p
|
|
|
153
156
|
)
|
|
154
157
|
return EXIT.fail
|
|
155
158
|
}
|
|
159
|
+
if (problems.length) {
|
|
160
|
+
say([`整组失败:各段都过了,跑完核对没通过(该跑到的没跑到)`, ...problems.map(problem => `- ${problem}`), `用时 ${took} · 日志:${log}`].join('\n'))
|
|
161
|
+
return EXIT.fail
|
|
162
|
+
}
|
|
156
163
|
const what = failed?.title ?? '整组'
|
|
157
164
|
const gap = /[A-Za-z0-9]$/.test(what) ? ' ' : ''
|
|
158
165
|
say(failureText(`整组失败:${what}${gap}没通过${failed === steps.at(-1) ? '' : ',后面的没有跑'}`, log, execution, excerptFrom))
|
package/src/base/module.ts
CHANGED
|
@@ -30,8 +30,10 @@ export interface FullPart {
|
|
|
30
30
|
/**
|
|
31
31
|
* 各段跑完(没被中断)以后:模块往这次的运行记录里加自己的字段(fields),在记录写下之后说给 agent 的话(notes,
|
|
32
32
|
* 拿得到写好的记录和这之前的全部记录)。
|
|
33
|
+
* problems:按跑完交回来的东西核对出的问题(比如该跑到的没跑到),一条一句、写明怎么改。各段都过了、却有问题的,整组算没过;
|
|
34
|
+
* 有哪一段没过时不看(后面的没跑,核对不出什么)。
|
|
33
35
|
*/
|
|
34
|
-
finish?(): { fields?: Record<string, unknown>; notes?(record: RunRecord, before: RunRecord[]): string[] }
|
|
36
|
+
finish?(): { fields?: Record<string, unknown>; problems?: string[]; notes?(record: RunRecord, before: RunRecord[]): string[] }
|
|
35
37
|
/** 这一轮结束(不管怎么结束)时收拾模块自己的临时文件。 */
|
|
36
38
|
dispose?(): void
|
|
37
39
|
}
|
package/src/craft/session.ts
CHANGED
|
@@ -10,7 +10,7 @@ export function guide(label = '这个仓库'): string[] {
|
|
|
10
10
|
`${label}用 testcraft 管测试的写法(.testcraft/):`,
|
|
11
11
|
'1. 什么时候写:分支上开发时不写新测试、不改已有的测试(需求还在试),做完告诉用户做完了、测试还没写。用户说要合并这个分支时才写:把这次定下来的规则用白话一条条列出来,交给一个子代理照 gatelight:write-tests 技能写新测试、改掉因为需求变了而不过的旧测试(没有起子代理的工具就自己写),跑通、提交,再合。例外,当场做:修已合进默认分支的规则的 bug,先写能重现它的测试再修。',
|
|
12
12
|
'2. 写哪些:小改动(文字、样式、注释、显示用的配置)不写。必跑层:钱、权限、状态与数据(什么状态下能做、数据会不会错)写在接口层、测透,每个功能留主流程的页面测试。细节层:界面细节、样式、提示文字这类人容易漏看的,也值得写。修过的 bug 留一条能重现它的测试。在页面上重复验证接口层守着的规则不写。',
|
|
13
|
-
'3.
|
|
13
|
+
'3. 已定的业务规则(合进默认分支的)以测试名为准。要改已定的业务规则(包括为此删测试、让测试不跑、改期望值),先用白话问用户,用户同意了再改;用户这次自己提出要改的不用再问。测试上别的调整(跟着代码改接法、换写法、挪位置、删重复的)自己定,不问用户,也不用写说明。文档里不另写已定的规则:设计文档只写代码和测试装不下的(为什么这样定、否掉的做法、还没定的、怎么跑),和测试名说法不一样时以测试为准;合并时规则写进了测试,文档里写着这几条规则的段落就删掉。',
|
|
14
14
|
'4. 改动命中 .testcraft/checklist/ 里条目的触发条件时(testcraft checklist 列出,落地前的整组里也会说一遍),按条目查一遍,查出问题就改好。修 bug 时,写不成测试、又能从改动看出来的坑,加一条清单。',
|
|
15
15
|
]
|
|
16
16
|
}
|
package/src/pace/full.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { loadConfig } from './config.ts'
|
|
|
7
7
|
import { unconfirmedChanges } from './consent.ts'
|
|
8
8
|
import type { PaceRun } from './record.ts'
|
|
9
9
|
import { FULL_STEP, TESTS_STEP } from './report.ts'
|
|
10
|
-
import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile } from './results.ts'
|
|
10
|
+
import { failedTests, noteResults, readResults, RESULTS_ENV, resultsFile, type TestResult } from './results.ts'
|
|
11
11
|
import { findTests } from './tests.ts'
|
|
12
12
|
|
|
13
13
|
export function fullPart(repo: Repo): FullPart | { problem: string } {
|
|
@@ -19,10 +19,11 @@ export function fullPart(repo: Repo): FullPart | { problem: string } {
|
|
|
19
19
|
const unconfirmed = unconfirmedChanges(repo)
|
|
20
20
|
if (unconfirmed) return { problem: unconfirmed }
|
|
21
21
|
const resultsAt = resultsFile()
|
|
22
|
+
const files = config.files
|
|
22
23
|
return {
|
|
23
24
|
steps: [
|
|
24
25
|
{ 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} 个文件):${
|
|
26
|
+
{ kind: 'tests', name: TESTS_STEP, title: `${TESTS_STEP}(${tests.length} 个文件)`, header: `${TESTS_STEP}(${tests.length} 个文件):${files}`, command: files, args: tests },
|
|
26
27
|
],
|
|
27
28
|
summary: `${tests.length} 个测试文件`,
|
|
28
29
|
env: { [RESULTS_ENV]: resultsAt.path },
|
|
@@ -30,9 +31,29 @@ export function fullPart(repo: Repo): FullPart | { problem: string } {
|
|
|
30
31
|
const results = readResults(resultsAt.path, repo.root)
|
|
31
32
|
return {
|
|
32
33
|
fields: { tests: tests.length, ...(results.length > 0 ? { failed: failedTests(results) } : {}) },
|
|
34
|
+
problems: silentFiles(tests, results, files),
|
|
33
35
|
notes: (record, before) => noteResults(repo, { record: record as PaceRun, results, before: before as PaceRun[], whole: tests }),
|
|
34
36
|
}
|
|
35
37
|
},
|
|
36
38
|
dispose: () => resultsAt.dispose(),
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
|
|
42
|
+
/** 一次最多点名几个没交回结果的文件。 */
|
|
43
|
+
const NAMED = 10
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 交给 files 的每个测试文件都要交回至少一条结果(过、没过、跳过都算)。不读脚本:脚本漏跑了哪一类测试,结果里就少了那些文件。
|
|
47
|
+
* 一条结果都没交回的,是 files 整个没经 testpace run 跑、也没自己写结果。
|
|
48
|
+
*/
|
|
49
|
+
export function silentFiles(tests: readonly string[], results: readonly TestResult[], files: string): string[] {
|
|
50
|
+
const reported = new Set(results.map(test => test.file))
|
|
51
|
+
const silent = tests.filter(file => !reported.has(file))
|
|
52
|
+
if (silent.length === 0) return []
|
|
53
|
+
const how = `node:test、Vitest、Playwright 的测试经 testpace run 跑(它会交回结果);别的跑法自己往环境变量 ${RESULTS_ENV} 给的文件里,每个测试追加一行 JSON:{"file":"文件的绝对路径","name":"测试名","status":"passed、failed 或 skipped"}`
|
|
54
|
+
if (results.length === 0) return [`files 命令(${files})跑完,一个测试结果都没交回,整组核对不了跑到了哪些测试。${how}。`]
|
|
55
|
+
const named = silent.slice(0, NAMED).join('、') + (silent.length > NAMED ? ` 等 ${silent.length} 个` : '')
|
|
56
|
+
return [
|
|
57
|
+
`交给 files 命令(${files})的测试文件里,这些一条结果都没交回:${named}。可能是 files 的脚本没把它们交给测试框架、被框架的配置排除了,或跑它们的那一路没交结果。${how}。`,
|
|
58
|
+
]
|
|
59
|
+
}
|
package/src/wall/commands.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { openRepo, type Repo } from '../base/repo.ts'
|
|
|
12
12
|
import { analyze, exitCode, formatReport, logCheck, prepare, type Report, violationLines } from './check.ts'
|
|
13
13
|
import { CONFIG_PATH, MODWALL_DIR, schemeOf } from './config.ts'
|
|
14
14
|
import { catalogViolations, readCatalog } from './dbcheck.ts'
|
|
15
|
+
import { leaveReceipt } from './receipt.ts'
|
|
15
16
|
import { draftConfig } from './init.ts'
|
|
16
17
|
import type { Module } from './layout.ts'
|
|
17
18
|
import { configText } from './loosen.ts'
|
|
@@ -153,6 +154,7 @@ function dbCheck(args: string[]): number {
|
|
|
153
154
|
}
|
|
154
155
|
const violations = catalogViolations(database, catalog.value)
|
|
155
156
|
const which = database.app.name === undefined ? '' : `(${database.app.name} 应用的库)`
|
|
157
|
+
leaveReceipt(database.app.name, violations.length === 0)
|
|
156
158
|
if (violations.length === 0) {
|
|
157
159
|
console.log(`modwall db check:通过${which}。库里没有越界。`)
|
|
158
160
|
return EXIT.ok
|
package/src/wall/full.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 整组里"模块边界"的部分(base/module.ts 的 fullPart):接入了的仓库在测试之前跑一次 modwall check。
|
|
2
2
|
// 它随插件一起装,不用在本机另外登记;没接入的仓库没有这一段。
|
|
3
|
-
// 库里的现状(modwall db check)不在这一段:要迁移跑完才能查,由项目写在自己的 full
|
|
3
|
+
// 库里的现状(modwall db check)不在这一段:要迁移跑完才能查,由项目写在自己的 full 命令里。整组跑完按它交回的凭据核对跑没跑(receipt.ts)。
|
|
4
4
|
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
6
6
|
import { quoted } from '../base/execute.ts'
|
|
@@ -8,6 +8,7 @@ import { forkPoint } from '../base/git.ts'
|
|
|
8
8
|
import type { FullPart } from '../base/module.ts'
|
|
9
9
|
import type { Repo } from '../base/repo.ts'
|
|
10
10
|
import { joined } from './config.ts'
|
|
11
|
+
import { DB_RECEIPTS_ENV, receiptProblems, receiptsFile } from './receipt.ts'
|
|
11
12
|
|
|
12
13
|
/** 这个插件里的 modwall 命令:用完整路径,不靠 PATH 上碰巧有哪一版。 */
|
|
13
14
|
const BIN = fileURLToPath(new URL('../../bin/modwall', import.meta.url))
|
|
@@ -15,7 +16,11 @@ const BIN = fileURLToPath(new URL('../../bin/modwall', import.meta.url))
|
|
|
15
16
|
export function fullPart(repo: Repo): FullPart {
|
|
16
17
|
// 按分叉点也算接入:删掉 .modwall/ 躲不过检查
|
|
17
18
|
if (!joined(repo.root, forkPoint(repo.root).commit)) return { steps: [] }
|
|
19
|
+
const receipts = receiptsFile()
|
|
18
20
|
return {
|
|
21
|
+
env: { [DB_RECEIPTS_ENV]: receipts.path },
|
|
22
|
+
finish: () => ({ problems: receiptProblems(repo.root, receipts.path) }),
|
|
23
|
+
dispose: () => receipts.dispose(),
|
|
19
24
|
steps: [
|
|
20
25
|
{
|
|
21
26
|
kind: 'wall',
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// modwall db check 在整组里交回的凭据。它由项目写进自己的 full 命令(迁移跑完才能查),脚本里删掉那一行,库的模块边界就不查了。
|
|
2
|
+
// 所以不读脚本,按凭据核对:整组给各段命令一个环境变量(DB_RECEIPTS_ENV),db check 查完往那个文件追加一行(查的是哪个应用、过没过);
|
|
3
|
+
// 整组跑完,配置里每个写了 database 的应用都要有凭据、而且都过了。只防看错:凭据是 agent 写得到的文件,故意伪造拦不住。
|
|
4
|
+
|
|
5
|
+
import { appendFileSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
|
6
|
+
import { tmpdir } from 'node:os'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { fileNow } from '../base/git.ts'
|
|
9
|
+
import { CONFIG_PATH, readConfig, schemeOf } from './config.ts'
|
|
10
|
+
|
|
11
|
+
export const DB_RECEIPTS_ENV = 'MODWALL_DB_RECEIPTS'
|
|
12
|
+
|
|
13
|
+
/** 一次 db check 的凭据。app:查的是哪个应用的库(单应用的写法没有名字,为 null)。 */
|
|
14
|
+
export interface DbReceipt {
|
|
15
|
+
app: string | null
|
|
16
|
+
passed: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** 给一次整组准备收凭据的文件。用完调 dispose。 */
|
|
20
|
+
export function receiptsFile(): { path: string; dispose: () => void } {
|
|
21
|
+
const dir = mkdtempSync(join(tmpdir(), 'modwall-db-receipts-'))
|
|
22
|
+
return { path: join(dir, 'receipts.jsonl'), dispose: () => rmSync(dir, { recursive: true, force: true }) }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** db check 查完时调:在整组里跑的(有那个环境变量),交一条凭据。 */
|
|
26
|
+
export function leaveReceipt(app: string | undefined, passed: boolean): void {
|
|
27
|
+
const path = process.env[DB_RECEIPTS_ENV]
|
|
28
|
+
if (path) appendFileSync(path, `${JSON.stringify({ app: app ?? null, passed } satisfies DbReceipt)}\n`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function readReceipts(path: string): DbReceipt[] {
|
|
32
|
+
let text: string
|
|
33
|
+
try {
|
|
34
|
+
text = readFileSync(path, 'utf8')
|
|
35
|
+
} catch {
|
|
36
|
+
return []
|
|
37
|
+
}
|
|
38
|
+
return text.split('\n').flatMap(line => {
|
|
39
|
+
try {
|
|
40
|
+
const value = JSON.parse(line) as Partial<DbReceipt>
|
|
41
|
+
return typeof value.passed === 'boolean' && (value.app === null || typeof value.app === 'string') ? [{ app: value.app, passed: value.passed }] : []
|
|
42
|
+
} catch {
|
|
43
|
+
return [] // 空行、写到一半的
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 工作区的配置里写了 database 的应用(单应用的写法为 null)。配置有问题的不算:整组里的 modwall check 已经报了。 */
|
|
49
|
+
function databaseApps(root: string): Array<string | null> {
|
|
50
|
+
const { config } = readConfig(fileNow(root, CONFIG_PATH))
|
|
51
|
+
if (!config) return []
|
|
52
|
+
return schemeOf(config).apps.filter(app => app.database).map(app => app.name ?? null)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 整组跑完:写了 database 的应用,哪个没交凭据、哪个没过却没让整组失败。一条一句、写明怎么改。 */
|
|
56
|
+
export function receiptProblems(root: string, path: string): string[] {
|
|
57
|
+
const receipts = readReceipts(path)
|
|
58
|
+
const problems: string[] = []
|
|
59
|
+
const apps = databaseApps(root)
|
|
60
|
+
for (const app of apps) {
|
|
61
|
+
// 只有一个应用写了 database 时,db check 不用 --app 也查它
|
|
62
|
+
const which = app === null ? '' : apps.length > 1 ? `(${app} 应用的库,用 --app ${app})` : `(${app} 应用的库)`
|
|
63
|
+
const mine = receipts.filter(receipt => receipt.app === app)
|
|
64
|
+
if (mine.length === 0) {
|
|
65
|
+
problems.push(
|
|
66
|
+
`整组里没跑 modwall db check${which}:${CONFIG_PATH} 写了 database,项目的 full 命令要在迁移跑完后跑它,查库里的模块边界(写法见 gatelight:setup-modwall 技能)。`,
|
|
67
|
+
)
|
|
68
|
+
} else if (mine.some(receipt => !receipt.passed)) {
|
|
69
|
+
problems.push(`modwall db check${which}没通过,整组却接着跑完了:项目的 full 命令里不要忽略它的退出码(比如 || true),没通过要让整组失败。`)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return problems
|
|
73
|
+
}
|