@firfi/quint-connect
Version:
Model-based testing framework connecting Quint specifications to TypeScript implementations
59 lines • 2.53 kB
JavaScript
import { Effect, Schema } from "effect";
export class StateMismatchError extends Schema.TaggedError()("StateMismatchError", {
message: Schema.String,
traceIndex: Schema.Number,
stepIndex: Schema.Number,
expected: Schema.Unknown,
actual: Schema.Unknown,
showDiff: Schema.optionalWith(Schema.Boolean, { default: () => true })
}) {
}
export class TraceReplayError extends Schema.TaggedError()("TraceReplayError", {
message: Schema.String,
traceIndex: Schema.Number,
stepIndex: Schema.Number,
action: Schema.String,
cause: Schema.optional(Schema.Unknown)
}) {
}
export class NoTracesError extends Schema.TaggedError()("NoTracesError", {
message: Schema.String
}) {
}
export const actionContext = (context, action) => ({
...context,
action
});
export const traceReplayError = (context, message, cause) => new TraceReplayError({
message,
traceIndex: context.traceIndex,
stepIndex: context.stepIndex,
action: context.action,
...(cause === undefined ? {} : { cause })
});
export const unknownActionMessage = (action) => action === "init"
? `Unknown action: init. This is likely the known Quint typescript backend bug (https://github.com/informalsystems/quint/pull/1929) where non-disjunctive step actions report "init" instead of the actual action name. Wrap your step action body in \`any { YourAction, }\` as a workaround, or use \`--backend rust\`.`
: `Unknown action: ${action}`;
export const withTraceReplayError = (effect, context, formatMessage) => effect.pipe(Effect.mapError((cause) => traceReplayError(context, formatMessage(cause), cause)), Effect.catchAllDefect((defect) => Effect.fail(traceReplayError(context, formatMessage(defect), defect))));
/** @internal */
export const jsonReplacer = (_, v) => {
if (typeof v === "bigint")
return `${v}n`;
if (v instanceof Map) {
const obj = {};
for (const [k, val] of v)
obj[String(k)] = val;
return obj;
}
if (v instanceof Set)
return [...v];
return v;
};
export const stateMismatchError = (context, seed, expected, actual) => new StateMismatchError({
message: `State mismatch at trace ${context.traceIndex}, step ${context.stepIndex}, action "${context.action}" (seed: ${seed})\nExpected: ${JSON.stringify(expected, jsonReplacer)}\nActual: ${JSON.stringify(actual, jsonReplacer)}`,
traceIndex: context.traceIndex,
stepIndex: context.stepIndex,
expected,
actual
});
//# sourceMappingURL=replay-errors.js.map