Repository navigation
Commit bc3ec37
test(app-shell): pre-filter the Studio address guard's walk before parsing (#37198)
Fixes #37174
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:只改界面工作区里的一份守卫测试,产品代码一行未动。
- 为什么做:这份「禁止手拼工作室地址」的守卫在繁忙的 CI 分片上超时,把一个无关的合并请求两次挤出合并队列,这次修复为它解围。
- 出错会怎样:最坏是守卫漏看某个文件里的手拼地址;新加的对照测试正是为这种情况变红而设,改动随时可直接撤回。
- 要你做什么:无。
## What changes
Test-only: one file,
`ui/packages/app-shell/src/views/studio-design/studioAddress.guard.test.ts`.
No product file, no published file (`@object-ui/app-shell` is private
and ships `dist` only), hence `skip-changeset`. This unblocks PR #37114,
whose Test UI shard timed out on this case twice (queue run 45501281672;
PR job 138901843717).
- **Pre-filter before parsing.** The walk case TypeScript-parsed every
non-test ui source (2,378 files at this head) inside the default 15 s
budget. A raw-text gate, `maySpellStudioAddress`, now keeps the parse to
the sources that may spell an address (123 of 2,378 here).
- **The gate is a superset of the matcher by construction, and wider
than the card's two words.** Reading the matcher showed `/studio` plus
`STUDIO_ROOT_PATH` is not exact:
- The matcher also flags a template or `+` on `STUDIO_LANDING_PATH` (it
is in `ROOT_NAMES`).
- The matcher reads COOKED literal text, so `'\x2fstudio'`,
`'\57\163tudio'`, `'/stud\u{69}o'` and a line continuation inside the
word all cook to `/studio` while the raw text holds no `/studio`.
Identifiers cook `\u` escapes the same way (`STUDIO_ROOT_PATH`).
- So the gate matches each of the three words with every character in
any of those spellings (itself, identity escape, `\x`, `\u`, `\u{}`,
legacy octal), with line continuations allowed between characters.
- A JSX attribute string is not cooked (TypeScript keeps `/` as is),
so its raw text is its text.
- The header comment on the gate gives the argument.
- **New control, "the pre-filter keeps every source the matcher
flags".** It runs over one shared fixture list, `FLAGGED_SPELLINGS`: the
first case's eight spellings plus ten escaped and `STUDIO_LANDING_PATH`
forms. Each fixture's only hit is that spelling. The control asserts the
matcher flags it once and the gate passes it. It also asserts that the
builder file fires the matcher and passes the gate, and that a source
naming no address is dropped. The first case now asserts the matcher
over the same list, so the two cannot drift apart.
- **Existing controls kept.** The walk still has to reach
`StudioDesignSurface.tsx` and `StudioRoute.tsx`, and the builder still
fires the matcher inside the walk case.
- **Explicit budget.** The walk case now runs under `{ timeout: 60_000
}` as the second line of defence; the measured wall time is below.
## Tests
<details><summary>Wall time of the walk case, before and after (local,
shared box, under os-verify-lock)</summary>
- Before (base `95734fef75`, unchanged file): `no ui source outside the
builder spells one 4471ms`. File total: `Duration 5.79s`.
- After (`45151aec2b`): `no ui source outside the builder spells one
873ms`; `the pre-filter keeps every source the matcher flags 18ms`. File
total: `Duration 1.48s`, `Tests 3 passed (3)`.
- Probe at the same tree: walk 24 ms, reading every file 166 ms, the
gate's regex over all 2,378 texts 47 ms. The rest of the before figure
was the parse.
</details>
<details><summary>Ablation 1: the gate drops everything
(`MAY_SPELL_STUDIO_ADDRESS.test(text) && false`)</summary>
Made through `scripts/ablation-replace.mjs`. Result: `ok mutation
landed: anchor 1 -> 0, blob fdd866a -> b763c5694c5f`.
- `× the pre-filter keeps every source the matcher flags`, failing with
`AssertionError: const a = '/studio';: expected false to be true`.
`Tests 1 failed | 2 passed (3)`.
- The walk case stayed GREEN under this ablation (196 ms, no file
parsed, so no offender). That is the hole the new control closes.
- Restore: `ok restored: blob == HEAD (fdd866a) and git diff HEAD
is empty`.
</details>
<details><summary>Ablation 2: the card's two-word filter (`/studio` or
`STUDIO_ROOT_PATH` as plain substrings)</summary>
Made through the same tool. Result: `ok mutation landed: anchor 1 -> 0,
blob fdd866a -> dbb5d30c77b9`.
- `× the pre-filter keeps every source the matcher flags`, failing with
`AssertionError: const a2 = '\x2Fstudio';: expected false to be true`.
`Tests 1 failed | 2 passed (3)`.
- Restore: `ok restored: blob == HEAD (fdd866a) and git diff HEAD
is empty`.
</details>
<details><summary>Derived gates at 45151ae (`dispatch-gates.mjs
--commands`, 27 commands)</summary>
- 26 of 27 exited 0 on the first pass.
- `pnpm --dir ui exec vitest run scripts/` first went red, 22 files
failing with `Cannot find package '@objectstack/spec/ui'`: the fresh
worktree had no `packages/spec/dist`. After `pnpm --filter
@objectstack/spec build` it went green: `Test Files 172 passed | 2
skipped (174)`, `Tests 5131 passed | 2 skipped (5133)`, `VERDICT
command-exit 0`.
- `node scripts/check-nul-bytes.mjs` and a control-byte grep over the
file are clean. `eslint --no-inline-config` on the file exits 0.
</details>
- Whole `@object-ui/app-shell` package suite (2,443 test files,
`--maxWorkers=2` on a shared box): NOT MEASURED. Reason: still running
after 70 minutes when this PR was opened. The CI `Test UI` shards own
that verdict.
## Acceptance notes
- The two-word pre-filter the card proposed would have missed
`STUDIO_LANDING_PATH` and every escaped spelling (ablation 2). The
filter was widened to stay an exact superset, as the dispatch asked.
- On today's tree the widened gate passes the same 123 files the
two-word filter would. The widening costs no parse time.
- `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0`
(origin/main `95734fef75`, 0 PR heads share the file).
## Verification
**Read first:**
1. The doc comment above `STUDIO_ADDRESS_WORDS` and the regex builder
under it. This is the risk hunk: the superset argument lives there.
2. The `FLAGGED_SPELLINGS` list and the new control case.
3. The walk case's `maySpellStudioAddress` early return and its `{
timeout: 60_000 }`.
**Two-minute check:** from `ui/`, run `pnpm --filter
@object-ui/app-shell exec vitest run --root ../.. --reporter=verbose
packages/app-shell/src/views/studio-design/studioAddress.guard.test.ts`.
Expect three passing cases, with the walk case at about 1 s instead of
about 4.5 s.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent 886e970 commit bc3ec37
1 file changed
Lines changed: 108 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
129 | 209 | | |
130 | 210 | | |
131 | 211 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 212 | + | |
140 | 213 | | |
141 | 214 | | |
142 | 215 | | |
| |||
150 | 223 | | |
151 | 224 | | |
152 | 225 | | |
153 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
154 | 248 | | |
155 | 249 | | |
156 | 250 | | |
| |||
163 | 257 | | |
164 | 258 | | |
165 | 259 | | |
166 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
167 | 265 | | |
168 | 266 | | |
169 | 267 | | |
0 commit comments