"""backend_guard.py contract violations must reach the existing auto-fix repair loop.

The step that runs codegen + the contract check is named "Run P2HS codegen"
(actions_pipeline.py) -- before this fix it matched none of _BUILD_STEP_KEYWORDS and
fell into auto_fix_unrecognized_step (does nothing). These are the two pure
classification helpers extracted from _auto_fix_failed_workflow so this doesn't
require mocking the whole GitHub API / DB chain to verify.
"""
from src.domain.github_webhooks.handlers import _is_build_step, _is_contract_violation


def test_codegen_step_is_now_classified_as_a_build_step():
    assert _is_build_step("run p2hs codegen") is True


def test_existing_build_step_names_still_classified():
    assert _is_build_step("install app dependencies") is True
    assert _is_build_step("build app") is True
    assert _is_build_step("npm run generate") is True


def test_deploy_step_names_are_not_build_steps():
    # is_deploy_step is checked first in the real function and takes priority
    # regardless -- this just confirms the keyword list itself doesn't overlap.
    assert _is_build_step("deploy to cloudflare pages") is False


def test_backend_guard_violation_text_is_recognized():
    assert _is_contract_violation(
        "Cloud persistence contract failed. Use platform auth for identities...\n"
        "js/dashboard.js: hardcoded /admin redirect (this project's admin path is /be-admin)"
    ) is True


def test_port_artifact_violation_text_is_recognized():
    assert _is_contract_violation("Homemade route shadows an installed platform port: server/api/contact.ts") is True
    assert _is_contract_violation("Platform port lock was changed or removed") is True


def test_unrelated_build_failure_is_not_a_contract_violation():
    assert _is_contract_violation("SyntaxError: Unexpected token at line 42") is False
