from pathlib import Path


README = Path(__file__).parents[1] / "README.md"
REQUIREMENTS = Path(__file__).parents[1] / "requirements.txt"


def test_release_worker_instructions_use_direct_agent_execution():
    text = README.read_text()

    assert "codex" not in text.lower()
    assert "RELEASE_AGENT_COMMAND=true" in text
    assert "--issue 19" in text


def test_readme_documents_a_complete_local_quickstart():
    text = README.read_text()

    assert "python3 -m venv .venv" in text
    assert "pip install -r requirements.txt" in text
    assert "GITEA_URL" in text
    assert "GITEA_TOKEN" in text
    assert "uvicorn src.main:app" in text
    assert "http://127.0.0.1:8000/api/v1/context" in text
    assert "uvicorn==" in REQUIREMENTS.read_text()


def test_readme_documents_liveness_and_gitea_readiness_checks():
    text = README.read_text()

    assert "`/healthz`" in text
    assert "`/readyz`" in text
    assert "does not contact Gitea" in text
    assert "HTTP 503" in text


def test_readme_documents_exact_later_return_times():
    text = " ".join(README.read_text().split())

    assert "Choose date & time" in text
    assert "valid future local date and time" in text
    assert "exact instant" in text


def test_readme_documents_bounded_offline_today_details_and_safe_actions():
    text = " ".join(README.read_text().split())

    assert "opened Today issue or pull request" in text
    assert "newest 20 comments" in text
    assert "comments can enter the account-bound durable outbox" in text
    assert "planning, assignment, review, merge, and close controls remain disabled" in text


def test_readme_documents_offline_unread_update_conversations_and_boundaries():
    text = " ".join(README.read_text().split())

    assert "previously opened unread update" in text
    assert "replies enter the account-bound durable outbox" in text
    assert "mark read, ownership, deferral, and older-message loading remain disabled" in text


def test_readme_documents_planning_sync_retention_contract():
    text = " ".join(README.read_text().split())

    assert "30 days" in text
    assert "4,096 operation receipts per account" in text
    assert "expired edit" in text
    assert "account plan is kept" in text
