Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ review bots read and write at the same time, written in Rust.
the HTTP routes (`http.rs`) and the command line's commands that the API
offers only translate into its calls, so neither duplicates the other.
`sync.rs` shares records with a remote (`remote.rs`), which answers the
same calls over the SDK or, for a local path, in-process.
same calls over the SDK or, for a local path, in-process. Every call
takes a `Caller`, authenticated by `auth.rs`; `permissions.rs` filters
what it reads and checks what it writes, by the rights `policy.rs`
resolves from `policy.toml`.
- `tools/xtask`: development tasks, run with `cargo xtask`, such as timing
origin against git (`just bench-git`).

## API changes

Every server feature lives in `OriginService`; transports like HTTP only
translate requests. A new HTTP endpoint also takes a line in the SDK's
`endpoints!` macro, and `just openapi` to update `docs/openapi.json`.

## Testing & Benchmarks

Performance is a primary goal, so benchmarks matter as much as tests. A change
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ send each server under `[tokens]`, by its URL
(`"http://127.0.0.1:7878" = "<token>"`), or in `$ORIGIN_TOKEN`. See
[the design](docs/design.md) for the model.

`origin token issue --scope <capability>... --ttl <period>` asks the remote
for a token acting for you with a narrower scope, such as `write src`,
`read /`, `annotate ci.*`, `land main` or `admin`; the server verifies it
without storing it. A server's operator signs one for any principal with
`origin token issue --config origin-server.toml --as user:agent-1 --scope
...`. A token never grants more than its principal's rights, lasts at most
7 days, and a token issued with a token expires with it.

`converge` merges the files of a change's heads. A text file two heads
changed holds both versions between conflict markers (`<<<<<<<`, `=======`,
`>>>>>>>`), and a binary one keeps one side. A `core.conflict` statement
Expand Down Expand Up @@ -175,7 +167,8 @@ cursor of another log, such as from before the repository was restored,
is refused as expired.
[`docs/openapi.json`](docs/openapi.json) describes it, and
[`origin-client`](crates/origin-client) is its Rust SDK. Callers send
`Authorization: Bearer <token>`; without one, they are anonymous.
`Authorization: Bearer <token>`; without one, they are anonymous, and only
read what everyone may.

## Development

Expand Down
45 changes: 35 additions & 10 deletions apps/origin-src/benches/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use origin_shared::api::LandRequest;
use origin_shared::landing::{Landing, Proposal};
use origin_shared::pack::Pack;
use origin_shared::{
Base, ChangeId, EncodedObject, Kind, NodeKey, Record, RecordId, Revision, Statement,
Base, ChangeId, EncodedObject, Kind, NodeKey, Principal, Record, RecordId, Revision, Statement,
TargetName, TreeId, Verdict,
};
use origin_src::auth::{Credentials, StaticTokens};
Expand Down Expand Up @@ -100,7 +100,7 @@ static SETUP: LazyLock<Setup> = LazyLock::new(|| {
let store = Store::new(client.path().join(".origin"), Native::default());
store.init().unwrap();
let remote = Remote::open(&url, node.clone(), Some("bench".to_owned())).unwrap();
let sync = Sync::new(&store, &remote, "laptop".parse().unwrap());
let sync = Sync::new(&store, &remote, "laptop".parse().unwrap(), bench_user());
sync.fetch_chains(&[TargetName::MAIN]).unwrap();
sync.need(tip.into(), &[]).unwrap();
// The client knows the records, as a fetch would have brought them.
Expand Down Expand Up @@ -186,6 +186,11 @@ impl Setup {
}
}

/// The user the benchmarks push as.
fn bench_user() -> Principal {
"user:bench".parse().unwrap()
}

/// The snapshot a clone fetches: every file, into an empty repository.
#[divan::bench(sample_count = 10)]
fn clone_snapshot(bencher: Bencher<'_, '_>) {
Expand All @@ -206,7 +211,7 @@ fn clone_snapshot(bencher: Bencher<'_, '_>) {
(dir, store)
})
.bench_local_refs(|(_, store)| {
let sync = Sync::new(store, &remote, "laptop".parse().unwrap());
let sync = Sync::new(store, &remote, "laptop".parse().unwrap(), bench_user());
assert!(sync.need(setup.tip.into(), &[]).unwrap());
});
}
Expand All @@ -217,7 +222,12 @@ fn clone_snapshot(bencher: Bencher<'_, '_>) {
fn fetch_100_edited(bencher: Bencher<'_, '_>) {
let setup = &*SETUP;
let remote = setup.remote();
let sync = Sync::new(&setup.client, &remote, "laptop".parse().unwrap());
let sync = Sync::new(
&setup.client,
&remote,
"laptop".parse().unwrap(),
bench_user(),
);
let next = AtomicUsize::new(0);
bencher
.with_inputs(|| setup.theirs[next.fetch_add(1, Ordering::Relaxed) % SAMPLES as usize])
Expand All @@ -232,7 +242,12 @@ fn fetch_100_edited(bencher: Bencher<'_, '_>) {
fn push_100_edited(bencher: Bencher<'_, '_>) {
let setup = &*SETUP;
let remote = setup.remote();
let sync = Sync::new(&setup.client, &remote, "laptop".parse().unwrap());
let sync = Sync::new(
&setup.client,
&remote,
"laptop".parse().unwrap(),
bench_user(),
);
let next = AtomicUsize::new(0);
bencher
.with_inputs(|| {
Expand Down Expand Up @@ -286,14 +301,14 @@ static HISTORY_SETUP: LazyLock<History> = LazyLock::new(|| {
deps: Vec::new(),
snapshot: state,
description: description.id().into(),
author: "user:bench".parse().unwrap(),
author: bench_user(),
}
.encode();
let statement = Statement {
subject: RecordId::Revision(revision.id().into()),
kind: Kind::new("ci.test").unwrap(),
verdict: Some(Verdict::Pass),
issuer: "user:bench".parse().unwrap(),
issuer: bench_user(),
inputs: None,
payload: None,
supersedes: None,
Expand All @@ -311,7 +326,7 @@ static HISTORY_SETUP: LazyLock<History> = LazyLock::new(|| {
let store = Store::new(client.path().join(".origin"), Native::default());
store.init().unwrap();
let remote = Remote::open(&url, node, Some("bench".to_owned())).unwrap();
let sync = Sync::new(&store, &remote, "laptop".parse().unwrap());
let sync = Sync::new(&store, &remote, "laptop".parse().unwrap(), bench_user());
let fetch = sync.fetch(&[TargetName::MAIN], &changes, None).unwrap();
assert_eq!(fetch.fetched.revisions, HISTORY as usize);
let cursor = fetch.cursor;
Expand All @@ -330,7 +345,12 @@ static HISTORY_SETUP: LazyLock<History> = LazyLock::new(|| {
#[divan::bench(sample_count = 20)]
fn fetch_unchanged(bencher: Bencher<'_, '_>) {
let history = &*HISTORY_SETUP;
let sync = Sync::new(&history.client, &history.remote, "laptop".parse().unwrap());
let sync = Sync::new(
&history.client,
&history.remote,
"laptop".parse().unwrap(),
bench_user(),
);
bencher.bench_local(|| {
let fetch = sync.fetch(&[], &[], Some(&history.cursor)).unwrap();
assert_eq!(fetch.fetched, Fetched::default());
Expand All @@ -342,7 +362,12 @@ fn fetch_unchanged(bencher: Bencher<'_, '_>) {
#[divan::bench(sample_count = 10)]
fn fetch_unchanged_without_cursor(bencher: Bencher<'_, '_>) {
let history = &*HISTORY_SETUP;
let sync = Sync::new(&history.client, &history.remote, "laptop".parse().unwrap());
let sync = Sync::new(
&history.client,
&history.remote,
"laptop".parse().unwrap(),
bench_user(),
);
bencher.bench_local(|| {
let fetch = sync.fetch(&[], &[], None).unwrap();
assert_eq!(fetch.fetched, Fetched::default());
Expand Down
3 changes: 2 additions & 1 deletion apps/origin-src/src/annotations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ impl<'a, P: Platform> Annotations<'a, P> {
}

/// Where the revisions are read that decide who may issue a reserved kind:
/// a store.
/// a store, or a batch being put along with what its store has, so a
/// statement can be about a revision of the same batch.
pub trait RevisionView {
/// The revision `id`.
///
Expand Down
Loading
Loading