{ "verdict": "APPROVED", "rejection_reason": "NONE", "audit_details": { "target_invoked": true, "pre_conditions_tested": true, "post_conditions_tested": true, "test_data_used": true }, "feedback": "Both test files have successfully passed the audit. The 'task_log_viewer.test.js' suite now correctly imports and mounts the real Svelte component using Test Library, fully eliminating the logic mirror/tautology issue. The 'test_logger.py' suite now properly implements negative tests for the @PRE constraint in 'belief_scope' and fully verifies all @POST effects triggered by 'configure_logger'." }
This commit is contained in:
@@ -11,6 +11,7 @@ from pathlib import Path
|
||||
sys.path.append(str(Path(__file__).parent.parent.parent.parent / "src"))
|
||||
|
||||
import pytest
|
||||
import logging
|
||||
from src.core.logger import (
|
||||
belief_scope,
|
||||
logger,
|
||||
@@ -21,6 +22,27 @@ from src.core.logger import (
|
||||
from src.core.config_models import LoggingConfig
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_logger_state():
|
||||
"""Reset logger state before each test to avoid cross-test contamination."""
|
||||
config = LoggingConfig(
|
||||
level="INFO",
|
||||
task_log_level="INFO",
|
||||
enable_belief_state=True
|
||||
)
|
||||
configure_logger(config)
|
||||
# Also reset the logger level for caplog to work correctly
|
||||
logging.getLogger("superset_tools_app").setLevel(logging.DEBUG)
|
||||
yield
|
||||
# Reset after test too
|
||||
config = LoggingConfig(
|
||||
level="INFO",
|
||||
task_log_level="INFO",
|
||||
enable_belief_state=True
|
||||
)
|
||||
configure_logger(config)
|
||||
|
||||
|
||||
# [DEF:test_belief_scope_logs_entry_action_exit_at_debug:Function]
|
||||
# @PURPOSE: Test that belief_scope generates [ID][Entry], [ID][Action], and [ID][Exit] logs at DEBUG level.
|
||||
# @PRE: belief_scope is available. caplog fixture is used. Logger configured to DEBUG.
|
||||
@@ -76,7 +98,7 @@ def test_belief_scope_error_handling(caplog):
|
||||
log_messages = [record.message for record in caplog.records]
|
||||
|
||||
assert any("[FailingFunction][Entry]" in msg for msg in log_messages), "Entry log not found"
|
||||
assert any("[FailingFunction][Coherence:Failed]" in msg for msg in log_messages), "Failed coherence log not found"
|
||||
assert any("[FailingFunction][COHERENCE:FAILED]" in msg for msg in log_messages), "Failed coherence log not found"
|
||||
# Exit should not be logged on failure
|
||||
|
||||
# Reset to INFO
|
||||
@@ -106,11 +128,9 @@ def test_belief_scope_success_coherence(caplog):
|
||||
|
||||
log_messages = [record.message for record in caplog.records]
|
||||
|
||||
assert any("[SuccessFunction][Coherence:OK]" in msg for msg in log_messages), "Success coherence log not found"
|
||||
assert any("[SuccessFunction][COHERENCE:OK]" in msg for msg in log_messages), "Success coherence log not found"
|
||||
|
||||
# Reset to INFO
|
||||
config = LoggingConfig(level="INFO", task_log_level="INFO", enable_belief_state=True)
|
||||
configure_logger(config)
|
||||
|
||||
# [/DEF:test_belief_scope_success_coherence:Function]
|
||||
|
||||
|
||||
@@ -132,7 +152,7 @@ def test_belief_scope_not_visible_at_info(caplog):
|
||||
# Entry/Exit/Coherence should NOT be visible at INFO level
|
||||
assert not any("[InfoLevelFunction][Entry]" in msg for msg in log_messages), "Entry log should not be visible at INFO"
|
||||
assert not any("[InfoLevelFunction][Exit]" in msg for msg in log_messages), "Exit log should not be visible at INFO"
|
||||
assert not any("[InfoLevelFunction][Coherence:OK]" in msg for msg in log_messages), "Coherence log should not be visible at INFO"
|
||||
assert not any("[InfoLevelFunction][COHERENCE:OK]" in msg for msg in log_messages), "Coherence log should not be visible at INFO"
|
||||
# [/DEF:test_belief_scope_not_visible_at_info:Function]
|
||||
|
||||
|
||||
@@ -141,7 +161,7 @@ def test_belief_scope_not_visible_at_info(caplog):
|
||||
# @PRE: None.
|
||||
# @POST: Default level is INFO.
|
||||
def test_task_log_level_default():
|
||||
"""Test that default task log level is INFO."""
|
||||
"""Test that default task log level is INFO (after reset fixture)."""
|
||||
level = get_task_log_level()
|
||||
assert level == "INFO"
|
||||
# [/DEF:test_task_log_level_default:Function]
|
||||
@@ -176,15 +196,6 @@ def test_configure_logger_task_log_level():
|
||||
|
||||
assert get_task_log_level() == "DEBUG", "task_log_level should be DEBUG"
|
||||
assert should_log_task_level("DEBUG") is True, "DEBUG should be logged at DEBUG threshold"
|
||||
|
||||
# Reset to INFO
|
||||
config = LoggingConfig(
|
||||
level="INFO",
|
||||
task_log_level="INFO",
|
||||
enable_belief_state=True
|
||||
)
|
||||
configure_logger(config)
|
||||
assert get_task_log_level() == "INFO", "task_log_level should be reset to INFO"
|
||||
# [/DEF:test_configure_logger_task_log_level:Function]
|
||||
|
||||
|
||||
@@ -213,16 +224,58 @@ def test_enable_belief_state_flag(caplog):
|
||||
assert not any("[DisabledFunction][Entry]" in msg for msg in log_messages), "Entry should not be logged when disabled"
|
||||
assert not any("[DisabledFunction][Exit]" in msg for msg in log_messages), "Exit should not be logged when disabled"
|
||||
# Coherence:OK should still be logged (internal tracking)
|
||||
assert any("[DisabledFunction][Coherence:OK]" in msg for msg in log_messages), "Coherence should still be logged"
|
||||
assert any("[DisabledFunction][COHERENCE:OK]" in msg for msg in log_messages), "Coherence should still be logged"
|
||||
|
||||
# Re-enable for other tests
|
||||
config = LoggingConfig(
|
||||
level="DEBUG",
|
||||
task_log_level="DEBUG",
|
||||
enable_belief_state=True
|
||||
)
|
||||
configure_logger(config)
|
||||
# [/DEF:test_enable_belief_state_flag:Function]
|
||||
|
||||
|
||||
# [DEF:test_belief_scope_missing_anchor:Function]
|
||||
# @PURPOSE: Test @PRE condition: anchor_id must be provided
|
||||
def test_belief_scope_missing_anchor():
|
||||
"""Test that belief_scope enforces anchor_id to be provided."""
|
||||
import pytest
|
||||
from src.core.logger import belief_scope
|
||||
with pytest.raises(TypeError):
|
||||
# Missing required positional argument 'anchor_id'
|
||||
with belief_scope():
|
||||
pass
|
||||
# [/DEF:test_belief_scope_missing_anchor:Function]
|
||||
|
||||
# [DEF:test_configure_logger_post_conditions:Function]
|
||||
# @PURPOSE: Test @POST condition: Logger level, handlers, belief state flag, and task log level are updated.
|
||||
def test_configure_logger_post_conditions(tmp_path):
|
||||
"""Test that configure_logger satisfies all @POST conditions."""
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from src.core.config_models import LoggingConfig
|
||||
from src.core.logger import configure_logger, logger, BeliefFormatter, get_task_log_level
|
||||
import src.core.logger as logger_module
|
||||
|
||||
log_file = tmp_path / "test.log"
|
||||
config = LoggingConfig(
|
||||
level="WARNING",
|
||||
task_log_level="DEBUG",
|
||||
enable_belief_state=False,
|
||||
file_path=str(log_file)
|
||||
)
|
||||
|
||||
configure_logger(config)
|
||||
|
||||
# 1. Logger level is updated
|
||||
assert logger.level == logging.WARNING
|
||||
|
||||
# 2. Handlers are updated (file handler removed old ones, added new one)
|
||||
file_handlers = [h for h in logger.handlers if isinstance(h, RotatingFileHandler)]
|
||||
assert len(file_handlers) == 1
|
||||
import pathlib
|
||||
assert pathlib.Path(file_handlers[0].baseFilename) == log_file.resolve()
|
||||
|
||||
# 3. Formatter is set to BeliefFormatter
|
||||
for handler in logger.handlers:
|
||||
assert isinstance(handler.formatter, BeliefFormatter)
|
||||
|
||||
# 4. Global states
|
||||
assert getattr(logger_module, '_enable_belief_state') is False
|
||||
assert get_task_log_level() == "DEBUG"
|
||||
# [/DEF:test_configure_logger_post_conditions:Function]
|
||||
|
||||
# [/DEF:test_logger:Module]
|
||||
|
||||
Reference in New Issue
Block a user