Skip to content

fix(url): Fix WOKWI_CLI_SERVER being ignored - #18

Merged
urish merged 1 commit into
wokwi:mainfrom
lucasssvaz:fix/server_url
Oct 2, 2026
Merged

urish merged 1 commit into
wokwi:mainfrom
lucasssvaz:fix/server_url

Conversation

@lucasssvaz

Copy link
Copy Markdown
Contributor

Problem

WokwiClient.__init__ falls back to the hard-coded public URL when server is not given:

self._transport = Transport(token, server or DEFAULT_WS_URL)

Because the client always passes a URL, the default in transport.py (TRANSPORT_DEFAULT_WS_URL = os.getenv("WOKWI_CLI_SERVER", DEFAULT_WS_URL)) is never used. As a result, WOKWI_CLI_SERVER is silently ignored by both WokwiClient and WokwiClientSync unless server is passed explicitly.

In practice this affects anyone using wokwi/wokwi-ci-server-action. The action sets WOKWI_CLI_SERVER=ws://localhost:9177, but clients created with just a token, such as the one in pytest-embedded-wokwi, still connect to wss://wokwi.com/api/ws/beta. The self-hosted CI server is bypassed and all simulations go to the shared public endpoint. In espressif/arduino-esp32 we've been seeing more and more intermittent ConnectionClosedError: no close frame received or sent and HTTP 503 failures because of this.

Fix

Fall back to TRANSPORT_DEFAULT_WS_URL instead of DEFAULT_WS_URL, so the existing environment variable lookup in transport.py is respected. An explicit server argument still takes priority.

Tests

Added tests/test_server_url.py, which runs without a token or network access and covers:

  • no server and no WOKWI_CLI_SERVER: uses the public server
  • no server with WOKWI_CLI_SERVER set: uses the environment variable
  • explicit server with WOKWI_CLI_SERVER set: uses the explicit server

Each case runs in a subprocess, because WOKWI_CLI_SERVER is read when wokwi_client.transport is imported.

@lucasssvaz lucasssvaz changed the title fix(url): Fix server URL being ignored fix(url): Fix WOKWI_CLI_SERVER being ignored Oct 1, 2026
@urish urish self-assigned this Oct 2, 2026
@urish
urish merged commit 0731dd4 into wokwi:main Oct 2, 2026
0 of 5 checks passed
@urish

urish commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thanks!

urish added a commit that referenced this pull request Oct 2, 2026
Follow-up to #18, which made WokwiClient fall back to the env var. The lookup still happened at import time via a module-level constant, so setting `WOKWI_CLI_SERVER` after `import wokwi_client` was ignored.
@urish

urish commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixed released as v0.4.1

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.

2 participants