-
-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathtest_scan_stub.py
More file actions
67 lines (52 loc) · 1.89 KB
/
Copy pathtest_scan_stub.py
File metadata and controls
67 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Offline scan stub — exercises generate_suite with no network generators."""
from typing import Any
import pytest
from giskard.checks import Equals, Scenario, SuiteResult
from giskard.scan.catalog import generate_suite
async def echo(inputs: str) -> str:
return inputs
async def test_generate_suite_empty_generators_offline() -> None:
suite = await generate_suite(
description="Demo support agent",
languages=["en"],
generators=[],
max_scenarios=5,
)
assert suite.scenarios == []
async def test_run_static_scenario_as_scan_stub(
monkeypatch: pytest.MonkeyPatch,
) -> None:
scenario = (
Scenario("stub")
.interact(inputs="ping", outputs=echo)
.check(Equals(key="trace.last.outputs", expected_value="ping"))
)
class _FakeSuite:
def __init__(self) -> None:
self.scenarios = [scenario]
async def run(
self,
target: object,
parallel: bool = True,
max_concurrency: int | None = None,
return_exception: bool = False,
) -> SuiteResult:
_ = parallel, max_concurrency, return_exception
scenario_result = await scenario.run(target=target) # pyright: ignore[reportArgumentType]
return SuiteResult(
results=[scenario_result],
duration_ms=scenario_result.duration_ms,
)
async def fake_generate_suite(**kwargs: Any) -> _FakeSuite:
_ = kwargs
return _FakeSuite()
import giskard.scan.vulnerability as vulnerability_module
monkeypatch.setattr(vulnerability_module, "generate_suite", fake_generate_suite)
from giskard.scan import vulnerability_scan
result = await vulnerability_scan(
target=echo,
description="Demo agent",
languages=["en"],
max_scenarios=1,
)
assert result.pass_rate == 1.0