Workspace/Coding labs
Loading progress

Route verified channel events

Intermediate50 min

Implement route_events(events, identities). Trusted identities maps (tenant, channel, external_user) to an internal actor. Events have tenant, channel, external_user, conversation, event_id, integer at, and text. Sort by (at,event_id) stably. Reject unmapped identities by adding their event id to rejected. For mapped events, deduplicate (tenant,channel,event_id), then append text to a session keyed by (tenant,channel,conversation,actor). Return sessions and rejected. Input events satisfy their schema and repeated event identifiers refer to the same logical delivery. This lab assumes prior transport authentication; it does not authenticate users.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

InputSame event id in north/chat and south/chat

OutputTwo distinct sessions

Tenant is part of both identity and delivery scope.
EXAMPLE 2

InputTwo deliveries of north/chat event 1

OutputOne appended message

The duplicate is ignored.
solution.pyPython 3.12