Skip to content

Commit bbc0295

Browse files
committed
[FIX]: Apply the _async naming convention repo-wide
Clears the .flake8 baseline added in the previous commit, so RMP001 is now enforced everywhere with no exemptions. Renames 8 async functions in rampart/ and 139 async test functions, plus all call sites, tests and docs. The test standards already required the suffix on async test names and 99 tests already followed it; this makes the rest consistent. pytest discovers tests by the test_ prefix, so the suffix does not affect collection and the test count is unchanged. InjectionHandle is a @runtime_checkable Protocol, so renaming wait_until_ready changes what isinstance() accepts. Attacks.xpia had an unguarded else branch that treated a non-conforming handle as a list, producing an unrelated "not iterable" TypeError deep in execution instead of a clear error at the boundary. That branch is now guarded and covered by tests.
1 parent d0dffce commit bbc0295

31 files changed

Lines changed: 233 additions & 234 deletions

‎.flake8‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ select = RMP
88
# are kept rather than replaced.
99
extend-exclude = .venv,build,dist
1010

11-
# Baseline of pre-existing violations, recorded so the rule can be enforced
12-
# from day one without a large mechanical rename in the same change. Each
13-
# entry is removed by the commit that fixes the file. Do not add new entries.
14-
per-file-ignores =
15-
rampart/core/execution.py:RMP001
16-
rampart/core/injection.py:RMP001
17-
rampart/evaluators/llm_judge.py:RMP001
18-
rampart/pyrit_bridge/llm_bridge.py:RMP001
19-
rampart/pytest_plugin/_collection.py:RMP001
20-
rampart/surfaces/onedrive.py:RMP001
21-
tests/*:RMP001
22-
2311
[flake8:local-plugins]
2412
extension =
2513
RMP = flake8_rampart:RampartChecker

‎.github/instructions/coding-standards.instructions.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,8 @@ while `# noqa:` is reserved for external codes like `RMP001`, which flake8
623623
rather than ruff reads. `RMP001` is listed in `[tool.ruff.lint] external` so
624624
that ruff's `RUF102` accepts it instead of rejecting it as an unknown code.
625625

626-
`.flake8` carries a `per-file-ignores` baseline of files that predate the rule.
627-
Those entries are removed as the files are fixed; do not add new ones.
628-
626+
`RMP001` applies repo-wide, including to tests: the test standards require the
627+
`_async` suffix on async test names too.
629628
[flake8-local]: https://flake8.pycqa.org/en/latest/user/configuration.html#using-local-plugins
630629

631630
---

‎.github/instructions/unit-tests-standards.instructions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TestParseConfig:
3737
```
3838

3939
### Async Tests
40-
- Async test method names MUST end with `_async`
40+
- Async test method names MUST end with `_async` (enforced by `RMP001`)
4141
- Use `AsyncMock` instead of `MagicMock` when mocking async methods
4242

4343
```python

‎docs/api/core-protocols.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Protocols and ABCs that define RAMPART's extension points. Implement these to co
3232
members:
3333
- Surface
3434
- InjectionHandle
35-
- sleep_until_ready
35+
- sleep_until_ready_async
3636

3737
## Converter
3838

‎docs/attacks/xpia.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sequenceDiagram
1717
1818
Test->>Surface: inject(payload) → handle
1919
Note over Surface: Payload placed in data source
20-
Test->>Surface: handle.wait_until_ready()
20+
Test->>Surface: handle.wait_until_ready_async()
2121
Test->>Agent: session.send_async("Summarize reports")
2222
Agent-->>Test: Response (text + tool_calls)
2323
Test->>Eval: evaluate_async(context)
@@ -28,7 +28,7 @@ sequenceDiagram
2828
**Phases:**
2929

3030
1. **Inject** — Place payloads into the agent's data sources via surfaces. Each `surface.inject(payload)` returns an [`InjectionHandle`][rampart.core.injection.InjectionHandle].
31-
2. **Wait** — Handles call `wait_until_ready()` to allow indexing. Runs concurrently for multiple surfaces.
31+
2. **Wait**: Handles call `wait_until_ready_async()` to allow indexing. Runs concurrently for multiple surfaces.
3232
3. **Trigger** — Send benign prompts that cause the agent to retrieve the injected content. Triggers are never adversarial — the attack is in the payload, not the prompt.
3333
4. **Evaluate** — Check each turn for the attack objective. Early-stops on detection.
3434
5. **Clean up** — Remove injected content. Guaranteed via `AsyncExitStack`, even on exceptions.

‎docs/contributing/extending-rampart.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ For the basic protocol skeleton, see [Implementing Surfaces](../usage/authoring-
337337

338338
- **`Surface.inject` does not activate** — it only prepares the handle. Activation happens when an execution strategy enters the handle as an async context manager.
339339
- **`__aexit__` must be idempotent and must not raise** — cleanup runs even on exceptions, and a failing cleanup must not mask the original error.
340-
- **`wait_until_ready` should bound itself** with `TimeoutError` rather than block indefinitely. For simple delay-based waits, call `sleep_until_ready` from `rampart.core.injection`.
340+
- **`wait_until_ready_async` should bound itself** with `TimeoutError` rather than block indefinitely. For simple delay-based waits, call `sleep_until_ready_async` from `rampart.core.injection`.
341341
- **Raise `InfrastructureError`** for transient, external failures (timeouts, rate limits, service outages). It's the documented convention for surfaces and adapters to signal "not a safety signal" — `BaseExecution` catches all exceptions and produces an `ERROR` result either way, but the exception type is preserved in metadata for triage.
342342

343343
For a complete reference, see [`OneDriveSurface`](https://github.com/microsoft/RAMPART/blob/main/rampart/surfaces/onedrive.py).

‎docs/usage/authoring-tests.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class MyFileSurface:
270270
def surface_name(self) -> str:
271271
return "file_system"
272272

273-
async def wait_until_ready(self) -> None:
273+
async def wait_until_ready_async(self) -> None:
274274
pass # or: await asyncio.sleep(10.0) for indexing delay
275275

276276
async def __aenter__(self):

‎rampart/attacks/_xpia.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def _activate_handles_async(
169169
# Concurrent: total = max of all wait times
170170
async with asyncio.TaskGroup() as tg:
171171
for handle in self._handles:
172-
tg.create_task(handle.wait_until_ready())
172+
tg.create_task(handle.wait_until_ready_async())
173173

174174
def _build_attack_result(
175175
self,

‎rampart/core/execution.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ExecutionEventHandler(ABC):
7373
"""
7474

7575
@abstractmethod
76-
async def on_event(self, *, event_data: ExecutionEventData) -> None:
76+
async def on_event_async(self, *, event_data: ExecutionEventData) -> None:
7777
"""Handle an execution lifecycle event.
7878
7979
Args:
@@ -231,7 +231,7 @@ async def execute_async(self, *, adapter: AgentAdapter) -> Result:
231231
Result: Safety verdict with evidence and diagnostics.
232232
"""
233233
start = time.monotonic()
234-
await self._fire(
234+
await self._fire_async(
235235
ExecutionEvent.ON_PRE_EXECUTE,
236236
adapter=adapter,
237237
elapsed=0.0,
@@ -247,7 +247,7 @@ async def execute_async(self, *, adapter: AgentAdapter) -> Result:
247247
self.strategy_name,
248248
)
249249

250-
await self._fire(
250+
await self._fire_async(
251251
ExecutionEvent.ON_ERROR,
252252
adapter=adapter,
253253
elapsed=time.monotonic() - start,
@@ -264,7 +264,7 @@ async def execute_async(self, *, adapter: AgentAdapter) -> Result:
264264

265265
elapsed = time.monotonic() - start
266266
result.duration_seconds = elapsed
267-
await self._fire(
267+
await self._fire_async(
268268
ExecutionEvent.ON_POST_EXECUTE,
269269
adapter=adapter,
270270
elapsed=elapsed,
@@ -284,7 +284,7 @@ async def _execute_async(self, *, adapter: AgentAdapter) -> Result:
284284
"""
285285
...
286286

287-
async def _fire(
287+
async def _fire_async(
288288
self,
289289
event: ExecutionEvent,
290290
*,
@@ -314,7 +314,7 @@ async def _fire(
314314
)
315315
for handler in self._handlers:
316316
try:
317-
await handler.on_event(event_data=event_data)
317+
await handler.on_event_async(event_data=event_data)
318318
except Exception:
319319
logger.warning(
320320
"ExecutionEventHandler %s raised on %s — ignored.",

‎rampart/core/injection.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Two protocols serving two audiences: Surface is what surface authors
77
implement; InjectionHandle is what execution strategies consume.
88
9-
``sleep_until_ready`` is a helper function for surfaces that only need
9+
``sleep_until_ready_async`` is a helper function for surfaces that only need
1010
a simple delay-based readiness wait.
1111
"""
1212

@@ -43,7 +43,7 @@ def surface_name(self) -> str:
4343
"""The name of the surface this handle injects into (e.g., 'SharePoint')."""
4444
...
4545

46-
async def wait_until_ready(self) -> None:
46+
async def wait_until_ready_async(self) -> None:
4747
"""Block until the injected content is visible to the agent.
4848
4949
Implementations should raise `TimeoutError` if readiness
@@ -52,7 +52,7 @@ async def wait_until_ready(self) -> None:
5252
...
5353

5454

55-
async def sleep_until_ready(delay: float) -> None:
55+
async def sleep_until_ready_async(delay: float) -> None:
5656
"""Sleep for `delay` seconds. Default readiness strategy for simple surfaces.
5757
5858
Args:

0 commit comments

Comments
 (0)