Repository navigation
test(AIC-3593): assert the SDK never loads a .env file - #220
Merged
Merged
Conversation
Import both entry points and call init_client() from a directory holding a .env that sets LD_SDK_KEY and a sentinel. Neither may reach os.environ, and init must fail for the missing key. Verified the test fails when lifecycle.py calls load_dotenv(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jeffdupont
marked this pull request as ready for review
October 26, 2026 22:09
apucacao
approved these changes
Oct 26, 2026
aknight-ld
approved these changes
Oct 27, 2026
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.
Why
AIC-3593: a library must not load the application's
.env. Which file gets read depends on the app's working directory, and a loader fills in exactly the variables the app left unset. JS loaded one on import until js-ai-sdk#69. Python never has (packages/client/agents.mdsays so), but nothing tested it, so a futureload_dotenv()would ship unnoticed.What
One test in
test_lifecycle.py. In a subprocess run from a directory holding a.envthat setsLD_SDK_KEYand a sentinel, withLD_SDK_KEYunset: import the root andexperimentalentry points, callinit_client(). It asserts init fails for the missing key and neither variable reachedos.environ.Made it fire: with
load_dotenv()appended tolifecycle.pythe test fails (sentinel: 1,key: from-dotenv). It passes on main as is.The spec rule: launchdarkly/ai-sdks-monorepo#93.
🤖 Generated with Claude Code
Note
Overview
Adds a regression test (
test_never_loads_a_dotenv_file) under the SDK-key init path to lock in the library contract: importinglaunchdarkly_ai_server(includingexperimental) and callinginit_client()must not read the host app’s.env.The test runs a subprocess with
cwdon a directory containing a.envthat setsLD_SDK_KEYand a sentinel, withLD_SDK_KEYstripped from the parent env. It expectsinit_client()to still fail for a missing SDK key and for neither variable to appear inos.environ—so a futureload_dotenv()would fail CI.Reviewed by Cursor Bugbot for commit 678e937. Bugbot is set up for automated code reviews on this repo. Configure here.