Skip to content

refactor: migrate Python API to websockets asyncio API (>=14.0)#61

Merged
carvalhoviniciusluiz merged 1 commit into
masterfrom
feat/57-import-607
Jul 22, 2026
Merged

refactor: migrate Python API to websockets asyncio API (>=14.0)#61
carvalhoviniciusluiz merged 1 commit into
masterfrom
feat/57-import-607

Conversation

@carvalhoviniciusluiz

Copy link
Copy Markdown
Owner

Closes #57

Summary

Imports upstream gnachman#607 ("Migrate Python API to websockets new asyncio API >=14.0") into the fork. This is a compatibility fix for our Tier 1 daemon, which imports the iterm2 Python library. No feature flag — it's an infra/compat change.

The change removes the legacy/new websockets API compatibility shim and migrates the iterm2 Python lib directly to the websockets 14.0+ asyncio API:

  • InvalidStatusCodeInvalidStatus (status now read via response.status_code)
  • extra_headersadditional_headers
  • response_headersresponse.headers
  • websockets.legacy.client.connectwebsockets.connect
  • websockets.legacy.client.unix_connectwebsockets.unix_connect

websockets version change

api/library/python/iterm2/setup.py: install_requires pin changed from 'websockets' (unpinned) to 'websockets>=14.0'.

Files changed

  • api/library/python/iterm2/iterm2/connection.py — API migration
  • api/library/python/iterm2/setup.py — pin websockets>=14.0
  • api/library/python/iterm2/tests/test_connection.py — new tests (added by the upstream PR)

Test status (honest)

Ran the new tests/test_connection.py in an isolated venv (Python 3.11, websockets 15.0, pytest, pytest-asyncio) with PYTHONPATH pointed at the lib: 12 passed (asyncio_mode=auto). The only output noise was unrelated Python enum DeprecationWarnings from mainmenu.py. No app/Xcode build was run — this change is Python-lib-only.

Provenance

Adapted from upstream gnachman#607.

Apply notes

Patch applied cleanly onto current master (no conflicts, no rejects) — these three files are untouched by the fork.

🤖 Generated with Claude Code

Remove the legacy/new websockets API compatibility shim in the iterm2
Python library and migrate directly to the websockets 14.0+ API:
- InvalidStatusCode -> InvalidStatus (with response.status_code)
- extra_headers -> additional_headers
- response_headers -> response.headers
- websockets.legacy.client.connect -> websockets.connect
- websockets.legacy.client.unix_connect -> websockets.unix_connect
- Pin websockets>=14.0 in setup.py

Add tests for the connection module covering protocol version parsing,
InvalidStatus error handling (406/500/401), async_create error paths,
and argument passing to connect methods.

This is a compatibility fix for the Tier 1 daemon, which imports the
iterm2 Python lib.

Adapted from upstream gnachman#607.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@carvalhoviniciusluiz

Copy link
Copy Markdown
Owner Author

Review by tech-lead — APPROVED ✅ (verificado de verdade — lib Python, não o app).

Aplicou limpo (3 arquivos, sem conflito). Migração completa p/ a nova API asyncio do websockets (grep confirma zero refs legadas: extra_headers/InvalidStatusCode/response_headers/.legacy); pin websockets>=14.0. O subagente rodou tests/test_connection.py em venv isolado (websockets 15.0) → 12 passed. Beneficia diretamente o nosso daemon (Tier 1). Proveniência: Adapted from upstream gnachman#607. Sem ressalvas.

@carvalhoviniciusluiz
carvalhoviniciusluiz merged commit cfbf015 into master Jul 22, 2026
@carvalhoviniciusluiz
carvalhoviniciusluiz deleted the feat/57-import-607 branch July 22, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import upstream #607 — Python API websockets >=14 compat (no flag)

1 participant