agenthub/tests/message-cmd.test.ts

40 lines
1.5 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdtempSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { init } from '../src/cli/commands/init.js';
import { messageRead, inboxMarkRead } from '../src/cli/commands/message.js';
import { createMessage, listInbox } from '../src/core/services/messageService.js';
describe('message commands', () => {
let cwd: string;
beforeEach(async () => {
cwd = mkdtempSync(join(tmpdir(), 'ah-msg-cmd-'));
await init(cwd, { yes: true, projectName: 'test' });
});
afterEach(() => {
rmSync(cwd, { recursive: true, force: true });
});
it('messageRead marks one message as read', () => {
const msg = createMessage(cwd, { from: 'codex', to: 'claude', text: 'done' });
messageRead(cwd, msg.id);
expect(listInbox(cwd, 'claude', { unreadOnly: true })).toHaveLength(0);
expect(listInbox(cwd, 'claude')).toMatchObject([{ id: msg.id, status: 'read' }]);
});
it('inboxMarkRead bulk-marks unread alias messages for architect', () => {
createMessage(cwd, { from: 'windows-claude', to: 'architect', text: 'ping 1' });
createMessage(cwd, { from: 'codex', to: 'claude', text: 'ping 2' });
expect(listInbox(cwd, 'architect', { unreadOnly: true })).toHaveLength(2);
inboxMarkRead(cwd, { agent: 'architect', unreadOnly: true });
expect(listInbox(cwd, 'architect', { unreadOnly: true })).toHaveLength(0);
expect(listInbox(cwd, 'claude')).toHaveLength(2);
});
});