Files
homeclaw/tests/tool-failure-backstop.test.ts
T

44 lines
2.5 KiB
TypeScript

/**
* tool-failure-backstop — 날씨 도구 전부 실패 + 수치 답 → 교체
* 표본: 2026-10-17 tool-bench E2, gemma4가 오류 응답 뒤 "최고 14도, 최저 4도"를 답한 실제 출력.
*/
import { test, describe } from 'node:test';
import assert from 'node:assert/strict';
import { weatherFabricationReplacement } from '../src/gateway/chat/tool-failure-backstop';
import { isUsableGroundingResult } from '../src/gateway/guards/prompt-gates';
const FAILED = [{ name: 'weather_kma', error: true, result: 'Error: 기상청 API 응답 없음 (timeout)' }];
describe('weatherFabricationReplacement', () => {
test('실패한 도구 + 지어낸 기온 → 교체', () => {
const r = weatherFabricationReplacement('오늘 부산의 날씨는 대체로 맑으며, 최고 기온은 14도, 최저 기온은 4도로 예상됩니다.', FAILED);
assert.ok(r && r.includes('확인할 수 없습니다'));
});
test('error 플래그가 없어도 "Error:" 한 줄이면 실패로 본다', () => {
const r = weatherFabricationReplacement('기온은 21.5℃입니다.', [{ name: 'weather_kma', error: false, result: 'Error: 응답 없음' }]);
assert.ok(r);
});
test('수치 없이 정직하게 실패를 알린 답은 그대로', () => {
assert.equal(weatherFabricationReplacement('기상청 조회에 실패해서 지금은 날씨를 알려드리기 어렵습니다.', FAILED), null);
});
test('도구가 하나라도 성공했으면 손대지 않는다', () => {
const ok = [...FAILED, { name: 'weather_airkorea', error: false, result: '서울 PM2.5 18㎍/㎥ 보통' }];
assert.equal(weatherFabricationReplacement('PM2.5는 18%가 아니라...', ok), null);
});
test('날씨 도구를 안 부른 턴은 건드리지 않는다', () => {
assert.equal(weatherFabricationReplacement('전기차 효율은 15%입니다.', [{ name: 'web_search', error: true, result: 'x' }]), null);
});
test('"정도" 같은 단어는 수치로 보지 않는다', () => {
assert.equal(weatherFabricationReplacement('조회에 실패했습니다. 이 정도로 안내드립니다.', FAILED), null);
});
});
describe('isUsableGroundingResult — Error 한 줄', () => {
test('Error: 로 시작하는 짧은 결과는 근거가 아니다', () => {
assert.equal(isUsableGroundingResult({ error: false, result: 'Error: timeout' }), false);
});
test('정상 결과는 그대로 근거', () => {
assert.equal(isUsableGroundingResult({ error: false, result: '서울 기온 18도 맑음' }), true);
});
});