Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Keep token reveal content and copy feedback current
pulse-triage[bot]a71e60086262
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex fe5416e1e0..e6b6abe195 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -20,6 +20,28 @@## Purpose+### Token reveals keep content and copy feedback with the admitted value++The existing token reveal consumer scrolls within the bounded shared dialog,+including short, narrow and enlarged-text viewports. The title/source and Close+control use separate flow space; literal notes, labels, hints and token values+wrap without hiding Copy or Dismiss. Shared dialog focus and dismissal ownership+are unchanged.++Replacing the reveal updates the actual value, record, hint, source and note+together; the consumer never retains a snapshot from the previous reveal.+Only one deliberate clipboard request runs per reveal at a time. Pending feedback+is distinct from success; a result is reported only while its originating reveal+is current and mounted, even when a later reveal has identical token bytes.+Replacement/dismissal/unmount invalidate feedback and its reset timer, not an+already-requested system clipboard write. Token generation, reveal admission,+authorisation and API/storage/clipboard permissions are unchanged. Normal-suite+`TokenRevealDialog.test.tsx` covers current success/failure/retry, pending dedupe,+replacement, dismissal, unmount and timer isolation. Source-bound browser proof+must exercise the real store/dialog/clipboard helper at desktop and narrow/short+viewports, with native scroll, keyboard/touch, deferred results and inspected pixels.++### Backup views share bounded owned-focus restorationCoverage posture sorting and By date regrouping use the same existing backupsdiff --git a/frontend-modern/src/components/TokenRevealDialog.tsx b/frontend-modern/src/components/TokenRevealDialog.tsxindex 76b0e8993f..3bd11ba263 100644--- a/frontend-modern/src/components/TokenRevealDialog.tsx+++ b/frontend-modern/src/components/TokenRevealDialog.tsx@@ -11,6 +11,8 @@ import { useTokenRevealState, dismissTokenReveal } from '@/stores/tokenReveal';export const TokenRevealDialog: Component = () => {const state = useTokenRevealState();const [copied, setCopied] = createSignal(false);+ const [copying, setCopying] = createSignal(false);+ let copyGeneration = 0;let copiedTimer: ReturnType<typeof setTimeout> | undefined;const handleDismiss = () => {@@ -19,7 +21,18 @@ export const TokenRevealDialog: Component = () => {};const handleCopy = async (token: string) => {+ const current = state();+ if (!current || current.token !== token || copying()) return;+ const generation = ++copyGeneration;+ if (copiedTimer) clearTimeout(copiedTimer);+ copiedTimer = undefined;+ setCopied(false);+ setCopying(true);const success = await copyToClipboard(token);+ // A clipboard write already requested by the operator cannot be cancelled.+ // Its completion must not confirm a different or dismissed reveal.+ if (generation !== copyGeneration || state() !== current) return;+ setCopying(false);if (success) {setCopied(true);showSuccess('Token copied to clipboard');@@ -31,12 +44,17 @@ export const TokenRevealDialog: Component = () => {};onCleanup(() => {+ copyGeneration += 1;if (copiedTimer) clearTimeout(copiedTimer);});createEffect(() => {const current = state();+ copyGeneration += 1;+ if (copiedTimer) clearTimeout(copiedTimer);+ copiedTimer = undefined;setCopied(false);+ setCopying(false);if (!current) {return;}@@ -52,9 +70,8 @@ export const TokenRevealDialog: Component = () => {});return (- <Show when={state()}>- {(tokenInfo) => {- const info = tokenInfo();+ <Show when={state()} keyed>+ {(info) => {const sourceBadge = getSourcePlatformBadge(info.source);const sourceLabel = sourceBadge?.label || getSourcePlatformLabel(info.source);const recordName = info.record?.name?.trim() || 'Untitled token';@@ -77,17 +94,8 @@ export const TokenRevealDialog: Component = () => {panelClass="max-w-xl"ariaLabel="API token ready">- <div class="w-full">+ <div class="w-full min-h-0 overflow-y-auto overscroll-contain"><Card padding="lg" class="shadow-xs relative">- <button- type="button"- class="absolute top-3 right-3 rounded-md px-2 py-1 text-xs font-medium hover:text-base-content transition-colors"- onClick={handleDismiss}- aria-label="Close token dialog"- >- Close- </button>-<div class="flex items-start gap-3"><div class="shrink-0 rounded-full bg-green-100 text-green-700 dark:bg-green-900/25 dark:text-green-300 p-2"><svg class="w-6 h-6" viewBox="0 0 24 24" fill="none" stroke="currentColor">@@ -99,47 +107,58 @@ export const TokenRevealDialog: Component = () => {/></svg></div>- <div class="space-y-2 flex-1">+ <div class="min-w-0 space-y-2 flex-1"><div class="flex flex-wrap items-center gap-2"><h2 class="text-lg font-semibold text-base-content">API token ready</h2><Show when={sourceLabel}><span- class={+ class={`max-w-full [overflow-wrap:anywhere] ${sourceBadge?.classes ||- 'inline-flex items-center rounded-sm px-2 py-0.5 text-[10px] font-medium whitespace-nowrap bg-surface-alt text-base-content'- }+ 'inline-flex items-center rounded-sm px-2 py-0.5 text-[10px] font-medium bg-surface-alt text-base-content'+ }`}>{sourceLabel}</span></Show></div>- <p class="text-sm text-base-content leading-snug">{hint}</p></div>+ <button+ type="button"+ class="shrink-0 rounded-md px-2 py-1 text-xs font-medium hover:text-base-content transition-colors"+ onClick={handleDismiss}+ aria-label="Close token dialog"+ >+ Close+ </button></div>+ <p class="mt-3 text-sm text-base-content leading-snug [overflow-wrap:anywhere]">+ {hint}+ </p><div class="mt-5 space-y-3"><div class="text-xs font-semibold uppercase tracking-wide text-muted">Token value</div><div class="flex flex-col sm:flex-row sm:items-center gap-2">- <code class="flex-1 rounded-md border border-green-300 dark:border-green-700 bg-surface px-4 py-3 font-mono text-base font-semibold text-base-content break-all">+ <code class="min-w-0 flex-1 rounded-md border border-green-300 dark:border-green-700 bg-surface px-4 py-3 font-mono text-base font-semibold text-base-content break-all">{info.token}</code><buttontype="button"onClick={() => handleCopy(info.token)}- class="inline-flex items-center justify-center rounded-md bg-green-600 hover:bg-green-700 text-white text-sm font-semibold px-4 py-2 transition-colors shadow-xs"+ disabled={copying()}+ class="disabled:cursor-wait disabled:opacity-60 inline-flex items-center justify-center rounded-md bg-green-600 hover:bg-green-700 text-white text-sm font-semibold px-4 py-2 transition-colors shadow-xs">- {copied() ? 'Copied!' : 'Copy token'}+ {copying() ? 'Copying…' : copied() ? 'Copied!' : 'Copy token'}</button></div>- <div class="text-xs text-muted">+ <div class="text-xs text-muted [overflow-wrap:anywhere]">Label: <span class="font-semibold text-base-content">{recordName}</span><Show when={tokenHint}><span>{' '}· Hint:{' '}- <code class="rounded-sm bg-surface-alt px-1.5 py-0.5 font-mono text-[11px] text-muted">+ <code class="rounded-sm bg-surface-alt px-1.5 py-0.5 font-mono text-[11px] text-muted break-all">{tokenHint as string}</code></span>diff --git a/frontend-modern/src/components/__tests__/TokenRevealDialog.test.tsx b/frontend-modern/src/components/__tests__/TokenRevealDialog.test.tsxindex 1d1d658e01..b16a085b38 100644--- a/frontend-modern/src/components/__tests__/TokenRevealDialog.test.tsx+++ b/frontend-modern/src/components/__tests__/TokenRevealDialog.test.tsx@@ -1,8 +1,26 @@-import { afterEach, describe, expect, it } from 'vitest';-import { cleanup, render, screen, fireEvent } from '@solidjs/testing-library';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { cleanup, render, screen, fireEvent, waitFor } from '@solidjs/testing-library';import { TokenRevealDialog } from '@/components/TokenRevealDialog';+import { copyToClipboard } from '@/utils/clipboard';+import { showSuccess, showError } from '@/utils/toast';import { showTokenReveal, dismissTokenReveal } from '@/stores/tokenReveal';+vi.mock('@/utils/clipboard', () => ({ copyToClipboard: vi.fn() }));+vi.mock('@/utils/toast', () => ({ showSuccess: vi.fn(), showError: vi.fn() }));++function deferredCopy() {+ let settle!: (success: boolean) => void;+ const promise = new Promise<boolean>((resolve) => {+ settle = resolve;+ });+ vi.mocked(copyToClipboard).mockReturnValueOnce(promise);+ return settle;+}++function reveal(token = 'synthetic-token-a') {+ showTokenReveal({ token, record: mockRecord, source: 'security' });+}+const mockRecord = {id: 'test-token',name: 'Integration token',@@ -15,6 +33,8 @@ describe('TokenRevealDialog', () => {afterEach(() => {dismissTokenReveal();cleanup();+ vi.resetAllMocks();+ vi.useRealTimers();});it('renders and dismisses the token dialog', async () => {@@ -61,4 +81,172 @@ describe('TokenRevealDialog', () => {const badge = await screen.findByText('PBS');expect(badge.className).toContain('bg-indigo-100');});++ it('replaces every displayed field when another reveal becomes current', async () => {+ render(() => <TokenRevealDialog />);+ reveal();+ expect(await screen.findByText('synthetic-token-a')).toBeInTheDocument();+ showTokenReveal({+ token: 'synthetic-token-b',+ record: {+ ...mockRecord,+ id: 'other-token',+ name: 'Replacement token',+ prefix: 'next',+ suffix: 'abcd',+ },+ source: 'pbs',+ note: 'Replacement-only guidance',+ });+ expect(screen.queryByText('synthetic-token-a')).not.toBeInTheDocument();+ expect(screen.queryByText('Integration token')).not.toBeInTheDocument();+ expect(screen.getByText('synthetic-token-b')).toBeInTheDocument();+ expect(screen.getByText('Replacement token')).toBeInTheDocument();+ expect(screen.getByText('next…abcd')).toBeInTheDocument();+ expect(screen.getByText('PBS')).toBeInTheDocument();+ expect(screen.getByText('Replacement-only guidance')).toBeInTheDocument();+ vi.mocked(copyToClipboard).mockResolvedValueOnce(true);+ fireEvent.click(screen.getByRole('button', { name: 'Copy token' }));+ expect(copyToClipboard).toHaveBeenCalledExactlyOnceWith('synthetic-token-b');+ await waitFor(() =>+ expect(screen.getByRole('button', { name: 'Copied!' })).toBeInTheDocument(),+ );+ });++ it('copies the current value once and reports pending and settled outcomes', async () => {+ const settle = deferredCopy();+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ const pending = screen.getByRole('button', { name: 'Copying…' });+ expect(pending).toBeDisabled();+ fireEvent.click(pending);+ expect(copyToClipboard).toHaveBeenCalledTimes(1);+ expect(copyToClipboard).toHaveBeenCalledWith('synthetic-token-a');+ expect(showSuccess).not.toHaveBeenCalled();+ settle(true);+ await waitFor(() => expect(screen.getByRole('button', { name: 'Copied!' })).toBeEnabled());+ expect(showSuccess).toHaveBeenCalledExactlyOnceWith('Token copied to clipboard');+ });++ it('reports failure only for the current attempt and allows a deliberate retry', async () => {+ const settle = deferredCopy();+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ settle(false);+ await waitFor(() => expect(showError).toHaveBeenCalledExactlyOnceWith('Failed to copy token'));+ expect(screen.getByRole('button', { name: 'Copy token' })).toBeEnabled();+ vi.mocked(copyToClipboard).mockResolvedValueOnce(true);+ fireEvent.click(screen.getByRole('button', { name: 'Copy token' }));+ await waitFor(() =>+ expect(screen.getByRole('button', { name: 'Copied!' })).toBeInTheDocument(),+ );+ expect(copyToClipboard).toHaveBeenCalledTimes(2);+ });++ it('withdraws an earlier success when a deliberate retry fails', async () => {+ vi.mocked(copyToClipboard).mockResolvedValueOnce(true);+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ await waitFor(() =>+ expect(screen.getByRole('button', { name: 'Copied!' })).toBeInTheDocument(),+ );+ const settle = deferredCopy();+ fireEvent.click(screen.getByRole('button', { name: 'Copied!' }));+ expect(screen.getByRole('button', { name: 'Copying…' })).toBeDisabled();+ settle(false);+ await waitFor(() => expect(screen.getByRole('button', { name: 'Copy token' })).toBeEnabled());+ expect(showSuccess).toHaveBeenCalledTimes(1);+ expect(showError).toHaveBeenCalledExactlyOnceWith('Failed to copy token');+ });++ it.each([true, false])(+ 'ignores a %s clipboard result after dismissal without reopening',+ async (success) => {+ const settle = deferredCopy();+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ fireEvent.click(screen.getByRole('button', { name: 'Dismiss' }));+ settle(success);+ await Promise.resolve();+ await Promise.resolve();+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();+ expect(showSuccess).not.toHaveBeenCalled();+ expect(showError).not.toHaveBeenCalled();+ },+ );++ it.each([true, false])(+ 'ignores a %s clipboard result after another reveal replaces it',+ async (success) => {+ const settle = deferredCopy();+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ // Reusing the same token bytes still creates a different reveal lifetime.+ reveal();+ settle(success);+ await Promise.resolve();+ await Promise.resolve();+ expect(screen.getByRole('button', { name: 'Copy token' })).toBeEnabled();+ expect(screen.queryByRole('button', { name: 'Copied!' })).not.toBeInTheDocument();+ expect(showSuccess).not.toHaveBeenCalled();+ expect(showError).not.toHaveBeenCalled();+ },+ );++ it.each([true, false])(+ 'ignores a %s clipboard result after dismissal and reopening',+ async (success) => {+ const settle = deferredCopy();+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ fireEvent.click(screen.getByRole('button', { name: 'Close token dialog' }));+ reveal('synthetic-token-b');+ settle(success);+ await Promise.resolve();+ await Promise.resolve();+ expect(screen.getByRole('button', { name: 'Copy token' })).toBeEnabled();+ expect(showSuccess).not.toHaveBeenCalled();+ expect(showError).not.toHaveBeenCalled();+ },+ );++ it.each([true, false])(+ 'ignores a %s clipboard result after the consuming dialog unmounts',+ async (success) => {+ const settle = deferredCopy();+ const { unmount } = render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(await screen.findByRole('button', { name: 'Copy token' }));+ unmount();+ settle(success);+ await Promise.resolve();+ await Promise.resolve();+ expect(showSuccess).not.toHaveBeenCalled();+ expect(showError).not.toHaveBeenCalled();+ },+ );++ it('does not let a previous copied timer erase the current reveal feedback', async () => {+ vi.useFakeTimers();+ vi.mocked(copyToClipboard).mockResolvedValue(true);+ render(() => <TokenRevealDialog />);+ reveal();+ fireEvent.click(screen.getByRole('button', { name: 'Copy token' }));+ await Promise.resolve();+ expect(screen.getByRole('button', { name: 'Copied!' })).toBeInTheDocument();+ await vi.advanceTimersByTimeAsync(1500);+ reveal('synthetic-token-b');+ fireEvent.click(screen.getByRole('button', { name: 'Copy token' }));+ await Promise.resolve();+ await vi.advanceTimersByTimeAsync(600);+ expect(screen.getByRole('button', { name: 'Copied!' })).toBeInTheDocument();+ await vi.advanceTimersByTimeAsync(1400);+ expect(screen.getByRole('button', { name: 'Copy token' })).toBeInTheDocument();+ });});