Skip to content

contains_xml method#177

Merged
sadrasabouri merged 6 commits intodevfrom
contains_xml
Nov 9, 2025
Merged

contains_xml method#177
sadrasabouri merged 6 commits intodevfrom
contains_xml

Conversation

@sepandhaghighi
Copy link
Copy Markdown
Member

@sepandhaghighi sepandhaghighi commented Nov 8, 2025

Reference Issues/PRs

What does this implement/fix? Explain your changes.

  • verify parameter added to contains_xml method
  • Test system modified

Any other comments?

@sepandhaghighi sepandhaghighi self-assigned this Nov 8, 2025
@sepandhaghighi sepandhaghighi added the enhancement New feature or request label Nov 8, 2025
@sepandhaghighi sepandhaghighi added this to the memor v1.0 milestone Nov 8, 2025
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.64%. Comparing base (60cb1d3) to head (9105352).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #177      +/-   ##
==========================================
+ Coverage   98.63%   98.64%   +0.01%     
==========================================
  Files          11       11              
  Lines        1745     1754       +9     
  Branches      167      168       +1     
==========================================
+ Hits         1721     1730       +9     
  Misses          5        5              
  Partials       19       19              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sepandhaghighi sepandhaghighi marked this pull request as ready for review November 8, 2025 21:11
Comment thread memor/message.py
Comment on lines +235 to +250
def contains_xml(self, verify: bool = False) -> bool:
"""
Check if the message contains any XML tags.

:param verify: verify if the XML structure is well-formed
"""
message = self.render(render_format=RenderFormat.STRING, show_warning=False)
wrapped = "<root>{message}</root>".format(message=message)
pattern_result = bool(re.search(XML_PATTERN, message))
if not verify:
return pattern_result
try:
_ = ElementTree.fromstring(wrapped)
return pattern_result
except Exception:
return False
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe contains_xml should always detect the variable XMLs in the message. This new method is a smarter way to detect whether XML is present in the text. So my suggestion is to remove the verify parameter and assume it's always True.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is very common for the structure of XML to be wrong, especially in responses. It is important for users to recognize that the response contains XML tags, but is not well-formed, so they can retry or take other actions.

@sadrasabouri sadrasabouri merged commit ac169b7 into dev Nov 9, 2025
25 checks passed
@sadrasabouri sadrasabouri deleted the contains_xml branch November 9, 2025 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants