From 037bf8cdb0c59ba7002c0d8237c3efbb7dc6d209 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 12:00:10 +0000 Subject: [PATCH 1/3] Build each TypeScript template's client in the template smoketests. 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. --- crates/smoketests/tests/cluster/templates.rs | 53 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/crates/smoketests/tests/cluster/templates.rs b/crates/smoketests/tests/cluster/templates.rs index 8bc30631734..7c344f76b8a 100644 --- a/crates/smoketests/tests/cluster/templates.rs +++ b/crates/smoketests/tests/cluster/templates.rs @@ -815,7 +815,7 @@ fn test_rust_template(test: &Smoketest, template: &Template, project_path: &Path Ok(()) } -/// Publishes a TypeScript server module and verifies the TypeScript client type-checks. +/// Publishes a TypeScript server module and verifies the TypeScript client builds. fn test_typescript_template(test: &Smoketest, template: &Template, project_path: &Path) -> Result<()> { // Server let server_path = project_path.join("spacetimedb"); @@ -840,18 +840,63 @@ fn test_typescript_template(test: &Smoketest, template: &Template, project_path: })?; let _ = test.spacetime(&["delete", "--server", &test.server_url, "--yes", &domain]); - // Client type-check (only if there's a client package.json in the project root) + // Client build (only if there's a client package.json in the project root) let client_package_json = project_path.join("package.json"); if client_package_json.exists() { setup_typescript_sdk_in_package_json(&client_package_json)?; run_pnpm(&["install"], project_path)?; - // TODO: some templates don't pass tsc yet, re-enable once they're fixed. - // run_pnpm(&["exec", "tsc", "--noEmit"], project_path)?; + if let Some(reason) = typescript_client_build_known_failure(&template.id) { + eprintln!( + "[TEMPLATES] Skipping client build for {}: known failure: {reason}", + template.id + ); + } else { + // Each template's own `build` script, which type-checks where the + // framework's tooling does (tsc, vue-tsc, svelte-check, ...). + run_pnpm(&["run", "--if-present", "build"], project_path) + .with_context(|| format!("Client build failed for template {}", template.id))?; + } } Ok(()) } +/// TypeScript templates whose client `build` script currently fails, and why. +/// Remove an entry as soon as its template is fixed, so the build is checked again. +const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[ + ( + "bun-ts", + "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", + ), + ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), + ( + "vue-ts", + "vue-tsc doesn't unwrap the `Readonly>` that useTable returns in App.vue", + ), +]; + +fn typescript_client_build_known_failure(template_id: &str) -> Option<&'static str> { + TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES + .iter() + .find(|(id, _)| *id == template_id) + .map(|(_, reason)| *reason) +} + +#[test] +fn test_typescript_client_build_known_failures_name_real_templates() { + let typescript_templates: Vec = get_templates() + .into_iter() + .filter(|template| template.server_lang.as_deref() == Some("typescript")) + .map(|template| template.id) + .collect(); + for (id, _) in TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES { + assert!( + typescript_templates.iter().any(|template| template == id), + "known-failure entry {id} is not a TypeScript template; remove it" + ); + } +} + /// Publishes a C# server module and verifies the C# client builds. fn test_csharp_template(test: &Smoketest, template: &Template) -> Result<()> { for dotnet_version in ["8", "10"] { From 3fc0f250ca2593d38bc1d2db1fe534ce5030de49 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 12:31:38 +0000 Subject: [PATCH 2/3] Install the local SDK into template smoketests as an injected dependency. 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>'. 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. --- Cargo.lock | 1 + crates/smoketests/src/lib.rs | 19 +++++- crates/smoketests/tests/cluster/templates.rs | 56 +++++++++++----- tools/ci/commands/smoketests/Cargo.toml | 1 + tools/ci/commands/smoketests/src/main.rs | 67 ++++++++++++++++++-- 5 files changed, 123 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 879e940a32a..a8252003541 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1180,6 +1180,7 @@ dependencies = [ "duct", "spacetimedb-guard", "tempfile", + "which 8.0.0", ] [[package]] diff --git a/crates/smoketests/src/lib.rs b/crates/smoketests/src/lib.rs index 2b9285dcab7..cb56a6513d3 100644 --- a/crates/smoketests/src/lib.rs +++ b/crates/smoketests/src/lib.rs @@ -410,8 +410,25 @@ pub fn pnpm(args: &[&str], cwd: &Path) -> Result { Ok(String::from_utf8_lossy(&output.stdout).to_string()) } -/// Builds the local TypeScript bindings package. +/// Set by the smoketest runner once it has built the TypeScript SDK, so that +/// tests skip rebuilding it. +pub const TYPESCRIPT_SDK_PREBUILT_ENV: &str = "SPACETIME_SMOKETEST_TS_SDK_PREBUILT"; + +/// Builds the local TypeScript bindings package, unless the runner has already +/// built it. +/// +/// Tests run in parallel and share one copy of the SDK. Rebuilding it clears +/// `dist/` while other tests may be copying it into their projects, so the +/// runner builds it once up front, and tests only build it when run directly. pub fn build_typescript_sdk() -> Result<()> { + if std::env::var_os(TYPESCRIPT_SDK_PREBUILT_ENV).is_some() { + return Ok(()); + } + prebuild_typescript_sdk() +} + +/// Builds the local TypeScript bindings package unconditionally. +pub fn prebuild_typescript_sdk() -> Result<()> { let workspace = workspace_root(); let ts_bindings = workspace.join("crates/bindings-typescript"); pnpm(&["--filter", "spacetimedb", "install"], &ts_bindings)?; diff --git a/crates/smoketests/tests/cluster/templates.rs b/crates/smoketests/tests/cluster/templates.rs index 7c344f76b8a..647763df5b5 100644 --- a/crates/smoketests/tests/cluster/templates.rs +++ b/crates/smoketests/tests/cluster/templates.rs @@ -12,7 +12,7 @@ use anyhow::{bail, Context, Result}; use regex::Regex; use serde_json::Value; -use spacetimedb_smoketests::{pnpm, random_string, workspace_root, Smoketest}; +use spacetimedb_smoketests::{build_typescript_sdk, pnpm, random_string, workspace_root, Smoketest}; use std::env; use std::fs; use std::path::{Path, PathBuf}; @@ -590,22 +590,12 @@ fn pin_csharp_client_sdk_package_version(project_path: &Path) -> Result<()> { Ok(()) } -/// Builds the TypeScript SDK (`crates/bindings-typescript`). -/// -/// Should be called once before testing any TypeScript templates. -fn build_typescript_sdk() -> Result<()> { - let sdk_path = workspace_root().join("crates/bindings-typescript"); - eprintln!("[TEMPLATES] Building TypeScript SDK at {:?}", sdk_path); - run_pnpm(&["--filter", "spacetimedb", "install"], &sdk_path)?; - run_pnpm(&["build"], &sdk_path)?; - Ok(()) -} - /// Points the `spacetimedb` entry in `package.json` at the local TypeScript /// SDK and removes the template's lockfile so pnpm re-resolves dependencies. fn setup_typescript_sdk_in_package_json(package_json_path: &Path) -> Result<()> { let sdk_path = workspace_root().join("crates/bindings-typescript"); update_package_json_dependency(package_json_path, "spacetimedb", &sdk_path)?; + inject_package_json_dependency(package_json_path, "spacetimedb")?; // Remove the template's lockfile; the dependency changed. let lockfile = package_json_path.parent().unwrap().join("pnpm-lock.yaml"); @@ -615,6 +605,44 @@ fn setup_typescript_sdk_in_package_json(package_json_path: &Path) -> Result<()> Ok(()) } +/// Marks a local-path dependency as injected (`dependenciesMeta..injected`). +/// +/// By default pnpm symlinks a local directory dependency, so the SDK resolves +/// its own imports, including the type declarations of its optional framework +/// peers (vue, react, svelte, ...), from the monorepo's `node_modules` rather +/// than the project's. The project then sees two copies of, for example, Vue's +/// types, and Vue brands `Ref` with a `unique symbol`, so a `Ref` from one copy +/// isn't recognised by the other. Injecting copies the SDK into the project and +/// resolves its peers there, as installing the published package would. +fn inject_package_json_dependency(package_json_path: &Path, package_name: &str) -> Result<()> { + let content = + fs::read_to_string(package_json_path).with_context(|| format!("Failed to read {:?}", package_json_path))?; + let mut data: Value = + serde_json::from_str(&content).with_context(|| format!("Failed to parse {:?}", package_json_path))?; + + let has_dependency = data + .get("dependencies") + .is_some_and(|deps| deps.get(package_name).is_some()); + if !has_dependency { + return Ok(()); + } + let Some(package) = data.as_object_mut() else { + bail!("{:?} is not a JSON object", package_json_path); + }; + let meta = package + .entry("dependenciesMeta") + .or_insert_with(|| Value::Object(Default::default())); + let Some(meta) = meta.as_object_mut() else { + bail!("dependenciesMeta in {:?} is not a JSON object", package_json_path); + }; + meta.insert(package_name.to_string(), serde_json::json!({ "injected": true })); + + let new_content = + serde_json::to_string_pretty(&data).with_context(|| format!("Failed to serialize {:?}", package_json_path))?; + fs::write(package_json_path, new_content).with_context(|| format!("Failed to write {:?}", package_json_path))?; + Ok(()) +} + /// Rewires the Rust server module's `spacetimedb` dependency to the local /// `crates/bindings` path. /// @@ -869,10 +897,6 @@ const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[ "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", ), ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), - ( - "vue-ts", - "vue-tsc doesn't unwrap the `Readonly>` that useTable returns in App.vue", - ), ]; fn typescript_client_build_known_failure(template_id: &str) -> Option<&'static str> { diff --git a/tools/ci/commands/smoketests/Cargo.toml b/tools/ci/commands/smoketests/Cargo.toml index f161fe64586..7f0b5c2d1a2 100644 --- a/tools/ci/commands/smoketests/Cargo.toml +++ b/tools/ci/commands/smoketests/Cargo.toml @@ -9,4 +9,5 @@ duct.workspace = true clap.workspace = true tempfile.workspace = true spacetimedb-guard.workspace = true +which = "8.0.0" ci-common = { path = "../../common" } diff --git a/tools/ci/commands/smoketests/src/main.rs b/tools/ci/commands/smoketests/src/main.rs index 869a75532d2..a6f42e9e5dd 100644 --- a/tools/ci/commands/smoketests/src/main.rs +++ b/tools/ci/commands/smoketests/src/main.rs @@ -193,6 +193,37 @@ fn build_precompiled_modules() -> Result<()> { Ok(()) } +/// Tells test processes the TypeScript SDK is already built. Must match +/// `spacetimedb_smoketests::TYPESCRIPT_SDK_PREBUILT_ENV`. +const TYPESCRIPT_SDK_PREBUILT_ENV: &str = "SPACETIME_SMOKETEST_TS_SDK_PREBUILT"; + +/// Builds the TypeScript SDK (`crates/bindings-typescript`) that the TypeScript +/// smoketests install into their projects. +/// +/// Tests run in parallel and share this one copy of the SDK. If each test built +/// it, one test's build would clear `dist/` while another was copying it into +/// its project. Returns whether the SDK was built; without pnpm the TypeScript +/// tests skip themselves, so there is nothing to build. +fn build_typescript_sdk(workspace_root: &Path) -> Result { + let Ok(pnpm) = which::which("pnpm") else { + eprintln!("Skipping TypeScript SDK build (pnpm not found).\n"); + return Ok(false); + }; + let sdk_dir = workspace_root.join("crates/bindings-typescript"); + + eprintln!("Building TypeScript SDK..."); + for args in [&["--filter", "spacetimedb", "install"][..], &["build"]] { + let status = Command::new(&pnpm).args(args).current_dir(&sdk_dir).status()?; + ensure!( + status.success(), + "Failed to build TypeScript SDK: pnpm {}", + args.join(" ") + ); + } + eprintln!("TypeScript SDK built.\n"); + Ok(true) +} + fn archive_smoketests(archive_file: &Path, suite: SmoketestSuite) -> Result<()> { build_precompiled_modules()?; @@ -220,9 +251,10 @@ fn run_smoketest_archive(archive_file: &Path, args: Vec) -> Result<()> { let cli_path = ensure_binaries_built(); let base_config_dir = prepare_base_config(&cli_path, None, None)?; let base_config_path = base_config_dir.path().join("config.toml"); + let typescript_sdk_prebuilt = build_typescript_sdk(&workspace_root)?; let mut cmd = Command::new("cargo"); - set_env(&mut cmd, None, true, false, &base_config_path); + set_env(&mut cmd, None, true, false, &base_config_path, typescript_sdk_prebuilt); cmd.args(["nextest", "run", "--archive-file"]) .arg(archive_file) .args(["--workspace-remap"]) @@ -266,6 +298,9 @@ fn run_smoketest( // 2. Build pre-compiled modules (this also warms the WASM dependency cache) build_precompiled_modules()?; + // 3. Build the TypeScript SDK once, rather than in every test that uses it + let typescript_sdk_prebuilt = build_typescript_sdk(&env::current_dir()?)?; + let cli_path = ensure_binaries_built(); let base_config_dir = prepare_base_config(&cli_path, server.as_deref(), auth_host)?; let base_config_path = base_config_dir.path().join("config.toml"); @@ -287,7 +322,14 @@ fn run_smoketest( let mut cmd = if use_nextest { eprintln!("Running smoketests with cargo nextest...\n"); let mut cmd = Command::new("cargo"); - set_env(&mut cmd, server, dotnet, auth_host.is_some(), &base_config_path); + set_env( + &mut cmd, + server, + dotnet, + auth_host.is_some(), + &base_config_path, + typescript_sdk_prebuilt, + ); cmd.args(["nextest", "run", "--release", "-p", "spacetimedb-smoketests"]) .args(suite.cargo_args()) .arg("--no-fail-fast"); @@ -304,7 +346,14 @@ fn run_smoketest( } else { eprintln!("Running smoketests with cargo test...\n"); let mut cmd = Command::new("cargo"); - set_env(&mut cmd, server, dotnet, auth_host.is_some(), &base_config_path); + set_env( + &mut cmd, + server, + dotnet, + auth_host.is_some(), + &base_config_path, + typescript_sdk_prebuilt, + ); cmd.args(["test", "--release", "-p", "spacetimedb-smoketests"]) .args(suite.cargo_args()); cmd @@ -385,7 +434,17 @@ fn prepare_base_config(cli_path: &Path, server: Option<&str>, auth_host: Option< Ok(temp_dir) } -fn set_env(cmd: &mut Command, server: Option, dotnet: bool, auth_host: bool, base_config_path: &Path) { +fn set_env( + cmd: &mut Command, + server: Option, + dotnet: bool, + auth_host: bool, + base_config_path: &Path, + typescript_sdk_prebuilt: bool, +) { + if typescript_sdk_prebuilt { + cmd.env(TYPESCRIPT_SDK_PREBUILT_ENV, "1"); + } if let Some(ref server_url) = server { cmd.env("SPACETIME_REMOTE_SERVER", server_url); } From 15119a64b503bd97b973876cf42aedc5534f91af Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 14:25:31 +0000 Subject: [PATCH 3/3] Check the tanstack-ts template's client build in the template smoketest 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 (25567d1961) 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. --- crates/smoketests/tests/cluster/templates.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/smoketests/tests/cluster/templates.rs b/crates/smoketests/tests/cluster/templates.rs index 647763df5b5..f2f9c8522d9 100644 --- a/crates/smoketests/tests/cluster/templates.rs +++ b/crates/smoketests/tests/cluster/templates.rs @@ -891,13 +891,10 @@ fn test_typescript_template(test: &Smoketest, template: &Template, project_path: /// TypeScript templates whose client `build` script currently fails, and why. /// Remove an entry as soon as its template is fixed, so the build is checked again. -const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[ - ( - "bun-ts", - "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", - ), - ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), -]; +const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[( + "bun-ts", + "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", +)]; fn typescript_client_build_known_failure(template_id: &str) -> Option<&'static str> { TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES