Skip to content

feat: bench-gate harness — corpus-root fixture, six module stubs, lab runner (#319) - #320

Merged
yoshi280 merged 5 commits into
mainfrom
feat/bench-gate-harness
Apr 30, 2026
Merged

feat: bench-gate harness — corpus-root fixture, six module stubs, lab runner (#319)#320
yoshi280 merged 5 commits into
mainfrom
feat/bench-gate-harness

Conversation

@yoshi280

@yoshi280 yoshi280 commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #319.

Public-repo bench-gate harness. No corpus content moves.

What lands

Verification

  • uv run pytest tests/bench_gate/ → 6 skipped, 0 failed (corpus absent on public repo). Skip reasons reference AELFRICE_CORPUS_ROOT.
  • Public CI stays green: bench-gate tests skip, never fail.

Out of scope

Detector implementations (live in #193/#197/#199/#201/#228/#229). Corpus content (lab repo, governed by #307).

Summary by Sourcery

Introduce a v2.0 bench-gate harness wired to an external evaluation corpus, keeping public CI green by skipping when the lab corpus is unavailable.

New Features:

  • Add a shared pytest fixture and helpers to resolve the AELFRICE_CORPUS_ROOT corpus directory and load per-module JSONL rows for bench-gated tests.
  • Add six bench-gate test modules that exercise the v2.0 detectors against the labeled corpus behind a bench_gated marker.
  • Add a lab-side run_bench_gate.sh script to run the bench-gate suite against a mounted private corpus.

Enhancements:

  • Register a bench_gated pytest marker in pyproject.toml to integrate the new harness into the existing test configuration.

Documentation:

  • Update the v2.0 corpus README with bench-gate harness usage, environment variable configuration, and lab mounting instructions.

Tests:

  • Introduce a dedicated tests/bench_gate/ test suite that validates detector performance against the v2.0 evaluation corpus while cleanly skipping when detectors or corpus are absent.

Summary by CodeRabbit

  • New Features

    • Added a bench-gate testing harness with an executable entrypoint to run labeled-corpus validation suites; tests auto-skip when the local corpus is not mounted and enforce minimum accuracy thresholds.
  • Tests

    • Added benchmark-gated suites exercising multiple detectors (contradiction, dedup, enforcement, promotion trigger, sentiment, consolidation) against labeled corpora.
  • Documentation

    • Updated corpus README with lab setup and run instructions for the benchmark suite.

Public-side scaffold for the v2.0 bench-gate harness. Resolves
AELFRICE_CORPUS_ROOT to a directory and exposes load_corpus_module()
to bench-gate tests. Public CI passes without corpus access; lab
runners export the env var to point at ~/projects/aelfrice-lab/tests/corpus/v2_0.

No corpus content moves; the locked rule on ~/.claude/-derived content
is respected.
One pytest entry-point per bench-gated module — #197 dedup,
#199 enforcement, #201 contradiction, #228 wonder_consolidation,
#229 promotion_trigger, #193 sentiment. Each loads the lab corpus via
the AELFRICE_CORPUS_ROOT fixture and skips when the detector module
isn't yet implemented. Public CI: 6 skipped (corpus absent). Lab CI
with corpus mounted: 6 skipped (detectors not yet shipped) — flips to
real assertions as each detector lands.
Defaults AELFRICE_CORPUS_ROOT to ~/projects/aelfrice-lab/tests/corpus/v2_0
matching the two-repo layout in CLAUDE.md. Errors clearly when the
corpus dir is missing rather than silently skipping. The script lives
public-side (path string only, no derived content).
…tions

Removes the stale #288 cross-reference (#288 is the rebuilder-precision
harness, not the v2.0 bench-gate harness). Documents AELFRICE_CORPUS_ROOT
and the run_bench_gate.sh entrypoint for lab-side runs.
@sourcery-ai

sourcery-ai Bot commented Apr 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a public bench-gate harness for the v2.0 evaluation corpus driven by an AELFRICE_CORPUS_ROOT-based pytest fixture, adds six per-module bench-gated tests that currently stub detector imports but fully exercise corpus loading, wires the new bench_gated marker into pytest config, documents lab-side corpus mounting, and provides a convenience script to run the suite in lab environments while ensuring public CI skips cleanly without the private corpus.

Sequence diagram for bench_gate harness execution via run_bench_gate.sh

sequenceDiagram
    actor LabUser
    participant run_bench_gate_sh as run_bench_gate_sh
    participant Env as environment
    participant Pytest as pytest
    participant Conftest as tests_conftest
    participant CorpusFixture as corpus_root_fixture
    participant BenchTests as bench_gate_tests

    LabUser->>run_bench_gate_sh: invoke script
    run_bench_gate_sh->>Env: read AELFRICE_CORPUS_ROOT
    alt env_var_unset
        Env-->>run_bench_gate_sh: unset
        run_bench_gate_sh->>Env: set default corpus path
    else env_var_set
        Env-->>run_bench_gate_sh: existing value
    end

    run_bench_gate_sh->>Env: export AELFRICE_CORPUS_ROOT
    run_bench_gate_sh->>Env: check corpus directory exists
    alt corpus_dir_missing
        run_bench_gate_sh-->>LabUser: print error and exit 1
    else corpus_dir_present
        run_bench_gate_sh->>Pytest: exec uv run pytest tests/bench_gate/ -m bench_gated
        Pytest->>Conftest: load configuration and fixtures
        Conftest->>Pytest: register bench_gated marker
        Pytest->>CorpusFixture: request corpus_root fixture
        CorpusFixture->>Env: read AELFRICE_CORPUS_ROOT
        Env-->>CorpusFixture: corpus path
        CorpusFixture-->>Pytest: provide corpus_root path

        loop each_bench_gate_test
            Pytest->>BenchTests: collect and run test
            BenchTests->>Conftest: apply autouse bench_gated marker
            Conftest->>Env: check AELFRICE_CORPUS_ROOT and per_module_dir
            alt corpus_available_for_module
                BenchTests->>CorpusFixture: load JSONL from corpus_root
                BenchTests-->>Pytest: test passes or fails
            else corpus_missing_for_module
                Conftest-->>Pytest: mark test as skipped
            end
        end

        Pytest-->>LabUser: report results
    end
Loading

File-Level Changes

Change Details Files
Add shared pytest corpus-root fixture and JSONL loader that gate tests based on AELFRICE_CORPUS_ROOT presence and module content.
  • Introduce CORPUS_ENV_VAR constant and helper _corpus_root() that resolves and validates the environment-configured corpus directory.
  • Add aelfrice_corpus_root session-scoped fixture that skips tests when the env var is unset, invalid, or directory missing.
  • Implement load_corpus_module() helper to load all JSONL rows under a module subdirectory and skip when the module dir is missing or empty.
tests/conftest.py
Create six bench-gated pytest entry-points for v2.0 modules that load module-specific corpus slices and assert minimal detector behavior, while skipping cleanly until detectors ship.
  • Add test_dedup_detector_against_corpus that loads the 'dedup' corpus partition, conditionally imports aelfrice.dedup, and asserts a minimum accuracy threshold.
  • Add test_contradiction_detector_against_corpus that uses the 'contradiction' partition and aelfrice.relationship_detector with an accuracy floor.
  • Add test_enforcement_detector_against_corpus for the 'enforcement' partition that evaluates aelfrice.enforcement on directive/output pairs with an accuracy floor.
  • Add test_promotion_trigger_against_corpus that consumes 'promotion_trigger' rows and checks aelfrice.promotion_trigger.decide meets an accuracy floor.
  • Add test_sentiment_detector_against_corpus over the 'sentiment' partition using aelfrice.sentiment.classify with an accuracy floor.
  • Add test_wonder_consolidation_against_corpus over the 'wonder_consolidation' partition that asserts the strategy scorer returns numeric ratings for all rows without defining the final metric.
tests/bench_gate/test_dedup.py
tests/bench_gate/test_contradiction.py
tests/bench_gate/test_enforcement.py
tests/bench_gate/test_promotion_trigger.py
tests/bench_gate/test_sentiment.py
tests/bench_gate/test_wonder_consolidation.py
Wire up a bench_gated pytest marker for the new harness and ensure it participates in strict marker validation.
  • Register a bench_gated marker description in the pytest configuration so the new tests can be selected and are allowed under strict_markers.
pyproject.toml
Document how the v2.0 corpus is consumed by the bench-gate harness and how to mount and run it in lab environments. tests/corpus/v2_0/README.md
Add a lab-side shell runner to execute the bench-gate suite against a mounted private corpus with sensible defaults and validation.
  • Create scripts/run_bench_gate.sh that defaults AELFRICE_CORPUS_ROOT to the standard lab repo path if unset and exports it.
  • Add a directory-existence check that emits a clear error message and exits when the corpus root is missing.
  • Invoke uv run pytest over tests/bench_gate/ with the bench_gated marker and verbose output, forwarding any additional CLI args.
scripts/run_bench_gate.sh

Assessment against linked issues

Issue Objective Addressed Explanation
#319 Implement a bench-gate harness in the public repo that uses the AELFRICE_CORPUS_ROOT env var to load JSONL from $AELFRICE_CORPUS_ROOT//*.jsonl, and ensures bench-gated tests cleanly skip (not fail) when the corpus root is unset or module data is missing/empty so public CI remains green.
#319 Add six per-module bench-gate pytest entry points (dedup, enforcement, contradiction, wonder_consolidation, promotion_trigger, sentiment) that use the harness to read their module’s JSONL corpus and invoke the corresponding detector APIs, stubbed to skip until implementations ship.
#319 Provide lab-side tooling and documentation: a runner script that exports AELFRICE_CORPUS_ROOT and runs the bench-gate suite, and updates to tests/corpus/v2_0/README.md describing the env var usage and clarifying the relationship between the corpus (#307), this harness, and the rebuilder harness (#288).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7e7fe419-e9eb-4460-853b-225b99a8c496

📥 Commits

Reviewing files that changed from the base of the PR and between 3fd820f and c176ea0.

📒 Files selected for processing (7)
  • tests/bench_gate/test_contradiction.py
  • tests/bench_gate/test_dedup.py
  • tests/bench_gate/test_enforcement.py
  • tests/bench_gate/test_promotion_trigger.py
  • tests/bench_gate/test_sentiment.py
  • tests/bench_gate/test_wonder_consolidation.py
  • tests/conftest.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/bench_gate/test_promotion_trigger.py
  • tests/bench_gate/test_sentiment.py
  • tests/bench_gate/test_wonder_consolidation.py
  • tests/bench_gate/test_contradiction.py
  • tests/bench_gate/test_enforcement.py
  • tests/conftest.py

📝 Walkthrough

Walkthrough

Adds a bench-gate pytest harness that reads a lab-mounted v2.0 corpus via AELFRICE_CORPUS_ROOT, new session fixtures and JSONL loaders, six bench-gated tests that validate detector outputs against labeled corpus rows, a lab-run shell entrypoint, and README updates. Tests skip when corpus is absent.

Changes

Cohort / File(s) Summary
Configuration & Runner
pyproject.toml, scripts/run_bench_gate.sh
Adds bench_gated pytest marker and a shell runner that resolves/exports AELFRICE_CORPUS_ROOT, validates the directory, and invokes pytest for tests/bench_gate/ with the marker.
Test Infrastructure
tests/conftest.py
Adds _corpus_root() env resolver, session-scoped aelfrice_corpus_root fixture, autouse guard to skip bench_gated tests when corpus is absent, and load_corpus_module() to read JSONL rows.
Bench-Gated Tests
tests/bench_gate/test_contradiction.py, tests/bench_gate/test_dedup.py, tests/bench_gate/test_enforcement.py, tests/bench_gate/test_promotion_trigger.py, tests/bench_gate/test_sentiment.py, tests/bench_gate/test_wonder_consolidation.py
Adds six @pytest.mark.bench_gated tests that load per-module JSONL rows, import corresponding aelfrice.* detectors (skip if missing), classify rows, compute accuracy, and assert a minimum 0.5 threshold (or fail with measured accuracy).
Documentation
tests/corpus/v2_0/README.md
Updates README to document bench-gate harness use of AELFRICE_CORPUS_ROOT, public-CI skip behavior, and lab-side mount/run instructions.

Sequence Diagram(s)

sequenceDiagram
  participant LabRunner as Lab Runner (scripts/run_bench_gate.sh)
  participant ShellEnv as Shell / Env
  participant Pytest as Pytest (uv)
  participant Conftest as tests/conftest.py
  participant FS as Corpus FS (AELFRICE_CORPUS_ROOT)
  participant Detector as aelfrice.<module>

  LabRunner->>ShellEnv: set/export AELFRICE_CORPUS_ROOT
  ShellEnv->>FS: validate directory exists
  LabRunner->>Pytest: invoke pytest tests/bench_gate/ -m bench_gated
  Pytest->>Conftest: request session fixtures / autouse guard
  Conftest->>FS: load JSONL via load_corpus_module(module)
  Pytest->>Detector: import aelfrice.<module> (skip if missing)
  Pytest->>Detector: call classify/score on each row
  Detector-->>Pytest: prediction
  Pytest->>Pytest: compute accuracy, assert threshold or skip/fail
Loading

(Note: colored rectangles not required for this simple sequence.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #307: Provides the v2.0 corpus contract and schema that the new harness and JSONL loaders consume.

Possibly related PRs

  • #311: Changes to tests/corpus/v2_0 README and corpus scaffold that the new bench-gate tests and fixtures depend on.

Suggested labels

author-Setr

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature: introducing a bench-gate harness with corpus-root fixture, six module test stubs, and a lab runner script. It directly matches the changeset.
Description check ✅ Passed The description covers all required sections: Summary, Linked issues, Type of change (feat), Verification steps, and Test plan. It provides comprehensive detail of what lands and out-of-scope work.
Linked Issues check ✅ Passed All requirements from #319 are met: env-var indirection with AELFRICE_CORPUS_ROOT, pytest marker with autouse fixture for skipping when corpus absent, six per-module test entry-points, public CI skip behavior, lab runner script, and README documentation updates.
Out of Scope Changes check ✅ Passed All changes are within scope: fixture infrastructure, test harness setup, runner script, and documentation. No detector implementations or corpus content are included.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/bench-gate-harness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider moving load_corpus_module (and any other reusable helpers) out of tests/conftest.py into a dedicated helper module under tests/ so test files don’t need to import from conftest, which is treated specially by pytest.
  • For the bench-gate tests that try: from aelfrice import ... and then call .classify / .decide, consider also guarding against missing attributes (e.g., via getattr and pytest.skip if absent) so partially implemented modules don’t cause hard failures in the bench harness.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider moving `load_corpus_module` (and any other reusable helpers) out of `tests/conftest.py` into a dedicated helper module under `tests/` so test files don’t need to import from `conftest`, which is treated specially by pytest.
- For the bench-gate tests that `try: from aelfrice import ...` and then call `.classify` / `.decide`, consider also guarding against missing attributes (e.g., via `getattr` and `pytest.skip` if absent) so partially implemented modules don’t cause hard failures in the bench harness.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/bench_gate/test_contradiction.py`:
- Around line 14-17: Replace the broad try/except ImportError around importing
aelfrice.relationship_detector with a presence check using
importlib.util.find_spec("aelfrice.relationship_detector") and only call
pytest.skip("contradiction detector not yet implemented (`#201`)") if find_spec
returns None; then perform a normal import of aelfrice.relationship_detector so
real import-time errors within relationship_detector are propagated rather than
being masked by the except clause.

In `@tests/bench_gate/test_dedup.py`:
- Around line 29-30: Add a guard to ensure rows is non-empty before computing
accuracy to avoid ZeroDivisionError: assert len(rows) > 0 (or assert rows) with
a clear message, then compute accuracy = correct / len(rows) and assert accuracy
>= 0.5; update the test in test_dedup.py around the accuracy calculation
(variables: accuracy, correct, rows) to perform the non-empty assertion first.
- Around line 19-22: Replace the broad except ImportError around the import of
"from aelfrice import dedup" with a narrow except ModuleNotFoundError that calls
pytest.skip(...), and re-raise any other exceptions so import-time failures
inside aelfrice.dedup surface; apply the same change to the equivalent import
blocks in the six bench-gate test files (test_dedup.py, test_contradiction.py,
test_enforcement.py, test_promotion_trigger.py, test_sentiment.py,
test_wonder_consolidation.py).

In `@tests/conftest.py`:
- Around line 31-44: Add an autouse fixture that enforces skipping any test
marked with `@pytest.mark.bench_gated` when the corpus root is unavailable: create
a new fixture (e.g., skip_bench_gated_without_corpus) with autouse=True that
inspects request.node.get_closest_marker("bench_gated") (or
request.node.iter_markers) and, if present and _corpus_root() returns None,
calls pytest.skip with the same message used in aelfrice_corpus_root
(referencing CORPUS_ENV_VAR and the existing skip message) so tests that forget
to request aelfrice_corpus_root still get skipped on CI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 03724bed-5a14-4707-b084-6d06be23f93a

📥 Commits

Reviewing files that changed from the base of the PR and between 9148f66 and 3fd820f.

📒 Files selected for processing (11)
  • pyproject.toml
  • scripts/run_bench_gate.sh
  • tests/bench_gate/__init__.py
  • tests/bench_gate/test_contradiction.py
  • tests/bench_gate/test_dedup.py
  • tests/bench_gate/test_enforcement.py
  • tests/bench_gate/test_promotion_trigger.py
  • tests/bench_gate/test_sentiment.py
  • tests/bench_gate/test_wonder_consolidation.py
  • tests/conftest.py
  • tests/corpus/v2_0/README.md

Comment thread tests/bench_gate/test_contradiction.py Outdated
Comment thread tests/bench_gate/test_dedup.py Outdated
Comment thread tests/bench_gate/test_dedup.py
Comment thread tests/conftest.py
CodeRabbit review on #320:

- conftest.py grows an autouse fixture keyed on the bench_gated marker.
  Backstops the aelfrice_corpus_root fixture so a marker-only test that
  forgets to request the fixture still skips on public CI.
- All six bench-gate tests narrow except ImportError to
  ModuleNotFoundError scoped to the missing detector module name; any
  other ImportError (broken submodule import, missing transitive dep)
  now surfaces instead of being masked as a skip.
- test_dedup.py adds an explicit non-empty rows assertion before the
  accuracy division.

uv run pytest tests/bench_gate/ -> 6 skipped, 0 failed (corpus absent).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v2.0] Bench-gate harness — consume lab corpus, skip-when-absent on public CI

2 participants