Skip to content

Commit bd4ffd0

Browse files
committed
Enable running tests in CI
1 parent 7bb8bc0 commit bd4ffd0

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ jobs:
3434
- name: Lint with ruff
3535
run: make lint
3636

37-
# TODO: enable this once all the tests pass
38-
# - name: Run tests
39-
# run: make tests
37+
- name: Run tests
38+
run: make tests

src/guardrails/types.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class GuardrailResult:
7171
original_exception (Exception | None): The original exception if execution failed.
7272
info (dict[str, Any]): Additional structured data about the check result,
7373
such as error details, matched patterns, or diagnostic messages.
74-
Must include 'checked_text' field containing the processed/validated text.
75-
Defaults to an empty dict.
74+
Implementations may include a 'checked_text' field containing the
75+
processed/validated text when applicable. Defaults to an empty dict.
7676
"""
7777

7878
tripwire_triggered: bool
@@ -82,9 +82,6 @@ class GuardrailResult:
8282

8383
def __post_init__(self) -> None:
8484
"""Validate required fields and consistency."""
85-
if "checked_text" not in self.info:
86-
raise ValueError("GuardrailResult.info must contain 'checked_text' field")
87-
8885
# Ensure consistency: if execution_failed=True, original_exception should be present
8986
if self.execution_failed and self.original_exception is None:
9087
raise ValueError(
@@ -108,5 +105,4 @@ def __post_init__(self) -> None:
108105
TCfg (TypeVar): The configuration type, usually a Pydantic model.
109106
Returns:
110107
GuardrailResult or Awaitable[GuardrailResult]: The outcome of the guardrail check.
111-
The result must include 'checked_text' in the info dict.
112108
"""

tests/unit/test_registry.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def check(_ctx: CtxProto, _value: str, _config: int) -> GuardrailResult:
3737
return GuardrailResult(tripwire_triggered=False)
3838

3939
model = _resolve_ctx_requirements(check)
40-
fields = getattr(model, "model_fields", getattr(model, "__fields__", {}))
40+
# Prefer Pydantic v2 API without eagerly touching deprecated v1 attributes
41+
fields = (
42+
model.model_fields
43+
if hasattr(model, "model_fields")
44+
else getattr(model, "__fields__", {})
45+
)
4146
assert issubclass(model, BaseModel) # noqa: S101
4247
assert set(fields) == {"foo"} # noqa: S101
4348

0 commit comments

Comments
 (0)