git-ents.gitmain
⌘K
foforge
lib.rs91 lines · 4.0 KB · rusthistorycomment on this file
1//! The `CommitQuery` algebra (`docs/spec/query.sdoc`): three atoms —
2//! `rev()`, `results()`, `meta()` — closed under union, intersection,
3//! and difference, denoting a set of commits as a pure function of ref
4//! state. Every effect's trigger is one of these queries; composition
5//! happens by writing the query itself, never by a workflow language or
6//! a runtime scheduler.
7//!
8//! This crate owns the grammar and parser ([`Query`]), static
9//! ref-footprint extraction ([`Query::footprint`]), and evaluation
10//! ([`Evaluator`]): full reconciliation-grade sets, incremental entry
11//! sets bounded by generation numbers, and the work set
12//! `trigger − results(self, any)`. It is deliberately separate from
13//! executor and run-loop code (`arch.query-effect-split`): `receive`
14//! links this crate for footprint matching on every push and must never
15//! link executor code.
16//!
17//! # Spec coverage
18//!
19//! From `docs/spec/query.sdoc`:
20//!
21//! - `query.grammar`, `query.set-ops` — [`Query`], the parser, and
22//! [`SetOp`]; left-associative, one precedence level.
23//! - `query.rev` — [`RevExpr`]; `refs/meta/*` patterns are rejected at
24//! parse time, never silently evaluated. The supported surface is
25//! exactly the rev-list-shaped subset the requirement states —
26//! refnames (short or full), `refs/` globs, full hex oids,
27//! `^negation`, and `A..B` — and every form outside it (`~n`/`^n`,
28//! `A...B`, `@{...}`, abbreviated hex) is an explicit
29//! [`ParseError::UnsupportedRev`]; growing the subset is a
30//! compatible, additive extension.
31//! - `query.results` — resolution is a refname scan of the effect's
32//! results namespace; membership tests compare hex prefixes and walk
33//! no history.
34//! - `query.meta` — the glob must stay under `refs/meta/*` and can
35//! never match `refs/meta/results/*` or `refs/meta/index/*`; the
36//! fanout index is not addressable by any atom.
37//! - `query.no-extensions` — the atom set is closed; `time(...)`,
38//! `content(...)`, or any other name is [`ParseError::UnknownAtom`].
39//! - `query.footprint` — [`Query::footprint`], from the syntax tree
40//! alone.
41//! - `query.incremental`, `query.monotone` — [`Evaluator::entry_set`].
42//! - `query.workset` — [`Evaluator::work_set`] (incremental) and
43//! [`Evaluator::outstanding`] (boot-time reconciliation); `self` is
44//! substituted at evaluation time and rejected in trigger text.
45//! - `query.recursion` — [`Query::results_dependencies`]; downstream-of
46//! is syntax, and `rev()`/`meta()` cannot name effect-written refs,
47//! so unwritten trigger cycles are unreachable by construction.
48//! - `query.rev-pattern-compat` — a bare ref glob parses as exactly
49//! `rev(<glob>)`.
50//!
51//! # Examples
52//!
53//! The staged-pipeline idiom, evaluated incrementally: integration only
54//! after unit tests pass.
55//!
56//! ```
57//! use ents_model::Status;
58//! use ents_query::{Evaluator, Query, Transition};
59//! use ents_testutil::{MemRefStore, ObjectStore, advance_ref, record_result};
60//!
61//! let refs = MemRefStore::default();
62//! let objects = ObjectStore::default();
63//! let commits = advance_ref(&refs, &objects, "refs/heads/main", 2, 100);
64//!
65//! let trigger: Query = "rev(refs/heads/main) & results(unit, pass)".parse().expect("valid");
66//! let evaluator = Evaluator::new(&refs, &objects);
67//!
68//! // A unit result lands for the first commit: exactly that commit
69//! // enters the staged trigger's set.
70//! let short = commits[0].to_string()[..12].to_owned();
71//! let result_tip = record_result(&refs, &objects, "unit", &short, Status::Pass, None, 300);
72//! let entered = evaluator.entry_set(&trigger, &Transition {
73//! name: format!("refs/meta/results/unit/{short}").as_str().try_into().expect("valid"),
74//! old: None,
75//! new: Some(result_tip),
76//! }).expect("evaluates");
77//! assert_eq!(entered.into_iter().collect::<Vec<_>>(), vec![commits[0]]);
78//! ```
79
80mod ast;
81mod error;
82mod eval;
83mod parse;
84mod pattern;
85mod rev;
86
87pub use ast::{Query, SetOp, StatusFilter};
88pub use error::{EvalError, EvalResult, ParseError};
89pub use eval::{Evaluator, Transition};
90pub use pattern::{Footprint, RefPattern};
91pub use rev::RevExpr;