fix: keep dave chat responsive on llm failures
Some checks failed
Codex Template Compliance / template-compliance (pull_request) Successful in 52s
Build / test-and-image (pull_request) Failing after 1m31s

This commit is contained in:
2026-07-11 18:27:12 +02:00
parent 74579375b3
commit 429114f272
7 changed files with 194 additions and 20 deletions

View File

@@ -117,6 +117,41 @@ test('Telegram transport routes authorized free text as plain-text AI reply', as
assert.equal(sent.body.reply_to_message_id, 11);
});
test('Telegram AI handler failures return short DAVE fallback messages', async () => {
const alerter = new TelegramAlerter({ botToken: 'test-token', chatId: '42' });
const requests = [];
alerter.onMessage(async () => {
throw new Error('The operation was aborted due to timeout');
});
const originalFetch = globalThis.fetch;
globalThis.fetch = async (url, options = {}) => {
requests.push({ url, body: options.body ? JSON.parse(options.body) : null });
if (url.includes('/getUpdates')) {
return {
ok: true,
json: async () => ({
ok: true,
result: [{ update_id: 1, message: { message_id: 10, text: 'Noch da?', chat: { id: 42 } } }],
}),
};
}
return { ok: true, json: async () => ({ ok: true, result: { message_id: requests.length } }) };
};
try {
await alerter._pollUpdates();
} finally {
globalThis.fetch = originalFetch;
}
const sent = requests.filter(request => request.url.includes('/sendMessage'));
assert.equal(sent.length, 2);
assert.match(sent[0].body.text, /Dave bekommt gerade keine stabile Antwort/);
assert.doesNotMatch(sent.map(item => item.body.text).join('\n'), /AI chat failed|Please try again/i);
assert.equal(sent[0].body.reply_to_message_id, 10);
});
test('Telegram conversation delivery strips visible markdown and splits large AI replies', async () => {
const alerter = new TelegramAlerter({ botToken: 'test-token', chatId: '42' });
const requests = [];
@@ -209,8 +244,8 @@ test('Telegram tiered fallback alert is sent as conversational DAVE messages', a
const texts = requests.filter(request => request.url.includes('/sendMessage')).map(request => request.body.text);
assert.ok(texts.length >= 2);
assert.match(texts[0], /^\[DAVE \/\/ HINWEIS\]/);
assert.doesNotMatch(texts.join('\n'), /CRUCIX ROUTINE|Confidence:|Direction:|Cross-correlation:|Werkzeuge|Tools used/);
assert.match(texts[0], /^Kurzer Hinweis:/);
assert.doesNotMatch(texts.join('\n'), /\[DAVE \/\/|CRUCIX ROUTINE|Confidence:|Direction:|Cross-correlation:|Werkzeuge|Tools used/);
for (const text of texts) assert.ok(text.length <= 380, `alert chunk too long: ${text.length}`);
});