Skip to content

feat: batch validation with auto-managed, resumable sessions#185

Draft
kikkomep wants to merge 15 commits into
crs4:developfrom
kikkomep:feat/batch-validation
Draft

feat: batch validation with auto-managed, resumable sessions#185
kikkomep wants to merge 15 commits into
crs4:developfrom
kikkomep:feat/batch-validation

Conversation

@kikkomep

Copy link
Copy Markdown
Member

This PR adds batch validation to the CLI: validate --batch validates every RO-Crate found under a directory and aggregates the results, with progress reporting, a per-crate summary table and machine-readable outputs. Each run is recorded as an auto-managed session that is saved incrementally (one save per validated crate), so an interrupted run — Ctrl+C, a crash, a killed job — can be resumed from where it stopped, either automatically by re-running the same command or explicitly via the new sessions subcommand.

What's included

CLI — validate --batch

  • --batch/-b validates every crate under RO-CRATE-URI (subdirectory crates, zipped crates and detached *-ro-crate-metadata.json files); --batch-pattern filters the crate names.
  • Live progress bar on stderr (passed/failed/remaining), per-crate result lines, and a final summary table (size, status, checks, issues, duration per crate); -v adds the details of every failed crate.
  • Exit code reflects the aggregated outcome (0 only if every crate passed).
  • Output formats: text (console or file), json, csv (one row per crate).

CLI — sessions

  • sessions list (alias ls): stored sessions with status, progress and target (--status, --json).
  • sessions show <ID>: re-render the recorded output of a session without re-validating anything; --stats for the statistics, -o report.md -f md to write them to a file.
  • sessions resume <ID>: continue an interrupted session (only the pending crates are processed).
  • sessions clear (alias rm) and sessions path to manage the history.
  • Interactive mode offers the stored sessions as a menu when no ID is given.

Sessions & resumability

  • Sessions are stored under the user cache directory and keyed deterministically by scan target, profile
    selection and severity: re-running the same command resumes the same session automatically; --no-resume starts over. Changing profiles or severity intentionally starts a new session.
  • The session file records per-crate outcomes (status, checks counters, serialized issues, duration, size), so summaries and reports can be rebuilt entirely from what was saved.

Memory behaviour

Batch runs keep memory usage flat regardless of the corpus size: per-crate outcomes are persisted to the session file instead of being retained in memory (retaining every live ValidationResult pinned ~4 MB/crate and got large batches OOM-killed). Live results can still be retained explicitly for debugging or scripting purposes via batch_validate(..., keep_results=True), exposed as BatchValidationResult.live_results; the recorded outcome of every crate is always available in .crates.

Usage

# Validate every crate under a directory (auto-resumes if interrupted)
rocrate-validator validate --batch path/to/crates/ -p ro-crate-1.1

# Machine-readable report + statistics
rocrate-validator validate --batch path/to/crates/ -f csv -o report.csv
rocrate-validator validate --batch path/to/crates/ --stats

# Browse and resume past runs
rocrate-validator sessions list
rocrate-validator sessions resume <ID>

kikkomep added 15 commits July 1, 2026 15:24
Introduce the storage location for auto-managed batch validation sessions.
Sessions live under the user cache directory (XDG-compliant) in a dedicated
`sessions/` subdir; each session file name is a deterministic SHA1 hash of
the batch target (scan root, glob pattern, relevant settings) so re-running
the same batch command resolves to the same file and can be resumed.
Add the data model backing batch validation:
- BatchCrateEntry: per-crate outcome (status, profiles, stats, issues, size,
  duration) with dict (de)serialization.
- BatchSession: the persistent, JSON-serializable session state, tracking the
  crate entries, validation settings and progress counts, with load/save and
  completion helpers so a run can be inspected and resumed.
- BatchValidationResult: the aggregated result over a session, exposing the
  overall verdict and the passed/failed entries for reporting.
Add the batch validation service on top of the batch models:
- discover_ro_crates(): scan a directory for RO-Crates matching a glob pattern.
- resolve_batch_session_path(): map a batch target to its session file.
- batch_validate(): validate every discovered crate, persisting progress to the
  session so an interrupted run can be resumed; resolves profiles per crate
  (auto-detection), reports progress via a callback, and handles SIGINT by
  saving the session before aborting.
Add single_choice(): render a single-select list menu from (value, label) pairs
and return the chosen value. Used by the interactive session pickers to let the
user select a batch session to show or resume.
Serialize a BatchValidationResult to JSON via its to_dict(), adding a `meta`
block (generator name and version), and register the formatter for the
BatchValidationResult type so batch runs support `--format json`.
Add a statistics reporting module for a batch run, with two entry points:
render_statistics() for rich console/text output and render_statistics_md()
for markdown. It aggregates per-crate outcomes into an overview (pass/fail/
error), error-type and per-check issue attribution, duration and outlier
breakdowns, and detailed tables. Consumed by `sessions show --stats`.
Add the text-mode batch view: BatchValidationCommandView renders a live
progress bar on stderr (passed/failed/remaining counts), a per-crate summary
table and verbose failure details. Extract shared helpers — render_batch_header,
render_batch_footer, format_crate_line and format_profile_selection — so the
`validate --batch` run and the `sessions` commands render consistently.
Extend `validate` with batch validation: new -b/--batch, --batch-pattern and
--no-resume options. Batch runs discover the RO-Crates under the target, resolve
(and auto-resume) the batch session, validate with a progress bar, write the
aggregated report — including the new batch-only `csv` format — and exit with the
combined status. The single-crate path is extracted into _run_single_validations
to keep the two flows separate.
Add the `sessions` command group to inspect and manage the auto-managed batch
validation sessions: `path`, `show` (with --stats and text/markdown file export),
`resume`, `list`/`ls` and `clear`/`rm` (by ID prefix, --completed or --all).
Sessions can be selected by ID prefix or picked from an interactive menu.
Register the group with the CLI.
Add tests for batch validation and session management: the validate `--batch`
mode and `--batch-pattern`, session auto-resume and `--no-resume`, JSON/CSV
report output and statistics, and the `sessions` subcommands (list, show,
resume, clear and file export)
@kikkomep
kikkomep marked this pull request as draft July 13, 2026 11:39
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.

1 participant