Skip to content

fix: trajectory roundtrip e2e test — wire MESSAGE_RECEIVED/SENT lifecycle through mock #1269

@Dexploarer

Description

@Dexploarer

Problem

packages/agent/test/trajectory-plugin-chat-roundtrip.e2e.test.ts is currently skipped because it times out waiting for trajectory LLM call data to appear in the database.

Root cause

The test's mock messageService.handleMessage calls runtime.useModel inside runWithTrajectoryContext, which logs the LLM call via trajectoryLogger.logLlmCall. However, the trajectory plugin's persistence is driven by its MESSAGE_RECEIVED and MESSAGE_SENT event handlers:

  1. MESSAGE_RECEIVED → starts a trajectory, creates a step
  2. MESSAGE_SENT → completes the step, persists steps_json to DB

The server's generateChatResponse emits both events (lines 3324 and 3414 of server.ts), but the test's runtime.emitEvent mock forwards events to trajectoryLoggerPlugin.events[eventName] — which may not receive the correct payload shape or timing for the trajectory step lifecycle to complete.

As a result, logLlmCall adds data to an in-memory step that never gets flushed to the trajectories table's steps_json column.

Fix required

Wire the test mock's event pipeline so that:

  1. MESSAGE_RECEIVED is emitted before messageService.handleMessage runs
  2. MESSAGE_SENT is emitted after the response, with the correct message payload
  3. The trajectory plugin's MESSAGE_SENT handler calls completeSteppersistTrajectory

This ensures the LLM call data lands in steps_json and the detail API returns it.

Files

  • packages/agent/test/trajectory-plugin-chat-roundtrip.e2e.test.ts (test)
  • packages/agent/src/api/server.ts (event emission, lines 3320-3430)
  • @elizaos/plugin-trajectory-logger (event handlers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions