4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
102 lines
4.0 KiB
Python
102 lines
4.0 KiB
Python
"""SelectiveEKSBackend — query-aware mock for Axis 2 adversarial tests.
|
|
|
|
Unlike FixtureEKSBackend (which returns every available pod, event, and
|
|
deployment on each call), this backend records every namespace and pod name
|
|
the agent requested so tests can assert the agent asked for the right things.
|
|
|
|
Filtering the returned slice by the requested namespace / pod is reserved for
|
|
a future iteration — the current action registry does not yet narrow requests
|
|
tightly enough for meaningful filtering to help.
|
|
|
|
Usage in test_suite_axis2.py
|
|
-----------------------------
|
|
backend = SelectiveEKSBackend(fixture)
|
|
final_state, score = run_scenario(fixture, use_mock_backends=True, eks_backend=backend)
|
|
assert "payments" in backend.queried_namespaces
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import copy
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
from tests.synthetic.mock_eks_backend.backend import FixtureEKSBackend
|
|
|
|
if TYPE_CHECKING:
|
|
from tests.synthetic.eks.scenario_loader import K8sScenarioFixture
|
|
|
|
|
|
class SelectiveEKSBackend(FixtureEKSBackend):
|
|
"""Query-aware EKSBackend for Axis 2 adversarial testing.
|
|
|
|
Satisfies the EKSBackend Protocol by inheriting every method from
|
|
FixtureEKSBackend, then augments each call with an audit record.
|
|
"""
|
|
|
|
def __init__(self, fixture: K8sScenarioFixture) -> None:
|
|
super().__init__(fixture)
|
|
self.queried_namespaces: list[str] = []
|
|
self.queried_pod_names: list[str] = []
|
|
self.queried_tools: list[str] = []
|
|
|
|
def list_pods(
|
|
self, cluster_name: str = "", namespace: str = "", **kwargs: Any
|
|
) -> dict[str, Any]:
|
|
self.queried_tools.append("list_pods")
|
|
self.queried_namespaces.append(self._namespace(namespace))
|
|
return super().list_pods(cluster_name=cluster_name, namespace=namespace, **kwargs)
|
|
|
|
def get_events(
|
|
self, cluster_name: str = "", namespace: str = "", **kwargs: Any
|
|
) -> dict[str, Any]:
|
|
self.queried_tools.append("get_events")
|
|
self.queried_namespaces.append(self._namespace(namespace))
|
|
return super().get_events(cluster_name=cluster_name, namespace=namespace, **kwargs)
|
|
|
|
def list_deployments(
|
|
self, cluster_name: str = "", namespace: str = "", **kwargs: Any
|
|
) -> dict[str, Any]:
|
|
self.queried_tools.append("list_deployments")
|
|
self.queried_namespaces.append(self._namespace(namespace))
|
|
return super().list_deployments(cluster_name=cluster_name, namespace=namespace, **kwargs)
|
|
|
|
def get_node_health(self, cluster_name: str = "", **kwargs: Any) -> dict[str, Any]:
|
|
self.queried_tools.append("get_node_health")
|
|
return super().get_node_health(cluster_name=cluster_name, **kwargs)
|
|
|
|
def get_pod_logs(
|
|
self,
|
|
cluster_name: str = "",
|
|
namespace: str = "",
|
|
pod_name: str = "",
|
|
**kwargs: Any,
|
|
) -> dict[str, Any]:
|
|
self.queried_tools.append("get_pod_logs")
|
|
self.queried_namespaces.append(self._namespace(namespace))
|
|
self.queried_pod_names.append(pod_name)
|
|
return super().get_pod_logs(
|
|
cluster_name=cluster_name, namespace=namespace, pod_name=pod_name, **kwargs
|
|
)
|
|
|
|
def reset(self) -> None:
|
|
"""Clear the audit log (useful for re-running a scenario)."""
|
|
self.queried_namespaces = []
|
|
self.queried_pod_names = []
|
|
self.queried_tools = []
|
|
|
|
@property
|
|
def unique_queried_tools(self) -> set[str]:
|
|
"""Deduplicated set of all tool methods that were invoked."""
|
|
return set(self.queried_tools)
|
|
|
|
def queried(self, tool_name: str) -> bool:
|
|
"""Return True if ``tool_name`` was ever invoked (exact match)."""
|
|
return tool_name in self.queried_tools
|
|
|
|
def __deepcopy__(self, memo: dict) -> SelectiveEKSBackend:
|
|
new = SelectiveEKSBackend(self._fixture)
|
|
new.queried_namespaces = copy.deepcopy(self.queried_namespaces, memo)
|
|
new.queried_pod_names = copy.deepcopy(self.queried_pod_names, memo)
|
|
new.queried_tools = copy.deepcopy(self.queried_tools, memo)
|
|
return new
|