Repository navigation
Commit 63a9bcb
test(plugin-audit): seed the comment gate's window with fewer docs and reuse the leaf gate's at-rest reads (test budget, slice 20) (#28398)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoMehpns1xDy9YL8qPyWdBPt)_
Part of #23181 (slice 20, `@objectstack/plugin-audit`). The card is a
series and stays open.
Clause-②: no
Metadata-protocol: none
Test-only diff: `skip-changeset`. Two files under
`packages/plugins/plugin-audit/src/`, both `*.integration.test.ts`;
`@objectstack/plugin-audit`'s `files[]` ships `dist`, `README.md` and
`CHANGELOG.md` only.
## 维护者速读
- 改了什么:plugin-audit 包 2 个集成测试文件。`comment-parent-pair` 把 2,600 条评论改为每个文档
10 条(260 个文档,而非 2,600 个),评论总数不变;`parent-record-read-leaf`
的各用例复用同一份系统读出的静止数据(行数变了就重读);两个文件都在模块顶层先付首次内核启动,并在第 2 行加 `//
test-budget:` 声明。只动测试文件。
- 为什么改:卡 #23181 要求单个测试文件不超过 10 s;这两个文件在最近一次计时刷新里分别是 28.07 s 和 35.78 s,是
server 车道里最慢的两个不在卡单上的文件。
- 风险与回滚:不改断言、超时与分层;38 个用例名前后一致、全绿;评论文件自己打印的读数(静止 2,607 行、成员 A 可读 2,303
行、管理员 2,605 行)前后逐字节相同。回滚即 revert 本 PR。
- 先看:`comment-parent-pair.integration.test.ts` 的 `COMMENTS_PER_DOC`
注释(为什么窗口按评论行计、不按文档计);`parent-record-read-leaf.integration.test.ts` 的
`atRestOf`(复用的依据与行数守卫)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-audit exec vitest run
--maxWorkers=2 src/comment-parent-pair.integration.test.ts`,预期 20
个用例全绿,`tests` 耗时约为 main 上的 40%。
- 需要你做的:无,席位落地。
## What changes
The newest per-file reading is still the weekly shard-timings refresh of
2026-10-26 (run 40275747937, refresh PR #25960's window, hourly runs
40200279306 to 40272142430); the next scheduled refresh is 2026-11-02.
Of the `domain:server` files over 10 s there that PR #28081's acceptance
notes list for a later slice, the two slowest are in one package:
`src/parent-record-read-leaf.integration.test.ts` 35.78 s and
`src/comment-parent-pair.integration.test.ts` 28.07 s, both in run
40204927516.
Profile (local, before): each file spends about 6 s of its clock seeding
2,600 `e5_doc` / `e7_doc` records. The records themselves cost about
0.15 s; the rest is the real CRUD mirror, which writes one
`sys_audit_log` row and one `sys_activity` row per record (2,600 + 2,600
single-row creates, about 2.2 ms per record). The engine runs plugin
hooks unconditionally (no opt-out reaches the audit writers, by design),
so the mirror's cost cannot be skipped, only not paid where nothing
reads it.
**`comment-parent-pair`: comments ten to a doc.** The window this file
proves the leaf lifts was over comment rows: the thread probe's
candidate pre-scan reads `sys_comment` (`READ_SCAN_LIMIT` in
`comment-access-hooks.ts`), never parent records. So the 2,600 comments
now sit on 260 docs (230 of member A's, 30 of member B's), and only 260
records pay the mirror rows, which nothing in this file reads. Every
comment count is unchanged: member A may read 2,303, the administrator
2,605, as the file's own `E7-COMMENT-READING` line prints on both sides.
The three withheld docs (`a0` to `a2`) still exist, and the delegated
case's withheld set is computed from the fixture, not assumed.
**`parent-record-read-leaf`: at-rest reads reused.** Its cases made 68
system reads of a whole object (ground truth reads five per call, across
12 calls, plus 8 direct), most over tables of 2,600 to 7,000 rows, and
the E5 describe writes nothing after its `beforeAll`. They now go
through `atRestOf`, which reads each object once and reuses it; every
reuse counts the object first and re-reads on a moved count, so a later
case that adds or removes rows is never judged against an older ground
truth. Its 2,600 records stay as they are: there the mirror's activity
and ledger rows ARE the subject, written "as their producers write them"
(the file's header), so this fixture is not shrunk.
**Module-scope first boots (both files).** One module-scope line boots
and shuts down a kernel with no fixture object before any hook runs
(AGENTS.md: clocked windows measure behaviour, never loading).
**Budget headers (ruling record 6181973363, letter B).** CI read these
files at about 3.3 (comments) and 3.0 (leaf) times their local clock
before, so both stay over 10 s on CI by that ratio, and each seeds a
real-mirror fixture past the window on a real SQL driver: one line at
line 2, N = the slowest CI reading x 1.25, rounded up to the next 10 s.
| file | change | slowest CI reading (s) | budget |
|:--|:--|--:|--:|
| `src/comment-parent-pair.integration.test.ts` | ten comments per doc +
module-scope first boot + header | 28.07 | 40 |
| `src/parent-record-read-leaf.integration.test.ts` | at-rest reuse +
module-scope first boot + header | 35.78 | 50 |
## Tests
Per file, vitest's own clock (`tests` in the Duration line, what the
refresh lane reads) and process wall, 3 isolated runs each,
`--maxWorkers=2`, on a shared 4 vCPU container; before = `3ba52069`,
after = `f267df4f` (`b905c57b` adds only the two header lines).
| file | before r1/r2/r3 (s) | after r1/r2/r3 (s) | wall before / after
(s) |
|:--|:--|:--|:--|
| comment-parent-pair | 9.56 / 7.84 / 8.41 | 3.67 / 3.88 / 3.59 | 30.9,
27.9, 26.0 / 23.7, 22.9, 22.5 |
| parent-record-read-leaf | 14.39 / 11.54 / 10.44 | 9.19 / 9.31 / 9.17 |
37.1, 32.7, 27.7 / 29.0, 28.3, 28.7 |
In `parent-record-read-leaf` the cases' own sum fell from 6.3 s to 3.0
s; what is left is the seeding above. The wall is mostly the package's
import graph (transform about 13 s, import about 17 s per isolated run),
which collection pays and no clock in the refresh lane reads.
Whole package on `b905c57b`: `Test Files 68 passed (68)`, `Tests 1097
passed (1097)`. Name census over the two files' JSON reports, before
(`3ba52069`) and after: 38 test names on both sides, 0 lost, 0 new, 0
with a changed status. After merging `origin/main` (`acf8e821`, no
change under `plugin-audit`) the two files re-ran green: `Test Files 2
passed (2)`, `Tests 38 passed (38)`.
<details><summary>Header parse</summary>
Both lines parse through `readTestBudget`
(`scripts/measure-test-shard-timings.mjs`): budgets 40 and 50 at line 2,
class `spawns the real producer once per single-cause fixture`.
</details>
No ablation: no tested behaviour changed.
## Acceptance notes
- `comment-parent-pair` may still read just over 10 s on CI after this
(local 3.7 s against the 3.3 ratio above), which is why it carries a
header; the next refresh is the reading that says.
- `parent-record-read-leaf`'s floor is its mirror-written fixture (about
6 s locally). Shrinking it toward the 2,000-row window was not done: an
earlier fix to this file (one case per reader) recorded "never a smaller
fixture" as its rule.
- The rest of PR #28081's list for later slices is unchanged by this PR:
`@objectstack/metadata`
(`src/serializers/typescript-serializer-annotation.test.ts` 23.74 s),
`@objectstack/plugin-pinyin-search`
(`src/boot-reconcile.integration.test.ts` 17.47 s),
`@objectstack/plugin-security` and `@objectstack/plugin-auth` (two files
each, 13.38 to 16.02 s).
- Branch `claude/project-thread-6vedk4` is the card thread's
platform-assigned branch; claim 6541983967 names it.
## Verification
Local, on `acf8e821`: `node scripts/pm/dispatch-gates.mjs --commands
--repo objectstack-ai/objectstack` derived 52 families; each run with
its exit captured by redirect before any pipe. 50 exit 0; `pnpm
check:dual-build-cjs-loads` and `pnpm check:i18n` exit 3 (PREREQUISITE
NOT MET: packages outside plugin-audit's closure have no `dist`, and the
CLI is not built), NOT MEASURED here and CI's. `--ran`: `52 derived
famil(ies) accounted for — 50 run, 2 NOT-MEASURED (2 DERIVED from a
recorded exit 3)`, exit 0. Scoped lint, the root `lint` script's own
command over `packages/plugins/plugin-audit`: exit 0. `pnpm --filter
@objectstack/plugin-audit typecheck`: VERDICT command-exit 0
(`check:test-typecheck: OK`, 0 errors held).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibz25B8NfvsjxU1ttwC)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 75ecaf4 commit 63a9bcb
2 files changed
Lines changed: 55 additions & 12 deletions
File tree
- packages/plugins/plugin-audit/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
| |||
145 | 156 | | |
146 | 157 | | |
147 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
148 | 165 | | |
149 | 166 | | |
150 | 167 | | |
| |||
209 | 226 | | |
210 | 227 | | |
211 | 228 | | |
212 | | - | |
| 229 | + | |
| 230 | + | |
213 | 231 | | |
214 | 232 | | |
215 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
| |||
201 | 208 | | |
202 | 209 | | |
203 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
204 | 229 | | |
205 | 230 | | |
206 | | - | |
| 231 | + | |
207 | 232 | | |
208 | 233 | | |
209 | | - | |
| 234 | + | |
210 | 235 | | |
211 | 236 | | |
212 | 237 | | |
| |||
298 | 323 | | |
299 | 324 | | |
300 | 325 | | |
301 | | - | |
| 326 | + | |
302 | 327 | | |
303 | 328 | | |
304 | 329 | | |
305 | 330 | | |
306 | | - | |
| 331 | + | |
307 | 332 | | |
308 | 333 | | |
309 | 334 | | |
| |||
328 | 353 | | |
329 | 354 | | |
330 | 355 | | |
331 | | - | |
| 356 | + | |
332 | 357 | | |
333 | 358 | | |
334 | 359 | | |
| |||
379 | 404 | | |
380 | 405 | | |
381 | 406 | | |
382 | | - | |
| 407 | + | |
383 | 408 | | |
384 | 409 | | |
385 | 410 | | |
| |||
431 | 456 | | |
432 | 457 | | |
433 | 458 | | |
434 | | - | |
| 459 | + | |
435 | 460 | | |
436 | 461 | | |
437 | 462 | | |
| |||
488 | 513 | | |
489 | 514 | | |
490 | 515 | | |
491 | | - | |
| 516 | + | |
492 | 517 | | |
493 | 518 | | |
494 | 519 | | |
| |||
0 commit comments