@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,852 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
- import { Effect } from "effect"
3
- import { mkdir, rm } from "node:fs/promises"
4
- import { join } from "node:path"
5
- import { cleanupTempDir, createTempDir, runTestEffect } from "../test-utils"
6
- import { EpicService } from "./EpicService"
7
- import { TaskService } from "./TaskService"
8
- import { PhaseService } from "./PhaseService"
9
- import { PullRequestService } from "./PullRequestService"
10
-
11
- describe("task and phase services", () => {
12
- let root: string
13
-
14
- beforeEach(async () => {
15
- root = await createTempDir()
16
- await Bun.write(join(root, "agency.json"), '{"version":2}\n')
17
- await mkdir(join(root, "repos/agency"), { recursive: true })
18
- await mkdir(join(root, "repos/effect"), { recursive: true })
19
- })
20
-
21
- afterEach(async () => cleanupTempDir(root))
22
-
23
- test("creates a single-phase task and updates its epic", async () => {
24
- await runTestEffect(
25
- EpicService.pipe(
26
- Effect.flatMap((service) =>
27
- service.create(
28
- "example",
29
- "https://example.com/epic",
30
- [{ repo: "agency", ref: "main" }],
31
- root,
32
- ),
33
- ),
34
- ),
35
- )
36
- const createdTask = await runTestEffect(
37
- TaskService.pipe(
38
- Effect.flatMap((service) =>
39
- service.create(
40
- {
41
- id: "task-one",
42
- ticketUrl: "https://example.com/task",
43
- epic: "example",
44
- repo: "agency",
45
- repos: [{ repo: "effect", ref: "main" }],
46
- branch: "task/one",
47
- base: "main",
48
- },
49
- root,
50
- ),
51
- ),
52
- ),
53
- )
54
- expect(createdTask.content).toContain(
55
- "# Task One\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.",
56
- )
57
-
58
- const epic = await runTestEffect(
59
- EpicService.pipe(
60
- Effect.flatMap((service) => service.show("example", root)),
61
- ),
62
- )
63
- expect(epic.data.tasks).toEqual([{ id: "task-one" }])
64
- })
65
-
66
- test("does not create a task when its parent update cannot start", async () => {
67
- await runTestEffect(
68
- EpicService.pipe(
69
- Effect.flatMap((service) =>
70
- service.create(
71
- "locked",
72
- "https://example.com/epic",
73
- [{ repo: "agency", ref: "main" }],
74
- root,
75
- ),
76
- ),
77
- ),
78
- )
79
- const lock = join(root, ".agency-graph-mutation.lock")
80
- await Bun.write(lock, "held")
81
- await expect(
82
- runTestEffect(
83
- TaskService.pipe(
84
- Effect.flatMap((service) =>
85
- service.create(
86
- {
87
- id: "not-created",
88
- ticketUrl: null,
89
- epic: "locked",
90
- repo: "agency",
91
- branch: "task/not-created",
92
- base: "main",
93
- },
94
- root,
95
- ),
96
- ),
97
- ),
98
- ),
99
- ).rejects.toThrow("Another graph mutation is in progress")
100
- await rm(lock)
101
- expect(
102
- await Bun.file(join(root, "tasks/not-created/TASK.md")).exists(),
103
- ).toBe(false)
104
- const epic = await runTestEffect(
105
- EpicService.pipe(
106
- Effect.flatMap((service) => service.show("locked", root)),
107
- ),
108
- )
109
- expect(epic.data.tasks).toEqual([])
110
- })
111
-
112
- test("creates revision-bound task and phase investigation handoffs", async () => {
113
- const source = await runTestEffect(
114
- TaskService.pipe(
115
- Effect.flatMap((service) =>
116
- service.create(
117
- {
118
- id: "investigate",
119
- ticketUrl: null,
120
- multiPhase: true,
121
- purpose: "investigation",
122
- },
123
- root,
124
- ),
125
- ),
126
- ),
127
- )
128
- const phase = await runTestEffect(
129
- PhaseService.pipe(
130
- Effect.flatMap((service) =>
131
- service.create(
132
- {
133
- taskId: "investigate",
134
- id: "evidence",
135
- repo: "agency",
136
- branch: "task/investigate-evidence",
137
- base: "main",
138
- },
139
- root,
140
- ),
141
- ),
142
- ),
143
- )
144
- const currentSource = await runTestEffect(
145
- TaskService.pipe(
146
- Effect.flatMap((service) => service.show("investigate", root)),
147
- ),
148
- )
149
- const sourceContent = await Bun.file(source.path).text()
150
- const phaseContent = await Bun.file(phase.path).text()
151
-
152
- const fromTask = await runTestEffect(
153
- TaskService.pipe(
154
- Effect.flatMap((service) =>
155
- service.handoff(
156
- {
157
- sourceTaskId: "investigate",
158
- id: "implement-task",
159
- ticketUrl: null,
160
- repo: "agency",
161
- branch: "task/implement-task",
162
- base: "main",
163
- },
164
- root,
165
- ),
166
- ),
167
- ),
168
- )
169
- const fromPhase = await runTestEffect(
170
- TaskService.pipe(
171
- Effect.flatMap((service) =>
172
- service.handoff(
173
- {
174
- sourceTaskId: "investigate",
175
- sourcePhaseId: "evidence",
176
- id: "implement-phase",
177
- ticketUrl: null,
178
- repo: "effect",
179
- branch: "task/implement-phase",
180
- base: "main",
181
- },
182
- root,
183
- ),
184
- ),
185
- ),
186
- )
187
-
188
- expect(fromTask.source).toEqual({
189
- selector: "task/investigate",
190
- documentPath: source.path,
191
- revision: currentSource.revision,
192
- })
193
- expect(fromPhase.source).toEqual({
194
- selector: "phase/investigate/evidence",
195
- documentPath: phase.path,
196
- revision: phase.revision,
197
- })
198
- expect(fromPhase.validation.valid).toBe(true)
199
- expect(fromPhase.worktreePrepare.command).toEqual([
200
- "agency",
201
- "worktree",
202
- "prepare",
203
- "implement-phase",
204
- ])
205
- expect(await Bun.file(source.path).text()).toBe(sourceContent)
206
- expect(await Bun.file(phase.path).text()).toBe(phaseContent)
207
- expect(
208
- await Bun.file(join(root, "tasks/implement-phase/code")).exists(),
209
- ).toBe(false)
210
-
211
- const created = await runTestEffect(
212
- TaskService.pipe(
213
- Effect.flatMap((service) => service.show("implement-phase", root)),
214
- ),
215
- )
216
- expect(created.data).toMatchObject({
217
- purpose: "implementation",
218
- handoff: {
219
- source: {
220
- kind: "phase",
221
- taskId: "investigate",
222
- phaseId: "evidence",
223
- },
224
- sourceRevision: phase.revision,
225
- },
226
- status: "open",
227
- })
228
- await Bun.write(
229
- phase.path,
230
- phaseContent.replace(
231
- "Describe the phase outcome.",
232
- "Recorded evidence remains stale-safe.",
233
- ),
234
- )
235
- const staleSource = await runTestEffect(
236
- TaskService.pipe(
237
- Effect.flatMap((service) => service.show("implement-phase", root)),
238
- ),
239
- )
240
- expect(staleSource.data.handoff?.sourceRevision).toBe(phase.revision)
241
-
242
- await expect(
243
- runTestEffect(
244
- TaskService.pipe(
245
- Effect.flatMap((service) =>
246
- service.handoff(
247
- {
248
- sourceTaskId: "investigate",
249
- id: "implement-task",
250
- ticketUrl: null,
251
- repo: "agency",
252
- branch: "task/duplicate",
253
- base: "main",
254
- },
255
- root,
256
- ),
257
- ),
258
- ),
259
- ),
260
- ).rejects.toThrow("already exists")
261
-
262
- await mkdir(join(root, "archive/tasks/reserved"), { recursive: true })
263
- await expect(
264
- runTestEffect(
265
- TaskService.pipe(
266
- Effect.flatMap((service) =>
267
- service.handoff(
268
- {
269
- sourceTaskId: "investigate",
270
- id: "reserved",
271
- ticketUrl: null,
272
- repo: "agency",
273
- branch: "task/reserved",
274
- base: "main",
275
- },
276
- root,
277
- ),
278
- ),
279
- ),
280
- ),
281
- ).rejects.toThrow("explicit creation requires a different ID")
282
- })
283
-
284
- test("rolls back handoff creation when a source revision is stale", async () => {
285
- const source = await runTestEffect(
286
- TaskService.pipe(
287
- Effect.flatMap((service) =>
288
- service.create(
289
- {
290
- id: "stale-investigation",
291
- ticketUrl: null,
292
- repo: "agency",
293
- branch: "task/stale-investigation",
294
- base: "main",
295
- purpose: "investigation",
296
- },
297
- root,
298
- ),
299
- ),
300
- ),
301
- )
302
- const staleRevision = source.revision
303
- await Bun.write(
304
- source.path,
305
- `${source.content}\nChanged after inspection.\n`,
306
- )
307
-
308
- await expect(
309
- runTestEffect(
310
- TaskService.pipe(
311
- Effect.flatMap((service) =>
312
- service.create(
313
- {
314
- id: "stale-implementation",
315
- ticketUrl: null,
316
- repo: "effect",
317
- branch: "task/stale-implementation",
318
- base: "main",
319
- purpose: "implementation",
320
- handoff: {
321
- source: {
322
- kind: "task",
323
- taskId: "stale-investigation",
324
- },
325
- sourceRevision: staleRevision,
326
- },
327
- preconditions: [{ path: source.path, revision: staleRevision }],
328
- },
329
- root,
330
- ),
331
- ),
332
- ),
333
- ),
334
- ).rejects.toThrow("Revision conflict")
335
- expect(
336
- await Bun.file(join(root, "tasks/stale-implementation/TASK.md")).exists(),
337
- ).toBe(false)
338
- })
339
-
340
- test("creates and sequences phases on a multi-phase task", async () => {
341
- await runTestEffect(
342
- TaskService.pipe(
343
- Effect.flatMap((service) =>
344
- service.create(
345
- {
346
- id: "multi",
347
- ticketUrl: "https://example.com/task",
348
- multiPhase: true,
349
- },
350
- root,
351
- ),
352
- ),
353
- ),
354
- )
355
- for (const phase of [
356
- { id: "first", dependsOn: undefined },
357
- { id: "second", dependsOn: ["first"] },
358
- ]) {
359
- await runTestEffect(
360
- PhaseService.pipe(
361
- Effect.flatMap((service) =>
362
- service.create(
363
- {
364
- taskId: "multi",
365
- id: phase.id,
366
- repo: "agency",
367
- branch: `task/${phase.id}`,
368
- base: "main",
369
- dependsOn: phase.dependsOn,
370
- },
371
- root,
372
- ),
373
- ),
374
- ),
375
- )
376
- }
377
-
378
- const task = await runTestEffect(
379
- TaskService.pipe(
380
- Effect.flatMap((service) => service.show("multi", root)),
381
- ),
382
- )
383
- expect("phases" in task.data && task.data.phases).toEqual([
384
- { id: "first" },
385
- { id: "second", dependsOn: ["first"] },
386
- ])
387
- const phases = await runTestEffect(
388
- PhaseService.pipe(
389
- Effect.flatMap((service) => service.list("multi", root)),
390
- ),
391
- )
392
- expect(phases.map((phase) => phase.id)).toEqual(["first", "second"])
393
- const firstPhase = await runTestEffect(
394
- PhaseService.pipe(
395
- Effect.flatMap((service) => service.show("multi", "first", root)),
396
- ),
397
- )
398
- expect(firstPhase.content).toContain(
399
- "# First\n\n## Outcome\n\nDescribe the phase outcome.\n\n## Plan\n\nDescribe the current approach.\n\n## Important Decisions\n\nRecord consequential decisions and their rationale.",
400
- )
401
- })
402
-
403
- test("converts a single-phase task when the existing phase ID is provided", async () => {
404
- await runTestEffect(
405
- TaskService.pipe(
406
- Effect.flatMap((service) =>
407
- service.create(
408
- {
409
- id: "single",
410
- ticketUrl: "https://example.com/task",
411
- description: "Deliver the complete task.",
412
- repo: "agency",
413
- repos: [{ repo: "effect", ref: "main" }],
414
- branch: "task/single",
415
- base: "main",
416
- purpose: "implementation",
417
- handoff: {
418
- source: { kind: "task", taskId: "investigation" },
419
- sourceRevision: "a".repeat(64),
420
- },
421
- },
422
- root,
423
- ),
424
- ),
425
- ),
426
- )
427
- await runTestEffect(
428
- PullRequestService.pipe(
429
- Effect.flatMap((service) =>
430
- service.setUrl(
431
- "single",
432
- undefined,
433
- "https://github.com/example/agency/pull/42",
434
- root,
435
- ),
436
- ),
437
- ),
438
- )
439
- await expect(
440
- runTestEffect(
441
- PhaseService.pipe(
442
- Effect.flatMap((service) =>
443
- service.create(
444
- {
445
- taskId: "single",
446
- id: "extra",
447
- repo: "agency",
448
- branch: "task/extra",
449
- base: "main",
450
- },
451
- root,
452
- ),
453
- ),
454
- ),
455
- ),
456
- ).rejects.toThrow("requires --first-phase")
457
-
458
- await runTestEffect(
459
- PhaseService.pipe(
460
- Effect.flatMap((service) =>
461
- service.create(
462
- {
463
- taskId: "single",
464
- id: "extra",
465
- firstPhase: "implementation",
466
- repo: "agency",
467
- branch: "task/extra",
468
- base: "main",
469
- dependsOn: ["implementation"],
470
- },
471
- root,
472
- ),
473
- ),
474
- ),
475
- )
476
-
477
- const task = await runTestEffect(
478
- TaskService.pipe(
479
- Effect.flatMap((service) => service.show("single", root)),
480
- ),
481
- )
482
- expect(task.data).toEqual({
483
- ticketUrl: "https://example.com/task",
484
- description: "Deliver the complete task.",
485
- purpose: "implementation",
486
- handoff: {
487
- source: { kind: "task", taskId: "investigation" },
488
- sourceRevision: "a".repeat(64),
489
- },
490
- phases: [
491
- { id: "implementation" },
492
- { id: "extra", dependsOn: ["implementation"] },
493
- ],
494
- })
495
- expect(task.content).toContain(
496
- "## Outcome\n\nDescribe the task outcome.\n\n## Plan\n\nDescribe the current approach.\n\n## Important Decisions",
497
- )
498
-
499
- const firstPhase = await runTestEffect(
500
- PhaseService.pipe(
501
- Effect.flatMap((service) =>
502
- service.show("single", "implementation", root),
503
- ),
504
- ),
505
- )
506
- expect(firstPhase.data).toEqual({
507
- repo: "agency",
508
- repos: [{ repo: "effect", ref: "main" }],
509
- branch: "task/single",
510
- base: "main",
511
- pr: {
512
- provider: "github",
513
- repository: "example/agency",
514
- identifier: "42",
515
- url: "https://github.com/example/agency/pull/42",
516
- state: "open",
517
- draft: false,
518
- merged: false,
519
- },
520
- status: "open",
521
- })
522
- })
523
-
524
- test("preserves non-PR completion when converting a task to phases", async () => {
525
- await runTestEffect(
526
- TaskService.pipe(
527
- Effect.flatMap((service) =>
528
- service.create(
529
- {
530
- id: "completed",
531
- ticketUrl: null,
532
- repo: "agency",
533
- branch: "task/completed",
534
- base: "main",
535
- },
536
- root,
537
- ),
538
- ),
539
- ),
540
- )
541
- await runTestEffect(
542
- TaskService.pipe(
543
- Effect.flatMap((service) =>
544
- service.setStatus("completed", "done", root, {
545
- summary: "Investigation completed without changes.",
546
- }),
547
- ),
548
- ),
549
- )
550
- await runTestEffect(
551
- PhaseService.pipe(
552
- Effect.flatMap((service) =>
553
- service.create(
554
- {
555
- taskId: "completed",
556
- id: "follow-up",
557
- firstPhase: "investigation",
558
- repo: "agency",
559
- branch: "task/completed-follow-up",
560
- base: "main",
561
- },
562
- root,
563
- ),
564
- ),
565
- ),
566
- )
567
-
568
- const firstPhase = await runTestEffect(
569
- PhaseService.pipe(
570
- Effect.flatMap((service) =>
571
- service.show("completed", "investigation", root),
572
- ),
573
- ),
574
- )
575
- expect(firstPhase.data).toMatchObject({
576
- status: "done",
577
- completion: {
578
- mode: "non-pr",
579
- summary: "Investigation completed without changes.",
580
- },
581
- })
582
- })
583
-
584
- test("updates status on execution units", async () => {
585
- const createdTask = await runTestEffect(
586
- TaskService.pipe(
587
- Effect.flatMap((service) =>
588
- service.create(
589
- {
590
- id: "single-status",
591
- ticketUrl: "https://example.com/task",
592
- repo: "agency",
593
- branch: "task/single-status",
594
- base: "main",
595
- },
596
- root,
597
- ),
598
- ),
599
- ),
600
- )
601
- expect(createdTask.content).toContain("status: open")
602
- const workingTask = await runTestEffect(
603
- TaskService.pipe(
604
- Effect.flatMap((service) =>
605
- service.setStatus("single-status", "working", root),
606
- ),
607
- ),
608
- )
609
- expect(workingTask.data.status).toBe("working")
610
- await expect(
611
- runTestEffect(
612
- TaskService.pipe(
613
- Effect.flatMap((service) =>
614
- service.setStatus("single-status", "delegated", root),
615
- ),
616
- ),
617
- ),
618
- ).rejects.toThrow("Delegated status cannot be set directly")
619
- await Bun.write(
620
- createdTask.path,
621
- workingTask.content.replace("status: working", "status: delegated"),
622
- )
623
- const reopenedDelegatedTask = await runTestEffect(
624
- TaskService.pipe(
625
- Effect.flatMap((service) =>
626
- service.setStatus("single-status", "open", root),
627
- ),
628
- ),
629
- )
630
- expect(reopenedDelegatedTask.data.status).toBe("open")
631
- await expect(
632
- runTestEffect(
633
- TaskService.pipe(
634
- Effect.flatMap((service) =>
635
- service.setStatus("single-status", "done", root),
636
- ),
637
- ),
638
- ),
639
- ).rejects.toThrow("authoritative pull request is merged")
640
- const completedTask = await runTestEffect(
641
- TaskService.pipe(
642
- Effect.flatMap((service) =>
643
- service.setStatus("single-status", "done", root, {
644
- summary: "Investigation completed without repository changes.",
645
- evidenceUrl: "https://example.com/investigation",
646
- }),
647
- ),
648
- ),
649
- )
650
- expect(completedTask.data).toMatchObject({
651
- status: "done",
652
- completion: {
653
- mode: "non-pr",
654
- summary: "Investigation completed without repository changes.",
655
- evidenceUrl: "https://example.com/investigation",
656
- },
657
- })
658
- expect(completedTask.data.completion?.completedAt).toMatch(
659
- /^\d{4}-\d{2}-\d{2}T/,
660
- )
661
- await expect(
662
- runTestEffect(
663
- PullRequestService.pipe(
664
- Effect.flatMap((service) =>
665
- service.setUrl(
666
- "single-status",
667
- undefined,
668
- "https://github.com/example/agency/pull/1",
669
- root,
670
- ),
671
- ),
672
- ),
673
- ),
674
- ).rejects.toThrow("Reopen non-PR completed work")
675
- const reopenedTask = await runTestEffect(
676
- TaskService.pipe(
677
- Effect.flatMap((service) =>
678
- service.setStatus("single-status", "open", root),
679
- ),
680
- ),
681
- )
682
- expect(reopenedTask.data.status).toBe("open")
683
- expect("completion" in reopenedTask.data).toBe(false)
684
- const droppedTask = await runTestEffect(
685
- TaskService.pipe(
686
- Effect.flatMap((service) =>
687
- service.setStatus("single-status", "dropped", root),
688
- ),
689
- ),
690
- )
691
- expect(droppedTask.data.status).toBe("dropped")
692
- await expect(
693
- runTestEffect(
694
- TaskService.pipe(
695
- Effect.flatMap((service) =>
696
- service.setStatus("single-status", "done", root, {
697
- summary: "Cannot bypass reopening.",
698
- }),
699
- ),
700
- ),
701
- ),
702
- ).rejects.toThrow("reopen it first")
703
-
704
- await runTestEffect(
705
- TaskService.pipe(
706
- Effect.flatMap((service) =>
707
- service.create(
708
- {
709
- id: "multi-status",
710
- ticketUrl: "https://example.com/task",
711
- multiPhase: true,
712
- },
713
- root,
714
- ),
715
- ),
716
- ),
717
- )
718
- await runTestEffect(
719
- PhaseService.pipe(
720
- Effect.flatMap((service) =>
721
- service.create(
722
- {
723
- taskId: "multi-status",
724
- id: "implementation",
725
- repo: "agency",
726
- branch: "task/multi-status",
727
- base: "main",
728
- },
729
- root,
730
- ),
731
- ),
732
- ),
733
- )
734
- const workingPhase = await runTestEffect(
735
- PhaseService.pipe(
736
- Effect.flatMap((service) =>
737
- service.setStatus("multi-status", "implementation", "working", root),
738
- ),
739
- ),
740
- )
741
- expect(workingPhase.data.status).toBe("working")
742
- const phase = await runTestEffect(
743
- PhaseService.pipe(
744
- Effect.flatMap((service) =>
745
- service.setStatus("multi-status", "implementation", "dropped", root),
746
- ),
747
- ),
748
- )
749
- expect(phase.data.status).toBe("dropped")
750
- await expect(
751
- runTestEffect(
752
- PhaseService.pipe(
753
- Effect.flatMap((service) =>
754
- service.setStatus("multi-status", "implementation", "done", root),
755
- ),
756
- ),
757
- ),
758
- ).rejects.toThrow("authoritative pull request is merged")
759
- await runTestEffect(
760
- PhaseService.pipe(
761
- Effect.flatMap((service) =>
762
- service.setStatus("multi-status", "implementation", "open", root),
763
- ),
764
- ),
765
- )
766
- await expect(
767
- runTestEffect(
768
- PhaseService.pipe(
769
- Effect.flatMap((service) =>
770
- service.setStatus("multi-status", "implementation", "done", root),
771
- ),
772
- ),
773
- ),
774
- ).rejects.toThrow("authoritative pull request is merged")
775
- await expect(
776
- runTestEffect(
777
- PhaseService.pipe(
778
- Effect.flatMap((service) =>
779
- service.setStatus("multi-status", "implementation", "done", root, {
780
- summary: " ",
781
- }),
782
- ),
783
- ),
784
- ),
785
- ).rejects.toThrow("summary must not be empty")
786
- const completedPhase = await runTestEffect(
787
- PhaseService.pipe(
788
- Effect.flatMap((service) =>
789
- service.setStatus("multi-status", "implementation", "done", root, {
790
- summary: "Operational work completed outside the repository.",
791
- }),
792
- ),
793
- ),
794
- )
795
- expect(completedPhase.data).toMatchObject({
796
- status: "done",
797
- completion: {
798
- mode: "non-pr",
799
- summary: "Operational work completed outside the repository.",
800
- },
801
- })
802
-
803
- await runTestEffect(
804
- TaskService.pipe(
805
- Effect.flatMap((service) =>
806
- service.create(
807
- {
808
- id: "recorded-pr",
809
- ticketUrl: null,
810
- repo: "agency",
811
- branch: "task/recorded-pr",
812
- base: "main",
813
- },
814
- root,
815
- ),
816
- ),
817
- ),
818
- )
819
- await runTestEffect(
820
- PullRequestService.pipe(
821
- Effect.flatMap((service) =>
822
- service.setUrl(
823
- "recorded-pr",
824
- undefined,
825
- "https://github.com/example/agency/pull/1",
826
- root,
827
- ),
828
- ),
829
- ),
830
- )
831
- await expect(
832
- runTestEffect(
833
- TaskService.pipe(
834
- Effect.flatMap((service) =>
835
- service.setStatus("recorded-pr", "done", root, {
836
- summary: "Attempted bypass",
837
- }),
838
- ),
839
- ),
840
- ),
841
- ).rejects.toThrow("authoritative pull request is recorded")
842
- await expect(
843
- runTestEffect(
844
- TaskService.pipe(
845
- Effect.flatMap((service) =>
846
- service.setStatus("multi-status", "done", root),
847
- ),
848
- ),
849
- ),
850
- ).rejects.toThrow("set status on a phase instead")
851
- })
852
- })