Simplify in-process env isolation to snapshot/restore#1929
Conversation
This comment has been minimized.
This comment has been minimized.
4c27c48 to
4c3e781
Compare
This comment has been minimized.
This comment has been minimized.
4c3e781 to
f0084e2
Compare
This comment has been minimized.
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>
f0084e2 to
8d191fd
Compare
Cross-SDK Consistency Review ✅All 4 changed files ( 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.
|
There was a problem hiding this comment.
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
| // 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); |
Simplifies the E2E test environment-variable isolation machinery (
InProcessEnvIsolation.cs).What changed
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 sharedIClassFixturemirrors per-test env onto the process before the first test'sBeforehook runs.InProcessEnvIsolationAttributenow neutralizes ambient credentials before each test and restores the full environment afterwards regardless of transport. RemovedIsActiveand the per-test / fixture-teardownRestore()backstops inE2ETestContext(restoration is now centralized). The graceful-vs-force stop decision inStopClientForCleanupAsyncinlines its own connection check.string?;nulluniformly means "unset" (no coercion to""). Credential suppression now unsets rather than blanking.CaptureEnvironmentis a one-line LINQ projection;SuppressEnvVarsrenamed fromLeakyCredentialVars; comments trimmed.Verification
ClientE2ETestswith a simulated ambientCOPILOT_HMAC_KEYset (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