Skip to content

Commit 2ebca70

Browse files
kashish2508guptakashish
andauthored
fix(playwrighttesting): handled limitation of character in parameters. (Azure#47608)
* fix(playwrighttesting): handled limitation of character in parameters. * update * update * message update --------- Co-authored-by: guptakashish <[email protected]>
1 parent f3c748c commit 2ebca70

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,14 @@ internal class Constants
215215
internal static readonly string s_invalid_os_error = "Invalid operating system, supported values are 'linux' and 'windows'.";
216216
internal static readonly string s_workspace_mismatch_error = "The provided access token does not match the specified workspace URL. Please verify that both values are correct.";
217217
internal static readonly string s_invalid_service_endpoint_error_message = "The service endpoint provided is invalid. Please verify the endpoint URL and try again.";
218+
internal static readonly string s_playwright_service_runId_length_exceeded_error_message = "Error: The Run Id you provided exceeds 200 characters. Please provide a shorter Run ID.";
218219

219220
internal static readonly string s_playwright_service_disable_scalable_execution_environment_variable = "_MPT_DISABLE_SCALABLE_EXECUTION";
220221
internal static readonly string s_playwright_service_reporting_url_environment_variable = "_MPT_REPORTING_URL";
221222
internal static readonly string s_playwright_service_workspace_id_environment_variable = "_MPT_WORKSPACE_ID";
222223
internal static readonly string s_playwright_service_auth_type_environment_variable = "_MPT_AUTH_TYPE";
224+
225+
internal static readonly string s_playwright_service_runName_truncated_warning = "WARNING: Run name exceeds the maximum limit of 200 characters and will be truncated.";
223226
}
224227

225228
internal class OSConstants

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/PlaywrightReporter.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,26 @@ internal void InitializePlaywrightReporter(string xmlSettings)
150150
_environment.Exit(1);
151151
return;
152152
}
153-
153+
if (cloudRunId?.Length > 200)
154+
{
155+
_consoleWriter.WriteError(Constants.s_playwright_service_runId_length_exceeded_error_message);
156+
_environment.Exit(1);
157+
return;
158+
}
154159
var baseUri = new Uri(baseUrl);
155160
var reporterUtils = new ReporterUtils();
156161
TokenDetails tokenDetails = reporterUtils.ParseWorkspaceIdFromAccessToken(jsonWebTokenHandler: _jsonWebTokenHandler, accessToken: accessToken);
157162
var workspaceId = tokenDetails.aid;
158-
163+
var runNameString = runName?.ToString();
164+
if (runNameString?.Length > 200)
165+
{
166+
runNameString = runNameString.Substring(0, 200);
167+
_consoleWriter.WriteLine(Constants.s_playwright_service_runName_truncated_warning);
168+
}
159169
var cloudRunMetadata = new CloudRunMetadata
160170
{
161171
RunId = cloudRunId,
162-
RunName = runName?.ToString(),
172+
RunName = runNameString,
163173
WorkspaceId = workspaceId,
164174
BaseUri = baseUri,
165175
EnableResultPublish = _enableResultPublish,

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Processor/DataProcessor.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public TestRunDto GetTestRun()
5353
CloudRunEnabled = false,
5454
CiConfig = new CIConfig
5555
{
56-
Branch = _cIInfo.Branch,
57-
Author = _cIInfo.Author,
58-
CommitId = _cIInfo.CommitId,
59-
RevisionUrl = _cIInfo.RevisionUrl,
56+
Branch = ReporterUtils.TruncateData(_cIInfo.Branch, 500),
57+
Author = ReporterUtils.TruncateData(_cIInfo.Author,500),
58+
CommitId = ReporterUtils.TruncateData(_cIInfo.CommitId,500),
59+
RevisionUrl = ReporterUtils.TruncateData(_cIInfo.RevisionUrl,1000),
6060
CiProviderName = _cIInfo.Provider ?? CIConstants.s_dEFAULT
6161
},
6262
TestRunConfig = new ClientConfig // TODO fetch some of these dynamically
@@ -104,16 +104,17 @@ public TestResults GetTestCaseResultData(TestResult? testResultSource)
104104
};
105105
testCaseResultData.TestCombinationId = testCaseResultData.TestExecutionId; // TODO check
106106
testCaseResultData.TestId = testResultSource.TestCase.Id.ToString();
107-
testCaseResultData.TestTitle = testResultSource.TestCase.DisplayName;
107+
testCaseResultData.TestTitle = ReporterUtils.TruncateData(testResultSource.TestCase.DisplayName, 500)!;
108+
testCaseResultData.TestTitle = ReporterUtils.TruncateData(testResultSource.TestCase.DisplayName, 500)!;
108109
var className = FetchTestClassName(testResultSource.TestCase.FullyQualifiedName);
109-
testCaseResultData.SuiteTitle = className;
110+
testCaseResultData.SuiteTitle = ReporterUtils.TruncateData(className,500)!;
110111
testCaseResultData.SuiteId = ReporterUtils.CalculateSha1Hash(className);
111-
testCaseResultData.FileName = FetchFileName(testResultSource.TestCase.Source);
112+
testCaseResultData.FileName = ReporterUtils.TruncateData(FetchFileName(testResultSource.TestCase.Source),300)!;
112113
testCaseResultData.LineNumber = testResultSource.TestCase.LineNumber;
113114
testCaseResultData.Retry = 0; // TODO Retry and PreviousRetries
114115
testCaseResultData.WebTestConfig = new WebTestConfig
115116
{
116-
JobName = _cIInfo.JobId ?? "",
117+
JobName = _cIInfo.JobId != null ? ReporterUtils.TruncateData(_cIInfo.JobId, 500) ?? "" : "",
117118
//ProjectName = "playwright-dotnet", // TODO no project concept NA??
118119
//BrowserName = "chromium", // TODO check if possible to get from test
119120
Os = ReporterUtils.GetCurrentOS(),

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/src/Utility/ReporterUtils.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ internal static string CalculateSha1Hash(string input)
4040
return BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
4141
}
4242
}
43+
internal static string? TruncateData(string? value, int maxLength)
44+
{
45+
if (string.IsNullOrEmpty(value))
46+
return value;
47+
return value?.Length <= maxLength ? value : value?.Substring(0, maxLength);
48+
}
4349

4450
internal static string GetRunName(CIInfo ciInfo)
4551
{

sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/tests/Utility/ReporterUtilsTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,25 @@ public void GetRunName_GitHubActionsPullRequest_ReturnsExpectedValue()
141141
var expected = "PR# 543 on Repo: owner/repo (owner/repo/pull/543)";
142142
Assert.AreEqual(expected, result);
143143
}
144+
[Test]
145+
public void TruncateData_ValueExceedsMaxLength_ReturnsTruncatedString()
146+
{
147+
string value = "This is a very long string that exceeds the maximum length.";
148+
int maxLength = 20;
149+
150+
var result = ReporterUtils.TruncateData(value, maxLength);
151+
152+
Assert.AreEqual("This is a very long ", result);
153+
}
154+
155+
[Test]
156+
public void TruncateData_ValueWithinMaxLength_ReturnsOriginalString()
157+
{
158+
string value = "Short string";
159+
int maxLength = 20;
160+
161+
var result = ReporterUtils.TruncateData(value, maxLength);
162+
163+
Assert.AreEqual(value, result);
164+
}
144165
}

0 commit comments

Comments
 (0)