mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 14:42:11 -03:00
fix(updates): avoid network stack traces offline
This commit is contained in:
45
tests/frontend/managers/updateService.test.js
Normal file
45
tests/frontend/managers/updateService.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, beforeEach, afterEach, expect, it, vi } from 'vitest';
|
||||
import { UpdateService } from '../../../static/js/managers/UpdateService.js';
|
||||
|
||||
function createFetchResponse(payload) {
|
||||
return {
|
||||
json: vi.fn().mockResolvedValue(payload)
|
||||
};
|
||||
}
|
||||
|
||||
describe('UpdateService passive checks', () => {
|
||||
let service;
|
||||
let fetchMock;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock = vi.fn().mockResolvedValue(createFetchResponse({
|
||||
success: true,
|
||||
current_version: 'v1.0.0',
|
||||
latest_version: 'v1.0.0',
|
||||
git_info: { short_hash: 'abc123' }
|
||||
}));
|
||||
global.fetch = fetchMock;
|
||||
|
||||
service = new UpdateService();
|
||||
service.updateNotificationsEnabled = false;
|
||||
service.lastCheckTime = 0;
|
||||
service.nightlyMode = false;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete global.fetch;
|
||||
});
|
||||
|
||||
it('skips passive update checks when notifications are disabled', async () => {
|
||||
await service.checkForUpdates();
|
||||
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows manual checks even when notifications are disabled', async () => {
|
||||
await service.checkForUpdates({ force: true });
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/lm/check-updates?nightly=false');
|
||||
});
|
||||
});
|
||||
59
tests/routes/test_update_routes.py
Normal file
59
tests/routes/test_update_routes.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import logging
|
||||
from aiohttp import ClientError
|
||||
import pytest
|
||||
|
||||
from py.routes import update_routes
|
||||
|
||||
|
||||
class OfflineDownloader:
|
||||
async def make_request(self, *_, **__):
|
||||
return False, "Cannot connect to host"
|
||||
|
||||
|
||||
class RaisingDownloader:
|
||||
async def make_request(self, *_, **__):
|
||||
raise ClientError("offline")
|
||||
|
||||
|
||||
async def _stub_downloader(instance):
|
||||
return instance
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_remote_version_offline_logs_without_traceback(monkeypatch, caplog):
|
||||
caplog.set_level(logging.WARNING)
|
||||
monkeypatch.setattr(update_routes, "get_downloader", lambda: _stub_downloader(OfflineDownloader()))
|
||||
|
||||
version, changelog = await update_routes.UpdateRoutes._get_remote_version()
|
||||
|
||||
assert version == "v0.0.0"
|
||||
assert changelog == []
|
||||
assert "Failed to fetch GitHub release" in caplog.text
|
||||
assert "Cannot connect to host" in caplog.text
|
||||
assert "Traceback" not in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_remote_version_network_error_logs_warning(monkeypatch, caplog):
|
||||
caplog.set_level(logging.WARNING)
|
||||
monkeypatch.setattr(update_routes, "get_downloader", lambda: _stub_downloader(RaisingDownloader()))
|
||||
|
||||
version, changelog = await update_routes.UpdateRoutes._get_remote_version()
|
||||
|
||||
assert version == "v0.0.0"
|
||||
assert changelog == []
|
||||
assert "Unable to reach GitHub for release info" in caplog.text
|
||||
assert "Traceback" not in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_nightly_version_network_error_logs_warning(monkeypatch, caplog):
|
||||
caplog.set_level(logging.WARNING)
|
||||
monkeypatch.setattr(update_routes, "get_downloader", lambda: _stub_downloader(RaisingDownloader()))
|
||||
|
||||
version, changelog = await update_routes.UpdateRoutes._get_nightly_version()
|
||||
|
||||
assert version == "main"
|
||||
assert changelog == []
|
||||
assert "Unable to reach GitHub for nightly version" in caplog.text
|
||||
assert "Traceback" not in caplog.text
|
||||
Reference in New Issue
Block a user