langgraph/libs/sdk-py/integration/scripts/test_extensions.py
Sera 37becf152a
fix(sdk-py): publish integration progress events on a named channel (#9746)
`sdk-py integration` fails on `main` (`test_extensions`: `unexpected
step sequence: []`). It started with `langgraph-api` 0.20.0.dev2 in the
`latest-py3.12` image, not #9728. That version wraps
`get_stream_writer()` data as `custom` events with `{"payload": ...}`
and no `name`, so `custom:progress` matches nothing.

## Changes
- The test graph relays root-level `progress` writes onto a named
`StreamChannel("progress")`, which the server delivers as
`custom:progress`.
- The extensions test and script read each event's `payload`.

## Reviewer notes
- The last real pass was Nov 15 (image on 0.20.0.dev1). Runs since then
either skipped the job (path filter) or failed.
- The Python SDK's `thread.extensions[name]` yields the `{name,
payload}` envelope; JS yields `payload`. That parity gap is separate.

## Test Plan
- [x] Integration suite against `langgraph dev` with `langgraph-api`
0.20.0.dev4 and local langgraph: 55 passed (2 failed before)

[no screenshot]

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-11-19 18:00:08 -05:00

67 lines
2.1 KiB
Python

"""Exercise `thread.extensions[name]` against the integration API.
Every node in the example graph writes `{"name": "progress", ...}` via
`get_stream_writer`, relayed onto the named `progress` channel. This script verifies the `extensions["progress"]`
projection yields each progress event in order.
"""
from __future__ import annotations
import asyncio
from _common import (
ASSISTANT_ID,
check_api_reachable,
header,
make_async_client,
make_sync_client,
)
async def run_async() -> None:
header("async extensions[progress]")
threads, raw = make_async_client()
try:
async with threads.stream(assistant_id=ASSISTANT_ID) as thread:
await thread.run.start(input={"messages": [], "value": "init", "items": []})
events: list[dict] = []
async for event in thread.extensions["progress"]:
print(f" progress: {event!r}")
events.append(event)
print(f" total progress events: {len(events)}")
assert events, "expected at least one progress event"
# Verify ordering covers the node sequence.
steps = [e["payload"]["step"] for e in events]
print(f" step sequence: {steps}")
finally:
await raw.aclose()
def run_sync() -> None:
header("sync extensions[progress]")
threads, raw = make_sync_client()
try:
with threads.stream(assistant_id=ASSISTANT_ID) as thread:
thread.run.start(input={"messages": [], "value": "init", "items": []})
events: list[dict] = []
for event in thread.extensions["progress"]:
print(f" progress: {event!r}")
events.append(event)
print(f" total progress events: {len(events)}")
assert events, "expected at least one progress event"
steps = [e["payload"]["step"] for e in events]
print(f" step sequence: {steps}")
finally:
raw.close()
def main() -> None:
check_api_reachable()
asyncio.run(run_async())
run_sync()
if __name__ == "__main__":
main()