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 type { EntityData } from '@entity';
import { describe, expect, it, vi } from 'vitest';
const archive = vi.hoisted(() => vi.fn(async () => true));
vi.mock(
'@app/features/block-agent/queries/change-session-archive-state',
() => ({
changeSessionArchiveState: archive,
})
);
import { makeArchiveSessionAction } from './make-archive-session-action';
const ME = 'macro|[email protected]';
const session = (overrides: Partial<EntityData> = {}) =>
({
type: 'agent_session',
id: 's1',
name: 'Session',
ownerId: ME,
...overrides,
}) as EntityData;
const action = makeArchiveSessionAction({ userId: () => ME });
describe('makeArchiveSessionAction', () => {
it('offers archiving only to the session owner', () => {
expect(action.canExecute(session())).toBe(true);
expect(action.canExecute(session({ ownerId: 'macro|other' }))).toBe(false);
expect(
action.canExecute({ ...session(), type: 'chat' } as EntityData)
).toBe(false);
});
it('archives an active session and unarchives an archived one', async () => {
await action.execute([session()]);
expect(archive).toHaveBeenLastCalledWith('s1', true);
await action.execute([
session({
archivedBy: 'user',
archivedAt: '2026-01-01T00:00:00Z',
} as Partial<EntityData>),
]);
expect(archive).toHaveBeenLastCalledWith('s1', false);
});
});