Skip to content

Commit 7d08ec2

Browse files
mikekistlerstephentoub
authored andcommitted
Add test to make sure all client conformance tests are covered
1 parent 10e4f5b commit 7d08ec2

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

tests/ModelContextProtocol.AspNetCore.Tests/ClientConformanceTests.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,82 @@ public ClientConformanceTests(ITestOutputHelper output)
2121
_output = output;
2222
}
2323

24+
// Expected scenarios based on InlineData attributes below
25+
private static readonly string[] ExpectedScenarios = [
26+
"initialize",
27+
"tools_call",
28+
"elicitation-sep1034-client-defaults",
29+
"sse-retry",
30+
"auth/metadata-default",
31+
"auth/metadata-var1",
32+
"auth/metadata-var2",
33+
"auth/metadata-var3",
34+
"auth/basic-cimd",
35+
"auth/2025-03-26-oauth-metadata-backcompat", // Expected but not required to pass
36+
"auth/2025-03-26-oauth-endpoint-fallback", // Expected but not required to pass
37+
"auth/scope-from-www-authenticate",
38+
"auth/scope-from-scopes-supported",
39+
"auth/scope-omitted-when-undefined",
40+
"auth/scope-step-up",
41+
"auth/scope-retry-limit",
42+
"auth/token-endpoint-auth-basic",
43+
"auth/token-endpoint-auth-post",
44+
"auth/token-endpoint-auth-none",
45+
"auth/resource-mismatch",
46+
"auth/pre-registration",
47+
"auth/client-credentials-jwt",
48+
"auth/client-credentials-basic"
49+
];
50+
51+
[Fact(Skip = "npx is not installed. Skipping client conformance tests.", SkipUnless = nameof(IsNpxInstalled))]
52+
public async Task VerifyAllConformanceTestsAreListed()
53+
{
54+
// Get the list of available conformance tests from the suite
55+
var startInfo = NodeHelpers.NpxStartInfo("-y @modelcontextprotocol/conformance list --client");
56+
57+
var outputBuilder = new StringBuilder();
58+
var process = new Process { StartInfo = startInfo };
59+
60+
process.OutputDataReceived += (sender, e) =>
61+
{
62+
if (e.Data != null)
63+
{
64+
outputBuilder.AppendLine(e.Data);
65+
}
66+
};
67+
68+
process.Start();
69+
process.BeginOutputReadLine();
70+
await process.WaitForExitAsync(TestContext.Current.CancellationToken);
71+
72+
Assert.True(process.ExitCode == 0, "Failed to list conformance tests");
73+
74+
var output = outputBuilder.ToString();
75+
var availableScenarios = output
76+
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
77+
.Select(line => line.Trim())
78+
.Where(line => line.StartsWith("- "))
79+
.Select(line => line.Substring(2).Trim())
80+
.ToHashSet();
81+
82+
// Verify all expected scenarios are available
83+
var missingScenarios = ExpectedScenarios.Except(availableScenarios).ToList();
84+
Assert.Empty(missingScenarios);
85+
86+
// Verify we haven't missed any new scenarios
87+
var newScenarios = availableScenarios.Except(ExpectedScenarios).ToList();
88+
if (newScenarios.Any())
89+
{
90+
var newScenariosMessage = string.Join("\r\n - ", newScenarios);
91+
Assert.Fail($"New conformance scenarios detected. Add these to ExpectedScenarios and the Theory:\r\n - {newScenariosMessage}");
92+
}
93+
}
94+
2495
[Theory(Skip = "npx is not installed. Skipping client conformance tests.", SkipUnless = nameof(IsNpxInstalled))]
2596
[InlineData("initialize")]
2697
[InlineData("tools_call")]
98+
[InlineData("elicitation-sep1034-client-defaults")]
99+
[InlineData("sse-retry")]
27100
[InlineData("auth/metadata-default")]
28101
[InlineData("auth/metadata-var1")]
29102
[InlineData("auth/metadata-var2")]
@@ -35,6 +108,14 @@ public ClientConformanceTests(ITestOutputHelper output)
35108
[InlineData("auth/scope-from-scopes-supported")]
36109
[InlineData("auth/scope-omitted-when-undefined")]
37110
[InlineData("auth/scope-step-up")]
111+
[InlineData("auth/scope-retry-limit")]
112+
[InlineData("auth/token-endpoint-auth-basic")]
113+
[InlineData("auth/token-endpoint-auth-post")]
114+
[InlineData("auth/token-endpoint-auth-none")]
115+
[InlineData("auth/resource-mismatch")]
116+
[InlineData("auth/pre-registration")]
117+
[InlineData("auth/client-credentials-jwt")]
118+
[InlineData("auth/client-credentials-basic")]
38119
public async Task RunConformanceTest(string scenario)
39120
{
40121
// Run the conformance test suite

0 commit comments

Comments
 (0)