fix(harness): with-test-isolation 里 vitest 0 匹配时退 0(假绿); 还一词二义
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 0
- Avg merge
- 1h 7m
- Merged PRs (30d)
- 969
Description
## 现象
`with-test-isolation` 壳里,内层 vitest 一条测试都没选中时,整条命令**干净地退 0**。
实测(#1704 定位过程中撞到,隔离 id `run-mt2b004r-afd78dc5-1a6cd8855fdd`):
```
$ pnpm exec tsx .harness/scripts/with-test-isolation.ts -- npx vitest run --root apps/api tests/chat/
(在**仓库根**执行)
RUN v2.1.9 …/apps/api
Test Files no tests
Tests no tests
EXIT=0
```
代价:**28 分钟**(其中 152s 卡在 stack-admission 排队,load1≈30),产出一个毫无信息量的绿。这正是本仓反复栽的「全绿但空转」。
## 为什么会 0 匹配
vitest 的**位置参数过滤器按 `process.cwd()` 解析,不按 `--root`**。在仓库根执行时 `tests/chat/` 匹配不到任何文件。
三组对照,都在仓库根跑:
| 命令 | 输出 | 退出码 |
|---|---|---|
| `npx vitest run tests/definitely-does-not-exist/`(cd apps/api) | `No test files found, exiting with code 1` | **1** |
| `npx vitest run --root apps/api tests/chat/`(无隔离壳) | `Test Files no tests` + globalSetup 隔离守卫报错 | **1**(红在守卫上,不是红在 no-tests) |
| `with-test-isolation -- npx vitest run --root apps/api tests/chat/` | `Test Files no tests` | **0** ← 假绿 |
即 `--root ` + 位置过滤器时,匹配到 0 个文件后 vitest 走的是 "no tests" 汇总分支(退 0),而不是 "No test files found"(退 1)。`passWithNoTests` 不背这个锅。
## 第二个问题:`Test Files no tests` 一词二义
同一个字符串代表两种完全不同的状况:
1. **过滤器没匹配上** → 退 0(本 issue)
2. **globalSetup 抛了**(例如 #1704 里 postgres 就绪竞态) → 退 1
`#1704` 里这两种我都撞到了,看到的是同一行输出。「跑法错了」和「依赖挂了」显示成同一个样子,诊断只能靠翻退出码。
## 建议收口
放在 `with-test-isolation` 这一层——它本来就是「跑法守卫」该待的地方,和 `db-global-setup.ts` 的 `assertIsolatedDatabase`(#538「第一行就查跑法」)同一个位置、同一条原则:
- 内层命令输出 `Test Files no tests` ⇒ 判红,并打印「你大概率在错误的 cwd 下用了位置过滤器;vitest 的过滤器按 cwd 解析,不按 --root」。
- 注意 `assertIsolatedDatabase` 够不着这个场景:0 匹配时 globalSetup 根本不执行。
## 反证要求(本仓纪律:写完门控立刻造反证)
门控加完必须能证明「不修则红」:在仓库根跑那条 `--root apps/api tests/chat/`,加门后**必须红**;`cd apps/api` 后跑同一目录**必须绿且真的跑了 56 个文件**。只验前者不够——那样很容易做出一个把所有跑法都判红的门。
## 来源
#1704 的定位过程,见该 issue 前两条评论。
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with .harness/scripts/with-test-isolation.ts and reproduce the root-level command using --root apps/api tests/chat/. Trace how the wrapper interprets Vitest's “Test Files no tests” output, then verify that the root invocation fails while running the same directory after cd apps/api succeeds and executes 56 files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100