@markjaquith/agency 3.2.13 → 3.2.15

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 (69) hide show
  1. package/package.json +7 -2
  2. package/src/workbase/schemas.ts +12 -0
  3. package/fixtures/protocol/orchestration-recipes.json +0 -53
  4. package/pi-extensions/agency.test.ts +0 -117
  5. package/src/check-commits.test.ts +0 -58
  6. package/src/cli-parser.test.ts +0 -945
  7. package/src/cli.test.ts +0 -1889
  8. package/src/commands/act.test.ts +0 -418
  9. package/src/commands/archive.test.ts +0 -236
  10. package/src/commands/context.test.ts +0 -665
  11. package/src/commands/description.test.ts +0 -103
  12. package/src/commands/doctor.test.ts +0 -185
  13. package/src/commands/epic.test.ts +0 -196
  14. package/src/commands/init.test.ts +0 -117
  15. package/src/commands/integration.test.ts +0 -165
  16. package/src/commands/pr.test.ts +0 -248
  17. package/src/commands/push.test.ts +0 -56
  18. package/src/commands/read-only.test.ts +0 -161
  19. package/src/commands/repo.test.ts +0 -199
  20. package/src/commands/restore.test.ts +0 -106
  21. package/src/commands/status.test.ts +0 -113
  22. package/src/commands/sync.test.ts +0 -200
  23. package/src/commands/task-phase.test.ts +0 -410
  24. package/src/commands/task.test.ts +0 -281
  25. package/src/commands/validate.test.ts +0 -186
  26. package/src/commands/work.test.ts +0 -1375
  27. package/src/commands/workbase.test.ts +0 -170
  28. package/src/graph-schema.test.ts +0 -124
  29. package/src/protocol.test.ts +0 -163
  30. package/src/readiness.test.ts +0 -105
  31. package/src/services/ArchiveBulkService.test.ts +0 -384
  32. package/src/services/ArchiveService.test.ts +0 -1092
  33. package/src/services/EpicService.test.ts +0 -74
  34. package/src/services/FileSystemService.test.ts +0 -81
  35. package/src/services/GraphMutationService.test.ts +0 -486
  36. package/src/services/GraphService.test.ts +0 -494
  37. package/src/services/IntegrationService.test.ts +0 -1091
  38. package/src/services/LifecycleTransaction.test.ts +0 -145
  39. package/src/services/PullRequestService.test.ts +0 -716
  40. package/src/services/PushService.test.ts +0 -408
  41. package/src/services/ReadinessService.test.ts +0 -290
  42. package/src/services/RepositoryService.test.ts +0 -789
  43. package/src/services/ReviewService.test.ts +0 -408
  44. package/src/services/SyncService.test.ts +0 -1377
  45. package/src/services/TaskPhaseService.test.ts +0 -852
  46. package/src/services/VersionControlService.test.ts +0 -62
  47. package/src/services/WorkbaseService.test.ts +0 -910
  48. package/src/services/WorktreeLock.test.ts +0 -205
  49. package/src/services/WorktreePerformance.test.ts +0 -71
  50. package/src/services/WorktreeService.test.ts +0 -2292
  51. package/src/test-utils.ts +0 -110
  52. package/src/usage-log.test.ts +0 -188
  53. package/src/utils/chooser.test.ts +0 -192
  54. package/src/utils/effect.test.ts +0 -30
  55. package/src/utils/interactive.pty.test.ts +0 -128
  56. package/src/utils/interactive.test.tsx +0 -860
  57. package/src/utils/process.test.ts +0 -132
  58. package/src/utils/progress.test.ts +0 -37
  59. package/src/work-view.test.ts +0 -151
  60. package/src/workbase/agent-command.test.ts +0 -128
  61. package/src/workbase/checkout-command.test.ts +0 -62
  62. package/src/workbase/delivery-command.test.ts +0 -180
  63. package/src/workbase/dependency-graph.test.ts +0 -50
  64. package/src/workbase/execution-contract.test.ts +0 -161
  65. package/src/workbase/frontmatter.test.ts +0 -67
  66. package/src/workbase/repository-reference.test.ts +0 -25
  67. package/src/workbase/schemas.test.ts +0 -543
  68. package/src/workbase/work-target.test.ts +0 -108
  69. package/src/workbase/worktree-command.test.ts +0 -61
@@ -1,384 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
- import { Effect } from "effect"
3
- import { chmod, mkdir } from "node:fs/promises"
4
- import { join } from "node:path"
5
- import { cleanupTempDir, createTempDir, runTestEffect } from "../test-utils"
6
- import { ArchiveService } from "./ArchiveService"
7
- import { EpicService } from "./EpicService"
8
- import { GraphMutationService } from "./GraphMutationService"
9
- import { PhaseService } from "./PhaseService"
10
- import { TaskService } from "./TaskService"
11
- import { WorktreeService } from "./WorktreeService"
12
-
13
- const git = (args: readonly string[], cwd?: string) => {
14
- const result = Bun.spawnSync(["git", ...args], { cwd })
15
- if (result.exitCode !== 0) {
16
- throw new Error(new TextDecoder().decode(result.stderr))
17
- }
18
- }
19
-
20
- describe("ArchiveService bulk task archive", () => {
21
- let root: string
22
- let source: string
23
-
24
- beforeEach(async () => {
25
- root = await createTempDir()
26
- await Bun.write(join(root, "agency.json"), '{"version":2}\n')
27
- source = join(root, "source")
28
- await mkdir(source, { recursive: true })
29
- git(["init", "--initial-branch=main"], source)
30
- git(["config", "user.email", "test@example.com"], source)
31
- git(["config", "user.name", "Test"], source)
32
- await Bun.write(join(source, "README.md"), "example\n")
33
- git(["add", "README.md"], source)
34
- git(["-c", "commit.gpgsign=false", "commit", "-m", "initial"], source)
35
- await mkdir(join(root, "repos"), { recursive: true })
36
- git(["clone", "--bare", source, join(root, "repos/agency")])
37
- })
38
-
39
- afterEach(async () => cleanupTempDir(root))
40
-
41
- const createTask = (id: string, epic?: string) =>
42
- runTestEffect(
43
- TaskService.pipe(
44
- Effect.flatMap((service) =>
45
- service.create(
46
- {
47
- id,
48
- ticketUrl: null,
49
- ...(epic ? { epic } : {}),
50
- repo: "agency",
51
- branch: `task/${id}`,
52
- base: "main",
53
- },
54
- root,
55
- ),
56
- ),
57
- ),
58
- )
59
-
60
- const dropTask = (id: string) =>
61
- runTestEffect(
62
- TaskService.pipe(
63
- Effect.flatMap((service) => service.setStatus(id, "dropped", root)),
64
- ),
65
- )
66
-
67
- const archiveTasks = (dryRun = false) =>
68
- runTestEffect(
69
- ArchiveService.pipe(
70
- Effect.flatMap((service) => service.archiveTasks(root, { dryRun })),
71
- ),
72
- )
73
-
74
- test("returns sorted dispositions and treats an empty multi-phase task as non-terminal", async () => {
75
- await createTask("z-dropped")
76
- await dropTask("z-dropped")
77
- await createTask("a-open")
78
- await runTestEffect(
79
- TaskService.pipe(
80
- Effect.flatMap((service) =>
81
- service.create(
82
- { id: "m-empty", ticketUrl: null, multiPhase: true },
83
- root,
84
- ),
85
- ),
86
- ),
87
- )
88
-
89
- const result = await archiveTasks(true)
90
-
91
- expect(result.tasks.map((task) => task.id)).toEqual([
92
- "a-open",
93
- "m-empty",
94
- "z-dropped",
95
- ])
96
- expect(result.tasks).toMatchObject([
97
- {
98
- id: "a-open",
99
- disposition: "skipped",
100
- reason: { code: "non-terminal", details: ["status=open"] },
101
- },
102
- {
103
- id: "m-empty",
104
- disposition: "skipped",
105
- reason: {
106
- code: "non-terminal",
107
- details: ["multi-phase task has no phases"],
108
- },
109
- },
110
- { id: "z-dropped", disposition: "planned" },
111
- ])
112
- expect(await Bun.file(join(root, "tasks/z-dropped/TASK.md")).exists()).toBe(
113
- true,
114
- )
115
- })
116
-
117
- test("reuses loaded records while preflighting task worktrees", async () => {
118
- for (const id of ["first", "second"]) {
119
- await createTask(id)
120
- await dropTask(id)
121
- }
122
- let taskReads = 0
123
- const file = Bun.file(join(root, "tasks/first/TASK.md"))
124
- const prototype = Object.getPrototypeOf(file) as {
125
- text: () => Promise<string>
126
- name: string
127
- }
128
- const originalText = prototype.text
129
- prototype.text = function () {
130
- if (this.name.endsWith("/TASK.md")) taskReads += 1
131
- return originalText.call(this)
132
- }
133
-
134
- try {
135
- const result = await archiveTasks(true)
136
- expect(result.tasks.map((task) => task.disposition)).toEqual([
137
- "planned",
138
- "planned",
139
- ])
140
- expect(taskReads).toBe(10)
141
- } finally {
142
- prototype.text = originalText
143
- }
144
- })
145
-
146
- test("uses aggregate phase status and archives only when every phase is terminal", async () => {
147
- await runTestEffect(
148
- TaskService.pipe(
149
- Effect.flatMap((service) =>
150
- service.create(
151
- { id: "multi", ticketUrl: null, multiPhase: true },
152
- root,
153
- ),
154
- ),
155
- ),
156
- )
157
- for (const id of ["done", "open"]) {
158
- await runTestEffect(
159
- PhaseService.pipe(
160
- Effect.flatMap((service) =>
161
- service.create(
162
- {
163
- taskId: "multi",
164
- id,
165
- repo: "agency",
166
- branch: `task/multi-${id}`,
167
- base: "main",
168
- },
169
- root,
170
- ),
171
- ),
172
- ),
173
- )
174
- }
175
- await runTestEffect(
176
- PhaseService.pipe(
177
- Effect.flatMap((service) =>
178
- service.setStatus("multi", "done", "dropped", root),
179
- ),
180
- ),
181
- )
182
-
183
- const mixed = await archiveTasks(true)
184
- expect(mixed.tasks[0]).toMatchObject({
185
- disposition: "skipped",
186
- reason: { code: "non-terminal" },
187
- })
188
-
189
- await runTestEffect(
190
- PhaseService.pipe(
191
- Effect.flatMap((service) =>
192
- service.setStatus("multi", "open", "dropped", root),
193
- ),
194
- ),
195
- )
196
- const terminal = await archiveTasks()
197
- expect(terminal.tasks[0]).toMatchObject({
198
- id: "multi",
199
- disposition: "archived",
200
- })
201
- expect(
202
- await Bun.file(join(root, "archive/tasks/multi/TASK.md")).exists(),
203
- ).toBe(true)
204
- })
205
-
206
- test("propagates retained-dependent skips to a fixed point", async () => {
207
- await runTestEffect(
208
- EpicService.pipe(
209
- Effect.flatMap((service) =>
210
- service.create(
211
- "parent",
212
- "https://example.com/epic",
213
- [{ repo: "agency", ref: "main" }],
214
- root,
215
- ),
216
- ),
217
- ),
218
- )
219
- for (const id of ["base", "middle", "retained"])
220
- await createTask(id, "parent")
221
- await runTestEffect(
222
- GraphMutationService.pipe(
223
- Effect.flatMap((service) =>
224
- service.mutateTaskDependency("add", "middle", "base", root),
225
- ),
226
- ),
227
- )
228
- await runTestEffect(
229
- GraphMutationService.pipe(
230
- Effect.flatMap((service) =>
231
- service.mutateTaskDependency("add", "retained", "middle", root),
232
- ),
233
- ),
234
- )
235
- await dropTask("base")
236
- await dropTask("middle")
237
-
238
- const result = await archiveTasks()
239
-
240
- expect(result.tasks).toMatchObject([
241
- {
242
- id: "base",
243
- disposition: "skipped",
244
- reason: { code: "retained-dependent", details: ["middle"] },
245
- },
246
- {
247
- id: "middle",
248
- disposition: "skipped",
249
- reason: { code: "retained-dependent", details: ["retained"] },
250
- },
251
- {
252
- id: "retained",
253
- disposition: "skipped",
254
- reason: { code: "non-terminal" },
255
- },
256
- ])
257
- })
258
-
259
- test("archives an internal dependency cohort and updates its parent once without archiving it", async () => {
260
- await runTestEffect(
261
- EpicService.pipe(
262
- Effect.flatMap((service) =>
263
- service.create(
264
- "parent",
265
- "https://example.com/epic",
266
- [{ repo: "agency", ref: "main" }],
267
- root,
268
- ),
269
- ),
270
- ),
271
- )
272
- await createTask("base", "parent")
273
- await createTask("dependent", "parent")
274
- await runTestEffect(
275
- GraphMutationService.pipe(
276
- Effect.flatMap((service) =>
277
- service.mutateTaskDependency("add", "dependent", "base", root),
278
- ),
279
- ),
280
- )
281
- await dropTask("base")
282
- await dropTask("dependent")
283
-
284
- const result = await archiveTasks()
285
-
286
- expect(result.tasks.map((task) => task.disposition)).toEqual([
287
- "archived",
288
- "archived",
289
- ])
290
- const parent = await runTestEffect(
291
- EpicService.pipe(
292
- Effect.flatMap((service) => service.show("parent", root)),
293
- ),
294
- )
295
- expect(parent.data.tasks).toEqual([])
296
- expect(await Bun.file(join(root, "epics/parent/EPIC.md")).exists()).toBe(
297
- true,
298
- )
299
- expect(await Bun.file(join(root, "archive/epics/parent")).exists()).toBe(
300
- false,
301
- )
302
- })
303
-
304
- test("skips destination collisions and dirty managed worktrees", async () => {
305
- await createTask("collision")
306
- await dropTask("collision")
307
- await mkdir(join(root, "archive/tasks/collision"), { recursive: true })
308
- await createTask("dirty")
309
- await dropTask("dirty")
310
- const workspace = await runTestEffect(
311
- WorktreeService.pipe(
312
- Effect.flatMap((service) =>
313
- service.materialize("dirty", undefined, root),
314
- ),
315
- ),
316
- )
317
- await Bun.write(join(workspace.writablePath!, "dirty.txt"), "keep\n")
318
-
319
- const result = await archiveTasks()
320
-
321
- expect(result.tasks).toMatchObject([
322
- {
323
- id: "collision",
324
- disposition: "skipped",
325
- reason: { code: "destination-exists" },
326
- },
327
- {
328
- id: "dirty",
329
- disposition: "skipped",
330
- reason: { code: "dirty-worktree" },
331
- },
332
- ])
333
- expect(
334
- await Bun.file(join(workspace.writablePath!, "dirty.txt")).exists(),
335
- ).toBe(true)
336
- })
337
-
338
- test("rolls back the entire cohort when application fails", async () => {
339
- await runTestEffect(
340
- EpicService.pipe(
341
- Effect.flatMap((service) =>
342
- service.create(
343
- "rollback-parent",
344
- "https://example.com/epic",
345
- [{ repo: "agency", ref: "main" }],
346
- root,
347
- ),
348
- ),
349
- ),
350
- )
351
- for (const id of ["first", "second"]) {
352
- await createTask(id, "rollback-parent")
353
- await dropTask(id)
354
- }
355
- const archiveDirectory = join(root, "archive")
356
- await mkdir(archiveDirectory, { mode: 0o500 })
357
-
358
- try {
359
- await expect(archiveTasks()).rejects.toThrow("rolled back")
360
- } finally {
361
- await chmod(archiveDirectory, 0o700)
362
- }
363
-
364
- for (const id of ["first", "second"]) {
365
- expect(await Bun.file(join(root, `tasks/${id}/TASK.md`)).exists()).toBe(
366
- true,
367
- )
368
- expect(
369
- await Bun.file(
370
- join(root, `tasks/${id}/.agency-lifecycle.json`),
371
- ).exists(),
372
- ).toBe(false)
373
- }
374
- const parent = await runTestEffect(
375
- EpicService.pipe(
376
- Effect.flatMap((service) => service.show("rollback-parent", root)),
377
- ),
378
- )
379
- expect(parent.data.tasks.map((task) => task.id)).toEqual([
380
- "first",
381
- "second",
382
- ])
383
- })
384
- })