Skip to content

Simplify in-process env isolation to snapshot/restore#1929

Merged
SteveSandersonMS merged 1 commit into
mainfrom
stevesa/simplify-inprocess-env-isolation
Jul 7, 2026
Merged

Simplify in-process env isolation to snapshot/restore#1929
SteveSandersonMS merged 1 commit into
mainfrom
stevesa/simplify-inprocess-env-isolation

Conversation

@SteveSandersonMS

Copy link
Copy Markdown
Contributor

Simplifies the E2E test environment-variable isolation machinery (InProcessEnvIsolation.cs).

What changed

  • Blanket load-time snapshot + restore. Replaces the targeted per-name pristine tracking (s_pristineByName, Mirror/Restore) with a single environment snapshot captured at assembly load ([ModuleInitializer]) and restored after every test. The snapshot must be load-time because the shared IClassFixture mirrors per-test env onto the process before the first test's Before hook runs.
  • Unconditional attribute. The assembly-level InProcessEnvIsolationAttribute now neutralizes ambient credentials before each test and restores the full environment afterwards regardless of transport. Removed IsActive and the per-test / fixture-teardown Restore() backstops in E2ETestContext (restoration is now centralized). The graceful-vs-force stop decision in StopClientForCleanupAsync inlines its own connection check.
  • Consistent null handling. The snapshot holds string?; null uniformly means "unset" (no coercion to ""). Credential suppression now unsets rather than blanking.
  • Cleanup. CaptureEnvironment is a one-line LINQ projection; SuppressEnvVars renamed from LeakyCredentialVars; comments trimmed.

Verification

  • Build clean (0 warnings).
  • Selected in-process E2E tests pass, including all 29 ClientE2ETests with a simulated ambient COPILOT_HMAC_KEY set (confirms neutralization prevents live-API auth).

This is still TEMPORARY test-only scaffolding — the whole file is deletable once the runtime stops reading the ambient process environment host-side over the in-process FFI transport.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@github-actions

This comment has been minimized.

@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/simplify-inprocess-env-isolation branch from 4c27c48 to 4c3e781 Compare July 7, 2026 09:16
@github-actions

This comment has been minimized.

@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/simplify-inprocess-env-isolation branch from 4c3e781 to f0084e2 Compare July 7, 2026 09:21
@github-actions

This comment has been minimized.

Replace the targeted per-name pristine tracking (s_pristineByName,
Mirror/Restore) with a blanket load-time environment snapshot restored
after every test. The attribute now blanks leaky CI credentials before
each test and reverts the whole process environment afterwards,
regardless of transport, so per-test mirrors and fixture-teardown
backstops in E2ETestContext are no longer needed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/simplify-inprocess-env-isolation branch from f0084e2 to 8d191fd Compare July 7, 2026 09:27
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

All 4 changed files (dotnet/test/AssemblyInfo.cs, dotnet/test/Harness/E2ETestContext.cs, dotnet/test/Harness/InProcessEnvIsolation.cs, dotnet/test/Harness/ModuleInitializerAttribute.cs) are scoped entirely to the .NET test harness — no production SDK code or public APIs are touched.

Since this is a test-infrastructure refactoring (snapshot/restore of env vars) with no API surface changes, there are no cross-language consistency concerns. Each SDK manages its own test isolation independently, and these changes don't introduce any feature parity gaps.

Generated by SDK Consistency Review Agent for issue #1929 · sonnet46 361.3K ·

@SteveSandersonMS SteveSandersonMS marked this pull request as ready for review July 7, 2026 09:45
@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner July 7, 2026 09:45
Copilot AI review requested due to automatic review settings July 7, 2026 09:45
@SteveSandersonMS SteveSandersonMS merged commit 34e89cd into main Jul 7, 2026
27 checks passed
@SteveSandersonMS SteveSandersonMS deleted the stevesa/simplify-inprocess-env-isolation branch July 7, 2026 09:45

Copilot AI 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 simplifies the .NET E2E test harness’s process environment isolation for the in-process (FFI) transport by taking a single “ambient environment” snapshot at assembly load and restoring that snapshot after each test via an assembly-level xUnit attribute.

Changes:

  • Added a net472 polyfill for [ModuleInitializer] so the harness can snapshot environment at module load across TFMs.
  • Replaced per-variable pristine tracking with a single load-time snapshot plus per-test restore, and updated credential suppression to unset variables.
  • Centralized env restore behavior in the InProcessEnvIsolationAttribute, removing the fixture-level restore backstops and simplifying cleanup logic.
Show a summary per file
File Description
dotnet/test/Harness/ModuleInitializerAttribute.cs Adds a net472 [ModuleInitializer] attribute polyfill to support assembly-load snapshotting.
dotnet/test/Harness/InProcessEnvIsolation.cs Implements load-time env snapshot + per-test restore; updates suppression/restore mechanics and xUnit hook.
dotnet/test/Harness/E2ETestContext.cs Switches mirroring to Apply(...) and removes explicit restore calls from cleanup/teardown paths.
dotnet/test/AssemblyInfo.cs Keeps assembly-level env isolation attribute, trimming now-obsolete commentary.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment on lines +290 to +294
// Restored after each test by InProcessEnvIsolationAttribute. Harmless for
// child-process transports, which configure their child's environment.
foreach (var (name, value) in options.Environment)
{
foreach (var (name, value) in options.Environment)
{
InProcessEnvIsolation.Mirror(name, value);
}
InProcessEnvIsolation.Apply(name, value);
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