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::event::Truncation;
fn tool_call(call_id: &str, status: &str) -> CursorEvent {
CursorEvent::ToolCall(ToolCallEvent {
call_id: call_id.to_owned(),
name: "run_terminal_cmd".to_owned(),
status: Some(status.to_owned()),
args: None,
result: None,
truncated: Truncation::default(),
})
}
#[test]
fn a_call_left_running_is_closed_as_failed() {
let mut machine = TranslateMachine::new();
machine.push(tool_call("call-1", "running"));
let updates = machine.close_open_calls();
assert_eq!(updates.len(), 1);
let SessionUpdate::ToolCallUpdate(update) = &updates[0] else {
panic!("expected a tool_call_update, got {updates:?}");
};
assert_eq!(&*update.tool_call_id.0, "call-1");
assert_eq!(update.fields.status, Some(ToolCallStatus::Failed));
}
#[test]
fn a_call_already_completed_is_not_closed_again() {
let mut machine = TranslateMachine::new();
machine.push(tool_call("call-1", "running"));
machine.push(tool_call("call-1", "completed"));
assert!(machine.close_open_calls().is_empty());
}
#[test]
fn only_calls_still_open_are_closed() {
let mut machine = TranslateMachine::new();
machine.push(tool_call("call-1", "running"));
machine.push(tool_call("call-2", "running"));
machine.push(tool_call("call-1", "completed"));
let updates = machine.close_open_calls();
assert_eq!(updates.len(), 1);
let SessionUpdate::ToolCallUpdate(update) = &updates[0] else {
panic!("expected a tool_call_update, got {updates:?}");
};
assert_eq!(&*update.tool_call_id.0, "call-2");
}
#[test]
fn closing_drains_so_a_second_call_finds_nothing_left() {
let mut machine = TranslateMachine::new();
machine.push(tool_call("call-1", "running"));
assert_eq!(machine.close_open_calls().len(), 1);
assert!(machine.close_open_calls().is_empty());
}
fn result(pr_url: Option<&str>) -> CursorEvent {
use crate::domain::event::{GitBranch, GitState};
use crate::domain::model::{CursorRunId, RunStatus};
CursorEvent::Result {
run_id: CursorRunId::new("run-1".to_owned()),
status: RunStatus::Finished,
text: Some("done".to_owned()),
duration_ms: Some(1),
git: Some(GitState {
branches: vec![GitBranch {
repo_url: "github.com/macro-inc/macro".to_owned(),
branch: Some("cursor/fix-1234".to_owned()),
pr_url: pr_url.map(str::to_owned),
}],
}),
}
}
#[test]
fn a_result_with_a_pull_request_announces_it_once() {
let mut machine = TranslateMachine::new();
let url = "https://github.com/macro-inc/macro/pull/6303";
let updates = machine.push(result(Some(url)));
assert!(
updates.is_empty(),
"PRs are host operations, not ACP metadata"
);
assert_eq!(machine.pull_request_url(), Some(url));
// The next run restates the same branches; the client heard already.
assert!(machine.push(result(Some(url))).is_empty());
}
#[test]
fn a_result_without_a_pull_request_announces_nothing() {
let mut machine = TranslateMachine::new();
assert!(machine.push(result(None)).is_empty());
assert_eq!(
machine
.working_branches()
.get("https://github.com/macro-inc/macro")
.map(String::as_str),
Some("cursor/fix-1234"),
);
let mut without_branch = result(None);
if let CursorEvent::Result { git: Some(git), .. } = &mut without_branch {
git.branches[0].branch = None;
}
machine.push(without_branch);
assert_eq!(
machine
.working_branches()
.get("https://github.com/macro-inc/macro")
.map(String::as_str),
Some("cursor/fix-1234"),
"missing provider facts must not erase the latest known branch",
);
}