@markjaquith/agency 3.2.14 → 3.3.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 (75) hide show
  1. package/README.md +20 -3
  2. package/cli-main.ts +1 -0
  3. package/package.json +7 -2
  4. package/src/cli-parser.ts +13 -0
  5. package/src/commands/work.ts +70 -2
  6. package/src/services/ReadinessService.ts +20 -0
  7. package/src/workbase/execution-contract.ts +10 -1
  8. package/src/workbase/schemas.ts +12 -0
  9. package/fixtures/protocol/orchestration-recipes.json +0 -53
  10. package/pi-extensions/agency.test.ts +0 -117
  11. package/src/check-commits.test.ts +0 -58
  12. package/src/cli-parser.test.ts +0 -945
  13. package/src/cli.test.ts +0 -1889
  14. package/src/commands/act.test.ts +0 -418
  15. package/src/commands/archive.test.ts +0 -236
  16. package/src/commands/context.test.ts +0 -711
  17. package/src/commands/description.test.ts +0 -103
  18. package/src/commands/doctor.test.ts +0 -185
  19. package/src/commands/epic.test.ts +0 -196
  20. package/src/commands/init.test.ts +0 -117
  21. package/src/commands/integration.test.ts +0 -165
  22. package/src/commands/pr.test.ts +0 -248
  23. package/src/commands/push.test.ts +0 -56
  24. package/src/commands/read-only.test.ts +0 -161
  25. package/src/commands/repo.test.ts +0 -199
  26. package/src/commands/restore.test.ts +0 -106
  27. package/src/commands/status.test.ts +0 -113
  28. package/src/commands/sync.test.ts +0 -200
  29. package/src/commands/task-phase.test.ts +0 -410
  30. package/src/commands/task.test.ts +0 -281
  31. package/src/commands/validate.test.ts +0 -186
  32. package/src/commands/work.test.ts +0 -1375
  33. package/src/commands/workbase.test.ts +0 -170
  34. package/src/graph-schema.test.ts +0 -124
  35. package/src/protocol.test.ts +0 -163
  36. package/src/readiness.test.ts +0 -105
  37. package/src/services/ArchiveBulkService.test.ts +0 -384
  38. package/src/services/ArchiveService.test.ts +0 -1092
  39. package/src/services/EpicService.test.ts +0 -74
  40. package/src/services/FileSystemService.test.ts +0 -81
  41. package/src/services/GraphMutationService.test.ts +0 -486
  42. package/src/services/GraphService.test.ts +0 -494
  43. package/src/services/IntegrationService.test.ts +0 -1091
  44. package/src/services/LifecycleTransaction.test.ts +0 -145
  45. package/src/services/PullRequestService.test.ts +0 -716
  46. package/src/services/PushService.test.ts +0 -408
  47. package/src/services/ReadinessService.test.ts +0 -290
  48. package/src/services/RepositoryService.test.ts +0 -789
  49. package/src/services/ReviewService.test.ts +0 -408
  50. package/src/services/SyncService.test.ts +0 -1377
  51. package/src/services/TaskPhaseService.test.ts +0 -852
  52. package/src/services/VersionControlService.test.ts +0 -62
  53. package/src/services/WorkbaseService.test.ts +0 -910
  54. package/src/services/WorktreeLock.test.ts +0 -205
  55. package/src/services/WorktreePerformance.test.ts +0 -71
  56. package/src/services/WorktreeService.test.ts +0 -2292
  57. package/src/test-utils.ts +0 -110
  58. package/src/usage-log.test.ts +0 -188
  59. package/src/utils/chooser.test.ts +0 -192
  60. package/src/utils/effect.test.ts +0 -30
  61. package/src/utils/interactive.pty.test.ts +0 -128
  62. package/src/utils/interactive.test.tsx +0 -860
  63. package/src/utils/process.test.ts +0 -132
  64. package/src/utils/progress.test.ts +0 -37
  65. package/src/work-view.test.ts +0 -151
  66. package/src/workbase/agent-command.test.ts +0 -128
  67. package/src/workbase/checkout-command.test.ts +0 -62
  68. package/src/workbase/delivery-command.test.ts +0 -180
  69. package/src/workbase/dependency-graph.test.ts +0 -50
  70. package/src/workbase/execution-contract.test.ts +0 -161
  71. package/src/workbase/frontmatter.test.ts +0 -67
  72. package/src/workbase/repository-reference.test.ts +0 -25
  73. package/src/workbase/schemas.test.ts +0 -543
  74. package/src/workbase/work-target.test.ts +0 -108
  75. package/src/workbase/worktree-command.test.ts +0 -61
@@ -1,716 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
- import { Effect } from "effect"
3
- import { chmod, mkdir, realpath, rm } from "node:fs/promises"
4
- import { join } from "node:path"
5
- import { cleanupTempDir, createTempDir, runTestEffect } from "../test-utils"
6
- import { PhaseService } from "./PhaseService"
7
- import { TaskService } from "./TaskService"
8
- import { PullRequestService } from "./PullRequestService"
9
- import { WorktreeService } from "./WorktreeService"
10
-
11
- interface CommandResult {
12
- readonly stdout: string
13
- readonly stderr: string
14
- readonly exitCode: number
15
- }
16
-
17
- const runCommand = async (
18
- args: readonly string[],
19
- cwd?: string,
20
- ): Promise<CommandResult> => {
21
- const process = Bun.spawn([...args], {
22
- cwd,
23
- stdout: "pipe",
24
- stderr: "pipe",
25
- })
26
- const [stdout, stderr, exitCode] = await Promise.all([
27
- new Response(process.stdout).text(),
28
- new Response(process.stderr).text(),
29
- process.exited,
30
- ])
31
- return { stdout: stdout.trim(), stderr: stderr.trim(), exitCode }
32
- }
33
-
34
- const requireCommand = async (args: readonly string[], cwd?: string) => {
35
- const result = await runCommand(args, cwd)
36
- if (result.exitCode !== 0) {
37
- throw new Error(`${args.join(" ")} failed: ${result.stderr}`)
38
- }
39
- return result
40
- }
41
-
42
- describe("PullRequestService", () => {
43
- let root: string
44
- let remotePath: string
45
- let ghCallPath: string
46
- let originalPath: string | undefined
47
-
48
- const createTask = (id = "example", branch = `task/${id}`) =>
49
- runTestEffect(
50
- TaskService.pipe(
51
- Effect.flatMap((service) =>
52
- service.create(
53
- {
54
- id,
55
- ticketUrl: "https://example.com/task",
56
- repo: "agency",
57
- branch,
58
- base: "main",
59
- },
60
- root,
61
- ),
62
- ),
63
- ),
64
- )
65
-
66
- const createPullRequest = (
67
- taskId = "example",
68
- phaseId?: string,
69
- draft = false,
70
- force = false,
71
- options: Record<string, unknown> = {},
72
- ) =>
73
- runTestEffect(
74
- PullRequestService.pipe(
75
- Effect.flatMap((service) =>
76
- service.create(taskId, phaseId, draft, root, { force, ...options }),
77
- ),
78
- ),
79
- )
80
-
81
- const materialize = (taskId = "example", phaseId?: string) =>
82
- runTestEffect(
83
- WorktreeService.pipe(
84
- Effect.flatMap((service) => service.materialize(taskId, phaseId, root)),
85
- ),
86
- )
87
-
88
- const writeFakeGh = async ({
89
- stdout = "",
90
- stderr = "",
91
- exitCode = 0,
92
- listStdouts = ["[]"],
93
- }: {
94
- stdout?: string
95
- stderr?: string
96
- exitCode?: number
97
- listStdouts?: readonly string[]
98
- }) => {
99
- const path = join(root, "bin", "gh")
100
- await Bun.write(
101
- path,
102
- `#!/usr/bin/env bun
103
- const args = Bun.argv.slice(2)
104
- const callFile = Bun.file(${JSON.stringify(ghCallPath)})
105
- const calls = await callFile.exists() ? await callFile.json() : []
106
- const listIndex = calls.filter((call) => call.args[1] === "list").length
107
- calls.push({ args, cwd: process.cwd() })
108
- await Bun.write(${JSON.stringify(ghCallPath)}, JSON.stringify(calls))
109
- if (args[1] === "list") {
110
- const responses = ${JSON.stringify(listStdouts)}
111
- process.stdout.write(responses[Math.min(listIndex, responses.length - 1)] ?? "[]")
112
- process.exit(0)
113
- }
114
- process.stdout.write(${JSON.stringify(stdout)})
115
- process.stderr.write(${JSON.stringify(stderr)})
116
- process.exit(${exitCode})
117
- `,
118
- )
119
- await chmod(path, 0o755)
120
- }
121
-
122
- const readGhCall = async () =>
123
- (
124
- (await Bun.file(ghCallPath).json()) as {
125
- args: string[]
126
- cwd: string
127
- }[]
128
- ).at(-1)!
129
-
130
- const readGhCalls = async () =>
131
- (await Bun.file(ghCallPath).json()) as {
132
- args: string[]
133
- cwd: string
134
- }[]
135
-
136
- const githubRecord = (
137
- number: number,
138
- branch = "task/example",
139
- base = "main",
140
- ) => ({
141
- number,
142
- url: `https://github.com/example/agency/pull/${number}`,
143
- state: "OPEN",
144
- isDraft: false,
145
- headRefName: branch,
146
- baseRefName: base,
147
- headRepository: { nameWithOwner: "example/agency" },
148
- mergeable: "UNKNOWN",
149
- })
150
-
151
- const expectRemoteBranch = async (branch: string, exists = true) => {
152
- const result = await runCommand([
153
- "git",
154
- "--git-dir",
155
- remotePath,
156
- "show-ref",
157
- "--verify",
158
- `refs/heads/${branch}`,
159
- ])
160
- expect(result.exitCode === 0).toBe(exists)
161
- }
162
-
163
- beforeEach(async () => {
164
- root = await createTempDir()
165
- remotePath = join(root, "remote.git")
166
- ghCallPath = join(root, "gh-call.json")
167
- originalPath = process.env.PATH
168
- await mkdir(join(root, "bin"), { recursive: true })
169
- process.env.PATH = `${join(root, "bin")}:${originalPath ?? ""}`
170
- await Bun.write(join(root, "agency.json"), '{"version":2}\n')
171
- await mkdir(join(root, "repos"), { recursive: true })
172
- await requireCommand([
173
- "git",
174
- "init",
175
- "--bare",
176
- "--initial-branch=main",
177
- remotePath,
178
- ])
179
- const seedPath = join(root, "seed")
180
- await requireCommand(["git", "init", "--initial-branch=main", seedPath])
181
- await requireCommand(
182
- ["git", "config", "user.name", "Agency Test"],
183
- seedPath,
184
- )
185
- await requireCommand(
186
- ["git", "config", "user.email", "agency@example.com"],
187
- seedPath,
188
- )
189
- await Bun.write(join(seedPath, "README.md"), "# Test repository\n")
190
- await requireCommand(["git", "add", "README.md"], seedPath)
191
- await requireCommand(["git", "commit", "-m", "Initial commit"], seedPath)
192
- await requireCommand(
193
- ["git", "remote", "add", "origin", remotePath],
194
- seedPath,
195
- )
196
- await requireCommand(["git", "push", "-u", "origin", "main"], seedPath)
197
- await requireCommand([
198
- "git",
199
- "clone",
200
- "--bare",
201
- remotePath,
202
- join(root, "repos", "agency"),
203
- ])
204
- })
205
-
206
- afterEach(async () => {
207
- process.env.PATH = originalPath
208
- await cleanupTempDir(root)
209
- })
210
-
211
- test("updates the execution document with a PR URL", async () => {
212
- await createTask()
213
- const url = "https://github.com/markjaquith/agency/pull/123"
214
- await runTestEffect(
215
- PullRequestService.pipe(
216
- Effect.flatMap((service) =>
217
- service.setUrl("example", undefined, url, root),
218
- ),
219
- ),
220
- )
221
- const task = await runTestEffect(
222
- TaskService.pipe(
223
- Effect.flatMap((service) => service.show("example", root)),
224
- ),
225
- )
226
- expect("pr" in task.data && task.data.pr).toMatchObject({
227
- provider: "github",
228
- repository: "markjaquith/agency",
229
- identifier: "123",
230
- url,
231
- })
232
- })
233
-
234
- test("rejects non-GitHub PR URLs", async () => {
235
- await createTask()
236
- await expect(
237
- runTestEffect(
238
- PullRequestService.pipe(
239
- Effect.flatMap((service) =>
240
- service.setUrl(
241
- "example",
242
- undefined,
243
- "https://example.com/pr/1",
244
- root,
245
- ),
246
- ),
247
- ),
248
- ),
249
- ).rejects.toThrow("Invalid GitHub pull request URL")
250
- })
251
-
252
- test("creates a clean single-phase PR and preserves the task body", async () => {
253
- await createTask()
254
- const taskPath = join(root, "tasks", "example", "TASK.md")
255
- const body = "# Example\n\nKeep this exact body after creating the PR."
256
- const original = await Bun.file(taskPath).text()
257
- await Bun.write(
258
- taskPath,
259
- original.replace(
260
- "# Example\n\n## Outcome\n\nDescribe the task outcome.\n\n## Plan\n\nDescribe the current approach.\n\n## Important Decisions\n\nRecord consequential decisions and their rationale.",
261
- body,
262
- ),
263
- )
264
- const url = "https://github.com/example/agency/pull/42"
265
- await writeFakeGh({ stdout: `${url}\n` })
266
-
267
- expect(await createPullRequest()).toBe(url)
268
- await expectRemoteBranch("task/example")
269
- const ghCall = await readGhCall()
270
- expect(ghCall).toEqual({
271
- args: [
272
- "pr",
273
- "create",
274
- "--fill",
275
- "--repo",
276
- remotePath.replace(/\.git$/, ""),
277
- "--base",
278
- "main",
279
- "--head",
280
- "task/example",
281
- ],
282
- cwd: await realpath(join(root, "tasks", "example", "code", "agency")),
283
- })
284
- const updated = await Bun.file(taskPath).text()
285
- expect(updated).toContain("pr:\n provider: github")
286
- expect(updated).toContain("url: https://github.com/example/agency/pull/42")
287
- expect(updated.endsWith(`${body}\n`)).toBe(true)
288
- })
289
-
290
- test("passes --draft to gh", async () => {
291
- await createTask()
292
- await writeFakeGh({
293
- stdout: "https://github.com/example/agency/pull/43\n",
294
- })
295
-
296
- await createPullRequest("example", undefined, true)
297
-
298
- expect((await readGhCall()).args).toEqual([
299
- "pr",
300
- "create",
301
- "--fill",
302
- "--repo",
303
- remotePath.replace(/\.git$/, ""),
304
- "--base",
305
- "main",
306
- "--head",
307
- "task/example",
308
- "--draft",
309
- ])
310
- })
311
-
312
- test("passes task-aware GitHub title and labels with declared refs", async () => {
313
- await createTask()
314
- await writeFakeGh({
315
- stdout: "https://github.com/example/agency/pull/45\n",
316
- })
317
-
318
- await createPullRequest("example", undefined, true, false, {
319
- title: "Ship the workflow",
320
- head: "task/example",
321
- base: "main",
322
- labels: ["ai-assisted", "platform"],
323
- })
324
-
325
- expect((await readGhCall()).args).toEqual([
326
- "pr",
327
- "create",
328
- "--fill",
329
- "--title",
330
- "Ship the workflow",
331
- "--repo",
332
- remotePath.replace(/\.git$/, ""),
333
- "--base",
334
- "main",
335
- "--head",
336
- "task/example",
337
- "--draft",
338
- "--label",
339
- "ai-assisted",
340
- "--label",
341
- "platform",
342
- ])
343
- })
344
-
345
- test("records an existing matching GitHub PR without creating another", async () => {
346
- await createTask()
347
- const existing = githubRecord(46)
348
- await writeFakeGh({ listStdouts: [JSON.stringify([existing])] })
349
-
350
- expect(await createPullRequest()).toBe(existing.url)
351
- const calls = await readGhCalls()
352
- expect(calls).toHaveLength(1)
353
- expect(calls[0]!.args).toEqual([
354
- "pr",
355
- "list",
356
- "--repo",
357
- remotePath.replace(/\.git$/, ""),
358
- "--head",
359
- "task/example",
360
- "--base",
361
- "main",
362
- "--state",
363
- "all",
364
- "--json",
365
- "number,state,isDraft,headRefName,baseRefName,headRepository,url,mergedAt,mergeable",
366
- ])
367
- })
368
-
369
- test("recovers a matching GitHub PR after an ambiguous create failure", async () => {
370
- await createTask()
371
- const recovered = githubRecord(47)
372
- await writeFakeGh({
373
- stderr: "a pull request already exists",
374
- exitCode: 1,
375
- listStdouts: ["[]", JSON.stringify([recovered])],
376
- })
377
-
378
- expect(await createPullRequest()).toBe(recovered.url)
379
- expect((await readGhCalls()).map((call) => call.args[1])).toEqual([
380
- "list",
381
- "create",
382
- "list",
383
- ])
384
- const task = await runTestEffect(
385
- TaskService.pipe(
386
- Effect.flatMap((service) => service.show("example", root)),
387
- ),
388
- )
389
- expect("pr" in task.data && task.data.pr).toMatchObject({
390
- url: recovered.url,
391
- headBranch: "task/example",
392
- baseBranch: "main",
393
- })
394
- })
395
-
396
- test("recovers a matching GitHub PR after create output is lost", async () => {
397
- await createTask()
398
- const recovered = githubRecord(48)
399
- await writeFakeGh({
400
- stdout: "Pull request created successfully",
401
- listStdouts: ["[]", JSON.stringify([recovered])],
402
- })
403
-
404
- expect(await createPullRequest()).toBe(recovered.url)
405
- expect((await readGhCalls()).map((call) => call.args[1])).toEqual([
406
- "list",
407
- "create",
408
- "list",
409
- ])
410
- })
411
-
412
- test("does not adopt a GitHub PR with mismatched refs", async () => {
413
- await createTask()
414
- await writeFakeGh({
415
- stdout: "Pull request created successfully",
416
- listStdouts: [
417
- JSON.stringify([githubRecord(49, "task/other")]),
418
- JSON.stringify([githubRecord(49, "task/other")]),
419
- ],
420
- })
421
-
422
- await expect(createPullRequest()).rejects.toThrow(
423
- "GitHub CLI did not return a pull request URL",
424
- )
425
- const task = await runTestEffect(
426
- TaskService.pipe(
427
- Effect.flatMap((service) => service.show("example", root)),
428
- ),
429
- )
430
- expect("pr" in task.data && task.data.pr).toBeNull()
431
- })
432
-
433
- test("rejects task-aware head and base values that contradict declarations", async () => {
434
- await createTask()
435
- await expect(
436
- createPullRequest("example", undefined, false, false, {
437
- head: "other",
438
- }),
439
- ).rejects.toThrow("does not match declared branch")
440
- await expect(
441
- createPullRequest("example", undefined, false, false, {
442
- base: "release",
443
- }),
444
- ).rejects.toThrow("does not match declared base")
445
- })
446
-
447
- test("guards terminal targets before materializing unless forced", async () => {
448
- await createTask()
449
- await runTestEffect(
450
- TaskService.pipe(
451
- Effect.flatMap((service) =>
452
- service.setStatus("example", "dropped", root),
453
- ),
454
- ),
455
- )
456
-
457
- await expect(createPullRequest()).rejects.toThrow("Task status is dropped")
458
- expect(
459
- await Bun.file(join(root, "tasks/example/code/agency")).exists(),
460
- ).toBe(false)
461
-
462
- const url = "https://github.com/example/agency/pull/49"
463
- await writeFakeGh({ stdout: url })
464
- expect(await createPullRequest("example", undefined, false, true)).toBe(url)
465
- })
466
-
467
- test("requires reopening non-PR completed work even when forced", async () => {
468
- await createTask()
469
- await runTestEffect(
470
- TaskService.pipe(
471
- Effect.flatMap((service) =>
472
- service.setStatus("example", "done", root, {
473
- summary: "Investigation completed without changes.",
474
- }),
475
- ),
476
- ),
477
- )
478
-
479
- await expect(
480
- createPullRequest("example", undefined, false, true),
481
- ).rejects.toThrow("Reopen non-PR completed work")
482
- expect(
483
- await Bun.file(join(root, "tasks/example/code/agency")).exists(),
484
- ).toBe(false)
485
- })
486
-
487
- test("updates only PHASE.md for a phase PR", async () => {
488
- await runTestEffect(
489
- TaskService.pipe(
490
- Effect.flatMap((service) =>
491
- service.create(
492
- {
493
- id: "multi",
494
- ticketUrl: "https://example.com/task",
495
- multiPhase: true,
496
- },
497
- root,
498
- ),
499
- ),
500
- ),
501
- )
502
- await runTestEffect(
503
- PhaseService.pipe(
504
- Effect.flatMap((service) =>
505
- service.create(
506
- {
507
- taskId: "multi",
508
- id: "implementation",
509
- repo: "agency",
510
- branch: "task/multi-implementation",
511
- base: "main",
512
- },
513
- root,
514
- ),
515
- ),
516
- ),
517
- )
518
- const taskPath = join(root, "tasks", "multi", "TASK.md")
519
- const phasePath = join(
520
- root,
521
- "tasks",
522
- "multi",
523
- "phases",
524
- "implementation",
525
- "PHASE.md",
526
- )
527
- const originalTask = await Bun.file(taskPath).text()
528
- const url = "https://github.com/example/agency/pull/44"
529
- await writeFakeGh({ stdout: url })
530
-
531
- await createPullRequest("multi", "implementation")
532
-
533
- expect(await Bun.file(taskPath).text()).toBe(originalTask)
534
- expect(await Bun.file(phasePath).text()).toContain(`url: ${url}`)
535
- await expectRemoteBranch("task/multi-implementation")
536
- })
537
-
538
- test("blocks a dirty checkout before push or gh", async () => {
539
- await createTask()
540
- const workspace = await materialize()
541
- await Bun.write(join(workspace.writablePath!, "dirty.txt"), "dirty\n")
542
- await writeFakeGh({ stdout: "https://github.com/example/agency/pull/45" })
543
-
544
- await expect(createPullRequest()).rejects.toThrow(
545
- "Cannot create a PR with a dirty worktree",
546
- )
547
-
548
- await expectRemoteBranch("task/example", false)
549
- expect(await Bun.file(ghCallPath).exists()).toBe(false)
550
- })
551
-
552
- test("blocks PR creation when workbase validation fails", async () => {
553
- await createTask()
554
- await materialize()
555
- await mkdir(join(root, "tasks", "missing-document"), { recursive: true })
556
- await writeFakeGh({ stdout: "https://github.com/example/agency/pull/45" })
557
-
558
- await expect(createPullRequest()).rejects.toThrow(
559
- "Required document is missing",
560
- )
561
-
562
- await expectRemoteBranch("task/example", false)
563
- expect(await Bun.file(ghCallPath).exists()).toBe(false)
564
- })
565
-
566
- test("reports push failure and does not invoke gh", async () => {
567
- await createTask()
568
- await materialize()
569
- const hookPath = join(remotePath, "hooks", "pre-receive")
570
- await Bun.write(hookPath, "#!/bin/sh\necho push rejected >&2\nexit 1\n")
571
- await chmod(hookPath, 0o755)
572
- await writeFakeGh({ stdout: "https://github.com/example/agency/pull/46" })
573
-
574
- await expect(createPullRequest()).rejects.toThrow("Failed to push branch")
575
-
576
- await expectRemoteBranch("task/example", false)
577
- expect(await Bun.file(ghCallPath).exists()).toBe(false)
578
- })
579
-
580
- test("reports gh failure without persisting a URL", async () => {
581
- await createTask()
582
- await writeFakeGh({ stderr: "authentication failed\n", exitCode: 1 })
583
-
584
- await expect(createPullRequest()).rejects.toThrow(
585
- "Failed to create pull request: authentication failed",
586
- )
587
-
588
- const task = await runTestEffect(
589
- TaskService.pipe(
590
- Effect.flatMap((service) => service.show("example", root)),
591
- ),
592
- )
593
- expect("pr" in task.data && task.data.pr).toBeNull()
594
- })
595
-
596
- test("rejects successful gh output without a PR URL", async () => {
597
- await createTask()
598
- await writeFakeGh({ stdout: "Pull request created successfully\n" })
599
-
600
- await expect(createPullRequest()).rejects.toThrow(
601
- "GitHub CLI did not return a pull request URL",
602
- )
603
- })
604
-
605
- test("extracts a PR URL from noisy gh output", async () => {
606
- await createTask()
607
- const url = "https://github.com/example/agency/pull/47"
608
- await writeFakeGh({
609
- stdout: `Creating pull request...\n${url}\nView it in your browser.\n`,
610
- })
611
-
612
- expect(await createPullRequest()).toBe(url)
613
-
614
- const task = await runTestEffect(
615
- TaskService.pipe(
616
- Effect.flatMap((service) => service.show("example", root)),
617
- ),
618
- )
619
- expect("pr" in task.data && task.data.pr).toMatchObject({ url })
620
- })
621
-
622
- test("uses a configured remote and argv provider", async () => {
623
- await createTask()
624
- await requireCommand(
625
- ["git", "remote", "rename", "origin", "upstream"],
626
- join(root, "repos", "agency"),
627
- )
628
- const callPath = join(root, "delivery-call.json")
629
- const providerRecord = {
630
- provider: "forge",
631
- repository: remotePath.replace(/\.git$/, ""),
632
- identifier: "17",
633
- url: "https://forge.example/example/agency/pulls/17",
634
- state: "open",
635
- draft: false,
636
- merged: false,
637
- } as const
638
- await Bun.write(
639
- join(root, "bin", "deliver"),
640
- `#!/usr/bin/env bun
641
- await Bun.write(${JSON.stringify(callPath)}, JSON.stringify({ args: Bun.argv.slice(2), base: process.env.DELIVERY_BASE }))
642
- process.stdout.write(${JSON.stringify(JSON.stringify(providerRecord))})
643
- `,
644
- )
645
- await chmod(join(root, "bin", "deliver"), 0o755)
646
- await Bun.write(
647
- join(root, "agency.json"),
648
- JSON.stringify({
649
- version: 2,
650
- delivery: {
651
- provider: "forge",
652
- remote: "upstream",
653
- createCommand: ["deliver", "create", "{repository}", "{branch}"],
654
- queryCommand: ["deliver", "query", "{identifier}"],
655
- environment: { DELIVERY_BASE: "{base}" },
656
- },
657
- }),
658
- )
659
-
660
- expect(await createPullRequest()).toBe(providerRecord.url)
661
- expect(await Bun.file(callPath).json()).toEqual({
662
- args: ["create", remotePath.replace(/\.git$/, ""), "task/example"],
663
- base: "main",
664
- })
665
- const task = await runTestEffect(
666
- TaskService.pipe(
667
- Effect.flatMap((service) => service.show("example", root)),
668
- ),
669
- )
670
- expect("pr" in task.data && task.data.pr).toEqual(providerRecord)
671
- })
672
-
673
- test("does not persist malformed provider output", async () => {
674
- await createTask()
675
- await Bun.write(
676
- join(root, "bin", "deliver"),
677
- "#!/usr/bin/env bun\nprocess.stdout.write('{}')\n",
678
- )
679
- await chmod(join(root, "bin", "deliver"), 0o755)
680
- await Bun.write(
681
- join(root, "agency.json"),
682
- JSON.stringify({
683
- version: 2,
684
- delivery: {
685
- provider: "forge",
686
- createCommand: ["deliver", "create"],
687
- queryCommand: ["deliver", "query"],
688
- },
689
- }),
690
- )
691
-
692
- await expect(createPullRequest()).rejects.toThrow(
693
- "Delivery provider did not return a valid pull request record",
694
- )
695
- const task = await runTestEffect(
696
- TaskService.pipe(
697
- Effect.flatMap((service) => service.show("example", root)),
698
- ),
699
- )
700
- expect("pr" in task.data && task.data.pr).toBeNull()
701
- })
702
-
703
- test("reports invalid reused Git checkout before push or gh", async () => {
704
- await createTask()
705
- const workspace = await materialize()
706
- await rm(join(workspace.writablePath!, ".git"))
707
- await writeFakeGh({ stdout: "https://github.com/example/agency/pull/48" })
708
-
709
- await expect(createPullRequest()).rejects.toThrow(
710
- "Failed to locate local excludes",
711
- )
712
-
713
- await expectRemoteBranch("task/example", false)
714
- expect(await Bun.file(ghCallPath).exists()).toBe(false)
715
- })
716
- })