fix(dashboard): address PR review 56
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
||||
import ssl
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -14,6 +15,21 @@ import streamlit_browser_evidence as evidence
|
||||
|
||||
|
||||
SECRET_VALUES = ("synthetic-password", "a" * 64, "cookie-value")
|
||||
SURFACE_STYLE = {
|
||||
"backgroundImage": "linear-gradient(rgb(1, 2, 3), rgb(4, 5, 6))",
|
||||
"backgroundColor": "rgb(255, 255, 255)",
|
||||
"visibility": "visible",
|
||||
"display": "block",
|
||||
"opacity": "1",
|
||||
"rendered": True,
|
||||
}
|
||||
|
||||
|
||||
def surface_records() -> dict[str, dict[str, object]]:
|
||||
return {
|
||||
"stAppViewContainer": dict(SURFACE_STYLE),
|
||||
"stSidebar": dict(SURFACE_STYLE),
|
||||
}
|
||||
|
||||
|
||||
def test_redact_secrets_removes_values_from_nested_manifest() -> None:
|
||||
@@ -39,7 +55,7 @@ def test_validate_transition_manifest_requires_observations() -> None:
|
||||
evidence.validate_transition_manifest(manifest)
|
||||
|
||||
|
||||
def complete_manifest() -> dict[str, object]:
|
||||
def complete_manifest() -> dict[str, Any]:
|
||||
return {
|
||||
"mode": "transition",
|
||||
"success": True,
|
||||
@@ -51,6 +67,7 @@ def complete_manifest() -> dict[str, object]:
|
||||
"body_text_hash": "hash",
|
||||
"loading": False,
|
||||
"prior_body_visible": True,
|
||||
"surfaces": surface_records(),
|
||||
},
|
||||
{
|
||||
"at_ms": 100,
|
||||
@@ -58,6 +75,7 @@ def complete_manifest() -> dict[str, object]:
|
||||
"body_text_hash": "hash2",
|
||||
"loading": True,
|
||||
"prior_body_visible": False,
|
||||
"surfaces": surface_records(),
|
||||
},
|
||||
],
|
||||
"document_navigation_events": [],
|
||||
@@ -66,6 +84,7 @@ def complete_manifest() -> dict[str, object]:
|
||||
"document_marker": {"pre": "doc-1", "post": "doc-1"},
|
||||
"sidebar_marker": {"pre": "side-1", "post": "side-1"},
|
||||
"background": {"pre": "rgb(255, 255, 255)", "post": "rgb(255, 255, 255)"},
|
||||
"surfaces": {"pre": surface_records(), "post": surface_records()},
|
||||
},
|
||||
"loading_observed": True,
|
||||
"prior_body_removed": True,
|
||||
@@ -164,3 +183,47 @@ def test_transition_manifest_rejects_secret_text() -> None:
|
||||
manifest = {"mode": "transition", "success": False, "error": "synthetic-password"}
|
||||
with pytest.raises(ValueError, match="secret"):
|
||||
evidence.validate_transition_manifest(manifest, SECRET_VALUES)
|
||||
|
||||
|
||||
def test_validate_transition_manifest_requires_surface_style_evidence_on_every_frame() -> None:
|
||||
manifest = complete_manifest()
|
||||
manifest["observations"]["frames"][1]["surfaces"].pop("stSidebar")
|
||||
with pytest.raises(ValueError, match="surface"):
|
||||
evidence.validate_transition_manifest(manifest)
|
||||
|
||||
|
||||
def test_validate_transition_manifest_requires_stable_surface_style_evidence() -> None:
|
||||
manifest = complete_manifest()
|
||||
manifest["observations"]["stable_shell"]["surfaces"]["post"]["stSidebar"]["opacity"] = "0"
|
||||
with pytest.raises(ValueError, match="surface"):
|
||||
evidence.validate_transition_manifest(manifest)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field", "value"),
|
||||
(
|
||||
("backgroundImage", "none"),
|
||||
("backgroundColor", ""),
|
||||
("visibility", "hidden"),
|
||||
("display", "none"),
|
||||
("opacity", "0"),
|
||||
("opacity", "NaN"),
|
||||
("rendered", False),
|
||||
),
|
||||
)
|
||||
def test_validate_transition_manifest_rejects_non_visible_surface_styles(field: str, value: object) -> None:
|
||||
manifest = complete_manifest()
|
||||
observations = manifest["observations"]
|
||||
for frame in observations["frames"]:
|
||||
frame["surfaces"]["stAppViewContainer"][field] = value
|
||||
observations["stable_shell"]["surfaces"]["pre"]["stAppViewContainer"][field] = value
|
||||
observations["stable_shell"]["surfaces"]["post"]["stAppViewContainer"][field] = value
|
||||
with pytest.raises(ValueError, match="surface"):
|
||||
evidence.validate_transition_manifest(manifest)
|
||||
|
||||
|
||||
def test_validate_transition_manifest_rejects_missing_stable_shell_markers() -> None:
|
||||
manifest = complete_manifest()
|
||||
manifest["observations"]["stable_shell"]["document_marker"] = {"pre": None, "post": None}
|
||||
with pytest.raises(ValueError, match="shell"):
|
||||
evidence.validate_transition_manifest(manifest)
|
||||
|
||||
Reference in New Issue
Block a user