From a278cf91cbe11f7d0e93b1772068443e5d70787e Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 20 Nov 2026 23:11:13 -0500 Subject: [PATCH 1/4] test(core): cover admin updater UI Add component tests for app lists, successful updates and the redirect countdown. Cover warnings, repair errors, failures and lost connections, including whether the updater continues monitoring or reports an unknown outcome. Assisted-by: Copilot:gpt-6.1-terra Signed-off-by: Josh --- core/src/views/UpdaterAdmin.spec.ts | 201 ++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 core/src/views/UpdaterAdmin.spec.ts diff --git a/core/src/views/UpdaterAdmin.spec.ts b/core/src/views/UpdaterAdmin.spec.ts new file mode 100644 index 0000000000000..5a1161e30de6b --- /dev/null +++ b/core/src/views/UpdaterAdmin.spec.ts @@ -0,0 +1,201 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { cleanup, fireEvent, render } from '@testing-library/vue' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { nextTick } from 'vue' +import UpdaterAdmin from './UpdaterAdmin.vue' + +class FakeEventSource extends EventTarget { + static instance: FakeEventSource + closed = false + + constructor(public url: string) { + super() + FakeEventSource.instance = this + } + + send(type: string, data: string) { + this.dispatchEvent(new MessageEvent(type, { data: JSON.stringify(data) })) + } + + close() { + this.closed = true + } +} + +const defaultInfo = { + appsToUpgrade: [], + incompatibleAppsList: [], + isAppsOnlyUpgrade: false, + oldTheme: null, + productName: 'Nextcloud', + version: '34.0.0', +} + +function setUpdateInfo(info: object = {}) { + const input = document.createElement('input') + input.id = 'initial-state-core-updateInfo' + input.type = 'hidden' + input.value = btoa(JSON.stringify({ ...defaultInfo, ...info })) + document.head.appendChild(input) +} + +async function startUpdate() { + const view = render(UpdaterAdmin) + await fireEvent.click(view.getByRole('button', { name: 'Start update' })) + return { view, source: FakeEventSource.instance } +} + +describe('UpdaterAdmin', () => { + beforeEach(() => { + delete globalThis._nc_initial_state + vi.stubGlobal('EventSource', FakeEventSource) + document.head.dataset.requesttoken = 'test-token' + }) + + afterEach(() => { + cleanup() + document.getElementById('initial-state-core-updateInfo')?.remove() + delete globalThis._nc_initial_state + delete document.head.dataset.requesttoken + vi.useRealTimers() + vi.unstubAllGlobals() + }) + + it('shows apps to update even when there are no incompatible apps', () => { + setUpdateInfo({ + appsToUpgrade: [{ id: 'calendar', name: 'Calendar', oldVersion: '1.0', version: '2.0' }], + }) + const view = render(UpdaterAdmin) + + expect(view.getByText('These apps will be updated:')).toBeInTheDocument() + expect(view.getByText('Calendar (calendar) from 1.0 to 2.0')).toBeInTheDocument() + expect(view.queryByText('These incompatible apps will be disabled:')).not.toBeInTheDocument() + }) + + it('does not show an empty update list when an incompatible app exists', () => { + setUpdateInfo({ incompatibleAppsList: [{ id: 'example', name: 'Example' }] }) + const view = render(UpdaterAdmin) + + expect(view.getByText('Example (example)')).toBeInTheDocument() + expect(view.queryByText('These apps will be updated:')).not.toBeInTheDocument() + }) + + it('shows success and starts the redirect countdown on done', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + vi.useFakeTimers() + + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeDisabled() + source.send('success', 'Preparing update') + source.send('done', '') + await nextTick() + + expect(source.closed).toBe(true) + expect(view.getByText('The update completed successfully.')).toBeInTheDocument() + expect(view.getByText('You will be redirected to Nextcloud in 5 seconds.')).toBeInTheDocument() + vi.advanceTimersByTime(1000) + await nextTick() + expect(view.getByText('You will be redirected to Nextcloud in 4 seconds.')).toBeInTheDocument() + }) + + it('shows repair warnings and does not redirect automatically', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + vi.useFakeTimers() + + source.send('warning', 'Repair warning: Unable to clear the frontend cache') + source.send('done', '') + await nextTick() + + expect(view.getByText(/The update completed with warnings/)).toBeInTheDocument() + expect(view.getByText('Repair warning: Unable to clear the frontend cache')).toBeVisible() + expect(view.queryByText(/You will be redirected/)).not.toBeInTheDocument() + expect(vi.getTimerCount()).toBe(0) + }) + + it('keeps monitoring after a repair error until done', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + + source.send('error', 'Repair error: step failed') + await nextTick() + expect(source.closed).toBe(false) + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeDisabled() + + source.send('success', 'Later step completed') + source.send('done', '') + await nextTick() + expect(source.closed).toBe(true) + expect(view.getByText(/The update ended with errors/)).toBeInTheDocument() + expect(view.getByText('Repair error: step failed')).toBeVisible() + expect(view.getByText('Later step completed')).toBeVisible() + expect(view.queryByText(/You will be redirected/)).not.toBeInTheDocument() + }) + + it('keeps monitoring after a failure that is followed by done', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + + source.send('failure', 'An app could not be installed') + source.send('success', 'Later step completed') + await nextTick() + expect(source.closed).toBe(false) + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeDisabled() + + source.send('done', '') + await nextTick() + expect(view.getByText(/The update ended with errors/)).toBeInTheDocument() + expect(view.getByText('An app could not be installed')).toBeVisible() + expect(view.getByText('Later step completed')).toBeVisible() + expect(view.queryByText(/You will be redirected/)).not.toBeInTheDocument() + }) + + it('finishes with an error when the server closes after a failure without done', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + + source.send('failure', 'Upgrade failed') + await nextTick() + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeDisabled() + source.send('__internal__', 'close') + await nextTick() + + expect(source.closed).toBe(true) + expect(view.getByText(/The update ended with errors/)).toBeInTheDocument() + expect(view.getByText('Upgrade failed')).toBeVisible() + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeEnabled() + expect(view.queryByText(/You will be redirected/)).not.toBeInTheDocument() + }) + + it('treats a server close without done or an error as an unknown outcome', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + + source.send('__internal__', 'close') + await nextTick() + expect(source.closed).toBe(true) + expect(view.getByText(/update status is unknown/)).toBeInTheDocument() + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeDisabled() + }) + + it('treats a transport error as an unknown outcome', async () => { + setUpdateInfo() + const { view, source } = await startUpdate() + + source.dispatchEvent(new Event('error')) + await nextTick() + + expect(source.closed).toBe(true) + expect(view.getByText(/update status is unknown/)).toBeInTheDocument() + expect(view.getByRole('button', { name: 'Continue to Nextcloud' })).toBeDisabled() + expect(view.queryByText(/The update completed/)).not.toBeInTheDocument() + expect(view.queryByText(/You will be redirected/)).not.toBeInTheDocument() + const beforeUnload = new Event('beforeunload', { cancelable: true }) + window.dispatchEvent(beforeUnload) + expect(beforeUnload.defaultPrevented).toBe(true) + }) +}) From ed0782b6b1ceb98af8fe666bab18d9d316badd40 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 20 Nov 2026 23:14:32 -0500 Subject: [PATCH 2/4] test(core): cover repair warning feedback Verify that repair warnings are sent to the updater as warning events with their translated message. Assisted-by: Copilot:gpt-6.1-terra Signed-off-by: Josh --- tests/Core/Listener/FeedBackHandlerTest.php | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/Core/Listener/FeedBackHandlerTest.php diff --git a/tests/Core/Listener/FeedBackHandlerTest.php b/tests/Core/Listener/FeedBackHandlerTest.php new file mode 100644 index 0000000000000..9031cb6ceee0e --- /dev/null +++ b/tests/Core/Listener/FeedBackHandlerTest.php @@ -0,0 +1,30 @@ +createMock(IEventSource::class); + $source->expects($this->once()) + ->method('send') + ->with('warning', 'Repair warning: Unable to clear the frontend cache'); + $l10n = $this->createMock(IL10N::class); + $l10n->method('t')->willReturnCallback(static fn (string $text): string => $text); + + $handler = new FeedBackHandler($source, $l10n); + $handler->handleRepairFeedback(new RepairWarningEvent('Unable to clear the frontend cache')); + } +} From b79ab251cb81e8f324d1deff337acd2fc003f07d Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 20 Nov 2026 23:17:51 -0500 Subject: [PATCH 3/4] fix(core): send repair warnings as warning events Preserve the severity of repair warnings so the updater can display them and avoid redirecting before administrators review them. Assisted-by: Copilot:gpt-6.1-terra Signed-off-by: Josh --- core/Listener/FeedBackHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Listener/FeedBackHandler.php b/core/Listener/FeedBackHandler.php index d355b63f1bcc0..b0bedf3712ab8 100644 --- a/core/Listener/FeedBackHandler.php +++ b/core/Listener/FeedBackHandler.php @@ -52,7 +52,7 @@ public function handleRepairFeedback(Event $event): void { } elseif ($event instanceof RepairInfoEvent) { $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getMessage()); } elseif ($event instanceof RepairWarningEvent) { - $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getMessage()); + $this->eventSource->send('warning', $this->l10n->t('Repair warning:') . ' ' . $event->getMessage()); } elseif ($event instanceof RepairErrorEvent) { $this->eventSource->send('error', $this->l10n->t('Repair error:') . ' ' . $event->getMessage()); } From 053bc60c709238d8b24f6d3db568003a8783dd15 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 20 Nov 2026 23:24:29 -0500 Subject: [PATCH 4/4] fix(core): handle updater events and outcomes correctly Previously, a repair error or lost connection could make the page report completion while the upgrade was still running. A server close without a done event could leave the page stuck in its running state. Keep monitoring until the server finishes or closes the stream, and report connection loss as an unknown outcome. Surface warnings and errors without automatically redirecting. Also show the app update list based on apps awaiting an upgrade, rather than the presence of incompatible apps. Assisted-by: Copilot:gpt-6.1-terra Signed-off-by: Josh --- core/src/views/UpdaterAdmin.vue | 55 ++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/core/src/views/UpdaterAdmin.vue b/core/src/views/UpdaterAdmin.vue index a5a9be93de9d2..bb7191af79cbd 100644 --- a/core/src/views/UpdaterAdmin.vue +++ b/core/src/views/UpdaterAdmin.vue @@ -35,6 +35,7 @@ const updateInfo = loadState<{ const isShowingDetails = ref(false) const isUpdateRunning = ref(false) const isUpdateDone = ref(false) +const isOutcomeUnknown = ref(false) const messages = ref<{ message: string, type: string }[]>([]) const wasSuccessfull = computed(() => messages.value.every((msg) => msg.type === 'success' || msg.type === 'notice')) @@ -42,8 +43,13 @@ const hasErrors = computed(() => messages.value.some((msg) => msg.type === 'erro const resultIcon = computed(() => wasSuccessfull.value ? mdiCheckCircleOutline : (hasErrors.value ? mdiCloseCircleOutline : mdiAlertCircleOutline)) const statusMessage = computed(() => { + if (isOutcomeUnknown.value) { + return t('core', 'The connection was lost and the update status is unknown. The update may still be running. Check the server logs and process status before reloading or retrying.') + } if (isUpdateDone.value) { - if (!wasSuccessfull.value) { + if (hasErrors.value) { + return t('core', 'The update ended with errors. Please check the details for more information.') + } else if (!wasSuccessfull.value) { return t('core', 'The update completed with warnings. Please check the details for more information.') } else { return t('core', 'The update completed successfully.') @@ -89,7 +95,7 @@ function getSeverityIcon(type: string) { * Start the update process */ async function onStartUpdate() { - if (isUpdateRunning.value || isUpdateDone.value) { + if (isUpdateRunning.value || isUpdateDone.value || isOutcomeUnknown.value) { return } @@ -101,19 +107,38 @@ async function onStartUpdate() { eventSource.listen('notice', (message) => { messages.value.push({ message, type: 'notice' }) }) - eventSource.listen('error', (message) => { - messages.value.push({ message, type: 'error' }) - isUpdateRunning.value = false - isUpdateDone.value = true + eventSource.listen('warning', (message) => { + messages.value.push({ message, type: 'warning' }) + }) + eventSource.source.addEventListener('error', (event) => { + if (event instanceof MessageEvent) { + messages.value.push({ message: JSON.parse(event.data), type: 'error' }) + return + } eventSource.close() + isUpdateRunning.value = false + isOutcomeUnknown.value = true + isShowingDetails.value = true }) eventSource.listen('failure', (message) => { messages.value.push({ message, type: 'failure' }) }) + eventSource.listen('__internal__', (message) => { + if (message === 'close' && !isUpdateDone.value && !isOutcomeUnknown.value) { + isUpdateRunning.value = false + if (hasErrors.value) { + isUpdateDone.value = true + } else { + isOutcomeUnknown.value = true + } + isShowingDetails.value = true + } + }) eventSource.listen('done', () => { isUpdateRunning.value = false isUpdateDone.value = true eventSource.close() + isShowingDetails.value = !wasSuccessfull.value updateCountdown() }) } @@ -139,7 +164,7 @@ function updateCountdown() { * @param event - The beforeunload event object. */ function onUnload(event: BeforeUnloadEvent) { - if (isUpdateRunning.value) { + if (isUpdateRunning.value || isOutcomeUnknown.value) { event.preventDefault() event.returnValue = t('core', 'The update is in progress, leaving this page might interrupt the process in some environments.') } @@ -174,7 +199,7 @@ function reloadPage() { - + {{ t('core', 'These apps will be updated:') }}
  • @@ -191,7 +216,7 @@ function reloadPage() {

    @@ -200,23 +225,23 @@ function reloadPage() { {{ t('core', 'Continue to {productName}', { productName: updateInfo.productName }) }} -
    +

    {{ t('core', 'Update to {version}', { version: updateInfo.version }) }}

    {{ statusMessage }}