aboutsummaryrefslogtreecommitdiff
path: root/modules/test/test-ollama-autoconnect.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/test/test-ollama-autoconnect.js')
-rw-r--r--modules/test/test-ollama-autoconnect.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/modules/test/test-ollama-autoconnect.js b/modules/test/test-ollama-autoconnect.js
index b9db4ff..12b0786 100644
--- a/modules/test/test-ollama-autoconnect.js
+++ b/modules/test/test-ollama-autoconnect.js
@@ -59,7 +59,7 @@ const json = (body, okFlag = true) => Promise.resolve({ ok: okFlag, status: okFl
const res = await om.chat('ping');
const text = out.map(o => o.text).join(' | ');
ok('A1 connect is attempted lazily', seen.some(u => u.includes('/api/tags')), seen.join(', '));
- ok('A2 the user sees a connecting hint', /Connecting to Ollama/.test(text), text.slice(0, 160));
+ ok('A2 the user sees a first-use hint', /connecting on first use/.test(text), text.slice(0, 160));
ok('A3 manager is connected after the attempt', om.connected === true);
ok('A4 the message is answered', String(res).includes('pong'), String(res).slice(0, 120));
ok('A5 no "ollamaconnect first" error', !/ollamaconnect first/.test(text), text.slice(0, 200));
@@ -89,6 +89,38 @@ const json = (body, okFlag = true) => Promise.resolve({ ok: okFlag, status: okFl
ok('C1 three concurrent messages probe /api/tags once', tagCalls === 1, 'tagCalls=' + tagCalls);
}
+ // D. a blackholed endpoint must not hang every later message
+ {
+ const { om, out } = mk(() => new Promise(() => {})); // never settles
+ om.connectTimeoutMs = 100;
+ const t0 = Date.now();
+ const res = await om.chat('ping');
+ const ms = Date.now() - t0;
+ const text = out.map(o => o.text).join(' | ');
+ ok('D1 chat settles on a silent endpoint', ms < 3000, ms + 'ms');
+ ok('D2 returns null', res === null, String(res));
+ ok('D3 the timeout is reported', /timed out/.test(text), text.slice(0, 220));
+ ok('D4 _connecting is cleared', om._connecting === null, String(om._connecting));
+ const before = out.length;
+ await om.chat('again');
+ ok('D5 the next message retries the connect', out.length > before, 'lines ' + before + ' -> ' + out.length);
+ }
+
+ // E. an automatic connect must not rewrite the model the user saved
+ {
+ store['webx11_ollama_model'] = 'my-saved-model';
+ const { om, out } = mk((url) => url.includes('/api/tags')
+ ? json({ models: [{ name: 'other-model' }] })
+ : json({ response: 'x', eval_count: 1, prompt_eval_count: 1 }));
+ om.currentModel = 'my-saved-model';
+ await om._ensureConnected();
+ const text = out.map(o => o.text).join(' | ');
+ ok('E1 the saved model survives an auto-connect', om.currentModel === 'my-saved-model', om.currentModel);
+ ok('E2 the stored preference is restored', store['webx11_ollama_model'] === 'my-saved-model', String(store['webx11_ollama_model']));
+ ok('E3 the user is told why', /Keeping your saved model/.test(text), text.slice(0, 200));
+ delete store['webx11_ollama_model'];
+ }
+
if (fails === 0) {
console.log('test-ollama-autoconnect: ' + passes + ' passed, 0 failed');
} else {