- agent_handler: guard scenario_mode against None uicontext (regression in test_handler_missing_auth_continues_gracefully) - tools_038.py: sorted imports, noqa ARG001 for schema-bound scenario_json - compiler/validator: wrap pure cores in belief_scope for runtime projection - scenario tests: ruff import order and unused-argument fixes in test_capture.py, test_capture_dispatch.py, test_vlm.py Backend scenario 80 passed; dashboard-testing 378 passed; agent 352 passed, 12 skipped; ruff clean for 038 scope.
54 lines
2.7 KiB
Python
54 lines
2.7 KiB
Python
# #region Test.Scenario.CaptureDispatch [C:3] [TYPE Module] [SEMANTICS testing,scenario,capture,dispatch]
|
|
# @defgroup Test.Scenario Capture dispatch through 036 Evidence bridge.
|
|
# @LAYER Test
|
|
# @RELATION BINDS_TO -> [ScenarioGraph.Capture.Dispatch]
|
|
# @RATIONALE Capture must register artifacts via 036 and apply masking when selectors exist.
|
|
# @REJECTED Testing only profile loading — dispatch is the integration boundary.
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock
|
|
|
|
from src.services.dashboard_testing.scenario.capture import dispatch_capture
|
|
from src.services.dashboard_testing.scenario.capture_profile import load_profile
|
|
|
|
|
|
def test_dispatch_without_mask_registers_original_only(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
registered: list[tuple] = []
|
|
|
|
def _fake_register(_db, _run_id, _user_id, name, intended_path, sha256, capture_meta, validation_status="pending"): # noqa: ARG001
|
|
registered.append(("original", name))
|
|
return MagicMock(id="art-1")
|
|
|
|
monkeypatch.setattr("src.services.dashboard_testing.scenario.capture.register_screenshot_draft", _fake_register)
|
|
monkeypatch.setattr("src.services.dashboard_testing.scenario.capture.register_masked_derivative", lambda *_a, **_k: (_ for _ in ()).throw(AssertionError("masked must not be called")))
|
|
|
|
profile = load_profile("default")
|
|
profile = profile.model_copy(update={"mask_selectors": []})
|
|
result = dispatch_capture(MagicMock(), "run-1", "user-1", "step-capture", profile)
|
|
assert len(result["artifact_refs"]) == 1
|
|
assert result["artifact_refs"][0]["masked"] is False
|
|
assert registered[0][1] == "step-capture_original"
|
|
|
|
|
|
def test_dispatch_with_mask_registers_both(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
registered: list[str] = []
|
|
|
|
def _fake_register(_db, _run_id, _user_id, name, intended_path, sha256, capture_meta, validation_status="pending"): # noqa: ARG001
|
|
registered.append("original")
|
|
return MagicMock(id="art-1")
|
|
|
|
def _fake_masked(_db, _run_id, _user_id, original_artifact_id, derivative_sha256, intended_path): # noqa: ARG001
|
|
registered.append("masked")
|
|
return MagicMock(id="art-2")
|
|
|
|
monkeypatch.setattr("src.services.dashboard_testing.scenario.capture.register_screenshot_draft", _fake_register)
|
|
monkeypatch.setattr("src.services.dashboard_testing.scenario.capture.register_masked_derivative", _fake_masked)
|
|
|
|
profile = load_profile("default").model_copy(update={"mask_selectors": ["#chart-1"]})
|
|
result = dispatch_capture(MagicMock(), "run-1", "user-1", "step-capture", profile)
|
|
assert len(result["artifact_refs"]) == 2
|
|
assert result["artifact_refs"][1]["masked"] is True
|
|
assert registered == ["original", "masked"]
|