@eliya-oss/agent-diff 0.1.0-alpha.1 → 0.1.0-alpha.100

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/adr/README.md +3 -0
  2. package/.agents/prd/README.md +2 -2
  3. package/CHANGELOG.md +666 -0
  4. package/README.md +37 -79
  5. package/bin/adiff.js +80 -2
  6. package/dist/main.js +17611 -0
  7. package/package.json +14 -10
  8. package/skills/adiff/SKILL.md +140 -26
  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,97 +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
- const rowWith = (frame: string, text: string): string =>
15
- rowsOf(frame).find((row) => row.includes(text)) ?? ""
16
-
17
- const boxHeight = (frame: string): number =>
18
- rowsOf(frame).filter((row) => row.includes("┃")).length
19
-
20
- const rowsOf = (frame: string): ReadonlyArray<string> => frame.split("\n")
21
-
22
- describe("the box you write a comment in", () => {
23
- it("is drawn as a panel with a bar down its edge, not a box", 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
-
30
- // ACT
31
- await driver.screen.pressKeys(["c"])
32
-
33
- // ASSERT
34
- const frame = await driver.screen.getFrame()
35
- const panel = rowsOf(frame).filter((row) => row.includes("┃")).join("")
36
- expect(frame).toContain("Comment on src/api.ts")
37
- expect(panel).not.toContain("╭")
38
- expect(panel).not.toContain("╰")
39
- expect(rowWith(frame, "Comment on src/api.ts")).toContain("┃")
40
- })
41
-
42
- it("ends just below what you have written", async () => {
43
- // ARRANGE
44
- await using driver = await TestDriver.create()
45
- await driver.branch.create(oneFile)
46
- await driver.screen.open()
47
- await driver.screen.pressKeys(["RETURN"])
48
- await driver.screen.pressKeys(["c"])
49
-
50
- // ACT
51
- await driver.screen.typeText("one short remark")
52
-
53
- // ASSERT
54
- const rows = rowsOf(await driver.screen.getFrame())
55
- const written = rows.findIndex((row) => row.includes("one short remark"))
56
- const actions = rows.findIndex((row) => row.includes("cancel"))
57
- expect(written).toBeGreaterThan(0)
58
- expect(actions - written).toBe(2)
59
- })
60
-
61
- it("offers its actions on the box, with their keys", async () => {
62
- // ARRANGE
63
- await using driver = await TestDriver.create()
64
- await driver.branch.create(oneFile)
65
- await driver.screen.open()
66
- await driver.screen.pressKeys(["RETURN"])
67
-
68
- // ACT
69
- await driver.screen.pressKeys(["c"])
70
-
71
- // ASSERT
72
- const frame = await driver.screen.getFrame()
73
- const actions = rowsOf(frame).find((row) => row.includes("cancel")) ?? ""
74
- expect(actions).toContain("esc")
75
- expect(actions).toContain("cancel")
76
- expect(actions).toContain("add to review")
77
- expect(actions).toContain("comment now")
78
- })
79
-
80
- it("grows as the comment runs onto more lines", async () => {
81
- // ARRANGE
82
- await using driver = await TestDriver.create()
83
- await driver.branch.create(oneFile)
84
- await driver.screen.open()
85
- await driver.screen.pressKeys(["RETURN"])
86
- await driver.screen.pressKeys(["c"])
87
- await driver.screen.typeText("first line")
88
- const before = boxHeight(await driver.screen.getFrame())
89
-
90
- // ACT
91
- await driver.screen.pressKeys(["RETURN"])
92
- await driver.screen.typeText("second line")
93
-
94
- // ASSERT
95
- expect(boxHeight(await driver.screen.getFrame())).toBe(before + 1)
96
- })
97
- })
@@ -1,67 +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
- describe("writing a comment", () => {
15
- it("shows the code the comment will be attached to", 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", "v", "j"])
21
-
22
- // ACT
23
- await driver.screen.pressKeys(["c"])
24
-
25
- // ASSERT
26
- const frame = await driver.screen.getFrame()
27
- expect(frame).toContain("Comment on src/api.ts")
28
- const echoed = frame.split("\n").filter((line) => line.includes("const first = 1"))
29
- expect(echoed).toHaveLength(2)
30
- })
31
-
32
- it("takes more than one line of prose", async () => {
33
- // ARRANGE
34
- await using driver = await TestDriver.create()
35
- await driver.branch.create(oneFile)
36
- await driver.screen.open()
37
- await driver.screen.pressKeys(["RETURN", "c"])
38
- await driver.screen.typeText("first line")
39
-
40
- // ACT
41
- await driver.screen.pressKeys(["RETURN"])
42
- await driver.screen.typeText("second line")
43
-
44
- // ASSERT
45
- const lines = (await driver.screen.getFrame()).split("\n")
46
- expect(lines.some((line) => line.includes("first line") && line.includes("second line"))).toBe(
47
- false,
48
- )
49
- expect(lines.some((line) => line.includes("second line"))).toBe(true)
50
- })
51
-
52
- it("stages a comment for later instead of waking the agent now", async () => {
53
- // ARRANGE
54
- await using driver = await TestDriver.create()
55
- const branch = await driver.branch.create(oneFile)
56
- await driver.screen.open()
57
- await driver.screen.pressKeys(["RETURN", "c"])
58
- await driver.screen.typeText("hold this back")
59
-
60
- // ACT
61
- await driver.screen.pressCtrl("a")
62
-
63
- // ASSERT
64
- expect(await driver.agent.listBatches(branch.worktree)).toHaveLength(0)
65
- expect(await driver.screen.getFrame()).toContain("1 staged")
66
- })
67
- })
@@ -1,77 +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 around = (mark: string): ReadonlyArray<string> => [
6
- ...Array.from({ length: 12 }, (_, index) => `const above${index} = ${index}`),
7
- `const changed = "${mark}"`,
8
- ...Array.from({ length: 12 }, (_, index) => `const below${index} = ${index}`),
9
- ]
10
-
11
- const buried = {
12
- files: [{ path: "src/api.ts", before: around("before"), after: around("after") }],
13
- }
14
-
15
- describe("asking for more of the file", () => {
16
- it("shows only a little context to begin with", async () => {
17
- // ARRANGE
18
- await using driver = await TestDriver.create()
19
- await driver.branch.create(buried)
20
- await driver.screen.open()
21
-
22
- // ACT
23
- await driver.screen.pressKeys(["RETURN"])
24
-
25
- // ASSERT
26
- const frame = await driver.screen.getFrame()
27
- expect(frame).toContain("above11")
28
- expect(frame).not.toContain("above2")
29
- })
30
-
31
- it("widens the context when asked", async () => {
32
- // ARRANGE
33
- await using driver = await TestDriver.create()
34
- await driver.branch.create(buried)
35
- await driver.screen.open()
36
- await driver.screen.pressKeys(["RETURN"])
37
-
38
- // ACT
39
- await driver.screen.typeText("+")
40
-
41
- // ASSERT
42
- expect(await driver.screen.getFrame()).toContain("above2")
43
- })
44
-
45
- it("narrows it again", async () => {
46
- // ARRANGE
47
- await using driver = await TestDriver.create()
48
- await driver.branch.create(buried)
49
- await driver.screen.open()
50
- await driver.screen.pressKeys(["RETURN"])
51
- await driver.screen.typeText("+")
52
-
53
- // ACT
54
- await driver.screen.typeText("-")
55
-
56
- // ASSERT
57
- expect(await driver.screen.getFrame()).not.toContain("above2")
58
- })
59
-
60
- it("keeps the cursor on the same line of the file", async () => {
61
- // ARRANGE
62
- await using driver = await TestDriver.create()
63
- await driver.branch.create(buried)
64
- await driver.screen.open()
65
- await driver.screen.pressKeys(["RETURN"])
66
- await driver.screen.pressKeys(["j", "j", "j", "j"])
67
- const before = await driver.screen.findHighlighted(palette.cursor)
68
- expect(before.join(" ")).toContain("changed")
69
-
70
- // ACT
71
- await driver.screen.typeText("+")
72
-
73
- // ASSERT
74
- const after = await driver.screen.findHighlighted(palette.cursor)
75
- expect(after.join(" ")).toContain("changed")
76
- })
77
- })
@@ -1,49 +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 numbered = {
6
- files: [
7
- {
8
- path: "src/steps.ts",
9
- before: ["const zero = 0"],
10
- after: ["const zero = 0", "const one = 1", "const two = 2", "const three = 3"],
11
- },
12
- ],
13
- }
14
-
15
- describe("knowing which line you are on", () => {
16
- it("highlights the line the cursor is on, and only that line", async () => {
17
- // ARRANGE
18
- await using driver = await TestDriver.create()
19
- await driver.branch.create(numbered)
20
- await driver.screen.open()
21
- await driver.screen.pressKeys(["RETURN"])
22
-
23
- // ACT
24
- await driver.screen.pressKeys(["j", "j"])
25
-
26
- // ASSERT
27
- const highlighted = await driver.screen.findHighlighted(palette.cursor)
28
- expect(highlighted).toHaveLength(1)
29
- expect(highlighted[0]).toContain("const two = 2")
30
- })
31
-
32
- it("highlights every line of a selection", async () => {
33
- // ARRANGE
34
- await using driver = await TestDriver.create()
35
- await driver.branch.create(numbered)
36
- await driver.screen.open()
37
- await driver.screen.pressKeys(["RETURN"])
38
-
39
- // ACT
40
- await driver.screen.pressKeys(["j", "v", "j", "j"])
41
-
42
- // ASSERT
43
- const selected = await driver.screen.findHighlighted(palette.selection)
44
- expect(selected.map((line) => line.trim())).toEqual(
45
- expect.arrayContaining([expect.stringContaining("const one = 1")]),
46
- )
47
- expect(selected).toHaveLength(2)
48
- })
49
- })
@@ -1,94 +0,0 @@
1
- import { describe, expect, it } from "@effect/vitest"
2
- import { TestDriver } from "./index.ts"
3
-
4
- describe("handing review comments to the agent", () => {
5
- it("gives the agent every comment written since it last looked", async () => {
6
- // ARRANGE
7
- await using driver = await TestDriver.create()
8
- const branch = await driver.branch.create()
9
- await driver.app.runComment({
10
- branch: branch.name,
11
- file: "src/api.ts",
12
- start: 4,
13
- end: 4,
14
- body: "why third",
15
- })
16
-
17
- // ACT
18
- const result = await driver.app.runTake(branch.worktree)
19
-
20
- // ASSERT
21
- expect(result.envelope).toMatchObject({
22
- ok: true,
23
- comments: [{ body: "why third", file: "src/api.ts", side: "new", start: 4, end: 4 }],
24
- })
25
- })
26
-
27
- it("does not hand the same comment to the agent twice", async () => {
28
- // ARRANGE
29
- await using driver = await TestDriver.create()
30
- const branch = await driver.branch.create()
31
- await driver.app.runComment({
32
- branch: branch.name,
33
- file: "src/api.ts",
34
- start: 4,
35
- end: 4,
36
- body: "why third",
37
- })
38
- await driver.app.runTake(branch.worktree)
39
-
40
- // ACT
41
- const result = await driver.app.runTake(branch.worktree)
42
-
43
- // ASSERT
44
- expect(result.envelope).toMatchObject({ ok: true, comments: [] })
45
- })
46
-
47
- it("keeps handing over comments written after the agent caught up", async () => {
48
- // ARRANGE
49
- await using driver = await TestDriver.create()
50
- const branch = await driver.branch.create()
51
- await driver.app.runComment({
52
- branch: branch.name,
53
- file: "src/api.ts",
54
- start: 4,
55
- end: 4,
56
- body: "first",
57
- })
58
- await driver.app.runTake(branch.worktree)
59
-
60
- // ACT
61
- await driver.app.runComment({
62
- branch: branch.name,
63
- file: "src/api.ts",
64
- start: 5,
65
- end: 5,
66
- body: "second",
67
- })
68
- const result = await driver.app.runTake(branch.worktree)
69
-
70
- // ASSERT
71
- expect(result.envelope).toMatchObject({ ok: true, comments: [{ body: "second" }] })
72
- })
73
-
74
- it("still remembers which files were vouched after the agent takes comments", async () => {
75
- // ARRANGE
76
- await using driver = await TestDriver.create()
77
- const branch = await driver.branch.create()
78
- await driver.app.runVouch({ branch: branch.name, file: "src/api.ts" })
79
- await driver.app.runComment({
80
- branch: branch.name,
81
- file: "src/api.ts",
82
- start: 4,
83
- end: 4,
84
- body: "why third",
85
- })
86
-
87
- // ACT
88
- await driver.app.runTake(branch.worktree)
89
- const result = await driver.app.runProgress(branch.name)
90
-
91
- // ASSERT
92
- expect(result.envelope).toMatchObject({ vouched: ["src/api.ts"], total: 1 })
93
- })
94
- })
@@ -1,50 +0,0 @@
1
- import { readdir, readFile } from "node:fs/promises"
2
- import { join } from "node:path"
3
- import { Effect } from "effect"
4
- import { reportsDir, Store, storeAt, type Batch } from "../../../service/store/index.ts"
5
- import type { DriverState } from "../../state.ts"
6
-
7
- export type DeliveredComment = {
8
- readonly body: string
9
- readonly file: string
10
- readonly side: string
11
- readonly start: number
12
- readonly end: number
13
- readonly snippet: string
14
- }
15
-
16
- export class AgentTestDriver {
17
- private readonly state: DriverState
18
-
19
- constructor(state: DriverState) {
20
- this.state = state
21
- }
22
-
23
- async listReports(): Promise<ReadonlyArray<string>> {
24
- const directory = reportsDir(this.state.storeRoot)
25
- const names = await readdir(directory).catch(() => [])
26
- return Promise.all(names.map((name) => readFile(join(directory, name), "utf8")))
27
- }
28
-
29
- async listBatches(worktree: string): Promise<ReadonlyArray<Batch>> {
30
- const read = Effect.gen(function* () {
31
- const store = yield* Store
32
- return yield* store.inbox(worktree)
33
- })
34
- return Effect.runPromise(read.pipe(Effect.provide(storeAt(this.state.storeRoot))))
35
- }
36
-
37
- async listComments(worktree: string): Promise<ReadonlyArray<DeliveredComment>> {
38
- const batches = await this.listBatches(worktree)
39
- return batches.flatMap((batch) =>
40
- batch.comments.map((comment) => ({
41
- body: comment.body,
42
- file: comment.anchor.path,
43
- side: comment.anchor.side,
44
- start: comment.anchor.start,
45
- end: comment.anchor.end,
46
- snippet: comment.anchor.snippet,
47
- })),
48
- )
49
- }
50
- }
@@ -1,2 +0,0 @@
1
- export { AgentTestDriver } from "./driver.ts"
2
- export type { DeliveredComment } from "./driver.ts"
@@ -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"