ci: block repository media assets (#256)
* ci: block repository media assets * test: stabilize cascade scanner loop test
This commit is contained in:
@ -13,6 +13,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from everos.core.persistence import MemoryRoot
|
||||
from everos.memory.cascade import scanner as scanner_module
|
||||
from everos.memory.cascade.scanner import CascadeScanner, _collect_scan_inputs
|
||||
|
||||
|
||||
@ -112,16 +113,26 @@ async def test_run_loop_swallows_scan_exception(
|
||||
scanner = CascadeScanner(mr, scan_interval_seconds=0.05)
|
||||
|
||||
call_count = {"n": 0}
|
||||
second_scan = asyncio.Event()
|
||||
logged_errors: list[str] = []
|
||||
|
||||
async def fake_scan() -> list: # type: ignore[type-arg]
|
||||
call_count["n"] += 1
|
||||
if call_count["n"] == 1:
|
||||
raise RuntimeError("simulated scanner failure")
|
||||
second_scan.set()
|
||||
return []
|
||||
|
||||
def fake_exception(_event: str, *, error: str) -> None:
|
||||
logged_errors.append(error)
|
||||
|
||||
monkeypatch.setattr(scanner, "scan_once", fake_scan)
|
||||
monkeypatch.setattr(scanner_module.logger, "exception", fake_exception)
|
||||
await scanner.start()
|
||||
# Let the loop iterate at least twice (interval is 50ms).
|
||||
await asyncio.sleep(0.2)
|
||||
await scanner.stop()
|
||||
try:
|
||||
await asyncio.wait_for(second_scan.wait(), timeout=1.0)
|
||||
finally:
|
||||
await scanner.stop()
|
||||
|
||||
assert logged_errors == ["simulated scanner failure"]
|
||||
assert call_count["n"] >= 2 # second call ran despite first throwing
|
||||
|
||||
80
tests/unit/test_scripts/test_check_repo_assets.py
Normal file
80
tests/unit/test_scripts/test_check_repo_assets.py
Normal file
@ -0,0 +1,80 @@
|
||||
"""Self-tests for ``scripts/check_repo_assets.py``."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
_REPO_ROOT = Path(__file__).resolve().parents[3]
|
||||
_CHECKER_PATH = _REPO_ROOT / "scripts" / "check_repo_assets.py"
|
||||
|
||||
|
||||
def _load_checker():
|
||||
assert _CHECKER_PATH.exists(), "repo asset checker should exist"
|
||||
spec = importlib.util.spec_from_file_location("_repo_asset_checker", _CHECKER_PATH)
|
||||
assert spec and spec.loader
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = mod
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
def test_clean_source_and_docs_paths_are_allowed() -> None:
|
||||
checker = _load_checker()
|
||||
|
||||
violations = checker.find_violations(
|
||||
[
|
||||
"README.md",
|
||||
"docs/engineering.md",
|
||||
"src/everos/__init__.py",
|
||||
"use-cases/claude-code-plugin/dashboard/dashboard.html",
|
||||
]
|
||||
)
|
||||
|
||||
assert violations == []
|
||||
|
||||
|
||||
def test_image_extensions_are_blocked() -> None:
|
||||
checker = _load_checker()
|
||||
|
||||
violations = checker.find_violations(["docs/banner.png", "icons/logo.svg"])
|
||||
|
||||
assert [violation.path for violation in violations] == [
|
||||
"docs/banner.png",
|
||||
"icons/logo.svg",
|
||||
]
|
||||
assert {violation.reason for violation in violations} == {"image file"}
|
||||
|
||||
|
||||
def test_video_extensions_are_blocked() -> None:
|
||||
checker = _load_checker()
|
||||
|
||||
violations = checker.find_violations(["demo/launch.mp4", "docs/clip.webm"])
|
||||
|
||||
assert [violation.path for violation in violations] == [
|
||||
"demo/launch.mp4",
|
||||
"docs/clip.webm",
|
||||
]
|
||||
assert {violation.reason for violation in violations} == {"video file"}
|
||||
|
||||
|
||||
def test_asset_and_media_directories_are_blocked() -> None:
|
||||
checker = _load_checker()
|
||||
|
||||
violations = checker.find_violations(
|
||||
[
|
||||
"assets/banner.txt",
|
||||
"docs/images/diagram.txt",
|
||||
"use-cases/example/media/story.md",
|
||||
"use-cases/example/videos/walkthrough.md",
|
||||
]
|
||||
)
|
||||
|
||||
assert [violation.path for violation in violations] == [
|
||||
"assets/banner.txt",
|
||||
"docs/images/diagram.txt",
|
||||
"use-cases/example/media/story.md",
|
||||
"use-cases/example/videos/walkthrough.md",
|
||||
]
|
||||
assert {violation.reason for violation in violations} == {"asset/media directory"}
|
||||
Reference in New Issue
Block a user