( actual: readonly RoutedAction[], invariant: ScenarioInvariantAssertion, path: string, )
| 151 | } |
| 152 | |
| 153 | function assertInvariant( |
| 154 | actual: readonly RoutedAction[], |
| 155 | invariant: ScenarioInvariantAssertion, |
| 156 | path: string, |
| 157 | ): ScenarioMismatch | null { |
| 158 | if (invariant.kind === "action_absence") { |
| 159 | const found = actual.find((action) => { |
| 160 | if (invariant.action.id !== undefined && action.id !== invariant.action.id) return false; |
| 161 | if (invariant.action.action !== undefined && action.action !== invariant.action.action) { |
| 162 | return false; |
| 163 | } |
| 164 | return matchesSubset(actionPayload(action), invariant.action.payloadSubset); |
| 165 | }); |
| 166 | if (found === undefined) return null; |
| 167 | return { |
| 168 | code: "ZR_SCENARIO_INVARIANT_MISMATCH", |
| 169 | path, |
| 170 | detail: "Invariant failed: forbidden action was observed", |
| 171 | expected: invariant, |
| 172 | actual: found, |
| 173 | }; |
| 174 | } |
| 175 | return { |
| 176 | code: "ZR_SCENARIO_UNSUPPORTED", |
| 177 | path, |
| 178 | detail: `Unsupported invariant kind ${String((invariant as { kind: string }).kind)}`, |
| 179 | }; |
| 180 | } |
| 181 | |
| 182 | export function evaluateScenarioResult( |
| 183 | scenario: ScenarioDefinition, |
no test coverage detected