Skip to content

Commit 617a9da

Browse files
committed
test(ui): cover context-heavy comment annotations
1 parent 6b7da14 commit 617a9da

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { describe, expect, test } from "bun:test";
2+
import { createTestDiffFile, lines } from "../../../test/helpers/diff-helpers";
3+
import { buildLiveComment, resolveCommentTarget } from "../../core/liveComments";
4+
import { getAnnotatedHunkIndices, getSelectedAnnotations } from "./agentAnnotations";
5+
6+
function createContextHeavyHunkFile() {
7+
const beforeLines = Array.from({ length: 25 }, (_, i) => `line${i + 1}`);
8+
const afterLines = [...beforeLines.slice(0, 12), "INSERTED", ...beforeLines.slice(12)];
9+
10+
return createTestDiffFile({
11+
before: lines(...beforeLines),
12+
after: lines(...afterLines),
13+
context: 100,
14+
id: "file:context-heavy-annotation",
15+
path: "src/sparse.ts",
16+
previousPath: "src/sparse.ts",
17+
});
18+
}
19+
20+
describe("agent annotations", () => {
21+
test("keeps hunk-number comments visible when anchored after leading context", () => {
22+
const file = createContextHeavyHunkFile();
23+
const hunk = file.metadata.hunks[0]!;
24+
25+
const target = resolveCommentTarget(file, {
26+
filePath: file.path,
27+
hunkIndex: 0,
28+
summary: "Explain inserted line",
29+
rationale: "The daemon resolves hunk-number comments to the first change row.",
30+
});
31+
32+
expect(target).toMatchObject({ hunkIndex: 0, side: "new", line: 13 });
33+
expect(hunk.additionLines).toBe(1);
34+
expect(hunk.additionCount).toBeGreaterThan(target.line - hunk.additionStart + 1);
35+
36+
const comment = buildLiveComment(
37+
{
38+
filePath: file.path,
39+
side: target.side,
40+
line: target.line,
41+
summary: "Explain inserted line",
42+
rationale: "The daemon resolves hunk-number comments to the first change row.",
43+
},
44+
"comment-1",
45+
"2026-03-22T00:00:00.000Z",
46+
target.hunkIndex,
47+
);
48+
const annotatedFile = {
49+
...file,
50+
agent: {
51+
path: file.path,
52+
annotations: [comment],
53+
},
54+
};
55+
56+
expect([...getAnnotatedHunkIndices(annotatedFile)]).toEqual([0]);
57+
expect(getSelectedAnnotations(annotatedFile, hunk)).toEqual([comment]);
58+
});
59+
});

0 commit comments

Comments
 (0)