Skip to content

Fix environment detection precedence and normalize CI/local execution metadata#105

Merged
xping-admin merged 5 commits into
mainfrom
copilot/implement-environment-detection
May 10, 2026
Merged

Fix environment detection precedence and normalize CI/local execution metadata#105
xping-admin merged 5 commits into
mainfrom
copilot/implement-environment-detection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

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

    • Fixes environment-name precedence so ASPNETCORE_ENVIRONMENT / DOTNET_ENVIRONMENT are used when no explicit Xping environment override is set.
    • Preserves XPING_ENVIRONMENT as the highest-priority override.
    • Adds configurable CI environment naming via CiEnvironmentName / XPING_CIENVIRONMENTNAME instead of hardcoding CI.
  • Execution context metadata

    • Adds ExecutionContext custom property with CI or Local.
    • Marks non-CI, non-container runs with IsDeveloperMachine=true for clearer local/developer-machine classification.
  • CI metadata normalization

    • Normalizes branch capture into CI.Branch across supported CI providers.
    • Improves GitHub Actions metadata by preferring GITHUB_HEAD_REF, then GITHUB_REF_NAME, then normalized GITHUB_REF.
    • Adds CI.HeadBranch / CI.BaseBranch for GitHub Actions and improves GitLab/Azure branch capture.
  • Configuration surface

    • Extends XpingConfiguration, builder APIs, and env-var binding to support configurable CI environment labels.
  • Documentation

    • Updates configuration and CI/CD docs to reflect the corrected precedence, configurable CI naming, and normalized branch metadata.

Example:

var config = new XpingConfigurationBuilder()
    .WithEnvironment("Staging")
    .WithAutoDetectCIEnvironment(true)
    .WithCiEnvironmentName("BuildPipeline")
    .Build();

With this behavior:

  • XPING_ENVIRONMENT still wins if set.
  • In CI, auto-detection uses "BuildPipeline" instead of hardcoded "CI".
  • Outside CI, ASPNETCORE_ENVIRONMENT / DOTNET_ENVIRONMENT can now determine the environment name before falling back to Local.
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:

  1. "I want you to investigate how SDK determines if SDK runs in CI vs Local machine?" - User seeks understanding of SDK's environment detection.
  2. "Create implementation plan for this gap." - User requests a structured approach to address the identified gaps.
  3. "Add into a plan to update related documentation for configurability." - User wants to ensure documentation reflects the new implementation.
  4. "Start implementation." - User indicates readiness to begin coding.]

[Technical Inventory:

  • Xping SDK: A software development kit that needs to differentiate between CI and local environments.
  • EnvironmentInfo.cs: The file currently being modified, likely containing logic for environment detection.]

[Code Archaeology:

  • File: EnvironmentInfo.cs
  • Recent focus on lines 75 to 79, which may contain relevant code for environment detection.]

[Progress Assessment:

  • Completed: User has outlined the need for investigation and documentation updates.
  • Pending: Implementation of the investigation findings and documentation updates.]

[Context Validation: All necessary context for continuing work on the SDK's environment detection and documentation updates is captured.]

[Recent Commands Analysis:

  • Last Agent Commands: User requested to start implementation.
  • Tool Results Summary: No specific tool results were returned as the focus was on user commands.
  • Pre-Summary State: The agent was actively working on the implementation of the environment detection logic in EnvironmentInfo.cs.
  • Operation Context: The commands executed were directly related to the user's goal of enhancing the SDK's functionality and ensuring proper documentation.]
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.
  1. Technical Foundation:
  • Xping SDK: A toolkit for software development that requires environment differentiation.
  • EnvironmentInfo.cs: The file under modification to implement environment detection logic.
  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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.

Copilot AI and others added 3 commits May 10, 2026 09:11
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
Copilot AI requested a review from xping-admin May 10, 2026 09:17
@xping-admin xping-admin requested a review from Copilot May 10, 2026 10:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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 Environment from default/fallback values and allowing ASPNETCORE_ENVIRONMENT / DOTNET_ENVIRONMENT to take effect when appropriate.
  • Adds CiEnvironmentName configuration (including builder + env-var binding) to customize the environment label used for auto-detected CI runs.
  • Normalizes execution metadata by introducing ExecutionContext (CI/Local), IsDeveloperMachine for local non-container runs, and CI.Branch normalization (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.

Comment thread src/Xping.Sdk.Core/Extensions/XpingServiceCollectionExtensions.cs Outdated
Comment thread tests/Xping.Sdk.Core.Tests/Services/Environment/EnvironmentDetectorTests.cs Outdated
Comment thread docs/getting-started/ci-cd-setup.md Outdated
…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
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 63.63636% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...vices/Environment/Internals/EnvironmentDetector.cs 51.51% 10 Missing and 6 partials ⚠️
Files with missing lines Coverage Δ
...Xping.Sdk.Core/Configuration/XpingConfiguration.cs 100.00% <100.00%> (ø)
...dk.Core/Configuration/XpingConfigurationBuilder.cs 96.22% <100.00%> (+0.14%) ⬆️
...ore/Extensions/XpingServiceCollectionExtensions.cs 96.58% <100.00%> (+0.05%) ⬆️
...vices/Environment/Internals/EnvironmentDetector.cs 40.14% <51.51%> (+5.42%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xping-admin xping-admin marked this pull request as ready for review May 10, 2026 20:02
@xping-admin xping-admin merged commit b6beb87 into main May 10, 2026
2 of 3 checks passed
@xping-admin xping-admin deleted the copilot/implement-environment-detection branch May 10, 2026 20:03
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