@eliya-oss/agent-diff 0.1.0-alpha.0 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -189
  4. package/bin/adiff.js +1 -1
  5. package/dist/main.js +14467 -0
  6. package/package.json +8 -6
  7. package/src/cli/catalog.ts +0 -178
  8. package/src/cli/commands.ts +0 -335
  9. package/src/cli/error.ts +0 -44
  10. package/src/cli/index.ts +0 -24
  11. package/src/cli/parse.ts +0 -31
  12. package/src/cli/report.ts +0 -96
  13. package/src/cli/story.ts +0 -223
  14. package/src/domain/narrative/coverage.ts +0 -54
  15. package/src/domain/narrative/index.ts +0 -4
  16. package/src/domain/narrative/model.ts +0 -46
  17. package/src/domain/narrative/version.ts +0 -63
  18. package/src/domain/patch/anchor.ts +0 -40
  19. package/src/domain/patch/index.ts +0 -7
  20. package/src/domain/patch/model.ts +0 -54
  21. package/src/domain/patch/parse.ts +0 -106
  22. package/src/domain/patch/render.ts +0 -48
  23. package/src/domain/patch/sticky.ts +0 -39
  24. package/src/domain/review/index.ts +0 -4
  25. package/src/domain/review/lifecycle.ts +0 -45
  26. package/src/domain/review/model.ts +0 -23
  27. package/src/domain/review/vouch.ts +0 -15
  28. package/src/main.ts +0 -186
  29. package/src/service/git/error.ts +0 -16
  30. package/src/service/git/index.ts +0 -3
  31. package/src/service/git/model.ts +0 -13
  32. package/src/service/git/run.ts +0 -27
  33. package/src/service/git/service.ts +0 -133
  34. package/src/service/store/error.ts +0 -11
  35. package/src/service/store/index.ts +0 -5
  36. package/src/service/store/model.ts +0 -33
  37. package/src/service/store/paths.ts +0 -25
  38. package/src/service/store/service.ts +0 -154
  39. package/src/testing/agent-surface.test.ts +0 -92
  40. package/src/testing/batch.test.ts +0 -93
  41. package/src/testing/branch-state.test.ts +0 -99
  42. package/src/testing/chrome-tone.test.ts +0 -57
  43. package/src/testing/comment-block.test.ts +0 -84
  44. package/src/testing/comment-walk.test.ts +0 -96
  45. package/src/testing/compose-box.test.ts +0 -97
  46. package/src/testing/compose.test.ts +0 -67
  47. package/src/testing/context.test.ts +0 -77
  48. package/src/testing/cursor.test.ts +0 -49
  49. package/src/testing/delivery.test.ts +0 -94
  50. package/src/testing/domains/agent/driver.ts +0 -50
  51. package/src/testing/domains/agent/index.ts +0 -2
  52. package/src/testing/domains/app/driver.ts +0 -168
  53. package/src/testing/domains/app/index.ts +0 -2
  54. package/src/testing/domains/branch/driver.ts +0 -51
  55. package/src/testing/domains/branch/index.ts +0 -3
  56. package/src/testing/domains/branch/model.ts +0 -39
  57. package/src/testing/domains/screen/driver.ts +0 -241
  58. package/src/testing/domains/screen/index.ts +0 -2
  59. package/src/testing/driver.ts +0 -31
  60. package/src/testing/escape.test.ts +0 -56
  61. package/src/testing/focus.test.ts +0 -104
  62. package/src/testing/footer-chips.test.ts +0 -65
  63. package/src/testing/footer.test.ts +0 -64
  64. package/src/testing/gaps.test.ts +0 -47
  65. package/src/testing/highlight.test.ts +0 -49
  66. package/src/testing/home-screen.test.ts +0 -51
  67. package/src/testing/index.ts +0 -4
  68. package/src/testing/inline-comments.test.ts +0 -131
  69. package/src/testing/marks.test.ts +0 -49
  70. package/src/testing/mouse.test.ts +0 -87
  71. package/src/testing/navigate.test.ts +0 -73
  72. package/src/testing/palette.test.ts +0 -68
  73. package/src/testing/pending.test.ts +0 -70
  74. package/src/testing/pin-align.test.ts +0 -37
  75. package/src/testing/progress.test.ts +0 -88
  76. package/src/testing/report.test.ts +0 -83
  77. package/src/testing/resume.test.ts +0 -39
  78. package/src/testing/review.test.ts +0 -181
  79. package/src/testing/roundtrip.test.ts +0 -70
  80. package/src/testing/scale.test.ts +0 -55
  81. package/src/testing/scroll-feel.test.ts +0 -81
  82. package/src/testing/sent-comments.test.ts +0 -106
  83. package/src/testing/state.ts +0 -55
  84. package/src/testing/sticky-removed.test.ts +0 -67
  85. package/src/testing/sticky.test.ts +0 -90
  86. package/src/testing/story-rail.test.ts +0 -122
  87. package/src/testing/story.test.ts +0 -183
  88. package/src/testing/stress.test.ts +0 -74
  89. package/src/testing/tree-collapse.test.ts +0 -108
  90. package/src/testing/tree-rows.test.ts +0 -66
  91. package/src/testing/tree.test.ts +0 -91
  92. package/src/testing/tui.test.ts +0 -73
  93. package/src/testing/typing.test.ts +0 -65
  94. package/src/testing/vouch-next.test.ts +0 -65
  95. package/src/testing/vouch-tui.test.ts +0 -77
  96. package/src/testing/wash.test.ts +0 -32
  97. package/src/testing/width.test.ts +0 -62
  98. package/src/tui/app.ts +0 -467
  99. package/src/tui/command.ts +0 -390
  100. package/src/tui/diffview.ts +0 -333
  101. package/src/tui/index.ts +0 -9
  102. package/src/tui/marks.ts +0 -102
  103. package/src/tui/match.ts +0 -34
  104. package/src/tui/model.ts +0 -310
  105. package/src/tui/reduce.ts +0 -305
  106. package/src/tui/render.ts +0 -897
  107. package/src/tui/report.ts +0 -74
  108. package/src/tui/session.ts +0 -32
  109. package/src/tui/theme.ts +0 -61
  110. package/src/tui/tree.ts +0 -149
@@ -1,73 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
- import { palette } from "../tui/index.ts"
4
-
5
- const filler = (count: number, mark: string): ReadonlyArray<string> =>
6
- Array.from({ length: count }, (_, index) => ` const ${mark}${index} = ${index}`)
7
-
8
- const twoHunks = {
9
- files: [
10
- {
11
- path: "src/wide.ts",
12
- before: ["export function wide() {", ...filler(40, "keep"), "}", "export default wide"],
13
- after: [
14
- "export function wide() {",
15
- " const first = 1",
16
- ...filler(40, "keep"),
17
- " const last = 2",
18
- "}",
19
- "export default wide",
20
- ],
21
- },
22
- ],
23
- }
24
-
25
- const cursorOn = async (driver: TestDriver): Promise<string> => {
26
- const rows = await driver.screen.findHighlighted(palette.cursor)
27
- return rows[0] ?? ""
28
- }
29
-
30
- describe("moving around a long diff", () => {
31
- it("jumps to the end of the file", async () => {
32
- // ARRANGE
33
- await using driver = await TestDriver.create()
34
- await driver.branch.create(twoHunks)
35
- await driver.screen.open()
36
- await driver.screen.pressKeys(["RETURN"])
37
-
38
- // ACT
39
- await driver.screen.pressKeys(["G"])
40
-
41
- // ASSERT
42
- expect(await cursorOn(driver)).toContain("export default wide")
43
- })
44
-
45
- it("comes back to the start", async () => {
46
- // ARRANGE
47
- await using driver = await TestDriver.create()
48
- await driver.branch.create(twoHunks)
49
- await driver.screen.open()
50
- await driver.screen.pressKeys(["RETURN"])
51
- await driver.screen.pressKeys(["G"])
52
-
53
- // ACT
54
- await driver.screen.pressKeys(["g"])
55
-
56
- // ASSERT
57
- expect(await cursorOn(driver)).toContain("export function wide")
58
- })
59
-
60
- it("jumps to the next hunk, skipping the context between them", async () => {
61
- // ARRANGE
62
- await using driver = await TestDriver.create()
63
- await driver.branch.create(twoHunks)
64
- await driver.screen.open()
65
- await driver.screen.pressKeys(["RETURN"])
66
-
67
- // ACT
68
- await driver.screen.pressKeys(["}"])
69
-
70
- // ASSERT
71
- expect(await cursorOn(driver)).toContain("keep37")
72
- })
73
- })
@@ -1,68 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- const twoFiles = {
5
- files: [
6
- { path: "src/api.ts", before: ["const a = 1"], after: ["const a = 1", "const b = 2"] },
7
- { path: "src/ui.tsx", before: ["const c = 3"], after: ["const c = 3", "const d = 4"] },
8
- ],
9
- }
10
-
11
- describe("finding a command without knowing its key", () => {
12
- it("lists the commands available on the current screen", async () => {
13
- // ARRANGE
14
- await using driver = await TestDriver.create()
15
- await driver.branch.create(twoFiles)
16
- await driver.screen.open()
17
- await driver.screen.pressKeys(["RETURN"])
18
-
19
- // ACT
20
- await driver.screen.pressCtrl("p")
21
- await driver.screen.typeText("comment")
22
-
23
- // ASSERT
24
- const frame = await driver.screen.getFrame()
25
- expect(frame).toContain("Commands")
26
- expect(frame).toContain("Comment on the selection")
27
- expect(frame).toContain("Next comment")
28
- expect(frame).toContain("Previous comment")
29
- })
30
-
31
- it("runs the command that was chosen, so the key never had to be learned", async () => {
32
- // ARRANGE
33
- await using driver = await TestDriver.create()
34
- await driver.branch.create(twoFiles)
35
- await driver.screen.open()
36
- await driver.screen.pressKeys(["RETURN"])
37
-
38
- // ACT
39
- await driver.screen.pressCtrl("p")
40
- await driver.screen.typeText("next file")
41
- await driver.screen.pressKeys(["RETURN"])
42
-
43
- // ASSERT
44
- const frame = await driver.screen.getFrame()
45
- expect(frame).toContain("src/ui.tsx")
46
- expect(frame).toContain("2/2")
47
- })
48
-
49
- it("leaves the review untouched when the palette is dismissed", async () => {
50
- // ARRANGE
51
- await using driver = await TestDriver.create()
52
- await driver.branch.create(twoFiles)
53
- await driver.screen.open()
54
- await driver.screen.pressKeys(["RETURN"])
55
-
56
- await driver.screen.pressCtrl("p")
57
- expect(await driver.screen.getFrame()).toContain("Go to last line")
58
-
59
- // ACT
60
- await driver.screen.pressEscape()
61
-
62
- // ASSERT
63
- const frame = await driver.screen.getFrame()
64
- expect(frame).not.toContain("Go to last line")
65
- expect(frame).toContain("src/api.ts")
66
- expect(frame).toContain("1/2")
67
- })
68
- })
@@ -1,70 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- const oneFile = {
5
- files: [
6
- {
7
- path: "src/api.ts",
8
- before: ["const keep = 0"],
9
- after: ["const keep = 0", "const first = 1", "const second = 2"],
10
- },
11
- ],
12
- }
13
-
14
- const stage = async (driver: TestDriver, body: string): Promise<void> => {
15
- await driver.screen.pressKeys(["c"])
16
- await driver.screen.typeText(body)
17
- await driver.screen.pressCtrl("a")
18
- }
19
-
20
- describe("looking over a review before sending it", () => {
21
- it("says nothing is staged when nothing is", async () => {
22
- // ARRANGE
23
- await using driver = await TestDriver.create()
24
- await driver.branch.create(oneFile)
25
- await driver.screen.open()
26
- await driver.screen.pressKeys(["RETURN"])
27
-
28
- // ACT
29
- await driver.screen.pressKeys(["S"])
30
-
31
- // ASSERT
32
- expect(await driver.screen.getFrame()).toContain("nothing staged")
33
- })
34
-
35
- it("lists every comment waiting to go", async () => {
36
- // ARRANGE
37
- await using driver = await TestDriver.create()
38
- await driver.branch.create(oneFile)
39
- await driver.screen.open()
40
- await driver.screen.pressKeys(["RETURN"])
41
- await stage(driver, "why first")
42
- await driver.screen.pressKeys(["j"])
43
- await stage(driver, "why second")
44
-
45
- // ACT
46
- await driver.screen.pressKeys(["S"])
47
-
48
- // ASSERT
49
- const frame = await driver.screen.getFrame()
50
- expect(frame).toContain("why first")
51
- expect(frame).toContain("why second")
52
- })
53
-
54
- it("sends the whole review as one wake-up", async () => {
55
- // ARRANGE
56
- await using driver = await TestDriver.create()
57
- const branch = await driver.branch.create(oneFile)
58
- await driver.screen.open()
59
- await driver.screen.pressKeys(["RETURN"])
60
- await stage(driver, "why first")
61
- await driver.screen.pressKeys(["S"])
62
-
63
- // ACT
64
- await driver.screen.pressCtrl("s")
65
-
66
- // ASSERT
67
- expect(await driver.agent.listBatches(branch.worktree)).toHaveLength(1)
68
- expect(await driver.screen.getFrame()).toContain("review sent")
69
- })
70
- })
@@ -1,37 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- const steps = (count: number, mark: string): ReadonlyArray<string> =>
5
- Array.from({ length: count }, (_, index) => ` const step${index} = ${mark}(${index})`)
6
-
7
- const shaped = (mark: string): ReadonlyArray<string> => [
8
- "export const client = async (input: string) => {",
9
- ...steps(40, mark),
10
- " return input",
11
- "}",
12
- ]
13
-
14
- const file = { files: [{ path: "src/client.ts", before: shaped("settle"), after: shaped("resolve") }] }
15
-
16
- describe("the pinned line sits over the code it names", () => {
17
- it("starts in the same column as the code below it", async () => {
18
- // ARRANGE
19
- await using driver = await TestDriver.create()
20
- await driver.branch.create(file)
21
- await driver.screen.open()
22
- await driver.screen.pressKeys(["RETURN"])
23
-
24
- // ACT
25
- await driver.screen.pressKeys(["G"])
26
-
27
- // ASSERT
28
- const rows = (await driver.screen.getFrame()).split("\n")
29
- const pin = rows.find((line) => line.includes("export const client"))
30
- const code = rows.find((line) => line.includes("const step3"))
31
- expect(pin).toBeDefined()
32
- expect(code).toBeDefined()
33
- expect((pin ?? "").indexOf("export const client")).toBe(
34
- (code ?? "").indexOf("const step3") - 4,
35
- )
36
- })
37
- })
@@ -1,88 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- describe("tracking review progress", () => {
5
- it("starts with nothing vouched for", async () => {
6
- // ARRANGE
7
- await using driver = await TestDriver.create()
8
- const branch = await driver.branch.create()
9
-
10
- // ACT
11
- const result = await driver.app.runProgress(branch.name)
12
-
13
- // ASSERT
14
- expect(result.envelope).toMatchObject({ ok: true, vouched: [], total: 1 })
15
- })
16
-
17
- it("records a file the reviewer vouched for", async () => {
18
- // ARRANGE
19
- await using driver = await TestDriver.create()
20
- const branch = await driver.branch.create()
21
-
22
- // ACT
23
- const result = await driver.app.runVouch({ branch: branch.name, file: "src/api.ts" })
24
-
25
- // ASSERT
26
- expect(result.envelope).toMatchObject({ ok: true, vouched: ["src/api.ts"], total: 1 })
27
- })
28
-
29
- it("survives the tool restarting, because progress is worth nothing if it does not", async () => {
30
- // ARRANGE
31
- await using driver = await TestDriver.create()
32
- const branch = await driver.branch.create()
33
- await driver.app.runVouch({ branch: branch.name, file: "src/api.ts" })
34
-
35
- // ACT
36
- const result = await driver.app.runProgress(branch.name)
37
-
38
- // ASSERT
39
- expect(result.envelope).toMatchObject({ vouched: ["src/api.ts"] })
40
- })
41
-
42
- it("takes the vouch back when the reviewer changes their mind", async () => {
43
- // ARRANGE
44
- await using driver = await TestDriver.create()
45
- const branch = await driver.branch.create()
46
- await driver.app.runVouch({ branch: branch.name, file: "src/api.ts" })
47
-
48
- // ACT
49
- const result = await driver.app.runVouch({ branch: branch.name, file: "src/api.ts" })
50
-
51
- // ASSERT
52
- expect(result.envelope).toMatchObject({ vouched: [] })
53
- })
54
-
55
- it("stops counting a file the agent rewrote after it was vouched for", async () => {
56
- // ARRANGE
57
- await using driver = await TestDriver.create()
58
- const branch = await driver.branch.create()
59
- await driver.app.runVouch({ branch: branch.name, file: "src/api.ts" })
60
-
61
- // ACT
62
- await driver.branch.setFile(branch, "src/api.ts", [
63
- "export function api() {",
64
- " return 'entirely different'",
65
- "}",
66
- ])
67
- const result = await driver.app.runProgress(branch.name)
68
-
69
- // ASSERT
70
- expect(result.envelope).toMatchObject({ vouched: [] })
71
- })
72
-
73
- it("refuses to vouch for a file that is not in the diff", async () => {
74
- // ARRANGE
75
- await using driver = await TestDriver.create()
76
- const branch = await driver.branch.create()
77
-
78
- // ACT
79
- const result = await driver.app.runVouch({ branch: branch.name, file: "src/absent.ts" })
80
-
81
- // ASSERT
82
- expect(result.code).toBe(3)
83
- expect(result.envelope).toMatchObject({
84
- ok: false,
85
- error: { type: "UnknownFile", known: expect.arrayContaining(["src/api.ts"]) },
86
- })
87
- })
88
- })
@@ -1,83 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- const oneFile = {
5
- files: [
6
- {
7
- path: "src/api.ts",
8
- before: ["const keep = 0"],
9
- after: ["const keep = 0", "const first = 1"],
10
- },
11
- ],
12
- }
13
-
14
- describe("reporting a bug from inside the terminal", () => {
15
- it("writes down what the reviewer said", async () => {
16
- // ARRANGE
17
- await using driver = await TestDriver.create()
18
- await driver.branch.create(oneFile)
19
- await driver.screen.open()
20
- await driver.screen.pressKeys(["RETURN", "j"])
21
- await driver.screen.pressCtrl("b")
22
- await driver.screen.typeText("the cursor jumps two lines when I press j")
23
-
24
- // ACT
25
- await driver.screen.pressCtrl("s")
26
-
27
- // ASSERT
28
- const reports = await driver.agent.listReports()
29
- expect(reports).toHaveLength(1)
30
- expect(reports[0]).toContain("the cursor jumps two lines when I press j")
31
- })
32
-
33
- it("attaches what was happening, so it can be reproduced", async () => {
34
- // ARRANGE
35
- await using driver = await TestDriver.create()
36
- const branch = await driver.branch.create(oneFile)
37
- await driver.screen.open()
38
- await driver.screen.pressKeys(["RETURN", "j", "v"])
39
- await driver.screen.pressCtrl("b")
40
- await driver.screen.typeText("selection looks wrong")
41
-
42
- // ACT
43
- await driver.screen.pressCtrl("s")
44
-
45
- // ASSERT
46
- const report = (await driver.agent.listReports())[0] ?? ""
47
- expect(report).toContain(branch.name)
48
- expect(report).toContain("src/api.ts")
49
- expect(report).toContain("select.start")
50
- expect(report).toContain("const first = 1")
51
- })
52
-
53
- it("refuses a report with nothing in it", async () => {
54
- // ARRANGE
55
- await using driver = await TestDriver.create()
56
- await driver.branch.create(oneFile)
57
- await driver.screen.open()
58
- await driver.screen.pressKeys(["RETURN"])
59
- await driver.screen.pressCtrl("b")
60
-
61
- // ACT
62
- await driver.screen.pressCtrl("s")
63
-
64
- // ASSERT
65
- expect(await driver.agent.listReports()).toHaveLength(0)
66
- })
67
-
68
- it("writes nothing when the report is abandoned", async () => {
69
- // ARRANGE
70
- await using driver = await TestDriver.create()
71
- await driver.branch.create(oneFile)
72
- await driver.screen.open()
73
- await driver.screen.pressKeys(["RETURN"])
74
- await driver.screen.pressCtrl("b")
75
- await driver.screen.typeText("never mind")
76
-
77
- // ACT
78
- await driver.screen.pressEscape()
79
-
80
- // ASSERT
81
- expect(await driver.agent.listReports()).toHaveLength(0)
82
- })
83
- })
@@ -1,39 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- const twoFiles = {
5
- files: [
6
- { path: "src/api.ts", before: ["const a = 1"], after: ["const a = 1", "const b = 2"] },
7
- { path: "src/ui.tsx", before: ["const c = 3"], after: ["const c = 3", "const d = 4"] },
8
- ],
9
- }
10
-
11
- describe("picking up where the terminal was closed", () => {
12
- it("comes back on the same branch and file", async () => {
13
- // ARRANGE
14
- await using driver = await TestDriver.create({ remember: true })
15
- await driver.branch.create(twoFiles)
16
- await driver.screen.open()
17
- await driver.screen.pressKeys(["RETURN"])
18
- await driver.screen.pressKeys(["]"])
19
- expect(await driver.screen.getFrame()).toContain("src/ui.tsx 2/2")
20
-
21
- // ACT
22
- await driver.screen.restart()
23
-
24
- // ASSERT
25
- expect(await driver.screen.getFrame()).toContain("src/ui.tsx 2/2")
26
- })
27
-
28
- it("starts on the branch list when nothing was remembered", async () => {
29
- // ARRANGE
30
- await using driver = await TestDriver.create()
31
- await driver.branch.create(twoFiles)
32
-
33
- // ACT
34
- await driver.screen.open()
35
-
36
- // ASSERT
37
- expect(await driver.screen.getFrame()).toContain("adiff")
38
- })
39
- })
@@ -1,181 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- describe("reviewing a branch", () => {
5
- it("lists only branches that have something to review", async () => {
6
- // ARRANGE
7
- await using driver = await TestDriver.create()
8
- await driver.branch.create({ name: "cdr-1-add-third" })
9
-
10
- // ACT
11
- const result = await driver.app.runBranches()
12
-
13
- // ASSERT
14
- expect(result.code).toBe(0)
15
- expect(result.envelope).toMatchObject({
16
- ok: true,
17
- branches: [{ branch: "cdr-1-add-third", files: 1, added: 2, removed: 1 }],
18
- })
19
- })
20
-
21
- it("delivers a comment to the agent anchored to the lines that were selected", async () => {
22
- // ARRANGE
23
- await using driver = await TestDriver.create()
24
- const branch = await driver.branch.create()
25
-
26
- // ACT
27
- const result = await driver.app.runComment({
28
- branch: branch.name,
29
- file: "src/api.ts",
30
- start: 4,
31
- end: 5,
32
- body: "third is unused outside this sum",
33
- })
34
-
35
- // ASSERT
36
- expect(result.code).toBe(0)
37
- const comments = await driver.agent.listComments(branch.worktree)
38
- expect(comments).toEqual([
39
- {
40
- body: "third is unused outside this sum",
41
- file: "src/api.ts",
42
- side: "new",
43
- start: 4,
44
- end: 5,
45
- snippet: " const third = 3\n return first + second + third",
46
- },
47
- ])
48
- })
49
-
50
- it("carries the changed source so the agent needs no other reference", async () => {
51
- // ARRANGE
52
- await using driver = await TestDriver.create()
53
- const branch = await driver.branch.create({
54
- files: [
55
- {
56
- path: "src/deep/nested.ts",
57
- before: ["const a = 1", "const b = 2"],
58
- after: ["const a = 1", "const renamed = 2", "const c = 3"],
59
- },
60
- ],
61
- })
62
-
63
- // ACT
64
- await driver.app.runComment({
65
- branch: branch.name,
66
- file: "src/deep/nested.ts",
67
- start: 2,
68
- end: 2,
69
- body: "why renamed",
70
- })
71
-
72
- // ASSERT
73
- const comments = await driver.agent.listComments(branch.worktree)
74
- expect(comments[0]?.snippet).toBe("const renamed = 2")
75
- expect(comments[0]?.file).toBe("src/deep/nested.ts")
76
- })
77
-
78
- it("anchors to the removed side when asked about code that was deleted", async () => {
79
- // ARRANGE
80
- await using driver = await TestDriver.create()
81
- const branch = await driver.branch.create({
82
- files: [
83
- {
84
- path: "src/api.ts",
85
- before: ["const kept = 1", "const doomed = 2"],
86
- after: ["const kept = 1"],
87
- },
88
- ],
89
- })
90
-
91
- // ACT
92
- await driver.app.runComment({
93
- branch: branch.name,
94
- file: "src/api.ts",
95
- start: 2,
96
- end: 2,
97
- side: "old",
98
- body: "why was this removed",
99
- })
100
-
101
- // ASSERT
102
- const comments = await driver.agent.listComments(branch.worktree)
103
- expect(comments[0]?.side).toBe("old")
104
- expect(comments[0]?.snippet).toBe("const doomed = 2")
105
- })
106
-
107
- it("refuses a range the diff does not show, rather than anchoring somewhere else", async () => {
108
- // ARRANGE
109
- await using driver = await TestDriver.create()
110
- const branch = await driver.branch.create()
111
-
112
- // ACT
113
- const result = await driver.app.runComment({
114
- branch: branch.name,
115
- file: "src/api.ts",
116
- start: 900,
117
- end: 901,
118
- body: "nowhere",
119
- })
120
-
121
- // ASSERT
122
- expect(result.code).toBe(2)
123
- expect(result.envelope).toMatchObject({
124
- ok: false,
125
- error: {
126
- type: "UnselectableRange",
127
- retriable: false,
128
- suggestion: expect.stringContaining("--side"),
129
- },
130
- })
131
- expect(await driver.agent.listComments(branch.worktree)).toHaveLength(0)
132
- })
133
-
134
- it("names the branches it knows when asked for one that does not exist", async () => {
135
- // ARRANGE
136
- await using driver = await TestDriver.create()
137
- await driver.branch.create({ name: "cdr-2-real" })
138
-
139
- // ACT
140
- const result = await driver.app.runComment({
141
- branch: "cdr-99-imaginary",
142
- file: "src/api.ts",
143
- start: 1,
144
- end: 1,
145
- body: "hello",
146
- })
147
-
148
- // ASSERT
149
- expect(result.code).toBe(3)
150
- expect(result.envelope).toMatchObject({
151
- ok: false,
152
- error: { type: "UnknownBranch", known: expect.arrayContaining(["cdr-2-real"]) },
153
- })
154
- })
155
-
156
- it("keeps every submitted comment, so a second review does not replace the first", async () => {
157
- // ARRANGE
158
- await using driver = await TestDriver.create()
159
- const branch = await driver.branch.create()
160
-
161
- // ACT
162
- await driver.app.runComment({
163
- branch: branch.name,
164
- file: "src/api.ts",
165
- start: 4,
166
- end: 4,
167
- body: "first",
168
- })
169
- await driver.app.runComment({
170
- branch: branch.name,
171
- file: "src/api.ts",
172
- start: 5,
173
- end: 5,
174
- body: "second",
175
- })
176
-
177
- // ASSERT
178
- const comments = await driver.agent.listComments(branch.worktree)
179
- expect(comments.map((comment) => comment.body)).toEqual(["first", "second"])
180
- })
181
- })