import sys

from flyway.migration import __main__ as cli


def test_resolutions_file_is_never_an_output_file(tmp_path, monkeypatch):
    decided = tmp_path / "pending-dates.csv"
    content = "table,row_id,column,raw,code,reason,nz_if_server_time,nz_if_user_input,resolution\nfw_X,1,Date,,,,,,server\n"
    decided.write_text(content, encoding="utf-8")
    monkeypatch.setattr(sys, "argv", ["m", "--server-tz", "UTC", "--resolutions", str(decided), "--out", str(tmp_path)])
    assert cli.main() == 2
    assert decided.read_text(encoding="utf-8") == content  # 业务判定原件保持不变


def test_invalid_resolution_value_rejected(tmp_path, monkeypatch):
    decided = tmp_path / "decisions.csv"
    decided.write_text("table,row_id,column,resolution\nfw_X,1,Date,nz\n", encoding="utf-8")
    monkeypatch.setattr(sys, "argv", ["m", "--server-tz", "UTC", "--resolutions", str(decided),
                                      "--out", str(tmp_path / "out")])
    assert cli.main() == 2
