Stream: beginners

Topic: shared types between prod and test platforms


view this post on Zulip Erik Karlsson (Nov 19 2026 at 23:33):

Hello!

I have my own platform, that's using the elm architecture

application: Application
application = {
    init: init,
    update: update,
    view: view,
}

Now, I want to test my application with a different platform that can do snapshot testing. And possibly the fuzzing platform too.

So, where is the Application type best housed? I guess it would have to be in a separate published package?

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:13):

I typically isolate most of my logic into modules (or groups of modules under a package) and then I can have multiple application roots use those same modules. So one application root might be using one platform, and another (sitting next to it or in a test/ directory) might be importing those same modules but with another platform.

This is how I structure things so I can use roc-fuzz

view this post on Zulip Erik Karlsson (Nov 20 2026 at 00:21):

I see, so for the Effect type from the platform, I could create a separate application-specific effect type, and then map that to the platform effect in main.roc?

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:26):

What is an application-specific Effect type?

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:27):

I would assume the platform specifies ahead of time what all the available effects are, and the application can use only those.

view this post on Zulip Erik Karlsson (Nov 20 2026 at 00:35):

Exactly, so the platform exposes an Effect type with all the effects. But I can't use that type in the code I want to fuzz.

So in order to do that, I would create a new type, ApplicationEffect, that's not bound to the platform, and then in my platform-specific main.roc, I would map that

toPlatformEffect : ApplicationEffect -> Effect

Or something like that

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:38):

You can do that, it should work ok.

I know there are some designs Richard has discussed for simulating effects in pure Roc using expect but I think that is deferred until post-0.1

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:38):

You can also have your application code or modules take the relevant effects it requires as an argument, use a where clause to constrain what that is. Then your tests can pass in a dummy implementation, and the real app passes in the platform's effects.

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:42):

In a lot of my platforms, I've been experimenting with a builtin test harness that the host implements and drives the app transparently to simulate effects. I define a custom or simple grammar for test "specs" and the platform host can pick that up and drive the application. The app doesn't know it is being tested and the effects aren't real etc. I can have thousands of e2e behaviour tests driven very fast this way.

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:43):

So it's not a Roc language level design, but it's been working really nicely.

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:45):

Here is a spec example from roc-signals -- I guess it's similar conceptually to a playwright style behavior test but built into the platform host.

https://github.com/lukewilliamboswell/roc-signals/blob/main/examples/data-grid/specs/filtering.scm

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:48):

So my general approach is

Both of these also provide information about allocations so you can write tests that assert things like this algorithm makes no allocations, or the allocations are flat over time, or the allocations scale linearly with the input etc

view this post on Zulip Erik Karlsson (Nov 20 2026 at 00:54):

Oh, interesting, so you're building the testing framework into the production platform. I guess that makes sense in a way, because the type of platform might dictate what kind of e2e tests are suitable.

view this post on Zulip Erik Karlsson (Nov 20 2026 at 00:55):

So, how are you triggering the tests vs the production build and run?

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:55):

Yeah, the test harness across my different platforms looks very different based on the domain

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:57):

Depends on the platform, in roc-signals if you build an app using --target=wasm32 you get a WASM module; if you build using roc build --target=x64musl you get a native test harness that accepts test spec files as a cli argument.

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:58):

In roc-gui its a little different, we reserve and intercept cli flags for the host.

roc build my-app.roc

./my-app --host-run-spec specs/greeting.scm

view this post on Zulip Luke Boswell (Nov 20 2026 at 00:59):

You can either have that be windowless such as in a CI environment without graphics drivers, or get a full-blown script driving an app.

view this post on Zulip Luke Boswell (Nov 20 2026 at 01:01):

I've even included "screenshot" functionality into the specs which closes the loop so an AI Agent can write throwaway specs to exercise and drive a GUI app and take screen captures of various UI elements all built in. It's so much more efficient and safer than giving access to random tools on my system.

view this post on Zulip Erik Karlsson (Nov 20 2026 at 01:03):

Both of those solutions seem a bit hacky to me, you're including the test harness in your production binary.

But doesn't seem to bad at this stage, I'll try going with the second option, since my test and production will share the same platform so I can't separate them at build time :)

view this post on Zulip Luke Boswell (Nov 20 2026 at 01:06):

you're including the test harness in your production binary.

I am -- but there is nothing stopping us from having a drop in replacement. We could switch the URL and have a "production build host" or a "development build host" etc. I've got it that way for convenience, the jury is out if that's a good idea. The additional cost in terms of code size of shipping the test infrastructure alongside the app seems to be almost nothing. As far as I can tell it doesn't increase or degrade the security boundary at all.

view this post on Zulip Erik Karlsson (Nov 20 2026 at 01:07):

Sounds good!

view this post on Zulip Erik Karlsson (Nov 20 2026 at 01:11):

I'd like to have my tests written in Roc too though. Maybe I can provide a list of test specs to the platform, and let the platform run them


Last updated: Nov 26 2026 at 20:35 UTC