WIP: feature: Add before Guardrail #26
10
README.md
10
README.md
@@ -104,9 +104,19 @@ Follow these steps before running the compaction test suite:
|
|||||||
```bash
|
```bash
|
||||||
gcloud emulators firestore start --host-port=localhost:8153
|
gcloud emulators firestore start --host-port=localhost:8153
|
||||||
```
|
```
|
||||||
|
In the therminal where execute the test:
|
||||||
|
```bash
|
||||||
|
export FIRESTORE_EMULATOR_HOST=localhost:8153
|
||||||
|
```
|
||||||
3. Execute the tests with `pytest` through `uv`:
|
3. Execute the tests with `pytest` through `uv`:
|
||||||
```bash
|
```bash
|
||||||
uv run pytest tests/test_compaction.py -v
|
uv run pytest tests/test_compaction.py -v
|
||||||
```
|
```
|
||||||
|
|
||||||
If any step fails, double-check that the tools are installed and available on your `PATH` before trying again.
|
If any step fails, double-check that the tools are installed and available on your `PATH` before trying again.
|
||||||
|
|
||||||
|
### Filter emojis
|
||||||
|
Execute the tests with `pytest` command:
|
||||||
|
```bash
|
||||||
|
uv run pytest tests/test_governance_emojis.py
|
||||||
|
```
|
||||||
|
|||||||
69
tests/test_governance_emojis.py
Normal file
69
tests/test_governance_emojis.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
"""Unit tests for the emoji filtering regex."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
os.environ.setdefault("CONFIG_YAML", str(Path(__file__).resolve().parents[1] / "config.yaml"))
|
||||||
|
|
||||||
|
from va_agent.governance import GovernancePlugin
|
||||||
|
|
||||||
|
|
||||||
|
def _make_plugin() -> GovernancePlugin:
|
||||||
|
plugin = object.__new__(GovernancePlugin)
|
||||||
|
plugin._combined_pattern = plugin._get_combined_pattern()
|
||||||
|
return plugin
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def plugin() -> GovernancePlugin:
|
||||||
|
return _make_plugin()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("original", "expected_clean", "expected_removed"),
|
||||||
|
[
|
||||||
|
("Hola 🔪 mundo", "Hola mundo", ["🔪"]),
|
||||||
|
("No 🔪💀🚬 permitidos", "No permitidos", ["🔪", "💀", "🚬"]),
|
||||||
|
("Dedo 🖕 grosero", "Dedo grosero", ["🖕"]),
|
||||||
|
("Dedo 🖕🏾 grosero", "Dedo grosero", ["🖕🏾"]),
|
||||||
|
("Todo Amor: 👩❤️👨 | 👩❤️👩 | 🧑❤️🧑 | 👨❤️👨 | 👩❤️💋👨 | 👩❤️💋👩 | 🧑❤️💋🧑 | 👨❤️💋👨", "Todo Amor: | | | | | | |", ["👩❤️👨", "👩❤️👩", "🧑❤️🧑", "👨❤️👨", "👩❤️💋👨", "👩❤️💋👩", "🧑❤️💋🧑", "👨❤️💋👨"]),
|
||||||
|
("Amor 👩🏽❤️👨🏻 bicolor", "Amor bicolor", ["👩🏽❤️👨🏻"]),
|
||||||
|
("Beso 👩🏻❤️💋👩🏿 bicolor gay", "Beso bicolor gay", ["👩🏻❤️💋👩🏿"]),
|
||||||
|
("Emoji compuesto permitido 👨🏽💻", "Emoji compuesto permitido 👨🏽💻", []),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_remove_emojis_blocks_forbidden_sequences(
|
||||||
|
plugin: GovernancePlugin,
|
||||||
|
original: str,
|
||||||
|
expected_clean: str,
|
||||||
|
expected_removed: list[str],
|
||||||
|
) -> None:
|
||||||
|
cleaned, removed = plugin._remove_emojis(original)
|
||||||
|
|
||||||
|
assert cleaned == expected_clean
|
||||||
|
assert removed == expected_removed
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_emojis_preserves_allowed_people_with_skin_tones(
|
||||||
|
plugin: GovernancePlugin,
|
||||||
|
) -> None:
|
||||||
|
original = "Persona 👩🏽 hola"
|
||||||
|
|
||||||
|
cleaned, removed = plugin._remove_emojis(original)
|
||||||
|
|
||||||
|
assert cleaned == original
|
||||||
|
assert removed == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_remove_emojis_trims_whitespace_after_removal(
|
||||||
|
plugin: GovernancePlugin,
|
||||||
|
) -> None:
|
||||||
|
cleaned, removed = plugin._remove_emojis(" 🔪Hola🔪 ")
|
||||||
|
|
||||||
|
assert cleaned == "Hola"
|
||||||
|
assert removed == ["🔪", "🔪"]
|
||||||
Reference in New Issue
Block a user