Skip to content

Commit 9f5562f

Browse files
test(plugin-approvals): seed the past-500-decided stranded-scan cases in batches, not 1200 serial inserts (#38235)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu3fvgcmTNiNVgQgr2PxiD85)_ Fixes #38223 Clause-②: no Metadata-protocol: none ## 维护者速读 - 是什么:用户无感,只改一个测试文件。审批插件里“超过 500 条已决审批后仍能报出卡住的请求”这组用例,造数据从 1200 次逐行插入改成每批 200 行的批量写。 - 为什么:属于「CI 稳定与合并队列提速」专题(#38081)。这条用例在忙的队列机器上跑到 5.8 到 13 秒,超过 5 秒上限,已经把不相关的 PR(#38164、#38167)弹出合并队列。量下来九成时间花在逐行插入上,扫描本身只要约 50 毫秒。 - 出错会怎样:只影响测试。数据规模、顺序和断言都没变,还多了一条“601 行全部被读到”的断言;撤掉 #37808 的修法时,两条用例照样变红。 - 要你做的:无。 ## What changes `packages/plugins/plugin-approvals/src/stranded-request-inspection.test.ts`, the `#37808 — past 500 decided requests` block only: - `insertAll` seeds through the engine's own array insert, `engine.insert('sys_approval_request', rows[], …)`, in batches of `SEED_BATCH = 200` rows, instead of one `engine.insert` per row. Same rows, same insertion order, same `isSystem` context, same real `ObjectQL` over `SqlDriver` (better-sqlite3, in-memory). - The batch is 200, not the whole set: one multi-row INSERT of 600 or 1200 rows is refused by SQLite with `too many terms in compound SELECT` (its default 500-term compound limit; knex emits a multi-row insert as a compound SELECT there). A comment beside `insertAll` says why the batch exists and why it is 200. - The 600-row case also asserts `out.scanned === 601`: the newest window (ids 102–601) plus the first walk page (ids 1–500) read every seeded row, so a short batch write cannot pass it silently. This only adds an assertion; none is removed or loosened. No timeout was raised, nothing is skipped, and the scale (600 and 1201 decided requests, 500 per window, 3 + 3 sweeps) is unchanged. ## Why The card's evidence (comment 7236773117): the case took about 1 s locally and 5.8 to 13 s on queue runners, against the 5000 ms default. Measured here, on the case "an older strand outside the newest window is reached by the cursor": | | seeding 1201 rows | 6 sweeps | case total | |---|---|---|---| | before (serial inserts) | 789 / 1146 ms | 53 / 63 ms | ~1000 ms | | after (batches of 200) | 93 / 99 / 103 ms | 41 / 54 / 52 ms | 149–178 ms | The 600-row case went from about 570 ms to 100–170 ms. The whole file's 39 tests are unchanged and green. ## Verification Ablation (the cases still detect the bug they pin): with `inspectStrandedRequests` reverted to the pre-#37808 read (no `orderBy` on the newest window, no id cursor on the walk), the 600-row and 1201-row cases both fail under the new seeding, exactly as they fail under the old one; CONTROL passes in both. Restored, 3/3. <details><summary>runs</summary> Head 19eeab6. - `pnpm turbo run build --filter='@objectstack/plugin-approvals^...'`: exit 0. - `npx vitest run src/stranded-request-inspection.test.ts` (in the package), three times: 39/39 passed each time. - `npx vitest run` (whole package): 131 files, 1979 tests passed. - `pnpm typecheck` (package, includes `check:test-typecheck`): exit 0. - `node scripts/pm/dispatch-gates.mjs --commands --changed`: 54 derived; 51 exit 0; 3 exit 3 (PREREQUISITE NOT MET), so NOT MEASURED locally and left to CI: `node scripts/check-plugin-teardown-shape.mjs --self-test` (its fixture commit is out of this shallow clone), `pnpm check:dual-build-cjs-loads` and `pnpm check:i18n` (both read every package's `dist/`; only this package's closure is built here). `--ran` reconcile: 54 accounted, 0 UNRUN. - `npx eslint` on the changed file: exit 0. </details> ## Acceptance notes - Found on the way, not fixed here (out of this card's test-only scope): an `ObjectQL` array insert of more than about 500 rows on SQLite throws `too many terms in compound SELECT` from `SqlDriver.bulkCreate`, which does not chunk. Reported to the seat as a follow-up candidate. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; eslint on the changed file passes (the full `pnpm lint` was not run locally; CI runs it). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. (branch `claude/project-thread-4xkl1n` is the harness-assigned name) - [x] 5. A change that publishes carries a changeset: this diff is a test file only and publishes nothing, so no changeset (`skip-changeset`). - [x] 6. `packages/spec` touched: no. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English (the 维护者速读 block is the maintainer summary). - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgVv7fqmna3sqqbjzf2 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 01c238a commit 9f5562f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎packages/plugins/plugin-approvals/src/stranded-request-inspection.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,17 @@ describe('#37808 — past 500 decided requests, a new strand is still reported',
795795
svc.attachAutomation(surface(strandedRuns) as any);
796796
return svc;
797797
};
798+
// [#38223] Seeded in batches through the engine's own array insert, not one
799+
// `insert` per row: 1200 serial single-row writes were ~90% of the slowest
800+
// case's ~1 s locally and 5.8–13 s on loaded merge-queue runners, past the
801+
// 5 s test default. The rows, their order and every assertion are unchanged;
802+
// the batch is ≤ 200 rows because SQLite refuses a multi-row INSERT past its
803+
// 500-term compound SELECT limit.
804+
const SEED_BATCH = 200;
798805
const insertAll = async (rows: FakeRow[]) => {
799-
for (const row of rows) await engine.insert('sys_approval_request', row, { context: { isSystem: true } } as any);
806+
for (let i = 0; i < rows.length; i += SEED_BATCH) {
807+
await engine.insert('sys_approval_request', rows.slice(i, i + SEED_BATCH), { context: { isSystem: true } } as any);
808+
}
800809
};
801810

802811
// A fresh in-memory store per test: each one counts rows from zero.
@@ -837,6 +846,8 @@ describe('#37808 — past 500 decided requests, a new strand is still reported',
837846
// The newest decision: its run is gone.
838847
await insertAll([decided(++seq, { flow_run_id: 'run_new_strand' })]);
839848
const out = await freshService(['run_new_strand']).inspectStrandedRequests();
849+
// Newest window (ids 102–601) plus the first walk page (ids 1–500): every one of the 601 seeded rows is read.
850+
expect(out.scanned).toBe(601);
840851
expect(out.stranded.map(s => s.runId)).toEqual(['run_new_strand']);
841852
});
842853

0 commit comments

Comments
 (0)