Skip to content

Commit c01ca3e

Browse files
Add mypy type checking, test fixtures, and build docs
- Add mypy config to pyproject.toml with baseline error suppressions - Add mypy step to lint CI workflow - Add make typecheck and make check (lint + typecheck + test) targets - Create tests/fixtures/ with sample garak config, intents models, report JSONL - Document dependency extras and lockfile workflow in CONTRIBUTING.md Made-with: Cursor
1 parent 402bc63 commit c01ca3e

File tree

7 files changed

+95
-3
lines changed

7 files changed

+95
-3
lines changed

.github/workflows/lint.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ jobs:
2020
with:
2121
python-version: '3.12'
2222

23-
- name: Install ruff
24-
run: pip install ruff
23+
- name: Install tools
24+
run: pip install ruff mypy
2525

2626
- name: Ruff check
2727
run: ruff check src/ tests/
2828

2929
- name: Ruff format check
3030
run: ruff format --check src/ tests/
31+
32+
- name: Mypy type check
33+
run: mypy src/

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ pip install -e ".[dev]"
1919
pre-commit install
2020
```
2121

22+
## Dependency Management
23+
24+
Dependencies are declared in `pyproject.toml` with optional extras:
25+
26+
| Extra | Install Command | What You Get |
27+
|-------|----------------|-------------|
28+
| (none) | `pip install -e .` | Core provider (Llama Stack remote mode) |
29+
| `[inline]` | `pip install -e ".[inline]"` | Core + garak for local scans |
30+
| `[dev]` | `pip install -e ".[dev]"` | Tests + ruff + pre-commit |
31+
| `[server]` | `pip install -e ".[server]"` | Llama Stack server |
32+
33+
**Lockfile**: `requirements.txt` is a pinned lockfile generated from the
34+
[RH AI PyPI index](https://console.redhat.com/api/pypi/public-rhai/rhoai/3.4/cpu-ubi9-test/simple/)
35+
via `uv pip compile`. It's used by downstream production builds for hermetic
36+
dependency pre-fetching. Regenerate with `make lock`.
37+
38+
**Container image**: The dev `Containerfile` installs from standard PyPI with
39+
garak from the midstream git branch. Production images use the AIPCC base image
40+
with the RH AI index. See `Containerfile` for the dev build and
41+
`Dockerfile.konflux` (downstream) for production.
42+
2243
## Development Workflow
2344

2445
### Running Tests

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test coverage lint format build lock install install-dev
1+
.PHONY: test coverage lint format typecheck check build lock install install-dev
22

33
test:
44
pytest tests -v
@@ -12,6 +12,11 @@ lint:
1212
format:
1313
ruff format src/ tests/
1414

15+
typecheck:
16+
mypy src/
17+
18+
check: lint typecheck test
19+
1520
build:
1621
docker build -f Containerfile -t trustyai-garak:dev .
1722

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,23 @@ ignore = [
8282
"tests/*" = ["F401", "F841"]
8383
"src/*/inline/garak_eval.py" = ["F841"]
8484
"src/*/remote/garak_remote_eval.py" = ["F841"]
85+
86+
[tool.mypy]
87+
python_version = "3.12"
88+
warn_unused_configs = true
89+
ignore_missing_imports = true
90+
check_untyped_defs = false
91+
disable_error_code = [
92+
"union-attr",
93+
"assignment",
94+
"no-any-return",
95+
"arg-type",
96+
"attr-defined",
97+
"valid-type",
98+
"no-redef",
99+
"call-arg",
100+
"var-annotated",
101+
"return-value",
102+
"index",
103+
"override",
104+
]

tests/fixtures/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Test Fixtures
2+
3+
Sample data files used by the test suite.
4+
5+
| File | Purpose |
6+
|------|---------|
7+
| `sample_garak_config.yaml` | Example garak config matching `GarakCommandConfig` schema |
8+
| `sample_intents_models.json` | Intents model endpoint configurations (single-role and all-roles) |
9+
| `sample_report.jsonl` | Minimal garak report JSONL output for result parsing tests |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Sample garak config used in tests.
2+
# Mirrors the structure of GarakCommandConfig.
3+
system:
4+
verbose: false
5+
parallel_requests: 0
6+
parallel_attempts: 1
7+
8+
run:
9+
seed: 42
10+
eval_threshold: 0.5
11+
generations: 5
12+
deprefix: true
13+
extended_detectors: false
14+
15+
plugins:
16+
model_type: openai.OpenAICompatible
17+
model_name: target-llm
18+
19+
probe_spec:
20+
- encoding.InjectBase64
21+
- promptinject.HijackHateHumans
22+
23+
extended_detectors: false
24+
25+
probes: {}
26+
detectors: {}
27+
buffs: {}
28+
29+
reporting:
30+
taxonomy: owasp
31+
report_prefix: scan

tests/fixtures/sample_report.jsonl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"entry_type": "config", "model_name": "target-llm", "model_type": "openai.OpenAICompatible"}
2+
{"entry_type": "attempt", "probe": "encoding.InjectBase64", "detector": "always.Pass", "passed": true, "prompt": "test prompt", "output": "test output", "trigger": null}
3+
{"entry_type": "eval", "probe": "encoding.InjectBase64", "detector": "always.Pass", "passed": 1, "total": 1, "rate": 1.0}

0 commit comments

Comments
 (0)