from pathlib import Path

from suzent.config import PROJECT_DIR
from suzent.memory.memory_context import format_core_memory_section
from suzent.prompts import build_execution_mode_section
from suzent.skills.manager import SkillManager


def _sample_blocks() -> dict[str, str]:
    return {
        "persona": "You are Suzent.",
        "user": "Test user.",
        "facts": "No facts.",
        "context": "No context.",
    }


def test_memory_context_host_mode_avoids_virtual_paths():
    text = format_core_memory_section(_sample_blocks(), sandbox_enabled=False)

    assert "/mnt/notebook" not in text
    assert "/shared/memory/" not in text
    assert "${SHARED_PATH}/memory/MEMORY.md" in text
    assert "${MOUNT_SKILLS}/official/notebook/ingest.md" in text


def test_memory_context_sandbox_mode_keeps_virtual_paths():
    text = format_core_memory_section(_sample_blocks(), sandbox_enabled=True)

    assert "/mnt/notebook" in text
    assert "/shared/memory/MEMORY.md" in text
    assert "/mnt/skills/official/notebook/ingest.md" in text


def test_skills_listing_host_mode_uses_host_locations():
    manager = SkillManager(skills_dir=PROJECT_DIR / "skills")
    manager.enabled_skills = {"notebook"}

    listing = manager.get_skills_listing(sandbox_enabled=False)

    assert "/mnt/skills/notebook/SKILL.md" not in listing
    assert "- notebook:" in listing
    assert "Location:" in listing
    assert "SKILL.md" in listing


def test_skill_content_host_mode_rewrites_virtual_paths():
    manager = SkillManager(skills_dir=PROJECT_DIR / "skills")

    content = manager.get_skill_content("notebook", sandbox_enabled=False)

    assert content is not None
    assert "/mnt/notebook" not in content
    assert "${MOUNT_NOTEBOOK}" in content


def test_prompt_assembly_host_mode_has_no_virtual_notebook_paths():
    memory_context = format_core_memory_section(_sample_blocks(), sandbox_enabled=False)
    skills_context = "- notebook: Notebook operations (Location: ${MOUNT_SKILLS}/official/notebook/SKILL.md)"

    prompt = "\n\n".join(
        [
            build_execution_mode_section(
                sandbox_enabled=False,
                workspace_root=str(Path(PROJECT_DIR)),
            ),
            memory_context,
            skills_context,
        ]
    )

    assert "Do NOT use virtual `/mnt/...` paths." in prompt
    assert "/mnt/notebook" not in prompt
