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
import { describe, expect, it } from 'vitest';
import {
applySuggestions,
fieldsSchema,
type Intent,
inferIntent,
missingFields,
} from './input';
import { resolveRecipients } from './recipients';
describe('inference decisions', () => {
it('starts with the strongest candidate even with low or closely matched scores', () => {
expect(
inferIntent([
{ intent: 'task', score: 0.8 },
{ intent: 'note', score: 0.6 },
])
).toBe('task');
expect(inferIntent([{ intent: 'task', score: 0.39 }])).toBe('task');
expect(
inferIntent([
{ intent: 'task', score: 0.95 },
{ intent: 'calendar', score: 0.9 },
])
).toBe('task');
expect(inferIntent([])).toBeUndefined();
});
it('clears old machine suggestions but preserves manually cleared fields', () => {
expect(
applySuggestions({ subject: 'old', title: '' }, ['title'], {
subject: null,
title: 'new',
recipients: [],
guests: [],
})
).toMatchObject({ subject: '', title: '' });
});
it.each<Intent>([
'ai',
'search',
'email',
'note',
'task',
'calendar',
'message',
])('accepts a complete %s snapshot', (intent) => {
expect(
missingFields({
intent,
id: 'id',
text: 'Some content',
fields: fieldsSchema.parse({
title: 'Title',
recipients: '[email protected]',
body: 'Hello',
subject: 'Subject',
start: '2026-10-10T15:00',
end: '2026-10-10T16:00',
}),
})
).toBeUndefined();
});
it('rejects an event ending before it starts', () => {
expect(
missingFields({
intent: 'calendar',
id: 'id',
text: 'Call',
fields: fieldsSchema.parse({
title: 'Call',
start: '2026-10-10T15:00',
end: '2026-10-10T14:00',
}),
})
).toContain('valid start');
});
});
describe('recipient matching', () => {
const people = [
{
id: 'john-a',
label: 'John Adams',
email: '[email protected]',
kind: 'user' as const,
},
{
id: 'john-b',
label: 'John Baker',
email: '[email protected]',
kind: 'user' as const,
},
];
it('requires a choice for ambiguous first names', () => {
expect(resolveRecipients('John', people, true).unresolved).toEqual([
'John',
]);
});
it('resolves a unique first name and exact addresses', () => {
expect(
resolveRecipients('John', people.slice(0, 1), false).recipients
).toEqual(people.slice(0, 1));
expect(
resolveRecipients('[email protected]', people, true).recipients
).toEqual(people.slice(1));
});
it('accepts external email addresses only for email/invites', () => {
expect(
resolveRecipients('[email protected]', [], true).recipients
).toHaveLength(1);
expect(
resolveRecipients('[email protected]', [], false).unresolved
).toHaveLength(1);
});
});
it('uses the shared email validator for inferred external recipients', () => {
for (const address of [
'<[email protected]>',
'[email protected]',
'[email protected].',
]) {
expect(resolveRecipients(address, [], true).unresolved).toEqual([address]);
}
});
it('preserves manually removed recurrence and copy recipients through subsequent predictions', () => {
const config = {
frequency: 'WEEKLY' as const,
interval: 1,
byDay: ['MO' as const],
ends: { kind: 'never' as const },
};
const previous = fieldsSchema.parse({
recurrence: '',
cc: '',
bcc: '[email protected]',
});
expect(
applySuggestions(previous, ['recurrence', 'cc', 'bcc'], {
recurrence: config,
cc: ['Julia'],
bcc: ['[email protected]'],
recipients: [],
guests: [],
})
).toMatchObject({ recurrence: '', cc: '', bcc: '[email protected]' });
expect(
applySuggestions(previous, [], {
recurrence: config,
recipients: [],
guests: [],
}).recurrence
).toBe(JSON.stringify(config));
});
it('allows email delivery to copy recipients without requiring To', () => {
expect(
missingFields({
intent: 'email',
text: 'Send the update',
id: 'id',
fields: fieldsSchema.parse({
subject: 'Update',
body: 'Hello',
bcc: '[email protected]',
}),
})
).toBeUndefined();
});