Skip to content

Move Test Config to Jsonc#4297

Draft
benrr101 wants to merge 9 commits into
mainfrom
dev/russellben/config-jsonc
Draft

Move Test Config to Jsonc#4297
benrr101 wants to merge 9 commits into
mainfrom
dev/russellben/config-jsonc

Conversation

@benrr101
Copy link
Copy Markdown
Contributor

Description

As a byproduct of the PR pipeline, I got annoyed with the red squigglies under the comments in the test config.json file. Technically speaking jsonc files support comments while json does not. So, this small PR does the following:

  • Changes the config.default.json file to config.default.jsonc
  • Rewrites the Config.Load logic so that it tries the environment variable path first, config.jsonc second, then config.json before failing.
  • Makes Config class #nullable
  • Sync'd the config.default.json file with the fields that actually exist (and removed unused fields).

Issues

N/A

Testing

Everything builds, but I want to validate with a PR run before taking it out of draft state.

Copilot AI review requested due to automatic review settings May 20, 2026 03:44
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 20, 2026
public string DNSCachingConnString = null;
public string DNSCachingServerCR = null; // this is for the control ring
public string DNSCachingServerTR = null; // this is for the tenant ring
public bool IsAzureSynapse = false; // True for Azure Data Warehouse/Synapse
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed as it is not used.

public string AliasName = null;

public static Config Load(string configPath = @"config.json")
public static Config Load(string configPath)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added as an escape hatch for preserving the behavior of ExtUtilities project. I have plans to remove the ExtUtilities project, so this method will hopefully go away someday.

"WorkloadIdentityFederationServiceConnectionId": "",
"KerberosDomainPassword": "",
"KerberosDomainuser": "",
"IsManagedInstance": false
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields exist in Config class, but did not in the json file.

"SupportsIntegratedSecurity": true,
"LocalDbAppName": "",
"LocalDbSharedInstanceName": "",
"SupportsFileStream": false,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field did not exist in the Config class.

"DNSCachingServerTR": "",
"IsDNSCachingSupportedCR": false,
"IsDNSCachingSupportedTR": false,
"IsAzureSynapse": false,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field existed in the Config class, but was removed since it's unused.

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 test utilities configuration workflow to support JSON-with-comments by moving the default test config to .jsonc, adjusting config-loading precedence, and enabling nullable reference types in the config model.

Changes:

  • Renames the default test config to config.default.jsonc and updates build logic to create/copy config.jsonc.
  • Updates Config.Load behavior to probe config locations in a new order and enables #nullable.
  • Updates ignore rules to exclude config.jsonc from source control.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj Copies default config to config.jsonc and sets output-copy metadata.
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc Updates the sample config content and adds/adjusts fields.
src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs Refactors config load logic, adds jsonc/json probing, and enables nullable annotations.
.gitignore Ignores generated config.jsonc files.
Comments suppressed due to low confidence (3)

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs:96

  • LoadInternal only catches FileNotFoundException. If TEST_MDS_CONFIG (or another attempted path) points to a non-existent directory, StreamReader will throw DirectoryNotFoundException and short-circuit the intended fallback to other locations. Consider treating DirectoryNotFoundException (and possibly other path-related IO exceptions) the same as file-not-found for the multi-location probe.
            try
            {
                using StreamReader sr = new StreamReader(configPath);
                return JsonConvert.DeserializeObject<Config>(sr.ReadToEnd()) ??
                       throw new InvalidOperationException($"Failed to deserialize config from '{configPath}'");
            }
            catch (FileNotFoundException)
            {
                // File did not exist at the path given. We will try a different location.
                return null;
            }

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs:76

  • UpdateConfig still defaults to writing config.json, but Load() now prefers config.jsonc when both exist. This can lead to updating one file while reads continue to use the other. Consider updating the default to config.jsonc, or writing to whichever config file was actually loaded/exists to avoid divergence.
        public static void UpdateConfig(Config updatedConfig, string configPath = @"config.json")
        {
            string config = JsonConvert.SerializeObject(updatedConfig);
            File.WriteAllText(configPath, config);

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc:40

  • Possible typo in the sample config key: KerberosDomainuser doesn't match the KerberosDomainUser field name used in code. Aligning the casing/spelling will make the sample easier to follow (even if deserialization is case-insensitive).

Comment on lines +47 to 52
public static Config Load(string configPath)
{
// Allow an override of the config path via an environment variable.
configPath = Environment.GetEnvironmentVariable("TEST_MDS_CONFIG") ?? configPath;
Config config = LoadInternal(Environment.GetEnvironmentVariable("TEST_MDS_CONFIG")) ??
LoadInternal(configPath) ??
throw new FileNotFoundException("Could not find test configuration file.");

Copilot AI review requested due to automatic review settings May 20, 2026 17:15
@benrr101 benrr101 added this to the 7.1.0-preview2 milestone May 20, 2026
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

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc:40

  • Property name KerberosDomainuser has inconsistent casing vs the code/config consumers (KerberosDomainUser, e.g., Config.KerberosDomainUser and Kerberos pipeline steps). With System.Text.Json’s default case-sensitive matching this won’t bind as intended. Rename the JSON property to KerberosDomainUser (and keep casing consistent for other acronyms, e.g., URL).

Comment on lines +86 to +91
{
if (configPath is null)
{
return null;
}

<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<PackageReference Include="Newtonsoft.Json" />
<None Update="config.jsonc" CopyToOutputDirectory="PreserveNewest" />
Comment thread TESTGUIDE.md
Comment on lines 233 to 237
You can override the config file path with the `MDS_TEST_CONFIG` environment variable:

```bash
MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2
MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2
```
Comment thread .github/instructions/testing.instructions.md
Copilot AI review requested due to automatic review settings May 20, 2026 20:01
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

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Comment thread TESTGUIDE.md
Comment on lines 197 to 199
Edit the source configuration file at `src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/
config.json`. The test utilities project copies that file to the test output directory, where the manual tests load it
config.jsonc`. The test utilities project copies that file to the test output directory, where the manual tests load it
by default.
Comment thread TESTGUIDE.md
Comment on lines 233 to 243
You can override the config file path with the `MDS_TEST_CONFIG` environment variable:

```bash
MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2
MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2
```

On PowerShell:

```powershell
$env:MDS_TEST_CONFIG = "C:\path\to\config.json"
$env:MDS_TEST_CONFIG = "C:\path\to\config.jsonc"
dotnet build -t:TestSqlClientManual -p:TestSet=2
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<PackageReference Include="Newtonsoft.Json" />
<None Update="config.jsonc" CopyToOutputDirectory="PreserveNewest" />
Copilot AI review requested due to automatic review settings May 20, 2026 23:56
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

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

# All properties should be added here, and this template should be used for any manipulation of the config.jsonc file.
- pwsh: |
$jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json
$jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json
Comment on lines 138 to +147
- pwsh: |
$managedSni = [System.Convert]::ToBoolean($env:MANAGED_SNI)
$jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json
$jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json
foreach ($p in $jdata) {
$p.TCPConnectionString = $env:REMOTE_TCP_CONN_STRING
$p.NPConnectionString = $env:REMOTE_NP_CONN_STRING
$p.SupportsIntegratedSecurity = $true
$p.UseManagedSNIOnWindows = $managedSni
}
$jdata | ConvertTo-Json | Set-Content "config.json"
$jdata | ConvertTo-Json | Set-Content "config.jsonc"
Comment on lines 7 to +12
<Target Name="CopyConfig" BeforeTargets="Compile">
<Copy SourceFiles="config.default.json" DestinationFiles="config.json" Condition="!Exists('config.json')" />
<Copy SourceFiles="config.default.jsonc" DestinationFiles="config.jsonc" Condition="!Exists('config.jsonc')" />
</Target>
<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<PackageReference Include="Newtonsoft.Json" />
<None Update="config.jsonc" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Comment on lines +100 to +102
catch (FileNotFoundException)
{
// File did not exist at the path given. We will try a different location.
Comment thread TESTGUIDE.md
Comment on lines 233 to 237
You can override the config file path with the `MDS_TEST_CONFIG` environment variable:

```bash
MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2
MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2
```
Comment thread TESTGUIDE.md
Comment on lines 197 to 199
Edit the source configuration file at `src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/
config.json`. The test utilities project copies that file to the test output directory, where the manual tests load it
config.jsonc`. The test utilities project copies that file to the test output directory, where the manual tests load it
by default.
@benrr101 benrr101 force-pushed the dev/russellben/config-jsonc branch from 5885bb9 to 57e9b41 Compare May 21, 2026 00:09
Copilot AI review requested due to automatic review settings May 21, 2026 15:51
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

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

# All properties should be added here, and this template should be used for any manipulation of the config.jsonc file.
- pwsh: |
$jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json
$jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json
Comment on lines 138 to +147
- pwsh: |
$managedSni = [System.Convert]::ToBoolean($env:MANAGED_SNI)
$jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json
$jdata = Get-Content -Raw "config.default.jsonc" | ConvertFrom-Json
foreach ($p in $jdata) {
$p.TCPConnectionString = $env:REMOTE_TCP_CONN_STRING
$p.NPConnectionString = $env:REMOTE_NP_CONN_STRING
$p.SupportsIntegratedSecurity = $true
$p.UseManagedSNIOnWindows = $managedSni
}
$jdata | ConvertTo-Json | Set-Content "config.json"
$jdata | ConvertTo-Json | Set-Content "config.jsonc"
Comment thread TESTGUIDE.md
Comment on lines 233 to 244
You can override the config file path with the `MDS_TEST_CONFIG` environment variable:

```bash
MDS_TEST_CONFIG=/path/to/config.json dotnet build -t:TestSqlClientManual -p:TestSet=2
MDS_TEST_CONFIG=/path/to/config.jsonc dotnet build -t:TestSqlClientManual -p:TestSet=2
```

On PowerShell:

```powershell
$env:MDS_TEST_CONFIG = "C:\path\to\config.json"
$env:MDS_TEST_CONFIG = "C:\path\to\config.jsonc"
dotnet build -t:TestSqlClientManual -p:TestSet=2
```
Comment on lines +100 to +102
catch (FileNotFoundException)
{
// File did not exist at the path given. We will try a different location.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

3 participants