import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
import { deriveCostSessionTitleFromMessages, resolveCostSessionTitle, truncateCostSessionTitle, } from './derive-cost-session-title';
const suite = createLogicSuite('deriveCostSessionTitle');
const userMsg = (content) => ({ role: 'user', content });
suite('truncateCostSessionTitle keeps first sentence only', () => {
    assert.is(truncateCostSessionTitle('Build a trade blotter. With FX options and limits.'), 'Build a trade blotter');
});
suite('truncateCostSessionTitle caps word count', () => {
    const long = 'one two three four five six seven eight nine ten eleven twelve thirteen fourteen';
    assert.is(truncateCostSessionTitle(long), 'one two three four five six seven eight nine ten…');
});
suite('truncateCostSessionTitle caps character count on one long word', () => {
    const word = 'a'.repeat(80);
    assert.is(truncateCostSessionTitle(word).length, 60);
    assert.ok(truncateCostSessionTitle(word).endsWith('…'));
});
suite('deriveCostSessionTitleFromMessages skips empty and uses first user turn', () => {
    assert.is(deriveCostSessionTitleFromMessages([
        { role: 'assistant', content: 'Hi' },
        { role: 'user', content: '   ' },
        { role: 'user', content: 'Equity options pricer for desk' },
    ]), 'Equity options pricer for desk');
});
suite('resolveCostSessionTitle prefers app title over messages', () => {
    assert.is(resolveCostSessionTitle({
        appTitle: 'fx-trading',
        messages: [userMsg('Something else entirely')],
        headerTitle: 'Genesis Assistant',
    }), 'fx-trading');
});
suite('resolveCostSessionTitle falls back to first user message', () => {
    assert.is(resolveCostSessionTitle({
        messages: [userMsg('Search for recent trades in APAC')],
        headerTitle: 'Genesis Assistant',
    }), 'Search for recent trades in APAC');
});
suite.run();
