Skip to content

Commit 2ac1038

Browse files
committed
feat(@probitas/probitas): add custom serializer for IPC step values
Standard JSON.stringify fails on BigInt, circular references, Symbol, Function, Map, Set, RegExp, TypedArray, and other JavaScript types. This causes step context values to be lost or corrupted when passed between processes via IPC. The custom serializer uses a marker object pattern ($type property) to preserve type information across the IPC boundary, enabling steps to receive BigInt, Map, circular references, and other complex values through ctx.previous and ctx.results. Handles: BigInt, Symbol, Function, undefined, circular references, Map, Set, WeakMap, WeakSet, RegExp, Date, Error, TypedArray, ArrayBuffer, DataView, WeakRef. Addresses #80
1 parent ccc57f6 commit 2ac1038

3 files changed

Lines changed: 968 additions & 4 deletions

File tree

src/cli/_templates/run_protocol.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
isErrorObject,
1919
toErrorObject,
2020
} from "@core/errorutil/error-object";
21+
import { deserialize, serialize } from "./serializer.ts";
2122

2223
/**
2324
* Message sent from CLI to subprocess
@@ -163,11 +164,17 @@ export function deserializeError(serialized: ErrorObject): Error {
163164
}
164165

165166
/**
166-
* Serialize StepResult error for transmission
167+
* Serialize StepResult for transmission
168+
*
169+
* Handles both error serialization (for failed/skipped) and value serialization
170+
* (for passed steps) to ensure all non-JSON-serializable values are converted.
167171
*/
168172
export function serializeStepResult(result: StepResult): StepResult {
169173
if (result.status === "passed") {
170-
return result;
174+
return {
175+
...result,
176+
value: serialize(result.value),
177+
};
171178
}
172179
return {
173180
...result,
@@ -193,11 +200,17 @@ export function serializeScenarioResult(
193200
}
194201

195202
/**
196-
* Deserialize StepResult error from transmission
203+
* Deserialize StepResult from transmission
204+
*
205+
* Handles both error deserialization (for failed/skipped) and value deserialization
206+
* (for passed steps) to restore non-JSON-serializable values.
197207
*/
198208
export function deserializeStepResult(result: StepResult): StepResult {
199209
if (result.status === "passed") {
200-
return result;
210+
return {
211+
...result,
212+
value: deserialize(result.value),
213+
};
201214
}
202215
if (isErrorObject(result.error)) {
203216
return {

0 commit comments

Comments
 (0)