From 505c4d74afaab96bce4eca149ff318885bdcc581 Mon Sep 17 00:00:00 2001 From: Phil Vendola Date: Wed, 18 Dec 2024 09:03:13 -0500 Subject: [PATCH] Remove parsing errors from empty tags and testsuite names (#241) Baby's first rust PR plz be gentle ## Context See [here](https://trunk-io.slack.com/archives/C044VBASZ0D/p1734365895854939) for the reasoning behind this. TL:DR is that we were reporting parsing errors for files that don't actually have errors that make them unparsable. These errors were: 1. `StackTraceEmpty` - empty stack trace tag 2. `SystemErrEmpty` empty `` 3. `SystemOutEmpty` empty `system-out/>` 4. `TestSuiteName` empty `testsuite name` StackAV was getting a ton of errors from this that we were reporting ## Fix Remove throwing errors relating to these. I left the logic for parsing the tags in there, but just made it so we aren't going to throw an error anymore ## Tests Update tests in order to addresss --- context-js/tests/parse_and_validate.test.ts | 19 +++++++++++++ context-py/tests/test_junit_parse.py | 31 ++++++++++++--------- context/src/junit/parser.rs | 14 ---------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/context-js/tests/parse_and_validate.test.ts b/context-js/tests/parse_and_validate.test.ts index 7e55ed15..8da1d491 100644 --- a/context-js/tests/parse_and_validate.test.ts +++ b/context-js/tests/parse_and_validate.test.ts @@ -68,6 +68,8 @@ describe("context-js", () => { + + @@ -101,6 +103,23 @@ describe("context-js", () => { .all_issues_owned() .filter((issue) => issue.error_type === JunitValidationType.Report), ).toHaveLength(1); + + const nestedJunitXml = ` + + + + + + + + + + `; + + report = junit_parse(Buffer.from(nestedJunitXml, "utf-8")); + junitReportValidation = junit_validate(report[0]); + + expect(junitReportValidation.max_level()).toBe(JunitValidationLevel.Valid); }); it("validates repos", () => { diff --git a/context-py/tests/test_junit_parse.py b/context-py/tests/test_junit_parse.py index beb7ec0f..44062604 100644 --- a/context-py/tests/test_junit_parse.py +++ b/context-py/tests/test_junit_parse.py @@ -19,7 +19,8 @@ def test_junit_parse_valid(): FAILURE BODY - + + @@ -86,22 +87,26 @@ def test_junit_parse_broken_xml(): def test_junit_parse_nested_testsuites(): import typing as PT + from datetime import datetime, timezone from context_py import BindingsReport, BindingsTestCaseStatusStatus, junit_parse - nested_testsuites_xml = b""" + valid_timestamp = datetime.now().astimezone(timezone.utc).isoformat() + + nested_testsuites_xml = f""" - - - - - - - - - """ - - reports: PT.List[BindingsReport] = junit_parse(nested_testsuites_xml) + + + + + + + + + + """ + + reports: PT.List[BindingsReport] = junit_parse(str.encode(nested_testsuites_xml)) assert len(reports) == 1 report = reports[0] diff --git a/context/src/junit/parser.rs b/context/src/junit/parser.rs index 1632e1ba..5059c6e8 100644 --- a/context/src/junit/parser.rs +++ b/context/src/junit/parser.rs @@ -38,8 +38,6 @@ pub enum JunitParseError { ReportMultipleFound, #[error("report end tag found without start tag")] ReportStartTagNotFound, - #[error("could not parse test suite name")] - TestSuiteName, #[error("test suite end tag found without start tag")] TestSuiteStartTagNotFound, #[error("could not parse test case name")] @@ -54,12 +52,6 @@ pub enum JunitParseError { TestRerunStartTagNotFound, #[error("test rerun end tag found without start tag")] TestRerunTestCaseNotFound, - #[error("system out is empty")] - SystemOutEmpty, - #[error("system err is empty")] - SystemErrEmpty, - #[error("stack trace is empty")] - StackTraceEmpty, } #[derive(Debug, Clone)] @@ -213,9 +205,6 @@ impl JunitParser { self.open_test_rerun(&e); self.close_test_rerun(); } - TAG_TEST_RERUN_STACK_TRACE => self.errors.push(JunitParseError::StackTraceEmpty), - TAG_SYSTEM_OUT => self.errors.push(JunitParseError::SystemOutEmpty), - TAG_SYSTEM_ERR => self.errors.push(JunitParseError::SystemErrEmpty), _ => (), }, Event::CData(e) => { @@ -295,9 +284,6 @@ impl JunitParser { } let test_suite_name = parse_attr::name(e).unwrap_or_default(); - if test_suite_name.is_empty() { - self.errors.push(JunitParseError::TestSuiteName); - }; let mut test_suite = TestSuite::new(test_suite_name); if let Some(timestamp) = parse_attr::timestamp(e, &mut self.date_parser) {