fix ai insight
CI / lint-and-test (push) Canceled after 0s

This commit is contained in:
Alberto-Audrix committed 2026-08-28 14:22:33 +07:00
1 parent 333b1cf370
commit 01b3178bc6
7 files changed
+333 -23

No files matched your search

+35
View File
@@ -53,3 +53,38 @@ TINDAKAN:
expect(parseAiResult('maaf, saya tidak bisa menjawab')).toBeNull();
});
});
/**
* The second habit, observed verbatim from qwen2.5:7b on the counting card:
* a complete answer whose last string value never gets its closing quote. The
* reply below is trimmed from a real capture — the TINDAKAN line ends at "]"
* and goes straight to the closing brace.
*/
describe('parseAiResult — balasan yang kutipnya tidak ditutup', () => {
const unterminated = `{
"kesimpulan": "Mortalitas kumulatif 9,91% (2.477 ekor) di atas standar CP 707 (5,75%).",
"insight": "PENYEBAB:
1. Suhu di atas target CP 707 (22°C) selama 36 hari, terparah pada hari ke-42. [Terbukti dari data]
TINDAKAN:
1. Lakukan pemeriksaan rutin program vaksinasi. [Dugaan — perlu dicek: Periksa riwayat penyakit]
}`;
it('memperbaikinya alih-alih membuang seluruh jawaban', () => {
const parsed = parseAiResult(unterminated);
expect(parsed).not.toBeNull();
expect(parsed?.kesimpulan).toContain('9,91%');
expect(parsed?.insight).toContain('PENYEBAB:');
// The last line must survive intact, without the stray brace.
expect(parsed?.insight).toContain('Periksa riwayat penyakit]');
expect(parsed?.insight).not.toContain('}');
});
it('tidak mengubah balasan yang kutipnya sudah benar', () => {
const wellFormed = `{"kesimpulan":"Mortalitas 2,68%.","insight":"PENYEBAB:
1. Suhu 34°C di hari ke-3."}`;
const parsed = parseAiResult(wellFormed);
expect(parsed?.kesimpulan).toBe('Mortalitas 2,68%.');
expect(parsed?.insight).toBe('PENYEBAB:\n1. Suhu 34°C di hari ke-3.');
});
});