Skip to content

Library API: Assertion object model + run_issue_tests reporting API#96

Open
gaurav wants to merge 2 commits into
library-packagingfrom
library-runner
Open

Library API: Assertion object model + run_issue_tests reporting API#96
gaurav wants to merge 2 commits into
library-packagingfrom
library-runner

Conversation

@gaurav

@gaurav gaurav commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #95 (base branch is library-packaging), which is itself stacked on #67. This is the second of two follow-up PRs making the GitHub-issue test framework usable as a library; see #67 for how they relate. Review #95 first.

This PR gives downstream tools (the Babel pipeline and Babel Explorer) a clean object model and a pytest-independent way to run issue tests and report results.

Changes

  • GitHubIssueTestAssertion (back-compat alias kept). Stop storing the live PyGitHub Issue; capture the few fields actually used (issue_id, url, state) as plain strings at construction, so the object is picklable and trivial to build in tests/other tools. Adds name/is_known accessors and run(), which yields (param_set, TestResult) pairs (running one param_set at a time so every result is attributable to its source; the cached clients dedupe the network calls).
  • babel_validation/runner.py: run_issue_tests() / run_assertions() returning IssueReport + ResultRecord. The library now owns the expectation rules — open issue ⇒ expected-fail (all-pass ⇒ closeable), closed issue ⇒ expected-pass (any-fail ⇒ reopened) — instead of burying them in the pytest test.
  • babel_validation/__init__.py: export the public surface (Assertion, GitHubIssuesTestCases, run_issue_tests, run_assertions, IssueReport, ResultRecord, CachedNodeNorm, CachedNameRes, TestResult, TestStatus).
  • tests/github_issues/test_github_issues.py: now a thin adapter that maps an IssueReport onto pytest outcomes (xfail/subtests/skip/fail) — behavior unchanged.
  • tests/github_issues/test_runner.py: offline unit tests for the runner with fake services, also exercising the public import surface.
  • README: "Use as a library" section with the Explorer (run_issue_tests) and Babel (parse + custom executor) usage examples.

Two consumer use-cases this enables

  • Babel Explorer (Streamlit): "run all issue tests from repo X against NodeNorm Y / NameRes Z and report which passed/failed + messages" → run_issue_tests(...)IssueReports.
  • Babel pipeline: fetch Assertions and run them against local DuckDB/JSON with a custom executor (reads assertion/param_sets), to flag closeable/reopened issues before data reaches NodeNorm.

Verification

  • uv run pytest -m unit → green (57 passed: 49 existing + 8 new runner tests).
  • uv build ships babel_validation/runner.py and the populated __init__; from babel_validation import Assertion, run_issue_tests works.

Follow-up ideas (out of scope; tracked separately)

Library-usability improvements identified during this work, deliberately left out of these PRs:

🤖 Generated with Claude Code

gaurav and others added 2 commits June 24, 2026 11:43
Rename GitHubIssueTest -> Assertion (with a back-compat alias) and stop storing
the live PyGitHub Issue: capture the few fields actually needed (issue_id, url,
state) as plain strings at construction. This makes the object picklable and
trivial to build in tests or other tools, and gives downstream consumers a
stable, low-level-free surface to interact with.

Also adds:
- `name`/`is_known` convenience accessors.
- `run()`, which yields (param_set, TestResult) pairs by evaluating one param_set
  at a time, so callers can attribute every result back to its source param_set
  (CachedNodeNorm/CachedNameRes dedupe the network calls, so it's no slower).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the issue-test orchestration out of the pytest test into a reusable,
pytest-free runner so other tools (e.g. Babel Explorer) can "run all issue tests
against NodeNorm X / NameRes Y and report pass/fail + messages":

- babel_validation/runner.py: run_issue_tests() / run_assertions() returning
  IssueReport + ResultRecord. The library now owns the expectation rules —
  open issue => expected-fail (all-pass => `closeable`), closed issue =>
  expected-pass (any-fail => `reopened`) — instead of burying them in the test.
- babel_validation/__init__.py: export the public surface (Assertion,
  GitHubIssuesTestCases, run_issue_tests, run_assertions, IssueReport,
  ResultRecord, CachedNodeNorm, CachedNameRes, TestResult, TestStatus).
- tests/github_issues/test_github_issues.py: now a thin adapter that maps an
  IssueReport onto pytest outcomes (xfail/subtests/skip/fail); behavior
  unchanged.
- tests/github_issues/test_runner.py: offline unit tests for the runner using
  fake services, also exercising the public import surface.
- README: "Use as a library" section with the Explorer (run_issue_tests) and
  Babel (parse + custom executor) usage examples.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR evolves the GitHub-issue-driven test framework into a more library-friendly API by introducing a picklable Assertion object model and a pytest-independent execution/reporting layer (run_assertions / run_issue_tests) that downstream tools can consume.

Changes:

  • Introduces Assertion (with a back-compat alias) that stores only plain issue metadata and provides a run() method yielding per-param_set results.
  • Adds babel_validation.runner with IssueReport/ResultRecord plus orchestration helpers for library consumers, and rewires pytest to act as a thin adapter.
  • Exposes a public import surface via babel_validation.__init__, adds offline runner unit tests, and documents library usage in the README.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/github_issues/test_system.py Updates a test comment to reflect Assertion rename.
tests/github_issues/test_runner.py Adds offline unit coverage for the new runner/reporting layer and public API imports.
tests/github_issues/test_github_issues.py Refactors pytest integration into a thin adapter over run_assertions.
src/babel_validation/sources/github/github_issues_test_cases.py Introduces Assertion, stops retaining live PyGitHub Issue, and adds run() for per-param-set execution.
src/babel_validation/runner.py Adds pytest-independent execution/reporting API (IssueReport, ResultRecord, run_*).
src/babel_validation/init.py Defines and exports the library’s public API surface.
README.md Adds “Use as a library” documentation and examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment on lines +68 to +70
`{{BabelTest|...}}` or ```` ```yaml babel_tests: ```` syntax — see
[`assertions/README.md`](./src/babel_validation/assertions/README.md)), so the library
needs a GitHub token to fetch them.
Comment on lines +121 to +127
handler = self._get_handler()
for param_set in self.param_sets:
for result in itertools.chain(
handler.test_with_nodenorm([param_set], nodenorm, label=str(self)),
handler.test_with_nameres([param_set], nodenorm, nameres, pass_if_found_in_top, label=str(self)),
):
yield param_set, result
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.

2 participants