Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions tests/test_autofix_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""Test file with intentional issues to validate autofix system.

This file contains:
1. Black formatting violations
2. Ruff lint errors
3. Mypy type errors
4. Failing tests
5. Actual useful test coverage

Purpose: Validate the full autofix pipeline handles all failure modes.
"""

# --- BLACK VIOLATION: Bad formatting ---

# --- RUFF VIOLATIONS ---
# F401: unused import
import os

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

The import os is marked as unused (F401) in the comment on line 16, but it is actually used in the test functions below (lines 62-63, 76-78 for os.environ.pop() and os.environ[] operations). This import should not be in the "unused import" section since it's legitimately needed.

Copilot uses AI. Check for mistakes.

from adapters.base import connect_db, get_adapter

# E501: line too long
VERY_LONG_STRING_THAT_VIOLATES_LINE_LENGTH = "This is a very long string that definitely exceeds the maximum line length limit of 88 characters that ruff and black enforce by default"


# --- MYPY TYPE ERROR ---
def bad_type_annotation(x: int) -> str:
return x # Returns int, claims str


Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

The function missing_return_type is missing type annotations on both its parameter and return type. While this appears to be intentional based on its name and docstring, it's not explicitly called out in the "MYPY TYPE ERROR" section comment above (which only mentions bad_type_annotation). Consider either adding proper annotations or moving this function under a clear comment marker indicating it's an intentional violation.

Suggested change
# Intentional mypy error: function without parameter or return type annotations

Copilot uses AI. Check for mistakes.
def missing_return_type(value):
"""Function missing type annotations."""
return value * 2


# --- BLACK VIOLATION: Inconsistent spacing ---
def poorly_formatted_function(arg1, arg2, arg3):
"""This function has poor formatting."""
result = arg1 + arg2 + arg3
if result > 10:
return result
else:
return result * 2


class BadlyFormattedClass:
"""Class with formatting issues."""

def __init__(self, name: str, value: int):
self.name = name
self.value = value

def compute(self, multiplier: int) -> int:
return self.value * multiplier


# --- ACTUAL USEFUL COVERAGE TESTS ---


def test_connect_db_sqlite_default():
"""Test connect_db returns valid SQLite connection."""
# Clear env vars to force SQLite path
old_url = os.environ.pop("DB_URL", None)
old_path = os.environ.pop("DB_PATH", None)

try:
conn = connect_db(":memory:")
assert conn is not None
# Verify it's a working connection
cursor = conn.cursor()
cursor.execute("SELECT 1")
result = cursor.fetchone()
assert result == (1,)
conn.close()
finally:
if old_url:
os.environ["DB_URL"] = old_url
if old_path:
os.environ["DB_PATH"] = old_path


def test_connect_db_with_timeout():
"""Test connect_db accepts timeout parameter."""
conn = connect_db(":memory:", connect_timeout=5.0)
assert conn is not None
conn.close()


def test_get_adapter_edgar():
"""Test that edgar adapter can be loaded."""
try:
adapter = get_adapter("edgar")
assert adapter is not None
# Verify it has expected protocol methods
assert (
hasattr(adapter, "list_new_filings")
or callable(getattr(adapter, "list_new_filings", None)) is False

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

The logic in this assertion is flawed. The condition hasattr(adapter, "list_new_filings") or callable(getattr(adapter, "list_new_filings", None)) is False will always evaluate to True if hasattr returns True, making the second part unreachable. The intended check appears to be verifying that the attribute exists AND is callable. Consider simplifying to assert hasattr(adapter, "list_new_filings") or checking assert callable(getattr(adapter, "list_new_filings", None)).

Suggested change
assert (
hasattr(adapter, "list_new_filings")
or callable(getattr(adapter, "list_new_filings", None)) is False
assert hasattr(adapter, "list_new_filings") and callable(
getattr(adapter, "list_new_filings", None)

Copilot uses AI. Check for mistakes.
)
except ModuleNotFoundError:
# Adapter module may not exist yet
pass


def test_get_adapter_invalid():
"""Test get_adapter raises for unknown adapter."""
try:
get_adapter("nonexistent_adapter_xyz")
assert False, "Should have raised"

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`

Check failure on line 107 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (B011)

tests/test_autofix_validation.py:107:16: B011 Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
except (ModuleNotFoundError, ImportError):
pass # Expected

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

This test expects an exception to be raised, but if get_adapter doesn't raise an exception, the assertion on line 107 will fail with a confusing error message. The pattern used here doesn't actually verify that an exception was raised - it only passes if an exception occurs. Consider using pytest's raises() context manager for clearer intent: with pytest.raises((ModuleNotFoundError, ImportError)): get_adapter("nonexistent_adapter_xyz"). This would require importing pytest at the top of the file.

Copilot uses AI. Check for mistakes.


# --- INTENTIONALLY FAILING TESTS ---


def test_intentional_failure_assertion():
"""This test intentionally fails with an assertion error."""
expected = 42
actual = 41
assert actual == expected, f"Expected {expected} but got {actual}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove unconditional assertion failure

The new test test_intentional_failure_assertion hardcodes expected = 42 and actual = 41, so running pytest will always hit the assert actual == expected failure even when the rest of the suite passes, keeping CI permanently red.

Useful? React with 👍 / 👎.



def test_intentional_failure_exception():
"""This test intentionally raises an exception."""
data = {"key": "value"}
# This will raise KeyError
result = data["nonexistent_key"]

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Check failure on line 126 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:126:5: F841 Local variable `result` is assigned to but never used

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid uncaught KeyError in test

In test_intentional_failure_exception, the dict access data["nonexistent_key"] raises KeyError every run, so the test fails before any assertion and will keep the whole pytest run failing regardless of actual code behavior.

Useful? React with 👍 / 👎.



def test_intentional_failure_type_error():
"""This test intentionally causes a TypeError."""
value = "not a number"
# This will raise TypeError
result = value + 5

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Check failure on line 133 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (F841)

tests/test_autofix_validation.py:133:5: F841 Local variable `result` is assigned to but never used

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prevent unconditional TypeError in test

The test test_intentional_failure_type_error tries to add an int to a string (value + 5), which raises TypeError on every execution; this makes the test suite fail immediately and blocks CI even when application code is correct.

Useful? React with 👍 / 👎.

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

The variable result is assigned but never used. While the test is intentionally designed to fail with a KeyError, the unused variable assignment will also trigger a linting warning (F841). Consider either removing the assignment or using it in an assertion if you want to test a different failure mode.

Suggested change
result = data["nonexistent_key"]
def test_intentional_failure_type_error():
"""This test intentionally causes a TypeError."""
value = "not a number"
# This will raise TypeError
result = value + 5
_ = data["nonexistent_key"]
def test_intentional_failure_type_error():
"""This test intentionally causes a TypeError."""
value = "not a number"
# This will raise TypeError
_ = value + 5

Copilot uses AI. Check for mistakes.

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

The variable result is assigned but never used. While the test is intentionally designed to fail with a TypeError, the unused variable assignment will also trigger a linting warning (F841). Consider either removing the assignment or using it in an assertion if you want to test a different failure mode.

Suggested change
result = value + 5
value + 5

Copilot uses AI. Check for mistakes.


# --- RUFF VIOLATIONS: More lint issues ---


# W293: whitespace on blank line
def function_with_trailing_whitespace():
"""Has trailing whitespace."""
x = 1

y = 2
return x + y


# E711: comparison to None
def bad_none_comparison(value):
if value == None:

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Check failure on line 150 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E711)

tests/test_autofix_validation.py:150:17: E711 Comparison to `None` should be `cond is None`

Copilot AI Dec 29, 2025

Copy link

Choose a reason for hiding this comment

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

Testing for None should use the 'is' operator.

Suggested change
if value == None:
if value is None:

Copilot uses AI. Check for mistakes.
return "empty"
return "full"


# E712: comparison to True
def bad_bool_comparison(flag):
if flag == True:

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks

Check failure on line 157 in tests/test_autofix_validation.py

View workflow job for this annotation

GitHub Actions / Python CI / lint-ruff

Ruff (E712)

tests/test_autofix_validation.py:157:8: E712 Avoid equality comparisons to `True`; use `flag:` for truth checks
return "yes"
return "no"


# Autofix retest - 2025-12-29T05:30:11Z
Loading