Skip to content

Commit

Permalink
Fix regression in the worldstate update_verb which was breaking set_v…
Browse files Browse the repository at this point in the history
…erb_code, etc.
  • Loading branch information
rdaum committed Nov 5, 2023
1 parent 4d5661a commit b0240c1
Showing 1 changed file with 64 additions and 9 deletions.
73 changes: 64 additions & 9 deletions crates/db/src/tb_worldstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,12 @@ impl DbTransaction for TupleBoxTransaction {
uuid: Uuid,
verb_attrs: VerbAttrs,
) -> Result<(), WorldStateError> {
let verbdefs = object_relations::get_composite_value(
&self.tx,
WorldStateRelation::ObjectVerbs,
obj,
uuid,
)
.await
.unwrap_or(VerbDefs::empty());
let Some(verbdefs): Option<VerbDefs> =
object_relations::get_object_value(&self.tx, WorldStateRelation::ObjectVerbs, obj)
.await
else {
return Err(WorldStateError::VerbNotFound(obj, format!("{}", uuid)));
};

let Some(verbdefs) = verbdefs.with_updated(uuid, |ov| {
let names = match &verb_attrs.names {
Expand Down Expand Up @@ -1088,7 +1086,7 @@ mod tests {
use moor_values::model::objects::ObjAttrs;
use moor_values::model::objset::ObjSet;
use moor_values::model::r#match::VerbArgsSpec;
use moor_values::model::verbs::BinaryType;
use moor_values::model::verbs::{BinaryType, VerbAttrs};
use moor_values::model::{CommitResult, WorldStateError};
use moor_values::util::bitenum::BitEnum;
use moor_values::var::objid::Objid;
Expand Down Expand Up @@ -1573,6 +1571,63 @@ mod tests {
assert_eq!(tx.commit().await, Ok(CommitResult::Success));
}

/// Regression test for updating-verbs failing.
#[tokio::test]
async fn test_verb_add_update() {
let db = test_db().await;
let tx = TupleBoxTransaction::new(db);
let oid = tx
.create_object(
None,
ObjAttrs {
owner: Some(NOTHING),
name: Some("test".into()),
parent: Some(NOTHING),
location: Some(NOTHING),
flags: Some(BitEnum::new()),
},
)
.await
.unwrap();
tx.add_object_verb(
oid,
oid,
vec!["test".into()],
vec![],
BinaryType::LambdaMoo18X,
BitEnum::new(),
VerbArgsSpec::this_none_this(),
)
.await
.unwrap();
// resolve the verb to its vh.
let vh = tx.resolve_verb(oid, "test".into(), None).await.unwrap();
assert_eq!(vh.names(), vec!["test"]);
// Verify it's actually on the object when we get verbs.
let verbs = tx.get_verbs(oid).await.unwrap();
assert_eq!(verbs.len(), 1);
assert!(verbs.contains(vh.uuid()));
// update the verb using its uuid, renaming it.
tx.update_verb(
oid,
vh.uuid(),
VerbAttrs {
definer: None,
owner: None,
names: Some(vec!["test2".into()]),
flags: None,
args_spec: None,
binary_type: None,
binary: None,
},
)
.await
.unwrap();
// resolve with the new name.
let vh = tx.resolve_verb(oid, "test2".into(), None).await.unwrap();
assert_eq!(vh.names(), vec!["test2"]);
}

#[tokio::test]
async fn test_transitive_property_resolution() {
let db = test_db().await;
Expand Down

0 comments on commit b0240c1

Please sign in to comment.