Skip to content

Commit 9705707

Browse files
committed
Gate SEP-2243 conformance tests on harness version >= 0.1.16
The http-standard-headers, http-custom-headers, and http-invalid-tool-headers client scenarios and http-header-validation, http-custom-header-server-validation server scenarios require conformance package >= 0.1.16 which is not yet published to npm. Add NodeHelpers.GetConformanceVersion() that runs 'conformance --version' and NodeHelpers.IsConformanceVersionAtLeast() for runtime version checks. Tests auto-skip when the harness is too old and auto-run once the package is updated. Works with both npm-published and local file: references.
1 parent ef7281a commit 9705707

3 files changed

Lines changed: 94 additions & 3 deletions

File tree

tests/Common/Utils/NodeHelpers.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,82 @@ public static ProcessStartInfo ConformanceTestStartInfo(string arguments)
133133
return startInfo;
134134
}
135135

136+
/// <summary>
137+
/// Gets the installed conformance package version by running 'conformance --version'.
138+
/// Returns null if the version cannot be determined.
139+
/// </summary>
140+
public static Version? GetConformanceVersion()
141+
{
142+
if (!IsNodeInstalled())
143+
{
144+
return null;
145+
}
146+
147+
try
148+
{
149+
EnsureNpmDependenciesInstalled();
150+
var repoRoot = FindRepoRoot();
151+
var binPath = Path.Combine(repoRoot, "node_modules", ".bin", "conformance");
152+
153+
ProcessStartInfo startInfo;
154+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
155+
{
156+
startInfo = new ProcessStartInfo
157+
{
158+
FileName = $"{binPath}.cmd",
159+
Arguments = "--version",
160+
RedirectStandardOutput = true,
161+
RedirectStandardError = true,
162+
UseShellExecute = false,
163+
CreateNoWindow = true
164+
};
165+
}
166+
else
167+
{
168+
startInfo = new ProcessStartInfo
169+
{
170+
FileName = binPath,
171+
Arguments = "--version",
172+
RedirectStandardOutput = true,
173+
RedirectStandardError = true,
174+
UseShellExecute = false,
175+
CreateNoWindow = true
176+
};
177+
}
178+
179+
using var process = Process.Start(startInfo);
180+
if (process == null)
181+
{
182+
return null;
183+
}
184+
185+
var output = process.StandardOutput.ReadToEnd().Trim();
186+
process.WaitForExit(10_000);
187+
188+
if (process.ExitCode == 0 && Version.TryParse(output, out var version))
189+
{
190+
return version;
191+
}
192+
193+
return null;
194+
}
195+
catch
196+
{
197+
return null;
198+
}
199+
}
200+
201+
/// <summary>
202+
/// Checks if the installed conformance package version is at least the specified minimum.
203+
/// </summary>
204+
public static bool IsConformanceVersionAtLeast(string minimumVersion)
205+
{
206+
var installed = GetConformanceVersion();
207+
return installed != null
208+
&& Version.TryParse(minimumVersion, out var min)
209+
&& installed >= min;
210+
}
211+
136212
/// <summary>
137213
/// Checks if Node.js is installed and available on the system.
138214
/// </summary>

tests/ModelContextProtocol.AspNetCore.Tests/ClientConformanceTests.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class ClientConformanceTests
1717
// Public static property required for SkipUnless attribute
1818
public static bool IsNodeInstalled => NodeHelpers.IsNodeInstalled();
1919

20+
// SEP-2243 scenarios require conformance package >= 0.1.16
21+
public static bool HasSep2243Scenarios => NodeHelpers.IsConformanceVersionAtLeast("0.1.16");
22+
2023
public ClientConformanceTests(ITestOutputHelper output)
2124
{
2225
_output = output;
@@ -51,12 +54,22 @@ public ClientConformanceTests(ITestOutputHelper output)
5154
// [InlineData("auth/client-credentials-jwt")]
5255
// [InlineData("auth/client-credentials-basic")]
5356

54-
// HTTP Standardization (SEP-2243)
57+
public async Task RunConformanceTest(string scenario)
58+
{
59+
// Run the conformance test suite
60+
var result = await RunClientConformanceScenario(scenario);
61+
62+
// Report the results
63+
Assert.True(result.Success,
64+
$"Conformance test failed.\n\nStdout:\n{result.Output}\n\nStderr:\n{result.Error}");
65+
}
66+
67+
// HTTP Standardization (SEP-2243) — requires conformance package >= 0.1.16
68+
[Theory(Skip = "Conformance package >= 0.1.16 not available.", SkipUnless = nameof(HasSep2243Scenarios))]
5569
[InlineData("http-standard-headers")]
5670
[InlineData("http-custom-headers")]
5771
[InlineData("http-invalid-tool-headers")]
58-
59-
public async Task RunConformanceTest(string scenario)
72+
public async Task RunConformanceTest_Sep2243(string scenario)
6073
{
6174
// Run the conformance test suite
6275
var result = await RunClientConformanceScenario(scenario);

tests/ModelContextProtocol.AspNetCore.Tests/ServerConformanceTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public async Task RunPendingConformanceTest_ServerSsePolling()
131131
public async Task RunConformanceTest_HttpHeaderValidation()
132132
{
133133
Assert.SkipWhen(!NodeHelpers.IsNodeInstalled(), "Node.js is not installed. Skipping conformance tests.");
134+
Assert.SkipWhen(!NodeHelpers.IsConformanceVersionAtLeast("0.1.16"), "Conformance package >= 0.1.16 not available.");
134135

135136
var result = await RunConformanceTestsAsync($"server --url {fixture.ServerUrl} --scenario http-header-validation");
136137

@@ -142,6 +143,7 @@ public async Task RunConformanceTest_HttpHeaderValidation()
142143
public async Task RunConformanceTest_HttpCustomHeaderServerValidation()
143144
{
144145
Assert.SkipWhen(!NodeHelpers.IsNodeInstalled(), "Node.js is not installed. Skipping conformance tests.");
146+
Assert.SkipWhen(!NodeHelpers.IsConformanceVersionAtLeast("0.1.16"), "Conformance package >= 0.1.16 not available.");
145147

146148
var result = await RunConformanceTestsAsync($"server --url {fixture.ServerUrl} --scenario http-custom-header-server-validation");
147149

0 commit comments

Comments
 (0)