Skip to content

test(AIC-3593): assert the SDK never loads a .env file - #220

Merged
jeffdupont merged 1 commit into
mainfrom
jdupont/aic-3593-no-dotenv
Oct 27, 2026
Merged

jeffdupont merged 1 commit into
mainfrom
jdupont/aic-3593-no-dotenv

Conversation

@jeffdupont

@jeffdupont jeffdupont commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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.md says so), but nothing tested it, so a future load_dotenv() would ship unnoticed.

What

One test in test_lifecycle.py. In a subprocess run from a directory holding a .env that sets LD_SDK_KEY and a sentinel, with LD_SDK_KEY unset: import the root and experimental entry points, call init_client(). It asserts init fails for the missing key and neither variable reached os.environ.

Made it fire: with load_dotenv() appended to lifecycle.py the 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: importing launchdarkly_ai_server (including experimental) and calling init_client() must not read the host app’s .env.

The test runs a subprocess with cwd on a directory containing a .env that sets LD_SDK_KEY and a sentinel, with LD_SDK_KEY stripped from the parent env. It expects init_client() to still fail for a missing SDK key and for neither variable to appear in os.environ—so a future load_dotenv() would fail CI.

Reviewed by Cursor Bugbot for commit 678e937. Bugbot is set up for automated code reviews on this repo. Configure here.

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
jeffdupont marked this pull request as ready for review October 26, 2026 22:09
@jeffdupont
jeffdupont merged commit eac2200 into main Oct 27, 2026
12 checks passed
@jeffdupont
jeffdupont deleted the jdupont/aic-3593-no-dotenv branch October 27, 2026 14:43
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.

3 participants