Skip to content

test(auth): fix sub-second race in TTL-cap introspection test#1675

Merged
bokelley merged 2 commits into
mainfrom
claude/issue-1673-fix-flaky-ttl-cap-test
May 11, 2026
Merged

test(auth): fix sub-second race in TTL-cap introspection test#1675
bokelley merged 2 commits into
mainfrom
claude/issue-1673-fix-flaky-ttl-cap-test

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Closes #1673

exp: Math.floor(Date.now() / 1000) + 1 gave the introspection cache a remaining lifetime window of anywhere from ~1 ms to ~999 ms depending on where in the current second the test started. On slow CI runners (or when the test fired within the last few ms of a second), the cache entry expired before the second auth() call landed, causing callCount to reach 2 instead of the asserted 1. The fix changes +1+2, which guarantees the effective TTL is always between 1000 ms and 2000 ms regardless of sub-second clock offset. The post-expiry sleep is extended from 1200 ms to 2500 ms to give 500 ms of slack over the new ~2-second worst-case window (the original 200 ms slack was the root of the timing fragility).

What was tested:

  • Formatting: npm run format:check — passed ✓
  • TypeScript: npm run typecheck — passed ✓ (pre-existing @types/node / moduleResolution deprecation errors present on main before this change; unrelated to diff)
  • Build + test suite: blocked in this environment by a network-gated schemas:ensure step (403 from adcontextprotocol.org); schema cache is gitignored and unavailable without network. Change is test-only — no library code touched. CI will run the full suite on push.
  • Syntax check of modified file: node --check test/server-auth-introspection.test.js — passed ✓

Pre-PR review:

  • code-reviewer: approved — +2 guarantees 1000–2000 ms effective TTL; 2500 ms sleep gives ≥500 ms slack over worst-case expiry. One nit: inline comment "Second call within 1s — cached." is slightly imprecise post-fix (token now lives 2 s); no blocker.
  • dx-expert: approved — timing-based fix is correct scope; clock-mocking follow-up would require raising Node engine floor or adding @sinonjs/fake-timers (separate decision). Nit: +2 / 2500 are implicitly coupled; a named constant would make the relationship explicit but is not a blocker.

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num>
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_01SSAxWkYWJZyuBy4CXHhzKx


Generated by Claude Code

`exp: Math.floor(Date.now() / 1000) + 1` gives a remaining lifetime
of ~1ms–999ms depending on sub-second clock position, so on slow CI
runners the cache entry expires before the second auth() call lands.

Change `+1` → `+2` (guarantees ≥1 s of remaining TTL regardless of
offset) and extend the post-expiry sleep from 1200 ms to 2500 ms
(500 ms slack over the new ~2-second window, vs. the previous 200 ms
which was the root of the flakiness).

Fixes #1673.

https://claude.ai/code/session_01SSAxWkYWJZyuBy4CXHhzKx
The `Check for changeset` CI gate runs `changeset status` which doesn't
distinguish test files from library code. Project CLAUDE.md says test-only
changes don't need a release changeset; the empty changeset is the
documented escape hatch (`changeset add --empty`) for that case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bokelley bokelley marked this pull request as ready for review May 11, 2026 10:21
@bokelley bokelley merged commit de32f23 into main May 11, 2026
9 checks passed
@bokelley bokelley deleted the claude/issue-1673-fix-flaky-ttl-cap-test branch May 11, 2026 10:21
bokelley added a commit that referenced this pull request May 22, 2026
The `Check for changeset` CI gate runs `changeset status` which doesn't
distinguish test files from library code. Project CLAUDE.md says test-only
changes don't need a release changeset; the empty changeset is the
documented escape hatch (`changeset add --empty`) for that case.

Same pattern as #1675.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bokelley added a commit that referenced this pull request May 22, 2026
…chema properties (#1918)

* test(codegen): lock @deprecated JSDoc generation on deprecated JSON Schema properties

Closes #1915

Adds three regression tests to `test/jsdoc-constraints-codegen.test.js` that
lock the behavior that `deprecated: true` in a JSON Schema property produces
`@deprecated` JSDoc in the TypeScript types generated by
`json-schema-to-typescript` v15.

Motivation: the expert review on adcontextprotocol/adcp#4904 (the 3.1
additive-deprecate on `CreateMediaBuySuccess.status` /
`UpdateMediaBuySuccess.status`) flagged that `deprecated: true` propagation
through codegen is partially reliable across toolchain versions. This test
fires on any jsts upgrade that silently drops the annotation, which would
remove the IDE deprecation signal for buyers without any runtime failure."

* chore: add empty changeset (test-only change, no release)

The `Check for changeset` CI gate runs `changeset status` which doesn't
distinguish test files from library code. Project CLAUDE.md says test-only
changes don't need a release changeset; the empty changeset is the
documented escape hatch (`changeset add --empty`) for that case.

Same pattern as #1675.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: server-auth-introspection 'caps positive TTL at the token's own remaining lifetime' has sub-second race window

1 participant