diff --git a/apps/origin-src/src/conflict.rs b/apps/origin-src/src/conflict.rs index 26d25ef5..4367cad4 100644 --- a/apps/origin-src/src/conflict.rs +++ b/apps/origin-src/src/conflict.rs @@ -23,7 +23,9 @@ //! Every revision made from one with unresolved paths, by a snapshot, //! `describe`, a new change on top, or a merge, carries those it still has //! the entries of over, in a `core.conflict` of its own, published before -//! the revision itself, so it's never found without it. +//! the revision itself, so it's never found without it. The landing queue +//! refuses a revision whose author's latest `core.conflict` lists a path it +//! still has the entry of. //! //! The landing queue also issues `core.conflict`, as a node, when a revision //! doesn't rebase onto its target, even one the queue rebased itself. That diff --git a/apps/origin-src/src/queue/mod.rs b/apps/origin-src/src/queue/mod.rs index 1cc1ccf9..d9220bd3 100644 --- a/apps/origin-src/src/queue/mod.rs +++ b/apps/origin-src/src/queue/mod.rs @@ -3,8 +3,9 @@ //! //! Landing a change lands its stack: the head of each change below it that //! isn't on the target yet, from the bottom, with an acceptance each. A -//! change that diverged is refused. A stack stops at the first change that -//! waits. For each revision: +//! change that diverged, that its creator abandoned, or whose head has +//! unresolved conflicts (see [`conflict`](crate::conflict)) is refused. A +//! stack stops at the first change that waits. For each revision: //! //! 1. **Rebase.** The changes it made to its base are merged onto the //! target's tip, file by file ([`Store::merge`]). A revision made on the @@ -159,7 +160,8 @@ impl<'a, P: Platform> Queue<'a, P> { /// # Errors /// /// Fails if this node isn't the target's authority, a change in the - /// stack diverged, or the records cannot be read or written. + /// stack diverged, was abandoned or has unresolved conflicts, or the + /// records cannot be read or written. pub fn land_change( &self, change: ChangeId, @@ -313,6 +315,22 @@ pub enum LandError { /// Its heads. heads: Vec, }, + /// The change was given up. + #[error("change {} was abandoned, so it cannot land", .0.short())] + Abandoned(ChangeId), + /// The change's head has unresolved conflicts. + #[error( + "change {} has unresolved conflicts, so it cannot land: edit {}, or accept them as they \ + are with `origin resolve`", + change.short(), + paths.iter().map(ToString::to_string).collect::>().join(", ") + )] + Unresolved { + /// The change. + change: ChangeId, + /// The unresolved paths. + paths: Vec, + }, /// Landing on `policy` would leave it without a valid policy. #[error("landing would leave `policy` without a valid policy.toml")] InvalidPolicy(#[source] PolicyError), diff --git a/apps/origin-src/src/queue/session.rs b/apps/origin-src/src/queue/session.rs index 4e3eedc5..e8869f6c 100644 --- a/apps/origin-src/src/queue/session.rs +++ b/apps/origin-src/src/queue/session.rs @@ -73,6 +73,20 @@ impl Session<'_, '_, P> { if self.has_landed(head, &revision)? { break; } + let claims = self.annotations.claims(RecordId::Revision(head))?; + for claim in &claims { + let statement = claim.statement(); + if statement.kind == Kind::ABANDON && self.store().authorizes(statement)? { + return Err(LandError::Abandoned(change)); + } + } + let conflicts = Conflicts::of(self.store(), &claims, &revision)?; + if !conflicts.is_empty() { + return Err(LandError::Unresolved { + change, + paths: conflicts.paths(), + }); + } if let Base::Revision(below) = revision.base { next = Some(self.store().get(below)?.change); } diff --git a/apps/origin-src/src/queue/tests/changes.rs b/apps/origin-src/src/queue/tests/changes.rs index 82e2aaf4..d8b62c66 100644 --- a/apps/origin-src/src/queue/tests/changes.rs +++ b/apps/origin-src/src/queue/tests/changes.rs @@ -3,6 +3,8 @@ use std::sync::Mutex; use std::thread; +use origin_shared::Statement; + use super::*; #[test] @@ -67,7 +69,7 @@ fn stacks_land_from_the_bottom() { } #[test] -fn refuses_divergent_changes() { +fn refuses_divergent_and_abandoned_changes() { let repo = Repo::new("[targets.main]\nauthority = \"node:queue\"\n"); let first = repo.change_on_main(1, &[("a", "a")]); let base = Base::Acceptance(repo.tip(&TargetName::MAIN).acceptance); @@ -79,6 +81,24 @@ fn refuses_divergent_changes() { .land_change(ChangeId::from_bytes([1; 16]), &main) .unwrap_err(); assert!(matches!(error, LandError::Divergent { .. }), "{error}"); + + let given_up = repo.change_on_main(2, &[("b", "b")]); + let abandon = Statement { + subject: RecordId::Revision(given_up), + kind: Kind::ABANDON, + verdict: None, + issuer: "user:ada".parse().unwrap(), + inputs: None, + payload: None, + supersedes: None, + promoted_from: None, + }; + repo.store.write_all(&[abandon.encode()]).unwrap(); + let error = repo + .queue() + .land_change(ChangeId::from_bytes([2; 16]), &main) + .unwrap_err(); + assert!(matches!(error, LandError::Abandoned(_)), "{error}"); } #[test] @@ -125,3 +145,23 @@ fn concurrent_landings_serialize() { } assert_eq!(repo.main_files().len(), changes.len(), "every file landed"); } + +#[test] +fn only_the_creator_of_a_change_abandons_it() { + let repo = Repo::new("[targets.main]\nauthority = \"node:queue\"\n"); + let revision = repo.change_on_main(1, &[("file", "work")]); + let abandon = |issuer: &str| Statement { + subject: RecordId::Revision(revision), + kind: Kind::ABANDON, + verdict: None, + issuer: issuer.parse().unwrap(), + inputs: None, + payload: None, + supersedes: None, + promoted_from: None, + }; + repo.store + .write_all(&[abandon("user:eve").encode()]) + .unwrap(); + assert!(matches!(repo.land(1)[..], [Landing::Landed { .. }])); +} diff --git a/apps/origin-src/src/queue/tests/conflicts.rs b/apps/origin-src/src/queue/tests/conflicts.rs index 8abd4dc2..73e12709 100644 --- a/apps/origin-src/src/queue/tests/conflicts.rs +++ b/apps/origin-src/src/queue/tests/conflicts.rs @@ -1,6 +1,7 @@ //! Landings that conflict, and what lets them through. use super::*; +use crate::conflict::Conflicted; #[test] fn conflicts_block_until_a_revision_merges() { @@ -26,3 +27,68 @@ fn conflicts_block_until_a_revision_merges() { repo.revision(2, &[two], tip, &[("shared", "one"), ("more", "m")]); assert!(matches!(repo.land(2)[..], [Landing::Landed { .. }])); } + +#[test] +fn unresolved_conflicts_never_land() { + let repo = Repo::new("[targets.main]\nauthority = \"node:queue\"\n"); + let marked = "<<<<<<< a\n=======\n>>>>>>> b\n"; + let revision = repo.change_on_main(1, &[("file", marked)]); + let path = RepoPath::new("file").unwrap(); + let conflicts = |content: &str| { + Conflicts::new(vec![Conflicted { + path: path.clone(), + written: Some(EncodedObject::blob(content.as_bytes()).id()), + }]) + }; + // From someone else, it says nothing about the revision's files. + let foreign = conflicts(marked).statement( + RecordId::Revision(revision), + "user:eve".parse().unwrap(), + None, + ); + // From its author, it does. + let (payload, statement) = conflicts(marked).statement( + RecordId::Revision(revision), + "user:ada".parse().unwrap(), + None, + ); + repo.store + .write_all(&[foreign.0, foreign.1.encode()]) + .unwrap(); + let mut annotations = Annotations::open(&repo.store).unwrap(); + assert_eq!( + annotations + .claims(RecordId::Revision(revision)) + .unwrap() + .len(), + 1 + ); + annotations.issue(&statement, Some(payload)).unwrap(); + annotations = Annotations::open(&repo.store).unwrap(); + assert_eq!( + annotations + .claims(RecordId::Revision(revision)) + .unwrap() + .len(), + 2 + ); + let error = repo + .queue() + .land_change(ChangeId::from_bytes([1; 16]), &TargetName::MAIN) + .unwrap_err(); + assert!( + matches!(&error, LandError::Unresolved { paths, .. } if *paths == [path.clone()]), + "{error}" + ); + + // A revision whose file is no longer what the conflict wrote there + // is resolved, whatever the file holds. + let edited = repo.change_on_main(2, &[("file", "Heading\n=======\n")]); + let (payload, statement) = conflicts(marked).statement( + RecordId::Revision(edited), + "user:ada".parse().unwrap(), + None, + ); + annotations.issue(&statement, Some(payload)).unwrap(); + assert!(matches!(repo.land(2)[..], [Landing::Landed { .. }])); +} diff --git a/apps/origin-src/src/queue/tests/mod.rs b/apps/origin-src/src/queue/tests/mod.rs index 173a3c47..0a5e2c86 100644 --- a/apps/origin-src/src/queue/tests/mod.rs +++ b/apps/origin-src/src/queue/tests/mod.rs @@ -11,6 +11,8 @@ use origin_shared::{ }; use super::*; +use crate::annotations::Annotations; +use crate::conflict::Conflicts; use crate::store::Store; use crate::targets::Head; use crate::tree::tests::build;