Skip to content

build: TypeScript 7, Rsbuild 2, and Jest -> Rstest - #900

Merged
bpowers merged 6 commits into
mainfrom
typescript-7-migration
Jul 10, 2026
Merged

bpowers merged 6 commits into
mainfrom
typescript-7-migration

Conversation

@bpowers

@bpowers bpowers commented Jul 8, 2026 •

Copy link
Copy Markdown
Owner

Modernizes the TypeScript toolchain in three commits: TypeScript 7, Rsbuild 2, and Jest -> Rstest. They ship together because they are entangled -- ts-jest cannot run on TypeScript 7, and picking a replacement runner constrains which bundler the repo carries.

No open issue is resolved by this PR, so there is no closing keyword. See "Does not close #635" below.

1. build: migrate to TypeScript 7

TypeScript 7 is the Go-native compiler rewrite. It ships no programmatic compiler API (deferred to 7.1) and no tsserver, so anything that embeds the compiler -- ts-jest, @rsbuild/plugin-type-check, typescript-eslint -- still needs a TS6-era package.

The repo therefore carries two entries per package, which is the layout the TypeScript team recommends for exactly this transition:

  • "typescript": "npm:@typescript/typescript6@^6.0.2" -- the compat shim. Aliased as typescript so peer-dependency ranges still see 6.0.2; its binary is renamed tsc6 to avoid colliding with TS7's.
  • "@typescript/native": "npm:typescript@^7.0.2" -- supplies the native tsc that pnpm tsc and the builds actually run.

Most of the breaking changes landed in TypeScript 6, not 7. The ones that bit us:

  • "moduleResolution": "node"/"node10" were removed. "bundler" is the closest analogue (extensionless relative imports plus exports support), and pairing it with "module": "commonjs" only became legal in TS6.
  • "baseUrl" was removed. Without it, paths targets resolve relative to the config file that declares them (even through extends), so every target is now ./-prefixed. TS7 rejects bare non-relative targets outright (TS5090).
  • "types" now defaults to [] rather than "every installed @types package". Each package names the globals-only packages it actually needs. Symbol.dispose used to arrive implicitly via @types/node; the engine now names esnext.disposable, the lib that owns it.
  • @types/resize-observer-browser is gone -- lib.dom has declared ResizeObserver since TS 4.2. A triple-slash /// <reference types="resize-observer-browser" /> in Canvas.tsx was keeping it alive.

Emit is unchanged. I diffed all 446 emitted files between TS 5.9 and TS 7: three .js files differ textually and all three are AST-identical (re-printed and compared). Nineteen .d.ts files change how React.memo components are spelled -- a TS6 change -- and the new type is assignable to the old (verified with a standalone assignability probe).

Gotcha for reviewers: a stale .tsbuildinfo written by TS 5.9 makes TS7 report hundreds of phantom errors. Buildinfo lives at <outDir>/<configName>.tsbuildinfo; src/engine's clean script now removes it. TS6-written buildinfo is read correctly by TS7 -- only the 5.9 artifacts are poison. If you see a wall of errors after checking this branch out, rm the buildinfo.

2. app: upgrade to Rsbuild 2

@rsbuild/core is now pure ESM and requires Node 20.19+/22.12+ (exactly where require(esm) became available).

Two real behavior fixes fell out of reading the changelog rather than trusting the config:

  • The dev-server proxy was silently matching everything. Rsbuild 2 bundles http-proxy-middleware 4, which renamed context to pathFilter. Neither the old key nor logLevel errors -- they are ignored -- and an array-form proxy entry with no pathFilter matches every request. Verified counterfactually against a dead backend: with context:, GET / returns 504 (the SPA itself was being proxied); with pathFilter:, SPA routes return 200 HTML and all seven API prefixes return 504.
  • PORT never worked. startDevServer() has never accepted a port option (checked against both 1.x and 2.x type definitions). The port now comes from server.port, where it belongs.

Also performance.chunkSplit: {strategy: 'all-in-one'} -> top-level splitChunks: false. The web-component build keeps its LimitChunkCountPlugin({maxChunks: 1}), which is a cross-origin embed contract, not a size tweak.

3. test: migrate from Jest to Rstest

Rstest compiles with the same Rspack/swc toolchain the app already bundles with, so the runner shares one dependency tree instead of dragging in a parallel one. (Vitest was the other candidate; it hard-depends on Vite, which would have entrenched a second bundler -- see the simlin-serve follow-up below.)

-260 packages from the lockfile. The only jest-family package left is a transitive jest-worker.

Test counts are unchanged, package for package: core 100, engine 442 + 1 skipped, server 139, app 99, diagram 1500, serve-web 113.

Non-obvious bits, all documented in docs/dev/typescript.md:

  • Globals are off. Every test imports what it uses from @rstest/core. That retires @types/jest and the shared eslint config's jest: 'readonly' block.
  • Mock<T>'s type argument is the whole function signature, not the return type. @types/jest typed jest.fn() loosely enough to hide argument mismatches -- serve-web's ws.test.ts had been passing <void, [WsMessage]> all along, and it type-checks now.
  • jest.requireActual is synchronous; rs.importActual is not, and Rstest rejects async mock factories outright. The replacement is the import ... with { rstest: 'importActual' } attribute, which hoists along with the factory. src/server cannot use it (import attributes need an ES module target, and that program emits CommonJS while type-checking its own tests), so static-config.test.ts uses rs.mock('fs', { spy: true }).
  • Rstest has no @jest-environment docblock. The 14 diagram tests that opted into a Node environment are now an explicit projects entry -- project-controller.ts documents a "zero React, zero DOM" invariant that an ambient jsdom global would quietly erode. The other 39 docblocks existed only to carry the pragma, so those files' block-comment copyright headers return to the canonical line-comment form.
  • @testing-library/react self-registers afterEach(cleanup) only when afterEach is a global, and @testing-library/dom's waitFor only pumps fake timers when a global jest object exists (helpers.js gates on typeof jest !== 'undefined', then calls jest.advanceTimersByTime). Both are wired up explicitly in a per-package tests/setup-testing-library.ts; the timer shim is inert under real timers.

Two Jest workarounds are deleted rather than ported:

  • The wouter stub and its moduleNameMapper existed because CommonJS Jest mishandled wouter's ESM-only exports. Rspack resolves it natively, which also retires the require.resolve() dance that guarded app: jest.config.js hardcodes a pnpm virtual-store hash for wouter; breaks on every React bump #523.
  • The CSS-module Proxy stubs (which echoed each property name back as its class name) give way to compiling the real stylesheets with output.cssModules.localIdentName: '[local]', so tests that query .eqnEditor still match -- against real CSS now.

One behavior change worth a close look

jsdom goes 26 -> 29, which implements PointerEvent. dialog.test.tsx asserted that a bare pointerdown dismisses a Radix dialog. That was only true because @testing-library/dom fell back to a plain Event whose button was undefined; given a real PointerEvent (button: 0), Radix waits for the matching click, as browsers do. The test now fires the full pointerdown/pointerup/click sequence, which is what a real pointer produces. The test was passing for the wrong reason.

Discovered along the way

Verification

  • pnpm test: 2393 passed, 1 skipped, exit 0 -- matching Jest package for package.
  • pnpm tsc, pnpm lint, scripts/lint-project.sh, check-copyright.py: clean.
  • Full pre-commit hook (Rust fmt/clippy/test, TS lint/build/tsc/test, pysimlin): passed.

bpowers added 3 commits July 8, 2026 15:34
TypeScript 7.0 is the Go-native compiler rewrite. It ships no programmatic
API -- `import * as ts from 'typescript'` does not exist, and a replacement
is not expected until 7.1. Both ts-jest and typescript-eslint link against
that API (typescript-estree requires it just to parse, independent of
parserOptions.project), so a single-version bump is impossible today.

Follow the upstream guidance and install both, disambiguated by npm alias:
`typescript` resolves to @typescript/typescript6, which re-exports the 6.0
API and renames its binary to tsc6; `@typescript/native` resolves to
typescript@7, which supplies `tsc`. Build and typecheck therefore run on the
native compiler while lint and test keep a working compiler API. pnpm's
strict-peer-dependencies is satisfied because the aliased package reports
version 6.0.2: within ts-jest's `<7` and typescript-eslint's `<6.1.0`.
typescript-eslint moves 8.54 -> 8.63 because 8.54 caps its peer at `<6.0.0`.

Most of what breaks is TypeScript 6.0's doing, not 7.0's. Verified against
6.0.3 and 7.0.2 side by side:

  - `baseUrl` and `moduleResolution: node10` are removed outright in 7.0.
    Dropping baseUrl is safe because `paths` targets resolve relative to the
    config file that declares them -- even through `extends` -- so `./src/*`
    in tsconfig.base.json reproduces the old repo-root mapping exactly. The
    targets must now be relative; TS7 rejects bare specifiers (TS5090).
  - `moduleResolution: bundler` is the closest analogue to node10, and
    pairing it with `module: commonjs` only became legal in 6.0 (5.9 rejects
    it with TS5095). Every consumer of these packages is a bundler or CJS
    Node, which resolve the same way.
  - `types` defaults to [] rather than every installed @types package, so
    each program now names the globals-only packages it actually relies on.
    Everything reached through an ordinary import (@types/katex, @types/react)
    still resolves without an entry.
  - `noUncheckedSideEffectImports` defaults on, so diagram needs the same
    `declare module '*.css'` that app already had. The narrower
    '*.module.css' declaration still wins for CSS modules.
  - Symbol.dispose used to arrive implicitly via @types/node augmenting
    SymbolConstructor. Name the lib that actually owns it instead.

Emit was checked rather than assumed: 446 emitted files were compared against
a TS 5.9 baseline by re-printing both from their parsed ASTs. Three .js files
differ, all AST-identical (JSX children placed on the same line). Nineteen
.d.ts files pick a different React.memo overload -- NamedExoticComponent<P>
becomes MemoExoticComponent<(p: P) => ReactElement>, a strict refinement that
is assignable to what it replaces, and a 6.0 change rather than a 7.0 one.

Upgrading has one sharp edge worth knowing: a .tsbuildinfo written by 5.9
under the old config makes 7.0 report phantom errors (475 of them in
src/server) instead of invalidating. Delete stale build state before the
first build. A 6.0-authored buildinfo is read correctly. engine's `clean`
now removes its two buildinfo files, which it had been leaving behind.

Dropping @types/resize-observer-browser falls out of making `types` explicit:
lib.dom has declared ResizeObserver since 4.2, and a triple-slash reference
in Canvas.tsx was the only thing keeping the package alive. diagram compiles
clean without either.

The `types: ["jest"]` entries exist only because ts-jest type-checks tests
against each package's tsconfig; they go away with the move to Rstest.
Rstest is built on Rsbuild 2, so the app has to move first. Two of the three
breaking changes that touch us are silent -- the old keys are ignored rather
than rejected -- which makes them worth spelling out.

Rsbuild 2 bundles http-proxy-middleware 4, where `context` became `pathFilter`
and `logLevel` was dropped. An array-style proxy entry with no `pathFilter`
matches every request, so keeping `context` does not preserve the old behavior:
it proxies the entire SPA to the backend. Confirmed by running the dev server
both ways -- with `context`, GET / returns 504 from the dead backend instead of
index.html. `changeOrigin` now defaults to true; kept explicit.

`performance.chunkSplit` is deprecated in favor of a top-level `splitChunks`,
where `strategy: 'all-in-one'` becomes `splitChunks: false`. That only disables
the SplitChunksPlugin; the LimitChunkCountPlugin in the component config is
still what collapses the dynamic-import chunks the cross-origin embed contract
depends on. Both bundles come out with the same chunk layout and sizes as
Rsbuild 1, and sd-component.js still resolves its publicPath from
document.currentScript.

@rsbuild/core is now pure ESM. Our config and scripts stay CommonJS: Rsbuild 2
already requires Node 20.19+/22.12+, which is exactly where `require(esm)`
became available, so `require('@rsbuild/core')` keeps working. Converting the
build scripts to ESM is a larger change and buys nothing today.

Separately: `startDevServer()` has never taken a `port` option -- not in 1.x
either -- so `PORT=3111 pnpm start:frontend` silently bound 3000. Move the port
to `server.port`, where Rsbuild reads it, and drop the argument that was being
discarded. Verified the dev server now binds PORT and still routes /api, /auth,
/oauth, /logout, /render, /session and /download to the backend while every
other path falls through to the SPA.
ts-jest needs TypeScript's programmatic compiler API, which TypeScript 7 does
not ship (deferred to 7.1). Rather than pin a second TypeScript just for the
test runner, move to Rstest: it compiles with the same Rspack/swc toolchain the
app already bundles with, so the runner shares one dependency tree instead of
dragging in a parallel one. Net -260 packages from the lockfile; the only
jest-family package left is a transitive jest-worker. Test counts are unchanged
package for package: core 100, engine 442 + 1 skipped, server 139, app 99,
diagram 1500, serve-web 113.

Rstest keeps test globals off, so each test file imports the helpers it uses
from '@rstest/core'. That retires @types/jest and the shared eslint config's
`jest: 'readonly'` globals block. `jest.*` maps onto `rs.*` 1:1 except:

  - `jest.Mock<Return, Args>` / `jest.SpyInstance` become `Mock<Fn>` /
    `MockInstance`, whose type argument is the whole function signature rather
    than the return type. @types/jest typed jest.fn() loosely enough to hide
    argument mismatches: nine were hiding in serve-web's ws.test.ts, which had
    been passing `<void, [WsMessage]>` all along.
  - `jest.requireActual` is synchronous; `rs.importActual` is not, and Rstest
    rejects async mock factories outright. The replacement is the
    `import ... with { rstest: 'importActual' }` attribute, which hoists along
    with the factory. src/server cannot use it -- import attributes require an
    ES module target, and that program emits CommonJS while type-checking its
    own tests -- so static-config.test.ts uses `rs.mock('fs', { spy: true })`.
  - `jest.requireMock` has no synchronous form either; login.test.tsx imports
    the (already mocked) module namespace directly.

Rstest has no `@jest-environment` docblock. The 14 diagram tests that opted into
a Node environment are now an explicit `projects` entry: project-controller.ts
documents a "zero React, zero DOM" invariant that an ambient jsdom global would
quietly erode. The other 39 docblocks existed only to carry that pragma, so
their block-comment copyright headers return to the canonical line-comment form,
and check-copyright.py stops advertising a block form nothing uses.

Two Jest workarounds are deleted rather than ported. The wouter stub and its
moduleNameMapper existed because CommonJS Jest mishandled wouter's ESM-only
"exports"; rspack resolves it natively, which also retires the require.resolve()
dance guarding issue #523. The CSS-module Proxy stubs (which echoed each
property name back as its class name) give way to compiling the real stylesheets
with `output.cssModules.localIdentName: '[local]'`, so tests that query
`.eqnEditor` still match.

@testing-library/react self-registers `afterEach(cleanup)` only when `afterEach`
is a global, and @testing-library/dom's waitFor only pumps fake timers when a
global `jest` object exists (helpers.js gates on `typeof jest !== 'undefined'`,
then calls `jest.advanceTimersByTime`). Both are wired up explicitly in a
per-package tests/setup-testing-library.ts; the timer shim is inert under real
timers.

jsdom goes 26 -> 29, which implements PointerEvent. dialog.test.tsx asserted
that a bare pointerdown dismisses a Radix dialog -- true only because
@testing-library/dom fell back to a plain Event whose `button` was undefined.
Given a real PointerEvent (button 0), Radix waits for the matching click, as
browsers do, so the test now fires the full pointerdown/pointerup/click
sequence.

src/app/scripts/test.js was an orphaned create-react-app launcher that required
jest and that nothing invoked.

Test files remain un-type-checked: `isolatedModules` in tsconfig.base.json made
ts-jest transpile-only, so nothing is lost here, but the hole is now explicit
and tracked in #899 (55 latent errors, including a diagram test importing a
module that does not exist).
@codecov

codecov Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.00%. Comparing base (aebf890) to head (4f45a4b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #900   +/-   ##
=======================================
  Coverage   91.00%   91.00%           
=======================================
  Files         226      226           
  Lines      145803   145803           
=======================================
  Hits       132684   132684           
  Misses      13119    13119           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e2a00e612

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app/tests/app.test.tsx Outdated
type FetchImpl = (input: unknown, init?: { method?: string }) => Promise<Response>;

const fetchMock = rs.fn<FetchImpl>(async () => userResponse(401, {}));
(globalThis as unknown as { fetch: Mock }).fetch = fetchMock;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Install fetch before importing App under Rstest

In the Rstest/Rspack runner, static imports are evaluated before this top-level assignment runs. App.tsx constructs UserInfoSingleton and calls fetch('/api/user') during module import, so the import { App, InnerApp } from '../App' below observes the native/missing fetch instead of this mock, causing the app suite to fail or make an uncontrolled relative fetch. Load App with a dynamic import after installing fetchMock, or move the fetch stub into setup that runs before test modules are evaluated.

Useful? React with 👍 / 👎.

Comment thread src/diagram/rstest.config.mts Outdated
testEnvironment: 'jsdom',
include: ['tests/**/*.test.ts', 'tests/**/*.test.tsx'],
exclude: NODE_ENV_TESTS,
setupFiles: ['./tests/setup-testing-library.ts'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move TextEncoder polyfill into jsdom setup

Several jsdom tests still rely on Object.assign(globalThis, { TextEncoder, TextDecoder }) inside the test file before importing engine-backed modules such as ErrorDetails and StaticDiagram. Under Rstest's bundled ESM execution, those static imports run before the test body, so the engine import can execute in jsdom without TextEncoder and fail before the local polyfill statement runs. Add the polyfill to this setup file (or a second setup file) so it is installed before test modules load.

Useful? React with 👍 / 👎.

@claude

claude Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review

Reviewed the toolchain migration end-to-end: TypeScript 6/7 dual-install with the aliased @typescript/typescript6 compat layer + native tsc, Rsbuild 1→2 (including the two real behavior fixes for pathFilter and server.port), and Jest→Rstest across 100+ test files.

Findings

No blocking correctness or behavior issues found. Specifically verified:

  • Proxy pathFilter migration (src/app/config/rsbuild/shared.config.js:104) — the http-proxy-middleware v4 rename is correctly applied; the counterfactual (an array-form proxy entry with no pathFilter matching everything) is genuinely averted.
  • PORT env handling (shared.config.js:88) — moved from the (silently-dropped) startDevServer({port}) to server.port; the parseInt || 3000 fallback handles unset/invalid values sensibly.
  • splitChunks: false — top-level key may be inert in Rsbuild 2, but the parallel tools.rspack.optimization.splitChunks: false is what actually does the work, and LimitChunkCountPlugin({maxChunks: 1}) in the web-component config preserves the cross-origin embed contract.
  • Test setup shims (setup-testing-library.ts in app/diagram/serve-web) — the globalThis.jest = { advanceTimersByTime } bridge and afterEach(cleanup) registration correctly compensate for RTL's global-detection logic; inert under real timers as claimed.
  • rs.mock hoisting above textual import position (widespread) — works because ES-module import bindings are hoisted at module load.
  • Dialog pointer-sequence fix (src/diagram/tests/dialog.test.tsx:49) — jsdom 29 gaining real PointerEvent correctly exposes that the old bare-pointerdown assertion was a passing-for-the-wrong-reason case; the new full pointerDown/pointerUp/click sequence is the right fix.
  • Deleted wouter-stub.ts / CSS-module Proxy stubs / orphaned src/app/scripts/test.js — all correctly retired now that Rspack resolves ESM natively and cssModules.localIdentName: '[local]' produces real, queryable class names.
  • moduleResolution: "bundler" + module: "commonjs" in the per-package tsconfigs and the ./-prefixed relative paths targets — both TS7 requirements are correctly threaded.

Minor nits (not worth follow-up):

  • src/diagram/hosted-web-editor-core.ts:142 has "a a spy installed" (accidental double a) in a comment.
  • src/engine/tsconfig.browser.json:9 comment still says "Jest's globals are not needed" — could say "Rstest's" for accuracy, but the behavior it describes is unchanged.

Overall correctness verdict

Correct. The migration preserves test coverage package-for-package (2393 passed / 1 skipped), the two real behavior fixes it discovered along the way are load-bearing improvements, and every non-obvious choice (dual TypeScript install, node-env test split, rs.mock hoisting rules, importActual attribute, server's rs.mock('fs', { spy: true }) workaround) is documented at the call site and in docs/dev/typescript.md. Approve.

Rspack hoists ES imports above the module body, as the spec requires.
TypeScript's CommonJS emit did not -- it left `require()` calls in source
order -- so a `globalThis.fetch = ...` or a TextEncoder polyfill written
above an import genuinely ran before that import under ts-jest. Both
patterns survived the Rstest migration unchanged and both are now too late.

App.tsx constructs UserInfoSingleton at module scope, whose constructor
fetches /api/user. Since app.test.tsx's `fetchMock` is a const declared
after the hoisted imports, it was still in its temporal dead zone when
`../App` evaluated: the singleton reached the real undici fetch, which
rejected with "Failed to parse URL from /api/user". The suite stayed green
because the rejection is caught and reported as signed-out -- which is what
the tests expect anyway -- and Rstest buffers console output on passing
files, so the error was never printed. Move the stub into setup-fetch.ts,
which runs before the test module's import graph, and pin the invariant
with a test that the module-load request lands on the stub.

The diagram tests' TextEncoder/TextDecoder polyfill has the same defect,
but was inert rather than harmful: unlike jest's vm-isolated jsdom, Rstest's
jsdom environment leaves Node's globals in place, so the engine's
module-scope `new TextEncoder()` always found one. Rather than depend on
that, hoist the polyfill into a jsdom setup file and drop the 19 misplaced
copies.

Also fix a duplicated word and a stale Jest reference in two comments.
@bpowers

bpowers commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown

Automated review — no findings

Traced the migration end-to-end (rstest configs, mock rewrites across all packages, tsconfig updates for TS7's stricter defaults, Rsbuild 2 proxy context→pathFilter fix, PORT moved to server.port, jsdom 26→29 PointerEvent fix in dialog.test.tsx, static-config.test.ts { spy: true } switch, setup-fetch.ts/setup-testing-library.ts timing). Nothing rose to a discrete, actionable correctness bug.

Verdict: correct.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91c7f78154

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Rsbuild prefers tsconfig `paths` over `alias` by default, and those paths
// resolve @simlin/engine to the package directory (i.e. its built output).
// @simlin/core needs no entry: tsconfig `paths` already lands on its source.
aliasStrategy: 'prefer-alias' as const,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore core source aliases under prefer-alias

With aliasStrategy: 'prefer-alias', Rsbuild does not use tsconfig paths as a bundling fallback; it uses only the explicit aliases. Since this config no longer aliases @simlin/core/datamodel, @simlin/core/common, or @simlin/core/collections, diagram tests that import those modules now resolve through the package exports to built lib/lib.module output (or fail when it is absent) instead of the source files that the Jest config exercised. That can let tests pass against stale built core output and miss source changes; add the core aliases here or avoid prefer-alias for this project.

Useful? React with 👍 / 👎.

`resolve.aliasStrategy: 'prefer-alias'` does not rank `alias` above tsconfig
`paths` -- it turns tsconfig-paths resolution off. Rsbuild wires rspack's
`resolve.tsConfig` only under the default `prefer-tsconfig`. The diagram
config leaned on the opposite reading ("@simlin/core needs no entry: tsconfig
paths already lands on its source"), so all five core subpaths it imports
resolved through package.json "exports" to src/core/lib instead. The suite
stayed green only because the built output happened to be current; a stale
build would have passed just as quietly while ignoring core source changes.

Alias @simlin/core to source in diagram, where jest's moduleNameMapper did.
Use a prefix entry rather than jest's one-subpath-at-a-time list: jest mapped
datamodel/common/collections and silently left canonicalize and base64 on the
built output, and a prefix cannot rot that way as subpaths are added. Give
app the same treatment -- it had the identical gap for base64 -- and pin bare
`@simlin/core` to index.ts, since resolving the directory would follow the
package's "main" straight back to lib.

src/core and src/server keep aliasing to built lib on purpose, as they did
under jest; their suites depend on a prior build.
@bpowers

bpowers commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12d8e9ebe2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app/tests/new-project.test.tsx Outdated
Comment on lines +16 to +20
rs.mock('@simlin/engine', () => ({
Project: {
open: (...args: unknown[]) => open(...args),
openVensim: (...args: unknown[]) => openVensim(...args),
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Hoist shared mock functions with rs.hoisted

Rstest hoists rs.mock registrations above the module body, so this factory can run while resolving the static ../NewProject import before the const open / openVensim bindings on lines 13-14 have initialized. In this test file that makes the suite fail at module load with a TDZ ReferenceError instead of installing the engine mock; shared mocks referenced from a factory need to be created via rs.hoisted or moved inside the factory.

Useful? React with 👍 / 👎.

@claude

claude Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review verdict

Reviewed the toolchain migration (TypeScript 7 dual-package strategy, Rsbuild 1→2, Jest→Rstest) with an adversarial eye on the mechanical hot spots:

  • eslint.config.shared.js — the new baseConfig.languageOptions.parserOptions.project = options.project mutation reads scary at first but the old configs[configs.length - (options.react ? 3 : 2)] arithmetic landed on that same shared object in every branch, so it's a pre-existing shape (tracked in build: shared eslint config mutates module-level objects #895), not a regression.
  • Rsbuild proxy fix — context → pathFilter and PORT moving from startDevServer({port}) to server.port are correct; the counterfactuals in the PR description hold.
  • Rstest configs — the prefer-alias note is load-bearing and correctly applied everywhere. The @simlin/engine/internal/wasm$/backend-factory$/@simlin/engine$ ordering is right (exact matches precede the prefix).
  • Setup files (setup-fetch.ts, setup-testing-library.ts, setup-text-encoder.ts) — correctly placed to run before the module-under-test's imports evaluate. The waitFor shim wiring a globalThis.jest.advanceTimersByTime onto rstest is a nice catch.
  • dialog.test.tsx — the added click(document.body) after pointerdown/pointerup is the right shape for Radix under a real PointerEvent (jsdom 29). Test was "passing for the wrong reason" as documented.
  • Mock<T> signature-argument usage — correct throughout; the ws.test.ts change is fine either way.
  • TS7 tsconfig changes — baseUrl removal + ./-prefixed paths, moduleResolution: bundler, explicit types: [...], and esnext.disposable for Symbol.dispose are all applied consistently across the tsconfigs.
  • static-config.test.ts — the rs.mock('fs', { spy: true }) + rs.importActual pattern works; actualFs is only read inside it() bodies which run after the beforeAll populates it.
  • Scripts / docs — the deploy scripts and copyright checker only change comments; no logic drift.

One item I flagged internally but could not confirm without a live install: the main SPA's top-level splitChunks: false (src/app/config/rsbuild/rsbuild.config.js:42) relies on that being a valid Rsbuild 2 config key. If it's silently ignored, tools.rspack's splitChunks: config.optimization?.splitChunks would forward Rsbuild's default splitting and the main bundle would regress from single-chunk to multi-chunk. The web-component config is not exposed to this because its tools.rspack sets optimization.splitChunks: false directly. Worth a quick ls build/static/js/ sanity check after a prod build if not already verified.

Overall correctness: correct. No blocking issues found.

A rs.mock factory runs the first time the module under test imports the
mocked specifier. NewProject.tsx statically imports @simlin/engine and
@simlin/core/datamodel, so both factories run while the hoisted `../NewProject`
import is being evaluated -- before any statement in the test file's body.
The shared `open`/`openVensim`/`projectFromJson` mocks are declared in that
body, so at factory time they sit in their temporal dead zone.

The file avoided the crash by having each factory return an arrow that calls
the mock rather than naming it: capturing a binding is not reading it, and
the read is deferred to call time, long after the body has run. That works,
but it is load-bearing indirection that reads as gratuitous, it erases the
mocks' types behind `(...args: unknown[])`, and simplifying it to the obvious
`Project: { open, openVensim }` turns the file into a ReferenceError at module
load. Confirmed by doing exactly that: the suite fails to collect.

Create the shared mocks with rs.hoisted, which is lifted alongside the
rs.mock calls, so the factories can name them directly. Under jest none of
this arose: its CommonJS emit preserved source order, so the consts were
initialized before `require('../NewProject')` ran.
@bpowers

bpowers commented Jul 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Automated review

I reviewed the TypeScript 7 / Rsbuild 2 / Rstest migration and did not find any actionable bugs. The changes are extensively documented and each subtle behavior change (jsdom PointerEvent breakage of dialog test, pathFilter proxy rename, splitChunks: false top-level, rs.hoisted for mock closures, setup-file ordering for module-load stubs) is called out with rationale in code comments. Pre-existing defects in eslint.config.shared.js (shared baseConfig mutation) are acknowledged rather than newly introduced.

Spot checks that came up clean:

  • parseInt(process.env.PORT, 10) || 3000 in shared.config.js preserves the prior semantics from start.js.
  • rs.spyOn(globalWithFloat64Array, 'Float64Array').mockImplementation((arg) => new RealFloat64Array(arg)) in wasmgen.test.ts still supports new because the spy is a regular function and JavaScript honors an object return value from a constructor call.
  • The @simlin/engine$/@simlin/engine alias pair (exact + prefix) is standard rspack alias behavior and the $ exact match takes priority for the bare specifier.
  • rs.mock factories referencing React (imported normally) run during the mocked module's first import, which is after all top-level imports have been resolved, so React is defined.

Overall correctness verdict: Correct.

Review by Claude Opus 4.7.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 4f45a4b98a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@bpowers
bpowers merged commit 2d5c09a into main Jul 10, 2026
13 of 15 checks passed
@bpowers
bpowers deleted the typescript-7-migration branch July 10, 2026 03:42
bpowers added a commit that referenced this pull request Jul 12, 2026
The Jest-to-Rstest migration (2d5c09a, PR #900) converted every test
file that existed on main to import describe/it/expect from
@rstest/core, but rename-ops.test.ts was added on this branch after
the migration's snapshot, so the rebase left it as the one file still
using jest-style globals -- it failed to load under rstest in CI and
tripped eslint's no-undef locally. Also drops the stale
jest-environment docblock; the tests are pure functions of view data
and run in the default node environment like their siblings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server: @simlin/server Jest suite intermittently fails one test under parallel pre-commit load

1 participant