Skip to content

feat(ClientTesting): Add way to differentiate between local, CI, and librarian environments - #16104

Open
efevans wants to merge 1 commit into
googleapis:mainfrom
efevans:environment-differentiation
Open

efevans wants to merge 1 commit into
googleapis:mainfrom
efevans:environment-differentiation

Conversation

@efevans

@efevans efevans commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

b/580033155

@efevans
efevans requested a review from a team as a code owner November 13, 2026 20:57

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces environment-based test skipping capabilities by adding support for CI, Librarian, and local environments. It defines new environment variable constants, helper methods to detect these environments, and corresponding skip methods. The feedback suggests ensuring that these new skip methods respect the MUST_NOT_SKIP_TESTS environment variable so developers can force-run tests when debugging. Additionally, the helper method IsEnvironmentVariableSet should be updated to check for an explicit 'true' value case-insensitively, preventing unexpected behavior when variables are set to 'false'.

@efevans efevans changed the title feat(ClientTesting): Add CI, Librarian, and local environment helpers feat(ClientTesting): Add way to differentiate between local, CI, and librarian environments Nov 16, 2026
@efevans
efevans marked this pull request as draft November 30, 2026 20:20
@efevans
efevans force-pushed the environment-differentiation branch 2 times, most recently from c8793f1 to 4e361cb Compare November 30, 2026 20:29
@efevans

efevans commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/gemini

@efevans
efevans force-pushed the environment-differentiation branch 2 times, most recently from 3f9fcb5 to a97fb92 Compare November 30, 2026 20:48
@efevans
efevans marked this pull request as ready for review November 30, 2026 20:51
@efevans
efevans force-pushed the environment-differentiation branch 2 times, most recently from 45156e5 to 7e4b6ee Compare November 30, 2026 23:48
Add IsCiEnvironment, IsLibrarianEnvironment, IsLocalEnvironment, and
corresponding SkipOn* methods to TestEnvironment so tests can
distinguish between Kokoro CI, Librarian, and local runs.

Also default GOOGLE_CLOUD_DOTNET_TEST_ENV=librarian for build-library and
integration-test-library in pipeline-config.json so tests running inside
Librarian containers can detect the Librarian environment.
@efevans
efevans force-pushed the environment-differentiation branch from 7e4b6ee to ddff971 Compare December 1, 2026 18:17
{
"name": "GOOGLE_CLOUD_DOTNET_TEST_ENV",
"defaultValue": "librarian"
}

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.

I don't think this is right, there's no guarantee that something using this file is running in librarian. For the jobs that run in librarian, we should inject the environment variables on those jobs.

public const string GoogleCloudTestsInVpcScEnvironmentVariable = "GOOGLE_CLOUD_TESTS_IN_VPCSC";
public const string GoogleCloudTestEnvEnvironmentVariable = "GOOGLE_CLOUD_DOTNET_TEST_ENV";
public const string LibrarianRepositoryEnvironmentVariable = "LIBRARIAN_REPOSITORY";
public const string CiEnvironment = "ci";

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.

Suggested change
public const string CiEnvironment = "ci";
public const string CIEnvironment = "ci";

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.

Are you missing dev.

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.

And maybe, let's talk about these values more. Maybe instead of librarian, ci and dev we have values for what's actually restricted on each, e.g. no-service-account. Let's discuss internally in the bug, which are all the ways in which we are restricted?

/// Returns true if the tests are running in a CI environment
/// (detected by the <c>GOOGLE_CLOUD_DOTNET_TEST_ENV</c> environment variable value <c>ci</c>).
/// </summary>
public static bool IsCiEnvironment() =>

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.

Suggested change
public static bool IsCiEnvironment() =>
public static bool IsCIEnvironment() =>


/// <summary>
/// Returns true if the tests are running in a local environment
/// (detected as not being in CI or Librarian environments).

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.

Let's have a specific value for this.

@@ -77,6 +81,33 @@ public static string GetProjectLocationId()
/// </summary>
public static bool IsRestrictedEnvironment() => string.IsNullOrEmpty(Environment.GetEnvironmentVariable(GoogleApplicationCredentialsEnvironmentVariable));

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.

Can we maybe remove this one now, or after?

This branch has not been deployed

No deployments
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