Skip to content

Build each TypeScript template's client in the template smoketest - #6711

Open
krisajenkins wants to merge 3 commits into
kris/init-drop-gen-bindings-scriptfrom
kris/template-client-builds
Open

krisajenkins wants to merge 3 commits into
kris/init-drop-gen-bindings-scriptfrom
kris/template-client-builds

Conversation

@krisajenkins

Copy link
Copy Markdown
Contributor

Stacked on #6709. Review only the last three commits.

Description of Changes

The template smoketest now builds each TypeScript template's client, so a broken client template fails CI. It also installs the local SDK the way a real install does.

Until now, the TypeScript template smoketest published the server module, ran pnpm install for the client, and stopped. The type-check was commented out:

// TODO: some templates don't pass tsc yet, re-enable once they're fixed.
// run_pnpm(&["exec", "tsc", "--noEmit"], project_path)?;

So no client code was ever compiled. An SDK change that broke a template's App.vue or App.svelte stayed green in CI, and users found the breakage on their first npm run build. Plain tsc wouldn't have caught much anyway, because it doesn't understand .vue or .svelte files.

This PR has three commits:

  • Build each TypeScript template's client. The test now runs the template's own build script (pnpm run --if-present build). That script uses the framework's own checker: tsc -b, vue-tsc, svelte-check, ng build or next build. Templates that fail today are listed in TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES, with a reason for each, and their builds are skipped with a log line. A unit test fails if an entry stops naming a real TypeScript template.

  • Install the local SDK as an injected dependency. vue-ts looked broken, because vue-tsc rejected App.vue. The template was fine; the smoketest's install was not. pnpm symlinks a local directory dependency, so the SDK resolved its vue peer from the monorepo's node_modules. The project then had two copies of Vue's types, and Vue brands Ref with a unique symbol. The smoketest now sets dependenciesMeta.spacetimedb.injected, so the SDK is copied into the project and resolves its peers there, as a registry install would.

    Injecting the SDK exposed an existing race. Every TypeScript test rebuilt the SDK, so one test's build cleared dist/ while another test was copying it. CI runs its partitions with -j 1, so it never saw the race. The smoketest runner now builds the SDK once before any test starts, for both local runs and CI's run-archive. It then sets SPACETIME_SMOKETEST_TS_SDK_PREBUILT so the tests skip the rebuild. A test run directly with cargo test still builds the SDK itself.

  • Check tanstack-ts again. Master's dependency update moved it to Vite 8, which fixed its build, so it comes off the known-failures list. Only bun-ts remains: pnpm doesn't run the bun package's postinstall, so bun build can't start.

API and ABI breaking changes

None.

Rollback safety impact

n/a

Expected complexity level and risk

  1. This changes only test infrastructure. The risk is CI time and flakiness: every TypeScript template now runs a full client build, and the smoketest runner gains a pnpm build step before any test runs.

Testing

Added one unit test:

  • Every known-failure entry names a real TypeScript template.

All 19 TypeScript template smoketests were run one at a time, as CI runs them (-j 1), with tanstack-ts still on the list. All passed, and vue-ts now builds its client. Before the injected-dependency fix, building vue-ts failed its smoketest with vue-tsc's errors. tanstack-ts was checked by running pnpm run build in the repo after the Vite 8 update. That build succeeds, but its smoketest has not been run with the build enabled.

Running the whole templates:: suite at the runner's default -j 16 (without the C++ and C# templates, which can't run locally) passed 23 tests. Before the runner prebuilt the SDK, six TypeScript templates failed this way.

Suppose someone changes the TypeScript SDK in a way that breaks a client
template: a hook's return type changes, say, so the Vue template's App.vue
no longer type-checks. CI runs a smoketest for every template, so surely
that template's test fails? It doesn't. For TypeScript templates the test
publishes the server module, runs 'pnpm install' for the client, and
stops:

    // TODO: some templates don't pass tsc yet, re-enable once they're fixed.
    // run_pnpm(&["exec", "tsc", "--noEmit"], project_path)?;

So no client code is ever compiled. That isn't hypothetical: building
every TypeScript template the way the smoketest scaffolds it shows that
vue-ts already doesn't type-check (vue-tsc rejects three expressions in
App.vue), tanstack-ts's build can't find an entry module, and bun-ts's
build can't start. All three are green in CI today. Users meet these on
their first 'npm run build'.

The commented-out tsc call wouldn't have caught all of them anyway. Plain
tsc doesn't understand .vue or .svelte files, so it can't check the
frameworks where type errors hide in templates.

The test now runs each template's own build script ('pnpm run
--if-present build'). That uses whatever checker the template's
framework uses (tsc -b, vue-tsc, svelte-check, ng build, next build), and
--if-present covers deno-ts, which has no build script. The three
templates that fail today are listed in TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES
with the reason for each. Their builds are skipped, with a log line, until
someone fixes them and deletes the entry. A new unit test fails if an
entry no longer names a TypeScript template, so the list can't quietly
outlive a rename.

Checked by scaffolding all 19 TypeScript templates with the CLI, pointing
them at the local SDK and running their builds: 15 build, deno-ts has no
build script, and the three listed fail. Then, with the real smoketests:
svelte-ts passes with its build running; vue-ts passes with its build
skipped; deno-ts passes via --if-present; and with vue-ts removed from the
list its smoketest fails, quoting vue-tsc's errors.
…ncy.

The template smoketest now builds each TypeScript template's client, and
vue-ts was on its known-failures list because vue-tsc rejected App.vue:

    src/App.vue(52,29): error TS2339: Property 'length' does not exist on type 'Readonly<Ref<readonly { readonly name: string; }[], ...>>'.

That reads like a bug in the template, or in the Vue bindings' useTable
types. If so, every Vue user would hit it on their first build. They
don't: the same template type-checks cleanly inside the repo, and the
error only appears in the project the smoketest scaffolds.

The difference is how that project gets the SDK. The smoketest points
'spacetimedb' at crates/bindings-typescript, and pnpm symlinks a local
directory dependency. The SDK's type declarations then resolve their
optional framework peers from the monorepo's node_modules, so in the
scaffolded vue-ts project the SDK sees vue 3.5.26 while the app has its
own fresh vue 3.5.45. Vue brands Ref with a unique symbol, so a Ref
declared against one copy isn't recognised as a Ref by the other, and
vue-tsc can't unwrap 'people' in the template. A user installing the
published package gets one copy of vue, resolved from their project.

So the smoketest wasn't testing what users get. It now also sets
dependenciesMeta.spacetimedb.injected, which makes pnpm copy the SDK into
the project and resolve its peers there, as a registry install would. The
helper comment explains why. vue-ts comes off the known-failures list.

Injecting the SDK also turns an old race into a reliable failure. Every
TypeScript test called build_typescript_sdk(), which runs pnpm install
and pnpm build in crates/bindings-typescript, and the local runner runs
16 tests at once. One test's build clears dist while another test's
pnpm install is copying it, so a parallel run fails at random: pnpm
reports missing files under dist, or a template can't import
spacetimedb/server. With a symlink the race was easy to miss, because a
project only read dist once the build had finished. CI's partitions run
with -j 1, so CI never saw it.

So the runner now builds the SDK once, before any test starts, both for
a local run and for CI's run-archive, and sets
SPACETIME_SMOKETEST_TS_SDK_PREBUILT for the tests, which makes
build_typescript_sdk() return early. templates.rs drops its own copy of
that build and uses the library's. A test run directly with cargo test
still builds the SDK itself, as before.

- The runner finds pnpm with which, so Windows resolves pnpm.cmd.
- It builds relative to the current directory rather than the library's
  workspace_root(), which is fixed at compile time, because CI runs the
  runner in a different job from the one that built it.

Checked with the template smoketests for all 19 TypeScript templates, one
at a time as CI runs them (-j 1): all pass, vue-ts now builds its client,
and only bun-ts and tanstack-ts are still skipped. With the runner's
default of -j 16, the whole templates:: suite (less the C++ and C#
templates, which can't run on this machine) also passes: 23 tests in
69s, where before the fix six TypeScript templates failed.
…st again.

The template smoketest builds each TypeScript template's client, but it has
been skipping tanstack-ts as a known failure:

    ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"),

That failure came from the template asking for Vite 7 while
@tanstack/react-start 1.169.0 and later need Vite 8. On Vite 7, TanStack
Start's plugin doesn't register its build environments, so Vite falls back
to looking for an index.html the template was never meant to have. Master's
dependency update (25567d1) has since moved the template to vite ^8.3.8,
@vitejs/plugin-react ^6.3.0 and react-start ^1.169.7, which fixes the build.
But nothing told the smoketest, so it would go on skipping a build that now
works, and a future regression would go unnoticed.

This removes tanstack-ts from TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES, leaving
only bun-ts.

Verified: in-repo, `pnpm run build` in templates/tanstack-ts succeeds on
Vite 8.
@krisajenkins
krisajenkins force-pushed the kris/template-client-builds branch from 7952591 to 15119a6 Compare November 26, 2026 16:08
@krisajenkins
krisajenkins force-pushed the kris/init-drop-gen-bindings-script branch from 9723c25 to 30d0f13 Compare November 26, 2026 16:08

This branch has not been deployed

No deployments
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.

2 participants