Skip to content

test: bring packages/swr/tests under the scoped typecheck gate - #743

Merged
trueadm merged 1 commit into
mainfrom
claude/magical-meitner-eece8e
Aug 12, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/magical-meitner-eece8e

Conversation

@trueadm

@trueadm trueadm commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

pnpm typecheck:files (the prescribed pre-push gate) failed on any edited swr test file, while repo-wide pnpm typecheck never looked at packages/swr/tests at all (packages/swr/tsconfig.json includes only src). The visible symptom was TS2339 on window.__SWR_DEVTOOLS_OCTANE__ / __SWR_DEVTOOLS_REACT__, but the baseline scoped run also failed on untyped .tsrx fixture props, a () => undefined sentinel passed as Middleware, and cache.clear() (the public Cache contract has keys()/delete(), no clear()). This PR makes the swr tests tree typecheck-clean under the scoped gate without shipping anything to the tarball.

Why

  • scripts/typecheck-files.mjs resolves ownership by walking up to the nearest tsconfig and only auto-includes the owning project's .d.ts files. With packages/swr/tsconfig.json (src-only) as the fallback owner, no tests-local ambient declaration could ever be seen, so the devtools Window globals — installed at runtime via Object.defineProperty in src/_internal/devtools-contract.ts (the settled OCTANE DIVERGENCE[swr-devtools-global], untouched here) — had no importable or ambient type.
  • The augmentation must not live in src/: the package publishes "files": ["src", …], and a shipped ambient Window augmentation would apply to every consumer program.

Changes

  • New packages/swr/tests/tsconfig.json (modeled on the existing tests/adoption/tsconfig.json) owns the tests tree for the scoped gate, excluding differential and probes/conditions, which need different programs. New packages/swr/tests/global.d.ts declares the two devtools globals as optional unknown (root.test.ts deletes them), test-side only.
  • New packages/swr/tests/differential/tsconfig.json: the differential tests compile the byte-pinned vendored upstream/src, where the ambient augmentation would turn upstream's @ts-expect-error on window.__SWR_DEVTOOLS_REACT__ = React into a fresh TS2578. A lane-local tsconfig keeps global.d.ts out of that program; the differential test files themselves are sha256-pinned in audit/react-parity.json and are not modified.
  • "types": ["node"] added to the three probes/conditions/tsconfig.*.json lanes and the new differential tsconfig: they check under tsgo, which does not auto-include visible @types, so octane's runtime.ts failed with TS2591 Cannot find name 'process' (pre-existing; every other tsgo project in the repo already declares "types": ["node"]).
  • Typed all fixture props per the tsrx authoring rule (upstream/root/fixtures.tsrx, upstream/specialized/fixtures.tsrx, probes/external-store.tsrx) against the port's real exported types, typed two callback params in specialized.test.ts, and made the mergeConfigs sentinels in unit/core.test.ts real Middleware identities.
  • Replaced the four cache.clear() cleanup sites with for (const key of [...cache.keys()]) cache.delete(key) — behaviorally identical on the default Map-backed cache and inside the public Cache surface.

Validation

  • pnpm format:check
  • pnpm typecheck (repo-wide, green — the fixed -p list is unaffected by the new tests tsconfigs)
  • pnpm test — ran the full root Vitest run twice locally; 20,9xx tests pass. Each run had a different small set of failures confined to real-browser/server-spawning suites outside this diff (octane-events-browser native-change with a Vite 504 Outdated Optimize Dep load error, doom-browser pointer-lock, website-mcp-unit plumbing). All three files pass 28/28 when run directly, so these are local parallel-load flakes, not regressions from this change; nothing in this diff is imported by them.
  • targeted tests: pnpm typecheck:files packages/swr/tests/upstream/root/root.test.ts packages/swr/tests/unit/core.test.ts packages/swr/tests/probes/architecture.test.ts (passes; previously 17 errors), tsrx-tsc --noEmit -p packages/swr/tests/tsconfig.json (whole tests project clean), scoped runs of the probes/conditions lanes (clean), vitest run --project swr (35/35) and --project swr-differential (4/4), pnpm tsrx-decls:check, pnpm sync (no generated changes)

Risk / follow-ups

  • One pre-existing gap is left deliberately: scoped typecheck of a differential test still fails on upstream/src/index/use-swr.ts(329) TS2578 (upstream builds with noUnusedLocals, which this repo's configs don't set; enabling it in the lane trips over two intentionally-unused declarations in octane's runtime.ts). Unchanged from baseline — fixing it needs an octane-core edit and is spun off separately.
  • packages/swr/tests stays out of repo-wide pnpm typecheck on purpose: no other package gates its tests dir there, and the scoped pre-push gate now covers the tree.
  • Test-only + test-tooling change: no changeset.

Provenance

  • An agent produced this diff (agent-authored)

Note

Low Risk
Test-only TypeScript and cleanup changes; no production src or consumer-facing behavior.

Overview
Adds packages/swr/tests/tsconfig.json (excluding differential and probes/conditions) plus a tests/global.d.ts Window augmentation for devtools globals so pnpm typecheck:files on swr tests is clean without shipping ambient types from src. A separate tests/differential/tsconfig.json keeps that augmentation out of the byte-pinned upstream differential program.

Probe condition tsconfigs and the differential config now set "types": ["node"] for tsgo. Test fixtures and a few unit tests gain explicit types (Middleware sentinels, .tsrx props, callback params), and teardown replaces cache.clear() with for (const key of [...cache.keys()]) cache.delete(key) to match the public Cache API.

Reviewed by Cursor Bugbot for commit a7a4491. Bugbot is set up for automated code reviews on this repo. Configure here.

pnpm typecheck:files failed on any edited swr test file (untyped devtools
Window globals, untyped .tsrx fixture props, Middleware/Cache contract
violations) while repo-wide typecheck never checks packages/swr/tests. Add a
tests-scoped tsconfig + tests-local Window d.ts (nothing ships: the tarball is
src-only), give the differential lane its own tsconfig so the ambient
augmentation cannot un-use the vendored upstream's @ts-expect-error, add
types:["node"] to the tsgo-checked conditions lanes, and fix the test-side
type errors within public contracts.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
octane-website Skipped Skipped Aug 12, 2026 8:31pm
octane-website-mcp Skipped Skipped Aug 12, 2026 8:31pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp August 12, 2026 20:31 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website August 12, 2026 20:31 Inactive
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only labels Aug 12, 2026
@trueadm
trueadm marked this pull request as ready for review August 12, 2026 20:32
@trueadm
trueadm merged commit dd2424e into main Aug 12, 2026
70 of 74 checks passed
@trueadm
trueadm deleted the claude/magical-meitner-eece8e branch August 12, 2026 22:08

This branch was previously deployed

2 inactive deployments
Preview – octane-website — a7a4491b Deployed Aug 12, 2026 by vercel[bot]
Preview – octane-website-mcp — a7a4491b Deployed Aug 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant