Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/commands/test_validate_role_capability_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Tests for commands/validate_role_capability_map.py."""

from pathlib import Path
from typing import Any
from unittest.mock import patch

from se_manifest_schema.commands.validate_role_capability_map import run


def test_run_returns_0_when_valid(tmp_path: Path) -> None:
with patch(
"se_manifest_schema.commands.validate_role_capability_map.validate_role_capability_map_file",
return_value=[],
):
result = run(path=tmp_path / "role-capability-map.toml")
assert result == 0


def test_run_returns_1_when_errors(tmp_path: Path) -> None:
with patch(
"se_manifest_schema.commands.validate_role_capability_map.validate_role_capability_map_file",
return_value=["schema.title: must be a nonempty string"],
):
result = run(path=tmp_path / "role-capability-map.toml")
assert result == 1


def test_run_against_real_file_returns_0() -> None:
project_root = Path(__file__).parent.parent.parent
real_path = project_root / "data" / "schema" / "role-capability-map.toml"
if real_path.exists():
result = run(path=real_path)
assert result == 0
Comment on lines +28 to +33
87 changes: 87 additions & 0 deletions tests/test_graph_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Tests for graph/diagnostics.py - GraphDiagnostic rendering."""

from pathlib import Path

from se_manifest_schema.graph.diagnostics import GraphDiagnostic


def test_render_code_only() -> None:
d = GraphDiagnostic(code="SE.ORG.TEST", message="something went wrong")
result = d.render()
assert result.startswith("SE.ORG.TEST")
assert "something went wrong" in result


def test_render_with_repo() -> None:
d = GraphDiagnostic(code="SE.ORG.TEST", message="bad repo", repo="my-repo")
result = d.render()
assert "my-repo" in result


def test_render_with_path_absolute() -> None:
d = GraphDiagnostic(
code="SE.ORG.TEST",
message="artifact missing",
path="/some/abs/path/file.toml",
)
result = d.render()
assert "/some/abs/path/file.toml" in result


def test_render_with_path_relative_to_root(tmp_path: Path) -> None:
artifact = tmp_path / "sub" / "file.toml"
d = GraphDiagnostic(
code="SE.ORG.TEST",
message="artifact missing",
path=str(artifact),
)
result = d.render(root=tmp_path)
assert "sub/file.toml" in result
assert str(tmp_path) not in result


def test_render_with_path_outside_root_falls_back_to_full(tmp_path: Path) -> None:
other_root = tmp_path / "other"
artifact = tmp_path / "somewhere" / "file.toml"
d = GraphDiagnostic(
code="SE.ORG.TEST",
message="artifact missing",
path=str(artifact),
)
result = d.render(root=other_root)
assert str(artifact) in result


def test_render_with_root_as_string(tmp_path: Path) -> None:
artifact = tmp_path / "sub" / "file.toml"
d = GraphDiagnostic(
code="SE.ORG.TEST",
message="artifact missing",
path=str(artifact),
)
result = d.render(root=str(tmp_path))
assert "sub/file.toml" in result


def test_render_all_fields() -> None:
d = GraphDiagnostic(
code="SE.ORG.CYCLE",
message="dependency cycle detected",
repo="repo-a",
path="/some/path",
)
result = d.render()
lines = result.splitlines()
assert lines[0] == "SE.ORG.CYCLE"
assert any("repo-a" in line for line in lines)
assert any("/some/path" in line for line in lines)
assert any("dependency cycle detected" in line for line in lines)


def test_render_without_repo_or_path() -> None:
d = GraphDiagnostic(code="SE.ORG.GENERIC", message="something failed")
result = d.render()
lines = result.splitlines()
assert len(lines) == 2
assert lines[0] == "SE.ORG.GENERIC"
assert "something failed" in lines[1]
Loading
Loading