mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
* feature: refine assistant artifact feedback * fix: clear hidden custom feedback reason * test: update assistant feedback expectations
128 lines
3.7 KiB
TypeScript
128 lines
3.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
/**
|
|
* Visibility-gate coverage for assistant artifact feedback (issue #1288).
|
|
* Feedback should only appear for successful assistant turns that produce
|
|
* or update an artifact, not for text-only acknowledgements, failed runs,
|
|
* streaming turns, or empty responses.
|
|
*/
|
|
|
|
import { cleanup, render, screen } from '@testing-library/react';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { AssistantMessage } from '../../src/components/AssistantMessage';
|
|
import type { ChatMessage, ProjectFile } from '../../src/types';
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
window.localStorage.clear();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
window.localStorage.clear();
|
|
});
|
|
|
|
function baseMessage(overrides: Partial<ChatMessage> = {}): ChatMessage {
|
|
return {
|
|
id: 'msg-1',
|
|
role: 'assistant',
|
|
content: 'Done.',
|
|
runStatus: 'succeeded',
|
|
startedAt: 1700000000,
|
|
endedAt: 1700000005,
|
|
events: [{ kind: 'text', text: 'Done.' } as ChatMessage['events'][number]],
|
|
producedFiles: [],
|
|
...overrides,
|
|
} as ChatMessage;
|
|
}
|
|
|
|
function producedFile(name: string): ProjectFile {
|
|
return {
|
|
name,
|
|
path: name,
|
|
size: 100,
|
|
updatedAt: 1700000005,
|
|
kind: 'html',
|
|
} as ProjectFile;
|
|
}
|
|
|
|
describe('AssistantMessage feedback gate (issue #1288)', () => {
|
|
it('shows the feedback widget after a successful turn that produced files', () => {
|
|
render(
|
|
<AssistantMessage
|
|
message={baseMessage({ producedFiles: [producedFile('index.html')] })}
|
|
streaming={false}
|
|
projectId="proj-1"
|
|
onFeedback={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole('group', { name: 'Feedback' })).toBeTruthy();
|
|
expect(screen.getByRole('button', { name: 'Helpful' })).toBeTruthy();
|
|
expect(screen.getByRole('button', { name: 'Not helpful' })).toBeTruthy();
|
|
});
|
|
|
|
it('hides the feedback widget for a successful text-only turn with no producedFiles', () => {
|
|
// Regression for lefarcen P2: the issue scopes feedback to
|
|
// turns that delivered a final artifact, not every successful
|
|
// turn. Text-only acknowledgements ("Got it.") must not prompt
|
|
// for feedback.
|
|
render(
|
|
<AssistantMessage
|
|
message={baseMessage({ producedFiles: [] })}
|
|
streaming={false}
|
|
projectId="proj-1"
|
|
onFeedback={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.queryByRole('group', { name: 'Feedback' })).toBeNull();
|
|
});
|
|
|
|
it('hides the feedback widget while the turn is still streaming', () => {
|
|
render(
|
|
<AssistantMessage
|
|
message={baseMessage({
|
|
producedFiles: [producedFile('index.html')],
|
|
runStatus: 'running',
|
|
endedAt: undefined,
|
|
})}
|
|
streaming
|
|
projectId="proj-1"
|
|
onFeedback={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.queryByRole('group', { name: 'Feedback' })).toBeNull();
|
|
});
|
|
|
|
it('hides the feedback widget when the run failed', () => {
|
|
render(
|
|
<AssistantMessage
|
|
message={baseMessage({
|
|
producedFiles: [producedFile('index.html')],
|
|
runStatus: 'failed',
|
|
})}
|
|
streaming={false}
|
|
projectId="proj-1"
|
|
onFeedback={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.queryByRole('group', { name: 'Feedback' })).toBeNull();
|
|
});
|
|
|
|
it('hides the feedback widget when the run ended with an empty_response status', () => {
|
|
render(
|
|
<AssistantMessage
|
|
message={baseMessage({
|
|
producedFiles: [producedFile('index.html')],
|
|
events: [
|
|
{ kind: 'status', label: 'empty_response' } as ChatMessage['events'][number],
|
|
],
|
|
})}
|
|
streaming={false}
|
|
projectId="proj-1"
|
|
onFeedback={vi.fn()}
|
|
/>,
|
|
);
|
|
expect(screen.queryByRole('group', { name: 'Feedback' })).toBeNull();
|
|
});
|
|
});
|