Skip to content

Commit 38d3b34

Browse files
mitchdennyCopilot
andauthored
Use xUnit test method name for CLI E2E recording filenames (#17484)
Resolves bug #1 of the two root causes that left CLI E2E recordings tagged as Unknown in the PR recording-comment. CliE2ETestHelpers.CreateTestTerminal / CreateDockerTestTerminal / CreatePodmanDockerTestTerminal (and the shared Hex1bTestHelpers.CreateTestTerminal) use [CallerMemberName] to pick the .cast filename. When a public [Fact] is a thin wrapper that delegates into a private helper — e.g. DashboardRunWithAgentMcpListTracesReturnsNoTraces => DashboardRunWithAgentMcpCore in DashboardRunTests, or the *Core helper in AgentMcpLogsTests — [CallerMemberName] captures the helper. The .cast file ends up named after the helper, the TRX has no entry for that name, and the recording-comment workflow's lookup falls through to Unknown on every PR. Fix: prefer TestContext.Current?.TestCase?.TestMethodName when running inside a live xUnit test context, fall back to the [CallerMemberName] default otherwise. The public API surface is unchanged (no caller passes testName explicitly), so the recording filenames quietly flip from 'DashboardRunWithAgentMcpCore' to the public test name with no test-side edits required. The companion workflow-side fix for the second root cause (jq splitting on '.' inside theory parameters before stripping the param suffix) ships in a follow-up commit on the same PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 35d7585 commit 38d3b34

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

tests/Aspire.Cli.EndToEnd.Tests/Helpers/CliE2ETestHelpers.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ internal static string GetTestResultsRecordingPath(string testName)
9393
return Hex1bTestHelpers.GetTestResultsRecordingPath(testName, "aspire-cli-e2e");
9494
}
9595

96+
/// <summary>
97+
/// Resolves the test method name for naming a recording file. See
98+
/// <see cref="Hex1bTestHelpers.ResolveTestMethodName"/> for the full rationale.
99+
/// </summary>
100+
private static string ResolveTestMethodName(string callerMemberName)
101+
=> Hex1bTestHelpers.ResolveTestMethodName(callerMemberName);
102+
96103
/// <summary>
97104
/// Creates a headless Hex1b terminal configured for E2E testing with asciinema recording.
98105
/// Uses default dimensions of 160x48 unless overridden.
@@ -103,7 +110,14 @@ internal static string GetTestResultsRecordingPath(string testName)
103110
/// <returns>A configured <see cref="Hex1bTerminal"/> instance. Caller is responsible for disposal.</returns>
104111
internal static Hex1bTerminal CreateTestTerminal(int width = 160, int height = 48, [CallerMemberName] string testName = "")
105112
{
106-
var recordingPath = GetTestResultsRecordingPath(testName);
113+
// Prefer the xUnit-reported test method name so that when a [Fact]/[Theory]
114+
// delegates into a private helper (e.g. *Core methods), the .cast file is
115+
// still named after the public test the TRX records an outcome for. Without
116+
// this, `[CallerMemberName]` captures the helper, the recording filename has
117+
// no matching TRX entry, and the recording-comment workflow tags the test as
118+
// "Unknown".
119+
var resolvedTestName = ResolveTestMethodName(testName);
120+
var recordingPath = GetTestResultsRecordingPath(resolvedTestName);
107121
RegisterCaptureFile("recording.cast", recordingPath);
108122
return Hex1bTerminal.CreateBuilder()
109123
.WithHeadless()
@@ -162,6 +176,9 @@ internal static Hex1bTerminal CreateDockerTestTerminal(
162176
int height = 48,
163177
[CallerMemberName] string testName = "")
164178
{
179+
// See CreateTestTerminal above for why we prefer the xUnit-reported test
180+
// method name over `[CallerMemberName]`.
181+
testName = ResolveTestMethodName(testName);
165182
var recordingPath = GetTestResultsRecordingPath(testName);
166183
RegisterCaptureFile("recording.cast", recordingPath);
167184
var dockerfilePath = GetDockerfilePath(repoRoot, variant);
@@ -334,6 +351,9 @@ internal static Hex1bTerminal CreatePodmanDockerTestTerminal(
334351
int height = 48,
335352
[CallerMemberName] string testName = "")
336353
{
354+
// See CreateTestTerminal above for why we prefer the xUnit-reported test
355+
// method name over `[CallerMemberName]`.
356+
testName = ResolveTestMethodName(testName);
337357
var recordingPath = GetTestResultsRecordingPath(testName);
338358
RegisterCaptureFile("recording.cast", recordingPath);
339359

tests/Shared/Hex1bTestHelpers.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ internal static Hex1bTerminal CreateTestTerminal(
8989
int height = 48,
9090
[CallerMemberName] string testName = "")
9191
{
92+
// Prefer the xUnit-reported test method name so that when a [Fact]/[Theory]
93+
// delegates into a private helper (e.g. *Core methods), the .cast file is
94+
// still named after the public test the TRX records an outcome for. The CLI
95+
// E2E recording-comment workflow joins .cast files to TRX outcomes by name;
96+
// when the helper name leaks in via `[CallerMemberName]`, no TRX entry
97+
// matches and the test ends up tagged "Unknown" on every PR.
98+
testName = ResolveTestMethodName(testName);
9299
var recordingPath = GetTestResultsRecordingPath(testName, localSubDir);
93100

94101
var builder = Hex1bTerminal.CreateBuilder()
@@ -128,6 +135,20 @@ internal static string GetTestResultsRecordingPath(string testName, string local
128135
return Path.Combine(recordingsDir, $"{testName}.cast");
129136
}
130137

138+
/// <summary>
139+
/// Resolves the test method name for naming a recording file. Prefers the xUnit-reported
140+
/// <c>TestContext.Current.TestCase.TestMethodName</c> when running inside a live test
141+
/// context, so a recording created from inside a private helper still gets named after
142+
/// the public <c>[Fact]</c>/<c>[Theory]</c> that the TRX records an outcome for. Falls
143+
/// back to the <see cref="CallerMemberNameAttribute"/>-supplied name when no test context
144+
/// is available.
145+
/// </summary>
146+
internal static string ResolveTestMethodName(string callerMemberName)
147+
{
148+
var fromXunit = Xunit.TestContext.Current?.TestCase?.TestMethodName;
149+
return !string.IsNullOrEmpty(fromXunit) ? fromXunit : callerMemberName;
150+
}
151+
131152
/// <summary>
132153
/// Waits for a successful command prompt with the expected sequence number.
133154
/// </summary>

0 commit comments

Comments
 (0)