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

fix: remove misleading playground copy confirmation

[._.]/ Adam Eivye52300106907
diff --git a/client/src/components/localLlm/PlaygroundOutput.jsx b/client/src/components/localLlm/PlaygroundOutput.jsx
index 9e67229f76..0e565c4f7e 100644
--- a/client/src/components/localLlm/PlaygroundOutput.jsx
+++ b/client/src/components/localLlm/PlaygroundOutput.jsx
@@ -1,5 +1,5 @@
import { useMemo, useState } from 'react';
-import { Check, Code2, Copy, Eye } from 'lucide-react';
+import { Code2, Copy, Eye } from 'lucide-react';
import MarkdownOutput from '../cos/MarkdownOutput';
import { copyToClipboard } from '../../lib/clipboard';
@@ -53,20 +53,6 @@ export function parseSegments(text) {
return segments;
}
-function CopyButton({ value, label = 'Copied' }) {
- const [copied, setCopied] = useState(false);
- return (
- <button
- onClick={() => { copyToClipboard(value, label); setCopied(true); setTimeout(() => setCopied(false), 1200); }}
- className="flex items-center gap-1 text-[11px] text-gray-400 hover:text-white"
- title="Copy code"
- >
- {copied ? <Check size={12} className="text-port-success" /> : <Copy size={12} />}
- {copied ? 'Copied' : 'Copy'}
- </button>
- );
-}
-
function CodeBlock({ lang, code, closed }) {
const htmlPreviewable = useMemo(() => isHtmlLike(lang, code), [lang, code]);
// 'code' | 'preview' — only meaningful when htmlPreviewable. Default to code so
@@ -97,7 +83,14 @@ function CodeBlock({ lang, code, closed }) {
</button>
</div>
)}
- <CopyButton value={code} label="Copied code" />
+ <button
+ type="button"
+ onClick={() => copyToClipboard(code, 'Copied code')}
+ className="flex items-center gap-1 text-[11px] text-gray-400 hover:text-white"
+ title="Copy code"
+ >
+ <Copy size={12} /> Copy
+ </button>
</div>
</div>
{showPreview ? (
diff --git a/client/src/components/localLlm/PlaygroundOutput.test.jsx b/client/src/components/localLlm/PlaygroundOutput.test.jsx
index 668e6a7e6b..2df9910db2 100644
--- a/client/src/components/localLlm/PlaygroundOutput.test.jsx
+++ b/client/src/components/localLlm/PlaygroundOutput.test.jsx
@@ -1,7 +1,15 @@
-import { describe, it, expect } from 'vitest';
-import { render, fireEvent } from '@testing-library/react';
+import { afterEach, describe, it, expect, vi } from 'vitest';
+import { render, fireEvent, waitFor } from '@testing-library/react';
import PlaygroundOutput, { parseSegments } from './PlaygroundOutput';
+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }));
+vi.mock('../ui/Toast', () => ({ default: toast }));
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.clearAllMocks();
+});
+
describe('parseSegments', () => {
it('splits prose and fenced code into ordered segments with the language captured', () => {
const segments = parseSegments('Here you go:\n```html\n<h1>Hi</h1>\n```\nDone.');
@@ -57,3 +65,28 @@ describe('PlaygroundOutput rendering', () => {
expect(getByText('Preview')).toBeTruthy();
});
});
+
+describe('code copying', () => {
+ it('reports success only after the code reaches the clipboard', async () => {
+ let finishWrite;
+ const writeText = vi.fn(() => new Promise(resolve => { finishWrite = resolve; }));
+ vi.stubGlobal('navigator', { clipboard: { writeText } });
+ const { getByTitle, queryByText } = render(<PlaygroundOutput text={'```js\nconst answer = 42;\n```'} />);
+ fireEvent.click(getByTitle('Copy code'));
+ expect(writeText).toHaveBeenCalledWith('const answer = 42;');
+ expect(queryByText('Copied')).toBeNull();
+ expect(toast.success).not.toHaveBeenCalled();
+ finishWrite();
+ await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Copied code'));
+ expect(toast.success).toHaveBeenCalledTimes(1);
+ });
+
+ it('reports a denied copy without a false Copied indicator', async () => {
+ vi.stubGlobal('navigator', { clipboard: { writeText: vi.fn().mockRejectedValue(new Error('denied')) } });
+ const { getByTitle, queryByText } = render(<PlaygroundOutput text={'```js\nconst answer = 42;\n```'} />);
+ fireEvent.click(getByTitle('Copy code'));
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Copy failed'));
+ expect(queryByText('Copied')).toBeNull();
+ expect(toast.success).not.toHaveBeenCalled();
+ });
+});