Skip to content

Commit

Permalink
fix tests, now that we know they're broken
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbanana committed Mar 16, 2024
1 parent a1fda11 commit 15d230d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
29 changes: 21 additions & 8 deletions src-tauri/src/gui_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl WorkspaceSession<'_> {

pub fn evaluate_revset_expr<'op>(&'op self, revset_expr: Rc<RevsetExpression>) -> Result<Box<dyn Revset + 'op>, RevsetError> {
let resolved_expression =
revset_expr.resolve_user_expression(self.operation.repo.as_ref(), &self.resolver())?;
revset_expr.resolve_user_expression(self.operation.repo.as_ref(), &self.resolver())?;
let revset = resolved_expression.evaluate(self.operation.repo.as_ref())?;
Ok(revset)
}
Expand Down Expand Up @@ -260,7 +260,12 @@ impl WorkspaceSession<'_> {
// policy: some commands try to operate on a change in order to preserve visual identity, but
// can fall back to operating on the commit described by the change at the time of the gesture
pub fn resolve_optional_id(&self, id: &RevId) -> Result<Option<Commit>, RevsetError> {
let change_revset = self.evaluate_revset_str(&id.change.hex)?;
let change_revset = match self.evaluate_revset_str(&id.change.hex) {
Ok(revset) => revset,
Err(RevsetError::Resolution(RevsetResolutionError::NoSuchRevision { .. })) => return Ok(None),
Err(err) => return Err(err)
};

let mut change_iter = change_revset.as_ref().iter().commits(self.operation.repo.store()).fuse();
match (change_iter.next(), change_iter.next()) {
(Some(commit), None) => Ok(Some(commit?)),
Expand All @@ -277,18 +282,26 @@ impl WorkspaceSession<'_> {
}

// policy: most commands prefer to operate on a change and will fail if the change has become ambiguous
pub fn resolve_optional_change(&self, id: &messages::ChangeId) -> Result<Option<Commit>, RevsetError> {
let revset = self.evaluate_revset_str(&id.hex)?;
pub fn resolve_optional_change(&self, id: &messages::ChangeId) -> Result<Option<Commit>, RevsetError> {
let revset = match self.evaluate_revset_str(&id.hex) {
Ok(revset) => revset,
Err(RevsetError::Resolution(RevsetResolutionError::NoSuchRevision { .. })) => return Ok(None),
Err(err) => return Err(err)
};

self.resolve_optional(revset)
}

// policy: enforces that the requested change maps only to the expected commit
pub fn resolve_single_change(&self, id: &RevId) -> Result<Commit, RevsetError> {
match self.resolve_optional_change(&id.change)? {
Some(commit) => if commit.id().hex().starts_with(&id.commit.prefix) {
Ok(commit)
} else {
Err(RevsetError::Other(anyhow!(r#""{}" didn't resolve to the expected commit {}"#, id.change.prefix, id.commit.prefix)))
Some(commit) => {
let resolved_id = commit.id();
if resolved_id == self.wc_id() || resolved_id.hex().starts_with(&id.commit.prefix) {
Ok(commit)
} else {
Err(RevsetError::Other(anyhow!(r#""{}" didn't resolve to the expected commit {}"#, id.change.prefix, id.commit.prefix)))
}
}
None => Err(RevsetError::Other(anyhow!(r#""{}" didn't resolve to any revisions"#, id.change.prefix)))
}
Expand Down
25 changes: 15 additions & 10 deletions src-tauri/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ mod revs {
use super::mkid;

pub fn working_copy() -> RevId {
mkid("kppkuplp", "a625ed5a")
mkid("kppkuplp", "a625ed5aa71d7c68b98b1d1521b2e1cbd0c54a0d")
}

pub fn main_branch() -> RevId {
mkid("mnkoropy", "87e9c6c0")
mkid("mnkoropy", "87e9c6c03e1b727ff712d962c03b32fffb704bc0")
}

pub fn conflict_branch() -> RevId {
mkid("nwrnuwyp", "880abeef")
mkid("nwrnuwyp", "880abeefdd3ac344e2a0901c5f486d02d34053da")
}

pub fn resolve_conflict() -> RevId {
mkid("rrxroxys", "db297552443bcafc0f0715b7ace7fb4488d7954d")
}
}

Expand All @@ -58,7 +62,7 @@ mod session {
use crate::{
gui_util::WorkerSession,
messages::{LogPage, RepoConfig, RevResult},
tests::mkid,
tests::{mkid, revs},
worker::{Session, SessionEvent},
};

Expand Down Expand Up @@ -279,8 +283,6 @@ mod session {
let (tx_rev, rx_rev) = channel::<Result<RevResult>>();
let (tx_page2, rx_page2) = channel::<Result<LogPage>>();

let wc = mkid("kppkuplp", "a625ed5a");

tx.send(SessionEvent::OpenWorkspace {
tx: tx_load,
wd: Some(repo.path().to_owned()),
Expand All @@ -289,7 +291,10 @@ mod session {
tx: tx_page1,
query: "all()".to_owned(),
})?;
tx.send(SessionEvent::QueryRevision { tx: tx_rev, id: wc })?;
tx.send(SessionEvent::QueryRevision {
tx: tx_rev,
id: revs::working_copy(),
})?;
tx.send(SessionEvent::QueryLogNextPage { tx: tx_page2 })?;
tx.send(SessionEvent::EndSession)?;

Expand Down Expand Up @@ -607,7 +612,8 @@ mod mutation {
matches!(rev, RevResult::Detail { header, changes, .. } if header.description.lines[0] == "" && changes.len() == 0)
);

fs::write(repo.path().join("new.txt"), []).unwrap();
fs::write(repo.path().join("new.txt"), []).unwrap(); // changes the WC commit

DescribeRevision {
id: revs::working_copy(),
new_description: "wip".to_owned(),
Expand All @@ -626,7 +632,6 @@ mod mutation {
#[test]
fn move_changes() -> Result<()> {
let repo = mkrepo();
let child = mkid("rrxroxys", "db297552"); // resolves conflict

let mut session = WorkerSession::default();
let mut ws = session.load_directory(repo.path())?;
Expand All @@ -635,7 +640,7 @@ mod mutation {
assert!(matches!(parent_rev, RevResult::Detail { header, .. } if header.has_conflict));

let result = MoveChanges {
from_id: child,
from_id: revs::resolve_conflict(),
to_id: revs::conflict_branch().commit,
paths: vec![],
}
Expand Down

0 comments on commit 15d230d

Please sign in to comment.