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

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 (111) hide show
  1. package/.agents/adr/README.md +33 -0
  2. package/.agents/prd/README.md +74 -0
  3. package/CHANGELOG.md +58 -0
  4. package/README.md +239 -0
  5. package/bin/adiff.js +2 -0
  6. package/package.json +54 -0
  7. package/skills/adiff/SKILL.md +135 -0
  8. package/src/cli/catalog.ts +178 -0
  9. package/src/cli/commands.ts +335 -0
  10. package/src/cli/error.ts +44 -0
  11. package/src/cli/index.ts +24 -0
  12. package/src/cli/parse.ts +31 -0
  13. package/src/cli/report.ts +96 -0
  14. package/src/cli/story.ts +223 -0
  15. package/src/domain/narrative/coverage.ts +54 -0
  16. package/src/domain/narrative/index.ts +4 -0
  17. package/src/domain/narrative/model.ts +46 -0
  18. package/src/domain/narrative/version.ts +63 -0
  19. package/src/domain/patch/anchor.ts +40 -0
  20. package/src/domain/patch/index.ts +7 -0
  21. package/src/domain/patch/model.ts +54 -0
  22. package/src/domain/patch/parse.ts +106 -0
  23. package/src/domain/patch/render.ts +48 -0
  24. package/src/domain/patch/sticky.ts +39 -0
  25. package/src/domain/review/index.ts +4 -0
  26. package/src/domain/review/lifecycle.ts +45 -0
  27. package/src/domain/review/model.ts +23 -0
  28. package/src/domain/review/vouch.ts +15 -0
  29. package/src/main.ts +186 -0
  30. package/src/service/git/error.ts +16 -0
  31. package/src/service/git/index.ts +3 -0
  32. package/src/service/git/model.ts +13 -0
  33. package/src/service/git/run.ts +27 -0
  34. package/src/service/git/service.ts +133 -0
  35. package/src/service/store/error.ts +11 -0
  36. package/src/service/store/index.ts +5 -0
  37. package/src/service/store/model.ts +33 -0
  38. package/src/service/store/paths.ts +25 -0
  39. package/src/service/store/service.ts +154 -0
  40. package/src/testing/agent-surface.test.ts +92 -0
  41. package/src/testing/batch.test.ts +93 -0
  42. package/src/testing/branch-state.test.ts +99 -0
  43. package/src/testing/chrome-tone.test.ts +57 -0
  44. package/src/testing/comment-block.test.ts +84 -0
  45. package/src/testing/comment-walk.test.ts +96 -0
  46. package/src/testing/compose-box.test.ts +97 -0
  47. package/src/testing/compose.test.ts +67 -0
  48. package/src/testing/context.test.ts +77 -0
  49. package/src/testing/cursor.test.ts +49 -0
  50. package/src/testing/delivery.test.ts +94 -0
  51. package/src/testing/domains/agent/driver.ts +50 -0
  52. package/src/testing/domains/agent/index.ts +2 -0
  53. package/src/testing/domains/app/driver.ts +168 -0
  54. package/src/testing/domains/app/index.ts +2 -0
  55. package/src/testing/domains/branch/driver.ts +51 -0
  56. package/src/testing/domains/branch/index.ts +3 -0
  57. package/src/testing/domains/branch/model.ts +39 -0
  58. package/src/testing/domains/screen/driver.ts +241 -0
  59. package/src/testing/domains/screen/index.ts +2 -0
  60. package/src/testing/driver.ts +31 -0
  61. package/src/testing/escape.test.ts +56 -0
  62. package/src/testing/focus.test.ts +104 -0
  63. package/src/testing/footer-chips.test.ts +65 -0
  64. package/src/testing/footer.test.ts +64 -0
  65. package/src/testing/gaps.test.ts +47 -0
  66. package/src/testing/highlight.test.ts +49 -0
  67. package/src/testing/home-screen.test.ts +51 -0
  68. package/src/testing/index.ts +4 -0
  69. package/src/testing/inline-comments.test.ts +131 -0
  70. package/src/testing/marks.test.ts +49 -0
  71. package/src/testing/mouse.test.ts +87 -0
  72. package/src/testing/navigate.test.ts +73 -0
  73. package/src/testing/palette.test.ts +68 -0
  74. package/src/testing/pending.test.ts +70 -0
  75. package/src/testing/pin-align.test.ts +37 -0
  76. package/src/testing/progress.test.ts +88 -0
  77. package/src/testing/report.test.ts +83 -0
  78. package/src/testing/resume.test.ts +39 -0
  79. package/src/testing/review.test.ts +181 -0
  80. package/src/testing/roundtrip.test.ts +70 -0
  81. package/src/testing/scale.test.ts +55 -0
  82. package/src/testing/scroll-feel.test.ts +81 -0
  83. package/src/testing/sent-comments.test.ts +106 -0
  84. package/src/testing/state.ts +55 -0
  85. package/src/testing/sticky-removed.test.ts +67 -0
  86. package/src/testing/sticky.test.ts +90 -0
  87. package/src/testing/story-rail.test.ts +122 -0
  88. package/src/testing/story.test.ts +183 -0
  89. package/src/testing/stress.test.ts +74 -0
  90. package/src/testing/tree-collapse.test.ts +108 -0
  91. package/src/testing/tree-rows.test.ts +66 -0
  92. package/src/testing/tree.test.ts +91 -0
  93. package/src/testing/tui.test.ts +73 -0
  94. package/src/testing/typing.test.ts +65 -0
  95. package/src/testing/vouch-next.test.ts +65 -0
  96. package/src/testing/vouch-tui.test.ts +77 -0
  97. package/src/testing/wash.test.ts +32 -0
  98. package/src/testing/width.test.ts +62 -0
  99. package/src/tui/app.ts +467 -0
  100. package/src/tui/command.ts +390 -0
  101. package/src/tui/diffview.ts +333 -0
  102. package/src/tui/index.ts +9 -0
  103. package/src/tui/marks.ts +102 -0
  104. package/src/tui/match.ts +34 -0
  105. package/src/tui/model.ts +310 -0
  106. package/src/tui/reduce.ts +305 -0
  107. package/src/tui/render.ts +897 -0
  108. package/src/tui/report.ts +74 -0
  109. package/src/tui/session.ts +32 -0
  110. package/src/tui/theme.ts +61 -0
  111. package/src/tui/tree.ts +149 -0
@@ -0,0 +1,5 @@
1
+ export { Store, StoreLive, storeAt } from "./service.ts"
2
+ export { StoreUnreadable, StoreUnwritable } from "./error.ts"
3
+ export { branchDir, defaultRoot, inboxPath, reportPath, reportsDir, slugOf, statePath, storyPath } from "./paths.ts"
4
+ export { emptyBranchState } from "./model.ts"
5
+ export type { Batch, BranchState, StoredComment, StoredStory } from "./model.ts"
@@ -0,0 +1,33 @@
1
+ import type { Anchor } from "../../domain/patch/index.ts"
2
+ import type { Step } from "../../domain/narrative/index.ts"
3
+
4
+ export type StoredStory = {
5
+ readonly version: number
6
+ readonly head: string
7
+ readonly base: string
8
+ readonly parent: number | undefined
9
+ readonly written: string
10
+ readonly summary: string
11
+ readonly steps: ReadonlyArray<Step>
12
+ }
13
+
14
+ export type StoredComment = {
15
+ readonly id: string
16
+ readonly anchor: Anchor
17
+ readonly body: string
18
+ }
19
+
20
+ export type Batch = {
21
+ readonly id: string
22
+ readonly at: string
23
+ readonly head: string
24
+ readonly comments: ReadonlyArray<StoredComment>
25
+ }
26
+
27
+ export type BranchState = {
28
+ readonly vouches: Readonly<Record<string, string>>
29
+ readonly consumed: number
30
+ readonly pending: ReadonlyArray<StoredComment>
31
+ }
32
+
33
+ export const emptyBranchState: BranchState = { vouches: {}, consumed: 0, pending: [] }
@@ -0,0 +1,25 @@
1
+ import { homedir } from "node:os"
2
+ import { join } from "node:path"
3
+
4
+ const NON_SLUG = /[^a-zA-Z0-9]+/g
5
+
6
+ export const slugOf = (worktreePath: string): string => worktreePath.replace(NON_SLUG, "-")
7
+
8
+ export const defaultRoot = (): string => join(homedir(), ".adiff")
9
+
10
+ export const branchDir = (root: string, worktreePath: string): string =>
11
+ join(root, "branches", slugOf(worktreePath))
12
+
13
+ export const inboxPath = (root: string, worktreePath: string): string =>
14
+ join(branchDir(root, worktreePath), "inbox.jsonl")
15
+
16
+ export const statePath = (root: string, worktreePath: string): string =>
17
+ join(branchDir(root, worktreePath), "state.json")
18
+
19
+ export const storyPath = (root: string, worktreePath: string): string =>
20
+ join(branchDir(root, worktreePath), "story.json")
21
+
22
+ export const reportsDir = (root: string): string => join(root, "reports")
23
+
24
+ export const reportPath = (root: string, stamp: string): string =>
25
+ join(reportsDir(root), `${stamp}.md`)
@@ -0,0 +1,154 @@
1
+ import { mkdir, readFile, appendFile, writeFile } from "node:fs/promises"
2
+ import { Context, Effect, Layer, Option } from "effect"
3
+ import { StoreUnreadable, StoreUnwritable } from "./error.ts"
4
+ import { emptyBranchState, type Batch, type BranchState, type StoredComment, type StoredStory } from "./model.ts"
5
+ import { branchDir, defaultRoot, inboxPath, reportPath, reportsDir, statePath, storyPath } from "./paths.ts"
6
+
7
+ type Shape = {
8
+ readonly root: string
9
+ readonly submit: (worktreePath: string, batch: Batch) => Effect.Effect<void, StoreUnwritable>
10
+ readonly inbox: (worktreePath: string) => Effect.Effect<ReadonlyArray<Batch>, StoreUnreadable>
11
+ readonly state: (worktreePath: string) => Effect.Effect<BranchState, StoreUnreadable>
12
+ readonly saveState: (
13
+ worktreePath: string,
14
+ state: BranchState,
15
+ ) => Effect.Effect<void, StoreUnwritable>
16
+ readonly stage: (
17
+ worktreePath: string,
18
+ comment: StoredComment,
19
+ ) => Effect.Effect<ReadonlyArray<StoredComment>, StoreUnreadable | StoreUnwritable>
20
+ readonly saveReport: (stamp: string, text: string) => Effect.Effect<string, StoreUnwritable>
21
+ readonly story: (
22
+ worktreePath: string,
23
+ ) => Effect.Effect<Option.Option<StoredStory>, StoreUnreadable>
24
+ readonly saveStory: (
25
+ worktreePath: string,
26
+ story: StoredStory,
27
+ ) => Effect.Effect<void, StoreUnwritable>
28
+ readonly take: (
29
+ worktreePath: string,
30
+ ) => Effect.Effect<ReadonlyArray<Batch>, StoreUnreadable | StoreUnwritable>
31
+ }
32
+
33
+ export class Store extends Context.Service<Store, Shape>()("adiff/Store") {}
34
+
35
+ const ensureDir = Effect.fn("Store.ensureDir")(function* (path: string) {
36
+ return yield* Effect.tryPromise({
37
+ try: () => mkdir(path, { recursive: true }),
38
+ catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
39
+ })
40
+ })
41
+
42
+ const readOptional = Effect.fn("Store.readOptional")(function* (path: string) {
43
+ return yield* Effect.tryPromise({
44
+ try: () => readFile(path, "utf8"),
45
+ catch: (cause) => new StoreUnreadable({ path, reason: String(cause) }),
46
+ }).pipe(Effect.map(Option.some), Effect.catchTag("StoreUnreadable", () => missing))
47
+ })
48
+
49
+ const missing = Effect.succeed(Option.none<string>())
50
+
51
+ const parseBatches = (raw: string): ReadonlyArray<Batch> =>
52
+ raw
53
+ .split("\n")
54
+ .filter((line) => line.trim().length > 0)
55
+ .map((line) => JSON.parse(line) as Batch)
56
+
57
+ const parseState = (raw: string): BranchState => ({
58
+ ...emptyBranchState,
59
+ ...(JSON.parse(raw) as Partial<BranchState>),
60
+ })
61
+
62
+ type Reader = (worktreePath: string) => Effect.Effect<BranchState, StoreUnreadable>
63
+ type Writer = (worktreePath: string, next: BranchState) => Effect.Effect<void, StoreUnwritable>
64
+ type Inbox = (worktreePath: string) => Effect.Effect<ReadonlyArray<Batch>, StoreUnreadable>
65
+
66
+ const cursorOps = (state: Reader, saveState: Writer, inbox: Inbox) => {
67
+ const stage = Effect.fn("Store.stage")(function* (worktreePath: string, comment: StoredComment) {
68
+ const current = yield* state(worktreePath)
69
+ const pending = [...current.pending, comment]
70
+ yield* saveState(worktreePath, { ...current, pending })
71
+ return pending as ReadonlyArray<StoredComment>
72
+ })
73
+
74
+ const take = Effect.fn("Store.take")(function* (worktreePath: string) {
75
+ const batches = yield* inbox(worktreePath)
76
+ const current = yield* state(worktreePath)
77
+ const pending = batches.slice(current.consumed)
78
+ if (pending.length > 0) yield* saveState(worktreePath, { ...current, consumed: batches.length })
79
+ return pending
80
+ })
81
+
82
+ return { stage, take }
83
+ }
84
+
85
+ const storyOps = (root: string) => {
86
+ const story = Effect.fn("Store.story")(function* (worktreePath: string) {
87
+ const raw = yield* readOptional(storyPath(root, worktreePath))
88
+ return Option.map(raw, (text) => JSON.parse(text) as StoredStory)
89
+ })
90
+
91
+ const saveStory = Effect.fn("Store.saveStory")(function* (
92
+ worktreePath: string,
93
+ next: StoredStory,
94
+ ) {
95
+ const path = storyPath(root, worktreePath)
96
+ yield* ensureDir(branchDir(root, worktreePath))
97
+ yield* Effect.tryPromise({
98
+ try: () => writeFile(path, JSON.stringify(next, undefined, 2), "utf8"),
99
+ catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
100
+ })
101
+ })
102
+
103
+ return { story, saveStory }
104
+ }
105
+
106
+ const makeStore = (root: string): Shape => {
107
+ const submit = Effect.fn("Store.submit")(function* (worktreePath: string, batch: Batch) {
108
+ const path = inboxPath(root, worktreePath)
109
+ yield* ensureDir(branchDir(root, worktreePath))
110
+ yield* Effect.tryPromise({
111
+ try: () => appendFile(path, `${JSON.stringify(batch)}\n`, "utf8"),
112
+ catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
113
+ })
114
+ })
115
+
116
+ const inbox = Effect.fn("Store.inbox")(function* (worktreePath: string) {
117
+ const raw = yield* readOptional(inboxPath(root, worktreePath))
118
+ return Option.match(raw, { onNone: (): ReadonlyArray<Batch> => [], onSome: parseBatches })
119
+ })
120
+
121
+ const state = Effect.fn("Store.state")(function* (worktreePath: string) {
122
+ const raw = yield* readOptional(statePath(root, worktreePath))
123
+ return Option.match(raw, { onNone: () => emptyBranchState, onSome: parseState })
124
+ })
125
+
126
+ const saveState = Effect.fn("Store.saveState")(function* (
127
+ worktreePath: string,
128
+ next: BranchState,
129
+ ) {
130
+ const path = statePath(root, worktreePath)
131
+ yield* ensureDir(branchDir(root, worktreePath))
132
+ yield* Effect.tryPromise({
133
+ try: () => writeFile(path, JSON.stringify(next, undefined, 2), "utf8"),
134
+ catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
135
+ })
136
+ })
137
+
138
+ const saveReport = Effect.fn("Store.saveReport")(function* (stamp: string, text: string) {
139
+ const path = reportPath(root, stamp)
140
+ yield* ensureDir(reportsDir(root))
141
+ yield* Effect.tryPromise({
142
+ try: () => writeFile(path, text, "utf8"),
143
+ catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
144
+ })
145
+ return path
146
+ })
147
+
148
+ const cursors = cursorOps(state, saveState, inbox)
149
+ return { root, submit, inbox, state, saveState, saveReport, ...storyOps(root), ...cursors }
150
+ }
151
+
152
+ export const storeAt = (root: string): Layer.Layer<Store> => Layer.succeed(Store)(makeStore(root))
153
+
154
+ export const StoreLive = storeAt(defaultRoot())
@@ -0,0 +1,92 @@
1
+ import { describe, expect, it } from "@effect/vitest"
2
+ import { TestDriver } from "./index.ts"
3
+
4
+ describe("using adiff without reading its documentation", () => {
5
+ it("describes the commands it exposes, with the options each needs", async () => {
6
+ // ARRANGE
7
+ await using driver = await TestDriver.create()
8
+
9
+ // ACT
10
+ const result = await driver.app.runDescribe()
11
+
12
+ // ASSERT
13
+ expect(result.code).toBe(0)
14
+ const commands = (result.envelope as { commands: ReadonlyArray<{ name: string }> }).commands
15
+ expect(commands.map((command) => command.name)).toEqual([
16
+ "branch list",
17
+ "comment add",
18
+ "comment stage",
19
+ "comment take",
20
+ "file vouch",
21
+ "review submit",
22
+ "review progress",
23
+ "story set",
24
+ "story show",
25
+ "review open",
26
+ "describe",
27
+ ])
28
+ expect(commands).toContainEqual(
29
+ expect.objectContaining({
30
+ name: "story set",
31
+ safety: "write",
32
+ dataKey: "story",
33
+ options: expect.arrayContaining([
34
+ expect.objectContaining({ name: "json", required: true }),
35
+ ]),
36
+ }),
37
+ )
38
+ expect(commands).toContainEqual(
39
+ expect.objectContaining({
40
+ name: "comment take",
41
+ safety: "write",
42
+ dataKey: "comments",
43
+ options: expect.arrayContaining([
44
+ expect.objectContaining({ name: "worktree", required: true }),
45
+ ]),
46
+ }),
47
+ )
48
+ })
49
+
50
+ it("names the commands it knows when asked to describe one that does not exist", async () => {
51
+ // ARRANGE
52
+ await using driver = await TestDriver.create()
53
+
54
+ // ACT
55
+ const result = await driver.app.runDescribe("comment delete")
56
+
57
+ // ASSERT
58
+ expect(result.code).toBe(2)
59
+ expect(result.envelope).toMatchObject({
60
+ ok: false,
61
+ error: { type: "UnknownCommand", known: expect.arrayContaining(["comment add"]) },
62
+ })
63
+ })
64
+
65
+ it("keeps failures off stdout, so a caller can parse stdout unconditionally", async () => {
66
+ // ARRANGE
67
+ await using driver = await TestDriver.create()
68
+ await driver.branch.create({ name: "cdr-1-real" })
69
+
70
+ // ACT
71
+ const result = await driver.app.runProgress("cdr-99-imaginary")
72
+
73
+ // ASSERT
74
+ expect(result.stdout).toBe("")
75
+ expect(result.stderr).toContain("UnknownBranch")
76
+ })
77
+
78
+ it("returns only the asked-for fields, so a caller pays for what it reads", async () => {
79
+ // ARRANGE
80
+ await using driver = await TestDriver.create()
81
+ await driver.branch.create({ name: "cdr-1-add-third" })
82
+
83
+ // ACT
84
+ const result = await driver.app.runBranches(["--fields", "branch,files"])
85
+
86
+ // ASSERT
87
+ expect(result.envelope).toEqual({
88
+ ok: true,
89
+ branches: [{ branch: "cdr-1-add-third", files: 1 }],
90
+ })
91
+ })
92
+ })
@@ -0,0 +1,93 @@
1
+ import { describe, expect, it } from "@effect/vitest"
2
+ import { TestDriver } from "./index.ts"
3
+
4
+ describe("reviewing a branch the way a pull request is reviewed", () => {
5
+ it("holds staged comments back until the review is submitted", async () => {
6
+ // ARRANGE
7
+ await using driver = await TestDriver.create()
8
+ const branch = await driver.branch.create()
9
+
10
+ // ACT
11
+ await driver.app.runStage({
12
+ branch: branch.name,
13
+ file: "src/api.ts",
14
+ start: 4,
15
+ end: 4,
16
+ body: "third is unused",
17
+ })
18
+
19
+ // ASSERT
20
+ expect(await driver.agent.listBatches(branch.worktree)).toHaveLength(0)
21
+ expect(await driver.agent.listComments(branch.worktree)).toHaveLength(0)
22
+ })
23
+
24
+ it("delivers a whole review as one batch, so the agent wakes once", async () => {
25
+ // ARRANGE
26
+ await using driver = await TestDriver.create()
27
+ const branch = await driver.branch.create()
28
+ await driver.app.runStage({
29
+ branch: branch.name,
30
+ file: "src/api.ts",
31
+ start: 4,
32
+ end: 4,
33
+ body: "first",
34
+ })
35
+ await driver.app.runStage({
36
+ branch: branch.name,
37
+ file: "src/api.ts",
38
+ start: 5,
39
+ end: 5,
40
+ body: "second",
41
+ })
42
+
43
+ // ACT
44
+ const result = await driver.app.runSubmit(branch.name)
45
+
46
+ // ASSERT
47
+ expect(result.code).toBe(0)
48
+ const batches = await driver.agent.listBatches(branch.worktree)
49
+ expect(batches).toHaveLength(1)
50
+ const comments = await driver.agent.listComments(branch.worktree)
51
+ expect(comments.map((comment) => comment.body)).toEqual(["first", "second"])
52
+ })
53
+
54
+ it("reports how many comments are waiting to be submitted", async () => {
55
+ // ARRANGE
56
+ await using driver = await TestDriver.create()
57
+ const branch = await driver.branch.create()
58
+ await driver.app.runStage({
59
+ branch: branch.name,
60
+ file: "src/api.ts",
61
+ start: 4,
62
+ end: 4,
63
+ body: "first",
64
+ })
65
+
66
+ // ACT
67
+ const result = await driver.app.runProgress(branch.name)
68
+
69
+ // ASSERT
70
+ expect(result.envelope).toMatchObject({ ok: true, pending: 1 })
71
+ })
72
+
73
+ it("empties the review once submitted, so nothing is sent twice", async () => {
74
+ // ARRANGE
75
+ await using driver = await TestDriver.create()
76
+ const branch = await driver.branch.create()
77
+ await driver.app.runStage({
78
+ branch: branch.name,
79
+ file: "src/api.ts",
80
+ start: 4,
81
+ end: 4,
82
+ body: "only",
83
+ })
84
+ await driver.app.runSubmit(branch.name)
85
+
86
+ // ACT
87
+ const result = await driver.app.runSubmit(branch.name)
88
+
89
+ // ASSERT
90
+ expect(result.code).toBe(2)
91
+ expect(await driver.agent.listBatches(branch.worktree)).toHaveLength(1)
92
+ })
93
+ })
@@ -0,0 +1,99 @@
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("choosing which branch needs you", () => {
15
+ it("says how many comments are waiting to be sent", async () => {
16
+ // ARRANGE
17
+ await using driver = await TestDriver.create()
18
+ const branch = await driver.branch.create(oneFile)
19
+ await driver.app.runStage({
20
+ branch: branch.name,
21
+ file: "src/api.ts",
22
+ start: 2,
23
+ end: 2,
24
+ body: "why",
25
+ })
26
+
27
+ // ACT
28
+ const result = await driver.app.runBranches()
29
+
30
+ // ASSERT
31
+ expect(result.envelope).toMatchObject({
32
+ ok: true,
33
+ branches: [{ branch: branch.name, staged: 1, unread: 0 }],
34
+ })
35
+ })
36
+
37
+ it("says how many the agent has not collected", async () => {
38
+ // ARRANGE
39
+ await using driver = await TestDriver.create()
40
+ const branch = await driver.branch.create(oneFile)
41
+ await driver.app.runComment({
42
+ branch: branch.name,
43
+ file: "src/api.ts",
44
+ start: 2,
45
+ end: 2,
46
+ body: "sent now",
47
+ })
48
+
49
+ // ACT
50
+ const result = await driver.app.runBranches()
51
+
52
+ // ASSERT
53
+ expect(result.envelope).toMatchObject({
54
+ ok: true,
55
+ branches: [{ branch: branch.name, staged: 0, unread: 1 }],
56
+ })
57
+ })
58
+
59
+ it("shows the counts on the branches screen", async () => {
60
+ // ARRANGE
61
+ await using driver = await TestDriver.create()
62
+ const branch = await driver.branch.create(oneFile)
63
+ await driver.app.runStage({
64
+ branch: branch.name,
65
+ file: "src/api.ts",
66
+ start: 2,
67
+ end: 2,
68
+ body: "why",
69
+ })
70
+
71
+ // ACT
72
+ await driver.screen.open()
73
+
74
+ // ASSERT
75
+ const rows = (await driver.screen.getFrame()).split("\n")
76
+ const row = rows.find((line) => line.includes("cdr-1-add-third"))
77
+ expect(row).toContain("1 staged")
78
+ })
79
+ })
80
+
81
+ describe("coming back to the branch list", () => {
82
+ it("shows work staged since the list was last drawn", async () => {
83
+ // ARRANGE
84
+ await using driver = await TestDriver.create()
85
+ await driver.branch.create(oneFile)
86
+ await driver.screen.open()
87
+ await driver.screen.pressKeys(["RETURN", "c"])
88
+ await driver.screen.typeText("hold this")
89
+ await driver.screen.pressCtrl("a")
90
+
91
+ // ACT
92
+ await driver.screen.pressEscape()
93
+
94
+ // ASSERT
95
+ const rows = (await driver.screen.getFrame()).split("\n")
96
+ const row = rows.find((line) => line.includes("cdr-1-add-third"))
97
+ expect(row).toContain("1 staged")
98
+ })
99
+ })
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it } from "@effect/vitest"
2
+ import { TestDriver } from "./index.ts"
3
+
4
+ const oneFile = {
5
+ files: [
6
+ { path: "src/api.ts", before: ["const keep = 0"], after: ["const keep = 0", "const a = 1"] },
7
+ ],
8
+ }
9
+
10
+ const indentOf = (row: string): number => row.length - row.trimStart().length
11
+
12
+ describe("how the chrome reads", () => {
13
+ it("draws footer keys brighter than what they do", async () => {
14
+ // ARRANGE
15
+ await using driver = await TestDriver.create()
16
+ await driver.branch.create(oneFile)
17
+ await driver.screen.open()
18
+
19
+ // ACT
20
+ await driver.screen.pressKeys(["RETURN"])
21
+
22
+ // ASSERT
23
+ expect(await driver.screen.listForegroundsOn("v select")).toHaveLength(2)
24
+ })
25
+
26
+ it("draws the branch name brighter than the rest of the header", async () => {
27
+ // ARRANGE
28
+ await using driver = await TestDriver.create()
29
+ await driver.branch.create(oneFile)
30
+ await driver.screen.open()
31
+
32
+ // ACT
33
+ await driver.screen.pressKeys(["RETURN"])
34
+
35
+ // ASSERT
36
+ expect(await driver.screen.listForegroundsOn("cdr-1-add-third src/api.ts")).toHaveLength(2)
37
+ })
38
+ })
39
+
40
+ describe("how the screen breathes", () => {
41
+ it("keeps an even gutter down the left of every bar", async () => {
42
+ // ARRANGE
43
+ await using driver = await TestDriver.create()
44
+ await driver.branch.create(oneFile)
45
+ await driver.screen.open()
46
+
47
+ // ACT
48
+ await driver.screen.pressKeys(["RETURN"])
49
+
50
+ // ASSERT
51
+ const rows = (await driver.screen.getFrame()).split("\n")
52
+ const header = rows.find((row) => row.includes("src/api.ts")) ?? ""
53
+ const footer = rows.findLast((row) => row.includes("select")) ?? ""
54
+ expect(indentOf(header)).toBeGreaterThan(0)
55
+ expect(indentOf(footer)).toBe(indentOf(header))
56
+ })
57
+ })
@@ -0,0 +1,84 @@
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 long =
15
+ "Worth carrying the tenant here too, otherwise the log line is ambiguous and nobody reading it later can tell which tenant the failure belonged to."
16
+
17
+ const rowsWith = (frame: string, text: string): ReadonlyArray<string> =>
18
+ frame.split("\n").filter((line) => line.includes(text))
19
+
20
+ const rowWith = (frame: string, text: string): string => rowsWith(frame, text)[0] ?? ""
21
+
22
+ describe("how a comment sits in the diff", () => {
23
+ it("says whether it is staged or already sent", async () => {
24
+ // ARRANGE
25
+ await using driver = await TestDriver.create()
26
+ await driver.branch.create(oneFile)
27
+ await driver.screen.open()
28
+ await driver.screen.pressKeys(["RETURN"])
29
+ await driver.screen.pressKeys(["j"])
30
+
31
+ // ACT
32
+ await driver.screen.pressKeys(["c"])
33
+ await driver.screen.typeText("short one")
34
+ await driver.screen.pressCtrl("a")
35
+
36
+ // ASSERT
37
+ const frame = await driver.screen.getFrame()
38
+ const lines = frame.split("\n")
39
+ const anchor = lines.findIndex((line) => line.includes("const first = 1"))
40
+ expect(lines[anchor + 1]).toContain("staged")
41
+ expect(lines[anchor + 2]).toContain("short one")
42
+ })
43
+
44
+ it("wraps a long comment inside the diff instead of running off it", async () => {
45
+ // ARRANGE
46
+ await using driver = await TestDriver.create()
47
+ await driver.branch.create(oneFile)
48
+ await driver.screen.open()
49
+ await driver.screen.pressKeys(["RETURN"])
50
+ await driver.screen.pressKeys(["j"])
51
+
52
+ // ACT
53
+ await driver.screen.pressKeys(["c"])
54
+ await driver.screen.typeText(long)
55
+ await driver.screen.pressCtrl("a")
56
+
57
+ // ASSERT
58
+ const frame = await driver.screen.getFrame()
59
+ expect(rowsWith(frame, "Worth carrying the tenant")).toHaveLength(1)
60
+ expect(frame).toContain("nobody reading it later")
61
+ expect(rowWith(frame, "Worth carrying the tenant").length).toBeLessThanOrEqual(
62
+ frame.split("\n")[0]?.length ?? 0,
63
+ )
64
+ })
65
+
66
+ it("runs a rule down the left of every line it takes up", async () => {
67
+ // ARRANGE
68
+ await using driver = await TestDriver.create()
69
+ await driver.branch.create(oneFile)
70
+ await driver.screen.open()
71
+ await driver.screen.pressKeys(["RETURN"])
72
+ await driver.screen.pressKeys(["j"])
73
+
74
+ // ACT
75
+ await driver.screen.pressKeys(["c"])
76
+ await driver.screen.typeText(long)
77
+ await driver.screen.pressCtrl("a")
78
+
79
+ // ASSERT
80
+ const frame = await driver.screen.getFrame()
81
+ expect(rowWith(frame, "Worth carrying the tenant")).toContain("│")
82
+ expect(rowWith(frame, "nobody reading it later")).toContain("│")
83
+ })
84
+ })