from __future__ import annotations

from pathlib import Path


ROOT = Path(__file__).resolve().parents[2]


def test_rest_deploy_refuses_to_drop_service_authentication() -> None:
    source = (ROOT / "scripts" / "deploy_1c_adapter_stack.ps1").read_text(encoding="utf-8-sig")
    assert "function Ensure-RestServiceToken" in source
    assert "ONEC_ADAPTER_ALLOW_UNAUTHENTICATED_ADMIN" in source
    assert "Reusing the existing REST service token without printing or persisting it" in source
    assert "Refusing to deploy an unauthenticated adapter" in source
    assert source.index("Ensure-RestServiceToken") < source.index("Invoke-ComposeUp `", source.index("try {"))


def test_deploy_can_forward_complete_saved_state_write_smoke_skip() -> None:
    source = (ROOT / "scripts" / "deploy_1c_adapter_stack.ps1").read_text(encoding="utf-8-sig")

    assert "[switch]$SkipSavedStateWriteSmoke" in source
    assert "[switch]$SkipCodeWriteSavedStateSmoke" in source
    assert '$verifyCommand += "-SkipSavedStateWriteSmoke"' in source
    assert '$verifyCommand += "-SkipCodeWriteSavedStateSmoke"' in source
