-
Notifications
You must be signed in to change notification settings - Fork 82
Improve .env discovery
#737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EricGustin
wants to merge
3
commits into
main
Choose a base branch
from
ericgustin/improve-env-discovery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
13 changes: 13 additions & 0 deletions
13
libs/arcade-cli/arcade_cli/templates/minimal/{{ toolkit_name }}/.env.example
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Environment variables for {{ toolkit_name }} MCP server | ||
| # | ||
| # Copy this file to .env and fill in your values: | ||
| # cp .env.example .env | ||
| # | ||
| # The .env file will be automatically discovered when running your server, | ||
| # even from subdirectories like src/{{ toolkit_name }}/. | ||
| # | ||
| # IMPORTANT: Never commit your .env file to version control! | ||
|
|
||
| # Example secret used by the whisper_secret tool | ||
| # Replace with your actual secret value | ||
| MY_SECRET_KEY="Your tools can have secrets injected at runtime!" |
1 change: 0 additions & 1 deletion
1
...e-cli/arcade_cli/templates/minimal/{{ toolkit_name }}/src/{{ toolkit_name }}/.env.example
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Tests for find_env_file() upward directory traversal.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from arcade_mcp_server.settings import find_env_file | ||
|
|
||
|
|
||
| class TestFindEnvFile: | ||
| """Test the find_env_file() utility function.""" | ||
|
|
||
| def test_finds_env_in_current_directory( | ||
| self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Should find .env file in cwd.""" | ||
| env_file = tmp_path / ".env" | ||
| env_file.write_text("TEST_VAR=value") | ||
| monkeypatch.chdir(tmp_path) | ||
|
|
||
| assert find_env_file() == env_file | ||
|
|
||
| def test_finds_env_in_parent_directory( | ||
| self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Should traverse upward to find .env in parent.""" | ||
| subdir = tmp_path / "a" / "b" / "c" | ||
| subdir.mkdir(parents=True) | ||
| env_file = tmp_path / ".env" | ||
| env_file.write_text("TEST_VAR=value") | ||
| monkeypatch.chdir(subdir) | ||
|
|
||
| assert find_env_file() == env_file | ||
|
|
||
| def test_prefers_closest_env_file( | ||
| self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Should find closest .env when multiple exist.""" | ||
| subdir = tmp_path / "subdir" | ||
| subdir.mkdir() | ||
| (tmp_path / ".env").write_text("ROOT=1") | ||
| closer_env = subdir / ".env" | ||
| closer_env.write_text("CLOSER=1") | ||
| monkeypatch.chdir(subdir) | ||
|
|
||
| assert find_env_file() == closer_env | ||
|
|
||
| def test_returns_none_when_not_found( | ||
| self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Should return None when no .env exists.""" | ||
| subdir = tmp_path / "subdir" | ||
| subdir.mkdir() | ||
| monkeypatch.chdir(subdir) | ||
|
|
||
| assert find_env_file() is None | ||
|
|
||
| def test_stop_at_limits_traversal( | ||
| self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """stop_at should prevent traversing past specified directory.""" | ||
| project = tmp_path / "project" / "src" | ||
| project.mkdir(parents=True) | ||
| (tmp_path / ".env").write_text("OUTSIDE=1") | ||
| monkeypatch.chdir(project) | ||
|
|
||
| assert find_env_file(stop_at=tmp_path / "project") is None |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| import io | ||
| import subprocess | ||
| import tarfile | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| """Tests for get_tool_secrets() in arcade configure.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from arcade_cli.configure import get_tool_secrets | ||
|
|
||
|
|
||
| def test_get_tool_secrets_loads_from_env_file( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Should load secrets from .env file.""" | ||
| env_file = tmp_path / ".env" | ||
| env_file.write_text("SECRET_ONE=value1\nSECRET_TWO=value2") | ||
| monkeypatch.chdir(tmp_path) | ||
|
|
||
| secrets = get_tool_secrets() | ||
| assert secrets.get("SECRET_ONE") == "value1" | ||
| assert secrets.get("SECRET_TWO") == "value2" | ||
|
|
||
|
|
||
| def test_get_tool_secrets_returns_empty_when_no_env( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Should return empty dict when no .env exists.""" | ||
| monkeypatch.chdir(tmp_path) | ||
|
|
||
| assert get_tool_secrets() == {} |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.