96 lines
2.9 KiB
Python
96 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/"active-runtime/app"))
|
|
|
|
from aios_release_lineage_contract import ( # noqa: E402
|
|
FIXED_V2R2C2,
|
|
ReleaseLineageError,
|
|
validate_fixed_v2r2c2_task,
|
|
)
|
|
|
|
|
|
def fixed_task(source=FIXED_V2R2C2.source_commit, *, status="FAILED", attempt=1, max_attempts=1, revision=4):
|
|
return {
|
|
"task_id":FIXED_V2R2C2.task_id,
|
|
"status":status,
|
|
"attempt":attempt,
|
|
"max_attempts":max_attempts,
|
|
"revision":revision,
|
|
"required_capabilities":["release:candidate"],
|
|
"constraints":{
|
|
"release_candidate":{
|
|
"candidate_id":FIXED_V2R2C2.candidate_id,
|
|
"source_commit":source,
|
|
"version":FIXED_V2R2C2.version,
|
|
"projection_id":"projection-"+"a"*32,
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
def test_fixed_v2r2c2_lineage_is_the_original_release_worker_candidate():
|
|
assert FIXED_V2R2C2.source_commit=="71e736b05fab13efc06af7a4fe2dc022c1cf9a85"
|
|
result=validate_fixed_v2r2c2_task(fixed_task())
|
|
assert result["status"]=="VERIFIED"
|
|
assert result["lineage"]["version"]=="V2R2C2"
|
|
|
|
|
|
def test_later_capability_remediation_is_not_retroactively_v2r2c2_source():
|
|
with pytest.raises(ReleaseLineageError,match="FIXED_RELEASE_LINEAGE_DRIFT"):
|
|
validate_fixed_v2r2c2_task(
|
|
fixed_task("17deb91ca7a187dc81766945b1174e854f86bd25")
|
|
)
|
|
|
|
|
|
def test_acp_engineering_candidate_is_not_retroactively_v2r2c2_source():
|
|
with pytest.raises(ReleaseLineageError,match="FIXED_RELEASE_LINEAGE_DRIFT"):
|
|
validate_fixed_v2r2c2_task(
|
|
fixed_task("b4b4416c93fedbe451d655d49e28f915b8fd38e6")
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"status,attempt,max_attempts,revision",
|
|
[
|
|
("FAILED",1,1,4),
|
|
("QUEUED",1,2,5),
|
|
("CLAIMED",2,2,6),
|
|
("VERIFYING",2,2,9),
|
|
("SUCCEEDED",2,2,10),
|
|
],
|
|
)
|
|
def test_lineage_contract_does_not_confuse_lifecycle_state_with_release_identity(
|
|
status,attempt,max_attempts,revision
|
|
):
|
|
result=validate_fixed_v2r2c2_task(
|
|
fixed_task(
|
|
status=status,
|
|
attempt=attempt,
|
|
max_attempts=max_attempts,
|
|
revision=revision,
|
|
)
|
|
)
|
|
assert result["status"]=="VERIFIED"
|
|
assert result["task_status"]==status
|
|
assert result["attempt"]==attempt
|
|
assert result["max_attempts"]==max_attempts
|
|
assert result["revision"]==revision
|
|
|
|
|
|
def test_capability_and_task_identity_are_bound():
|
|
value=fixed_task()
|
|
value["required_capabilities"]=[]
|
|
with pytest.raises(ReleaseLineageError,match="FIXED_TASK_CAPABILITY_DRIFT"):
|
|
validate_fixed_v2r2c2_task(value)
|
|
|
|
value=fixed_task()
|
|
value["task_id"]="replacement-v2r2c2"
|
|
with pytest.raises(ReleaseLineageError,match="FIXED_TASK_ID_DRIFT"):
|
|
validate_fixed_v2r2c2_task(value)
|