Skip to content

Make Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variables - #4156

Merged
Chris (crickman) merged 3 commits into
mainfrom
copilot/search-cosmosdb-key-usage
Feb 23, 2026
Merged

Make Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variables#4156
Chris (crickman) merged 3 commits into
mainfrom
copilot/search-cosmosdb-key-usage

Conversation

CopilotAI commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

The CI workflow sets COSMOSDB_ENDPOINT and COSMOSDB_KEY environment variables for Cosmos DB emulator tests, but both test classes ignored them entirely — using hardcoded private const string values instead. The workflow configuration was dead.

Description

  • Changed EmulatorEndpoint and EmulatorKey from private const string to private static readonly string in both CosmosCheckpointStoreTests and CosmosChatHistoryProviderTests, reading from env vars with the original hardcoded values as fallbacks.
  • Renamed fields to follow the codebase s_ prefix convention for static fields (s_emulatorEndpoint, s_emulatorKey).
// BeforeprivateconststringEmulatorEndpoint="https://localhost:8081";privateconststringEmulatorKey="C2y6yDjf5/...";// Afterprivatestaticreadonlystrings_emulatorEndpoint=Environment.GetEnvironmentVariable("COSMOSDB_ENDPOINT")??"https://localhost:8081";privatestaticreadonlystrings_emulatorKey=Environment.GetEnvironmentVariable("COSMOSDB_KEY")??"C2y6yDjf5/...";

No behavioral change locally; in CI the workflow-supplied values now take effect.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? No.

CopilotAI self-assigned this Feb 22, 2026
…ironment variables
Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>
CopilotAI changed the title [WIP] Search repository for COSMOSDB_KEY configuration setting usageMake Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variablesFeb 22, 2026
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the .NET Usage: [Issues, PRs], Target: .Net label Feb 22, 2026
@github-actionsgithub-actionsBot changed the title Make Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variables.NET: Make Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variablesFeb 22, 2026
…nvention
Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>
CopilotAI changed the title .NET: Make Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variablesMake Cosmos DB tests read COSMOSDB_ENDPOINT and COSMOSDB_KEY from environment variablesFeb 22, 2026
@crickman
Chris (crickman) marked this pull request as ready for review February 22, 2026 20:42
CopilotAI review requested due to automatic review settings February 22, 2026 20:42

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR enables Cosmos DB tests to respect environment variables set by the CI workflow, which were previously ignored due to hardcoded connection settings. The changes align the test classes with the CI configuration while maintaining backward compatibility for local development.

Changes:

  • Converted hardcoded Cosmos DB connection constants to read from COSMOSDB_ENDPOINT and COSMOSDB_KEY environment variables with fallback to original default values
  • Renamed fields from EmulatorEndpoint/EmulatorKey to s_emulatorEndpoint/s_emulatorKey following the codebase's static field naming convention

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

FileDescription
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosCheckpointStoreTests.csUpdated to read Cosmos DB connection settings from environment variables, renamed fields to follow s_ prefix convention, updated all 2 usages
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.csUpdated to read Cosmos DB connection settings from environment variables, renamed fields to follow s_ prefix convention, updated all 4 usages

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .Net

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants

@alliscode@crickman@peibekwe@moonbox3@markwallace-microsoft