Merge remote-tracking branch 'origin/store-yaml-helpers-core' into store-yaml-firmware-wt

This commit is contained in:
J. Nick Koston
2026-10-07 13:34:24 -10:00
3 changed files with 18 additions and 2 deletions
+2 -1
View File
@@ -1203,12 +1203,13 @@ def secret_values_registered(values: dict[str, str]) -> Generator[set[str]]:
global _EMITTED_SECRET_NAMES # noqa: PLW0603
added = {v: n for v, n in values.items() if v not in _SECRET_VALUES}
_SECRET_VALUES.update(added)
outer = _EMITTED_SECRET_NAMES
emitted: set[str] = set()
_EMITTED_SECRET_NAMES = emitted
try:
yield emitted
finally:
_EMITTED_SECRET_NAMES = None
_EMITTED_SECRET_NAMES = outer
# Only drop mappings this context still owns; a real !secret loaded
# meanwhile may have registered the same value under its own name.
for value, name in added.items():
+6 -1
View File
@@ -71,8 +71,10 @@ def decode_fields(payload: bytes) -> dict[int, list[int | bytes]]:
value, pos = varint(pos)
elif wire_type == 2:
length, pos = varint(pos)
assert pos + length <= len(buf), "truncated length-delimited field"
value, pos = bytes(buf[pos : pos + length]), pos + length
elif wire_type == 5:
assert pos + 4 <= len(buf), "truncated fixed32 field"
value, pos = int.from_bytes(buf[pos : pos + 4], "little"), pos + 4
else:
raise AssertionError(f"unexpected wire type {wire_type}")
@@ -182,7 +184,10 @@ class RawApiClient:
await asyncio.wait_for(_read_loop(), timeout)
async def read_frame(self, msg_type: int, timeout: float = 10.0) -> bytes:
"""Return the payload of the next frame of msg_type, dropping other frames before it."""
"""Return the payload of the oldest unconsumed frame of msg_type, dropping other frames before it.
Frames received earlier, also through read_until_frame, count as unconsumed.
"""
frames = self._parser.frames
async def _read_loop() -> bytes:
+10
View File
@@ -2005,6 +2005,16 @@ def test_secret_values_registered_keeps_a_real_secret_loaded_meanwhile() -> None
assert yaml_util.is_secret("hunter2") == "real_name"
def test_secret_values_registered_nested_keeps_the_outer_collector() -> None:
"""An inner context does not stop the outer one from collecting names."""
with yaml_util.secret_values_registered({"outer_value": "outer"}) as outer:
with yaml_util.secret_values_registered({"inner_value": "inner"}) as inner:
yaml_util.dump({"a": make_data_base("inner_value")})
yaml_util.dump({"b": make_data_base("outer_value")})
assert inner == {"inner"}
assert outer == {"outer"}
def test_registered_secret_names() -> None:
yaml_util._SECRET_VALUES["value_a"] = "name_a"
assert "name_a" in yaml_util.registered_secret_names()