One script, two interpreters
BS Lang runs in two places. A form rule runs in the browser, in TypeScript; a plugin step or a Custom API runs on the server, in C#. Those are two separate interpreters of one language, so we keep them the same with one shared set of test scripts that both must pass. This is a developer's look at how that works, and at the two cases where they still disagree.

This one is for developers. It explains something you don't normally have to think about, and why you can rely on it.
Two places a script runs
BS Lang runs in the browser and on the server:
| In the browser (TypeScript) | On the server (C#) |
|---|---|
| Form rules | Plugin steps |
| Command buttons | Custom APIs |
| Studio screens | Scheduled jobs |
| Processes |
The browser side needs no round trip, so a field can appear the moment you type. The server side is the one that can't be skipped: it runs however the record was saved.
And one script can reach both. A solution script is imported by whatever needs it: a form rule in the browser, a plugin step on the server. The editor says so above the code:

So the same needsApproval(amount) can decide what a form shows and what the server accepts. That
only works if both sides agree on what the script means.
Two implementations of one language
Underneath, there are two interpreters: one written in TypeScript, one in C#. Both are built from the same grammar, so they read a script the same way. What they do with it is written twice.
Two implementations drift. Not on purpose, and not all at once, but a fix goes into one and not the other, and nothing in either compiler notices. The result is the worst kind of bug: a rule that shows a field on the form and then refuses the save, or a condition that works in one place and branches the other way in another.
One set of tests, run by both
So there's a conformance suite: a folder of test scripts, each with the values it must produce. Both interpreters run the same files. Neither side owns them, so a case added for one is added for both.
Each case is a script and what it must record:

record(v) is a function both test runners give the script. It notes the type and the value of
whatever it's handed. The comparison is on what a script can tell apart, the type and the
value, not on how each side stores it inside.
int and number are separate types on purpose. 1 is an int and 1.0 is a number in both,
so a case that records 1 / 2 is also checking which one the language gives you.
There are 131 cases in eight files: arithmetic, strings, control flow, functions and closures, lists and objects, equality, the execution budget, and variables.
Both sides, green
The TypeScript side runs them with Vitest:

And the C# side with xUnit, reading the very same files:

(The totals differ because each side also has a couple of checks of its own, like one that fails if the case files can't be found, so an empty run can't pass by accident.)
What the suite has caught
The equality file exists because the two sides disagreed. true == true was false in the
browser, silently, and an error on the server. A comparison with an empty value was never true
in the browser, so a sample rule that should have filled in a default currency did nothing at all.
The fix was one rule, written down as cases: nothing equals nothing, values compare within their kind, different kinds are never equal, and none of that is an error. Now both sides pass it, and a change that breaks it fails the build on whichever side broke it.
Where they still disagree
Some cases are marked pending: a known difference, with the reason written next to it. Both runners skip them and list them, so the suite stays green and the list stays visible. There are two today. This is the one that matters:

0.1 + 0.2 is exactly 0.3 on the server and 0.30000000000000004 in the browser, because the
two runtimes use different kinds of number. That's a real difference a script can see. Until the
language picks one kind of number, compare money with a tolerance, or round first, rather than
testing a computed total for exact equality.
The other pending case is a bug on the browser side: reverse() on a list isn't found. It's listed
so it can't be forgotten.
A case, as text
Each file in cases/ has a suite name, a description, and a list of cases. A case is a script and what it must
record, in order:
{
"name": "two booleans compare",
"script": "record(true == true);\nrecord(true == false);\nrecord(false == false);",
"expect": [
{ "type": "bool", "value": "true" },
{ "type": "bool", "value": "false" },
{ "type": "bool", "value": "true" }
]
}
A case can also say that a script must be refused, and roughly why:
{
"name": "adding a number to a boolean is rejected",
"script": "record(1 + true);",
"expectFailure": true,
"expectMessageContains": "number"
}
And a known difference is recorded with "pending" and a short reason, so both runners skip it and list it.
Values are compared as text, so "3" means three whichever side produced it. The one adjustment made for the two
runtimes is that a decimal's trailing zeros don't count: C#'s decimal keeps 3.0 as 3.0 while JavaScript prints 3,
and that is how the two hosts store numbers, not something the language means. Everything else is left visible on
purpose, which is how 0.1 + 0.2 came to be on the pending list.
Adding a case, step by step
-
Pick the file whose subject the case belongs to, such as
06-equality.json, or add a new file. -
Write the smallest script that shows the behaviour, with one
record(...)per value you care about. -
Write what each
recordmust produce, type and value. -
Run both runners:
npm run test -w ui/packages/bs-lang dotnet test platform/tests/Parsware.BsLang.Tests -
If both pass, the behaviour is now a promise. If one fails, you have found a real divergence: decide which side is right, fix it, and keep the case. The TypeScript interpreter is the reference unless it is the one that is wrong.
Because both runners read the same JSON, there is nothing to copy across. The case exists once and is checked twice.
Writing scripts that behave the same on both sides
The suite guarantees what it covers. For a maker writing a script that will run on both sides, such as a solution script imported by a form rule and a plugin step, a few habits stay clear of the known edges:
- Don't compare computed decimals for exact equality.
0.1 + 0.2 == 0.3is true on the server and false in the browser. Compare with a tolerance, or round both sides to the precision that matters. - Use
isEmptyfor empty values. It is the platform's own test and means the same everywhere; comparing with""ornulldepends on how a value arrived. - Use templates to put numbers in text.
'Total ' + totalis refused on both sides, so the mistake can't slip through on one. - Call methods with brackets.
list.length()behaves the same everywhere;list.lengthwithout brackets is not a number on either side. - Keep shared scripts to shared functions. A solution script used on both sides should call only what both offer,
such as
getValueandisEmpty. What a script can see has the lists.
Why both sides are worth having
It would be simpler to run every script on the server. It would also make forms slow and clumsy: a field that appears when a box is ticked would wait for a round trip every time. And it would be simpler to run everything in the browser, except that anything in a browser can be avoided by whoever controls it, so a limit enforced only there isn't enforced.
So Parsware keeps both, for different jobs. The browser interpreter makes forms responsive; the server interpreter makes rules binding. Business logic: which one to use turns that into a choice between a client rule and a server rule, and the conformance suite is what lets one script serve both without surprises.
Questions that come up
Do I need to run the suite to write a rule? No. It is for whoever changes the interpreters. A maker writing a rule relies on it, the way you rely on a calculator having been tested.
Where are the pending cases listed? In the same files, marked "pending" with their reason, and in the output of
both runners as skipped tests. There are two today: the decimal difference above, and reverse() on a list in the
browser.
Can the two sides disagree about errors? The suite checks that both refuse a script that should be refused, and that the message says roughly why. It doesn't yet compare error codes, because the server side doesn't pass them through.
The rules we follow
- A behaviour that isn't in the suite isn't a promise. If you rely on it, it should be a case.
- A change to either interpreter lands with a case, run on both sides.
- A difference found in the wild becomes a case first, then a fix.
- The TypeScript interpreter is the reference, unless it's the one that's wrong.
One known limit: the suite checks that a script was refused and roughly why, not the exact error code, because the C# side doesn't pass the code through yet.
Try it
The cases are in ui/packages/bs-lang/conformance/cases. Run
npm run test -w ui/packages/bs-lang and dotnet test platform/tests/Parsware.BsLang.Tests,
and add a case of your own to both by adding it once.