69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
|
|
import pytest
|
||
|
|
from agent.utils.path_validator import validate_paths
|
||
|
|
|
||
|
|
|
||
|
|
def test_valid_backend_path():
|
||
|
|
errors = validate_paths(
|
||
|
|
["backend/app/services/rebalance.py"],
|
||
|
|
writable=["backend/app/", "backend/tests/"],
|
||
|
|
blocked=[".env", "quant.md"],
|
||
|
|
)
|
||
|
|
assert errors == []
|
||
|
|
|
||
|
|
|
||
|
|
def test_valid_multiple_paths():
|
||
|
|
errors = validate_paths(
|
||
|
|
[
|
||
|
|
"backend/app/api/signal.py",
|
||
|
|
"backend/tests/unit/test_signal.py",
|
||
|
|
"frontend/src/app/page.tsx",
|
||
|
|
"docs/README.md",
|
||
|
|
],
|
||
|
|
writable=["backend/app/", "backend/tests/", "frontend/src/", "docs/"],
|
||
|
|
blocked=[".env"],
|
||
|
|
)
|
||
|
|
assert errors == []
|
||
|
|
|
||
|
|
|
||
|
|
def test_blocked_path_rejected():
|
||
|
|
errors = validate_paths(
|
||
|
|
[".env", "backend/app/main.py"],
|
||
|
|
writable=["backend/app/"],
|
||
|
|
blocked=[".env", "quant.md"],
|
||
|
|
)
|
||
|
|
assert len(errors) == 1
|
||
|
|
assert ".env" in errors[0]
|
||
|
|
|
||
|
|
|
||
|
|
def test_non_writable_path_rejected():
|
||
|
|
errors = validate_paths(
|
||
|
|
["docker-compose.prod.yml"],
|
||
|
|
writable=["backend/app/"],
|
||
|
|
blocked=[],
|
||
|
|
)
|
||
|
|
assert len(errors) == 1
|
||
|
|
|
||
|
|
|
||
|
|
def test_quant_md_blocked():
|
||
|
|
errors = validate_paths(
|
||
|
|
["quant.md"],
|
||
|
|
writable=["backend/app/", "docs/"],
|
||
|
|
blocked=["quant.md"],
|
||
|
|
)
|
||
|
|
assert len(errors) == 1
|
||
|
|
assert "quant.md" in errors[0]
|
||
|
|
|
||
|
|
|
||
|
|
def test_empty_paths_ok():
|
||
|
|
errors = validate_paths([], writable=["backend/app/"], blocked=[".env"])
|
||
|
|
assert errors == []
|
||
|
|
|
||
|
|
|
||
|
|
def test_alembic_versions_writable():
|
||
|
|
errors = validate_paths(
|
||
|
|
["backend/alembic/versions/001_add_table.py"],
|
||
|
|
writable=["backend/alembic/versions/"],
|
||
|
|
blocked=[],
|
||
|
|
)
|
||
|
|
assert errors == []
|