Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
use super::*;
use crate::domain::model::{McpHeader, McpServer, McpTransport};
/// The MCP selection must serialize to the shape `POST /v1/agents` documents:
/// `name`, a `type` discriminator, `url`, and headers as an object.
#[test]
fn mcp_servers_serialize_to_the_documented_shape() {
let server = McpServer {
name: "docs".to_owned(),
transport: McpTransport::Sse,
url: "https://mcp.example.com/sse".to_owned(),
headers: vec![McpHeader {
name: "Authorization".to_owned(),
value: "Bearer t".to_owned(),
}],
};
assert_eq!(
serde_json::to_value(McpServerSelection::from(&server)).expect("serializes"),
serde_json::json!({
"name": "docs",
"type": "sse",
"url": "https://mcp.example.com/sse",
"headers": { "Authorization": "Bearer t" },
})
);
}
/// A server with no headers omits the key rather than sending an empty
/// object.
#[test]
fn headerless_mcp_servers_omit_the_key() {
let server = McpServer {
name: "plain".to_owned(),
transport: McpTransport::Http,
url: "https://mcp.example.com".to_owned(),
headers: Vec::new(),
};
assert_eq!(
serde_json::to_value(McpServerSelection::from(&server)).expect("serializes"),
serde_json::json!({
"name": "plain",
"type": "http",
"url": "https://mcp.example.com",
})
);
}
/// An agent created without MCP servers omits the field entirely, so Cursor's
/// own configuration is left alone rather than overridden with an empty list.
#[test]
fn no_mcp_servers_means_no_field() {
let request = CreateAgentRequest {
prompt: PromptBody {
text: "hi".to_owned(),
images: Vec::new(),
},
repos: Vec::new(),
model: None,
mcp_servers: Vec::new(),
auto_create_pr: false,
};
let body = serde_json::to_value(&request).expect("serializes");
assert!(body.get("mcpServers").is_none(), "got {body}");
}
/// A repo agent asks Cursor for a pull request under Cursor's own spelling,
/// `autoCreatePR`; camel case alone would send `autoCreatePr` and be ignored.
#[test]
fn a_repo_agent_asks_for_a_pull_request() {
let request = CreateAgentRequest {
prompt: PromptBody {
text: "hi".to_owned(),
images: Vec::new(),
},
repos: vec![RepoSelection {
url: "https://github.com/macro-inc/macro".to_owned(),
starting_ref: "main".to_owned(),
}],
model: None,
mcp_servers: Vec::new(),
auto_create_pr: true,
};
let body = serde_json::to_value(&request).expect("serializes");
assert_eq!(body.get("autoCreatePR"), Some(&serde_json::json!(true)));
}
/// Prompt images go out as base64 `data` plus `mimeType`, which is the shape
/// Cursor requires when the bytes are already in hand.
#[test]
fn prompt_images_serialize_as_data_and_mime_type() {
let body = PromptBody {
text: "look".to_owned(),
images: vec![PromptImage {
data: "aW1n".to_owned(),
mime_type: "image/png".to_owned(),
}],
};
assert_eq!(
serde_json::to_value(body).expect("serializes"),
serde_json::json!({
"text": "look",
"images": [{ "data": "aW1n", "mimeType": "image/png" }]
})
);
}
/// An empty image list is omitted, so a text prompt sends no `images` key.
#[test]
fn a_text_prompt_omits_images() {
let body = PromptBody {
text: "look".to_owned(),
images: Vec::new(),
};
let value = serde_json::to_value(body).expect("serializes");
assert!(value.get("images").is_none(), "got {value}");
}
/// A repo-less agent has nothing to open a pull request against, so the field
/// is omitted rather than sent as false.
#[test]
fn a_repoless_agent_omits_the_pull_request_flag() {
let request = CreateAgentRequest {
prompt: PromptBody {
text: "hi".to_owned(),
images: Vec::new(),
},
repos: Vec::new(),
model: None,
mcp_servers: Vec::new(),
auto_create_pr: false,
};
let body = serde_json::to_value(&request).expect("serializes");
assert!(body.get("autoCreatePR").is_none(), "got {body}");
}
/// The list response reads a documented page: items plus a `nextCursor` that
/// is absent — not null — on the last page.
#[test]
fn agent_pages_deserialize_with_and_without_a_next_cursor() {
let page: ListAgentsResponse = serde_json::from_value(serde_json::json!({
"items": [{
"id": "bc-1",
"name": "Add README",
"status": "ACTIVE",
"url": "https://cursor.com/agents/bc-1",
"createdAt": "2026-04-13T18:30:00.000Z",
}],
"nextCursor": "bc-2",
}))
.expect("page with cursor");
assert_eq!(page.items.len(), 1);
assert_eq!(page.items[0].name, "Add README");
assert_eq!(page.next_cursor.as_deref(), Some("bc-2"));
let last: ListAgentsResponse =
serde_json::from_value(serde_json::json!({ "items": [] })).expect("last page");
assert!(last.next_cursor.is_none());
}
/// A service-account `GET /v1/me` body has no user fields; a user key's does.
/// Both must read.
#[test]
fn me_reads_user_and_service_account_shapes() {
let user: MeResponse = serde_json::from_value(serde_json::json!({
"apiKeyName": "wolf's key",
"userId": 42,
"createdAt": "2026-04-13T18:30:00.000Z",
"userEmail": "[email protected]",
}))
.expect("user key");
assert_eq!(user.user_email.as_deref(), Some("[email protected]"));
let service: MeResponse = serde_json::from_value(serde_json::json!({
"apiKeyName": "Production Service Account",
"createdAt": "2026-04-13T18:30:00.000Z",
}))
.expect("service-account key");
assert!(service.user_email.is_none());
}
/// Artifact fields arrive camel-cased, and an agent that has written none may
/// answer with a bare object rather than an empty `items` array.
#[test]
fn artifact_listings_read_camel_case_and_an_absent_items_key() {
let listing: ListArtifactsResponse = serde_json::from_value(serde_json::json!({
"items": [{
"path": "artifacts/mobile_selection_menu_formatting_walkthrough.mp4",
"sizeBytes": 48_500_000_u64,
"updatedAt": "2026-04-13T18:45:00.000Z",
}],
}))
.expect("a documented listing");
assert_eq!(listing.items[0].size_bytes, 48_500_000);
assert_eq!(listing.items[0].updated_at, "2026-04-13T18:45:00.000Z");
let empty: ListArtifactsResponse =
serde_json::from_value(serde_json::json!({})).expect("no artifacts yet");
assert!(empty.items.is_empty());
}
/// The download body is the presigned url plus its expiry, both camel-cased.
#[test]
fn an_artifact_download_reads_the_documented_body() {
let download: ArtifactDownloadResponse = serde_json::from_value(serde_json::json!({
"url": "https://cloud-agent-artifacts.s3.us-east-1.amazonaws.com/a?sig=1",
"expiresAt": "2026-04-13T19:00:00.000Z",
}))
.expect("a documented download");
assert!(download.url.contains("cloud-agent-artifacts"));
assert_eq!(download.expires_at, "2026-04-13T19:00:00.000Z");
}