ruvnet/ruflo · error
Expected to find ${JSON.stringify(expected)} after index ${l
Error message
Expected to find ${JSON.stringify(expected)} after index ${lastIndex} in array What it means
assertPartialOrder() walks expectedOrder and requires each expected item to appear (matched by key/value subset with strict equality) after the index where the previous one matched. It throws naming the expected item and the index boundary as soon as one cannot be found, meaning the actual array is missing an expected event or events happened out of order.
Source
Thrown at v3/@claude-flow/testing/src/helpers/assertion-helpers.ts:385
* { type: 'End' },
* ]);
*/
export function assertPartialOrder<T>(
actual: T[],
expectedOrder: Partial<T>[]
): void {
let lastIndex = -1;
for (const expected of expectedOrder) {
const index = actual.findIndex((item, i) =>
i > lastIndex &&
Object.entries(expected as Record<string, unknown>).every(
([key, value]) => (item as Record<string, unknown>)[key] === value
)
);
if (index === -1) {
throw new Error(
`Expected to find ${JSON.stringify(expected)} after index ${lastIndex} in array`
);
}
lastIndex = index;
}
}
/**
* Assert that all items in a collection pass a predicate
*
* @example
* assertAllPass(results, result => result.success);
*/
export function assertAllPass<T>(
items: T[],
predicate: (item: T, index: number) => boolean,
message?: stringView on GitHub (pinned to fa13ee4ad6)
Solutions
- Await or flush all async work before asserting (Promise.all, runAllTimers, and similar)
- Include in expectedOrder only events whose relative order is actually guaranteed; drop incidental ones
- Check that key names and value types match exactly, since matching uses === on item[key]
Example fix
// before
emitEvents(); // not awaited
assertPartialOrder(events, [{ type: 'task.completed' }, { type: 'agent.released' }]); // throws
// after
await emitEvents(); // wait until emissions settle
assertPartialOrder(events, [{ type: 'task.completed' }, { type: 'agent.released' }]); Defensive patterns
Strategy: validation
Validate before calling
// Pre-check order yourself to produce a targeted failure message
function isPartialOrder(actual: Record<string, unknown>[], expected: Record<string, unknown>[]): boolean {
let last = -1;
for (const exp of expected) {
const idx = actual.findIndex((item, i) =>
i > last && Object.entries(exp).every(([k, v]) => item[k] === v)
);
if (idx === -1) return false;
last = idx;
}
return true;
}
if (!isPartialOrder(events, expectedOrder)) {
console.error('actual events:', JSON.stringify(events, null, 2));
}
assertPartialOrder(events, expectedOrder); Prevention
- Flush all promises and timers before order assertions
- Assert order only between events with a causal dependency
- Normalize ids and types (for example String(id)) before collecting events
When it happens
Trigger: Events emitted in a different order than asserted because of async completion races; an expected event never emitted (swallowed error); key values of different types (string id vs number id) failing strict equality.
Common situations: Asserting before flushing microtasks or timers; parallel tasks with nondeterministic completion order; ids collected as numbers but asserted as strings.
Related errors
- Invalid domain object: ${result.errors?.join(', ')}
- Mock was called with unexpected arguments: ${JSON.stringify(
- Item at index ${i} failed predicate: ${JSON.stringify(items[
- Item at index ${i} passed predicate but should not have: ${J
- Invalid state transition from '${from}' to '${to}'. Allowed
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/d4629814a35af9ba.
Report an issue: GitHub.