Skip to content
← Public packages

@kody/mailroom

Offline-first PWA for your Kody mailbox: sent and received threads, copy-prompt for agents, no send.

src/prompt-text.node.test.ts

51 lines · 1.6 KB · TypeScript
import assert from 'node:assert/strict'
import test from 'node:test'
import { buildMessagePrompt, buildThreadPrompt, textFromMessage } from './prompt-text.ts'
import type { MailMessage } from './types.ts'

const message: MailMessage = {
	id: 'msg-1',
	direction: 'inbound',
	inbox_id: null,
	thread_id: 'thr-1',
	from_address: 'ada@example.com',
	envelope_from: 'ada@example.com',
	to_addresses: ['me@kody.codes'],
	subject: 'Ship it',
	message_id_header: null,
	processing_status: 'stored',
	classification: 'accepted',
	delivery_status: null,
	received_at: '2026-09-02T18:00:00.000Z',
	sent_at: null,
	created_at: '2026-09-02T18:00:00.000Z',
	updated_at: '2026-09-02T18:00:00.000Z',
	cc_addresses: [],
	bcc_addresses: [],
	reply_to_addresses: [],
	in_reply_to_header: null,
	references: [],
	text_body: 'Please review the pull request.',
	html_body: '<p>Please review the pull request.</p>',
	attachments: [],
}

test('copy prompt includes execute example and forbids send', () => {
	const prompt = buildMessagePrompt(message)
	assert.match(prompt, /read-only; do not send/)
	assert.match(prompt, /kody\.emailMessageGet/)
	assert.match(prompt, /msg-1/)
	assert.match(prompt, /Please review the pull request/)
	assert.equal(prompt.toLowerCase().includes('compose'), false)
})

test('thread prompt concatenates messages', () => {
	const prompt = buildThreadPrompt({
		id: 'thr-1',
		subject: 'Ship it',
		messages: [message],
	})
	assert.match(prompt, /Thread id: thr-1/)
	assert.match(prompt, /emailMessageList/)
	assert.equal(textFromMessage({ ...message, text_body: null }).includes('Please review'), true)
})