Repository navigation
feat(python-sdk): honour the dev environment switch - #484
Merged
Merged
Conversation
The Python SDK implements the dev environment switch (docs/internal/dev-environment-switch.md): - The switch: the environment option on Arete.connect, create_session and ProtocolClient, else ARETE_ENVIRONMENT, else production. With the switch unset no dev input is read and requests are unchanged. - Edge mode: chain, transactions, Program Read, stack socket and queries, and the protocol API go to the a4 dev up edge with no credential and the X-Arete-Dev-Identity header; the edge is checked before the socket opens. - Direct mode: the client resolves its gateway, stack and program read identities in one request at connect (protocols on first use) and mints environment tokens with environment. - Refusals raise DevEnvironmentError (an AreteError) with the wire code, message, and fix and every other detail in details. client.environment, ProtocolClient.environment and Session.environment report the mode. - The shared vectors run in pytest, targets end to end through a mock transport.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
[Medium impact] The PR appears safe to merge; the cancelled-request retry issue is fixed. SummaryThe Python SDK adds a dev environment switch for stack clients, sessions, and protocol clients.
|
…sals and the owned HTTP client in dev mode
…flight resolves per identity
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The Python SDK (
python/arete-sdk) honours the dev environment switch fromdocs/internal/dev-environment-switch.md. This is the Python half of the parity work; the Rust SDK anda4/MCP are in #482. The two PRs are independent.environment=onArete.connect,create_sessionandProtocolClient("production"or{"kind": "dev", "url"?, "env"?};arete.dev_environment.dev(url=..., env=...)builds one). Without it,ARETE_ENVIRONMENTdecides, and production is the default. Precedence, edge URL and environment reference grammar, and the nearest.arete/dev/session.jsonfollow the contract. With the switch unset no dev input is read (the secret-key check is lazy too) and production requests are unchanged.environmentis only added to session bodies when it is set.Authorizationand theX-Arete-Dev-Identityheader (none for stacks). Answers withoutX-Arete-Dev-Edge: 1, or a failed connection, raisedevenv-edge-unreachable.GET /.well-known/arete-dev-edgeis checked before the socket opens. Unpublished protocols usepackage:<package>. A stack without a release raisesdevenv-stack-not-loaded.environment. Program Read authenticates with the installed release and reads the served release. Protocol sessions name the environment's deployment.arete.DevEnvironmentError(anAreteError).codeis the wire code,messageis the message, anddetailsholdsfixand every other detail field (.fixreads it). It is read from the API problem envelope or the Program Read envelope, from services, the edge, resolve and the session endpoint. Malformed config raisesAreteErrorwith codeINVALID_CONFIG. A refused surface raises before anything is sent; other surfaces keep working.client.environment,ProtocolClient.environment,Session.environment("production"/"dev").Vectors
tests/test_dev_environment_vectors.pyruns every case ofswitch.json,targets.jsonandrefusals.jsonand is picked up by the existing Python CI matrix.targets.jsonruns end to end: each surface is built the way a client builds it, and its requests (endpoint, token request, session endpoint, identity header, resolve request, absence ofAuthorization) are captured by a mock transport. Three client-level tests coverARETE_ENVIRONMENT=dev+ARETE_DEV_URLonArete.connect, an unknown switch value, andenvironment == "production".Known gaps
transaction:inspect, ortransaction:sendfor sends). That is existing production behaviour, so the test checks the minted scope is a subset of the vector'stokenRequest.scopes.scopes. The stack query session body matches the vector.url/http_urlis refused (INVALID_CONFIG), because the stack is resolved by identity.Testing
Run locally:
python -m pytestinpython/arete-sdkon Python 3.11: 1173 passed, 102 of them dev-environment tests. Python 3.9/3.10 and thesolanaextra run only in CI.