Fix environment detection precedence and normalize CI/local execution metadata#105
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/xping-dev/sdk-dotnet/sessions/3f753eb5-b070-4f8a-a450-4423ad940fb6 Co-authored-by: xping-admin <180879096+xping-admin@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xping-dev/sdk-dotnet/sessions/3f753eb5-b070-4f8a-a450-4423ad940fb6 Co-authored-by: xping-admin <180879096+xping-admin@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xping-dev/sdk-dotnet/sessions/3f753eb5-b070-4f8a-a450-4423ad940fb6 Co-authored-by: xping-admin <180879096+xping-admin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Start implementation of environment detection for Xping SDK
Fix environment detection precedence and normalize CI/local execution metadata
May 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Xping SDK’s environment detection and CI/local metadata capture to more accurately reflect how executions should be classified across CI providers and developer machines, while also expanding the configuration surface to allow customizable CI environment labels.
Changes:
- Fixes environment-name precedence by distinguishing explicitly configured
Environmentfrom default/fallback values and allowingASPNETCORE_ENVIRONMENT/DOTNET_ENVIRONMENTto take effect when appropriate. - Adds
CiEnvironmentNameconfiguration (including builder + env-var binding) to customize the environment label used for auto-detected CI runs. - Normalizes execution metadata by introducing
ExecutionContext(CI/Local),IsDeveloperMachinefor local non-container runs, andCI.Branchnormalization (notably improved for GitHub Actions).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Xping.Sdk.Core.Tests/Services/Environment/EnvironmentDetectorTests.cs | Adds coverage for updated environment detection precedence and new CI/local metadata. |
| tests/Xping.Sdk.Core.Tests/Extensions/XpingServiceCollectionExtensionsTests.cs | Verifies env-var binding for XPING_CIENVIRONMENTNAME. |
| tests/Xping.Sdk.Core.Tests/Configuration/XpingConfigurationTests.cs | Updates defaults test to include CiEnvironmentName. |
| tests/Xping.Sdk.Core.Tests/Configuration/XpingConfigurationBuilderTests.cs | Verifies builder support for WithCiEnvironmentName. |
| src/Xping.Sdk.Core/Services/Environment/Internals/EnvironmentDetector.cs | Implements corrected precedence, CI label configurability, and normalized CI branch properties. |
| src/Xping.Sdk.Core/Services/Environment/IEnvironmentDetector.cs | Updates documented precedence to match new behavior. |
| src/Xping.Sdk.Core/Extensions/XpingServiceCollectionExtensions.cs | Adds env-var binding and instance-copy support for CiEnvironmentName. |
| src/Xping.Sdk.Core/Configuration/XpingConfigurationBuilder.cs | Adds fluent builder API WithCiEnvironmentName. |
| src/Xping.Sdk.Core/Configuration/XpingConfiguration.cs | Adds CiEnvironmentName, introduces explicit-environment tracking, and updates Environment semantics. |
| docs/getting-started/ci-cd-setup.md | Documents normalized branch capture and CI environment label customization. |
| docs/configuration/configuration-reference.md | Documents new configuration option and updated precedence rules. |
…c consistency - Guard target.Environment assignment in CopyConfiguration with HasExplicitEnvironment check to prevent overwriting ASPNETCORE_ENVIRONMENT/DOTNET_ENVIRONMENT precedence - Rename _ciVariables to _environmentVariables and add XPING_ENVIRONMENT, ASPNETCORE_ENVIRONMENT, DOTNET_ENVIRONMENT to cleanup list to prevent flaky tests - Fix YAML example in ci-cd-setup.md to use single underscore (XPING_CIENVIRONMENTNAME) instead of double underscore which is not the SDK custom binding format
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
xping-admin
approved these changes
May 10, 2026
xping-admin
approved these changes
May 10, 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.
The SDK’s environment detection was skipping framework environment variables in practice and did not clearly distinguish local developer-machine runs from CI executions. This change corrects the precedence logic, makes CI labeling configurable, and normalizes captured CI branch metadata.
Environment resolution
ASPNETCORE_ENVIRONMENT/DOTNET_ENVIRONMENTare used when no explicit Xping environment override is set.XPING_ENVIRONMENTas the highest-priority override.CiEnvironmentName/XPING_CIENVIRONMENTNAMEinstead of hardcodingCI.Execution context metadata
ExecutionContextcustom property withCIorLocal.IsDeveloperMachine=truefor clearer local/developer-machine classification.CI metadata normalization
CI.Branchacross supported CI providers.GITHUB_HEAD_REF, thenGITHUB_REF_NAME, then normalizedGITHUB_REF.CI.HeadBranch/CI.BaseBranchfor GitHub Actions and improves GitLab/Azure branch capture.Configuration surface
XpingConfiguration, builder APIs, and env-var binding to support configurable CI environment labels.Documentation
Example:
With this behavior:
XPING_ENVIRONMENTstill wins if set."BuildPipeline"instead of hardcoded"CI".ASPNETCORE_ENVIRONMENT/DOTNET_ENVIRONMENTcan now determine the environment name before falling back toLocal.Original prompt
Start implementation
The user has attached the following file paths as relevant context:
- .github/copilot-instructions.md
- AGENTS.md
[Chronological Review: The conversation began with the user requesting an investigation into how the Xping SDK determines if it runs in a CI environment versus a local machine. The user also inquired about how the SDK identifies if it is running on a developer's machine and retrieves CI variables like branch names. Following this, the user requested an implementation plan to address the identified gaps and to update related documentation for configurability. Finally, the user initiated the implementation phase.][Intent Mapping:
[Technical Inventory:
[Code Archaeology:
[Progress Assessment:
[Context Validation: All necessary context for continuing work on the SDK's environment detection and documentation updates is captured.]
[Recent Commands Analysis:
1. Conversation Overview: - Primary Objectives: - "I want you to investigate how SDK determines if SDK runs in CI vs Local machine?" - "Create implementation plan for this gap." - "Add into a plan to update related documentation for configurability." - "Start implementation." - Session Context: The conversation flowed from investigation requests to planning and finally to the initiation of implementation. - User Intent Evolution: The user transitioned from seeking information to planning and executing the implementation.- Technical Foundation:
- Xping SDK: A toolkit for software development that requires environment differentiation.
- EnvironmentInfo.cs: The file under modification to implement environment detection logic.
- Codebase Status:
- File Name: EnvironmentInfo.cs
- Purpose: Contains logic for determining the environment in which the SDK is running.
- Current State: Focus on lines 75 to 79, which are likely related to environment detection.
- Key Code Segments: Specific functions or classes were not detailed but are critical for the implementation.
- Dependencies: This file's logic is essential for the overall functionality of the SDK.
- Problem Resolution:
- Issues Encountered: Need for clarity on environment detection and CI variable retrieval.
- Solutions Implemented: User has outlined steps for investigation and documentation.
- Debugging Context: No specific debugging issues were mentioned.
- Lessons Learned: Understanding of environment detection is crucial for SDK functionality.
- Progress Tracking:
- Completed Tasks: User has defined the scope of investigation and planning.
- Partially Complete Work: Implementation of findings and documentation updates are pending.
- Validated Outcomes: No specific outcomes validated yet as implementation has just begun.
- Active Work State:
- Current Focus: Implementation of environment detection logic in EnvironmentInfo.cs.
- Recent Context: User has been working on the implementation and has just initiated it.
- Working Code: Specific code snippets were not provided but are being modified in the current file.
- Immediate Context: User is focused on implementing the logic to determine if the SDK is running in CI or locally.
- Recent Operations:
- Last Agent Commands: User requested to start implementation.
- Tool Results Summary: No specific tool results were returned; focus was on user commands.
- Pre-Summary State: The agent was actively working on the implementation of the environment detection logic.
- Operation Context: The commands executed were directly related to enhancing the SDK's functiona...
Created from VS Code.