chore(storage): bound build retention, caches and test resources

Track build ownership, qualified pins and bounded cache/log lifecycles. Move Vite fixtures to a job-owned server helper and preserve private outputs outside Git.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:09:58 +03:00
parent 55f64f195b
commit 70ef3f9f1c
119 changed files with 3128 additions and 331 deletions
+19 -19
View File
@@ -13,6 +13,7 @@ from pathlib import Path
from typing import Final
from uuid import uuid4
from k1link.cache_budget import CacheCapacityError, cache_publication
from k1link.compute.lidar_field_review import E10LidarFieldSource
from k1link.compute.lidar_ground import LidarGroundError
from k1link.compute.lidar_local_surface import (
@@ -68,9 +69,7 @@ class K1LocalSurfaceReadService:
) -> None:
if max_entries < 1:
raise ValueError("LiDAR reader cache must retain at least one entry")
self.cache_root = (
cache_root.expanduser().absolute() if cache_root is not None else None
)
self.cache_root = cache_root.expanduser().absolute() if cache_root is not None else None
self.max_entries = max_entries
self._lock = threading.RLock()
self._models: OrderedDict[Path, _ModelEntry] = OrderedDict()
@@ -124,10 +123,7 @@ class K1LocalSurfaceReadService:
) -> tuple[K1LocalSurfaceV1, E10LidarFieldSource]:
model = self._model(model_path)
source_pack_id = model.identity.get("source_pack_id")
if (
not isinstance(source_pack_id, str)
or _E10_PACK_ID.fullmatch(source_pack_id) is None
):
if not isinstance(source_pack_id, str) or _E10_PACK_ID.fullmatch(source_pack_id) is None:
raise LidarGroundError("K1 local-surface source id is invalid")
source_path = source_root / source_pack_id
if not source_path.is_dir():
@@ -254,19 +250,23 @@ class K1LocalSurfaceReadService:
separators=(",", ":"),
sort_keys=True,
).encode("utf-8")
descriptor = os.open(
temporary,
os.O_WRONLY | os.O_CREAT | os.O_EXCL,
0o600,
)
try:
with os.fdopen(descriptor, "wb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, destination)
finally:
temporary.unlink(missing_ok=True)
with cache_publication(root, len(payload), kind="lidar-read-cache"):
descriptor = os.open(
temporary,
os.O_WRONLY | os.O_CREAT | os.O_EXCL,
0o600,
)
try:
with os.fdopen(descriptor, "wb") as stream:
stream.write(payload)
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, destination)
finally:
temporary.unlink(missing_ok=True)
except CacheCapacityError:
return
def _evict_models(self) -> None:
while len(self._models) > self.max_entries:
+25 -3
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import json
import logging
import os
import stat
from datetime import UTC, datetime
from logging.handlers import RotatingFileHandler
from pathlib import Path
@@ -116,7 +117,7 @@ class ScannerDiagnosticJsonFormatter(logging.Formatter):
for field in _EXTRA_FIELDS:
value = getattr(record, field, None)
if value is not None and isinstance(value, (str, int, bool)):
document[field] = value
document[field] = value[:256] if isinstance(value, str) else value
if record.exc_info is not None:
exception_type, _exception, traceback = record.exc_info
if exception_type is not None:
@@ -137,7 +138,28 @@ class ScannerDiagnosticJsonFormatter(logging.Formatter):
for value in properties
):
document["write_characteristic_properties"] = sorted(set(properties))
return json.dumps(document, ensure_ascii=False, separators=(",", ":"))
payload = json.dumps(document, ensure_ascii=False, separators=(",", ":"))
# An oversized extra field cannot bypass the rotation budget in one record.
for field in reversed(_EXTRA_FIELDS):
if len(payload.encode("utf-8")) <= 16384:
break
document.pop(field, None)
document["fields_omitted"] = True
payload = json.dumps(document, ensure_ascii=False, separators=(",", ":"))
return payload
class PrivateRotatingFileHandler(RotatingFileHandler):
def _open(self):
descriptor = os.open(
self.baseFilename, os.O_WRONLY | os.O_CREAT | os.O_APPEND | os.O_NOFOLLOW, 0o600
)
info = os.fstat(descriptor)
if not stat.S_ISREG(info.st_mode) or info.st_nlink != 1 or info.st_uid != os.getuid():
os.close(descriptor)
raise ValueError("Invalid diagnostic journal")
os.fchmod(descriptor, 0o600)
return os.fdopen(descriptor, "a", encoding=self.encoding, errors=self.errors)
def configure_scanner_diagnostics(logs_root: Path) -> Path:
@@ -151,7 +173,7 @@ def configure_scanner_diagnostics(logs_root: Path) -> Path:
if getattr(handler, _HANDLER_MARKER, None) == str(target):
return target
handler = RotatingFileHandler(
handler = PrivateRotatingFileHandler(
target,
maxBytes=5 * 1024 * 1024,
backupCount=5,