From ad5046655d99b58062676733f096381832fa92b4 Mon Sep 17 00:00:00 2001 From: dimavedenyapin Date: Thu, 23 Apr 2026 22:13:53 +0700 Subject: [PATCH] fix: guard malformed task output fields --- .../tasks/OutputFieldsDisplay.test.tsx | 20 ++++++++++ .../components/tasks/OutputFieldsDisplay.tsx | 31 ++++++++------ src/renderer/src/stores/task-store.test.ts | 31 +++++++++++++- src/renderer/src/stores/task-store.ts | 40 ++++++++++++++++++- 4 files changed, 107 insertions(+), 15 deletions(-) diff --git a/src/renderer/src/components/tasks/OutputFieldsDisplay.test.tsx b/src/renderer/src/components/tasks/OutputFieldsDisplay.test.tsx index a4410ac0..e658f1b1 100644 --- a/src/renderer/src/components/tasks/OutputFieldsDisplay.test.tsx +++ b/src/renderer/src/components/tasks/OutputFieldsDisplay.test.tsx @@ -122,4 +122,24 @@ describe('OutputFieldsDisplay', () => { expect(screen.getByText('Complete Task')).toBeInTheDocument() }) + + it('renders malformed legacy output fields without crashing', () => { + render( + + ) + + expect(screen.getByDisplayValue('https://example.com/pr/123')).toBeInTheDocument() + expect(screen.getByText('pr url')).toBeInTheDocument() + expect(screen.getByPlaceholderText('Enter pr url...')).toBeInTheDocument() + }) }) diff --git a/src/renderer/src/components/tasks/OutputFieldsDisplay.tsx b/src/renderer/src/components/tasks/OutputFieldsDisplay.tsx index bf516b92..1fd9434c 100644 --- a/src/renderer/src/components/tasks/OutputFieldsDisplay.tsx +++ b/src/renderer/src/components/tasks/OutputFieldsDisplay.tsx @@ -9,6 +9,12 @@ import { Label } from '@/components/ui/Label' import { shellApi } from '@/lib/ipc-client' import type { OutputField } from '@/types' +function getFieldLabel(field: OutputField): string { + if (typeof field.name === 'string' && field.name.trim()) return field.name + if (typeof field.id === 'string' && field.id.trim()) return field.id.replace(/_/g, ' ') + return 'Output' +} + function isFieldFilled(field: OutputField): boolean { const v = field.value if (v === null || v === undefined) return false @@ -68,6 +74,7 @@ export function OutputFieldsDisplay({ fields, onChange, isActive, onComplete, ta function OutputFieldInput({ field, onValueChange, taskUpdatedAt }: { field: OutputField; onValueChange: (value: unknown) => void; taskUpdatedAt?: string }) { const [localValue, setLocalValue] = useState(String(field.value ?? '')) + const fieldLabel = getFieldLabel(field) // Sync local state when field.value changes externally (e.g. agent extraction) useEffect(() => { @@ -84,13 +91,13 @@ function OutputFieldInput({ field, onValueChange, taskUpdatedAt }: { field: Outp return (