6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
"""Unit tests for the agent revert service."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.services.revert_service import can_revert
|
|
|
|
|
|
class _FakeAction:
|
|
def __init__(self, *, user_id: Any, tool_name: str = "edit_file") -> None:
|
|
self.user_id = user_id
|
|
self.tool_name = tool_name
|
|
|
|
|
|
class TestCanRevert:
|
|
def test_owner_can_revert_their_own_action(self) -> None:
|
|
action = _FakeAction(user_id="user-123")
|
|
assert can_revert(requester_user_id="user-123", action=action, is_admin=False)
|
|
|
|
def test_other_user_cannot_revert(self) -> None:
|
|
action = _FakeAction(user_id="user-123")
|
|
assert not can_revert(
|
|
requester_user_id="someone-else", action=action, is_admin=False
|
|
)
|
|
|
|
def test_admin_always_allowed(self) -> None:
|
|
action = _FakeAction(user_id="user-123")
|
|
assert can_revert(requester_user_id="anybody", action=action, is_admin=True)
|
|
|
|
def test_admin_can_revert_anonymous_action(self) -> None:
|
|
action = _FakeAction(user_id=None)
|
|
assert can_revert(requester_user_id="admin", action=action, is_admin=True)
|
|
|
|
def test_anonymous_action_blocks_non_admin(self) -> None:
|
|
action = _FakeAction(user_id=None)
|
|
assert not can_revert(requester_user_id="user-1", action=action, is_admin=False)
|
|
|
|
def test_uuid_string_normalization(self) -> None:
|
|
"""``user_id`` may be a UUID object; comparison should still work."""
|
|
import uuid
|
|
|
|
u = uuid.uuid4()
|
|
action = _FakeAction(user_id=u)
|
|
# Same UUID, passed as string from the requesting side.
|
|
assert can_revert(requester_user_id=str(u), action=action, is_admin=False)
|