diff --git a/launch_env.sh b/launch_env.sh index 74fd65ca7c..858f20402e 100755 --- a/launch_env.sh +++ b/launch_env.sh @@ -25,7 +25,7 @@ if [ -z "$AGNOS_VERSION" ]; then fi if [ -z "$AGNOS_ACCEPTED_VERSIONS" ]; then - export AGNOS_ACCEPTED_VERSIONS="$AGNOS_VERSION" + export AGNOS_ACCEPTED_VERSIONS="19.8.1 19.8.2" fi export STAGING_ROOT="/data/safe_staging" diff --git a/system/updated/tests/test_agnos_compatibility.py b/system/updated/tests/test_agnos_compatibility.py new file mode 100644 index 0000000000..da0cae9d06 --- /dev/null +++ b/system/updated/tests/test_agnos_compatibility.py @@ -0,0 +1,30 @@ +import ast +from pathlib import Path +from types import SimpleNamespace + +import pytest + + +def load_handle_agnos_update(cur_version: str): + source_path = Path(__file__).parents[1] / "updated.py" + module = ast.parse(source_path.read_text()) + function = next(node for node in module.body if isinstance(node, ast.FunctionDef) and node.name == "handle_agnos_update") + + def fail(*_args, **_kwargs): + raise AssertionError("accepted AGNOS version attempted to update") + + scope = { + "HARDWARE": SimpleNamespace(get_os_version=lambda: cur_version), + "OVERLAY_MERGED": "/unused", + "cloudlog": SimpleNamespace(info=lambda *_args, **_kwargs: None), + "run": lambda *_args, **_kwargs: "19.8.1\n19.8.1 19.8.2\n", + "set_consistent_flag": fail, + } + ast.fix_missing_locations(function) + exec(compile(ast.Module(body=[function], type_ignores=[]), str(source_path), "exec"), scope) + return scope["handle_agnos_update"] + + +@pytest.mark.parametrize("cur_version", ["19.8.1", "19.8.2"]) +def test_accepted_agnos_version_is_not_reflashed(cur_version): + load_handle_agnos_update(cur_version)() diff --git a/system/updated/updated.py b/system/updated/updated.py index 8e7c8890c3..d77f27553b 100644 --- a/system/updated/updated.py +++ b/system/updated/updated.py @@ -247,11 +247,14 @@ def handle_agnos_update() -> None: from openpilot.system.hardware.tici.agnos import flash_agnos_update, get_target_slot_number cur_version = HARDWARE.get_os_version() - updated_version = run(["bash", "-c", r"unset AGNOS_VERSION && source launch_env.sh && \ - echo -n $AGNOS_VERSION"], OVERLAY_MERGED).strip() + version_output = run(["bash", "-c", r'''unset AGNOS_VERSION AGNOS_ACCEPTED_VERSIONS + source launch_env.sh + printf '%s\n%s\n' "$AGNOS_VERSION" "${AGNOS_ACCEPTED_VERSIONS:-$AGNOS_VERSION}"'''], OVERLAY_MERGED) + updated_version, accepted_versions_raw = version_output.splitlines()[:2] + accepted_versions = set(accepted_versions_raw.split()) | {updated_version} - cloudlog.info(f"AGNOS version check: {cur_version} vs {updated_version}") - if cur_version == updated_version: + cloudlog.info(f"AGNOS version check: {cur_version} vs {sorted(accepted_versions)}") + if cur_version in accepted_versions: return # prevent an openpilot getting swapped in with a mismatched or partially downloaded agnos