Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions static/app/components/events/autofix/autofixRootCause.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
type CommentThread,
} from 'sentry/components/events/autofix/types';
import {makeAutofixQueryKey} from 'sentry/components/events/autofix/useAutofix';
import {formatRootCauseWithEvent} from 'sentry/components/events/autofix/utils';
import {IconArrow, IconChat, IconClose, IconCopy, IconFocus} from 'sentry/icons';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {Event} from 'sentry/types/event';
import {singleLineRenderer} from 'sentry/utils/marked/marked';
import {useMutation, useQueryClient} from 'sentry/utils/queryClient';
import testableTransition from 'sentry/utils/testableTransition';
Expand Down Expand Up @@ -70,6 +72,7 @@ type AutofixRootCauseProps = {
rootCauseSelection: AutofixRootCauseSelection;
runId: string;
agentCommentThread?: CommentThread;
event?: Event;
isRootCauseFirstAppearance?: boolean;
previousDefaultStepIndex?: number;
previousInsightCount?: number;
Expand Down Expand Up @@ -191,7 +194,7 @@ export function formatRootCauseText(
}

if (event.relevant_code_file) {
eventParts.push(`(See ${event.relevant_code_file.file_path})`);
eventParts.push(`(See @${event.relevant_code_file.file_path})`);
}

return eventParts.join('\n');
Expand All @@ -206,11 +209,13 @@ export function formatRootCauseText(
function CopyRootCauseButton({
cause,
customRootCause,
event,
}: {
cause?: AutofixRootCauseData;
customRootCause?: string;
event?: Event;
}) {
const text = formatRootCauseText(cause, customRootCause);
const text = formatRootCauseWithEvent(cause, customRootCause, event);
const {onClick, label} = useCopyToClipboard({
text,
});
Expand Down Expand Up @@ -238,6 +243,7 @@ function AutofixRootCauseDisplay({
previousDefaultStepIndex,
previousInsightCount,
agentCommentThread,
event,
}: AutofixRootCauseProps) {
const cause = causes[0];
const iconFocusRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -324,7 +330,10 @@ function AutofixRootCauseDisplay({
<CauseDescription>{rootCauseSelection.custom_root_cause}</CauseDescription>
<BottomDivider />
<BottomButtonContainer>
<CopyRootCauseButton customRootCause={rootCauseSelection.custom_root_cause} />
<CopyRootCauseButton
customRootCause={rootCauseSelection.custom_root_cause}
event={event}
/>
</BottomButtonContainer>
</CustomRootCausePadding>
</CausesContainer>
Expand Down Expand Up @@ -424,7 +433,7 @@ function AutofixRootCauseDisplay({
</SolutionInputContainer>
) : (
<ButtonBar>
<CopyRootCauseButton cause={cause} />
<CopyRootCauseButton cause={cause} event={event} />
<Button
size="sm"
onClick={handleMySolution}
Expand Down
16 changes: 14 additions & 2 deletions static/app/components/events/autofix/autofixSolution.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import {
} from 'sentry-test/reactTestingLibrary';

import {AutofixSolution} from 'sentry/components/events/autofix/autofixSolution';
import type {AutofixSolutionTimelineEvent} from 'sentry/components/events/autofix/types';
import {useAutofixRepos} from 'sentry/components/events/autofix/useAutofix';
import {
type AutofixData,
type AutofixSolutionTimelineEvent,
} from 'sentry/components/events/autofix/types';
import {
useAutofixData,
useAutofixRepos,
} from 'sentry/components/events/autofix/useAutofix';

jest.mock('sentry/components/events/autofix/useAutofix');

Expand Down Expand Up @@ -45,6 +51,12 @@ describe('AutofixSolution', () => {
codebases: {},
});

jest.mocked(useAutofixData).mockReset();
jest.mocked(useAutofixData).mockReturnValue({
data: {} as AutofixData,
isPending: false,
});

MockApiClient.addMockResponse({
url: '/organizations/org-slug/issues/123/',
method: 'GET',
Expand Down
37 changes: 29 additions & 8 deletions static/app/components/events/autofix/autofixSolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import {
} from 'sentry/components/events/autofix/types';
import {
makeAutofixQueryKey,
useAutofixData,
useAutofixRepos,
type AutofixResponse,
} from 'sentry/components/events/autofix/useAutofix';
import {formatSolutionWithEvent} from 'sentry/components/events/autofix/utils';
import {Timeline} from 'sentry/components/timeline';
import {IconAdd, IconChat, IconCopy, IconFix} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {Event} from 'sentry/types/event';
import {trackAnalytics} from 'sentry/utils/analytics';
import {singleLineRenderer} from 'sentry/utils/marked/marked';
import {valueIsEqual} from 'sentry/utils/object/valueIsEqual';
Expand Down Expand Up @@ -119,6 +122,7 @@ type AutofixSolutionProps = {
changesDisabled?: boolean;
customSolution?: string;
description?: string;
event?: Event;
isSolutionFirstAppearance?: boolean;
previousDefaultStepIndex?: number;
previousInsightCount?: number;
Expand Down Expand Up @@ -264,27 +268,27 @@ export function formatSolutionText(
}

if (customSolution) {
return `# Proposed Changes\n\n${customSolution}`;
return `# Solution Plan\n\n${customSolution}`;
}

if (!solution || solution.length === 0) {
return '';
}

const parts = ['# Proposed Changes'];
const parts = ['# Solution Plan'];

parts.push(
solution
.filter(event => event.is_active)
.map(event => {
const eventParts = [`### ${event.title}`];
.map((event, index) => {
const eventParts = [`### ${index + 1}. ${event.title}`];

if (event.code_snippet_and_analysis) {
eventParts.push(event.code_snippet_and_analysis);
}

if (event.relevant_code_file) {
eventParts.push(`(See ${event.relevant_code_file.file_path})`);
eventParts.push(`(See @${event.relevant_code_file.file_path})`);
}

return eventParts.join('\n');
Expand All @@ -298,13 +302,17 @@ export function formatSolutionText(
function CopySolutionButton({
solution,
customSolution,
event,
isEditing,
rootCause,
}: {
solution: AutofixSolutionTimelineEvent[];
customSolution?: string;
event?: Event;
isEditing?: boolean;
rootCause?: any;
}) {
const text = formatSolutionText(solution, customSolution);
const text = formatSolutionWithEvent(solution, customSolution, event, rootCause);
const {onClick, label} = useCopyToClipboard({
text,
});
Expand Down Expand Up @@ -338,12 +346,20 @@ function AutofixSolutionDisplay({
customSolution,
solutionSelected,
agentCommentThread,
event,
}: Omit<AutofixSolutionProps, 'repos'>) {
const organization = useOrganization();
const {data: group} = useGroup({groupId});
const project = group?.project;

const {repos} = useAutofixRepos(groupId);
const {data: autofixData} = useAutofixData({groupId});

// Get root cause data from autofix data
const rootCauseStep = autofixData?.steps?.find(
step => step.type === AutofixStepType.ROOT_CAUSE_ANALYSIS
);
const rootCause = rootCauseStep?.causes?.[0];
const {mutate: handleContinue, isPending} = useSelectSolution({groupId, runId});
const [instructions, setInstructions] = useState('');
const [solutionItems, setSolutionItems] = useState<AutofixSolutionTimelineEvent[]>( // This will become outdated if multiple people use it, but we can ignore this for now.
Expand Down Expand Up @@ -474,7 +490,12 @@ function AutofixSolutionDisplay({
<BottomDivider />
<BottomFooter>
<div style={{flex: 1}} />
<CopySolutionButton solution={solution} customSolution={customSolution} />
<CopySolutionButton
solution={solution}
customSolution={customSolution}
event={event}
rootCause={rootCause}
/>
</BottomFooter>
</CustomSolutionPadding>
</SolutionContainer>
Expand Down Expand Up @@ -558,7 +579,7 @@ function AutofixSolutionDisplay({
</InstructionsInputWrapper>
</AddInstructionWrapper>
<ButtonBar>
<CopySolutionButton solution={solution} />
<CopySolutionButton solution={solution} event={event} rootCause={rootCause} />
<Tooltip
isHoverable
title={
Expand Down
9 changes: 8 additions & 1 deletion static/app/components/events/autofix/autofixSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import {getAutofixRunErrorMessage} from 'sentry/components/events/autofix/utils';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {Event} from 'sentry/types/event';
import testableTransition from 'sentry/utils/testableTransition';
import useOrganization from 'sentry/utils/useOrganization';

Expand All @@ -35,6 +36,7 @@ interface StepProps {
hasStepBelow: boolean;
runId: string;
step: AutofixStep;
event?: Event;
isAutoTriggeredRun?: boolean;
isChangesFirstAppearance?: boolean;
isRootCauseFirstAppearance?: boolean;
Expand All @@ -48,6 +50,7 @@ interface AutofixStepsProps {
data: AutofixData;
groupId: string;
runId: string;
event?: Event;
}

function isProgressLog(
Expand All @@ -69,6 +72,7 @@ function Step({
isSolutionFirstAppearance,
isChangesFirstAppearance,
isAutoTriggeredRun,
event,
}: StepProps) {
return (
<StepCard id={`autofix-step-${step.id}`} data-step-type={step.type}>
Expand Down Expand Up @@ -103,6 +107,7 @@ function Step({
previousDefaultStepIndex={previousDefaultStepIndex}
previousInsightCount={previousInsightCount}
isRootCauseFirstAppearance={isRootCauseFirstAppearance}
event={event}
/>
)}
{step.type === AutofixStepType.SOLUTION && (
Expand All @@ -117,6 +122,7 @@ function Step({
previousInsightCount={previousInsightCount}
agentCommentThread={step.agent_comment_thread ?? undefined}
isSolutionFirstAppearance={isSolutionFirstAppearance}
event={event}
/>
)}
{step.type === AutofixStepType.CHANGES && (
Expand All @@ -138,7 +144,7 @@ function Step({
);
}

export function AutofixSteps({data, groupId, runId}: AutofixStepsProps) {
export function AutofixSteps({data, groupId, runId, event}: AutofixStepsProps) {
const organization = useOrganization();
const codingDisabled =
organization.enableSeerCoding === undefined ? false : !organization.enableSeerCoding;
Expand Down Expand Up @@ -245,6 +251,7 @@ export function AutofixSteps({data, groupId, runId}: AutofixStepsProps) {
step.type === AutofixStepType.CHANGES && !isInitialMount
}
isAutoTriggeredRun={isAutoTriggeredRun}
event={event}
/>
</div>
);
Expand Down
43 changes: 43 additions & 0 deletions static/app/components/events/autofix/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import {
AutofixStepType,
type AutofixCodebaseChange,
type AutofixData,
type AutofixRootCauseData,
type AutofixSolutionTimelineEvent,
} from 'sentry/components/events/autofix/types';
import {t} from 'sentry/locale';
import type {Event} from 'sentry/types/event';
import type {Group} from 'sentry/types/group';
import {formatEventToMarkdown} from 'sentry/views/issueDetails/streamline/hooks/useCopyIssueDetails';

export function getRootCauseDescription(autofixData: AutofixData) {
const rootCause = autofixData.steps?.find(
Expand Down Expand Up @@ -59,6 +63,45 @@ export function getSolutionCopyText(autofixData: AutofixData) {
return formatSolutionText(solution.solution, solution.custom_solution);
}

export function formatRootCauseWithEvent(
cause: AutofixRootCauseData | undefined,
customRootCause: string | undefined,
event: Event | undefined
): string {
const rootCauseText = formatRootCauseText(cause, customRootCause);

if (!event) {
return rootCauseText;
}

const eventText = '\n# Raw Event Data\n' + formatEventToMarkdown(event);
return rootCauseText + eventText;
}

export function formatSolutionWithEvent(
solution: AutofixSolutionTimelineEvent[] | undefined,
customSolution: string | undefined,
event: Event | undefined,
rootCause?: AutofixRootCauseData
): string {
let combinedText = '';

if (rootCause) {
const rootCauseText = formatRootCauseText(rootCause);
combinedText += rootCauseText + '\n\n';
}

const solutionText = formatSolutionText(solution || [], customSolution);
combinedText += solutionText;

if (event) {
const eventText = '\n# Raw Event Data\n' + formatEventToMarkdown(event);
combinedText += eventText;
}

return combinedText;
}

export function getSolutionIsLoading(autofixData: AutofixData) {
const solutionProgressStep = autofixData.steps?.find(
step => step.key === 'solution_processing'
Expand Down
Loading
Loading