Skip to content
Merged
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
19 changes: 19 additions & 0 deletions tests/unit/memory/test_attack_analytics_eval_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uuid
from datetime import UTC, datetime, timedelta
from typing import TYPE_CHECKING
from unittest.mock import patch

import pytest
from sqlalchemy import text
Expand Down Expand Up @@ -46,9 +47,19 @@
from unit.mocks import add_legacy_attack_results_async

if TYPE_CHECKING:
from collections.abc import Iterator

from pyrit.memory import SQLiteMemory


@pytest.fixture(autouse=True)
def _freeze_query_clock() -> Iterator[None]:
started = time.monotonic()
with patch("pyrit.memory.query_control.time", spec=time) as clock:
clock.monotonic.return_value = started
yield


def _target(*, deployment: str, endpoint: str, temperature: float = 0.3) -> TargetIdentifier:
return TargetIdentifier(
class_name="MockTarget",
Expand Down Expand Up @@ -82,6 +93,14 @@ def _control() -> QueryControl:
return QueryControl(deadline=time.monotonic() + 20)


def test_identity_query_deadline_does_not_follow_runner_clock() -> None:
control = _control()
remaining = control.remaining
with patch.object(time, "monotonic", return_value=control.deadline + 1):
control.check()
assert control.remaining == remaining


def test_target_evaluation_v1_is_frozen_to_the_current_marker_rules() -> None:
first = _target(deployment="deploy-a", endpoint="https://one.example")
second = _target(deployment="deploy-b", endpoint="https://two.example")
Expand Down
Loading