add prompt
This commit is contained in:
parent
30cde54483
commit
a8fa4d7e0d
|
|
@ -78,7 +78,7 @@ export const ReportView: React.FC<{
|
||||||
return result;
|
return result;
|
||||||
}, [report, filter]);
|
}, [report, filter]);
|
||||||
|
|
||||||
return <MetadataContext.Provider value={gitCommitInfo}><div className='htmlreport vbox px-4 pb-4'>
|
return <GitCommitInfoContext.Provider value={gitCommitInfo}><div className='htmlreport vbox px-4 pb-4'>
|
||||||
<main>
|
<main>
|
||||||
{report?.json() && <HeaderView stats={report.json().stats} filterText={filterText} setFilterText={setFilterText}></HeaderView>}
|
{report?.json() && <HeaderView stats={report.json().stats} filterText={filterText} setFilterText={setFilterText}></HeaderView>}
|
||||||
<Route predicate={testFilesRoutePredicate}>
|
<Route predicate={testFilesRoutePredicate}>
|
||||||
|
|
@ -94,7 +94,7 @@ export const ReportView: React.FC<{
|
||||||
{!!report && <TestCaseViewLoader report={report} tests={filteredTests.tests} testIdToFileIdMap={testIdToFileIdMap} />}
|
{!!report && <TestCaseViewLoader report={report} tests={filteredTests.tests} testIdToFileIdMap={testIdToFileIdMap} />}
|
||||||
</Route>
|
</Route>
|
||||||
</main>
|
</main>
|
||||||
</div></MetadataContext.Provider>;
|
</div></GitCommitInfoContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const TestCaseViewLoader: React.FC<{
|
const TestCaseViewLoader: React.FC<{
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,47 @@ import * as React from 'react';
|
||||||
import './testErrorView.css';
|
import './testErrorView.css';
|
||||||
import type { ImageDiff } from '@web/shared/imageDiffView';
|
import type { ImageDiff } from '@web/shared/imageDiffView';
|
||||||
import { ImageDiffView } from '@web/shared/imageDiffView';
|
import { ImageDiffView } from '@web/shared/imageDiffView';
|
||||||
|
import { GitCommitInfoContext } from './reportView';
|
||||||
|
|
||||||
export const TestErrorView: React.FC<{
|
export const TestErrorView: React.FC<{
|
||||||
error: string;
|
error: string;
|
||||||
testId?: string;
|
testId?: string;
|
||||||
}> = ({ error, testId }) => {
|
}> = ({ error, testId }) => {
|
||||||
const html = React.useMemo(() => ansiErrorToHtml(error), [error]);
|
const html = React.useMemo(() => ansiErrorToHtml(error), [error]);
|
||||||
return <div className='test-error-view test-error-text' data-testid={testId} dangerouslySetInnerHTML={{ __html: html || '' }}></div>;
|
return (
|
||||||
|
<div className='test-error-view test-error-text' data-testid={testId}>
|
||||||
|
<PromptButton error={error} />
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: html || '' }}></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ansiRegex = new RegExp('([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))', 'g');
|
||||||
|
export function stripAnsiEscapes(str: string): string {
|
||||||
|
return str.replace(ansiRegex, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const PromptButton: React.FC<{
|
||||||
|
error: string;
|
||||||
|
}> = ({ error }) => {
|
||||||
|
const gitCommitInfo = React.useContext(GitCommitInfoContext);
|
||||||
|
if (!gitCommitInfo)
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
const diff = gitCommitInfo['pull.diff'] ?? gitCommitInfo['revision.diff'];
|
||||||
|
if (!diff)
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button onClick={() => {
|
||||||
|
navigator.clipboard.writeText([
|
||||||
|
'You are a helpful assistant. Help me understand the error cause. Here is the error:',
|
||||||
|
stripAnsiEscapes(error),
|
||||||
|
'And this is the code diff:',
|
||||||
|
diff
|
||||||
|
].join('\n'));
|
||||||
|
}}>Copy AI Prompt</button>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TestScreenshotErrorView: React.FC<{
|
export const TestScreenshotErrorView: React.FC<{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue