feat: update repository names to support special characters in configuration files

Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
d9pouces
2026-10-09 19:13:12 +02:00
parent 1e9e87b11c
commit e58820ac98
13 changed files with 58 additions and 15 deletions
+29
View File
@@ -1,3 +1,5 @@
import tomllib
from id_configurator.config import Configuration
from id_configurator.context import Context
from id_configurator.modules.python import PythonModule
@@ -76,6 +78,33 @@ def test_apply_single_repository(tmp_path) -> None:
assert not (dst / "usr/lib").exists()
def test_apply_escapes_non_bmp_characters_as_valid_toml(tmp_path) -> None:
data = {
"uuid": "12345678-1234-5678-1234-567812345678",
"organisation": "InterDiode",
"configurations": {
"python": {
"repositories": [
{"name": "demo 😀", "index-url": "https://example.invalid/simple"}
]
}
},
}
config = Configuration.model_validate(data)
dst = tmp_path / "dst"
context = Context(config=config, dst=dst, src=None)
PythonModule().apply(context)
uv_toml = (dst / "etc/uv/uv.toml").read_text(encoding="utf-8")
# json.dumps's default ensure_ascii=True would encode the emoji as a
# UTF-16 surrogate pair (😀), which is valid JSON but not
# valid TOML (TOML's \uXXXX must be a Unicode scalar value on its own).
assert '"demo 😀"' in uv_toml
parsed = tomllib.loads(uv_toml)
assert parsed["index"][0]["name"] == "demo 😀"
def test_apply_adds_trusted_host_for_non_https_repository(tmp_path) -> None:
data = {
"uuid": "12345678-1234-5678-1234-567812345678",