From 3f223d56577fcb4cd9c16188111e3af39f49e282 Mon Sep 17 00:00:00 2001 From: emil Date: Thu, 13 Aug 2026 17:27:20 +0200 Subject: [PATCH] test: add unicode preservation and round-trip tests for save_vault_yaml Add tests verifying allow_unicode=True behavior: - test_save_preserves_unicode: non-ASCII content (Cyrillic, German umlaut, Chinese) is written as UTF-8, not \uXXXX escapes - test_save_unicode_round_trip: saved unicode data loads back correctly Also add CHANGELOG entry under [Unreleased] > Fixed. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- CHANGELOG.md | 5 +++++ tests/unit/test_utils_vault.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41dbc1a..057007b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Fixed + +- `save_vault_yaml`: pass `allow_unicode=True` to `yaml.dump` to prevent + corruption of non-ASCII vault content (matches infra's `save_yaml` pattern) + ### Ci - Add composite actions (setup-env, notify-failure, quality-checks) in `.gitea/actions/` diff --git a/tests/unit/test_utils_vault.py b/tests/unit/test_utils_vault.py index 0a08370..e368ffd 100644 --- a/tests/unit/test_utils_vault.py +++ b/tests/unit/test_utils_vault.py @@ -75,6 +75,25 @@ class TestSaveVaultYaml: content = f.read_text() assert "key: value" in content + def test_save_preserves_unicode(self, tmp_path: Path) -> None: + """allow_unicode=True writes UTF-8 instead of \\uXXXX escapes.""" + f = tmp_path / "output.yml" + data = {"name": "Тест", "city": "München", "role": "管理员"} + save_vault_yaml(f, data) + content = f.read_text() + assert "Тест" in content + assert "München" in content + assert "管理员" in content + assert "\\u" not in content + + def test_save_unicode_round_trip(self, tmp_path: Path) -> None: + """Saved unicode data loads back correctly.""" + f = tmp_path / "output.yml" + data = {"name": "Тест", "city": "München"} + save_vault_yaml(f, data) + loaded = load_vault_yaml(f) + assert loaded == data + def test_save_with_vault_pass_not_exists(self, tmp_path: Path) -> None: f = tmp_path / "output.yml" vp = tmp_path / "nonexistent"