Variable MistakeKindConst

MistakeKind: ClosedSet<
    {
        AnotherService: "another service";
        AttemptLeftOut: "attempt left out";
        AttemptScriptedTwice: "attempt scripted twice";
        GapInTheAttempts: "gap in the attempts";
        NoContributor: "no contributor";
        NoReporter: "no reporter";
        NoSuchAttempt: "no such attempt";
        RescueStepLeftOut: "rescue step left out";
        RescueStepSkips: "rescue step skips";
        StepLeftOut: "step left out";
        StepScriptedTwice: "step scripted twice";
        UnknownProvider: "unknown provider";
        UnknownStep: "unknown step";
    },
> = ...

What a mistake in a test is, each written in words, such as "attempt left out".

import assert from "node:assert/strict";
import { type Outcome, Step, step } from "itinera/step";
import { MistakeKind, scripted, TestMistake } from "itinera/testing";
import { withStep, Workflow, workflow } from "itinera/workflow";

@step()
class Charge extends Step {
override run(): Outcome {
return this.succeed();
}
}

@workflow({ name: "orders" })
@withStep(Charge, { name: "charge", retryBudget: 1 })
class Orders extends Workflow {}

export default (async () => {
const instance = Orders.build().instance({});

assert.throws(
() => scripted(instance).step("chrage"),
new TestMistake([{ kind: MistakeKind.UnknownStep, step: "chrage" }]),
);

await assert.rejects(
scripted(instance).step("charge").willFail("declined").run(),
(mistake: unknown) =>
mistake instanceof TestMistake &&
mistake.message ===
"the test is mistaken: attempt 2 of charge is left out" &&
mistake.problems[0]?.kind === MistakeKind.AttemptLeftOut,
);
})();