Skip to main content

ptox_conformance/
lib.rs

1//! # ptox-conformance
2//!
3//! A contract conformance suite for ptox providers. It validates that a provider —
4//! written in Rust (`check_in_process`) or as a subprocess speaking the NDJSON
5//! wire format (`check_command`) — obeys the core contract
6//! (`../ptox/spec/core-contract.md`).
7//!
8//! Use it as a library or via the `ptox-conformance` binary:
9//!
10//! ```sh
11//! ptox-conformance -- ptox-provider-example --config /etc/example.conf
12//! ```
13
14#![forbid(unsafe_code)]
15#![warn(missing_docs)]
16
17mod command;
18mod in_process;
19mod report;
20mod schemes;
21
22pub use command::check_command;
23pub use in_process::check_in_process;
24pub use report::{Check, Report};
25
26use ptox::FileQuery;
27use std::time::Duration;
28
29/// What to run the provider against.
30#[derive(Debug, Clone)]
31pub struct Options {
32    /// Queries sent to the provider. Each is an independent invocation.
33    pub queries: Vec<FileQuery>,
34    /// Time budget per query; exceeding it fails the termination check.
35    pub timeout: Duration,
36    /// Maximum accepted wire-line length (hostile-output bound).
37    pub max_line_bytes: usize,
38}
39
40impl Default for Options {
41    fn default() -> Self {
42        Self {
43            queries: vec![FileQuery::new("conformance test")],
44            timeout: Duration::from_secs(10),
45            max_line_bytes: ptox::MAX_LINE_BYTES,
46        }
47    }
48}
49
50/// The name of the check that verifies a provider honors `limit`.
51pub(crate) const LIMIT_CHECK: &str = "limit_honored";
52
53/// The `limit` carried by the suite's probe query.
54pub(crate) const LIMIT_PROBE: u32 = 1;
55
56/// The probe query used to verify that a provider honors `limit`.
57///
58/// The suite sends it once, separately from [`Options::queries`], and requires
59/// the provider to return at most [`LIMIT_PROBE`] results. A provider that
60/// returns fewer still passes; one that ignores the selector is caught.
61pub(crate) fn limit_probe() -> FileQuery {
62    FileQuery::new("conformance limit probe").with_limit(LIMIT_PROBE)
63}