Repository navigation
Commit 9e0c0c2
test(plugin-auth): the forced-reset OAuth test takes its token time from the routine reset, not the wall clock (#36706)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8XGffEBTNhotjbfjKWmvMXT)_
Fixes #36361
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:用户无感,只改一条登录插件的测试;产品行为不变。
- 为什么做:这条测试在合并队列满载时会偶发变红,把无关的 PR 踢出队列,堵住主干。
- 出错会怎样:只影响测试本身,产品代码一行未动,可直接撤回。
- 要你做什么:无。
## What changes
One test, `an administrator's forced reset ends them too and reports the
apps; with revocation off it ends none`
in
`packages/plugins/plugin-auth/src/password-reset-ends-added-access.test.ts`.
Test-only: no product file moves.
The test used to take its token's `iat` as `Math.floor(Date.now() /
1000) + 1` **before** the routine admin reset ran.
Now it runs the routine reset first, reads the credential-change time
that reset wrote
(`readCredentialChangedAt`, the same reader the MCP door uses), and
takes `iat` as the first whole second at or
after it (`Math.ceil(changedAtMs / 1000)`). The forced-reset half is
unchanged.
The slow call is pinned: just before the routine reset the test moves
the wall clock two seconds on
(`vi.useFakeTimers({ toFake: ['Date'] })` + `vi.setSystemTime`, the same
pattern the file's credential-change
describe already uses), standing in for an admin call that takes longer
than a second under load. Every run now
takes the path the queue build failed on. The describe's `afterEach`
restores real timers.
## Why — root cause is the test's clock, not the product
`mcpConsentAdmits` places a token with no millisecond claim on a consent
row at `iat * 1000` and refuses it when that
is earlier than the account's credential-change time
(`issuedBeforeCredentialChange`). The routine reset
(`revokeSessionsAndKeys: false`) writes a new change time. The old test
fixed `iat` at most one second ahead of the
clock it read *before* the reset, so it assumed the admin HTTP call
finished inside that second. Under full-suite
load the call took longer, the change time landed after `iat * 1000`,
and the door correctly refused a token that,
by its own `iat`, predates the reset: `expected false to be true` at
line 538 (merge-queue run 44999732595, Test
Core 10/10). The product rule is right; the test's premise about timing
was wrong.
The two other `+ 1` sites in the file (the self-service reset case at
line 468, the disabled-app case at line 983)
have no credential change between taking `iat` and the assertion that
needs it to stand, so they cannot hit this.
## Tests
All on head `b4de067d`.
- **The pin fails without the fix.** `main`'s version of the test with
only the two clock lines added fails at the
card's assertion: `AssertionError: expected false to be true` at the
`grantStands()` right after the routine reset
(the same line as merge-queue run 44999732595, shifted by the two
inserted lines). The fixed test passes in the
same run. The `main` copy was temporary and is not in the diff.
- Before the pin existed, the same was shown with a real 1.5 s pause in
place of the clock move: red on `main`,
green with the fix.
- The fixed test, 20 consecutive runs: 20/20 passed.
- `pnpm --filter @objectstack/plugin-auth typecheck` (including
`check:test-typecheck`): passed.
- `pnpm --filter @objectstack/plugin-auth test`: 293 files, 6265 passed,
10 skipped.
- `eslint --no-inline-config` on the changed file: clean.
No skip, no narrowing, no retry wrapper, no timeout change.
## Acceptance notes
None.
## Verification
Two-minute check: `pnpm --filter @objectstack/plugin-auth exec vitest
run --maxWorkers=2 src/password-reset-ends-added-access.test.ts -t
"forced reset ends them too"` — 1 passed. Swap the two `issuedAt` lines
back to `Math.floor(Date.now() / 1000) + 1` taken before the routine
reset and it fails with `expected false to be true`.
Files to read first: in `password-reset-ends-added-access.test.ts`, the
forced-reset case (the clock move and the `iat` read back), then the
describe's `afterEach` (`vi.useRealTimers()`).
Changeset: none; the diff changes a test file only and publishes nothing
(`skip-changeset`).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JQwxbWUnHRCP5qaRA2VJEj
<!-- signed: repo:objectstack#1 · os-warren ·
session_01JQwxbWUnHRCP5qaRA2VJEj -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6206939 commit 9e0c0c2
1 file changed
Lines changed: 16 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
413 | 414 | | |
414 | 415 | | |
415 | 416 | | |
| 417 | + | |
416 | 418 | | |
417 | 419 | | |
418 | 420 | | |
| |||
525 | 527 | | |
526 | 528 | | |
527 | 529 | | |
528 | | - | |
529 | | - | |
530 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
531 | 536 | | |
532 | 537 | | |
533 | 538 | | |
534 | 539 | | |
535 | 540 | | |
536 | 541 | | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
537 | 550 | | |
538 | | - | |
| 551 | + | |
539 | 552 | | |
540 | 553 | | |
541 | 554 | | |
| |||
0 commit comments