Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 buildReviewCommentRenderablePatch,
5 parseReviewCommentMessageSegments,
6} from "./reviewCommentContext";
7
8describe("review comment context parsing", () => {
9 it("extracts comment metadata, user text, and fenced diff without raw wrapper text", () => {
10 const segments = parseReviewCommentMessageSegments(
11 [
12 'Before <review_comment sectionId="turn:2" sectionTitle="Turn 2" filePath="apps/web/src/lib/contextWindow.test.ts" startIndex="3" endIndex="14" rangeLabel="+47 to +58">',
13 "Wadduo",
14 "```diff",
15 "@@ -0,0 +47,2 @@",
16 '+ it("keeps valid zero-usage snapshots", () => {',
17 "+ expect(snapshot).not.toBeNull();",
18 "```",
19 "</review_comment> after",
20 ].join("\n"),
21 );
22
23 expect(segments).toHaveLength(3);
24 expect(segments[0]).toEqual(
25 expect.objectContaining({
26 kind: "text",
27 text: expect.stringContaining("Before"),
28 }),
29 );
30 expect(segments[1]).toEqual(
31 expect.objectContaining({
32 kind: "review-comment",
33 comment: expect.objectContaining({
34 filePath: "apps/web/src/lib/contextWindow.test.ts",
35 rangeLabel: "+47 to +58",
36 text: "Wadduo",
37 diff: expect.stringContaining('it("keeps valid zero-usage snapshots"'),
38 }),
39 }),
40 );
41 expect(segments[2]).toEqual(
42 expect.objectContaining({
43 kind: "text",
44 text: " after",
45 }),
46 );
47 });
48
49 it("wraps hunk-only review diffs in a renderable file patch", () => {
50 const [segment] = parseReviewCommentMessageSegments(
51 [
52 '<review_comment sectionId="s" filePath="src/app.ts" startIndex="0" endIndex="0">',
53 "Please check this.",
54 "```diff",
55 "@@ -1,1 +1,1 @@",
56 "-old",
57 "+new",
58 "```",
59 "</review_comment>",
60 ].join("\n"),
61 );
62
63 expect(segment?.kind).toBe("review-comment");
64 if (segment?.kind !== "review-comment") return;
65
66 expect(buildReviewCommentRenderablePatch(segment.comment)).toBe(
67 [
68 "diff --git a/src/app.ts b/src/app.ts",
69 "--- a/src/app.ts",
70 "+++ b/src/app.ts",
71 "@@ -1,1 +1,1 @@",
72 "-old",
73 "+new",
74 ].join("\n"),
75 );
76 });
77});