from abyss.utils.redact import redact, redact_line


def test_redact_keeps_last_4_chars():
    assert redact("ghp_aBcD1234efGH5678") == "•" * 16 + "5678"


def test_redact_short_secret_fully_masked():
    assert redact("abc") == "•••"


def test_redact_empty_string():
    assert redact("") == ""


def test_redact_line_replaces_secret_in_context():
    line = 'API_KEY = "ghp_aBcD1234efGH5678"'
    result = redact_line(line, "ghp_aBcD1234efGH5678")
    assert "ghp_aBcD1234efGH5678" not in result
    assert result.endswith('5678"')


def test_redact_line_no_secret_present_unchanged():
    line = "some unrelated line"
    assert redact_line(line, "not-here") == line