|
| 1 | +// @vitest-environment jsdom |
| 2 | +// |
| 3 | +// Companion to trace-viewer-user-snapshot.test.tsx, which pins the viewer's |
| 4 | +// own chrome but mocks SpanInfoPanel away — and SpanInfoPanel's chip row is |
| 5 | +// the one place the agent-trace work touched the customer path. This |
| 6 | +// snapshot renders the REAL SpanInfoPanel for a customer trace that carries a |
| 7 | +// user and a session and has no RCA, so the User:/Session: chips are pinned |
| 8 | +// with nothing new beside them. Never re-generate it (`-u`) once agent-trace |
| 9 | +// changes land. |
| 10 | +// |
| 11 | +// Scope, stated plainly: "byte-identical" holds for customer traces WITHOUT |
| 12 | +// an available RCA. A customer trace whose finding has a completed, exported |
| 13 | +// analysis intentionally gains the "Root cause analysis" chip in this row — |
| 14 | +// that is the feature's entry point, not a leak. |
| 15 | +process.env.TZ = "UTC"; |
| 16 | + |
| 17 | +import { describe, expect, it, vi } from "vitest"; |
| 18 | +import { render } from "@testing-library/react"; |
| 19 | + |
| 20 | +const trace = { |
| 21 | + trace_id: "t1", |
| 22 | + project_id: "p1", |
| 23 | + name: "agent_turn", |
| 24 | + source: "user", |
| 25 | + user_id: "user-42", |
| 26 | + session_id: "sess-7", |
| 27 | + trace_start_time: "2026-01-01T00:00:00Z", |
| 28 | + trace_end_time: "2026-01-01T00:00:01Z", |
| 29 | + spans: [ |
| 30 | + { |
| 31 | + span_id: "s1", |
| 32 | + parent_span_id: null, |
| 33 | + name: "agent_turn", |
| 34 | + span_kind: "AGENT", |
| 35 | + status: "OK", |
| 36 | + span_start_time: "2026-01-01T00:00:00Z", |
| 37 | + span_end_time: "2026-01-01T00:00:01Z", |
| 38 | + }, |
| 39 | + ], |
| 40 | +}; |
| 41 | + |
| 42 | +vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn() }) })); |
| 43 | +vi.mock("@tanstack/react-query", () => ({ |
| 44 | + useQuery: () => ({ data: trace, isLoading: false, error: null }), |
| 45 | +})); |
| 46 | +vi.mock("@/lib/api", () => ({ getTrace: vi.fn() })); |
| 47 | +vi.mock("../../hooks/use-trace-stream", () => ({ useTraceStream: vi.fn() })); |
| 48 | +// SpanInfoPanel lazily fetches the selection's I/O; nothing to fetch here. |
| 49 | +vi.mock("../../hooks", async (importOriginal) => ({ |
| 50 | + ...(await importOriginal<typeof import("../../hooks")>()), |
| 51 | + useSpanIO: () => ({ data: undefined, isLoading: false, error: null }), |
| 52 | +})); |
| 53 | +vi.mock("@/features/detectors/hooks/use-findings", () => ({ |
| 54 | + useTraceFindings: () => ({ data: { findings: [] } }), |
| 55 | + useRca: () => ({ data: { rca: null } }), |
| 56 | +})); |
| 57 | +vi.mock("@/components/layout/app-layout", () => ({ |
| 58 | + useLayout: () => ({ |
| 59 | + aiPanelOpen: false, |
| 60 | + setAiPanelOpen: vi.fn(), |
| 61 | + setAiContext: vi.fn(), |
| 62 | + setAiInitialSessionId: vi.fn(), |
| 63 | + registerAiHost: () => () => {}, |
| 64 | + sidebarCollapsed: false, |
| 65 | + }), |
| 66 | +})); |
| 67 | +// Everything but SpanInfoPanel is a stand-in, as in the chrome snapshot. |
| 68 | +vi.mock("../SpanTreeView", () => ({ SpanTreeView: () => <div data-testid="tree" /> })); |
| 69 | +vi.mock("../SpanTimelineView", () => ({ SpanTimelineView: () => <div data-testid="timeline" /> })); |
| 70 | +vi.mock("../TraceDetectorsTab", () => ({ |
| 71 | + TraceDetectorsTab: () => <div data-testid="detectors-tab" />, |
| 72 | +})); |
| 73 | +vi.mock("@/features/ai-assistant/components/ai-assistant-panel", () => ({ |
| 74 | + AiAssistantPanel: () => <div data-testid="ai-panel" />, |
| 75 | +})); |
| 76 | +vi.mock("@/components/RetentionGateBanner", () => ({ |
| 77 | + RetentionGateBanner: () => <div data-testid="retention-banner" />, |
| 78 | +})); |
| 79 | +vi.mock("@/components/ui/resizable", () => ({ |
| 80 | + ResizablePanelGroup: ({ children }: { children: React.ReactNode }) => <div>{children}</div>, |
| 81 | + ResizablePanel: ({ children }: { children: React.ReactNode }) => <div>{children}</div>, |
| 82 | + ResizableHandle: () => null, |
| 83 | +})); |
| 84 | + |
| 85 | +import { TraceViewerPanel } from "../TraceViewerPanel"; |
| 86 | + |
| 87 | +describe("user-trace span panel (real SpanInfoPanel) is unchanged by agent-trace work", () => { |
| 88 | + it("matches the committed snapshot for a trace with a user and session and no RCA", async () => { |
| 89 | + const { container, findByText } = render( |
| 90 | + <TraceViewerPanel |
| 91 | + projectId="p1" |
| 92 | + traceId="t1" |
| 93 | + onClose={() => {}} |
| 94 | + onNavigate={() => {}} |
| 95 | + canNavigateUp={false} |
| 96 | + canNavigateDown={false} |
| 97 | + source="user" |
| 98 | + />, |
| 99 | + ); |
| 100 | + // The chip row is on screen, with exactly the two customer chips. |
| 101 | + await findByText("user-42"); |
| 102 | + await findByText("sess-7"); |
| 103 | + expect(container.querySelector('[title*="RCA agent run"]')).toBeNull(); |
| 104 | + expect(container.querySelector('[title*="Back to the trace"]')).toBeNull(); |
| 105 | + expect(container.innerHTML).toMatchSnapshot(); |
| 106 | + }); |
| 107 | +}); |
0 commit comments