# #region TestContext [TYPE Module] [C:3] [SEMANTICS tests, task-context, background-tasks, sub-context]
# @RELATION BINDS_TO -> SrcRoot
# @BRIEF Verify TaskContext preserves optional background task scheduler across sub-context creation.
from unittest.mock import MagicMock

from src.core.task_manager.context import TaskContext


# #region test_task_context_preserves_background_tasks_across_sub_context [TYPE Function]
# @RELATION BINDS_TO -> TestContext
# @BRIEF Plugins must be able to access background_tasks from both root and sub-context loggers.
# @PRE  TaskContext is initialized with a BackgroundTasks-like object.
# @POST  background_tasks remains available on root and derived sub-contexts.
def test_task_context_preserves_background_tasks_across_sub_context():
    background_tasks = MagicMock()
    context = TaskContext(
        task_id="task-1",
        add_log_fn=lambda **_kwargs: None,
        params={"x": 1},
        background_tasks=background_tasks,
    )
    sub_context = context.create_sub_context("llm")
    assert context.background_tasks is background_tasks
    assert sub_context.background_tasks is background_tasks
# #endregion test_task_context_preserves_background_tasks_across_sub_context
# #endregion TestContext
