From f39f95477f2f3ab9b9269e2e6e13d4604455b1ea Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 31 Jan 2025 09:35:24 +0000 Subject: [PATCH] Avoid backup size difference by sorting JSON keys It seems that the order of keys in the `homeassistant.json` file leads to a different homeassistant.tar.gz size, which in turn leads to a different overall backup size. It seems that running the full test suite compared to run tests individually lead to a different order of keys in the JSON file. This PR sorts the keys when dumping the JSON. With that change, the backup size is consistent. --- supervisor/utils/json.py | 3 ++- tests/api/test_backups.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/supervisor/utils/json.py b/supervisor/utils/json.py index d3a6b43e4..833817c6f 100644 --- a/supervisor/utils/json.py +++ b/supervisor/utils/json.py @@ -55,7 +55,8 @@ def write_json_file(jsonfile: Path, data: Any) -> None: orjson.dumps( # pylint: disable=no-member data, option=orjson.OPT_INDENT_2 # pylint: disable=no-member - | orjson.OPT_NON_STR_KEYS, # pylint: disable=no-member + | orjson.OPT_NON_STR_KEYS # pylint: disable=no-member + | orjson.OPT_SORT_KEYS, # pylint: disable=no-member default=json_encoder_default, ).decode("utf-8") ) diff --git a/tests/api/test_backups.py b/tests/api/test_backups.py index 24aaa0bd5..c7d524b45 100644 --- a/tests/api/test_backups.py +++ b/tests/api/test_backups.py @@ -1035,6 +1035,9 @@ async def test_protected_backup( assert body["data"]["backups"][0]["location"] is None assert body["data"]["backups"][0]["locations"] == [None] assert body["data"]["backups"][0]["protected"] is True + + # NOTE: Maybe it is not safe to compare size here, as random data in the + # backup might change the size (due to gzip). assert body["data"]["backups"][0]["location_attributes"] == { ".local": { "protected": True,