feat(control-station): configure page-specific shell

This commit is contained in:
DCCONSTRUCTIONS
2026-07-26 17:06:04 +03:00
parent dc55ff16c9
commit 360ec39ff3
9 changed files with 619 additions and 259 deletions
+84 -12
View File
@@ -2,6 +2,7 @@ from __future__ import annotations
import asyncio
import hashlib
import json
from collections.abc import Callable
from pathlib import Path
from typing import Any
@@ -71,24 +72,34 @@ def _streaming_request(payload: bytes, media_type: str) -> Request:
)
def test_environment_settings_are_versioned_and_persist_header_labels(tmp_path: Path) -> None:
def test_environment_settings_are_versioned_and_persist_page_controls(tmp_path: Path) -> None:
store = EnvironmentSettingsStore(tmp_path / "operator-environment")
initial = store.read()
assert initial.revision == 0
assert initial.header_labels.polygon == "Тестировочный контур"
assert initial.backgrounds.home.enabled is False
assert initial.pages.polygon.header_label == "Тестировочный контур"
assert initial.pages.fleet.primary_workspace_id == "contour-health"
assert initial.pages.home.background.enabled is False
request = EnvironmentSettingsPut(
revision=initial.revision,
header_labels=initial.header_labels.model_copy(update={"center": "Командный центр"}),
backgrounds=initial.backgrounds,
pages=initial.pages.model_copy(
update={
"observation": initial.pages.observation.model_copy(
update={
"header_label": "Контроль",
"title": "Контроль пространства",
}
)
}
),
)
saved = store.save(request)
restored = EnvironmentSettingsStore(store.root).read()
assert saved.revision == 1
assert restored == saved
assert restored.header_labels.center == "Командный центр"
assert restored.pages.observation.header_label == "Контроль"
assert restored.pages.observation.title == "Контроль пространства"
assert str(tmp_path) not in restored.model_dump_json()
@@ -98,8 +109,7 @@ def test_environment_settings_reject_stale_revision(tmp_path: Path) -> None:
store.save(
EnvironmentSettingsPut(
revision=0,
header_labels=initial.header_labels,
backgrounds=initial.backgrounds,
pages=initial.pages,
)
)
@@ -107,8 +117,7 @@ def test_environment_settings_reject_stale_revision(tmp_path: Path) -> None:
store.save(
EnvironmentSettingsPut(
revision=0,
header_labels=initial.header_labels,
backgrounds=initial.backgrounds,
pages=initial.pages,
)
)
@@ -185,9 +194,8 @@ def test_environment_media_upload_route_streams_and_publishes_safe_metadata(
def test_default_environment_has_every_product_surface() -> None:
document = default_environment_settings()
assert set(document.backgrounds.model_dump()) == {
assert set(document.pages.model_dump()) == {
"home",
"center",
"fleet",
"observation",
"missions",
@@ -195,3 +203,67 @@ def test_default_environment_has_every_product_surface() -> None:
"system",
"polygon",
}
assert document.schema_version == "missioncore.operator-environment/v2"
assert document.pages.fleet.primary_workspace_id == "contour-health"
def test_legacy_v1_environment_is_migrated_without_losing_operator_media(
tmp_path: Path,
) -> None:
store = EnvironmentSettingsStore(tmp_path / "operator-environment")
store.root.mkdir(parents=True)
empty_background = {
"enabled": False,
"source": "file",
"url": None,
"media_kind": None,
"file_name": None,
}
store.settings_path.write_text(
json.dumps(
{
"schema_version": "missioncore.operator-environment/v1",
"revision": 10,
"header_labels": {
"center": "Центр",
"fleet": "Парк",
"observation": "Контроль",
"missions": "Миссии",
"data": "Данные",
"system": "Система",
"polygon": "Тестировочный контур",
},
"backgrounds": {
"home": empty_background,
"center": empty_background,
"fleet": {
"enabled": True,
"source": "file",
"url": (
"/api/v1/environment/media/fleet?generation="
+ "a" * 64
),
"media_kind": "image",
"file_name": "park.png",
},
"observation": empty_background,
"missions": empty_background,
"data": empty_background,
"system": empty_background,
"polygon": empty_background,
},
},
ensure_ascii=False,
indent=2,
)
+ "\n",
encoding="utf-8",
)
migrated = store.read()
assert migrated.revision == 10
assert migrated.pages.observation.header_label == "Контроль"
assert migrated.pages.fleet.background.file_name == "park.png"
assert migrated.pages.fleet.primary_workspace_id == "contour-health"
assert "center" not in migrated.pages.model_dump()