Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

9.4 KB
Raw Blame
#[allow(unused_imports)]
use super::*;
use ai_toolset::schema::generate_validated_input_schema;

#[test]
fn test_get_entity_properties_schema_validation() {
    let result = generate_validated_input_schema::<GetEntityProperties>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "GetEntityProperties");
    assert!(
        validated.description.contains("Get all properties"),
        "Description should contain expected text"
    );
}

#[test]
fn test_set_entity_property_schema_validation() {
    let result = generate_validated_input_schema::<SetEntityProperty>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "SetEntityProperty");
    assert!(
        validated.description.contains("Set or update a property"),
        "Description should contain expected text"
    );
}

#[test]
fn test_set_entity_property_schema_documents_delta_options() {
    let validated = generate_validated_input_schema::<SetEntityProperty>().unwrap();
    let schema_json = serde_json::to_string(&validated.schema).unwrap();
    assert!(
        schema_json.contains("add_option_ids"),
        "schema should expose add_option_ids"
    );
    assert!(
        schema_json.contains("remove_option_ids"),
        "schema should expose remove_option_ids"
    );
    assert!(
        validated.description.contains("atomically"),
        "description should steer to atomic add/remove over full replace"
    );
}

#[test]
fn test_bulk_set_entity_property_options_schema_validation() {
    let result = generate_validated_input_schema::<BulkSetEntityPropertyOptions>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "BulkSetEntityPropertyOptions");
    assert!(
        validated.description.contains("many entities"),
        "Description should explain the multi-entity apply"
    );

    let schema_json = serde_json::to_string(&validated.schema).unwrap();
    assert!(
        schema_json.contains("entities")
            && schema_json.contains("add_option_ids")
            && schema_json.contains("remove_option_ids"),
        "schema should expose entities and the add/remove option deltas"
    );
}

#[test]
fn test_list_tags_schema_validation() {
    let result = generate_validated_input_schema::<ListTags>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "ListTags");
    assert!(
        validated.description.contains("personal tag set"),
        "Description should explain the personal/team tag sets"
    );
    assert!(
        validated.description.contains("SetEntityProperty"),
        "Description should point at SetEntityProperty for applying tags"
    );
}

#[test]
fn test_create_tag_schema_validation() {
    let result = generate_validated_input_schema::<CreateTag>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "CreateTag");
    assert!(
        validated.description.contains("Create a new tag"),
        "Description should explain that it creates a new tag"
    );

    let schema_json = serde_json::to_string(&validated.schema).unwrap();
    assert!(
        schema_json.contains("label") && schema_json.contains("color"),
        "schema should expose label and color"
    );
    assert!(
        schema_json.contains("scope"),
        "schema should expose the personal/team scope"
    );
}

#[test]
fn test_edit_tag_schema_validation() {
    let result = generate_validated_input_schema::<EditTag>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "EditTag");
    assert!(
        validated.description.contains("Rename or recolor"),
        "Description should explain rename/recolor"
    );

    let schema_json = serde_json::to_string(&validated.schema).unwrap();
    assert!(
        schema_json.contains("label") && schema_json.contains("color"),
        "schema should expose label and color"
    );
    assert!(
        schema_json.contains("property_definition_id"),
        "schema should require the tag set's property_definition_id"
    );
}

#[test]
fn test_delete_tag_schema_validation() {
    let result = generate_validated_input_schema::<DeleteTag>();
    assert!(result.is_ok(), "{:?}", result);

    let validated = result.unwrap();
    assert_eq!(validated.name, "DeleteTag");
    assert!(
        validated.description.contains("Permanently delete a tag"),
        "Description should explain the destructive delete"
    );

    let schema_json = serde_json::to_string(&validated.schema).unwrap();
    assert!(
        schema_json.contains("property_definition_id"),
        "schema should require the tag set's property_definition_id"
    );
}

// run `cargo test -p properties inbound::toolset::test::print_get_input_schema -- --nocapture --include-ignored`
#[test]
#[ignore = "prints the input schema"]
fn print_get_input_schema() {
    let schema = generate_validated_input_schema::<GetEntityProperties>()
        .unwrap()
        .schema;
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

// run `cargo test -p properties inbound::toolset::test::print_set_input_schema -- --nocapture --include-ignored`
#[test]
#[ignore = "prints the input schema"]
fn print_set_input_schema() {
    let schema = generate_validated_input_schema::<SetEntityProperty>()
        .unwrap()
        .schema;
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

// run `cargo test -p properties inbound::toolset::test::print_get_output_schema -- --nocapture --include-ignored`
#[test]
#[ignore = "prints the output schema"]
fn print_get_output_schema() {
    let schema = schemars::schema_for!(GetEntityPropertiesResponse);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

// run `cargo test -p properties inbound::toolset::test::print_set_output_schema -- --nocapture --include-ignored`
#[test]
#[ignore = "prints the output schema"]
fn print_set_output_schema() {
    let schema = schemars::schema_for!(SetEntityPropertyResponse);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

mod entity_type_aliases {
    use super::super::get_entity_properties::{ToolEntityType, ToolPropertyTargetEntityType};
    use super::*;

    /// ListEntities and search report email threads as `email`, so the
    /// property tools accept that spelling alongside the canonical `thread`.
    #[test]
    fn set_entity_property_accepts_email_as_thread() {
        let tool: SetEntityProperty = serde_json::from_value(serde_json::json!({
            "entity_id": "01a09073-8a65-71f0-84b6-5ae47da19367",
            "entity_type": "email",
            "property_definition_id": "01a08770-8c51-7299-a31b-8569d2959337",
            "add_option_ids": ["01a09083-9c93-7732-9ffc-8f2b45f508bb"],
        }))
        .expect("email should deserialize as a thread target");

        assert!(matches!(
            tool.entity_type,
            ToolPropertyTargetEntityType::Thread
        ));
        assert_eq!(
            model_entity::EntityType::from(tool.entity_type),
            model_entity::EntityType::EmailThread
        );
    }

    #[test]
    fn bulk_set_entity_property_options_accepts_email_and_email_thread() {
        let tool: BulkSetEntityPropertyOptions = serde_json::from_value(serde_json::json!({
            "entities": [
                { "entity_id": "01a09073-8a65-71f0-84b6-5ae47da19367", "entity_type": "email" },
                { "entity_id": "01a0905a-3ab3-7c60-83fa-6987af8935fd", "entity_type": "email_thread" },
                { "entity_id": "01a08e26-fd59-7120-8a4b-594e492eb054", "entity_type": "thread" },
            ],
            "property_definition_id": "01a08770-8c51-7299-a31b-8569d2959337",
            "add_option_ids": ["01a09083-9c93-7732-9ffc-8f2b45f508bb"],
        }))
        .expect("email spellings should deserialize as thread targets");

        assert_eq!(tool.entities.len(), 3);
        assert!(
            tool.entities
                .iter()
                .all(|entity| matches!(entity.entity_type, ToolPropertyTargetEntityType::Thread))
        );
    }

    #[test]
    fn get_entity_properties_accepts_email_as_thread() {
        let tool: GetEntityProperties = serde_json::from_value(serde_json::json!({
            "entity_id": "01a09073-8a65-71f0-84b6-5ae47da19367",
            "entity_type": "email",
        }))
        .expect("email should deserialize as a thread target");

        assert!(matches!(
            tool.entity_type,
            ToolPropertyTargetEntityType::Thread
        ));
    }

    #[test]
    fn entity_ref_accepts_email_as_thread() {
        let tool: SetEntityProperty = serde_json::from_value(serde_json::json!({
            "entity_id": "01a09073-8a65-71f0-84b6-5ae47da19367",
            "entity_type": "document",
            "property_definition_id": "01a08770-8c51-7299-a31b-8569d2959337",
            "entity_ref": { "entityType": "email", "entityId": "01a0905a-3ab3-7c60-83fa-6987af8935fd" },
        }))
        .expect("email should deserialize as a thread reference");

        let entity_ref = tool.entity_ref.expect("entity_ref should be set");
        assert!(matches!(entity_ref.entity_type, ToolEntityType::Thread));
        assert_eq!(
            models_properties::EntityType::from(entity_ref.entity_type),
            models_properties::EntityType::Thread
        );
    }
}