from src.core.public_output import redact_public_output


def test_redacts_urls_and_runner_paths_from_websocket_output():
    raw = (
        "To https://github.com/P2HS/private-app.git\n"
        "saved deploy artifact /home/runner/work/app/action-result.json"
    )

    result = redact_public_output(raw)

    assert "github.com" not in result
    assert "/home/runner" not in result
    assert "action-result.json" not in result
    assert "[internal URL redacted]" in result


def test_preserves_safe_status_copy():
    assert redact_public_output("Code saved. Building your preview.") == (
        "Code saved. Building your preview."
    )


def test_redacts_cloud_provider_urls_too():
    result = redact_public_output(
        "Preview deployed at https://preview.p2hs-example.pages.dev"
    )
    assert "pages.dev" not in result
    assert "[internal URL redacted]" in result


def test_neutralizes_executor_labels():
    result = redact_public_output(
        "[p2hs-codegen] saved deploy artifact /home/runner/work/a.json\n"
        "Codegen has been dispatched to GitHub Actions.\nP2HS AI is running."
    )
    assert "p2hs-codegen" not in result.lower()
    assert "github actions" not in result.lower()
    assert "p2hs ai" not in result.lower()
    assert "the build service" in result
    assert "the build service is running" in result


def test_preserves_relative_edit_paths_but_hides_generated_project_root():
    result = redact_public_output(
        "Edit: p2hs-0b9b8881f0f44987a1149993e1fac039/login.html\n"
        "Edit: js/booking-workflow.js\nEdit: css/app.css"
    )
    assert "p2hs-0b9b8881f0f44987a1149993e1fac039" not in result
    assert "login.html" in result
    assert "js/booking-workflow.js" in result
    assert "css/app.css" in result
