XState version
XState version 5
Description
createTestModel(...).getSimplePaths() returns paths that pass through transitions whose guards evaluate to false. The guards are not being respected during graph traversal.
Example minimal reproduction:
const machine = createMachine({
id: 'bug-repro',
initial: 'start', // <-- separate initial state is required to trigger the bug
context: { allowed: false },
states: {
start: {
on: { NEXT: 'idle' },
},
idle: {
on: {
// Guard blocks this until ALLOW has been dispatched first
PROCEED: {
target: 'done',
guard: ({ context }) => context.allowed === true,
},
ALLOW: {
target: 'idle',
actions: assign({ allowed: () => true }),
},
},
},
done: { type: 'final' },
},
});
const model = createTestModel(machine);
const paths = model.getSimplePaths({ toState: (s) => s.status === 'done' });
paths.forEach((p) => console.log(p.description));
Expected result
One path, requiring ALLOW before PROCEED
Reaches state "done"({"allowed":true}): xstate.init → NEXT → ALLOW → PROCEED
Actual result
Two paths, one of which passes through PROCEED before ALLOW has ever fired, ignoring the guard:
Reaches state "done"({"allowed":true}): xstate.init → NEXT → PROCEED → ALLOW → PROCEED
Reaches state "done"({"allowed":true}): xstate.init → NEXT → ALLOW → PROCEED
Reproduction
https://stackblitz.com/edit/github-cguebm7g?file=src%2Fmain.ts
Additional context
I have also prepared the same machine with xstate 4 and @xstate/test, which illustrates the expected result: https://stackblitz.com/edit/github-cguebm7g-hv4u2asb
XState version
XState version 5
Description
createTestModel(...).getSimplePaths()returns paths that pass through transitions whose guards evaluate tofalse. The guards are not being respected during graph traversal.Example minimal reproduction:
Expected result
One path, requiring
ALLOWbeforePROCEEDActual result
Two paths, one of which passes through
PROCEEDbeforeALLOWhas ever fired, ignoring the guard:Reproduction
https://stackblitz.com/edit/github-cguebm7g?file=src%2Fmain.ts
Additional context
I have also prepared the same machine with xstate 4 and @xstate/test, which illustrates the expected result: https://stackblitz.com/edit/github-cguebm7g-hv4u2asb