#!/usr/bin/env python3
"""Tests for Story 1.05 (Track B): NullInterceptor"""
import asyncio
import sys
sys.path.insert(0, '/mnt/e/genesis-system')


def test_null_interceptor():
    from core.interceptors.integration_contracts import NullInterceptor
    from core.interceptors.base_interceptor import BaseInterceptor

    null = NullInterceptor()

    # BB1: pre_execute returns identical dict (not mutated)
    async def run_tests():
        original = {"key": "value", "nested": {"a": 1}}
        result = await null.pre_execute(original)
        assert result is original, "Should return same dict object"
        assert result == {"key": "value", "nested": {"a": 1}}

        # BB2: on_correction adds "CORRECTION: " prefix
        payload = {"prompt": "Build the feature"}
        corrected = await null.on_correction(payload)
        assert corrected["prompt"] == "CORRECTION: Build the feature"

        # BB3: NullInterceptor is usable as a concrete class
        assert isinstance(null, BaseInterceptor)
        assert null.metadata.name == "null_interceptor"
        assert null.metadata.priority == 50
        assert null.metadata.enabled == True

        # WB1: All 4 abstract methods implemented
        assert not hasattr(NullInterceptor, '__abstractmethods__') or len(NullInterceptor.__abstractmethods__) == 0

        # WB2: on_correction only prepends if "prompt" key exists
        no_prompt = {"other": "data"}
        result = await null.on_correction(no_prompt)
        assert "prompt" not in result
        assert result["other"] == "data"

        # WB3: on_error returns error details
        error_result = await null.on_error(ValueError("test error"), {"task": "test"})
        assert error_result["error"] == "test error"
        assert error_result["task_payload"]["task"] == "test"

        # WB4: post_execute returns None
        post_result = await null.post_execute({"done": True}, {"task": "test"})
        assert post_result is None

    asyncio.run(run_tests())
    print("ALL TESTS PASSED — Story 1.05 (Track B)")


if __name__ == "__main__":
    test_null_interceptor()
