Assertion helper for verifying run events in sequence.

Constructors

Methods

  • Access a specific event by index for assertions. Supports negative indices (e.g., -1 for last event).

    Parameters

    • index: number

    Returns EventAssert

    Example

    result.expect.at(0).isMessage({ role: 'user' });
    result.expect.at(-1).isMessage({ role: 'assistant' });
  • Advance to the next event, optionally filtering by type.

    Parameters

    Returns EventAssert

    Example

    result.expect.nextEvent().isMessage({ role: 'assistant' });
    result.expect.nextEvent({ type: 'function_call' }).isFunctionCall({ name: 'foo' });
  • Assert that there are no further events.

    Returns void

    Example

    result.expect.noMoreEvents();
    
  • Get an EventRangeAssert for a range of events. Similar to Python's slice access: expect[0:3] or expect[:]

    Parameters

    • Optional start: number

      Start index (inclusive), defaults to 0

    • Optional end: number

      End index (exclusive), defaults to events.length

    Returns EventRangeAssert

    Example

    // Search all events
    result.expect.range().containsFunctionCall({ name: 'foo' });
    // Search first 3 events
    result.expect.range(0, 3).containsMessage({ role: 'assistant' });
  • Skip a specified number of upcoming events without assertions.

    Parameters

    • count: number = 1

    Returns this

    Example

    result.expect.skipNext(2);
    
  • Conditionally skip the next event if it matches the specified criteria. Returns the event assertion if matched and skipped, or undefined if not matched.

    Parameters

    • options: {
          role?: ChatRole;
          type: "message";
      } | {
          args?: Record<string, unknown>;
          name?: string;
          type: "function_call";
      } | {
          isError?: boolean;
          output?: string;
          type: "function_call_output";
      } | {
          newAgentType?: AgentConstructor;
          type: "agent_handoff";
      }

    Returns undefined | MessageAssert | FunctionCallAssert | FunctionCallOutputAssert | AgentHandoffAssert

    Example

    // Skip optional assistant message before function call
    result.expect.skipNextEventIf({ type: 'message', role: 'assistant' });
    result.expect.nextEvent().isFunctionCall({ name: 'foo' });