diff --git a/apps/web/tests/desktop-channel.e2e.ts b/apps/web/tests/desktop-channel.e2e.ts index cf7dc8d63e..c14542736f 100644 --- a/apps/web/tests/desktop-channel.e2e.ts +++ b/apps/web/tests/desktop-channel.e2e.ts @@ -15,8 +15,7 @@ it('persists a Desktop channel from Settings and keeps external edits startup-on const browser = await chromium.launch() try { const settings = new DesktopUpdateSettings(join(scaffold.harnessHome, 'shell')) - await settings.save('nightly') - let state: DesktopChannelState = { channel: 'nightly', packagedChannel: 'nightly', unlocked: true, changing: false } + let state: DesktopChannelState = { channel: 'stable', packagedChannel: 'stable', unlocked: false, changing: false } const page = await browser.newPage({ viewport: { width: 1280, height: 900 }, locale: 'en-US' }) const tripwire = watchConsole(page) let detailOpens = 0 @@ -25,7 +24,7 @@ it('persists a Desktop channel from Settings and keeps external edits startup-on await page.exposeFunction('setChannel', async (channel: 'nightly' | 'stable'): Promise => { try { await settings.save(channel) - state = { ...state, channel, error: undefined } + state = { ...state, channel, unlocked: true, error: undefined } return { kind: 'applied', state } } catch (_error) { return { kind: 'failed', state, reason: 'format' } } }) @@ -44,12 +43,28 @@ it('persists a Desktop channel from Settings and keeps external edits startup-on await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) await openSettings(page, 'en') const row = page.getByRole('group', { name: 'Update channel', exact: true }) + const versionRow = page.getByText(/^Current version:/u) + await versionRow.waitFor() + expect(await row.count()).toBe(0) + for (let i = 0; i < 4; i++) await versionRow.click() + expect(await page.getByRole('dialog', { name: 'Switch to development update channel?', exact: true }).count()).toBe(0) + await versionRow.click() + const unlockDialog = page.getByRole('dialog', { name: 'Switch to development update channel?', exact: true }) + await unlockDialog.waitFor() + await unlockDialog.getByRole('button', { name: 'Switch to development', exact: true }).click() await row.getByText('Development', { exact: true }).waitFor() + expect(JSON.parse(await readFile(settings.path, 'utf8'))).toMatchObject({ + version: '1', + updates: { channel: 'nightly', channelUnlocked: true }, + }) await row.getByRole('button', { name: 'Update channel', exact: true }).click() await page.getByRole('menuitem', { name: 'Stable', exact: true }).click() await row.getByText('Stable', { exact: true }).waitFor() await page.getByText('Update channel changed', { exact: true }).waitFor() - expect(JSON.parse(await readFile(settings.path, 'utf8'))).toMatchObject({ updates: { channel: 'stable' } }) + expect(JSON.parse(await readFile(settings.path, 'utf8'))).toMatchObject({ + version: '1', + updates: { channel: 'stable', channelUnlocked: true }, + }) await compareOrRefreshGolden(fileURLToPath(new URL('./expected/desktop-channel/stable.expected.md', import.meta.url)), await captureStableAria(page, '[role="group"][aria-label="Update channel"]', scaffold.workspaceCwd), webSnapshotMode()) await writeFile(settings.path, JSON.stringify({ version: '1', updates: { channel: 'nightly', channelUnlocked: true } })) diff --git a/packages/client/ui-settings-general/src/client/CurrentVersionRow.tsx b/packages/client/ui-settings-general/src/client/CurrentVersionRow.tsx index e104e40e3a..69d3aa0d38 100644 --- a/packages/client/ui-settings-general/src/client/CurrentVersionRow.tsx +++ b/packages/client/ui-settings-general/src/client/CurrentVersionRow.tsx @@ -1,14 +1,89 @@ -/** Installed release version in General Settings for Web and Desktop. */ -import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' +/** Installed release version in General Settings, with hidden 5-click unlock in Desktop. */ +import { useState } from 'react' +import { Button, Modal } from '@deepseek-ai/dsh-client-ui-primitives' +import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' +import type { DesktopChannelSnapshot, DesktopChannelSource } from './desktop-channel-source.ts' import css from './CurrentVersionRow.module.css' +const UNLOCK_CLICKS_REQUIRED = 5 +const INACTIVE_CHANNEL: DesktopChannelSnapshot = { failed: false } +const fallbackUseChannel = (selector: (snapshot: DesktopChannelSnapshot) => R): R => selector(INACTIVE_CHANNEL) + +/** Optional Desktop channel observation and unlock action injected only in Electron. */ +export interface CurrentVersionRowInjected { + hooks: { channel: DesktopChannelSource['store'] } + unlock(): Promise +} + +/** Props for CurrentVersionRow in Web (no channel injection) and Desktop (channel injection). */ +export type CurrentVersionRowProps = + PropsRuntime<'settings.general.group.updates.item'> & + PropsLocale<'settings'> & + Partial> + /** - * Render the version embedded by the client build; partial builds without metadata omit the row. - * @param props - runtime share and localized copy. - * @returns the current release label, or nothing when build metadata is absent. + * Render the version embedded by the client build; clicking 5 times in Desktop opens the unlock confirmation. + * @param props - runtime share, localized copy, and optional Desktop channel unlock controls. + * @returns the current release label and confirmation modal, or nothing when build metadata is absent. */ -export function CurrentVersionRow({ t }: PropsRuntime<'settings.general.group.updates.item'> & PropsLocale<'settings'>) { +export function CurrentVersionRow({ t, useChannel, unlock }: CurrentVersionRowProps) { + const snapshot = (useChannel ?? fallbackUseChannel)(value => value) + const [clicks, setClicks] = useState(0) + const [confirming, setConfirming] = useState(false) const version = process.env.DSH_CLIENT_VERSION if (version === undefined) return null - return
{t('general.currentVersion', { version })}
+ const state = snapshot.state + const canUnlock = unlock !== undefined + && state !== undefined + && !state.unlocked + && !state.changing + && state.error === undefined + && snapshot.pending === undefined + && !snapshot.failed + const dismiss = (): void => { setConfirming(false) } + return ( + <> +
{ + const next = clicks + 1 + if (next >= UNLOCK_CLICKS_REQUIRED) { + setClicks(0) + setConfirming(true) + } else { + setClicks(next) + } + } : undefined} + > + {t('general.currentVersion', { version })} +
+ {canUnlock && ( + + + + + )} + /> + )} + + ) } diff --git a/packages/client/ui-settings-general/src/client/DesktopChannelRow.tsx b/packages/client/ui-settings-general/src/client/DesktopChannelRow.tsx index b0bc8bde9a..d9c00a34cf 100644 --- a/packages/client/ui-settings-general/src/client/DesktopChannelRow.tsx +++ b/packages/client/ui-settings-general/src/client/DesktopChannelRow.tsx @@ -21,6 +21,8 @@ export function DesktopChannelRow({ useChannel, select, t }: PropsRuntime<'settings.general.group.updates.item'> & PropsLocale<'settings'> & InjectFace) { const { state, failed, pending } = useChannel(value => value) const [open, setOpen] = useState(false) + const visible = state?.unlocked === true || pending !== undefined || failed || state?.error !== undefined + if (!visible) return null const busy = pending !== undefined || state?.changing === true const channel = pending ?? state?.channel return
diff --git a/packages/client/ui-settings-general/src/client/desktop-channel-source.ts b/packages/client/ui-settings-general/src/client/desktop-channel-source.ts index 8c2ac0961a..d2d5acb32e 100644 --- a/packages/client/ui-settings-general/src/client/desktop-channel-source.ts +++ b/packages/client/ui-settings-general/src/client/desktop-channel-source.ts @@ -51,7 +51,7 @@ export class DesktopChannelSource { async select(channel: DesktopUpdateChannel): Promise { if (!this.isLive() || this.store.getSnapshot().pending !== undefined) return const state = this.store.getSnapshot().state - if (state?.channel === channel && state.error === undefined && !state.changing) return + if (state?.unlocked && state.channel === channel && state.error === undefined && !state.changing) return const revision = this.revision const { notice: _notice, ...previous } = this.store.getSnapshot() this.store.set({ ...previous, pending: channel }) diff --git a/packages/client/ui-settings-general/src/client/index.ts b/packages/client/ui-settings-general/src/client/index.ts index c70bef4e55..9537376b24 100644 --- a/packages/client/ui-settings-general/src/client/index.ts +++ b/packages/client/ui-settings-general/src/client/index.ts @@ -43,7 +43,7 @@ import { CloseLabel, HeaderContent, TriggerContent } from './chrome.tsx' import { GeneralSection, type GeneralSectionInjected } from './GeneralSection.tsx' import { SettingsSectionView } from './SettingsSectionView.tsx' import { GeneralGroup, DisplayGroup, InteractionGroup, NotificationsGroup, DataGroup, UpdatesGroup } from './GeneralGroup.tsx' -import { CurrentVersionRow } from './CurrentVersionRow.tsx' +import { CurrentVersionRow, type CurrentVersionRowInjected } from './CurrentVersionRow.tsx' import { DeveloperToolsRow, type DeveloperToolsRowInjected } from './DeveloperToolsRow.tsx' import { SettingsDocumentAction } from './SettingsDocumentAction.tsx' import type { SettingsDocumentActionInjected } from './SettingsDocumentAction.tsx' @@ -100,18 +100,14 @@ export function apply(ctx: ClientContext): void { }, }), }, DeveloperToolsRow)) - // Version information follows the core preferences. - ctx.slots.inject('settings.general.group.updates.item', () => ctx.slots.register({ - name: 'settings.general.group.updates.item', id: 'current-version', order: 101, locale: NS, - }, CurrentVersionRow)) ctx.effect(() => ctx.locale.register(NS, { zh, en, ja, es, fr, de, ru, pt }), 'ui-settings-general: dictionaries') const connection = ctx.get('connection') as ConnectionHandle const carrier = (globalThis as typeof globalThis & { dshDesktop?: { protocolVersion: number; updates?: DesktopUpdateBridge } }).dshDesktop const desktopUpdate = new DesktopUpdateSource(carrier?.protocolVersion === 1 ? carrier.updates : undefined) ctx.effect(() => () => { desktopUpdate.dispose() }, 'ui-settings-general: desktop update carrier') const channelBridge = carrier?.protocolVersion === 1 ? carrier.updates?.channels : undefined - if (channelBridge !== undefined) { - const channel = new DesktopChannelSource(channelBridge) + const channel = channelBridge === undefined ? undefined : new DesktopChannelSource(channelBridge) + if (channel !== undefined) { ctx.effect(() => () => { channel.dispose() }, 'ui-settings-general: desktop channel') ctx.slots.inject('settings.general.group.updates.item', () => ctx.slots.register({ name: 'settings.general.group.updates.item', id: 'desktop-update-channel', order: 100, locale: NS, @@ -123,6 +119,18 @@ export function apply(ctx: ClientContext): void { dismiss: (sequence: number) => { channel.dismissNotice(sequence) }, openConfiguration: () => { desktopUpdate.open() } }), }, DesktopChannelToast)) } + // Version information follows the core preferences; Desktop binds hidden 5-click channel unlock. + ctx.slots.inject('settings.general.group.updates.item', () => channel === undefined + ? ctx.slots.register({ + name: 'settings.general.group.updates.item', id: 'current-version', order: 101, locale: NS, + }, CurrentVersionRow) + : ctx.slots.register({ + name: 'settings.general.group.updates.item', id: 'current-version', order: 101, locale: NS, + inject: (): CurrentVersionRowInjected => ({ + hooks: { channel: channel.store }, + unlock: () => channel.select('nightly'), + }), + }, CurrentVersionRow)) ctx.slots.inject('sidebar.toggle.badge', () => ctx.slots.register({ name: 'sidebar.toggle.badge', locale: NS, diff --git a/packages/client/ui-settings-general/src/client/locales.ts b/packages/client/ui-settings-general/src/client/locales.ts index 0771a4c1ed..4d033c9092 100644 --- a/packages/client/ui-settings-general/src/client/locales.ts +++ b/packages/client/ui-settings-general/src/client/locales.ts @@ -6,6 +6,10 @@ export const zh = { 'desktop.channel.description': '正式版适合日常使用;开发版可提前体验新功能,但可能不稳定。', 'desktop.channel.stable': '正式版', 'desktop.channel.nightly': '开发版', + 'desktop.channel.unlock.title': '切换到开发版更新渠道?', + 'desktop.channel.unlock.description': '开发版包含尚未完全稳定的实验功能,可能影响日常使用。切换后仍可在设置中切回正式版。', + 'desktop.channel.unlock.confirm': '切换到开发版', + 'desktop.channel.unlock.cancel': '取消', 'desktop.channel.unavailable': '配置不可用', 'desktop.channel.error': '未能应用更新配置。请点击桌面更新入口查看原因。', 'desktop.channel.readError': '无法读取更新渠道状态,请重启应用。', @@ -84,6 +88,10 @@ export const en = { 'desktop.channel.description': 'Stable is suitable for everyday use. Development offers early access to new features but may be unstable.', 'desktop.channel.stable': 'Stable', 'desktop.channel.nightly': 'Development', + 'desktop.channel.unlock.title': 'Switch to development update channel?', + 'desktop.channel.unlock.description': 'Development builds include experimental changes and may be unstable for everyday use. You can switch back to the stable channel in settings at any time.', + 'desktop.channel.unlock.confirm': 'Switch to development', + 'desktop.channel.unlock.cancel': 'Cancel', 'desktop.channel.unavailable': 'Configuration unavailable', 'desktop.channel.error': 'Could not apply update settings. Open the desktop update indicator for details.', 'desktop.channel.readError': 'Could not read the update channel. Restart the app.', @@ -159,6 +167,10 @@ export const ja = { 'desktop.channel.description': '安定版は日常的な使用に適しています。開発版では新機能をいち早く試せますが、不安定な場合があります。', 'desktop.channel.stable': '安定版', 'desktop.channel.nightly': '開発版', + 'desktop.channel.unlock.title': '開発版の更新チャンネルに切り替えますか?', + 'desktop.channel.unlock.description': '開発版には実験的な変更が含まれ、日常的な使用では不安定になる場合があります。設定からいつでも安定版に戻せます。', + 'desktop.channel.unlock.confirm': '開発版に切り替える', + 'desktop.channel.unlock.cancel': 'キャンセル', 'desktop.channel.unavailable': '設定を利用できません', 'desktop.channel.error': '更新設定を適用できませんでした。デスクトップの更新表示で詳細を確認してください。', 'desktop.channel.readError': '更新チャンネルを読み取れません。アプリを再起動してください。', @@ -234,6 +246,10 @@ export const es = { 'desktop.channel.description': 'Estable es adecuado para el uso diario. Desarrollo permite probar nuevas funciones antes, pero puede ser inestable.', 'desktop.channel.stable': 'Estable', 'desktop.channel.nightly': 'Desarrollo', + 'desktop.channel.unlock.title': '¿Cambiar al canal de actualización de desarrollo?', + 'desktop.channel.unlock.description': 'Las compilaciones de desarrollo incluyen cambios experimentales y pueden ser inestables en el uso diario. Puedes volver al canal estable en la configuración en cualquier momento.', + 'desktop.channel.unlock.confirm': 'Cambiar a desarrollo', + 'desktop.channel.unlock.cancel': 'Cancelar', 'desktop.channel.unavailable': 'Configuración no disponible', 'desktop.channel.error': 'No se pudo aplicar la configuración. Abre el indicador de actualización para ver los detalles.', 'desktop.channel.readError': 'No se pudo leer el canal de actualización. Reinicia la aplicación.', @@ -309,6 +325,10 @@ export const fr = { 'desktop.channel.description': 'Stable convient à un usage quotidien. Développement permet de découvrir les nouveautés en avance, mais peut être instable.', 'desktop.channel.stable': 'Stable', 'desktop.channel.nightly': 'Développement', + 'desktop.channel.unlock.title': 'Passer au canal de mise à jour de développement ?', + 'desktop.channel.unlock.description': 'Les versions de développement incluent des changements expérimentaux et peuvent être instables au quotidien. Vous pourrez revenir au canal stable à tout moment dans les paramètres.', + 'desktop.channel.unlock.confirm': 'Passer au développement', + 'desktop.channel.unlock.cancel': 'Annuler', 'desktop.channel.unavailable': 'Configuration indisponible', 'desktop.channel.error': 'Impossible d’appliquer les paramètres. Ouvrez l’indicateur de mise à jour pour plus de détails.', 'desktop.channel.readError': 'Impossible de lire le canal de mise à jour. Redémarrez l’application.', @@ -384,6 +404,10 @@ export const de = { 'desktop.channel.description': 'Stabil eignet sich für den Alltag. Entwicklung bietet frühzeitigen Zugang zu neuen Funktionen, kann aber instabil sein.', 'desktop.channel.stable': 'Stabil', 'desktop.channel.nightly': 'Entwicklung', + 'desktop.channel.unlock.title': 'Zum Entwicklungs-Update-Kanal wechseln?', + 'desktop.channel.unlock.description': 'Entwicklungsversionen enthalten experimentelle Änderungen und können im Alltag instabil sein. Sie können in den Einstellungen jederzeit wieder zum stabilen Kanal wechseln.', + 'desktop.channel.unlock.confirm': 'Zu Entwicklung wechseln', + 'desktop.channel.unlock.cancel': 'Abbrechen', 'desktop.channel.unavailable': 'Konfiguration nicht verfügbar', 'desktop.channel.error': 'Update-Einstellungen konnten nicht angewendet werden. Details finden Sie in der Update-Anzeige.', 'desktop.channel.readError': 'Der Update-Kanal konnte nicht gelesen werden. Starten Sie die App neu.', @@ -459,6 +483,10 @@ export const ru = { 'desktop.channel.description': 'Стабильный канал подходит для повседневного использования. Канал разработки позволяет раньше попробовать новые функции, но может быть нестабильным.', 'desktop.channel.stable': 'Стабильный', 'desktop.channel.nightly': 'Разработка', + 'desktop.channel.unlock.title': 'Переключиться на канал обновлений разработки?', + 'desktop.channel.unlock.description': 'Сборки для разработки содержат экспериментальные изменения и могут работать нестабильно при повседневном использовании. Вы сможете вернуться на стабильный канал в настройках в любое время.', + 'desktop.channel.unlock.confirm': 'Переключиться на разработку', + 'desktop.channel.unlock.cancel': 'Отмена', 'desktop.channel.unavailable': 'Настройки недоступны', 'desktop.channel.error': 'Не удалось применить настройки. Откройте индикатор обновления для подробностей.', 'desktop.channel.readError': 'Не удалось прочитать канал обновлений. Перезапустите приложение.', @@ -534,6 +562,10 @@ export const pt = { 'desktop.channel.description': 'Estável é adequado para o uso diário. Desenvolvimento oferece acesso antecipado a novos recursos, mas pode ser instável.', 'desktop.channel.stable': 'Estável', 'desktop.channel.nightly': 'Desenvolvimento', + 'desktop.channel.unlock.title': 'Mudar para o canal de atualização de desenvolvimento?', + 'desktop.channel.unlock.description': 'As compilações de desenvolvimento incluem alterações experimentais e podem ser instáveis no uso diário. Você pode voltar para o canal estável nas configurações a qualquer momento.', + 'desktop.channel.unlock.confirm': 'Mudar para desenvolvimento', + 'desktop.channel.unlock.cancel': 'Cancelar', 'desktop.channel.unavailable': 'Configuração indisponível', 'desktop.channel.error': 'Não foi possível aplicar as configurações. Abra o indicador de atualização para ver detalhes.', 'desktop.channel.readError': 'Não foi possível ler o canal de atualização. Reinicie o aplicativo.', diff --git a/packages/client/ui-settings-general/tests/apply.client.spec.ts b/packages/client/ui-settings-general/tests/apply.client.spec.ts index f4365a543e..cad0a40da1 100644 --- a/packages/client/ui-settings-general/tests/apply.client.spec.ts +++ b/packages/client/ui-settings-general/tests/apply.client.spec.ts @@ -17,6 +17,7 @@ import { inject } from '../src/client/index.ts' import type { DeveloperToolsRowInjected } from '../src/client/DeveloperToolsRow.tsx' import { HostReleasePrompt, type HostReleasePromptInjected } from '../src/client/HostReleasePrompt.tsx' import { CloseLabel, HeaderContent, TriggerContent } from '../src/client/chrome.tsx' +import type { CurrentVersionRowInjected } from '../src/client/CurrentVersionRow.tsx' import type { DesktopChannelRowInjected, DesktopChannelToastInjected } from '../src/client/DesktopChannelRow.tsx' import type { DesktopChannelBridge } from '../src/types.ts' import { GeneralSection } from '../src/client/GeneralSection.tsx' @@ -218,8 +219,11 @@ describe('ui-settings-general apply', () => { it('removes the Desktop channel row and shell subscription when its plugin unloads', async ({ mock, start }) => { const unsubscribe = vi.fn() - const state = { channel: 'nightly', packagedChannel: 'nightly', changing: false } as const - const save = vi.fn(async () => ({ kind: 'applied' as const, state })) + let state = { channel: 'stable' as 'nightly' | 'stable', packagedChannel: 'stable' as const, unlocked: false, changing: false } + const save = vi.fn(async (channel: 'nightly' | 'stable') => { + state = { ...state, channel, unlocked: true } + return { kind: 'applied' as const, state } + }) const channels: DesktopChannelBridge = { get: async () => state, set: save, subscribe: () => unsubscribe } const open = vi.fn(async () => {}) @@ -227,6 +231,13 @@ describe('ui-settings-general apply', () => { status: async () => ({ phase: 'idle' }), open, subscribe: () => () => {} } }) onTestFinished(() => { vi.unstubAllGlobals() }) const { c } = await client(mock, start) + const versionRow = c.ctx.slots.entries('settings.general.group.updates.item').find(row => row.options.id === 'current-version')! + const versionInjected = versionRow.inject!() + const versionHooks = versionInjected.hooks as CurrentVersionRowInjected['hooks'] + const unlock = versionInjected.unlock as CurrentVersionRowInjected['unlock'] + expect(versionHooks.channel).toBeDefined() + await unlock() + expect(save).toHaveBeenCalledWith('nightly') const row = c.ctx.slots.entries('settings.general.group.updates.item').find(row => row.options.id === 'desktop-update-channel')! expect(row.options.order).toBe(100) expect(c.ctx.slots.entries('shell.overlay').some(entry => entry.options.id === 'desktop-channel-toast')).toBe(true) @@ -241,7 +252,7 @@ describe('ui-settings-general apply', () => { openConfiguration() expect(open).toHaveBeenCalledOnce() expect(hooks.channel.getSnapshot().notice?.outcome).toBe('applied') - dismiss(1) + dismiss(2) expect(hooks.channel.getSnapshot().notice).toBeUndefined() await c.unload(SELF) await c.flush() diff --git a/packages/client/ui-settings-general/tests/components.client.spec.tsx b/packages/client/ui-settings-general/tests/components.client.spec.tsx index 336982ebf6..53c50ea690 100644 --- a/packages/client/ui-settings-general/tests/components.client.spec.tsx +++ b/packages/client/ui-settings-general/tests/components.client.spec.tsx @@ -327,6 +327,49 @@ describe('current version', () => { const view = render() expect(view.container.textContent).toBe('') }) + + it('unlocks the development channel after 5 clicks and confirmation while keeping Cancel focused first', async () => { + vi.stubEnv('DSH_CLIENT_VERSION', '1.2.3-rc.4') + const store = createSnapshotStore({ + failed: false, + state: { channel: 'stable', packagedChannel: 'stable', unlocked: false, changing: false }, + }) + const unlock = vi.fn(async () => { + store.set({ + failed: false, + state: { channel: 'nightly', packagedChannel: 'stable', unlocked: true, changing: false }, + }) + }) + const useChannel = bindSnapshotSelector(store) + render( + <> + {})} /> + + , + ) + expect(screen.queryByRole('group', { name: 'Update channel' })).toBeNull() + const versionRow = screen.getByText(en['general.currentVersion']) + for (let i = 0; i < 4; i++) fireEvent.click(versionRow) + expect(screen.queryByRole('dialog', { name: en['desktop.channel.unlock.title'] })).toBeNull() + + fireEvent.click(versionRow) + const modal = screen.getByRole('dialog', { name: en['desktop.channel.unlock.title'] }) + expect(modal.textContent).toContain(en['desktop.channel.unlock.description']) + expect(document.activeElement?.textContent).toBe('Cancel') + fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) + expect(screen.queryByRole('dialog', { name: en['desktop.channel.unlock.title'] })).toBeNull() + expect(unlock).not.toHaveBeenCalled() + + for (let i = 0; i < 5; i++) fireEvent.click(versionRow) + expect(screen.getByRole('dialog', { name: en['desktop.channel.unlock.title'] })).toBeTruthy() + fireEvent.click(screen.getByRole('button', { name: 'Switch to development' })) + await waitFor(() => { expect(unlock).toHaveBeenCalledOnce() }) + expect(screen.queryByRole('dialog', { name: en['desktop.channel.unlock.title'] })).toBeNull() + expect(screen.getByRole('button', { name: 'Update channel' }).textContent).toBe('Development') + + for (let i = 0; i < 5; i++) fireEvent.click(versionRow) + expect(screen.queryByRole('dialog', { name: en['desktop.channel.unlock.title'] })).toBeNull() + }) }) describe('Host release change confirmation', () => { @@ -392,19 +435,23 @@ describe('Host release change confirmation', () => { }) -it('shows channel load errors and waits for an explicit selection to settle', async () => { +it('hides the channel row while locked, shows load errors, and waits for an explicit selection to settle', async () => { let state: { state?: DesktopChannelState; failed: boolean; pending?: 'stable' } = { failed: false } const pending = Promise.withResolvers() const select = vi.fn(() => pending.promise) const props = { ...kit, t, select, useChannel: bindSnapshotSelector(createSnapshotStore(state)) } const view = render() - const control = screen.getByRole('button', { name: 'Update channel' }) - expect(control.hasAttribute('disabled')).toBe(true) + expect(screen.queryByRole('button', { name: 'Update channel' })).toBeNull() + state = { failed: false, state: { channel: 'stable', packagedChannel: 'stable', unlocked: false, changing: false } } + view.rerender() + expect(screen.queryByRole('button', { name: 'Update channel' })).toBeNull() state = { failed: true } view.rerender() expect(screen.getByRole('alert').textContent).toBe(en['desktop.channel.readError']) - state = { failed: false, state: { channel: null, packagedChannel: 'nightly', unlocked: true, changing: false, error: 'format' } } + expect(screen.getByRole('button', { name: 'Update channel' }).hasAttribute('disabled')).toBe(true) + state = { failed: false, state: { channel: null, packagedChannel: 'nightly', unlocked: false, changing: false, error: 'format' } } view.rerender() + const control = screen.getByRole('button', { name: 'Update channel' }) expect(control.textContent).toContain('Configuration unavailable') fireEvent.click(control) fireEvent.click(screen.getByRole('menuitem', { name: 'Stable' })) diff --git a/packages/client/ui-settings-general/tests/desktop-channel.client.spec.ts b/packages/client/ui-settings-general/tests/desktop-channel.client.spec.ts index 57bbf61c9e..254a5b6591 100644 --- a/packages/client/ui-settings-general/tests/desktop-channel.client.spec.ts +++ b/packages/client/ui-settings-general/tests/desktop-channel.client.spec.ts @@ -122,13 +122,18 @@ it('does not let a late initial read overwrite an accepted selection', async () }) -it('does not submit or toast for the current healthy selection', async () => { +it('submits when locked on stable, then skips redundant submits once unlocked', async () => { const f = fixture() - f.get.resolve(nightly) + const lockedStable: DesktopChannelState = { ...stable, unlocked: false } + f.get.resolve(lockedStable) await f.get.promise - await f.source.select('nightly') - expect(f.select).not.toHaveBeenCalled() - expect(f.source.store.getSnapshot()).toEqual({ state: nightly, failed: false }) + const unlocking = f.source.select('stable') + expect(f.select).toHaveBeenCalledExactlyOnceWith('stable') + f.set.resolve({ kind: 'applied', state: stable }) + await unlocking + await f.source.select('stable') + expect(f.select).toHaveBeenCalledOnce() + expect(f.source.store.getSnapshot().state).toEqual(stable) f.source.dispose() })