Repository navigation
Commit 19cc897
test(cli): stored-references binds name fixed row ids, and a run with no JSON says why (#33426)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D4Jsmd91BqTVB7dSii9uJMV)_
Fixes #32976
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:只改一个测试文件。`os migrate stored-references` 集成测试给种子行写死
id(不再随机生成),并且当命令没有输出 JSON 时,测试失败信息会带上退出码、oclif 抛出的错误原文、耗时、argv 和 stderr
尾部。
- 为什么改:偶发失败已复现并定位。行 id 是 16 位 nanoid,字母表含 `-`;bind 命令声明了短参数
`-y`(`--yes`),oclif 会把以 `-y` 开头的参数值当成 `-y` 参数,在解析阶段就拒绝(`Flag --id
expects a value`,退出码 2),命令一个字节都没写,所以 16 ms、stdout 为空。概率约 1/4096 每个 id。
- 风险与回滚:只动测试,不发布任何包;回滚即 revert 本 PR。
-
先看:`packages/cli/src/commands/migrate/stored-references.integration.test.ts`
的 `SEEDED_IDS` 注释与 `run()` 里的空 stdout 诊断分支。
- 两分钟验证:`pnpm --filter @objectstack/cli exec vitest run --project
integration
src/commands/migrate/stored-references.integration.test.ts`,预期 13/13 通过。
- 需要你做的:本 PR 只改测试、不发布任何包,需要挂 `skip-changeset` 标签(dev 未自挂)。产品侧缺陷(以 `-y`
开头的 id 在任何拼写下都无法 bind)已作为发现上报,未在本 PR 修。
## What changes
`packages/cli/src/commands/migrate/stored-references.integration.test.ts`
only:
1. **The rows the seed writes carry fixed ids** (`SEEDED_IDS`), so every
`bind --id` the file passes is deterministic. Before, the ids were
minted by the SQL driver as `nanoid(16)`, whose alphabet contains `-`.
2. **A run that prints no JSON document fails loudly.** `run()` no
longer answers a bare `{ unparsed: '' }`: it adds the exit code, the
exit signal's own message (an oclif parse refusal throws before the
command writes a byte), the elapsed ms, the argv, and the tail of
stderr. The CONTROL bind assertion prints that payload as its message.
3. **`bind()` refuses an id that opens with `-`** before it reaches the
argv, naming why, instead of an opaque parse refusal.
### Root cause (reproduced, not inferred)
oclif 5.1.2's parser (`lib/parser/parse.js`, `parseFlag`) refuses a flag
value whenever `findFlag(value)` resolves it to one of the command's
flags; `findShortFlag` looks only at the value's second character. `os
migrate stored-references bind` declares `yes` with `char: 'y'`, so a
row id beginning with `-y` is read as `-y` and refused: `Flag --id
expects a value`, exit 2, in **both** spellings, `--id X` and `--id=X`.
In the test, that `CLIError` carries `oclif.exit`, so `isExitSignal`
swallows it as an ordinary exit and stdout is empty: the exact signature
of run 43341064666 (CONTROL failed in 16 ms on `{ unparsed: '' }`, every
other case green; next group green on the same shard because the next
seed minted different ids).
Measured: a sweep of all 4096 two-character prefixes after `-` through
the bind's real flag set refuses exactly the 64 that begin `-y` and no
other. With three ids bound per run, roughly one run in 1,400 hits it.
### Not fixed here (reported as a finding)
The same refusal is a product defect at the public door: a row whose
minted id begins with `-y` cannot be bound by `os migrate
stored-references bind` in any spelling (`objectstack: INVOCATION ERROR
— Flag --id expects a value`, exit 2, 0 bytes on stdout under `--json`).
It is a family (any string flag carrying a minted id on a command that
declares a short flag; 27 commands declare `-y`), so it is reported to
the seat with evidence rather than patched in this test PR.
## Tests
<details><summary>Integration file, final head: 13/13</summary>
```
pnpm --filter @objectstack/cli exec vitest run --project integration --maxWorkers=2 src/commands/migrate/stored-references.integration.test.ts
Test Files 1 passed (1)
Tests 13 passed (13)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Reproduction (one-time ablation through
scripts/ablation-replace.mjs, restored to HEAD)</summary>
The `bind()` guard was replaced by `id = '-y' + id` (anchor 1 to 0, blob
b4ae844 to d53987cede12) and only the CONTROL bind case run. It
failed in 27 ms with the CI signature, now loud:
```
AssertionError: {"unparsed":"","exitCode":2,"thrown":"Flag --id expects a value","ms":13,"argv":["--table","sys_sharing_rule","--id","-ym31693_share_row",...,"--json"],"stderr":""}
Tests 1 failed | 12 skipped (13)
ablation-replace: ok restored: blob == HEAD (b4ae844) and git diff HEAD is empty
```
</details>
<details><summary>CLI unit tier and typecheck (head 01321f6)</summary>
```
pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2
Test Files 2 failed | 416 passed (418)
Tests 5930 passed | 29 skipped (5959)
```
The two failed files are `test/published-subpath-console.pin.test.ts`
and `test/published-subpath-hook-body.pin.test.ts`, both refusing at
setup with `packages/cli is not built (./dist/index.js is absent)`: only
the CLI's dependency closure was built locally. NOT MEASURED locally,
reason: prerequisite (no CLI dist); this diff touches neither. CI's Test
Core builds and runs them.
```
pnpm --filter @objectstack/cli typecheck
check:test-typecheck: OK — @objectstack/cli's test layer compiles under packages/cli/tsconfig.test.json
os-verify-lock: VERDICT command-exit 0
npx eslint --no-inline-config packages/cli/src/commands/migrate/stored-references.integration.test.ts exit 0
```
</details>
## Verification
<details><summary>Derived gate families (dispatch-gates, head
01321f6): 49 exit 0, 4 NOT MEASURED</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 53 commands for
the one changed path; each was run and its exit code recorded, and
`--ran` reconciled: `53 derived famil(ies) accounted for — 49 run, 4
NOT-MEASURED (4 DERIVED from a recorded exit 3)`.
The four exit-3 families refused their own prerequisite (the workspace
is not fully built locally): `check:dual-build-cjs-loads`, `check:i18n`,
`check:i18n-coverage`, `check:i18n-walk-parity`. NOT MEASURED locally,
reason: prerequisite; CI's Lint and Repo Gates runs them.
</details>
Not merged with `origin/main` before opening: it is 13 commits ahead of
the base, none under `packages/cli`, so CI's merge ref is the first
joint reading.
This PR changes only a test file and publishes nothing, so it needs the
`skip-changeset` label (not added by the dev).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3c44a97 commit 19cc897
1 file changed
Lines changed: 43 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
173 | 190 | | |
174 | 191 | | |
175 | 192 | | |
| |||
179 | 196 | | |
180 | 197 | | |
181 | 198 | | |
182 | | - | |
| 199 | + | |
183 | 200 | | |
184 | | - | |
| 201 | + | |
185 | 202 | | |
186 | 203 | | |
187 | 204 | | |
188 | 205 | | |
| 206 | + | |
189 | 207 | | |
190 | 208 | | |
191 | 209 | | |
| |||
215 | 233 | | |
216 | 234 | | |
217 | 235 | | |
218 | | - | |
| 236 | + | |
219 | 237 | | |
220 | 238 | | |
221 | 239 | | |
222 | 240 | | |
| 241 | + | |
| 242 | + | |
223 | 243 | | |
224 | 244 | | |
225 | 245 | | |
226 | 246 | | |
227 | 247 | | |
228 | 248 | | |
| 249 | + | |
229 | 250 | | |
230 | 251 | | |
231 | | - | |
232 | | - | |
233 | 252 | | |
234 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
235 | 266 | | |
236 | 267 | | |
237 | 268 | | |
238 | 269 | | |
239 | 270 | | |
240 | 271 | | |
241 | 272 | | |
242 | | - | |
243 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
244 | 278 | | |
245 | 279 | | |
246 | 280 | | |
| |||
458 | 492 | | |
459 | 493 | | |
460 | 494 | | |
461 | | - | |
| 495 | + | |
462 | 496 | | |
463 | 497 | | |
464 | 498 | | |
| |||
0 commit comments