69 lines
4.5 KiB
TypeScript
69 lines
4.5 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { weatherFollowUpHint } from '../src/gateway/chat/followup-hints';
|
|
|
|
const H = [{ role: 'user', content: '현풍 지금까지 강수량' }, { role: 'assistant', content: '0mm입니다' }];
|
|
|
|
test('"내일 가지" 오타 + 직전 지역 이어받기', () => {
|
|
const h = weatherFollowUpHint('내일 가지 예상 강수량은?', H)!;
|
|
assert.match(h, /까지/); assert.match(h, /현풍/);
|
|
});
|
|
test('정상 "까지"는 오타 힌트 없음, 지역 이어받기만', () => {
|
|
const h = weatherFollowUpHint('내일까지 강수량은?', H)!;
|
|
assert.doesNotMatch(h, /typo/); assert.match(h, /현풍/);
|
|
});
|
|
test('날씨 맥락이 없으면 지역 힌트 없음', () => {
|
|
assert.equal(weatherFollowUpHint('내일 비 와?', [{ role: 'user', content: '파스타 맛집' }]), null);
|
|
});
|
|
test('날씨 질문이 아니면 null', () => assert.equal(weatherFollowUpHint('내일 가지 볶음 레시피', H), null));
|
|
test('긴 질문은 건드리지 않음', () => assert.equal(weatherFollowUpHint('내일 구미와 서울과 부산과 대구와 광주와 대전의 날씨와 기온과 강수량을 모두 자세히 비교해서 알려줘', H), null));
|
|
test('"가지"가 채소면 오타로 보지 않음', () => assert.equal(weatherFollowUpHint('가지 키우기 좋은 날씨야?', []), null));
|
|
|
|
test('"내일까지 강수량"은 누적 힌트', () => assert.match(weatherFollowUpHint('내일까지 현풍 강수량은?', [])!, /CUMULATIVE/));
|
|
test('오타 "내일 가지 강수량"도 누적 힌트', () => assert.match(weatherFollowUpHint('내일 가지 예상 강수량은?', [])!, /CUMULATIVE/));
|
|
test('"내일 강수량"(까지 없음)은 누적 힌트 없음', () => assert.equal(weatherFollowUpHint('내일 강수량은?', []), null));
|
|
|
|
const HW = [{ role: 'user', content: '오늘 세월에 비가 많이 왔나?' }, { role: 'assistant', content: '찾지 못했습니다' }];
|
|
test('"아니 서울" → 장소 정정 힌트', () => { const h = weatherFollowUpHint('아니 서울', HW)!; assert.match(h, /"서울"/); assert.match(h, /weather_kma/); });
|
|
test('"부산으로" / "서울은?" → 정정 힌트', () => { assert.match(weatherFollowUpHint('부산으로', HW)!, /"부산"/); assert.match(weatherFollowUpHint('서울은?', HW)!, /"서울"/); });
|
|
test('날씨 맥락 없으면 정정 힌트 없음', () => assert.equal(weatherFollowUpHint('아니 서울', [{ role: 'user', content: '파스타 맛집' }]), null));
|
|
test('"고마워" 같은 짧은 응답은 제외', () => { assert.equal(weatherFollowUpHint('고마워', HW), null); assert.equal(weatherFollowUpHint('알겠어요', HW), null); });
|
|
|
|
test('history 끝에 현재 메시지가 이미 들어 있어도 직전 날씨 질문을 찾는다', () => {
|
|
const h = weatherFollowUpHint('아니 서울', [...HW, { role: 'user', content: '아니 서울' }])!;
|
|
assert.match(h, /"서울"/);
|
|
});
|
|
|
|
test('이미 내린 비(이번 비 누적/어제 온 비) → current 실황을 쓰라는 힌트', () => {
|
|
for (const q of ['현풍 이번 비 누적 강수량은?', '어제 온 비', '지금까지 온 비는?', '비 얼마나 왔어']) {
|
|
const h = weatherFollowUpHint(q, H);
|
|
assert.ok(h && /type="past"/.test(h) && /type="current"/.test(h), q);
|
|
}
|
|
});
|
|
|
|
test('앞으로 올 비·무관한 말에는 과거 비 힌트가 붙지 않는다', () => {
|
|
for (const q of ['내일 비 올까', '이번 주말 비 예보', '고마워']) {
|
|
const h = weatherFollowUpHint(q, H);
|
|
assert.ok(!h || !/ALREADY fell/.test(h), q);
|
|
}
|
|
});
|
|
|
|
import { describe } from 'node:test';
|
|
import { currencyFollowUpHint } from '../src/gateway/chat/followup-hints';
|
|
|
|
describe('currencyFollowUpHint', () => {
|
|
test('직전 답의 달러 금액을 환산하라고 한다', () => {
|
|
const h = currencyFollowUpHint('원으로는 얼마나 되지?', '| Dillon | 월 임대료 중앙값 약 $1,000 |');
|
|
assert.match(String(h), /exchange_rate\(from="USD", to="KRW", amounts=\[1000\]\)/);
|
|
assert.match(String(h), /do not ask which amount/);
|
|
});
|
|
test('범위는 양 끝 모두', () => {
|
|
const h = currencyFollowUpHint('한달에 300 만원 정도란 거지?', '2베드룸은 월 $1,600~2,400 선입니다.');
|
|
assert.match(String(h), /amounts=\[1600, 2400\]/);
|
|
});
|
|
test('외화 금액이 없거나 원화를 묻지 않으면 없음', () => {
|
|
assert.equal(currencyFollowUpHint('원으로는 얼마나 되지?', '보즈먼은 집값이 높습니다.'), null);
|
|
assert.equal(currencyFollowUpHint('비싸군..', '중간가 $650,000'), null);
|
|
});
|
|
});
|