Skip to content

Commit d78a7e4

Browse files
test(plugin-auth): register the #8243 rotation cases only in their own file, not in the 32 suites that import its double (#28624)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XHbvKE5cT3AmzSZKFm5wgRg)_ Part of #23181 (slice 30, the seat's ruling D on report `6555141723`). The card stays open for later slices. Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:`impersonation-bearer-rotation.test.ts` 只在自己是 vitest 正在运行的那个文件时才注册它的 10 个 #8243 用例(`expect.getState().testPath` 与本模块路径比较);另外 6 个导入它的测试文件里,以「代价已测量」为由解释导入的注释改为现状。共享的 `createMemoryEngine` 替身、两个门禁台账、32 处 import 行都不动。 - **为什么改**:32 个测试文件从这个测试文件导入替身,每次导入都把那 10 个用例在导入方里重新注册一遍,同样 10 个用例每轮跑 33 次(#23181 测试提速职责)。 - **风险与回滚**:只改测试文件;plugin-auth 的 `files[]` 只发 `dist`、README、CHANGELOG,不发布任何东西。模块级钩子(console 桩、`restoreAllMocks`、scrypt 记忆)仍不加守卫,24 个只靠这次导入拿到 scrypt 记忆的文件照旧拿到。回滚即 revert。 - **先看**:`packages/plugins/plugin-auth/src/impersonation-bearer-rotation.test.ts`(`isEntry` 守卫;用 `git diff -w` 看,除守卫外只有缩进变化);`admin-impersonate-endpoint.test.ts` 第 32–43 行的注释。 - **两分钟验证**:`pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/impersonation-bearer-rotation.test.ts src/admin-has-permission-endpoint.test.ts` → 前者 10 个用例、后者 3 个(base 上后者是 13 个)。 - **需要你做的**:无,席位落地。 ## What changes - `packages/plugins/plugin-auth/src/impersonation-bearer-rotation.test.ts`: the three top-level `describe.concurrent` blocks (the ten #8243 cases) are wrapped in `if (isEntry) { … }`, where `isEntry = expect.getState().testPath === fileURLToPath(import.meta.url)`. A comment says why (#23181 slice 30, the 32 importers). The precedent is `metadata-protocol/src/protocol.lock-one-resolution.kit.test.ts`. `git diff -w` shows only the guard, its comment, the `fileURLToPath` import and a re-worded #23184 comment above it (which said the cases still run in importers). Every case keeps its body and assertions. The export and the double are byte-identical. The module-scope hooks stay unguarded: the console stubs, `afterEach(restoreAllMocks)`, and `memoizeScrypt()` with `afterAll(restore)`. - Prose in importers. Import lines do not change. `git grep` over the 32 importers for comments justifying the import by its cost, or saying the bearer-rotation cases run there: - `admin-impersonate-endpoint.test.ts`: the "re-registers … 10 rotation tests also execute" sentence and "Ten duplicated hermetic tests is the cheapest of the four." are replaced by one sentence: the file registers its `describe`s only when it is the one run. The reason to import (one double in both gates' sight) stays. - `platform-admin-standing.consolidation.test.ts` and `session-positions-security-axis.test.ts`: "re-registering that file's `describe`s here is cheaper than minting a second engine double" becomes "sharing its double is better than minting a second engine double". - `admin-impersonate-endpoint`, `platform-admin-standing.consolidation`, `session-grants-resolved-once`, `two-factor-reenrollment-verified-reset` and `two-factor-rotated-token-echo`: in the vendor-preload comment, "(and the bearer-rotation cases it imports)" becomes "(and, until #23181 slice 30, the bearer-rotation cases it imported)". The preload lists themselves are untouched. - Left as they are, because they are still true: `bridge-redispatch-transport.pin.test.ts` line 36 and `sso-domain-verification-unknown-provider.pin.test.ts` line 123 (the import still registers `afterEach(restoreAllMocks)` in the importer). ## Tests Probe, a throwaway run with two temp files deleted after. A module that reads `expect.getState().testPath` at collection sees the file vitest is collecting, in all three runs: ```text === run: kit alone PROBE kit-module: testPath=…/zzprobe-kit.test.ts own=…/zzprobe-kit.test.ts isEntry=true Tests 1 passed (1) === run: importer alone PROBE kit-module: testPath=…/zzprobe-importer.test.ts own=…/zzprobe-kit.test.ts isEntry=false PROBE importer-module: testPath=…/zzprobe-importer.test.ts Tests 1 passed (1) === run: both in one invocation PROBE kit-module: testPath=…/zzprobe-importer.test.ts … isEntry=false PROBE kit-module: testPath=…/zzprobe-kit.test.ts … isEntry=true Tests 2 passed (2) ``` Each file gets its own module graph (vitest's default `isolate: true`; neither plugin-auth's config nor CI turns it off), so the module is evaluated again per file and the reading is per file. Count and wall A/B on one box: the full plugin-auth suite in separate invocations, interleaved base, head, base, head, base, head, in one lock hold. Base `ce001f97` was swapped in for the 7 files and HEAD restored after; `git diff HEAD` was empty at the end. | run | base | head | |:--|--:|--:| | tests (all runs identical) | 3943 passed, 10 skipped (3953) | 3623 passed, 10 skipped (3633) | | package wall, s | 266.7 / 263.5 / 262.1 (mean 264.1) | 256.6 / 255.8 / 246.1 (mean 252.8, −4.3%) | | sum of all 207 default-reporter file lines, s | 229.6 / 224.6 / 225.0 | 205.0 / 205.8 / 194.0 (−11%) | | sum of the 32 importers' file lines, s | 86.7 / 85.3 / 85.0 | 65.0 / 63.4 / 61.0 (−26%) | - The fall is exactly 320 = 10 × 32, and every exit is 0. From the JSON reporter, per file: each of the 32 importers falls by exactly 10. `impersonation-bearer-rotation.test.ts` runs 10 before and 10 after. The other 174 files' counts are identical. Run alone, `impersonation-bearer-rotation.test.ts` reads 10/10 at head. - The package wall falls less than the summed file lines because the run is bound by workers and module collection, not by these cases. - `pnpm --filter @objectstack/plugin-auth typecheck` (tsc, examples, `check:test-typecheck`): exit 0. - No ablation: test-only, and no tested behaviour changed. ## Acceptance notes - `// test-budget:` headers: none added or changed (order item 6). - The hidden limit-blind `find` double in `plugin-sharing/src/exec-context-seam.testkit.ts`, and whether the two double gates should walk `*.testkit.ts`, are filed by the seat as a finding for triage. They are not in this PR. ## Verification - Head `31320abb`. `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 51 families. All 51 were run after a full `turbo run build` (118/118) and all exit 0. `--ran` reports: 51 accounted, 51 run, 0 NOT-MEASURED. - `check:engine-double-contract`: exit 0, 1060 rows held by the RETAINED ledger, as on base. `check:objectql-double-limit`: exit 0, "baseline key set verified … no files added". Neither ledger file is in the diff. - `eslint --no-inline-config` over the 7 files: exit 0. plugin-auth has no lint script. - `check-commit-card-trailers --range ce001f9..HEAD`: exit 0. - `skip-changeset`: plugin-auth's `files[]` is `dist`, `README.md`, `CHANGELOG.md`, and the diff is `*.test.ts` only. No `files[]` changes. --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5kvkRpCLsRcpPnABwj)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6e11a92 commit d78a7e4

7 files changed

Lines changed: 210 additions & 194 deletions

‎packages/plugins/plugin-auth/src/admin-impersonate-endpoint.test.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';
3030
import { ADMIN_FULL_ACCESS } from '@objectstack/spec/identity';
3131
import { AuthManager } from './auth-manager';
32-
// ⚠️ Imported from a sibling TEST file on purpose, and the cost is measured, not
33-
// missed: importing a `.test.ts` re-registers its `describe`s here, so that
34-
// file's 10 rotation tests also execute inside this one. The alternatives are
32+
// ⚠️ Imported from a sibling TEST file on purpose. That file registers its
33+
// `describe`s only when it is the file vitest is running (#23181 slice 30), so
34+
// the import brings the double and none of its tests. The alternatives are
3535
// worse. Minting a second engine double is a second looseness risk plus two new
3636
// `check:engine-double-contract` ledger entries, when this suite needs no
3737
// fidelity that double does not already have. Extracting it to a plain `.ts`
@@ -40,7 +40,6 @@ import { AuthManager } from './auth-manager';
4040
// `walk()`), so the pinned entries would go stale and the double would end up
4141
// scanned by nobody. And a suite-free `*.test.ts` fixture file is not available
4242
// either: this package runs a bare `vitest run`, with no `--passWithNoTests`.
43-
// Ten duplicated hermetic tests is the cheapest of the four.
4443
import { createMemoryEngine } from './impersonation-bearer-rotation.test';
4544
import { ADMIN_SESSION_RECOVERY_RESPONSE_HEADER } from './impersonation-bearer-rotation';
4645
import { USER_NOT_FOUND } from './admin-impersonate-endpoint';
@@ -52,7 +51,7 @@ import { memoizeScrypt } from './__tests__/scrypt-memo.testkit';
5251
// through a lazy `await import()` (the package root stays light on purpose), so
5352
// without these lines the file's first case paid about half a second of vendor
5453
// module evaluation on a dev container. The list is what the managers in this
55-
// file (and the bearer-rotation cases it imports) boot through; a module it
54+
// file (and, until #23181 slice 30, the bearer-rotation cases it imported) boot through; a module it
5655
// misses is still loaded in the first case, as before. The module cache hands
5756
// `AuthManager` these same instances, and this file changes no environment the
5857
// vendor reads at load (better-auth captures `NODE_ENV` when its env module is

‎packages/plugins/plugin-auth/src/impersonation-bearer-rotation.test.ts‎

Lines changed: 195 additions & 178 deletions
Large diffs are not rendered by default.

‎packages/plugins/plugin-auth/src/platform-admin-standing.consolidation.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';
4141
import { ADMIN_FULL_ACCESS } from '@objectstack/spec/identity';
4242
import { AuthManager } from './auth-manager';
43-
// ⚠️ Imported from a sibling TEST file on purpose — the same trade
44-
// `admin-impersonate-endpoint.test.ts` measured and documented at its own
45-
// import of it: re-registering that file's `describe`s here is cheaper than
46-
// minting a second engine double (a second looseness risk plus new
43+
// ⚠️ Imported from a sibling TEST file on purpose, for the reason
44+
// `admin-impersonate-endpoint.test.ts` documents at its own import of it (that
45+
// file registers its `describe`s only when it is the one run): sharing its
46+
// double is better than minting a second engine double (a second looseness risk plus new
4747
// `check:engine-double-contract` ledger entries) and far cheaper than moving it
4848
// to a plain `.ts` helper, which would remove it from that gate's sight
4949
// entirely (the gate discovers doubles by walking `*.test.ts` only).
@@ -56,7 +56,7 @@ import { memoizeScrypt } from './__tests__/scrypt-memo.testkit';
5656
// through a lazy `await import()` (the package root stays light on purpose), so
5757
// without these lines the file's first case paid about half a second of vendor
5858
// module evaluation on a dev container. The list is what the managers in this
59-
// file (and the bearer-rotation cases it imports) boot through; a module it
59+
// file (and, until #23181 slice 30, the bearer-rotation cases it imported) boot through; a module it
6060
// misses is still loaded in the first case, as before. The module cache hands
6161
// `AuthManager` these same instances, and this file changes no environment the
6262
// vendor reads at load (better-auth captures `NODE_ENV` when its env module is

‎packages/plugins/plugin-auth/src/session-grants-resolved-once.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { memoizeScrypt } from './__tests__/scrypt-memo.testkit';
3939
// through a lazy `await import()` (the package root stays light on purpose), so
4040
// without these lines the file's first case paid about half a second of vendor
4141
// module evaluation on a dev container. The list is what the managers in this
42-
// file (and the bearer-rotation cases it imports) boot through; a module it
42+
// file (and, until #23181 slice 30, the bearer-rotation cases it imported) boot through; a module it
4343
// misses is still loaded in the first case, as before. The module cache hands
4444
// `AuthManager` these same instances, and this file changes no environment the
4545
// vendor reads at load (better-auth captures `NODE_ENV` when its env module is

‎packages/plugins/plugin-auth/src/session-positions-security-axis.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3939
import { celEngine } from '@objectstack/formula';
4040
import { AuthManager } from './auth-manager';
4141
// Imported from a sibling TEST file for the reason `platform-admin-standing.
42-
// consolidation.test.ts` documents at its own import: re-registering that
43-
// file's `describe`s here is cheaper than minting a second engine double (a
44-
// second looseness risk plus new `check:engine-double-contract` ledger rows).
42+
// consolidation.test.ts` documents at its own import: sharing that file's
43+
// double is better than minting a second engine double (a second looseness
44+
// risk plus new `check:engine-double-contract` ledger rows).
4545
import { createMemoryEngine } from './impersonation-bearer-rotation.test';
4646
import { inviteForAudienceGate } from './audience-gate-test-support';
4747

‎packages/plugins/plugin-auth/src/two-factor-reenrollment-verified-reset.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { memoizeScrypt } from './__tests__/scrypt-memo.testkit';
6666
// through a lazy `await import()` (the package root stays light on purpose), so
6767
// without these lines the file's first case paid about half a second of vendor
6868
// module evaluation on a dev container. The list is what the managers in this
69-
// file (and the bearer-rotation cases it imports) boot through; a module it
69+
// file (and, until #23181 slice 30, the bearer-rotation cases it imported) boot through; a module it
7070
// misses is still loaded in the first case, as before. The module cache hands
7171
// `AuthManager` these same instances, and this file changes no environment the
7272
// vendor reads at load (better-auth captures `NODE_ENV` when its env module is

‎packages/plugins/plugin-auth/src/two-factor-rotated-token-echo.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { memoizeScrypt } from './__tests__/scrypt-memo.testkit';
4646
// through a lazy `await import()` (the package root stays light on purpose), so
4747
// without these lines the file's first case paid about half a second of vendor
4848
// module evaluation on a dev container. The list is what the managers in this
49-
// file (and the bearer-rotation cases it imports) boot through; a module it
49+
// file (and, until #23181 slice 30, the bearer-rotation cases it imported) boot through; a module it
5050
// misses is still loaded in the first case, as before. The module cache hands
5151
// `AuthManager` these same instances, and this file changes no environment the
5252
// vendor reads at load (better-auth captures `NODE_ENV` when its env module is

0 commit comments

Comments
 (0)