GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — C# module unit testing by lisandroct · Pull Request #6501 · clockworklabs/SpacetimeDB

Conversation

@lisandroct

@lisandroct lisandroct commented Nov 5, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Description of Changes

Depends on: #6499 and #6500

Adds unit testing for C# modules. Tests call reducers, procedures, views and typed queries directly, in-process, against the real datastore.

using var test = ModuleTestContext.Create(typeof(Module).Assembly);
test.Clock.Set(new Timestamp(1_000_000));
test.WithReducerTx(TestAuth.Internal(), ctx => Module.SendMessage(ctx, "Hello!"));
Assert.Equal("Hello!", Assert.Single(test.Db.Message.Iter()).Text);
  • New SpacetimeDB.Testing NuGet package (only .NET 10).

  • New Rust crate crates/test-datastore-ffi. A cdylib (publish = false) that exposes test-datastore through a versioned C ABI. Important: this was 100% implemented by LLMs.

  • Changes to Runtime to . The net10 package now contains two assemblies:

    • a managed assembly in lib/net10.0, used for compiling and testing;
    • the WASM assembly in runtimes/wasi-wasm/lib/net10.0, which spacetime build selects.

    In the managed build, table and index handles go through the fixture's transaction. A handle used after its transaction or fixture has ended throws.

    • Package validation compares the public API of the two assemblies.
    • HTTP request validation is now shared between them, with no behavior change in WASM.
  • Codegen emits the same WASM output when SPACETIMEDB_WASM_AOT is defined (spacetime publish and spacetime build). When managed (test environment) it generates no module of its own, instead it adds a global using for the root module's namespace.

  • Adds module testing to the chat-console-cs template.

  • Updates spacetime init to copy the test package from a module only for .NET 10 and sets the SpacetimeDB.Testing version to the Runtime version.

  • Updates documentation.

  • CI and release (this were also fully implemented by an LLM):

    • A new reusable csharp-testing.yml workflow builds the native bridge and packs the packages.
    • Release publishes SpacetimeDB.Testing from the same tested package set as SpacetimeDB.Runtime and SpacetimeDB.BSATN.Runtime.

Important note: test-datastore-ffi was 100% implemented by LLMs.

API and ABI breaking changes

No breaking changes. All the new stuff affects testing only.

Rollback safety impact

n/a.

Expected complexity level and risk

Possibly a 4/5.

  • Runtime now has both managed and WASM builds selected by #if. A mistake in a conditional block could change WASM output, and the managed-only tests wouldn't notice. It's not the most robust thing in the world. If it starts becoming a problem or a pain to maintain, I'll have to think of something better.
  • The FFI layer handles buffer ownership, handle lifetimes across finalizers, and a worker thread per datastore.
  • CI and release. The release now waits on a three-platform native build matrix (Linux ARM, Linux x86 and Windows x86).

Testing

  • All new tests are passing
    These cover the new Testing project, the release and packaging, the new test-datastore-ffi and more...
  • Old tests are still passing

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lisandroct
lisandroct requested review from bfops, cloutiertyler, jdetter and rekhoff as code owners November 5, 2026 20:48
@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from 8d6a5eb to 756a2e3 Compare November 6, 2026 14:27
@lisandroct
lisandroct marked this pull request as draft November 6, 2026 15:03
@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from 6e02c8c to 1fe54be Compare November 9, 2026 15:47
@lisandroct
lisandroct marked this pull request as ready for review November 9, 2026 19:48
@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from f7dab74 to c73a019 Compare November 19, 2026 11:31
@lisandroct
lisandroct requested a review from JasonAtClockwork November 19, 2026 16:23
JasonAtClockwork
JasonAtClockwork requested changes Nov 19, 2026
View reviewed changes

@JasonAtClockwork JasonAtClockwork left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I haven't completed a full review but found something important enough to reach out on straight-away. It looks like we have a regression for sub-modules with this change because they are not getting built with the wasm flag so they're becoming managed and then fail during publish.

I had AI whip up a quick small repro to keep it small to describe:


Repro. This is the docs example, inside the project spacetime init --lang csharp creates for .NET 10. Pack the PR's packages into a local feed first:

dotnet pack crates/bindings-csharp/BSATN.Runtime -c Release -p:Version=2.16.0-pr -o feed
dotnet pack crates/bindings-csharp/Runtime       -c Release -p:Version=2.16.0-pr -o feed
NuGet.config                      add `feed` as a package source
spacetimedb/
  StdbModule.csproj               from `spacetime init`, plus the docs' ProjectReference
  Lib.cs
  libraries/AuthLib/
    AuthLib.csproj
    Lib.cs

Files

spacetimedb/StdbModule.csproj: spacetime init output with SpacetimeDB.Runtime at 2.16.0-pr, plus the ItemGroup from the docs.

<ItemGroup>
  <ProjectReference Include="libraries/AuthLib/AuthLib.csproj" />
  <!-- Prevent the root project from also compiling the library's source. -->
  <Compile Remove="libraries/**/*.cs" />
</ItemGroup>

spacetimedb/Lib.cs

using SpacetimeDB;

[assembly: Namespace(typeof(AuthLib.Marker), Accessor = "MyAuth", Name = "auth_data")]

public static partial class Module
{
    [Reducer]
    public static void AddAuthUser(ReducerContext ctx, uint id)
    {
        AuthLib.Functions.Add(ctx.As.MyAuth, id);
        Log.Info($"Auth users: {AuthLib.Functions.Count(ctx.As.MyAuth)}");
    }
}

spacetimedb/libraries/AuthLib/AuthLib.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="SpacetimeDB.Runtime" Version="2.16.0-pr" />
  </ItemGroup>
</Project>

spacetimedb/libraries/AuthLib/Lib.cs

using SpacetimeDB;

namespace AuthLib;

public class Marker { }

[Table(Accessor = "User", Name = "auth_users", Public = true)]
public partial struct User
{
    [PrimaryKey]
    public uint Id;
    public uint Score;
}

public static partial class Functions
{
    public static void Insert(ReducerContext ctx, uint id) =>
        ctx.Db.User.Insert(new User { Id = id, Score = 42 });

    public static ulong Count(ReducerContext ctx) => ctx.Db.User.Count;

    [Reducer]
    public static void Add(ReducerContext ctx, uint id) => Insert(ctx, id);
}

Result

$ spacetime publish -p spacetimedb submodule-docs
...
Build finished successfully.
Error: Local module schema inspection failed:
Error: wasm trap while calling "__preinit__10_init_csharp"
   ...
   9: S_P_CoreLib_Internal_Runtime_CompilerHelpers_ThrowHelpers__ThrowTypeLoadException
  10: StdbModule.wasm!AuthLib_ModuleRegistration__Register
  11: StdbModule_ModuleRegistration__RegisterModule

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lisandroct
lisandroct requested a review from JasonAtClockwork November 20, 2026 13:23
@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from 79e41d0 to 7f18777 Compare November 20, 2026 13:33
JasonAtClockwork
JasonAtClockwork reviewed Nov 20, 2026
View reviewed changes
Comment thread crates/bindings-csharp/Testing/ModuleTestContext.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from 5547a26 to 3c8728c Compare November 20, 2026 22:22
@lisandroct
lisandroct requested a review from JasonAtClockwork November 21, 2026 04:46
JasonAtClockwork
JasonAtClockwork approved these changes Nov 23, 2026
View reviewed changes

@JasonAtClockwork JasonAtClockwork left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great! Submodules and nested submodules work and I see nothing else missing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cloutiertyler
cloutiertyler reviewed Nov 24, 2026
View reviewed changes
Comment thread .github/workflows/csharp-testing.yml Resolved

Uh oh!

There was an error while loading. Please reload this page.

cloutiertyler
cloutiertyler reviewed Nov 24, 2026
View reviewed changes
Comment thread .github/workflows/csharp-testing.yml Resolved

Uh oh!

There was an error while loading. Please reload this page.

github-advanced-security[bot]
github-advanced-security Bot found potential problems Nov 24, 2026
View reviewed changes
Comment thread .github/workflows/csharp-testing.yml Dismissed

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .github/workflows/csharp-testing.yml Dismissed

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .github/workflows/csharp-testing.yml Dismissed

Uh oh!

There was an error while loading. Please reload this page.

cloutiertyler
cloutiertyler approved these changes Nov 24, 2026
View reviewed changes

@cloutiertyler cloutiertyler left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Code owned files now look good to me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from 5fafea0 to 2fec249 Compare November 24, 2026 17:08
lisandroct and others added 8 commits November 24, 2026 15:04
@lisandroct @claude
Add native unit testing for C# modules
8f49be9
C# modules can now be unit tested natively. The new SpacetimeDB.Testing
package runs reducers, procedures and views against a native test
datastore through the spacetimedb-test-datastore-ffi C ABI.

Includes codegen and runtime support, the Testing library and its tests,
templates, docs, CI packaging and release flow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lisandroct
Fix release workflow, testing version, WASM snapshots and allocations
857a95b
@lisandroct
Rename TestContext to ModuleTestContext and simplify API
b0dc50c
@lisandroct @claude
Bound each row when decoding native row snapshots
e9e215e
Decode each row from a slice of its declared length (FramedRows), so
malformed results always throw InvalidDataException. Used by RunQuery
and the managed TableAccessor.Iter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lisandroct @claude
Report the original error after a native worker stops
3d1f733
After an internal error stops the native worker, later calls report
INTERNAL_ERROR with the original message (including the panic message)
instead of DATASTORE_CLOSED, so C# no longer reports a panic as a
disposed datastore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lisandroct @claude
Share HTTP request validation between WASM and managed builds
c5e6eba
HttpClient.Send validates the request and clamps its timeout the same
way in both builds, before the managed transaction check, matching WASM.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lisandroct @claude
Validate Runtime package API between managed and WASM assemblies
8a06277
Enable package validation so pack fails when the WASM assembly lacks
API the managed one exposes. Existing intended differences are listed in
CompatibilitySuppressions.xml.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lisandroct
Validate transaction callbacks once at the public entry point
c156f05
lisandroct added 24 commits November 24, 2026 15:05
@lisandroct
Clean tests
b27cc0b
@lisandroct
Reduce CI cost
4ee1e68
@lisandroct
Clean tests even further
ec76296
@lisandroct
Fix versions
76e876a
@lisandroct
Add [EditorBrowsable(Never)] to methods
945de05
@lisandroct
Lint
0af6ed1
@lisandroct
Clean
2409ca6
@lisandroct
Add Testing and Testing.Tests to the solution
4cb82d2
@lisandroct
Clean
a0ffcc6
@lisandroct
Update docs
f4cba24
@lisandroct
Clean
41cc4ec
@lisandroct
Clean
e8a16b0
@lisandroct
Fix CI
ec3f389
@lisandroct
Fix CI
9769ebc
@lisandroct
Update Verify
7095fa8
@lisandroct
Fix version in Cargo.lock
589d4c2
@lisandroct
Flag libraries and submodules for WASM compilation
1f6c87d
@lisandroct
Fix nested submodules
53d853b
@lisandroct
Allow creation of identity
5d04848
@lisandroct
Fix lint
84bc8d4
@lisandroct
Move csharp-testing-packages to cargo ci other-workflows
01eb6c0
@lisandroct
Only save the C# testing Rust cache on pushes to master
f4dcaee
@lisandroct
Version bump
97b3717
@lisandroct
Quote the RID list passed to dotnet pack
06f6ab9
@lisandroct
lisandroct force-pushed the lisandro/csharp-module-unit-testing-split branch from 646ed28 to 06f6ab9 Compare November 24, 2026 21:06
@lisandroct
lisandroct added this pull request to the merge queue Nov 24, 2026
Merged via the queue into master with commit b304fd5 Nov 24, 2026
86 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@joshua-spacetime joshua-spacetime mentioned this pull request Nov 24, 2026
C# module unit tests #6359
Closed
@clockwork-labs-bot clockwork-labs-bot mentioned this pull request Nov 25, 2026
docs: complete catch-up audit for storage, modules and SDKs #6621
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cloutiertyler cloutiertyler cloutiertyler approved these changes
@JasonAtClockwork JasonAtClockwork JasonAtClockwork approved these changes
@bfops bfops Awaiting requested review from bfops bfops is a code owner
@jdetter jdetter Awaiting requested review from jdetter jdetter is a code owner
@rekhoff rekhoff Awaiting requested review from rekhoff rekhoff is a code owner
+1 more reviewer
@github-advanced-security github-advanced-security[bot] github-advanced-security[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@lisandroct @cloutiertyler @github-advanced-security @JasonAtClockwork
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.