Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: cover Ollama.app download stall guard through upgradeBackend (#11682)

[._.]/ Adam Eivya951602538fb
diff --git a/server/services/localLlm.js b/server/services/localLlm.js
index a5c9b82d12..fcb30b3479 100644
--- a/server/services/localLlm.js
+++ b/server/services/localLlm.js
@@ -379,7 +379,7 @@ const DOWNLOAD_IDLE_TIMEOUT_MS = 60_000
* aborts after `idleMs` without bytes. `signal` aborts early (client gone).
* Resolves `{ error }` on any failure, `{}` on success — never throws.
*/
-export async function downloadWithStallGuard(url, destPath, signal, { headerMs = DOWNLOAD_HEADER_TIMEOUT_MS, idleMs = DOWNLOAD_IDLE_TIMEOUT_MS } = {}) {
+async function downloadWithStallGuard(url, destPath, signal, { headerMs = DOWNLOAD_HEADER_TIMEOUT_MS, idleMs = DOWNLOAD_IDLE_TIMEOUT_MS } = {}) {
const ac = new AbortController()
let stall = null
let timer = null
diff --git a/server/services/localLlm.test.js b/server/services/localLlm.test.js
index 072ae83491..0476fede6f 100644
--- a/server/services/localLlm.test.js
+++ b/server/services/localLlm.test.js
@@ -851,57 +851,75 @@ describe('localLlm', () => {
});
});
- // The .app swap is the only upgrade path that REPLACES a working install on
- // disk, so each test below pins where the bundle ends up — not which commands
- // ran. Before #7238 the old bundle was `rm`'d first and its failure swallowed,
- // which could leave the machine with no Ollama at all, or a nested
- // Ollama.app/Ollama.app reported as a successful upgrade.
- describe('downloadWithStallGuard', () => {
- const dest = () => path.join(os.tmpdir(), `portos-stall-test-${Date.now()}-${Math.random().toString(36).slice(2)}.zip`);
- afterEach(() => { vi.useRealTimers(); vi.unstubAllGlobals(); });
+ // The Ollama.app download is bounded by header + idle deadlines, not a total
+ // one: a stalled body aborts, a slow-but-progressing one must not (#11682).
+ describe('upgradeBackend — Ollama.app download stall guard', () => {
+ const tmpDirs = () => fs.readdirSync(os.tmpdir()).filter((n) => n.startsWith('portos-ollama-upgrade-'));
+ afterEach(() => {
+ vi.useRealTimers();
+ for (const n of tmpDirs()) fs.rmSync(path.join(os.tmpdir(), n), { recursive: true, force: true });
+ });
- it('aborts with the stall error when the body stops emitting', async () => {
+ const run = async (downloadFetch, advanceMs) => {
vi.useFakeTimers();
- vi.stubGlobal('fetch', vi.fn(async (_url, { signal }) => ({
+ const restorePlatform = pinPlatform('darwin');
+ pathExistsImpl.fn = async (p) => p === '/Applications/Ollama.app';
+ vi.stubGlobal('fetch', vi.fn(async (url, init) => {
+ if (String(url).includes('api.github.com')) {
+ return { ok: true, json: async () => ({ tag_name: 'v0.34.0', assets: [{ name: 'Ollama-darwin.zip', size: 1024, browser_download_url: 'https://example.com/Ollama-darwin.zip' }] }) };
+ }
+ return downloadFetch(init);
+ }));
+ mocks.ollama.getStatus.mockResolvedValueOnce({ version: '0.33.3' });
+ try {
+ const p = svc.upgradeBackend('ollama');
+ // Step in small increments so each chunk's idle-timer reset lands before the clock moves on.
+ for (let elapsed = 0; elapsed < advanceMs; elapsed += 1_000) await vi.advanceTimersByTimeAsync(1_000);
+ return await p;
+ } finally {
+ mocks.ollama.getStatus.mockReset();
+ vi.unstubAllGlobals();
+ restorePlatform();
+ }
+ };
+
+ it('aborts a body that stops emitting, removes the temp dir and returns the stall error', async () => {
+ const r = await run(({ signal }) => ({
ok: true,
- body: new ReadableStream({
- start(c) { c.enqueue(new Uint8Array([1])); signal.addEventListener('abort', () => c.error(new Error('aborted'))); }
- })
- })));
- const p = svc.downloadWithStallGuard('https://example.com/x.zip', dest());
- await vi.advanceTimersByTimeAsync(60_001);
- expect(await p).toEqual({ error: expect.stringMatching(/no data for 60 s/) });
+ body: new ReadableStream({ start(c) { c.enqueue(new Uint8Array([1])); signal.addEventListener('abort', () => c.error(new Error('aborted'))); } })
+ }), 60_001);
+ expect(r).toEqual({ success: false, error: expect.stringMatching(/no data for 60 s/) });
+ expect(tmpDirs()).toEqual([]);
+ });
+
+ it('aborts when no response headers arrive in time', async () => {
+ const r = await run(({ signal }) => new Promise((_res, rej) => signal.addEventListener('abort', () => rej(new Error('aborted')))), 30_001);
+ expect(r).toEqual({ success: false, error: expect.stringMatching(/no response from the server within 30 s/) });
+ expect(tmpDirs()).toEqual([]);
});
it('does not abort a slow stream that keeps making progress', async () => {
- vi.useFakeTimers();
let n = 0;
- vi.stubGlobal('fetch', vi.fn(async () => ({
+ const r = await run(() => ({
ok: true,
body: new ReadableStream({
async pull(c) {
if (n++ >= 4) return c.close();
- await new Promise((r) => setTimeout(r, 40_000));
+ await new Promise((res) => setTimeout(res, 40_000));
c.enqueue(new Uint8Array([n]));
}
})
- })));
- const out = dest();
- const p = svc.downloadWithStallGuard('https://example.com/x.zip', out);
- await vi.advanceTimersByTimeAsync(200_000);
- expect(await p).toEqual({});
- fs.rmSync(out, { force: true });
- });
-
- it('aborts when no response headers arrive within the header deadline', async () => {
- vi.useFakeTimers();
- vi.stubGlobal('fetch', vi.fn((_url, { signal }) => new Promise((_res, rej) => signal.addEventListener('abort', () => rej(new Error('aborted'))))));
- const p = svc.downloadWithStallGuard('https://example.com/x.zip', dest());
- await vi.advanceTimersByTimeAsync(30_001);
- expect(await p).toEqual({ error: expect.stringMatching(/no response from the server within 30 s/) });
+ }), 200_000);
+ // Past the download the flow proceeds to the swap; whatever it fails on, it is not a stall.
+ expect(r.error || '').not.toMatch(/stalled/);
});
});
+ // The .app swap is the only upgrade path that REPLACES a working install on
+ // disk, so each test below pins where the bundle ends up — not which commands
+ // ran. Before #7238 the old bundle was `rm`'d first and its failure swallowed,
+ // which could leave the machine with no Ollama at all, or a nested
+ // Ollama.app/Ollama.app reported as a successful upgrade.
describe('upgradeBackend — macOS Ollama.app swap', () => {
const APP = '/Applications/Ollama.app';
const aside = () => [...appFs.entries.keys()].filter((p) => p.startsWith(`${APP}.portos-old-`));