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

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 (112) hide show
  1. package/.agents/prd/README.md +2 -2
  2. package/CHANGELOG.md +70 -0
  3. package/LICENSE +21 -0
  4. package/README.md +81 -188
  5. package/bin/adiff.js +76 -2
  6. package/dist/main.js +15039 -0
  7. package/package.json +9 -7
  8. package/skills/adiff/SKILL.md +40 -18
  9. package/src/cli/catalog.ts +0 -178
  10. package/src/cli/commands.ts +0 -335
  11. package/src/cli/error.ts +0 -44
  12. package/src/cli/index.ts +0 -24
  13. package/src/cli/parse.ts +0 -31
  14. package/src/cli/report.ts +0 -96
  15. package/src/cli/story.ts +0 -223
  16. package/src/domain/narrative/coverage.ts +0 -54
  17. package/src/domain/narrative/index.ts +0 -4
  18. package/src/domain/narrative/model.ts +0 -46
  19. package/src/domain/narrative/version.ts +0 -63
  20. package/src/domain/patch/anchor.ts +0 -40
  21. package/src/domain/patch/index.ts +0 -7
  22. package/src/domain/patch/model.ts +0 -54
  23. package/src/domain/patch/parse.ts +0 -106
  24. package/src/domain/patch/render.ts +0 -48
  25. package/src/domain/patch/sticky.ts +0 -39
  26. package/src/domain/review/index.ts +0 -4
  27. package/src/domain/review/lifecycle.ts +0 -45
  28. package/src/domain/review/model.ts +0 -23
  29. package/src/domain/review/vouch.ts +0 -15
  30. package/src/main.ts +0 -186
  31. package/src/service/git/error.ts +0 -16
  32. package/src/service/git/index.ts +0 -3
  33. package/src/service/git/model.ts +0 -13
  34. package/src/service/git/run.ts +0 -27
  35. package/src/service/git/service.ts +0 -133
  36. package/src/service/store/error.ts +0 -11
  37. package/src/service/store/index.ts +0 -5
  38. package/src/service/store/model.ts +0 -33
  39. package/src/service/store/paths.ts +0 -25
  40. package/src/service/store/service.ts +0 -154
  41. package/src/testing/agent-surface.test.ts +0 -92
  42. package/src/testing/batch.test.ts +0 -93
  43. package/src/testing/branch-state.test.ts +0 -99
  44. package/src/testing/chrome-tone.test.ts +0 -57
  45. package/src/testing/comment-block.test.ts +0 -84
  46. package/src/testing/comment-walk.test.ts +0 -96
  47. package/src/testing/compose-box.test.ts +0 -97
  48. package/src/testing/compose.test.ts +0 -67
  49. package/src/testing/context.test.ts +0 -77
  50. package/src/testing/cursor.test.ts +0 -49
  51. package/src/testing/delivery.test.ts +0 -94
  52. package/src/testing/domains/agent/driver.ts +0 -50
  53. package/src/testing/domains/agent/index.ts +0 -2
  54. package/src/testing/domains/app/driver.ts +0 -168
  55. package/src/testing/domains/app/index.ts +0 -2
  56. package/src/testing/domains/branch/driver.ts +0 -51
  57. package/src/testing/domains/branch/index.ts +0 -3
  58. package/src/testing/domains/branch/model.ts +0 -39
  59. package/src/testing/domains/screen/driver.ts +0 -241
  60. package/src/testing/domains/screen/index.ts +0 -2
  61. package/src/testing/driver.ts +0 -31
  62. package/src/testing/escape.test.ts +0 -56
  63. package/src/testing/focus.test.ts +0 -104
  64. package/src/testing/footer-chips.test.ts +0 -65
  65. package/src/testing/footer.test.ts +0 -64
  66. package/src/testing/gaps.test.ts +0 -47
  67. package/src/testing/highlight.test.ts +0 -49
  68. package/src/testing/home-screen.test.ts +0 -51
  69. package/src/testing/index.ts +0 -4
  70. package/src/testing/inline-comments.test.ts +0 -131
  71. package/src/testing/marks.test.ts +0 -49
  72. package/src/testing/mouse.test.ts +0 -87
  73. package/src/testing/navigate.test.ts +0 -73
  74. package/src/testing/palette.test.ts +0 -68
  75. package/src/testing/pending.test.ts +0 -70
  76. package/src/testing/pin-align.test.ts +0 -37
  77. package/src/testing/progress.test.ts +0 -88
  78. package/src/testing/report.test.ts +0 -83
  79. package/src/testing/resume.test.ts +0 -39
  80. package/src/testing/review.test.ts +0 -181
  81. package/src/testing/roundtrip.test.ts +0 -70
  82. package/src/testing/scale.test.ts +0 -55
  83. package/src/testing/scroll-feel.test.ts +0 -81
  84. package/src/testing/sent-comments.test.ts +0 -106
  85. package/src/testing/state.ts +0 -55
  86. package/src/testing/sticky-removed.test.ts +0 -67
  87. package/src/testing/sticky.test.ts +0 -90
  88. package/src/testing/story-rail.test.ts +0 -122
  89. package/src/testing/story.test.ts +0 -183
  90. package/src/testing/stress.test.ts +0 -74
  91. package/src/testing/tree-collapse.test.ts +0 -108
  92. package/src/testing/tree-rows.test.ts +0 -66
  93. package/src/testing/tree.test.ts +0 -91
  94. package/src/testing/tui.test.ts +0 -73
  95. package/src/testing/typing.test.ts +0 -65
  96. package/src/testing/vouch-next.test.ts +0 -65
  97. package/src/testing/vouch-tui.test.ts +0 -77
  98. package/src/testing/wash.test.ts +0 -32
  99. package/src/testing/width.test.ts +0 -62
  100. package/src/tui/app.ts +0 -467
  101. package/src/tui/command.ts +0 -390
  102. package/src/tui/diffview.ts +0 -333
  103. package/src/tui/index.ts +0 -9
  104. package/src/tui/marks.ts +0 -102
  105. package/src/tui/match.ts +0 -34
  106. package/src/tui/model.ts +0 -310
  107. package/src/tui/reduce.ts +0 -305
  108. package/src/tui/render.ts +0 -897
  109. package/src/tui/report.ts +0 -74
  110. package/src/tui/session.ts +0 -32
  111. package/src/tui/theme.ts +0 -61
  112. package/src/tui/tree.ts +0 -149
@@ -1,168 +0,0 @@
1
- import { execFile } from "node:child_process"
2
- import { fileURLToPath } from "node:url"
3
- import { promisify } from "node:util"
4
- import type { DriverState } from "../../state.ts"
5
-
6
- const exec = promisify(execFile)
7
-
8
- const NODE_FLAGS = ["--experimental-ffi", "--disable-warning=ExperimentalWarning"]
9
-
10
- const ENTRY = fileURLToPath(new URL("../../../main.ts", import.meta.url))
11
-
12
- export type CliResult = {
13
- readonly code: number
14
- readonly stdout: string
15
- readonly stderr: string
16
- readonly envelope: unknown
17
- }
18
-
19
- export type StoryStepInput = {
20
- readonly title: string
21
- readonly note?: string
22
- readonly spans: ReadonlyArray<{ readonly path: string; readonly start: number; readonly end: number }>
23
- }
24
-
25
- export type StoryInput = {
26
- readonly summary?: string
27
- readonly steps: ReadonlyArray<StoryStepInput>
28
- }
29
-
30
- export type CommentOptions = {
31
- readonly branch: string
32
- readonly file: string
33
- readonly start: number
34
- readonly end: number
35
- readonly body: string
36
- readonly side?: "old" | "new"
37
- }
38
-
39
- const parse = (text: string): unknown => {
40
- const line = text.split("\n").findLast((candidate) => candidate.startsWith("{"))
41
- return line === undefined ? undefined : JSON.parse(line)
42
- }
43
-
44
- export class AppTestDriver {
45
- private readonly state: DriverState
46
-
47
- constructor(state: DriverState) {
48
- this.state = state
49
- }
50
-
51
- async run(args: ReadonlyArray<string>): Promise<CliResult> {
52
- const env = { ...process.env, ADIFF_ROOT: this.state.storeRoot }
53
- try {
54
- const { stdout, stderr } = await exec(process.execPath, [...NODE_FLAGS, ENTRY, ...args], { env, encoding: "utf8" })
55
- return { code: 0, stdout, stderr, envelope: parse(stdout) }
56
- } catch (cause) {
57
- const failed = cause as { code?: number; stdout?: string; stderr?: string }
58
- const stdout = failed.stdout ?? ""
59
- const stderr = failed.stderr ?? ""
60
- return { code: failed.code ?? 1, stdout, stderr, envelope: parse(stderr) || parse(stdout) }
61
- }
62
- }
63
-
64
- private runWith(args: ReadonlyArray<string>, input: string): Promise<CliResult> {
65
- const env = { ...process.env, ADIFF_ROOT: this.state.storeRoot }
66
- return new Promise((resolve) => {
67
- const child = execFile(
68
- process.execPath,
69
- [...NODE_FLAGS, ENTRY, ...args],
70
- { env, encoding: "utf8" },
71
- (cause, stdout, stderr) => {
72
- const failed = cause as { code?: number } | null
73
- const code = failed === null ? 0 : Number(failed.code ?? 1)
74
- resolve({
75
- code,
76
- stdout: String(stdout),
77
- stderr: String(stderr),
78
- envelope: parse(String(stderr)) || parse(String(stdout)),
79
- })
80
- },
81
- )
82
- child.stdin?.end(input)
83
- })
84
- }
85
-
86
- runStorySet(worktree: string, story: StoryInput | string): Promise<CliResult> {
87
- const document = typeof story === "string" ? story : JSON.stringify(story)
88
- return this.runWith(["story", "set", "--worktree", worktree, "--json", "-"], document)
89
- }
90
-
91
- runStoryShow(worktree: string, fields?: ReadonlyArray<string>): Promise<CliResult> {
92
- return this.run(["story", "show", "--worktree", worktree, ...(fields ?? [])])
93
- }
94
-
95
- runStage(options: CommentOptions): Promise<CliResult> {
96
- return this.run([
97
- "comment",
98
- "stage",
99
- "--repo",
100
- this.state.repo,
101
- "--branch",
102
- options.branch,
103
- "--file",
104
- options.file,
105
- "--start",
106
- String(options.start),
107
- "--end",
108
- String(options.end),
109
- "--body",
110
- options.body,
111
- ...(options.side === undefined ? [] : ["--side", options.side]),
112
- ])
113
- }
114
-
115
- runSubmit(branch: string): Promise<CliResult> {
116
- return this.run(["review", "submit", "--repo", this.state.repo, "--branch", branch])
117
- }
118
-
119
- runDescribe(command?: string): Promise<CliResult> {
120
- return this.run(command === undefined ? ["describe"] : ["describe", "--command", command])
121
- }
122
-
123
- runTake(worktree: string, wait?: number): Promise<CliResult> {
124
- const args = ["comment", "take", "--worktree", worktree]
125
- return this.run(wait === undefined ? args : [...args, "--wait", String(wait)])
126
- }
127
-
128
- runBranches(fields?: ReadonlyArray<string>): Promise<CliResult> {
129
- return this.run(["branch", "list", "--repo", this.state.repo, ...(fields ?? [])])
130
- }
131
-
132
- runVouch(options: { readonly branch: string; readonly file: string }): Promise<CliResult> {
133
- return this.run([
134
- "file",
135
- "vouch",
136
- "--repo",
137
- this.state.repo,
138
- "--branch",
139
- options.branch,
140
- "--file",
141
- options.file,
142
- ])
143
- }
144
-
145
- runProgress(branch: string): Promise<CliResult> {
146
- return this.run(["review", "progress", "--repo", this.state.repo, "--branch", branch])
147
- }
148
-
149
- runComment(options: CommentOptions): Promise<CliResult> {
150
- return this.run([
151
- "comment",
152
- "add",
153
- "--repo",
154
- this.state.repo,
155
- "--branch",
156
- options.branch,
157
- "--file",
158
- options.file,
159
- "--start",
160
- String(options.start),
161
- "--end",
162
- String(options.end),
163
- "--body",
164
- options.body,
165
- ...(options.side === undefined ? [] : ["--side", options.side]),
166
- ])
167
- }
168
- }
@@ -1,2 +0,0 @@
1
- export { AppTestDriver } from "./driver.ts"
2
- export type { CliResult, CommentOptions, StoryInput, StoryStepInput } from "./driver.ts"
@@ -1,51 +0,0 @@
1
- import { mkdir, realpath, writeFile } from "node:fs/promises"
2
- import { dirname, join } from "node:path"
3
- import { series, type DriverState } from "../../state.ts"
4
- import { generateBranchTestModel, type BranchTestModel, type FileTestModel } from "./model.ts"
5
-
6
- export type CreateBranchOptions = {
7
- readonly name?: string
8
- readonly files?: ReadonlyArray<Partial<FileTestModel>>
9
- }
10
-
11
- export type CreatedBranch = BranchTestModel & {
12
- readonly worktree: string
13
- }
14
-
15
- export class BranchTestDriver {
16
- private readonly state: DriverState
17
-
18
- constructor(state: DriverState) {
19
- this.state = state
20
- }
21
-
22
- async create(options: CreateBranchOptions = {}): Promise<CreatedBranch> {
23
- const model = generateBranchTestModel(options)
24
- await this.commitBaseline(model)
25
- const worktree = join(dirname(this.state.repo), model.name)
26
- await this.state.git(this.state.repo, ["worktree", "add", "-q", "-b", model.name, worktree])
27
- await Promise.all(model.files.map((file) => this.write(worktree, file.path, file.after)))
28
- return { ...model, worktree: await realpath(worktree) }
29
- }
30
-
31
- async commitAll(branch: CreatedBranch, message: string): Promise<void> {
32
- await this.state.git(branch.worktree, ["add", "-A"])
33
- await this.state.git(branch.worktree, ["commit", "-q", "-m", message])
34
- }
35
-
36
- async setFile(branch: CreatedBranch, path: string, lines: ReadonlyArray<string>): Promise<void> {
37
- await this.write(branch.worktree, path, lines)
38
- }
39
-
40
- private async commitBaseline(model: BranchTestModel): Promise<void> {
41
- await series(model.files, (file) => this.write(this.state.repo, file.path, file.before))
42
- await this.state.git(this.state.repo, ["add", "-A"])
43
- await this.state.git(this.state.repo, ["commit", "-q", "-m", "baseline"])
44
- }
45
-
46
- private async write(root: string, path: string, lines: ReadonlyArray<string>): Promise<void> {
47
- const absolute = join(root, path)
48
- await mkdir(dirname(absolute), { recursive: true })
49
- await writeFile(absolute, `${lines.join("\n")}\n`, "utf8")
50
- }
51
- }
@@ -1,3 +0,0 @@
1
- export { BranchTestDriver } from "./driver.ts"
2
- export type { CreateBranchOptions, CreatedBranch } from "./driver.ts"
3
- export type { BranchTestModel, FileTestModel } from "./model.ts"
@@ -1,39 +0,0 @@
1
- export type FileTestModel = {
2
- readonly path: string
3
- readonly before: ReadonlyArray<string>
4
- readonly after: ReadonlyArray<string>
5
- }
6
-
7
- export type BranchTestModel = {
8
- readonly name: string
9
- readonly files: ReadonlyArray<FileTestModel>
10
- }
11
-
12
- export const generateFileTestModel = (overrides: Partial<FileTestModel> = {}): FileTestModel => ({
13
- path: overrides.path ?? "src/api.ts",
14
- before: overrides.before ?? [
15
- "export function api() {",
16
- " const first = 1",
17
- " const second = 2",
18
- " return first + second",
19
- "}",
20
- ],
21
- after: overrides.after ?? [
22
- "export function api() {",
23
- " const first = 1",
24
- " const second = 2",
25
- " const third = 3",
26
- " return first + second + third",
27
- "}",
28
- ],
29
- })
30
-
31
- export type BranchOverrides = {
32
- readonly name?: string
33
- readonly files?: ReadonlyArray<Partial<FileTestModel>>
34
- }
35
-
36
- export const generateBranchTestModel = (overrides: BranchOverrides = {}): BranchTestModel => ({
37
- name: overrides.name ?? "cdr-1-add-third",
38
- files: (overrides.files ?? [{}]).map(generateFileTestModel),
39
- })
@@ -1,241 +0,0 @@
1
- import { createTestRenderer, type TestRendererSetup } from "@opentui/core/testing"
2
- import { Effect, Exit, Layer, Scope } from "effect"
3
- import { GitLive } from "../../../service/git/index.ts"
4
- import { storeAt } from "../../../service/store/index.ts"
5
- import { launch } from "../../../tui/index.ts"
6
- import type { App } from "../../../tui/index.ts"
7
- import { series, type DriverState } from "../../state.ts"
8
-
9
- const hex = (value: number): string => value.toString(16).padStart(2, "0")
10
-
11
- const fgOf = (span: Span): string =>
12
- `#${hex(Math.round(span.fg.r * 255))}${hex(Math.round(span.fg.g * 255))}${hex(Math.round(span.fg.b * 255))}`
13
-
14
- const bgOf = (span: Span): string =>
15
- `#${hex(Math.round(span.bg.r * 255))}${hex(Math.round(span.bg.g * 255))}${hex(Math.round(span.bg.b * 255))}`
16
-
17
- const ESCAPE_FLUSH_MS = 150
18
- const PAINT_ATTEMPTS = 20
19
- const PAINT_WAIT_MS = 50
20
-
21
- type Span = { readonly fg: Channels; readonly bg: Channels }
22
-
23
- type Channels = { r: number; g: number; b: number }
24
- const NOTICE_MS = 900
25
- const WIDTH = 120
26
- const HEIGHT = 32
27
-
28
- export type OpenOptions = {
29
- readonly width?: number
30
- readonly height?: number
31
- }
32
-
33
- export class ScreenTestDriver {
34
- private setup: TestRendererSetup | undefined
35
- private scope: Scope.Closeable | undefined
36
- private app: App | undefined
37
- private readonly crashes: Array<string> = []
38
- private watching: ((cause: unknown) => void) | undefined
39
-
40
- private readonly state: DriverState
41
-
42
- constructor(state: DriverState) {
43
- this.state = state
44
- }
45
-
46
- async open(options: OpenOptions = {}): Promise<void> {
47
- const setup = await createTestRenderer({
48
- width: options.width ?? WIDTH,
49
- height: options.height ?? HEIGHT,
50
- })
51
- this.setup = setup
52
- this.watch()
53
- const layer = Layer.mergeAll(GitLive, storeAt(this.state.storeRoot))
54
- const scope = Scope.makeUnsafe()
55
- this.scope = scope
56
- const context = await Effect.runPromise(Layer.buildWithScope(layer, scope))
57
- this.app = await Effect.runPromise(
58
- launch(this.state.repo, setup.renderer, NOTICE_MS, this.state.sessionPath).pipe(
59
- Effect.provideContext(context),
60
- ),
61
- )
62
- await this.app.settled()
63
- await setup.waitForVisualIdle()
64
- }
65
-
66
- async restart(): Promise<void> {
67
- await this.close()
68
- await this.open()
69
- }
70
-
71
- private watch(): void {
72
- const record = (cause: unknown): void => {
73
- const message = cause instanceof Error ? cause.message : String(cause)
74
- this.crashes.push(message)
75
- }
76
- this.watching = record
77
- process.on("uncaughtException", record)
78
- process.on("unhandledRejection", record)
79
- }
80
-
81
- private stopWatching(): void {
82
- if (this.watching === undefined) return
83
- process.off("uncaughtException", this.watching)
84
- process.off("unhandledRejection", this.watching)
85
- this.watching = undefined
86
- }
87
-
88
- renderCrashes(): ReadonlyArray<string> {
89
- return this.crashes
90
- }
91
-
92
- private guard(): void {
93
- const first = this.crashes[0]
94
- if (first !== undefined) throw new Error(`the renderer crashed: ${first}`)
95
- }
96
-
97
- private active(): TestRendererSetup {
98
- const setup = this.setup
99
- if (setup === undefined) throw new Error("screen.open must run before the screen is driven")
100
- return setup
101
- }
102
-
103
- async pressKeys(keys: ReadonlyArray<string>): Promise<void> {
104
- const setup = this.active()
105
- await setup.mockInput.pressKeys([...keys])
106
- await this.app?.settled()
107
- await setup.waitForVisualIdle()
108
- }
109
-
110
- async typeText(text: string): Promise<void> {
111
- const setup = this.active()
112
- await setup.mockInput.typeText(text)
113
- await this.app?.settled()
114
- await setup.flush()
115
- }
116
-
117
- async waitForNoticeToClear(): Promise<void> {
118
- const setup = this.active()
119
- await new Promise((resolve) => setTimeout(resolve, NOTICE_MS + 300))
120
- await setup.flush()
121
- }
122
-
123
- async scroll(direction: "up" | "down", times = 1): Promise<void> {
124
- const setup = this.active()
125
- const x = Math.floor(WIDTH / 2) + 10
126
- const y = Math.floor(HEIGHT / 2)
127
- await series(
128
- Array.from({ length: times }, (_, step) => step),
129
- () => setup.mockMouse.scroll(x, y, direction),
130
- )
131
- await this.app?.settled()
132
- await setup.waitForVisualIdle()
133
- this.guard()
134
- }
135
-
136
- async dragOverDiff(fromY: number, toY: number): Promise<void> {
137
- const setup = this.active()
138
- const x = Math.floor(WIDTH / 2) + 10
139
- await setup.mockMouse.drag(x, fromY, x, toY)
140
- await this.app?.settled()
141
- await setup.waitForVisualIdle()
142
- this.guard()
143
- }
144
-
145
- async pressEscape(): Promise<void> {
146
- const setup = this.active()
147
- setup.mockInput.pressEscape()
148
- await new Promise((resolve) => setTimeout(resolve, ESCAPE_FLUSH_MS))
149
- await this.app?.settled()
150
- await setup.waitForVisualIdle()
151
- }
152
-
153
- async pressCtrl(letter: string): Promise<void> {
154
- const setup = this.active()
155
- setup.mockInput.pressKey(letter, { ctrl: true })
156
- await this.app?.settled()
157
- await setup.flush()
158
- }
159
-
160
- async findForeground(marker: string): Promise<ReadonlyArray<string>> {
161
- return this.findPainted(marker, fgOf)
162
- }
163
-
164
- private async findPainted(
165
- marker: string,
166
- read: (span: Span) => string,
167
- ): Promise<ReadonlyArray<string>> {
168
- const setup = this.active()
169
- const wanted = marker.toLowerCase()
170
- const rows = (): ReadonlyArray<string> =>
171
- setup
172
- .captureSpans()
173
- .lines.filter((line) => line.spans.some((span) => read(span as Span) === wanted))
174
- .map((line) => line.spans.map((span) => span.text).join("").trimEnd())
175
- const attempt = async (left: number): Promise<ReadonlyArray<string>> => {
176
- await setup.waitForVisualIdle()
177
- this.guard()
178
- const found = rows()
179
- if (found.length > 0 || left === 0) return found
180
- await new Promise((resolve) => setTimeout(resolve, PAINT_WAIT_MS))
181
- return attempt(left - 1)
182
- }
183
- return attempt(PAINT_ATTEMPTS)
184
- }
185
-
186
- async listForegroundsOn(text: string): Promise<ReadonlyArray<string>> {
187
- const setup = this.active()
188
- await setup.waitForVisualIdle()
189
- this.guard()
190
- const line = setup
191
- .captureSpans()
192
- .lines.find((candidate) => candidate.spans.map((span) => span.text).join("").includes(text))
193
- if (line === undefined) return []
194
- const whole = line.spans.map((span) => span.text).join("")
195
- const from = whole.indexOf(text)
196
- const to = from + text.length
197
- let at = 0
198
- const painted: Array<string> = []
199
- for (const span of line.spans) {
200
- const ends = at + span.text.length
201
- if (at < to && ends > from && span.text.trim().length > 0) painted.push(fgOf(span as Span))
202
- at = ends
203
- }
204
- return [...new Set(painted)]
205
- }
206
-
207
- async findHighlighted(marker: string): Promise<ReadonlyArray<string>> {
208
- return this.findPainted(marker, bgOf)
209
- }
210
-
211
- async debugSpans(): Promise<ReadonlyArray<string>> {
212
- const setup = this.active()
213
- await setup.waitForVisualIdle()
214
- return setup
215
- .captureSpans()
216
- .lines.map((line) =>
217
- line.spans.map((span) => `${bgOf(span)}:${span.text.trimEnd()}`).filter((s) => s.length > 8).join(" | "),
218
- )
219
- }
220
-
221
- async lastFailure(): Promise<string> {
222
- return this.app?.lastFailure() ?? ""
223
- }
224
-
225
- async getFrame(): Promise<string> {
226
- const setup = this.active()
227
- await setup.waitForVisualIdle()
228
- this.guard()
229
- return setup.captureCharFrame()
230
- }
231
-
232
- async close(): Promise<void> {
233
- this.stopWatching()
234
- this.setup?.renderer.destroy()
235
- this.setup = undefined
236
- this.app = undefined
237
- const scope = this.scope
238
- this.scope = undefined
239
- if (scope !== undefined) await Effect.runPromise(Scope.close(scope, Exit.void))
240
- }
241
- }
@@ -1,2 +0,0 @@
1
- export { ScreenTestDriver } from "./driver.ts"
2
- export type { OpenOptions } from "./driver.ts"
@@ -1,31 +0,0 @@
1
- import { AgentTestDriver } from "./domains/agent/index.ts"
2
- import { AppTestDriver } from "./domains/app/index.ts"
3
- import { BranchTestDriver } from "./domains/branch/index.ts"
4
- import { ScreenTestDriver } from "./domains/screen/index.ts"
5
- import { createDriverState, type DriverOptions, type DriverState } from "./state.ts"
6
-
7
- export class TestDriver implements AsyncDisposable {
8
- readonly branch: BranchTestDriver
9
- readonly app: AppTestDriver
10
- readonly agent: AgentTestDriver
11
- readonly screen: ScreenTestDriver
12
-
13
- private readonly state: DriverState
14
-
15
- private constructor(state: DriverState) {
16
- this.state = state
17
- this.branch = new BranchTestDriver(state)
18
- this.app = new AppTestDriver(state)
19
- this.agent = new AgentTestDriver(state)
20
- this.screen = new ScreenTestDriver(state)
21
- }
22
-
23
- static async create(options: DriverOptions = {}): Promise<TestDriver> {
24
- return new TestDriver(await createDriverState(options))
25
- }
26
-
27
- async [Symbol.asyncDispose](): Promise<void> {
28
- await this.screen.close()
29
- await this.state.dispose()
30
- }
31
- }
@@ -1,56 +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.ts", before: ["const c = 3"], after: ["const c = 3", "const d = 4"] },
8
- ],
9
- }
10
-
11
- describe("backing out of what you are doing", () => {
12
- it("clears a selection without leaving the file", 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", "v", "j"])
18
-
19
- // ACT
20
- await driver.screen.pressEscape()
21
-
22
- // ASSERT
23
- const frame = await driver.screen.getFrame()
24
- expect(frame).toContain("src/api.ts")
25
- expect(frame).toContain("1/2")
26
- })
27
-
28
- it("leaves the review only on a second press", async () => {
29
- // ARRANGE
30
- await using driver = await TestDriver.create()
31
- await driver.branch.create(twoFiles)
32
- await driver.screen.open()
33
- await driver.screen.pressKeys(["RETURN", "v", "j"])
34
- await driver.screen.pressEscape()
35
-
36
- // ACT
37
- await driver.screen.pressEscape()
38
-
39
- // ASSERT
40
- expect(await driver.screen.getFrame()).toContain("worktree")
41
- })
42
-
43
- it("treats q as back while reviewing, so a review is never lost to a stray key", async () => {
44
- // ARRANGE
45
- await using driver = await TestDriver.create()
46
- await driver.branch.create(twoFiles)
47
- await driver.screen.open()
48
- await driver.screen.pressKeys(["RETURN"])
49
-
50
- // ACT
51
- await driver.screen.pressKeys(["q"])
52
-
53
- // ASSERT
54
- expect(await driver.screen.getFrame()).toContain("worktree")
55
- })
56
- })