Testing and Debugging Lua
The script editor runs your code against a sample without opening a port, consuming a real message, or sending anything to a destination. Use it before you start a node.
Run Test or Debug?
| Run Test | Debug | |
|---|---|---|
| Button | Blue Run Test | Grey Debug, bug icon |
| Keyboard | Ctrl+Enter (⌘+Enter on a Mac) | Ctrl+Shift+Enter (⇧+⌘+Enter on a Mac) |
| Breakpoints | Ignored | Honoured — execution pauses |
| Execution | Runs to completion | Pauses and steps |
| Variables shown | Final locals of main | Locals of the paused frame |
| Call stack | Not shown | Full stack, frames selectable |
Reach for Run Test first. It answers "does this parse, and what did it produce?" in one click. Switch to Debug when you need to know why a value is what it is.
Keyboard shortcuts
Both work anywhere on the Scripting page, including while you are typing in the editor, on Windows, Linux and macOS:
| Action | Windows and Linux | macOS |
|---|---|---|
| Run Test | Ctrl+Enter or Ctrl+F5 | ⌘+Enter or Ctrl+F5 |
| Debug | Ctrl+Shift+Enter or F5 | ⇧+⌘+Enter or F5 |
The F5 forms match VS Code. On a laptop keyboard you may need to hold Fn for them. The tooltips on the Run Test and Debug buttons show the shortcuts too.
The shortcuts do nothing while a window such as Samples or Commit is open. In a Data Map's Map view, which has no Debug button, the Debug shortcuts do nothing either, and F5 reloads the page as usual.
Create samples first
Both modes run against a sample, so you need at least one.
- Click Samples at the top of the Scripting page.
- Add a sample and paste the content your node would actually receive, or upload a file (
.txt,.hl7or.json). The same window is where samples are read, edited and renamed later.
A Data Map node can also take samples while you create a map, in the New map wizard.
What a sample contains depends on the node type:
| Node type | Sample content |
|---|---|
| Source HTTP | A complete raw HTTP request: request line, headers, blank line, body |
| Source LLP | An HL7 v2 message |
| Transform Custom | The message the upstream node produces |
A Source HTTP sample looks like this — the blank line before the body is required:
POST /intake HTTP/1.1
Host: 127.0.0.1:9001
Content-Type: application/json
{"patientId":"TEST-1001","status":"active"}
Samples persist with the node, so they travel with the interface and are available to whoever maintains it next. Each one is a real file in the node's samples folder, which appears in the Explorer as soon as the first sample is added — so a sample can be opened, edited, and committed like any other file in the node.
Samples are stored with the project and are visible to anyone who can open the node. Use clearly fake identifiers — TEST000001, TEST^PATIENT, 19700101 — never real patient data.
Run Test
- Select a sample from the toolbar dropdown.
- Click Run Test, or press Ctrl+Enter (⌘+Enter on a Mac).
The Debug panel shows every local variable as it stood at the end of main, plus anything your script printed.
Use it to confirm:
- The script compiles.
- Parsing produced the tree you expected.
- Field mappings landed in the right places.
- Your
printoutput shows the path the script took.
Debug
- Click the editor gutter, left of the line numbers, to place breakpoints. Any open file works —
main.luaor a module it requires. - Select a sample.
- Click Debug, or press Ctrl+Shift+Enter (⇧+⌘+Enter on a Mac).
Execution starts at main and pauses at the first breakpoint. From there:
| Control | Does |
|---|---|
| Continue | Run to the next breakpoint, or to the end |
| Step Over | Next line in the current function |
| Step Into | First line of the function being called |
| Step Out | Run until the current function returns |
| Stop | End the session immediately |
The Call Stack lists the active frames, such as mapPID @ mapping/maps/adt.lua:16. Click a frame to inspect its variables; the editor jumps to that file and line. Step Into switches files automatically.
Variables always reflect the paused frame, not the end of main. That is the point: it is how you catch a value that is correct at the end but wrong in the middle.
Reading the variables tree
- Branches are collapsed by default. Expand what you need.
- Hide empty is on by default and prunes branches with no values — useful with HL7, where most of a schema is unpopulated.
- Message trees show schema names: segments as
PID, fields as[5] Name, down to the leaf value.
Turn Hide empty off when you are checking that a field really is empty rather than simply mis-navigated.
Nothing leaves a test unless you ask
In both modes, calls that reach outside the grid are simulated. Each one takes a live option, which defaults to false:
| Call | In Run Test and Debug |
|---|---|
linkiir.flow.push | Validates the call and returns a placeholder message ID. It never produces a message, even with live = true. |
linkiir.link.web.get, .post and the other methods | Return { code = 0, body = "", simulated = true } without sending the request. |
linkiir.link.mail.send | Returns true without sending the email. |
linkiir.link.socket.connect, linkiir.link.file.open | Return a simulated, closed connection. |
linkiir.store.open | Returns a simulated connection. Its query and execute return nil and an error; merge returns 0. |
To make a call for real while you test, pass live = true, for example linkiir.store.open{ driver = linkiir.store.SQLITE, name = 'test.db', live = true }. Point such calls at test endpoints and test databases.
live only matters in the editor. A running node always makes every call, whatever live says, so there is nothing to change before you deploy.
This is worth knowing when reading test output: a push or request that "succeeded" in Run Test confirms the call is well-formed, not that delivery works. Verify delivery by starting the node.
Reading and writing files is not simulated. linkiir.sys.fs and io calls touch the disk during a test, as they do in a running node.
IntelliSense does not run your script
Completion, hover, and signature help come from the API definitions, your schema, and the text in the buffer. Typing never executes anything and never reads sample values or live data.
What it gives you:
| Type | Get |
|---|---|
linkiir. | Sub-modules, then their functions |
Msg. after linkiir.data.extract | Segment names from the schema, with field documentation |
Msg: | Node methods |
req. after linkiir.link.web.request | method, path, headers, body, and the rest |
Inside fn{ … } | Parameter hints |
Runtime values appear only in the Debug panel. They are never fed back into completion.
A test set worth keeping
Test more than the happy path. Keep a sample for each:
| Sample | Catches |
|---|---|
| Normal message | The baseline works |
| Missing required field | Unhandled nil |
| Optional segment absent | Navigation assuming a segment exists |
| Repeating field with several repeats | Code reading only the first repeat |
| Unsupported message type | Whether you filter or crash |
| Malformed input | Parse failure handling |
| Largest expected message | Size and performance surprises |
| Unusual characters | Encoding assumptions |
The missing-field and absent-segment samples earn their keep fastest. Most production script failures are an unhandled nil from a field that was always present in development.
When a test passes but the node fails
| Symptom | Likely cause |
|---|---|
Node goes to ERRORED on start | Compile error in a file you did not test, or a missing require |
| Works in test, fails on real traffic | The real message differs from your sample. Capture one from the logs and add it as a sample. |
| Test push succeeds, nothing arrives downstream | Nothing is connected after the node. Check the workflow. |
| Outbound call works in test, fails when running | Credentials or network reachability differ for the service account |
For a message that already went through a running node, open its record in log search and copy the payload into a new sample. Reproducing with the exact payload beats guessing.