provevi.checks
Each check returns a list of problems; an empty list means it passes. No
check prints or exits, so a program can call them as prove does.
read_events
read_events(folder: Path) -> list[EvidenceEvent]Read the events of an evidence folder.
Raises EvidenceError if events.jsonl cannot be read, or at a line that is not an event.
| Parameter | Type | Default | Description |
|---|---|---|---|
folder |
Path | required | A run’s evidence folder, which holds events.jsonl |
| returns | list[EvidenceEvent] | Its events, in the order of the lines |
verify
verify(folder: Path | RunRecord, run_id: str | None = None) -> list[str]Check that a run’s evidence is consistent and whole.
It checks the chain, the sequence, the payloads and the manifest, and that the evidence is the whole record of one run: run_created first, one ending event last, as many events as the manifest says, the payloads that the manifest lists, and the run ID given, if one is. A malformed folder gives problems, never an exception.
The check proves that the folder is consistent. Someone who can write the folder can still write a
consistent false record. To rule that out, compare the folder with the bundle committed in the store,
which verify_against does.
| Parameter | Type | Default | Description |
|---|---|---|---|
folder |
Path | RunRecord | required | An evidence folder, or a run that a store reads back |
run_id |
str | None | None |
The run the events must be of; None to accept any one run |
| returns | list[str] | The problems found; empty when it verifies |
verify_against
verify_against(folder: Path, events: bytes, manifest: bytes) -> list[str]Compare the local evidence with the committed bundle.
A difference means that one of them was changed.
| Parameter | Type | Default | Description |
|---|---|---|---|
folder |
Path | required | The local evidence folder |
events |
bytes | required | The bytes of events.jsonl in the committed bundle |
manifest |
bytes | required | The bytes of manifest.json in the committed bundle |
| returns | list[str] | A problem for each of the two files that differs; empty when both are the same |
verify_outputs
verify_outputs(run_folder: Path) -> list[str]Check that the files in output/ are exactly the recorded outputs.
Each must have its recorded bytes, be a regular file, and be recorded once. An output event names its file
by its reference, <run URI>/output/<path>.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_folder |
Path | required | The run folder, which holds evidence/ and output/ |
| returns | list[str] | The problems found; empty when the outputs match the evidence |
bundle_pin
bundle_pin(run_folder: Path, given: str | None = None) -> str | NoneFind the pinned bundle to compare a run with.
It is the one given, if there is one, else the one that bundle.json names. bundle.json is in the run folder, so whoever can change the folder can remove it or point it elsewhere; a commit given from outside the folder does not have that weakness. Raises EvidenceError if bundle.json cannot be read.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_folder |
Path | required | The run folder, which may hold bundle.json |
given |
str | None | None |
The pinned URI of the bundle, given from outside the folder |
| returns | str | None | The pinned URI to compare with; None when neither names one |
verify_bundle
verify_bundle(run_folder: Path, pinned: str | None, catalog: Catalog | Callable[[], Catalog] | None, *, require: bool = False) -> list[str]Compare a run’s evidence with its committed bundle, read through the catalog.
A bad URI, an unpinned URI, a missing catalog, a catalog that does not open and a bundle that cannot be read each give a problem.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_folder |
Path | required | The run folder, whose evidence/ is compared |
pinned |
str | None | required | The pinned URI of the committed bundle, with ?at=; None when there is none |
catalog |
Catalog | Callable[[], Catalog] | None | required | The catalog to read the bundle through, or a function that opens one, called only when there is a bundle to read |
require |
bool | False |
Give a problem when there is no bundle to compare with |
| returns | list[str] | The problems found; empty when the evidence matches the bundle, or when there is none and none is required |
class RunCheck
RunCheck(run_id: str, problems: list[str] = <factory>, pinned: str | None = None, experiment: str | None = None)The result of verify_run.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_id |
str | required | The run checked: the name of its folder |
problems |
list[str] | <factory> |
The problems found; empty when the run verifies |
pinned |
str | None | None |
the committed bundle compared with, if any |
experiment |
str | None | None |
the pinned experiment checked, if the run names one |
RunCheck.to_dict
RunCheck.to_dict() -> dictThe result as a dict that JSON can hold, with ok beside the fields.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | dict | run_id, ok, problems, pinned and experiment |
verify_store_copy
verify_store_copy(run_folder: Path, store: EvidenceStore) -> list[str]Check a run as the store holds it, against its run folder.
The store’s copy must verify, and the files in the run’s evidence folder, which are its bundle, must be the same as the store’s. For a store that records the bundle, the record must match bundle.json.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_folder |
Path | required | The run folder; its name is the run ID |
store |
EvidenceStore | required | The store that holds the run |
| returns | list[str] | The problems found: those of the store’s copy start in the store:, and the others name what differs; empty for a store that cannot read runs back |
verify_run
verify_run(run_folder: Path, *, catalog: Catalog | Callable[[], Catalog] | None = None, bundle: str | None = None, require_bundle: bool = False, store: EvidenceStore | None = None) -> RunCheckCheck a run as prove verify does.
It checks the evidence, then the outputs, then the committed bundle, then the version of the experiment that the run names, read at its pin, whose hash must match the run’s. With a store that keeps its own record, such as a SqliteStore, the run as the store holds it is checked too, and must match the folder. A malformed run gives problems, never an exception.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_folder |
Path | required | The run folder; its name is the run ID |
catalog |
Catalog | Callable[[], Catalog] | None | None |
The catalog to read the bundle and the experiment through, or a function that opens one, called once when it succeeds, and called again by the next check after it fails |
bundle |
str | None | None |
The pinned URI of the bundle, taken from outside the run folder; None to use the one in bundle.json |
require_bundle |
bool | False |
Give a problem when there is no bundle to compare with |
store |
EvidenceStore | None | None |
The store the run was written through; a store other than a FileStore is checked too |
| returns | RunCheck | The run ID, the problems found, and the bundle and experiment checked |
verify_experiment
verify_experiment(run_folder: Path, catalog: Catalog | Callable[[], Catalog] | None) -> list[str]Check the experiment that a run names in run_created.
Its pin must read through the catalog, and the file there must have the hash that the run recorded.
| Parameter | Type | Default | Description |
|---|---|---|---|
run_folder |
Path | required | The run folder, whose run_created event names the experiment |
catalog |
Catalog | Callable[[], Catalog] | None | required | The catalog to read the experiment through, or a function that opens one |
| returns | list[str] | The problems found; empty when the experiment matches, or the run names none |