"""Unit tests for git operations."""
from domin8.git_ops import create_diff, generate_commit_message
def test_create_diff():
"""Test unified diff creation."""
original = "line 1\nline 2\nline 3\n"
new = "line 1\nline 2 modified\nline 3\n"
diff = create_diff(original, new, "test.txt")
assert "--- a/test.txt" in diff
assert "+++ b/test.txt" in diff
assert "-line 2" in diff
assert "+line 2 modified" in diff
def test_generate_commit_message():
"""Test commit message generation."""
uuid = "550e8400-e29b-41d4-a716-446655440000"
path = "src/test.py"
meta = {
"action": "edit",
"actor": {"id": "test-agent", "type": "agent"},
"pre_state_sha": "abc123",
"post_state_sha": "def456",
"created_at": "2026-01-12T16:34:00+00:00"
}
intent = {
"summary": "Fix bug in test function because it failed to handle X edge case",
"diff": "@@ -1 +1 @@\n- old\n+ new\n"
}
approval = {
"approver_id": "human-reviewer",
"approved_at": "2026-01-12T17:00:00+00:00",
"decision": "approved",
"comments": "Looks good"
}
msg = generate_commit_message(uuid, path, meta, intent, approval)
# Check key components
assert f"domin8: {uuid}" in msg
assert path in msg
assert "EDIT" in msg
assert "Fix bug in test function" in msg
assert "test-agent" in msg
# tags are intentionally removed from commit messages
# Previous versions included explainability bullets; with the simplified schema the agent summary is used instead
assert "Fix bug in test function" in msg
assert "human-reviewer" in msg
assert "Artifact reference:" in msg