Skip to content

Conversation

@codebeaver-ai
Copy link
Contributor

@codebeaver-ai codebeaver-ai bot commented Jan 12, 2025

Test Coverage Improvements 🎯

This PR adds new tests to improve coverage across multiple files.

Summary

  • Overall average coverage improvement: +59.28%
  • Files modified: 6

Detailed Changes

  • tests/test_split_text_into_chunks.py
    • New coverage: 78.95%
    • Improvement: +78.95%
  • tests/test_tokenizer.py
    • New coverage: 100.00%
    • Improvement: +100.00%
  • tests/test_tokenizer_openai.py
    • New coverage: 100.00%
    • Improvement: +100.00%
  • tests/test_parse_node.py
    • New coverage: 40.98%
    • Improvement: +40.98%
  • tests/test_generate_answer_node.py
    • New coverage: 21.48%
    • Improvement: +21.48%
  • tests/test_chromium.py
    • New coverage: 14.29%
    • Improvement: +14.29%

Generated by CodeBeaver

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. tests Improvements or additions to test labels Jan 12, 2025
assert "link_urls" in result_state
assert "img_urls" in result_state

assert "https://example.com" in result_state["link_urls"]

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
https://example.com
may be at an arbitrary position in the sanitized URL.

Copilot Autofix

AI 11 months ago

To fix the problem, we need to ensure that the URL is properly parsed and validated before performing the check. This can be done by using the urlparse function from the urllib.parse module to extract the hostname and then performing the check on the parsed hostname.

  • Parse the URL using urlparse to extract the hostname.
  • Check if the hostname matches the expected value.
  • Update the test case to use this new validation method.
Suggested changeset 1
tests/test_parse_node.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/test_parse_node.py b/tests/test_parse_node.py
--- a/tests/test_parse_node.py
+++ b/tests/test_parse_node.py
@@ -111,5 +111,9 @@
 
-        assert "https://example.com" in result_state["link_urls"]
-        assert "https://sourcesite.com/relative/path.html" in result_state["link_urls"]
-        assert "https://sourcesite.com/image.jpg" in result_state["img_urls"]
+        from urllib.parse import urlparse
+        def get_hostname(url):
+            return urlparse(url).hostname
+
+        assert any(get_hostname(url) == "example.com" for url in result_state["link_urls"])
+        assert any(get_hostname(url) == "sourcesite.com" and url.endswith("/relative/path.html") for url in result_state["link_urls"])
+        assert any(get_hostname(url) == "sourcesite.com" and url.endswith("/image.jpg") for url in result_state["img_urls"])
         assert len(result_state["chunks"]) > 0
EOF
@@ -111,5 +111,9 @@

assert "https://example.com" in result_state["link_urls"]
assert "https://sourcesite.com/relative/path.html" in result_state["link_urls"]
assert "https://sourcesite.com/image.jpg" in result_state["img_urls"]
from urllib.parse import urlparse
def get_hostname(url):
return urlparse(url).hostname

assert any(get_hostname(url) == "example.com" for url in result_state["link_urls"])
assert any(get_hostname(url) == "sourcesite.com" and url.endswith("/relative/path.html") for url in result_state["link_urls"])
assert any(get_hostname(url) == "sourcesite.com" and url.endswith("/image.jpg") for url in result_state["img_urls"])
assert len(result_state["chunks"]) > 0
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test fail
Screenshot 2025-01-12 alle 15 55 22

@VinciGit00 VinciGit00 self-assigned this Jan 12, 2025
@VinciGit00 VinciGit00 closed this Jan 15, 2025
@codebeaver-ai codebeaver-ai bot deleted the codebeaver/pre/beta-tests-20250112_122537 branch January 15, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files. tests Improvements or additions to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants