Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(chat): remove ArtifactCard component and its tests

Steven Enamakelb74b29fc2f4f
diff --git a/app/src/components/chat/ArtifactCard.tsx b/app/src/components/chat/ArtifactCard.tsx
deleted file mode 100644
index e9fd2e5dd5..0000000000
--- a/app/src/components/chat/ArtifactCard.tsx
+++ /dev/null
@@ -1,261 +0,0 @@
-import { useState } from 'react';
-
-import { formatFileSize } from '../../lib/attachments';
-import { useT } from '../../lib/i18n/I18nContext';
-import {
- revealArtifactInFileManager,
- saveArtifactViaDialog,
-} from '../../services/artifactDownloadService';
-import type { ArtifactSnapshot } from '../../store/chatRuntimeSlice';
-import { Button } from '../ui';
-import { extensionFor } from './artifactExtension';
-
-/**
- * Inline chat card surfacing a single agent-generated artifact (#2779).
- *
- * Renders three visual states keyed off `artifact.status`:
- *
- * - `in_progress` — pulsing dot + title + "Generating <kind>…" label.
- * Derived state: a `ChatToolCallEvent` for an artifact-producing
- * tool was seen but no `artifact_ready` / `artifact_failed` has
- * landed yet.
- * - `ready` — kind icon + title + human-readable size + Download
- * button. Click → `downloadArtifact()` → "Saved to …" w/ a
- * "Show in folder" link.
- * - `failed` — error icon + title + producer-supplied reason +
- * optional Retry button (only when `onRetry` is provided).
- *
- * Visual style mirrors `ApprovalRequestCard` / `AttachmentPreview`:
- * rounded card, dark/light Tailwind variants, mono accents on
- * numeric values, inline SVG icons. No new icon dependency.
- */
-interface ArtifactCardProps {
- artifact: ArtifactSnapshot;
- /** When provided, render a Retry button on the `failed` state. */
- onRetry?: (artifactId: string) => void;
-}
-
-function KindIcon({ kind }: { kind: ArtifactSnapshot['kind'] }) {
- const stroke = 'currentColor';
- switch (kind) {
- case 'presentation':
- return (
- <svg
- aria-hidden="true"
- className="w-5 h-5 shrink-0"
- fill="none"
- stroke={stroke}
- strokeWidth={1.8}
- viewBox="0 0 24 24">
- <path strokeLinecap="round" strokeLinejoin="round" d="M3 5h18v12H3z" />
- <path strokeLinecap="round" d="M8 21h8M12 17v4" />
- <path strokeLinecap="round" strokeLinejoin="round" d="M7 11l3 3 4-5 3 4" />
- </svg>
- );
- case 'document':
- return (
- <svg
- aria-hidden="true"
- className="w-5 h-5 shrink-0"
- fill="none"
- stroke={stroke}
- strokeWidth={1.8}
- viewBox="0 0 24 24">
- <path
- strokeLinecap="round"
- strokeLinejoin="round"
- d="M14 3H7a2 2 0 00-2 2v14a2 2 0 002 2h10a2 2 0 002-2V8z"
- />
- <path strokeLinecap="round" d="M14 3v5h5M9 13h6M9 17h6" />
- </svg>
- );
- case 'image':
- return (
- <svg
- aria-hidden="true"
- className="w-5 h-5 shrink-0"
- fill="none"
- stroke={stroke}
- strokeWidth={1.8}
- viewBox="0 0 24 24">
- <path strokeLinecap="round" strokeLinejoin="round" d="M3 5h18v14H3z" />
- <circle cx="9" cy="10" r="1.5" />
- <path strokeLinecap="round" strokeLinejoin="round" d="M3 17l5-5 4 4 3-3 6 6" />
- </svg>
- );
- default:
- return (
- <svg
- aria-hidden="true"
- className="w-5 h-5 shrink-0"
- fill="none"
- stroke={stroke}
- strokeWidth={1.8}
- viewBox="0 0 24 24">
- <path strokeLinecap="round" strokeLinejoin="round" d="M4 4h16v16H4z" />
- </svg>
- );
- }
-}
-
-function Spinner() {
- return (
- <svg
- aria-hidden="true"
- className="w-5 h-5 shrink-0 animate-spin"
- fill="none"
- viewBox="0 0 24 24">
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="3" />
- <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z" />
- </svg>
- );
-}
-
-function FailedIcon() {
- return (
- <svg
- aria-hidden="true"
- className="w-5 h-5 shrink-0 text-coral-500"
- fill="none"
- stroke="currentColor"
- strokeWidth={1.8}
- viewBox="0 0 24 24">
- <circle cx="12" cy="12" r="9" />
- <path strokeLinecap="round" d="M12 8v4M12 16h.01" />
- </svg>
- );
-}
-
-/**
- * Cap the visible failure reason at ~280 chars. Producer-side errors
- * can be enormous (e.g. a multi-KB pip stderr from a failed venv
- * setup — observed at 13K chars in dev:app on 2026-05-30) and
- * dumping that raw into a flex card breaks layout + can freeze the
- * scrolling page. We collapse by default and let the user expand
- * via "Show more" if they actually want to read it.
- */
-const ERROR_REASON_PREVIEW_CHARS = 280;
-
-export default function ArtifactCard({ artifact, onRetry }: ArtifactCardProps) {
- const { t } = useT();
- const [download, setDownload] = useState<{
- state: 'idle' | 'downloading' | 'done' | 'error';
- path?: string;
- error?: string;
- }>({ state: 'idle' });
- const [errorExpanded, setErrorExpanded] = useState(false);
-
- const handleDownload = async () => {
- setDownload({ state: 'downloading' });
- const ext = extensionFor(artifact.kind, artifact.title);
- const outcome = await saveArtifactViaDialog(artifact.artifactId, artifact.title, ext);
- if (outcome.ok) {
- setDownload({ state: 'done', path: outcome.path });
- } else if (outcome.code === 'CANCELLED') {
- // User dismissed the Save-As dialog — quietly return to idle.
- setDownload({ state: 'idle' });
- } else {
- setDownload({ state: 'error', error: outcome.error });
- }
- };
-
- const handleReveal = async () => {
- if (download.path) {
- await revealArtifactInFileManager(download.path);
- }
- };
-
- return (
- <div
- role="group"
- aria-label={t('chat.artifact.aria').replace('{title}', artifact.title)}
- className="flex flex-col gap-1.5 rounded-xl border border-line bg-surface-muted px-3 py-2.5 text-sm text-content-secondary max-w-[420px]">
- <div className="flex items-center gap-2.5">
- {artifact.status === 'in_progress' ? (
- <Spinner />
- ) : artifact.status === 'failed' ? (
- <FailedIcon />
- ) : (
- <KindIcon kind={artifact.kind} />
- )}
- <div className="flex flex-col min-w-0 flex-1">
- <span className="truncate font-medium leading-tight">{artifact.title}</span>
- <span className="text-xs text-content-muted leading-tight font-mono">
- {artifact.status === 'in_progress'
- ? t('chat.artifact.generating').replace('{kind}', artifact.kind)
- : artifact.status === 'ready' && artifact.sizeBytes != null
- ? `${t('chat.artifact.ready')} · ${formatFileSize(artifact.sizeBytes)}`
- : artifact.status === 'failed'
- ? t('chat.artifact.failed')
- : ''}
- </span>
- </div>
- {artifact.status === 'ready' && download.state !== 'done' && (
- <Button
- variant="primary"
- size="xs"
- analyticsId={`chat-artifact-download-${artifact.kind}`}
- onClick={handleDownload}
- disabled={download.state === 'downloading'}
- className="ml-auto">
- {download.state === 'downloading'
- ? t('chat.artifact.downloading')
- : t('chat.artifact.download')}
- </Button>
- )}
- {artifact.status === 'failed' && onRetry && (
- <Button
- variant="secondary"
- size="xs"
- analyticsId={`chat-artifact-retry-${artifact.kind}`}
- onClick={() => onRetry(artifact.artifactId)}
- className="ml-auto">
- {t('chat.artifact.retry')}
- </Button>
- )}
- </div>
- {artifact.status === 'failed' && artifact.error && (
- <div className="text-xs text-coral-600 dark:text-coral-400 mt-1">
- <p
- className={`font-mono wrap-break-word whitespace-pre-wrap ${
- errorExpanded ? 'max-h-48 overflow-y-auto' : ''
- }`}>
- {errorExpanded || artifact.error.length <= ERROR_REASON_PREVIEW_CHARS
- ? artifact.error
- : `${artifact.error.slice(0, ERROR_REASON_PREVIEW_CHARS)}…`}
- </p>
- {artifact.error.length > ERROR_REASON_PREVIEW_CHARS && (
- <Button
- variant="tertiary"
- size="xs"
- analyticsId="chat-artifact-error-toggle"
- onClick={() => setErrorExpanded(prev => !prev)}
- className="mt-1 h-auto! p-0! underline text-coral-700 hover:bg-transparent hover:text-coral-900">
- {errorExpanded ? t('chat.artifact.show_less') : t('chat.artifact.show_more')}
- </Button>
- )}
- </div>
- )}
- {download.state === 'done' && download.path && (
- <div className="flex items-center gap-2 text-xs text-sage-600 mt-1">
- <span className="truncate font-mono">
- {t('chat.artifact.downloaded').replace('{path}', download.path)}
- </span>
- <Button
- variant="tertiary"
- size="xs"
- analyticsId={`chat-artifact-reveal-${artifact.kind}`}
- onClick={handleReveal}
- className="ml-auto h-auto! p-0! underline text-sage-600 hover:bg-transparent hover:text-sage-800 shrink-0">
- {t('chat.artifact.reveal')}
- </Button>
- </div>
- )}
- {download.state === 'error' && download.error && (
- <p className="text-xs text-coral-600 mt-1 wrap-break-word">
- {t('chat.artifact.download_failed').replace('{reason}', download.error)}
- </p>
- )}
- </div>
- );
-}
diff --git a/app/src/components/chat/__tests__/ArtifactCard.test.tsx b/app/src/components/chat/__tests__/ArtifactCard.test.tsx
deleted file mode 100644
index 096048a568..0000000000
--- a/app/src/components/chat/__tests__/ArtifactCard.test.tsx
+++ /dev/null
@@ -1,252 +0,0 @@
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
-
-import {
- revealArtifactInFileManager,
- saveArtifactViaDialog,
-} from '../../../services/artifactDownloadService';
-import type { ArtifactSnapshot } from '../../../store/chatRuntimeSlice';
-import ArtifactCard from '../ArtifactCard';
-
-vi.mock('../../../services/artifactDownloadService', () => ({
- saveArtifactViaDialog: vi.fn(),
- revealArtifactInFileManager: vi.fn(),
-}));
-
-function inProgress(overrides: Partial<ArtifactSnapshot> = {}): ArtifactSnapshot {
- return {
- artifactId: 'art-1',
- kind: 'presentation',
- title: 'Climate Deck',
- status: 'in_progress',
- updatedAt: Date.now(),
- ...overrides,
- };
-}
-
-function ready(overrides: Partial<ArtifactSnapshot> = {}): ArtifactSnapshot {
- return {
- artifactId: 'art-1',
- kind: 'presentation',
- title: 'Climate Deck',
- status: 'ready',
- path: 'artifacts/art-1.pptx',
- sizeBytes: 4096,
- updatedAt: Date.now(),
- ...overrides,
- };
-}
-
-function failed(overrides: Partial<ArtifactSnapshot> = {}): ArtifactSnapshot {
- return {
- artifactId: 'art-1',
- kind: 'presentation',
- title: 'Climate Deck',
- status: 'failed',
- error: 'producer crashed',
- updatedAt: Date.now(),
- ...overrides,
- };
-}
-
-describe('ArtifactCard', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- });
-
- // ─── in_progress ────────────────────────────────────────────────────────
-
- it('renders the in-progress label and no download button', () => {
- render(<ArtifactCard artifact={inProgress()} />);
- expect(screen.getByText(/Generating presentation/)).toBeInTheDocument();
- // No download button while in progress
- expect(screen.queryByRole('button', { name: /Download/ })).toBeNull();
- // role=group + aria carries the title
- expect(screen.getByRole('group', { name: /Climate Deck/ })).toBeInTheDocument();
- });
-
- // ─── ready ──────────────────────────────────────────────────────────────
-
- it('renders the size + Download button when ready', () => {
- render(<ArtifactCard artifact={ready({ sizeBytes: 4096 })} />);
- expect(screen.getByText(/Ready/)).toBeInTheDocument();
- // 4096 bytes → "4.0 KB" per formatFileSize
- expect(screen.getByText(/4\.0 KB/)).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Download' })).toBeInTheDocument();
- });
-
- it('on Download click → calls saveArtifactViaDialog with title-derived extension on success', async () => {
- vi.mocked(saveArtifactViaDialog).mockResolvedValueOnce({
- ok: true,
- path: '/Users/me/Downloads/Climate Deck.pptx',
- });
- render(<ArtifactCard artifact={ready({ title: 'climate-deck.pptx' })} />);
- fireEvent.click(screen.getByRole('button', { name: 'Download' }));
- await waitFor(() => {
- expect(saveArtifactViaDialog).toHaveBeenCalledWith('art-1', 'climate-deck.pptx', 'pptx');
- });
- // Saved-to label appears with the resolved path
- await waitFor(() => {
- expect(screen.getByText(/Saved to/)).toBeInTheDocument();
- });
- // Reveal button appears and the original Download button is gone
- expect(screen.getByRole('button', { name: 'Show in folder' })).toBeInTheDocument();
- expect(screen.queryByRole('button', { name: 'Download' })).toBeNull();
- });
-
- it('on Reveal click → calls revealArtifactInFileManager with the saved path', async () => {
- vi.mocked(saveArtifactViaDialog).mockResolvedValueOnce({
- ok: true,
- path: '/Users/me/Downloads/Climate Deck.pptx',
- });
- render(<ArtifactCard artifact={ready()} />);
- fireEvent.click(screen.getByRole('button', { name: 'Download' }));
- await waitFor(() => {
- expect(screen.getByRole('button', { name: 'Show in folder' })).toBeInTheDocument();
- });
- fireEvent.click(screen.getByRole('button', { name: 'Show in folder' }));
- await waitFor(() => {
- expect(revealArtifactInFileManager).toHaveBeenCalledWith(
- '/Users/me/Downloads/Climate Deck.pptx'
- );
- });
- });
-
- it('on Download failure → surfaces the error reason and leaves the Download button in place', async () => {
- vi.mocked(saveArtifactViaDialog).mockResolvedValueOnce({
- ok: false,
- code: 'NOT_DESKTOP',
- error: 'Downloads are only available in the desktop app',
- });
- render(<ArtifactCard artifact={ready()} />);
- fireEvent.click(screen.getByRole('button', { name: 'Download' }));
- await waitFor(() => {
- expect(screen.getByText(/Download failed:/)).toBeInTheDocument();
- });
- // Original Download button is still there for retry
- expect(screen.getByRole('button', { name: 'Download' })).toBeInTheDocument();
- // No "Show in folder" affordance on failure
- expect(screen.queryByRole('button', { name: 'Show in folder' })).toBeNull();
- });
-
- it.each([
- ['document' as const, 'docx'],
- ['image' as const, 'png'],
- ['other' as const, 'bin'],
- ['presentation' as const, 'pptx'],
- ])(
- 'falls back to per-kind extension when title lacks one (kind=%s → ext=%s)',
- async (kind, expectedExt) => {
- vi.mocked(saveArtifactViaDialog).mockResolvedValueOnce({ ok: true, path: '/d/x' });
- render(<ArtifactCard artifact={ready({ kind, title: 'no-extension' })} />);
- fireEvent.click(screen.getByRole('button', { name: 'Download' }));
- await waitFor(() => {
- expect(saveArtifactViaDialog).toHaveBeenCalledWith('art-1', 'no-extension', expectedExt);
- });
- }
- );
-
- it('treats a trailing-dot title as having no extension (falls through to kind default)', async () => {
- vi.mocked(saveArtifactViaDialog).mockResolvedValueOnce({ ok: true, path: '/d/x' });
- render(<ArtifactCard artifact={ready({ kind: 'presentation', title: 'trailing.' })} />);
- fireEvent.click(screen.getByRole('button', { name: 'Download' }));
- await waitFor(() => {
- expect(saveArtifactViaDialog).toHaveBeenCalledWith('art-1', 'trailing.', 'pptx');
- });
- });
-
- it('Download button is disabled while a download is in flight', async () => {
- let resolveDownload: (v: { ok: true; path: string }) => void = () => {};
- vi.mocked(saveArtifactViaDialog).mockImplementationOnce(
- () =>
- new Promise(r => {
- resolveDownload = r;
- })
- );
- render(<ArtifactCard artifact={ready()} />);
- const btn = screen.getByRole('button', { name: 'Download' });
- fireEvent.click(btn);
- // While in-flight, button text flips to "Downloading…" and is disabled.
- await waitFor(() => {
- expect(screen.getByRole('button', { name: 'Downloading…' })).toBeDisabled();
- });
- // Finish the download to settle the promise.
- resolveDownload({ ok: true, path: '/d/x.pptx' });
- await waitFor(() => {
- expect(screen.getByRole('button', { name: 'Show in folder' })).toBeInTheDocument();
- });
- });
-
- // ─── failed ─────────────────────────────────────────────────────────────
-
- it('renders the failed label and the producer-supplied reason', () => {
- render(<ArtifactCard artifact={failed({ error: 'pip install crashed' })} />);
- expect(screen.getByText(/Generation failed/)).toBeInTheDocument();
- expect(screen.getByText('pip install crashed')).toBeInTheDocument();
- });
-
- it('renders Retry only when onRetry is provided; clicking it fires the callback', () => {
- const onRetry = vi.fn();
- const a = failed();
- const { rerender } = render(<ArtifactCard artifact={a} />);
- // No Retry when onRetry is absent.
- expect(screen.queryByRole('button', { name: 'Retry' })).toBeNull();
-
- rerender(<ArtifactCard artifact={a} onRetry={onRetry} />);
- const retryBtn = screen.getByRole('button', { name: 'Retry' });
- fireEvent.click(retryBtn);
- expect(onRetry).toHaveBeenCalledWith('art-1');
- });
-
- it('long error reason is truncated by default and expands via Show more', () => {
- const longError = 'x'.repeat(400);
- render(<ArtifactCard artifact={failed({ error: longError })} />);
- // Truncated preview ends with ellipsis.
- const para = screen.getByText((_content, el) => {
- return !!el && el.tagName === 'P' && (el.textContent ?? '').endsWith('…');
- });
- expect(para).toBeInTheDocument();
- expect((para.textContent ?? '').length).toBeLessThan(longError.length);
-
- // Show more → full error visible + button flips to Show less.
- fireEvent.click(screen.getByRole('button', { name: 'Show more' }));
- expect(screen.getByText(longError)).toBeInTheDocument();
- expect(screen.getByRole('button', { name: 'Show less' })).toBeInTheDocument();
-
- // Show less → re-collapses.
- fireEvent.click(screen.getByRole('button', { name: 'Show less' }));
- expect(screen.getByRole('button', { name: 'Show more' })).toBeInTheDocument();
- });
-
- it('short error reason (≤ preview cap) does NOT show the Show more affordance', () => {
- render(<ArtifactCard artifact={failed({ error: 'short oops' })} />);
- expect(screen.getByText('short oops')).toBeInTheDocument();
- expect(screen.queryByRole('button', { name: 'Show more' })).toBeNull();
- });
-
- it('failed status uses the failed icon (not the kind icon) and no Download button', () => {
- render(<ArtifactCard artifact={failed()} />);
- expect(screen.queryByRole('button', { name: 'Download' })).toBeNull();
- });
-
- // ─── kind variants (icon paths) ─────────────────────────────────────────
-
- it.each(['presentation', 'document', 'image', 'other'] as const)(
- 'renders the in-progress spinner with the kind-specific label for kind=%s',
- kind => {
- render(<ArtifactCard artifact={inProgress({ kind })} />);
- // The generating sub-label reflects the artifact kind (e.g. "Generating
- // image") — folded in from the former sibling ArtifactCard.test.tsx.
- expect(screen.getByText(new RegExp(`Generating ${kind}`, 'i'))).toBeInTheDocument();
- }
- );
-
- it.each(['presentation', 'document', 'image', 'other'] as const)(
- 'renders the kind icon when ready for kind=%s',
- kind => {
- render(<ArtifactCard artifact={ready({ kind })} />);
- // Ready label is present regardless of kind.
- expect(screen.getByText(/Ready/)).toBeInTheDocument();
- }
- );
-});