MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / assertInvariant

Function assertInvariant

packages/core/src/testing/assertions.ts:153–180  ·  view source on GitHub ↗
(
  actual: readonly RoutedAction[],
  invariant: ScenarioInvariantAssertion,
  path: string,
)

Source from the content-addressed store, hash-verified

151}
152
153function 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
182export function evaluateScenarioResult(
183 scenario: ScenarioDefinition,

Callers 1

evaluateScenarioResultFunction · 0.85

Calls 2

matchesSubsetFunction · 0.85
actionPayloadFunction · 0.85

Tested by

no test coverage detected