Skip to content

Conversation

@clincoln8
Copy link
Contributor

@clincoln8 clincoln8 commented Dec 5, 2025

Ensures .env files are correctly loaded for API key validation using load_dotenv from cwd and establishes global environment isolation for hermetic testing.

Key Changes

  • Fix .env Loading: Updated cli.py to ensure load_dotenv respects the current working directory when resolving .env files.
  • Test Environment Isolation:
    • Added a clean_env autouse fixture in tests/conftest.py that clears environment variables and changes the working directory to a temporary path for every test. This ensures tests are hermetic and do not accidentally read the host's .env file.
  • Test Standardization:
    • Updated test_cli.py, test_settings.py, test_dc_client.py, and test_temp_constrained_vars.py to consistently use the with mock.patch.dict(os.environ, ...): context manager pattern.

Will bump version to a new RC in a subsequent PR.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @clincoln8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the DC_API_KEY was not reliably loaded from .env files, particularly when the CLI was executed from a different directory than where the application was installed. It introduces the python-dotenv library to ensure correct loading of environment variables from the current working directory. Furthermore, it significantly improves the robustness and reliability of the test suite by implementing global environment isolation for all tests and refactoring test fixtures for better maintainability and clarity.

Highlights

  • .env File Loading: The CLI now correctly loads environment variables from .env files located in the current working directory, ensuring DC_API_KEY validation works as expected by integrating the python-dotenv library.
  • Enhanced Test Isolation: A new conftest.py file introduces global fixtures to automatically clear environment variables and mock load_dotenv for all tests, preventing interference from the host environment and ensuring hermetic testing.
  • Test Suite Expansion & Refactoring: The test suite has been expanded with new tests covering stdio mode, HTTP option handling, and missing API key scenarios, alongside refactoring existing tests to centralize common fixtures and improve maintainability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of loading the DC_API_KEY from .env files by integrating python-dotenv. The introduction of global test fixtures in conftest.py is a significant improvement for test hermeticity and maintainability, successfully isolating test environments from the host system. The refactoring to centralize the isolated_env fixture and remove duplicates is also a welcome cleanup. I've added a couple of suggestions to further refine the new test code by removing some redundancy and improving conciseness.

@clincoln8 clincoln8 changed the title [v1.1.4rc1] Fix loading DC_API_KEY from .env for validation [v1.1.4rc1] Fix loading DC_API_KEY from .env for validation and isolate testing environment Dec 5, 2025
@clincoln8 clincoln8 changed the title [v1.1.4rc1] Fix loading DC_API_KEY from .env for validation and isolate testing environment Fix loading DC_API_KEY from .env for validation and isolate testing environment Dec 5, 2025
@clincoln8
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great improvement, especially with the introduction of global test environment isolation in conftest.py. This makes the test suite much more robust and hermetic. The changes to load the .env file from the current working directory are also correctly implemented and tested. I have a few minor suggestions in test_cli.py to improve consistency with the new testing patterns and to simplify one of the end-to-end tests.

@clincoln8
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly improves the project's testing infrastructure and fixes an important bug in environment variable loading. The introduction of a global clean_env fixture to ensure hermetic tests is an excellent change that will improve test reliability. The standardization of environment variable mocking across the test suite is also a great cleanup. The fix for loading the .env file from the current working directory is correctly implemented. I have one suggestion to make a test assertion more specific, but overall, this is a high-quality contribution.

@clincoln8
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent pull request that significantly improves the project's testing infrastructure and fixes an important bug in environment variable loading. The introduction of the clean_env autouse fixture is a great step towards fully hermetic tests, and the standardization of environment variable patching across test files improves consistency and readability. The new tests for the CLI are thorough and well-written. I have one minor suggestion to make one of the new tests even cleaner by leveraging the new fixture setup.

Copy link
Contributor

@keyurva keyurva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pytest.fixture(autouse=True)
def clean_env(tmp_path, monkeypatch):
"""
Automatically clear environment variables and change to a temporary directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@clincoln8 clincoln8 merged commit ee3cc40 into datacommonsorg:main Dec 6, 2025
8 of 9 checks passed
@clincoln8 clincoln8 deleted the env branch December 6, 2025 00:10
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