From dc90bc74bf58361560032c2b0c556f48993ea48d Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 16:03:49 +0100 Subject: [PATCH] feat(server): serve statements, landings and events over HTTP The HTTP API could only move records and read targets. Clients also need to read what is known about a change, land it, and react to what happens. The remaining routes, each one line of the SDK: the statements about a record, a change's revisions, creating a target, landing a change or a target, the landings that wait, and the events long-poll, which answers as soon as there are events after the cursor. The new `server` benchmarks time a batch of records put and fetched over HTTP, a long-poll woken by a put from the server's process or from another, and a landing in a repository of 200,000 statements through a service that keeps its index open, against one that reads it per landing. --- AGENTS.md | 3 +- apps/origin-src/Cargo.toml | 4 + apps/origin-src/benches/server.rs | 281 +++++++ apps/origin-src/src/http.rs | 167 ++++- apps/origin-src/tests/http.rs | 240 +++++- crates/origin-client/src/lib.rs | 22 +- docs/openapi.json | 1145 ++++++++++++++++++++++++++++- 7 files changed, 1828 insertions(+), 34 deletions(-) create mode 100644 apps/origin-src/benches/server.rs diff --git a/AGENTS.md b/AGENTS.md index ad4a67f0..278bc0eb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,7 +30,8 @@ to a hot path (hashing, storage, snapshots, transfer) should come with a benchmark, and its numbers in the pull request. - `just bench`: the divan micro-benchmarks (encoding, store writes, - snapshots, input digests and promotion, landing, reading events). + snapshots, input digests and promotion, landing, reading events, and the + server's request latency and long-poll wakeups). - `just bench-git`: times origin against git on a 20,000-file tree with hyperfine, and rewrites `docs/benchmarks.md`. diff --git a/apps/origin-src/Cargo.toml b/apps/origin-src/Cargo.toml index 7cc5202c..f9b70dab 100644 --- a/apps/origin-src/Cargo.toml +++ b/apps/origin-src/Cargo.toml @@ -48,6 +48,10 @@ harness = false name = "land" harness = false +[[bench]] +name = "server" +harness = false + [[bench]] name = "snapshot" harness = false diff --git a/apps/origin-src/benches/server.rs b/apps/origin-src/benches/server.rs new file mode 100644 index 00000000..80568719 --- /dev/null +++ b/apps/origin-src/benches/server.rs @@ -0,0 +1,281 @@ +//! The server: request latency over HTTP on localhost, through the SDK, for +//! a batch of records put and fetched and for an event long-poll woken by a +//! write; and a landing through a service that keeps its index open, against +//! one that reads it per landing. Run on a real disk: syncs are most of the +//! cost of a put. + +use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::time::Duration; + +use divan::Bencher; +use divan::counter::ItemsCount; +use origin_client::Repo; +use origin_shared::api::{EventsQuery, FetchRecords, LandRequest, List}; +use origin_shared::landing::{Landing, Proposal}; +use origin_shared::pack::Pack; +use origin_shared::{ + Base, BlobId, ChangeId, EncodedObject, EntryKind, EntryName, Kind, NodeKey, Period, Record, + RecordId, Revision, RevisionId, Statement, TargetName, Tree, TreeEntry, Verdict, +}; +use origin_src::http::Api; +use origin_src::policy::Policy; +use origin_src::server::Repositories; +use origin_src::service::{Caller, Node, OriginService}; +use origin_src::store::Store; +use tokio::runtime::Runtime; + +fn main() { + divan::main(); +} + +/// A repository with one revision on `main`, which statements are about. +struct Hosted { + dir: tempfile::TempDir, + node: Node, + revision: RevisionId, +} + +impl Hosted { + fn new() -> Self { + let dir = tempfile::tempdir().unwrap(); + let node = Node { + name: "hosted".parse().unwrap(), + key: Arc::new(NodeKey::from_bytes(&[7; 32])), + }; + let policy = Policy::initial(&node.name, &node.key.public()); + let service = + OriginService::create(dir.path().join("demo"), node.clone(), &policy).unwrap(); + let revision = Self::put_change(&service, 0); + Self { + dir, + node, + revision, + } + } + + fn service(&self) -> OriginService { + OriginService::open(self.dir.path().join("demo"), self.node.clone()).unwrap() + } + + /// Puts a change on the tip of `main`, with one file, `file-`. + fn put_change(service: &OriginService, n: u64) -> RevisionId { + let store = service.store(); + let tip = store.head(&TargetName::MAIN).unwrap().unwrap().acceptance; + let mut tree: Tree = store.get(store.get(tip).unwrap().body().state).unwrap(); + let content = EncodedObject::blob(format!("fn f{n}() {{}}\n").as_bytes()); + tree.insert( + EntryName::new(format!("file-{n}")).unwrap(), + TreeEntry { + kind: EntryKind::File, + id: content.id(), + }, + ); + let tree = tree.encode(); + let description = EncodedObject::blob(b""); + let mut change = [0; 16]; + change[..8].copy_from_slice(&n.to_le_bytes()); + let revision = Revision { + change: ChangeId::from_bytes(change), + predecessors: Vec::new(), + base: Base::Acceptance(tip), + deps: Vec::new(), + snapshot: tree.id().into(), + description: BlobId::from(description.id()), + author: "user:bench".parse().unwrap(), + } + .encode(); + let id = revision.id().into(); + let pack = Pack { + objects: vec![content, tree, description, revision], + }; + service.put_records(&Caller::Owner, pack).unwrap(); + id + } + + /// Starts serving the repository, returning the runtime that runs the + /// server and the SDK's handle on the repository. + fn serve(&self) -> (Runtime, Repo) { + let runtime = Runtime::new().unwrap(); + let mut repositories = Repositories::default(); + repositories.insert("demo".parse().unwrap(), self.service()); + let url = runtime.block_on(async { + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + tokio::spawn(async move { axum::serve(listener, Api::router(repositories)).await }); + format!("http://{address}") + }); + let repo = origin_client::Client::new(&url).repo("demo".parse().unwrap()); + (runtime, repo) + } +} + +/// Statements numbered from `start` about `subject`, each of its own kind. +fn statements(subject: RevisionId, start: usize, count: usize) -> Vec { + (start..start + count) + .map(|n| { + Statement { + subject: RecordId::Revision(subject), + kind: Kind::new(format!("bench.k{n}")).unwrap(), + verdict: Some(Verdict::Pass), + issuer: "node:ci".parse().unwrap(), + inputs: None, + payload: None, + supersedes: None, + promoted_from: None, + } + .encode() + }) + .collect() +} + +/// Putting a batch of new statements, durably: one request. +#[divan::bench(args = [1, 100, 1000], sample_count = 30)] +fn put_records(bencher: Bencher<'_, '_>, batch: usize) { + let hosted = Hosted::new(); + let (runtime, repo) = hosted.serve(); + let next = AtomicUsize::new(0); + bencher + .counter(ItemsCount::new(batch)) + .with_inputs(|| Pack { + objects: statements( + hosted.revision, + next.fetch_add(batch, Ordering::Relaxed), + batch, + ), + }) + .bench_local_refs(|pack| runtime.block_on(repo.put_records(pack)).unwrap()); +} + +/// Fetching a batch of statements by id: one request. +#[divan::bench(args = [1, 100, 1000], sample_count = 30)] +fn fetch_records(bencher: Bencher<'_, '_>, batch: usize) { + let hosted = Hosted::new(); + let (runtime, repo) = hosted.serve(); + let objects = statements(hosted.revision, 0, batch); + let request = FetchRecords { + ids: objects.iter().map(EncodedObject::id).collect(), + }; + runtime + .block_on(repo.put_records(&Pack { objects })) + .unwrap(); + bencher + .counter(ItemsCount::new(batch)) + .bench(|| runtime.block_on(repo.fetch_records(&request)).unwrap()); +} + +/// An idle long-poll woken by a statement put: from the put's start to the +/// poll's answer. A put alone, `put_records` with 1, is most of it. +#[divan::bench(sample_count = 30)] +fn long_poll_wakeup(bencher: Bencher<'_, '_>) { + let hosted = Hosted::new(); + let (runtime, repo) = hosted.serve(); + let next = AtomicUsize::new(0); + bencher + .with_inputs(|| { + let cursor = runtime + .block_on(repo.events(&EventsQuery::default())) + .unwrap() + .next; + let query = EventsQuery { + cursor: Some(cursor), + wait: Some(Period(Duration::from_secs(30))), + kind: List(vec!["statement.issued".parse().unwrap()]), + ..EventsQuery::default() + }; + let poller = repo.clone(); + let poll = runtime.spawn(async move { poller.events(&query).await.unwrap() }); + // Long enough for the poll to be waiting. + std::thread::sleep(Duration::from_millis(20)); + let pack = Pack { + objects: statements(hosted.revision, next.fetch_add(1, Ordering::Relaxed), 1), + }; + (poll, pack) + }) + .bench_local_values(|(poll, pack)| { + runtime.block_on(async { + repo.put_records(&pack).await.unwrap(); + let page = poll.await.unwrap(); + assert_eq!(page.events.len(), 1); + }); + }); +} + +/// An idle long-poll woken by a statement another process wrote: the +/// server only sees it at its next read of the op log, every 50 ms. +#[divan::bench(sample_count = 10)] +fn long_poll_wakeup_from_another_process(bencher: Bencher<'_, '_>) { + let hosted = Hosted::new(); + let (runtime, repo) = hosted.serve(); + let other = Store::new( + hosted.dir.path().join("demo"), + origin_platform::Native::default(), + ); + let next = AtomicUsize::new(0); + bencher + .with_inputs(|| { + let cursor = runtime + .block_on(repo.events(&EventsQuery::default())) + .unwrap() + .next; + let query = EventsQuery { + cursor: Some(cursor), + wait: Some(Period(Duration::from_secs(30))), + kind: List(vec!["statement.issued".parse().unwrap()]), + ..EventsQuery::default() + }; + let poller = repo.clone(); + let poll = runtime.spawn(async move { poller.events(&query).await.unwrap() }); + std::thread::sleep(Duration::from_millis(20)); + ( + poll, + statements(hosted.revision, next.fetch_add(1, Ordering::Relaxed), 1), + ) + }) + .bench_local_values(|(poll, objects)| { + other.write_all(&objects).unwrap(); + let page = runtime.block_on(poll).unwrap(); + assert_eq!(page.events.len(), 1); + }); +} + +/// How many records the repository holds for `land_with_large_index`. +const RECORDS: usize = 200_000; + +/// Landing a change made on the tip in a repository of 200k statements, +/// through one service that keeps its index open (`true`), or a new one +/// each time, which reads the index whole (`false`), as a command does. +#[divan::bench(args = [true, false], sample_count = 10)] +fn land_with_large_index(bencher: Bencher<'_, '_>, kept: bool) { + let hosted = Hosted::new(); + let service = hosted.service(); + for batch in statements(hosted.revision, 0, RECORDS).chunks(1000) { + service.store().write_all(batch).unwrap(); + } + let land = |service: &OriginService, change: ChangeId| { + let request = LandRequest { + proposal: Proposal::Change(change), + onto: None, + }; + let landed = service.land(&Caller::Owner, &request).unwrap(); + assert!(matches!(landed.landings[..], [Landing::Landed { .. }])); + }; + // Reads the index for the kept service. + service + .statements(&Caller::Owner, RecordId::Revision(hosted.revision)) + .unwrap(); + let mut n = 0; + bencher + .with_inputs(|| { + n += 1; + let revision = Hosted::put_change(&service, n); + service.store().get(revision).unwrap().change + }) + .bench_local_values(|change| { + if kept { + land(&service, change); + } else { + land(&hosted.service(), change); + } + }); +} diff --git a/apps/origin-src/src/http.rs b/apps/origin-src/src/http.rs index d3bee4a5..f028238a 100644 --- a/apps/origin-src/src/http.rs +++ b/apps/origin-src/src/http.rs @@ -12,10 +12,14 @@ use axum::extract::{DefaultBodyLimit, FromRequestParts, Path, Query, State}; use axum::http::request::Parts; use axum::http::{StatusCode, header}; use axum::response::{IntoResponse, Response}; +use origin_shared::ChangeId; +use origin_shared::Head; use origin_shared::api::{ - ApiError, ErrorCode, FetchRecords, LogEntry, LogQuery, RepoName, RepoSummary, Stored, - TargetInfo, + Annotation, ApiError, ErrorCode, EventsQuery, FetchRecords, LandRequest, Landings, LogEntry, + LogQuery, NewTarget, RepoName, RepoSummary, Revisions, StatementsQuery, Stored, TargetInfo, }; +use origin_shared::event::Page; +use origin_shared::landing::Pending; use origin_shared::pack::{Pack, PackError}; use utoipa::OpenApi; use utoipa_axum::router::OpenApiRouter; @@ -48,8 +52,13 @@ impl Api { .routes(routes!(list_repos)) .routes(routes!(fetch_records)) .routes(routes!(put_records)) - .routes(routes!(targets)) + .routes(routes!(statements)) + .routes(routes!(revisions)) + .routes(routes!(targets, create_target)) .routes(routes!(log)) + .routes(routes!(land)) + .routes(routes!(landings)) + .routes(routes!(events)) .routes(routes!(openapi_document)) } @@ -209,6 +218,57 @@ async fn put_records( .map(Json) } +/// Lists the statements about a record, in the order the repository +/// received them. +#[utoipa::path( + get, + path = "/api/v1/repos/{repo}/statements", + operation_id = "statements", + params(("repo" = String, Path, description = "The repository"), StatementsQuery), + responses( + (status = 200, description = "The statements", body = Vec), + (status = 404, description = "The repository does not exist", body = ApiError) + ) +)] +async fn statements( + repos: Repos, + Path(repo): Path, + caller: Caller, + Query(query): Query, +) -> Result>, HttpError> { + call(repos, repo, caller, move |service, caller| { + service.statements(caller, query.subject) + }) + .await + .map(Json) +} + +/// Lists the revisions of a change, and its heads. +#[utoipa::path( + get, + path = "/api/v1/repos/{repo}/changes/{change}/revisions", + operation_id = "revisions", + params( + ("repo" = String, Path, description = "The repository"), + ("change" = String, Path, description = "The change's id") + ), + responses( + (status = 200, description = "The revisions, in the order the repository received them", body = Revisions), + (status = 404, description = "The repository or the change does not exist", body = ApiError) + ) +)] +async fn revisions( + repos: Repos, + Path((repo, change)): Path<(RepoName, ChangeId)>, + caller: Caller, +) -> Result, HttpError> { + call(repos, repo, caller, move |service, caller| { + service.revisions(caller, change) + }) + .await + .map(Json) +} + /// Lists the targets, with their tips, authorities and requirements. #[utoipa::path( get, @@ -230,6 +290,32 @@ async fn targets( .map(Json) } +/// Creates a target at the tip of another, ordered by this server. +#[utoipa::path( + post, + path = "/api/v1/repos/{repo}/targets", + operation_id = "create_target", + params(("repo" = String, Path, description = "The repository")), + request_body = NewTarget, + responses( + (status = 200, description = "The new target's first acceptance", body = Head), + (status = 404, description = "The repository or the target to start from does not exist", body = ApiError), + (status = 409, description = "The name is taken, or this server wouldn't order the target", body = ApiError) + ) +)] +async fn create_target( + repos: Repos, + Path(repo): Path, + caller: Caller, + Json(request): Json, +) -> Result, HttpError> { + call(repos, repo, caller, move |service, caller| { + service.create_target(caller, &request) + }) + .await + .map(Json) +} + /// Lists the acceptances of a target, oldest first. #[utoipa::path( get, @@ -254,6 +340,81 @@ async fn log( .map(Json) } +/// Submits a change, or a target's tip, to a target's landing queue, run +/// by this server. +#[utoipa::path( + post, + path = "/api/v1/repos/{repo}/land", + operation_id = "land", + params(("repo" = String, Path, description = "The repository")), + request_body = LandRequest, + responses( + (status = 200, description = "How each landing went: landed, unchanged, or waiting for evidence or a conflict's resolution", body = Landings), + (status = 400, description = "A target was proposed without a target to land on", body = ApiError), + (status = 404, description = "The repository, the change or a target does not exist", body = ApiError), + (status = 409, description = "The change diverged or was abandoned, or this server doesn't order the target", body = ApiError) + ) +)] +async fn land( + repos: Repos, + Path(repo): Path, + caller: Caller, + Json(request): Json, +) -> Result, HttpError> { + call(repos, repo, caller, move |service, caller| { + service.land(caller, &request) + }) + .await + .map(Json) +} + +/// Lists the landings that wait, and why. +#[utoipa::path( + get, + path = "/api/v1/repos/{repo}/landings", + operation_id = "landings", + params(("repo" = String, Path, description = "The repository")), + responses( + (status = 200, description = "The waiting landings, by target", body = Vec), + (status = 404, description = "The repository does not exist", body = ApiError) + ) +)] +async fn landings( + repos: Repos, + Path(repo): Path, + caller: Caller, +) -> Result>, HttpError> { + call(repos, repo, caller, OriginService::landings) + .await + .map(Json) +} + +/// Reads the events after a cursor, waiting up to `wait` for some: a +/// long-poll. Pass the page's `next` as the next request's cursor. +#[utoipa::path( + get, + path = "/api/v1/repos/{repo}/events", + operation_id = "events", + params(("repo" = String, Path, description = "The repository"), EventsQuery), + responses( + (status = 200, description = "The events, oldest first, and the next cursor: empty if none came in time", body = Page), + (status = 404, description = "The repository does not exist", body = ApiError), + (status = 410, description = "The server no longer keeps the events after the cursor", body = ApiError) + ) +)] +async fn events( + repos: Repos, + Path(repo): Path, + caller: Caller, + Query(query): Query, +) -> Result, HttpError> { + call(repos, repo, caller, move |service, caller| { + service.events(caller, &query) + }) + .await + .map(Json) +} + /// The OpenAPI document of this API. #[utoipa::path( get, diff --git a/apps/origin-src/tests/http.rs b/apps/origin-src/tests/http.rs index fed0bd2c..5a4c46f7 100644 --- a/apps/origin-src/tests/http.rs +++ b/apps/origin-src/tests/http.rs @@ -1,14 +1,22 @@ //! The HTTP API, driven through the SDK against a real server: every SDK //! method, over the server's own repositories. +use std::slice; use std::sync::Arc; +use std::time::{Duration, Instant}; use origin_client::{Client, Error, Repo}; -use origin_shared::api::{ErrorCode, FetchRecords, LogQuery, RepoName}; +use origin_shared::api::{ + ErrorCode, EventsQuery, FetchRecords, LandRequest, List, LogQuery, NewTarget, RepoName, + StatementsQuery, +}; +use origin_shared::event::EventKind; +use origin_shared::landing::{Blocked, Landing, Proposal}; use origin_shared::pack::Pack; use origin_shared::{ Base, BlobId, ChangeId, Digest, EncodedObject, EntryKind, EntryName, Inputs, Kind, NodeKey, - Record, RecordId, Revision, RevisionId, Statement, TargetName, Tree, TreeEntry, Verdict, + Period, Record, RecordId, Revision, RevisionId, Source, Statement, TargetName, Tree, TreeEntry, + Verdict, }; use origin_src::http::Api; use origin_src::policy::Policy; @@ -122,6 +130,20 @@ async fn main_tip(repo: &Repo) -> Base { Base::Acceptance(main.head.acceptance) } +fn ci_test(subject: RevisionId) -> EncodedObject { + Statement { + subject: RecordId::Revision(subject), + kind: Kind::new("ci.test").unwrap(), + verdict: Some(Verdict::Pass), + issuer: "user:ci".parse().unwrap(), + inputs: None, + payload: None, + supersedes: None, + promoted_from: None, + } + .encode() +} + fn change(seed: u8) -> ChangeId { ChangeId::from_bytes([seed; 16]) } @@ -335,6 +357,220 @@ async fn promotions_must_match_their_original() { assert_eq!(stored.new, 1, "the original was stored with the forgery"); } +#[tokio::test] +async fn reads_statements_and_revisions() { + let server = Server::start().await; + let repo = &server.demo; + let base = main_tip(repo).await; + let first = Made::revision(change(1), base, vec![], &[("a.txt", "1")]); + let statement = ci_test(first.id); + let mut pack = first.pack(); + pack.objects.push(statement.clone()); + repo.put_records(&pack).await.unwrap(); + + let about_first = StatementsQuery { + subject: RecordId::Revision(first.id), + }; + let found = repo.statements(&about_first).await.unwrap(); + assert_eq!(found.len(), 1); + assert_eq!(found[0].id, statement.id().into()); + assert_eq!(found[0].statement.kind.as_str(), "ci.test"); + assert_eq!(found[0].superseded_by, None); + + // Two revisions evolving from the same one make the change diverge, + // which the server flags. + let left = Made::revision(change(1), base, vec![first.id], &[("a.txt", "2")]); + let right = Made::revision(change(1), base, vec![first.id], &[("a.txt", "3")]); + for made in [&left, &right] { + repo.put_records(&made.pack()).await.unwrap(); + } + let revisions = repo.revisions(change(1)).await.unwrap(); + let ids: Vec<_> = revisions.revisions.iter().map(|entry| entry.id).collect(); + assert_eq!(ids, [first.id, left.id, right.id]); + assert_eq!(revisions.heads, [left.id, right.id]); + let mut flagged = Vec::new(); + for head in [left.id, right.id] { + let query = StatementsQuery { + subject: RecordId::Revision(head), + }; + flagged.extend(repo.statements(&query).await.unwrap()); + } + assert_eq!(flagged.len(), 1, "one statement names both heads"); + assert_eq!(flagged[0].statement.kind, Kind::DIVERGENT); + assert_eq!(flagged[0].statement.issuer.to_string(), "node:hosted"); + + let error = repo.revisions(change(9)).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::NotFound); +} + +#[tokio::test] +async fn lands_changes_and_targets() { + let server = Server::start().await; + let repo = &server.demo; + let made = Made::revision(change(1), main_tip(repo).await, vec![], &[("a.txt", "a")]); + repo.put_records(&made.pack()).await.unwrap(); + + let land = LandRequest { + proposal: Proposal::Change(change(1)), + onto: None, + }; + let landed = repo.land(&land).await.unwrap(); + assert_eq!(landed.onto, TargetName::MAIN, "the target the change is on"); + let [ + Landing::Landed { + source, acceptance, .. + }, + ] = landed.landings[..] + else { + panic!("expected a landing, got {:?}", landed.landings); + }; + assert_eq!( + source, + Source::Revision(made.id), + "made on the tip, so not rebased" + ); + assert_eq!(acceptance.seq, 1); + + let log = repo + .log(&LogQuery { + target: TargetName::MAIN, + since: 1, + }) + .await + .unwrap(); + assert_eq!(log.len(), 1); + assert_eq!(log[0].id, acceptance.acceptance); + assert_eq!(log[0].acceptance.body().landed, [Source::Revision(made.id)]); + + let release = TargetName::new("release").unwrap(); + let new = NewTarget { + name: release.clone(), + from: TargetName::MAIN, + }; + assert_eq!(repo.create_target(&new).await.unwrap().seq, 0); + let error = repo.create_target(&new).await.unwrap_err(); + assert_eq!(code(error), ErrorCode::Conflict, "the name is taken"); + let targets = repo.targets().await.unwrap(); + let names: Vec<_> = targets.iter().map(|target| target.name.as_str()).collect(); + assert_eq!(names, ["main", "policy", "release"]); + assert!( + targets + .iter() + .all(|target| target.authority == Some("hosted".parse().unwrap())) + ); + + let from_main = LandRequest { + proposal: Proposal::Target(TargetName::MAIN), + onto: Some(release), + }; + let landed = repo.land(&from_main).await.unwrap(); + assert!(matches!(landed.landings[..], [Landing::Unchanged(_)])); + let nowhere = LandRequest { + onto: None, + ..from_main + }; + assert_eq!( + code(repo.land(&nowhere).await.unwrap_err()), + ErrorCode::BadRequest + ); + let unknown = LandRequest { + proposal: Proposal::Change(change(9)), + onto: None, + }; + assert_eq!( + code(repo.land(&unknown).await.unwrap_err()), + ErrorCode::NotFound + ); +} + +#[tokio::test] +async fn landings_wait_for_evidence() { + let server = Server::start().await; + let repo = &server.strict; + let made = Made::revision(change(1), main_tip(repo).await, vec![], &[("a.txt", "a")]); + repo.put_records(&made.pack()).await.unwrap(); + let land = LandRequest { + proposal: Proposal::Change(change(1)), + onto: None, + }; + + let landed = repo.land(&land).await.unwrap(); + let [Landing::Pending(pending)] = &landed.landings[..] else { + panic!("expected a waiting landing, got {:?}", landed.landings); + }; + assert_eq!(pending.subject, RecordId::Revision(made.id)); + assert!(matches!(&pending.blocked, Blocked::Evidence(missing) if missing.len() == 1)); + assert_eq!(repo.landings().await.unwrap(), slice::from_ref(pending)); + + let query = EventsQuery { + cursor: Some(0), + kind: List(vec!["check.requested".parse().unwrap()]), + ..EventsQuery::default() + }; + let page = repo.events(&query).await.unwrap(); + assert!( + matches!(&page.events[..], [event] if matches!(event.kind, + EventKind::CheckRequested { subject, .. } if subject == RecordId::Revision(made.id))), + "{page:?}" + ); + + repo.put_records(&Pack { + objects: vec![ci_test(made.id)], + }) + .await + .unwrap(); + let landed = repo.land(&land).await.unwrap(); + assert!(matches!(landed.landings[..], [Landing::Landed { .. }])); + assert_eq!(repo.landings().await.unwrap(), []); +} + +#[tokio::test] +async fn events_long_poll() { + let server = Server::start().await; + let repo = server.demo.clone(); + let now = repo.events(&EventsQuery::default()).await.unwrap(); + assert!( + now.events.is_empty(), + "without a cursor, only new events come" + ); + + let query = EventsQuery { + cursor: Some(now.next), + wait: Some(Period(Duration::from_secs(30))), + kind: List(vec!["revision.created".parse().unwrap()]), + ..EventsQuery::default() + }; + let start = Instant::now(); + let poll = tokio::spawn(async move { repo.events(&query).await.unwrap() }); + tokio::time::sleep(Duration::from_millis(100)).await; + let made = Made::revision(change(1), main_tip(&server.demo).await, vec![], &[]); + server.demo.put_records(&made.pack()).await.unwrap(); + let page = poll.await.unwrap(); + assert!( + start.elapsed() < Duration::from_secs(10), + "it answered once a revision came" + ); + assert!( + matches!(&page.events[..], [event] if event.kind.record() == RecordId::Revision(made.id)), + "{page:?}" + ); + assert!(page.next > now.next); + + let all = server + .demo + .events(&EventsQuery { + cursor: Some(0), + limit: Some(1), + ..EventsQuery::default() + }) + .await + .unwrap(); + assert!( + matches!(&all.events[..], [event] if event.kind.name() == "target.advanced"), + "the first event is `policy`'s first acceptance: {all:?}" + ); +} + #[tokio::test] async fn serves_its_openapi_document() { let server = Server::start().await; diff --git a/crates/origin-client/src/lib.rs b/crates/origin-client/src/lib.rs index 046ca71c..398f2d9c 100644 --- a/crates/origin-client/src/lib.rs +++ b/crates/origin-client/src/lib.rs @@ -19,9 +19,13 @@ //! in `docs/openapi.json`, for other languages. use origin_shared::api::{ - ApiError, FetchRecords, LogEntry, LogQuery, RepoName, RepoSummary, Stored, TargetInfo, + Annotation, ApiError, EventsQuery, FetchRecords, LandRequest, Landings, LogEntry, LogQuery, + NewTarget, RepoName, RepoSummary, Revisions, StatementsQuery, Stored, TargetInfo, }; +use origin_shared::event::Page; +use origin_shared::landing::Pending; use origin_shared::pack::{Pack, PackError}; +use origin_shared::{ChangeId, Head}; use reqwest::{Method, RequestBuilder}; use serde::de::DeserializeOwned; @@ -67,10 +71,26 @@ endpoints! { /// Puts a batch of objects: snapshots, revisions and statements, /// each needing only objects the batch or the repository has. fn put_records(pack: &Pack) -> Stored = PUT "records", body(pack.encode()) => json; + /// The statements about a record, in the order the repository + /// received them. + fn statements(query: &StatementsQuery) -> Vec = + GET "statements", query(query) => json; + /// The revisions of a change, and its heads. + fn revisions(change: ChangeId) -> Revisions = GET "changes/{change}/revisions" => json; /// Every target, with its tip, authority and requirements. fn targets() -> Vec = GET "targets" => json; + /// Creates a target at the tip of another, ordered by the server. + fn create_target(request: &NewTarget) -> Head = POST "targets", json(request) => json; /// The acceptances of a target, oldest first. fn log(query: &LogQuery) -> Vec = GET "log", query(query) => json; + /// Submits a change, or a target's tip, to a target's landing + /// queue, which the server runs. + fn land(request: &LandRequest) -> Landings = POST "land", json(request) => json; + /// The landings that wait, and why. + fn landings() -> Vec = GET "landings" => json; + /// The events after a cursor, waiting up to the query's `wait` for + /// some: pass the page's `next` as the next query's cursor. + fn events(query: &EventsQuery) -> Page = GET "events", query(query) => json; } } diff --git a/docs/openapi.json b/docs/openapi.json index 7e8fc9fe..3e2e4de0 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -48,6 +48,263 @@ } } }, + "/api/v1/repos/{repo}/changes/{change}/revisions": { + "get": { + "summary": "Lists the revisions of a change, and its heads.", + "operationId": "revisions", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "change", + "in": "path", + "description": "The change's id", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The revisions, in the order the repository received them", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Revisions" + } + } + } + }, + "404": { + "description": "The repository or the change does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + }, + "/api/v1/repos/{repo}/events": { + "get": { + "summary": "Reads the events after a cursor, waiting up to `wait` for some: a\nlong-poll. Pass the page's `next` as the next request's cursor.", + "operationId": "events", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "cursor", + "in": "query", + "description": "The cursor to read after: the `next` of the previous page. By\ndefault, the end of the stream, so only new events come.", + "required": false, + "schema": { + "type": "integer", + "format": "int64", + "minimum": 0 + } + }, + { + "name": "wait", + "in": "query", + "description": "How long to wait for events, such as `30s`. Without it, the answer\ncomes at once, possibly empty.", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "limit", + "in": "query", + "description": "Stop after about this many events: an entry's events are delivered\nwhole.", + "required": false, + "schema": { + "type": "integer", + "format": "int32", + "minimum": 0 + } + }, + { + "name": "kind", + "in": "query", + "description": "Only events of these names or statement kinds, comma-separated, such\nas `check.requested,ci.*`.", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "subject", + "in": "query", + "description": "Only events whose subject starts with one of these, comma-separated,\nsuch as a revision id prefix, `change:3fa2` or `main`.", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The events, oldest first, and the next cursor: empty if none came in time", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Page" + } + } + } + }, + "404": { + "description": "The repository does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "410": { + "description": "The server no longer keeps the events after the cursor", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + }, + "/api/v1/repos/{repo}/land": { + "post": { + "summary": "Submits a change, or a target's tip, to a target's landing queue, run\nby this server.", + "operationId": "land", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LandRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "How each landing went: landed, unchanged, or waiting for evidence or a conflict's resolution", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Landings" + } + } + } + }, + "400": { + "description": "A target was proposed without a target to land on", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "404": { + "description": "The repository, the change or a target does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "409": { + "description": "The change diverged or was abandoned, or this server doesn't order the target", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + }, + "/api/v1/repos/{repo}/landings": { + "get": { + "summary": "Lists the landings that wait, and why.", + "operationId": "landings", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The waiting landings, by target", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pending" + } + } + } + } + }, + "404": { + "description": "The repository does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + }, "/api/v1/repos/{repo}/log": { "get": { "summary": "Lists the acceptances of a target, oldest first.", @@ -219,10 +476,10 @@ } } }, - "/api/v1/repos/{repo}/targets": { + "/api/v1/repos/{repo}/statements": { "get": { - "summary": "Lists the targets, with their tips, authorities and requirements.", - "operationId": "targets", + "summary": "Lists the statements about a record, in the order the repository\nreceived them.", + "operationId": "statements", "parameters": [ { "name": "repo", @@ -232,17 +489,26 @@ "schema": { "type": "string" } + }, + { + "name": "subject", + "in": "query", + "description": "The record, such as `revision:`.", + "required": true, + "schema": { + "type": "string" + } } ], "responses": { "200": { - "description": "The targets, by name", + "description": "The statements", "content": { "application/json": { "schema": { "type": "array", "items": { - "$ref": "#/components/schemas/TargetInfo" + "$ref": "#/components/schemas/Annotation" } } } @@ -260,29 +526,128 @@ } } } - } - }, - "components": { - "schemas": { - "Acceptance": { - "allOf": [ - { - "$ref": "#/components/schemas/AcceptanceBody" - }, + }, + "/api/v1/repos/{repo}/targets": { + "get": { + "summary": "Lists the targets, with their tips, authorities and requirements.", + "operationId": "targets", + "parameters": [ { - "type": "object", - "required": [ - "signature" - ], - "properties": { - "signature": { - "type": "string" - } - } - } - ], - "description": "One landing on a target, signed by the target's authority.\n\nAcceptances form a hash chain per target: each names the one before it,\nand its sequence number is its position in the target's log.\n\nIn JSON, the body's fields and the signature, in hex." - }, + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The targets, by name", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TargetInfo" + } + } + } + } + }, + "404": { + "description": "The repository does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + }, + "post": { + "summary": "Creates a target at the tip of another, ordered by this server.", + "operationId": "create_target", + "parameters": [ + { + "name": "repo", + "in": "path", + "description": "The repository", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NewTarget" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "The new target's first acceptance", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Head" + } + } + } + }, + "404": { + "description": "The repository or the target to start from does not exist", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + }, + "409": { + "description": "The name is taken, or this server wouldn't order the target", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiError" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Acceptance": { + "allOf": [ + { + "$ref": "#/components/schemas/AcceptanceBody" + }, + { + "type": "object", + "required": [ + "signature" + ], + "properties": { + "signature": { + "type": "string" + } + } + } + ], + "description": "One landing on a target, signed by the target's authority.\n\nAcceptances form a hash chain per target: each names the one before it,\nand its sequence number is its position in the target's log.\n\nIn JSON, the body's fields and the signature, in hex." + }, "AcceptanceBody": { "type": "object", "description": "An acceptance without its signature.", @@ -352,6 +717,40 @@ "48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" ] }, + "Annotation": { + "type": "object", + "description": "A statement, whether its issuer superseded it, and whether its claim\nholds.", + "required": [ + "id", + "statement", + "holds" + ], + "properties": { + "holds": { + "type": "boolean", + "description": "Whether its claim counts, as the landing queue counts evidence: it\nisn't superseded, and a promotion is valid, its original isn't\nsuperseded, and no result about the record replaces it." + }, + "id": { + "$ref": "#/components/schemas/StatementId", + "description": "The statement's id." + }, + "statement": { + "$ref": "#/components/schemas/Statement", + "description": "The statement." + }, + "superseded_by": { + "oneOf": [ + { + "$ref": "#/components/schemas/StatementId", + "description": "The first statement from the same issuer that supersedes it." + }, + { + "type": "null" + } + ] + } + } + }, "ApiError": { "type": "object", "description": "What went wrong with a request.", @@ -370,10 +769,110 @@ } } }, + "Base": { + "oneOf": [ + { + "type": "object", + "description": "The state of a target after one of its acceptances.", + "required": [ + "acceptance" + ], + "properties": { + "acceptance": { + "$ref": "#/components/schemas/AcceptanceId", + "description": "The state of a target after one of its acceptances." + } + } + }, + { + "type": "object", + "description": "Another revision, such as the one below in a stack.", + "required": [ + "revision" + ], + "properties": { + "revision": { + "$ref": "#/components/schemas/RevisionId", + "description": "Another revision, such as the one below in a stack." + } + } + } + ], + "description": "What a revision was made on top of." + }, "Binary": { "type": "string", "contentMediaType": "application/octet-stream" }, + "BlobId": { + "type": "string", + "examples": [ + "48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" + ] + }, + "Blocked": { + "oneOf": [ + { + "type": "object", + "description": "The target requires these statements about the subject.", + "required": [ + "evidence" + ], + "properties": { + "evidence": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Requirement" + }, + "description": "The target requires these statements about the subject." + } + } + }, + { + "type": "object", + "description": "Both sides changed these paths. The `core.conflict` statement lists\nthem too.", + "required": [ + "conflict" + ], + "properties": { + "conflict": { + "type": "object", + "description": "Both sides changed these paths. The `core.conflict` statement lists\nthem too.", + "required": [ + "statement", + "paths" + ], + "properties": { + "paths": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RepoPath" + }, + "description": "The paths, sorted." + }, + "statement": { + "$ref": "#/components/schemas/StatementId", + "description": "The statement." + } + } + } + } + } + ], + "description": "Why a landing waits." + }, + "ChangeId": { + "type": "string", + "examples": [ + "3fa2c1d0e9b84f6a7c5d2e1f0a9b8c7d" + ] + }, + "Digest": { + "type": "string", + "examples": [ + "48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" + ] + }, "ErrorCode": { "type": "string", "description": "The kind of an [`ApiError`].", @@ -385,6 +884,172 @@ "internal" ] }, + "Event": { + "allOf": [ + { + "$ref": "#/components/schemas/EventKind", + "description": "What happened." + }, + { + "type": "object", + "required": [ + "cursor" + ], + "properties": { + "cursor": { + "type": "integer", + "format": "int64", + "description": "The sequence number of the op log entry it comes from. Reading from\nit delivers the events of the entries after it.", + "minimum": 0 + } + } + } + ], + "description": "Something that happened, and where it is in the op log." + }, + "EventKind": { + "oneOf": [ + { + "type": "object", + "description": "A statement was issued.", + "required": [ + "statement", + "subject", + "kind", + "issuer", + "event" + ], + "properties": { + "event": { + "type": "string", + "enum": [ + "statement.issued" + ] + }, + "issuer": { + "$ref": "#/components/schemas/Principal", + "description": "Who issued it." + }, + "kind": { + "$ref": "#/components/schemas/Kind", + "description": "Its kind." + }, + "statement": { + "$ref": "#/components/schemas/StatementId", + "description": "The statement." + }, + "subject": { + "$ref": "#/components/schemas/RecordId", + "description": "What it's about." + }, + "verdict": { + "oneOf": [ + { + "$ref": "#/components/schemas/Verdict", + "description": "Its verdict." + }, + { + "type": "null" + } + ] + } + } + }, + { + "type": "object", + "description": "A revision was created.", + "required": [ + "revision", + "change", + "author", + "event" + ], + "properties": { + "author": { + "$ref": "#/components/schemas/Principal", + "description": "Who made it." + }, + "change": { + "$ref": "#/components/schemas/ChangeId", + "description": "Its change." + }, + "event": { + "type": "string", + "enum": [ + "revision.created" + ] + }, + "revision": { + "$ref": "#/components/schemas/RevisionId", + "description": "The revision." + } + } + }, + { + "type": "object", + "description": "A target advanced.", + "required": [ + "target", + "seq", + "acceptance", + "event" + ], + "properties": { + "acceptance": { + "$ref": "#/components/schemas/AcceptanceId", + "description": "The acceptance." + }, + "event": { + "type": "string", + "enum": [ + "target.advanced" + ] + }, + "seq": { + "type": "integer", + "format": "int64", + "description": "The acceptance's position in its log.", + "minimum": 0 + }, + "target": { + "$ref": "#/components/schemas/TargetName", + "description": "The target." + } + } + }, + { + "type": "object", + "description": "A landing waits for a statement it requires.", + "required": [ + "onto", + "subject", + "requirement", + "event" + ], + "properties": { + "event": { + "type": "string", + "enum": [ + "check.requested" + ] + }, + "onto": { + "$ref": "#/components/schemas/TargetName", + "description": "The target it lands on." + }, + "requirement": { + "$ref": "#/components/schemas/Requirement", + "description": "The statement required." + }, + "subject": { + "$ref": "#/components/schemas/RecordId", + "description": "What the statement must be about." + } + } + } + ], + "description": "What happened: an event's identity, which consumers deduplicate by. In\nJSON, the `event` field names it, as [`EventKind::name`] does." + }, "FetchRecords": { "type": "object", "description": "Asks for records, and any other objects, by id.", @@ -421,12 +1086,151 @@ } } }, + "Inputs": { + "type": "object", + "description": "What a statement depended on.\n\nThe input digest of a snapshot hashes the ids it stores at `paths`, with\n`definition` and `toolchain`. A statement that declares inputs and isn't\n`external` is promoted to every revision with the same input digest.", + "required": [ + "paths", + "definition", + "toolchain", + "external" + ], + "properties": { + "definition": { + "$ref": "#/components/schemas/Digest", + "description": "The check's command and configuration." + }, + "external": { + "type": "boolean", + "description": "Whether the claim also depended on things outside the snapshot, such\nas the network, which makes it never promotable." + }, + "paths": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RepoPath" + }, + "description": "The files and directories read, each covering everything under it." + }, + "toolchain": { + "$ref": "#/components/schemas/Digest", + "description": "The tools that ran it, such as the hash of `rustc -V`." + } + } + }, "Kind": { "type": "string", "examples": [ "ci.test" ] }, + "LandRequest": { + "type": "object", + "description": "Asks the queue to land something.", + "required": [ + "proposal" + ], + "properties": { + "onto": { + "oneOf": [ + { + "$ref": "#/components/schemas/TargetName", + "description": "The target to land on. For a change, the target its stack is on by\ndefault; a target needs one." + }, + { + "type": "null" + } + ] + }, + "proposal": { + "$ref": "#/components/schemas/Proposal", + "description": "What to land." + } + } + }, + "Landing": { + "oneOf": [ + { + "type": "object", + "description": "It landed.", + "required": [ + "landed" + ], + "properties": { + "landed": { + "type": "object", + "description": "It landed.", + "required": [ + "proposal", + "source", + "acceptance" + ], + "properties": { + "acceptance": { + "$ref": "#/components/schemas/Head", + "description": "The acceptance." + }, + "proposal": { + "$ref": "#/components/schemas/Proposal", + "description": "What landed." + }, + "source": { + "$ref": "#/components/schemas/Source", + "description": "The revision or acceptance the acceptance names." + } + } + } + } + }, + { + "type": "object", + "description": "The target already has it, so nothing landed.", + "required": [ + "unchanged" + ], + "properties": { + "unchanged": { + "$ref": "#/components/schemas/Proposal", + "description": "The target already has it, so nothing landed." + } + } + }, + { + "type": "object", + "description": "It waits, and the queue keeps it.", + "required": [ + "pending" + ], + "properties": { + "pending": { + "$ref": "#/components/schemas/Pending", + "description": "It waits, and the queue keeps it." + } + } + } + ], + "description": "How a landing went." + }, + "Landings": { + "type": "object", + "description": "How a landing went.", + "required": [ + "onto", + "landings" + ], + "properties": { + "landings": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Landing" + }, + "description": "How each landing went: one for each change of a stack that the\ntarget didn't have, from the bottom, up to the first that waits." + }, + "onto": { + "$ref": "#/components/schemas/TargetName", + "description": "The target landed on." + } + } + }, "LogEntry": { "type": "object", "description": "One acceptance of a target's log.", @@ -445,12 +1249,87 @@ } } }, + "NewTarget": { + "type": "object", + "description": "Asks for a new target.", + "required": [ + "name", + "from" + ], + "properties": { + "from": { + "$ref": "#/components/schemas/TargetName", + "description": "The target whose tip it starts at." + }, + "name": { + "$ref": "#/components/schemas/TargetName", + "description": "Its name." + } + } + }, "ObjectId": { "type": "string", "examples": [ "48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" ] }, + "Page": { + "type": "object", + "description": "A batch of events, and the cursor to read the next batch from.", + "required": [ + "events", + "next" + ], + "properties": { + "events": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Event" + }, + "description": "The events, oldest first." + }, + "next": { + "type": "integer", + "format": "int64", + "description": "The cursor after the entries read: pass it to the next read.", + "minimum": 0 + } + } + }, + "Pending": { + "type": "object", + "description": "A landing that waits, kept in the queue to be listed and retried.", + "required": [ + "onto", + "proposal", + "subject", + "blocked" + ], + "properties": { + "blocked": { + "$ref": "#/components/schemas/Blocked", + "description": "Why it waits." + }, + "onto": { + "$ref": "#/components/schemas/TargetName", + "description": "The target it lands on." + }, + "proposal": { + "$ref": "#/components/schemas/Proposal", + "description": "What lands." + }, + "subject": { + "$ref": "#/components/schemas/RecordId", + "description": "What the evidence must be about: the revision that would land, or\nthe merged snapshot of a target. A conflict is about the revision,\nor the acceptance, that didn't merge." + } + } + }, + "Principal": { + "type": "string", + "examples": [ + "user:alice" + ] + }, "PrincipalName": { "type": "string", "examples": [ @@ -463,11 +1342,54 @@ "group:runners" ] }, + "Proposal": { + "oneOf": [ + { + "type": "object", + "description": "A change, as of its head.", + "required": [ + "change" + ], + "properties": { + "change": { + "$ref": "#/components/schemas/ChangeId", + "description": "A change, as of its head." + } + } + }, + { + "type": "object", + "description": "Another target, as of its tip.", + "required": [ + "target" + ], + "properties": { + "target": { + "$ref": "#/components/schemas/TargetName", + "description": "Another target, as of its tip." + } + } + } + ], + "description": "What a landing lands." + }, + "RecordId": { + "type": "string", + "examples": [ + "revision:48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" + ] + }, "RepoName": { "type": "string", "description": "The name of a repository on a server: ASCII letters, digits, `.`, `_`\nand `-`, not starting with `.`.", "example": "origin" }, + "RepoPath": { + "type": "string", + "examples": [ + "src/main.rs" + ] + }, "RepoSummary": { "type": "object", "description": "A repository, as listed by the server.", @@ -504,12 +1426,103 @@ } } }, + "Revision": { + "type": "object", + "description": "One immutable version of a change.\n\nEditing, rebasing or handing a change to someone else creates a new\nrevision of the same change, whose predecessors are the revisions it\nevolves from.", + "required": [ + "change", + "predecessors", + "base", + "deps", + "snapshot", + "description", + "author" + ], + "properties": { + "author": { + "$ref": "#/components/schemas/Principal", + "description": "Who wrote the revision." + }, + "base": { + "$ref": "#/components/schemas/Base", + "description": "What the revision was made on top of." + }, + "change": { + "$ref": "#/components/schemas/ChangeId", + "description": "The change this is a version of." + }, + "deps": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RevisionId" + }, + "description": "The exact revisions this one requires: the changes below it in a\nstack." + }, + "description": { + "$ref": "#/components/schemas/BlobId", + "description": "The intent, written for humans and agents." + }, + "predecessors": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RevisionId" + }, + "description": "The revisions this one evolves from. Two make it a convergence of\ndivergent heads." + }, + "snapshot": { + "$ref": "#/components/schemas/TreeId", + "description": "The root tree of the files." + } + } + }, + "RevisionEntry": { + "type": "object", + "description": "A revision and its id.", + "required": [ + "id", + "revision" + ], + "properties": { + "id": { + "$ref": "#/components/schemas/RevisionId", + "description": "The revision's id." + }, + "revision": { + "$ref": "#/components/schemas/Revision", + "description": "The revision." + } + } + }, "RevisionId": { "type": "string", "examples": [ "48fc721fbbc172e0925fa27af1671de225ba927134802998b10a1568a188652b" ] }, + "Revisions": { + "type": "object", + "description": "The revisions of a change.", + "required": [ + "revisions", + "heads" + ], + "properties": { + "heads": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RevisionId" + }, + "description": "Those that no other revision of the change evolves from: more than\none is divergence." + }, + "revisions": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RevisionEntry" + }, + "description": "Every revision, in the order the repository received them." + } + } + }, "Source": { "oneOf": [ { @@ -541,6 +1554,84 @@ ], "description": "What an acceptance landed." }, + "Statement": { + "type": "object", + "description": "An attributable claim about another record: a check result, a review, a\nconflict, an abandonment.\n\nStatements are permanent. An issuer revises one by issuing another that\nsupersedes it. A promoted statement carries another one over to a record\nwith the same input digest, pointing at it instead of copying its issuer.", + "required": [ + "subject", + "kind", + "issuer" + ], + "properties": { + "inputs": { + "oneOf": [ + { + "$ref": "#/components/schemas/Inputs", + "description": "What the claim depended on, which lets it be promoted to revisions\nwith the same inputs." + }, + { + "type": "null" + } + ] + }, + "issuer": { + "$ref": "#/components/schemas/Principal", + "description": "Who makes the claim." + }, + "kind": { + "$ref": "#/components/schemas/Kind", + "description": "What kind of claim it is." + }, + "payload": { + "oneOf": [ + { + "$ref": "#/components/schemas/BlobId", + "description": "Free-form details, defined by whoever owns the kind." + }, + { + "type": "null" + } + ] + }, + "promoted_from": { + "oneOf": [ + { + "$ref": "#/components/schemas/StatementId", + "description": "The statement this one promotes: its kind, verdict, inputs and\npayload hold here too, because the input digests are equal. The\nissuer is whoever promoted it, the original's stays on the original." + }, + { + "type": "null" + } + ] + }, + "subject": { + "$ref": "#/components/schemas/RecordId", + "description": "The record the claim is about." + }, + "supersedes": { + "oneOf": [ + { + "$ref": "#/components/schemas/StatementId", + "description": "A statement from the same issuer that this one replaces." + }, + { + "type": "null" + } + ] + }, + "verdict": { + "oneOf": [ + { + "$ref": "#/components/schemas/Verdict", + "description": "The outcome, the only field core interprets." + }, + { + "type": "null" + } + ] + } + } + }, "StatementId": { "type": "string", "examples": [