developer(ET): auto-commit from developer run_id=192
Some checks failed
CI / test (push) Failing after 17s
Some checks failed
CI / test (push) Failing after 17s
This commit is contained in:
47
tests/test_deploy_hook_mapping.py
Normal file
47
tests/test_deploy_hook_mapping.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""ORCH-036 TC-01/02/03: deterministic exit-code -> deploy_status mapping.
|
||||
|
||||
The finalizer (Phase C) maps the host-hook exit-code to the machine verdict via a
|
||||
PURE function (no LLM, no I/O), so it is unit-testable in isolation. Contract
|
||||
(hook exit-code 0/1/2, AC-1/AC-3): 0 -> SUCCESS; 1 (rolled back), 2 (rollback also
|
||||
failed), and anything else -> FAILED (fail-closed).
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
|
||||
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")
|
||||
|
||||
from src.self_deploy import map_exit_code_to_status, build_deploy_log # noqa: E402
|
||||
|
||||
|
||||
def test_tc01_exit0_maps_to_success():
|
||||
assert map_exit_code_to_status(0) == "SUCCESS"
|
||||
|
||||
|
||||
def test_tc02_exit1_rolled_back_maps_to_failed():
|
||||
assert map_exit_code_to_status(1) == "FAILED"
|
||||
|
||||
|
||||
def test_tc03_exit2_rollback_also_failed_maps_to_failed():
|
||||
assert map_exit_code_to_status(2) == "FAILED"
|
||||
|
||||
|
||||
def test_other_exit_codes_map_to_failed():
|
||||
for code in (3, 127, 255, -1):
|
||||
assert map_exit_code_to_status(code) == "FAILED"
|
||||
|
||||
|
||||
def test_non_int_or_none_maps_to_failed_fail_closed():
|
||||
assert map_exit_code_to_status(None) == "FAILED"
|
||||
assert map_exit_code_to_status("garbage") == "FAILED"
|
||||
|
||||
|
||||
def test_deploy_log_frontmatter_carries_status():
|
||||
"""The rendered log must expose deploy_status in YAML frontmatter so the
|
||||
existing _parse_deploy_status contract (AC-10) reads the right verdict."""
|
||||
body_ok = build_deploy_log("ORCH-036", 0, "SUCCESS")
|
||||
assert body_ok.startswith("---\n")
|
||||
assert "deploy_status: SUCCESS" in body_ok
|
||||
body_fail = build_deploy_log("ORCH-036", 2, "FAILED")
|
||||
assert "deploy_status: FAILED" in body_fail
|
||||
assert "hook_exit_code: 2" in body_fail
|
||||
Reference in New Issue
Block a user