Camera permission and review fixes (openpanel C3, C4)
C4: a device's `viewers` (superusers by default, or members) covers the image and video messages its ports publish. Anyone else gets none of their values on the socket, in the catalogue or a flow's state, 403 for their history, for the frames they hold (the last 8 included) and for TURN credentials, no bytes when asking for them, and `bye: forbidden` for a live view. A device credential stays bounded by its dashboards. The device page sets it in its Camera section, and a tile the viewer may not see says "No access to this camera" and asks the camera for nothing. C3: - A volatile upload is held to MAX_FRAME_BYTES (4 MiB, 413 above it, read without extra copies), and so is a frame on a device's socket. - A frame the engine holds in memory is written to the ring directory before a local worker is handed it, so load_artifact finds it. - A socket the bus dropped events for catches up with a snapshot, demand included, and a device's credential is checked again per frame, cached by the flow store revision and its nonce, so a lost event never keeps an unpaired device's frames coming. - A report is at most 64 KB once its named config_schemas are put in place. - A device away for 60 s has its true bool messages set to false. - Refused frames are logged by fixed keys, a frame is named after its message, `fluksio serve` waits 5 s for open connections, a tile with a stream URL creates no demand, the 8-name cap keeps the newest names. - Every container's log rotates (json-file, 3 x 10 MB).
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from fluksio.flow.alerts import Alert, AlertManager, AlertsConfig, Channel, Rule
|
||||
from fluksio.flow.controller import HEALTH_FLOOR, FlowController
|
||||
from fluksio.flow.devices import presence
|
||||
@@ -165,3 +167,41 @@ def test_a_device_away_after_a_restart_alerts_nobody(tmp_path: Path) -> None:
|
||||
]
|
||||
assert sent == []
|
||||
presence.forget("wall")
|
||||
|
||||
|
||||
def test_a_device_gone_for_the_grace_reads_false(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""A flag such as `person` stops saying someone is there once the device
|
||||
has been away for the grace, and a device back in time keeps it."""
|
||||
from fluksio.flow.nodes import device as device_node
|
||||
|
||||
monkeypatch.setattr(device_node, "OFFLINE_GRACE_S", 0.1)
|
||||
controller = _controller(tmp_path)
|
||||
|
||||
def bell() -> object:
|
||||
return controller.values("hall")["hall.bell"]["value"]
|
||||
|
||||
async def scenario() -> list[object]:
|
||||
await controller.reload()
|
||||
presence.opened("wall")
|
||||
controller.publish_message("hall.bell", True)
|
||||
seen = [bell()]
|
||||
# Back within the grace: nothing changes.
|
||||
presence.closed("wall")
|
||||
presence.opened("wall")
|
||||
await asyncio.sleep(0.25)
|
||||
seen.append(bell())
|
||||
# Away for good.
|
||||
presence.closed("wall")
|
||||
await asyncio.sleep(0.05)
|
||||
seen.append(bell())
|
||||
await asyncio.sleep(0.25)
|
||||
seen.append(bell())
|
||||
# What reads it hears so too.
|
||||
seen.append(controller.values("hall")["hall.rung"]["value"])
|
||||
await controller._teardown()
|
||||
presence.forget("wall")
|
||||
return seen
|
||||
|
||||
assert asyncio.run(scenario()) == [True, True, True, False, False]
|
||||
|
||||
@@ -69,6 +69,25 @@ def test_a_slow_subscriber_still_loses_its_oldest() -> None:
|
||||
assert oldest == "n50"
|
||||
|
||||
|
||||
def test_a_subscriber_that_lost_events_is_told_once() -> None:
|
||||
"""What a device's socket catches up by: it may have lost its demand."""
|
||||
|
||||
async def run() -> tuple[bool, bool, bool]:
|
||||
bus = EventBus()
|
||||
bus.bind(asyncio.get_running_loop())
|
||||
async with bus.subscribe() as kept, bus.subscribe() as behind:
|
||||
for i in range(QUEUE_SIZE):
|
||||
bus.publish(_event(i))
|
||||
await asyncio.sleep(0.01)
|
||||
while not kept.empty():
|
||||
kept.get_nowait()
|
||||
bus.publish(_event(QUEUE_SIZE))
|
||||
await asyncio.sleep(0.01)
|
||||
return bus.dropped(kept), bus.dropped(behind), bus.dropped(behind)
|
||||
|
||||
assert asyncio.run(run()) == (False, True, False)
|
||||
|
||||
|
||||
def test_nothing_is_buffered_with_nobody_listening() -> None:
|
||||
"""An engine with no browser open holds no events."""
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import time
|
||||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
from fluksio_worker.worker_main import ARTIFACT_DIR_ENV
|
||||
from fluksio_worker.worker_main import ARTIFACT_DIR_ENV, ARTIFACT_VOLATILE_DIR_ENV
|
||||
|
||||
from fluksio.flow.artifacts import ArtifactStore
|
||||
from fluksio.flow.artifacts import ArtifactStore, VolatileStore
|
||||
from fluksio.flow.controller import EmitSink, FlowController
|
||||
from fluksio.flow.messages import DType, MessageSpec
|
||||
from fluksio.flow.nodes import Node
|
||||
@@ -473,6 +473,43 @@ def test_a_node_saves_and_loads_an_artifact(tmp_path):
|
||||
pool.stop()
|
||||
|
||||
|
||||
def test_a_node_opens_a_camera_frame_held_in_memory(tmp_path):
|
||||
"""A frame from a device's socket is in the engine's memory only, which a
|
||||
worker cannot read: the pool writes it out for the call naming it."""
|
||||
store = ArtifactStore(tmp_path / "artifacts")
|
||||
store.volatile = VolatileStore(tmp_path / "ring", 1024 * 1024)
|
||||
pool = PythonWorkerPool(
|
||||
python=sys.executable,
|
||||
size=1,
|
||||
env={
|
||||
ARTIFACT_DIR_ENV: str(store.root),
|
||||
ARTIFACT_VOLATILE_DIR_ENV: str(store.volatile.root),
|
||||
},
|
||||
spill=store.volatile.spill,
|
||||
)
|
||||
pool.start()
|
||||
try:
|
||||
frame = store.put([b"\xff\xd8 a frame"], media_type="image/jpeg", volatile=True)
|
||||
assert not store.volatile._file(frame["digest"]).exists()
|
||||
loaded = pool.run(
|
||||
"demo",
|
||||
"look",
|
||||
"import fluksio\n"
|
||||
"def process(snapshot, earlier):\n"
|
||||
" with open(fluksio.load_artifact(snapshot), 'rb') as f:\n"
|
||||
" return {'bytes': f.read().decode('latin-1')}\n",
|
||||
# Nested, as a node handing on a list of frames would get them.
|
||||
{"snapshot": frame, "earlier": [frame]},
|
||||
"demo.look",
|
||||
timeout=10,
|
||||
)
|
||||
assert loaded == {"bytes": "\xff\xd8 a frame"}
|
||||
# On the ring's directory, which the engine trims, never the volume.
|
||||
assert store.path(frame["digest"]) is None
|
||||
finally:
|
||||
pool.stop()
|
||||
|
||||
|
||||
def test_a_node_passes_audio_to_the_next_one(tmp_path):
|
||||
# The media path end to end: one node writes a clip and declares what kind
|
||||
# of bytes it is, the next opens it. Only the reference travels.
|
||||
|
||||
Reference in New Issue
Block a user