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.
This commit is contained in:
Stefan Agner 2025-01-31 09:35:24 +00:00
parent 05b648629f
commit f39f95477f
No known key found for this signature in database
GPG Key ID: AE01353D1E44747D
2 changed files with 5 additions and 1 deletions

View File

@ -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")
)

View File

@ -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,