# Contributing to AAS-RS

Thanks for helping. Most work on AAS-RS needs only Rust and a system Python 3.
No API keys are needed, and no benchmark download.

## Ground rules

- **Do not change official scoring semantics.** Commit check, run-error rules,
  latest-run selection, `combined` and aggregation are ports of upstream
  AgentAbstain at commit `cfc3faf7ab1c`. A change there must be backed by
  fixtures regenerated from upstream code (see below), not by reasoning alone.
- **Keep the three kinds of numbers separate:** commit check, official
  judge/combined, and AAS-RS diagnostics (see `docs/SCORING.md`).
- **No paid API calls in tests or CI.** Live-model tests must be opt-in and
  `#[ignore]`d.
- **Never commit secrets, datasets or results.** `.gitignore` covers the usual
  places.
- **Be honest about verification.** If you did not run something, say so in
  the PR.

## Setup (offline development)

```bash
git clone https://github.com/amarjaleelbanbhan/aas-rs && cd aas-rs
rustup toolchain install stable -c rustfmt -c clippy
python3 --version        # any Python 3; tests use only the standard library
cargo test --all-targets --all-features
```

If Python is not on `PATH` as `python3`, set `AAS_TEST_PYTHON` (for example
`AAS_TEST_PYTHON=python` on Windows).

## Checks (same as CI)

```bash
cargo fmt --all -- --check
cargo check --all-targets --all-features
cargo clippy --all-targets -- -D warnings
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-targets --all-features
```

## What the test suites cover

| suite | needs | what it proves |
|---|---|---|
| unit tests (`src/**`) | nothing | parsing, validation, scoring and aggregation edge cases |
| `tests/official_fixtures.rs` | nothing | Rust scoring and aggregation equal the **upstream Python** outputs stored in `tests/fixtures/` |
| `tests/properties.rs` | nothing | invariants (bounds, pairing, JSON round trips) |
| `tests/mock_runner.rs` | Python stdlib | process lifecycle, timeouts, budget, secret isolation, against a **mock** server |
| `tests/official_subprocess.rs` | Python stdlib | evaluator subprocess wiring, against a **mock** `eval.runner` |
| `tests/rig_agent_offline.rs` | Python stdlib, `--features rig` | Rig request/response handling and the tool loop, against a **scripted** local HTTP server |
| `tests/upstream_e2e.rs` and one ignored test in `tests/rig_agent_offline.rs` | upstream checkout + dataset | behaviour against **real** benchmark environments |

Mocks test AAS-RS plumbing only. A passing mock test is not evidence of
upstream compatibility.

## Running against the real benchmark

Follow "Installation" in `README.md` (pinned upstream commit and dataset
revision), then:

```bash
export AAS_UPSTREAM=... AGENTABSTAIN_DATA=... AAS_PYTHON=...
cargo test --all-features -- --ignored
cargo run --release -- run --policy always-act --pair critical_tool_failure/preview_002
```

To check scoring against the official Python evaluator on real runs:

```bash
cargo run --release -- run --policy always-abstain --category high_stakes_action \
    --official-results /tmp/aas-results --output /tmp/aas.report.json
$AAS_PYTHON scripts/crosscheck_official.py --upstream $AAS_UPSTREAM --data $AGENTABSTAIN_DATA \
    --official-results /tmp/aas-results --report /tmp/aas.report.json   # must print ALL AGREE
```

## Changing scoring or aggregation

1. Find the upstream function you are porting. Cite file and commit in a
   comment.
2. Add cases to `scripts/gen_official_fixtures.py`. Expected values must come
   from running the upstream code, never from AAS-RS.
3. Regenerate the fixtures with the upstream venv:
   `$AAS_PYTHON -I scripts/gen_official_fixtures.py --upstream $AAS_UPSTREAM --out tests/fixtures`
4. Commit the fixture changes together with the code, and explain the diff in
   the PR.

## Code style

- `rustfmt` defaults. `clippy -D warnings` passes with and without `--features rig`.
- Library errors use `thiserror` enums. No `unwrap` on fallible I/O outside tests.
- No `unsafe` outside tests. Every `unsafe` block needs a `SAFETY:` comment.
- Add a dependency only if it pulls its weight. Say why in the PR.
- Comments explain *why*. When porting upstream behaviour, name the upstream
  source.

## Reporting bugs and proposing features

Use the issue forms (bug report, feature request, documentation). Include the
`aas-rs` commit and the upstream and dataset revisions printed in every report.
Leave out keys. Report security problems privately (see `docs/SECURITY.md`).

## Pull requests

- One coherent change per PR. Link the issue.
- Fill in the PR template checklist.
- Use Conventional Commit style titles (`fix:`, `feat:`, `docs:`, `test:`, `ci:`, `chore:`).
- By contributing you agree that your contribution is licensed under the MIT
  license of this repository.
