@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.
- package/package.json +7 -2
- package/src/workbase/schemas.ts +12 -0
- package/fixtures/protocol/orchestration-recipes.json +0 -53
- package/pi-extensions/agency.test.ts +0 -117
- package/src/check-commits.test.ts +0 -58
- package/src/cli-parser.test.ts +0 -945
- package/src/cli.test.ts +0 -1889
- package/src/commands/act.test.ts +0 -418
- package/src/commands/archive.test.ts +0 -236
- package/src/commands/context.test.ts +0 -665
- package/src/commands/description.test.ts +0 -103
- package/src/commands/doctor.test.ts +0 -185
- package/src/commands/epic.test.ts +0 -196
- package/src/commands/init.test.ts +0 -117
- package/src/commands/integration.test.ts +0 -165
- package/src/commands/pr.test.ts +0 -248
- package/src/commands/push.test.ts +0 -56
- package/src/commands/read-only.test.ts +0 -161
- package/src/commands/repo.test.ts +0 -199
- package/src/commands/restore.test.ts +0 -106
- package/src/commands/status.test.ts +0 -113
- package/src/commands/sync.test.ts +0 -200
- package/src/commands/task-phase.test.ts +0 -410
- package/src/commands/task.test.ts +0 -281
- package/src/commands/validate.test.ts +0 -186
- package/src/commands/work.test.ts +0 -1375
- package/src/commands/workbase.test.ts +0 -170
- package/src/graph-schema.test.ts +0 -124
- package/src/protocol.test.ts +0 -163
- package/src/readiness.test.ts +0 -105
- package/src/services/ArchiveBulkService.test.ts +0 -384
- package/src/services/ArchiveService.test.ts +0 -1092
- package/src/services/EpicService.test.ts +0 -74
- package/src/services/FileSystemService.test.ts +0 -81
- package/src/services/GraphMutationService.test.ts +0 -486
- package/src/services/GraphService.test.ts +0 -494
- package/src/services/IntegrationService.test.ts +0 -1091
- package/src/services/LifecycleTransaction.test.ts +0 -145
- package/src/services/PullRequestService.test.ts +0 -716
- package/src/services/PushService.test.ts +0 -408
- package/src/services/ReadinessService.test.ts +0 -290
- package/src/services/RepositoryService.test.ts +0 -789
- package/src/services/ReviewService.test.ts +0 -408
- package/src/services/SyncService.test.ts +0 -1377
- package/src/services/TaskPhaseService.test.ts +0 -852
- package/src/services/VersionControlService.test.ts +0 -62
- package/src/services/WorkbaseService.test.ts +0 -910
- package/src/services/WorktreeLock.test.ts +0 -205
- package/src/services/WorktreePerformance.test.ts +0 -71
- package/src/services/WorktreeService.test.ts +0 -2292
- package/src/test-utils.ts +0 -110
- package/src/usage-log.test.ts +0 -188
- package/src/utils/chooser.test.ts +0 -192
- package/src/utils/effect.test.ts +0 -30
- package/src/utils/interactive.pty.test.ts +0 -128
- package/src/utils/interactive.test.tsx +0 -860
- package/src/utils/process.test.ts +0 -132
- package/src/utils/progress.test.ts +0 -37
- package/src/work-view.test.ts +0 -151
- package/src/workbase/agent-command.test.ts +0 -128
- package/src/workbase/checkout-command.test.ts +0 -62
- package/src/workbase/delivery-command.test.ts +0 -180
- package/src/workbase/dependency-graph.test.ts +0 -50
- package/src/workbase/execution-contract.test.ts +0 -161
- package/src/workbase/frontmatter.test.ts +0 -67
- package/src/workbase/repository-reference.test.ts +0 -25
- package/src/workbase/schemas.test.ts +0 -543
- package/src/workbase/work-target.test.ts +0 -108
- package/src/workbase/worktree-command.test.ts +0 -61
|
@@ -1,2292 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
|
|
2
|
-
import { Effect } from "effect"
|
|
3
|
-
import { mkdir, realpath, rename, rm, symlink } from "node:fs/promises"
|
|
4
|
-
import { join, resolve } from "node:path"
|
|
5
|
-
import {
|
|
6
|
-
captureErrors,
|
|
7
|
-
cleanupTempDir,
|
|
8
|
-
createTempDir,
|
|
9
|
-
runTestEffect,
|
|
10
|
-
} from "../test-utils"
|
|
11
|
-
import { TaskService } from "./TaskService"
|
|
12
|
-
import { PhaseService } from "./PhaseService"
|
|
13
|
-
import { WorktreeService } from "./WorktreeService"
|
|
14
|
-
|
|
15
|
-
const git = async (args: string[], cwd?: string) => {
|
|
16
|
-
const process = Bun.spawn(["git", ...args], {
|
|
17
|
-
cwd,
|
|
18
|
-
stdout: "pipe",
|
|
19
|
-
stderr: "pipe",
|
|
20
|
-
})
|
|
21
|
-
await process.exited
|
|
22
|
-
if (process.exitCode !== 0)
|
|
23
|
-
throw new Error(await new Response(process.stderr).text())
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const gitOutput = async (args: string[], cwd?: string) => {
|
|
27
|
-
const process = Bun.spawn(["git", ...args], {
|
|
28
|
-
cwd,
|
|
29
|
-
stdout: "pipe",
|
|
30
|
-
stderr: "pipe",
|
|
31
|
-
})
|
|
32
|
-
const [exitCode, stdout, stderr] = await Promise.all([
|
|
33
|
-
process.exited,
|
|
34
|
-
new Response(process.stdout).text(),
|
|
35
|
-
new Response(process.stderr).text(),
|
|
36
|
-
])
|
|
37
|
-
if (exitCode !== 0) throw new Error(stderr)
|
|
38
|
-
return stdout.trim()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
describe("WorktreeService", () => {
|
|
42
|
-
let root: string
|
|
43
|
-
let source: string
|
|
44
|
-
let effectRepositoryInitialized: boolean
|
|
45
|
-
|
|
46
|
-
const ensureEffectRepository = async () => {
|
|
47
|
-
if (effectRepositoryInitialized) return
|
|
48
|
-
await git(["clone", "--bare", source, join(root, "repos/effect")])
|
|
49
|
-
effectRepositoryInitialized = true
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
beforeEach(async () => {
|
|
53
|
-
effectRepositoryInitialized = false
|
|
54
|
-
root = await createTempDir()
|
|
55
|
-
await Bun.write(join(root, "agency.json"), '{"version":2}\n')
|
|
56
|
-
source = join(root, "source")
|
|
57
|
-
await mkdir(source, { recursive: true })
|
|
58
|
-
await git(["init", "--initial-branch=main"], source)
|
|
59
|
-
await git(["config", "user.email", "test@example.com"], source)
|
|
60
|
-
await git(["config", "user.name", "Test"], source)
|
|
61
|
-
await Bun.write(join(source, "README.md"), "example\n")
|
|
62
|
-
await git(["add", "README.md"], source)
|
|
63
|
-
await git(["-c", "commit.gpgsign=false", "commit", "-m", "initial"], source)
|
|
64
|
-
await mkdir(join(root, "repos"), { recursive: true })
|
|
65
|
-
await git(["clone", "--bare", source, join(root, "repos/agency")])
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
afterEach(async () => cleanupTempDir(root))
|
|
69
|
-
|
|
70
|
-
test("materializes writable and reference worktrees", async () => {
|
|
71
|
-
await ensureEffectRepository()
|
|
72
|
-
await runTestEffect(
|
|
73
|
-
TaskService.pipe(
|
|
74
|
-
Effect.flatMap((service) =>
|
|
75
|
-
service.create(
|
|
76
|
-
{
|
|
77
|
-
id: "example",
|
|
78
|
-
ticketUrl: "https://example.com/task",
|
|
79
|
-
repo: "agency",
|
|
80
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
81
|
-
branch: "task/example",
|
|
82
|
-
base: "main",
|
|
83
|
-
},
|
|
84
|
-
root,
|
|
85
|
-
),
|
|
86
|
-
),
|
|
87
|
-
),
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
const workspace = await runTestEffect(
|
|
91
|
-
WorktreeService.pipe(
|
|
92
|
-
Effect.flatMap((service) =>
|
|
93
|
-
service.materialize("example", undefined, root),
|
|
94
|
-
),
|
|
95
|
-
),
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
expect(
|
|
99
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).text(),
|
|
100
|
-
).toBe("example\n")
|
|
101
|
-
expect(
|
|
102
|
-
await Bun.file(join(workspace.codePath, "effect/README.md")).text(),
|
|
103
|
-
).toBe("example\n")
|
|
104
|
-
const branch = Bun.spawnSync(
|
|
105
|
-
["git", "-C", workspace.writablePath!, "branch", "--show-current"],
|
|
106
|
-
{ stdout: "pipe" },
|
|
107
|
-
)
|
|
108
|
-
expect(new TextDecoder().decode(branch.stdout).trim()).toBe("task/example")
|
|
109
|
-
for (const checkout of [
|
|
110
|
-
workspace.writablePath!,
|
|
111
|
-
join(workspace.codePath, "effect"),
|
|
112
|
-
]) {
|
|
113
|
-
await Bun.write(join(checkout, ".worktree.lock"), "")
|
|
114
|
-
expect(await gitOutput(["status", "--porcelain"], checkout)).toBe("")
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
test("reconciles local worktree excludes without overwriting user entries", async () => {
|
|
119
|
-
await runTestEffect(
|
|
120
|
-
TaskService.pipe(
|
|
121
|
-
Effect.flatMap((service) =>
|
|
122
|
-
service.create(
|
|
123
|
-
{
|
|
124
|
-
id: "existing-ignore",
|
|
125
|
-
ticketUrl: null,
|
|
126
|
-
repo: "agency",
|
|
127
|
-
branch: "task/existing-ignore",
|
|
128
|
-
base: "main",
|
|
129
|
-
},
|
|
130
|
-
root,
|
|
131
|
-
),
|
|
132
|
-
),
|
|
133
|
-
),
|
|
134
|
-
)
|
|
135
|
-
const first = await runTestEffect(
|
|
136
|
-
WorktreeService.pipe(
|
|
137
|
-
Effect.flatMap((service) =>
|
|
138
|
-
service.materialize("existing-ignore", undefined, root),
|
|
139
|
-
),
|
|
140
|
-
),
|
|
141
|
-
)
|
|
142
|
-
const checkout = first.writablePath!
|
|
143
|
-
const excludePath = resolve(
|
|
144
|
-
checkout,
|
|
145
|
-
await gitOutput(["rev-parse", "--git-path", "info/exclude"], checkout),
|
|
146
|
-
)
|
|
147
|
-
await Bun.write(excludePath, "user-entry")
|
|
148
|
-
|
|
149
|
-
await runTestEffect(
|
|
150
|
-
WorktreeService.pipe(
|
|
151
|
-
Effect.flatMap((service) =>
|
|
152
|
-
service.materialize("existing-ignore", undefined, root),
|
|
153
|
-
),
|
|
154
|
-
),
|
|
155
|
-
)
|
|
156
|
-
await runTestEffect(
|
|
157
|
-
WorktreeService.pipe(
|
|
158
|
-
Effect.flatMap((service) =>
|
|
159
|
-
service.materialize("existing-ignore", undefined, root),
|
|
160
|
-
),
|
|
161
|
-
),
|
|
162
|
-
)
|
|
163
|
-
const excludes = await Bun.file(excludePath).text()
|
|
164
|
-
expect(excludes).toBe("user-entry\n/.worktree.lock\n")
|
|
165
|
-
expect(excludes.match(/^\/\.worktree\.lock$/gm)).toHaveLength(1)
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
test("runs repository hooks for new writable and reference checkouts", async () => {
|
|
169
|
-
await ensureEffectRepository()
|
|
170
|
-
const hook = [
|
|
171
|
-
"sh",
|
|
172
|
-
"-c",
|
|
173
|
-
'printf "%s\\n" "$@" > post-checkout-argv; env | grep "^AGENCY_" | sort > post-checkout-env; printf x >> post-checkout-count',
|
|
174
|
-
"post-checkout",
|
|
175
|
-
"{repoAlias}",
|
|
176
|
-
"{repositoryPath}",
|
|
177
|
-
"{checkoutPath}",
|
|
178
|
-
"{checkoutKind}",
|
|
179
|
-
"{requestedRef}",
|
|
180
|
-
"{base}",
|
|
181
|
-
"{vcs}",
|
|
182
|
-
"{workbaseRoot}",
|
|
183
|
-
"{taskId}",
|
|
184
|
-
"{phaseId}",
|
|
185
|
-
]
|
|
186
|
-
await Bun.write(
|
|
187
|
-
join(root, "agency.json"),
|
|
188
|
-
JSON.stringify({
|
|
189
|
-
version: 2,
|
|
190
|
-
repositories: {
|
|
191
|
-
agency: {
|
|
192
|
-
remote: "https://example.com/agency.git",
|
|
193
|
-
postCheckoutCommand: hook,
|
|
194
|
-
},
|
|
195
|
-
effect: {
|
|
196
|
-
remote: "https://example.com/effect.git",
|
|
197
|
-
postCheckoutCommand: hook,
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
}),
|
|
201
|
-
)
|
|
202
|
-
await runTestEffect(
|
|
203
|
-
TaskService.pipe(
|
|
204
|
-
Effect.flatMap((service) =>
|
|
205
|
-
service.create(
|
|
206
|
-
{
|
|
207
|
-
id: "hooked",
|
|
208
|
-
ticketUrl: null,
|
|
209
|
-
repo: "agency",
|
|
210
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
211
|
-
branch: "task/hooked",
|
|
212
|
-
base: "main",
|
|
213
|
-
},
|
|
214
|
-
root,
|
|
215
|
-
),
|
|
216
|
-
),
|
|
217
|
-
),
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
const workspace = await runTestEffect(
|
|
221
|
-
WorktreeService.pipe(
|
|
222
|
-
Effect.flatMap((service) =>
|
|
223
|
-
service.materialize("hooked", undefined, root),
|
|
224
|
-
),
|
|
225
|
-
),
|
|
226
|
-
)
|
|
227
|
-
const writable = workspace.writablePath!
|
|
228
|
-
const reference = join(workspace.codePath, "effect")
|
|
229
|
-
expect(await Bun.file(join(writable, "post-checkout-argv")).text()).toBe(
|
|
230
|
-
[
|
|
231
|
-
"agency",
|
|
232
|
-
join(root, "repos/agency"),
|
|
233
|
-
writable,
|
|
234
|
-
"writable",
|
|
235
|
-
"task/hooked",
|
|
236
|
-
"main",
|
|
237
|
-
"git",
|
|
238
|
-
root,
|
|
239
|
-
"hooked",
|
|
240
|
-
"",
|
|
241
|
-
"",
|
|
242
|
-
].join("\n"),
|
|
243
|
-
)
|
|
244
|
-
expect(
|
|
245
|
-
await Bun.file(join(reference, "post-checkout-argv")).text(),
|
|
246
|
-
).toContain("reference\nmain\nmain\ngit")
|
|
247
|
-
const environment = await Bun.file(
|
|
248
|
-
join(writable, "post-checkout-env"),
|
|
249
|
-
).text()
|
|
250
|
-
expect(environment).toContain(`AGENCY_CHECKOUT_PATH=${writable}\n`)
|
|
251
|
-
expect(environment).toContain("AGENCY_CHECKOUT_KIND=writable\n")
|
|
252
|
-
expect(environment).toContain("AGENCY_PHASE_ID=\n")
|
|
253
|
-
expect(workspace.operations).toEqual(
|
|
254
|
-
expect.arrayContaining([
|
|
255
|
-
expect.objectContaining({
|
|
256
|
-
action: "post-checkout",
|
|
257
|
-
repo: "agency",
|
|
258
|
-
status: "completed",
|
|
259
|
-
}),
|
|
260
|
-
expect.objectContaining({
|
|
261
|
-
action: "post-checkout",
|
|
262
|
-
repo: "effect",
|
|
263
|
-
status: "completed",
|
|
264
|
-
}),
|
|
265
|
-
]),
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
const reused = await runTestEffect(
|
|
269
|
-
WorktreeService.pipe(
|
|
270
|
-
Effect.flatMap((service) =>
|
|
271
|
-
service.materialize("hooked", undefined, root),
|
|
272
|
-
),
|
|
273
|
-
),
|
|
274
|
-
)
|
|
275
|
-
expect(
|
|
276
|
-
reused.operations.filter(
|
|
277
|
-
(operation) => operation.action === "post-checkout",
|
|
278
|
-
),
|
|
279
|
-
).toEqual([])
|
|
280
|
-
expect(await Bun.file(join(writable, "post-checkout-count")).text()).toBe(
|
|
281
|
-
"x",
|
|
282
|
-
)
|
|
283
|
-
expect(await Bun.file(join(reference, "post-checkout-count")).text()).toBe(
|
|
284
|
-
"x",
|
|
285
|
-
)
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
test("does not fetch the origin for an existing writable worktree", async () => {
|
|
289
|
-
await runTestEffect(
|
|
290
|
-
TaskService.pipe(
|
|
291
|
-
Effect.flatMap((service) =>
|
|
292
|
-
service.create(
|
|
293
|
-
{
|
|
294
|
-
id: "existing",
|
|
295
|
-
ticketUrl: "https://example.com/task",
|
|
296
|
-
repo: "agency",
|
|
297
|
-
branch: "task/existing",
|
|
298
|
-
base: "main",
|
|
299
|
-
},
|
|
300
|
-
root,
|
|
301
|
-
),
|
|
302
|
-
),
|
|
303
|
-
),
|
|
304
|
-
)
|
|
305
|
-
await runTestEffect(
|
|
306
|
-
WorktreeService.pipe(
|
|
307
|
-
Effect.flatMap((service) =>
|
|
308
|
-
service.materialize("existing", undefined, root),
|
|
309
|
-
),
|
|
310
|
-
),
|
|
311
|
-
)
|
|
312
|
-
await git(
|
|
313
|
-
["remote", "set-url", "origin", join(root, "missing")],
|
|
314
|
-
join(root, "repos/agency"),
|
|
315
|
-
)
|
|
316
|
-
const reused = await runTestEffect(
|
|
317
|
-
WorktreeService.pipe(
|
|
318
|
-
Effect.flatMap((service) =>
|
|
319
|
-
service.materialize("existing", undefined, root),
|
|
320
|
-
),
|
|
321
|
-
),
|
|
322
|
-
)
|
|
323
|
-
expect(reused.checkouts).toEqual([
|
|
324
|
-
expect.objectContaining({ repo: "agency", action: "reused" }),
|
|
325
|
-
])
|
|
326
|
-
expect(reused.operations).toEqual([])
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
test("reuses an immutable reference checkout without fetching", async () => {
|
|
330
|
-
await ensureEffectRepository()
|
|
331
|
-
const commit = new TextDecoder()
|
|
332
|
-
.decode(
|
|
333
|
-
Bun.spawnSync(
|
|
334
|
-
["git", "-C", join(root, "repos/effect"), "rev-parse", "main"],
|
|
335
|
-
{ stdout: "pipe" },
|
|
336
|
-
).stdout,
|
|
337
|
-
)
|
|
338
|
-
.trim()
|
|
339
|
-
await runTestEffect(
|
|
340
|
-
TaskService.pipe(
|
|
341
|
-
Effect.flatMap((service) =>
|
|
342
|
-
service.create(
|
|
343
|
-
{
|
|
344
|
-
id: "immutable-reference",
|
|
345
|
-
ticketUrl: "https://example.com/task",
|
|
346
|
-
repo: "agency",
|
|
347
|
-
repos: [{ repo: "effect", ref: commit }],
|
|
348
|
-
branch: "task/immutable-reference",
|
|
349
|
-
base: "main",
|
|
350
|
-
},
|
|
351
|
-
root,
|
|
352
|
-
),
|
|
353
|
-
),
|
|
354
|
-
),
|
|
355
|
-
)
|
|
356
|
-
await runTestEffect(
|
|
357
|
-
WorktreeService.pipe(
|
|
358
|
-
Effect.flatMap((service) =>
|
|
359
|
-
service.materialize("immutable-reference", undefined, root),
|
|
360
|
-
),
|
|
361
|
-
),
|
|
362
|
-
)
|
|
363
|
-
await git(
|
|
364
|
-
["remote", "set-url", "origin", join(root, "missing")],
|
|
365
|
-
join(root, "repos/effect"),
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
await expect(
|
|
369
|
-
runTestEffect(
|
|
370
|
-
WorktreeService.pipe(
|
|
371
|
-
Effect.flatMap((service) =>
|
|
372
|
-
service.materialize("immutable-reference", undefined, root),
|
|
373
|
-
),
|
|
374
|
-
),
|
|
375
|
-
),
|
|
376
|
-
).resolves.toMatchObject({ repos: [{ repo: "effect", ref: commit }] })
|
|
377
|
-
})
|
|
378
|
-
|
|
379
|
-
test("stops before materializing when workbase validation fails", async () => {
|
|
380
|
-
await runTestEffect(
|
|
381
|
-
TaskService.pipe(
|
|
382
|
-
Effect.flatMap((service) =>
|
|
383
|
-
service.create(
|
|
384
|
-
{
|
|
385
|
-
id: "valid-target",
|
|
386
|
-
ticketUrl: "https://example.com/task",
|
|
387
|
-
repo: "agency",
|
|
388
|
-
branch: "task/valid-target",
|
|
389
|
-
base: "main",
|
|
390
|
-
},
|
|
391
|
-
root,
|
|
392
|
-
),
|
|
393
|
-
),
|
|
394
|
-
),
|
|
395
|
-
)
|
|
396
|
-
await mkdir(join(root, "tasks", "missing-document"), { recursive: true })
|
|
397
|
-
|
|
398
|
-
await expect(
|
|
399
|
-
runTestEffect(
|
|
400
|
-
WorktreeService.pipe(
|
|
401
|
-
Effect.flatMap((service) =>
|
|
402
|
-
service.materialize("valid-target", undefined, root),
|
|
403
|
-
),
|
|
404
|
-
),
|
|
405
|
-
),
|
|
406
|
-
).rejects.toThrow("Required document is missing")
|
|
407
|
-
expect(
|
|
408
|
-
await Bun.file(join(root, "tasks", "valid-target", "code")).exists(),
|
|
409
|
-
).toBe(false)
|
|
410
|
-
|
|
411
|
-
await expect(
|
|
412
|
-
runTestEffect(
|
|
413
|
-
WorktreeService.pipe(
|
|
414
|
-
Effect.flatMap((service) =>
|
|
415
|
-
service.materialize("valid-target", undefined, root, {
|
|
416
|
-
force: true,
|
|
417
|
-
}),
|
|
418
|
-
),
|
|
419
|
-
),
|
|
420
|
-
),
|
|
421
|
-
).resolves.toMatchObject({ repo: "agency" })
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
test("uses a configured worktree creation command", async () => {
|
|
425
|
-
await Bun.write(
|
|
426
|
-
join(root, "agency.json"),
|
|
427
|
-
JSON.stringify({
|
|
428
|
-
version: 2,
|
|
429
|
-
worktreeCreateCommand: [
|
|
430
|
-
"git",
|
|
431
|
-
"-C",
|
|
432
|
-
"{repo}",
|
|
433
|
-
"worktree",
|
|
434
|
-
"add",
|
|
435
|
-
"-b",
|
|
436
|
-
"{branch}",
|
|
437
|
-
"{worktree}",
|
|
438
|
-
"{base}",
|
|
439
|
-
],
|
|
440
|
-
}),
|
|
441
|
-
)
|
|
442
|
-
await runTestEffect(
|
|
443
|
-
TaskService.pipe(
|
|
444
|
-
Effect.flatMap((service) =>
|
|
445
|
-
service.create(
|
|
446
|
-
{
|
|
447
|
-
id: "configured",
|
|
448
|
-
ticketUrl: "https://example.com/task",
|
|
449
|
-
repo: "agency",
|
|
450
|
-
branch: "task/configured",
|
|
451
|
-
base: "main",
|
|
452
|
-
},
|
|
453
|
-
root,
|
|
454
|
-
),
|
|
455
|
-
),
|
|
456
|
-
),
|
|
457
|
-
)
|
|
458
|
-
|
|
459
|
-
const workspace = await runTestEffect(
|
|
460
|
-
WorktreeService.pipe(
|
|
461
|
-
Effect.flatMap((service) =>
|
|
462
|
-
service.materialize("configured", undefined, root),
|
|
463
|
-
),
|
|
464
|
-
),
|
|
465
|
-
)
|
|
466
|
-
expect(
|
|
467
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).text(),
|
|
468
|
-
).toBe("example\n")
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
test("logs the expanded configured command in verbose mode", async () => {
|
|
472
|
-
await Bun.write(
|
|
473
|
-
join(root, "agency.json"),
|
|
474
|
-
JSON.stringify({
|
|
475
|
-
version: 2,
|
|
476
|
-
worktreeCreateCommand: [
|
|
477
|
-
"sh",
|
|
478
|
-
"-c",
|
|
479
|
-
'git -C "$1" worktree add -b "$3" "$2" "$4" >/dev/null 2>&1',
|
|
480
|
-
"agency-worktree",
|
|
481
|
-
"{repo}",
|
|
482
|
-
"{worktree}",
|
|
483
|
-
"{branch}",
|
|
484
|
-
"{base}",
|
|
485
|
-
],
|
|
486
|
-
}),
|
|
487
|
-
)
|
|
488
|
-
await runTestEffect(
|
|
489
|
-
TaskService.pipe(
|
|
490
|
-
Effect.flatMap((service) =>
|
|
491
|
-
service.create(
|
|
492
|
-
{
|
|
493
|
-
id: "verbose-command",
|
|
494
|
-
ticketUrl: "https://example.com/task",
|
|
495
|
-
repo: "agency",
|
|
496
|
-
branch: "task/verbose-command",
|
|
497
|
-
base: "main",
|
|
498
|
-
},
|
|
499
|
-
root,
|
|
500
|
-
),
|
|
501
|
-
),
|
|
502
|
-
),
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
const logs = await captureErrors(() =>
|
|
506
|
-
runTestEffect(
|
|
507
|
-
WorktreeService.pipe(
|
|
508
|
-
Effect.flatMap((service) =>
|
|
509
|
-
service.materialize("verbose-command", undefined, root, {
|
|
510
|
-
verbose: true,
|
|
511
|
-
}),
|
|
512
|
-
),
|
|
513
|
-
),
|
|
514
|
-
),
|
|
515
|
-
)
|
|
516
|
-
|
|
517
|
-
expect(logs).toHaveLength(1)
|
|
518
|
-
expect(logs[0]).toStartWith("Running worktree command: sh -c ")
|
|
519
|
-
expect(logs[0]).toContain(join(root, "repos", "agency"))
|
|
520
|
-
expect(logs[0]).toContain(
|
|
521
|
-
join(root, "tasks", "verbose-command", "code", "agency"),
|
|
522
|
-
)
|
|
523
|
-
})
|
|
524
|
-
|
|
525
|
-
test("selects phases and rejects missing or unexpected phase IDs", async () => {
|
|
526
|
-
await Bun.write(
|
|
527
|
-
join(root, "agency.json"),
|
|
528
|
-
JSON.stringify({
|
|
529
|
-
version: 2,
|
|
530
|
-
repositories: {
|
|
531
|
-
agency: {
|
|
532
|
-
remote: "https://example.com/agency.git",
|
|
533
|
-
postCheckoutCommand: [
|
|
534
|
-
"sh",
|
|
535
|
-
"-c",
|
|
536
|
-
'printf "%s:%s" "$AGENCY_TASK_ID" "$AGENCY_PHASE_ID" > post-checkout-owner',
|
|
537
|
-
],
|
|
538
|
-
},
|
|
539
|
-
},
|
|
540
|
-
}),
|
|
541
|
-
)
|
|
542
|
-
await runTestEffect(
|
|
543
|
-
TaskService.pipe(
|
|
544
|
-
Effect.flatMap((service) =>
|
|
545
|
-
service.create(
|
|
546
|
-
{
|
|
547
|
-
id: "multi",
|
|
548
|
-
ticketUrl: "https://example.com/task",
|
|
549
|
-
multiPhase: true,
|
|
550
|
-
},
|
|
551
|
-
root,
|
|
552
|
-
),
|
|
553
|
-
),
|
|
554
|
-
),
|
|
555
|
-
)
|
|
556
|
-
await runTestEffect(
|
|
557
|
-
PhaseService.pipe(
|
|
558
|
-
Effect.flatMap((service) =>
|
|
559
|
-
service.create(
|
|
560
|
-
{
|
|
561
|
-
taskId: "multi",
|
|
562
|
-
id: "selected",
|
|
563
|
-
repo: "agency",
|
|
564
|
-
branch: "task/selected",
|
|
565
|
-
base: "main",
|
|
566
|
-
},
|
|
567
|
-
root,
|
|
568
|
-
),
|
|
569
|
-
),
|
|
570
|
-
),
|
|
571
|
-
)
|
|
572
|
-
|
|
573
|
-
await expect(
|
|
574
|
-
runTestEffect(
|
|
575
|
-
WorktreeService.pipe(
|
|
576
|
-
Effect.flatMap((service) =>
|
|
577
|
-
service.materialize("multi", undefined, root),
|
|
578
|
-
),
|
|
579
|
-
),
|
|
580
|
-
),
|
|
581
|
-
).rejects.toThrow("phase ID is required")
|
|
582
|
-
await expect(
|
|
583
|
-
runTestEffect(
|
|
584
|
-
WorktreeService.pipe(
|
|
585
|
-
Effect.flatMap((service) =>
|
|
586
|
-
service.materialize("multi", "missing", root),
|
|
587
|
-
),
|
|
588
|
-
),
|
|
589
|
-
),
|
|
590
|
-
).rejects.toThrow("Phase 'missing' does not exist on task 'multi'")
|
|
591
|
-
|
|
592
|
-
const workspace = await runTestEffect(
|
|
593
|
-
WorktreeService.pipe(
|
|
594
|
-
Effect.flatMap((service) =>
|
|
595
|
-
service.materialize("multi", "selected", root),
|
|
596
|
-
),
|
|
597
|
-
),
|
|
598
|
-
)
|
|
599
|
-
expect(workspace.phasePath).toBe(
|
|
600
|
-
join(root, "tasks/multi/phases/selected/PHASE.md"),
|
|
601
|
-
)
|
|
602
|
-
expect(workspace.writablePath).toBe(
|
|
603
|
-
join(root, "tasks/multi/phases/selected/code/agency"),
|
|
604
|
-
)
|
|
605
|
-
expect(
|
|
606
|
-
await Bun.file(
|
|
607
|
-
join(workspace.writablePath!, "post-checkout-owner"),
|
|
608
|
-
).text(),
|
|
609
|
-
).toBe("multi:selected")
|
|
610
|
-
|
|
611
|
-
await runTestEffect(
|
|
612
|
-
TaskService.pipe(
|
|
613
|
-
Effect.flatMap((service) =>
|
|
614
|
-
service.create(
|
|
615
|
-
{
|
|
616
|
-
id: "single",
|
|
617
|
-
ticketUrl: "https://example.com/task",
|
|
618
|
-
repo: "agency",
|
|
619
|
-
branch: "task/single",
|
|
620
|
-
base: "main",
|
|
621
|
-
},
|
|
622
|
-
root,
|
|
623
|
-
),
|
|
624
|
-
),
|
|
625
|
-
),
|
|
626
|
-
)
|
|
627
|
-
await expect(
|
|
628
|
-
runTestEffect(
|
|
629
|
-
WorktreeService.pipe(
|
|
630
|
-
Effect.flatMap((service) =>
|
|
631
|
-
service.materialize("single", "unexpected", root),
|
|
632
|
-
),
|
|
633
|
-
),
|
|
634
|
-
),
|
|
635
|
-
).rejects.toThrow("does not accept a phase ID")
|
|
636
|
-
})
|
|
637
|
-
|
|
638
|
-
test("reports meaningful worktree creation failures", async () => {
|
|
639
|
-
const cases = [
|
|
640
|
-
{
|
|
641
|
-
id: "missing-repo",
|
|
642
|
-
repo: "missing",
|
|
643
|
-
base: "main",
|
|
644
|
-
config: { version: 2 },
|
|
645
|
-
expected: "Unknown repository alias 'missing'",
|
|
646
|
-
},
|
|
647
|
-
{
|
|
648
|
-
id: "bad-base",
|
|
649
|
-
repo: "agency",
|
|
650
|
-
base: "absent-base",
|
|
651
|
-
config: { version: 2 },
|
|
652
|
-
expected:
|
|
653
|
-
"Base 'absent-base' for repository 'agency' does not resolve to a commit",
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
id: "failed-command",
|
|
657
|
-
repo: "agency",
|
|
658
|
-
base: "main",
|
|
659
|
-
config: {
|
|
660
|
-
version: 2,
|
|
661
|
-
worktreeCreateCommand: [
|
|
662
|
-
"sh",
|
|
663
|
-
"-c",
|
|
664
|
-
"echo command-failed >&2; exit 7",
|
|
665
|
-
"{repo}",
|
|
666
|
-
"{worktree}",
|
|
667
|
-
],
|
|
668
|
-
},
|
|
669
|
-
expected: "Failed to create worktree for 'agency': command-failed",
|
|
670
|
-
},
|
|
671
|
-
{
|
|
672
|
-
id: "missing-destination",
|
|
673
|
-
repo: "agency",
|
|
674
|
-
base: "main",
|
|
675
|
-
config: {
|
|
676
|
-
version: 2,
|
|
677
|
-
worktreeCreateCommand: ["sh", "-c", "exit 0", "{repo}", "{worktree}"],
|
|
678
|
-
},
|
|
679
|
-
expected: "Worktree command did not create",
|
|
680
|
-
},
|
|
681
|
-
] as const
|
|
682
|
-
|
|
683
|
-
for (const fixture of cases) {
|
|
684
|
-
await Bun.write(join(root, "agency.json"), JSON.stringify(fixture.config))
|
|
685
|
-
const taskDirectory = join(root, "tasks", fixture.id)
|
|
686
|
-
await mkdir(taskDirectory, { recursive: true })
|
|
687
|
-
await Bun.write(
|
|
688
|
-
join(taskDirectory, "TASK.md"),
|
|
689
|
-
`---
|
|
690
|
-
ticketUrl: https://example.com/tasks/${fixture.id}
|
|
691
|
-
repo: ${fixture.repo}
|
|
692
|
-
branch: task/${fixture.id}
|
|
693
|
-
base: ${fixture.base}
|
|
694
|
-
pr: null
|
|
695
|
-
---
|
|
696
|
-
`,
|
|
697
|
-
)
|
|
698
|
-
|
|
699
|
-
await expect(
|
|
700
|
-
runTestEffect(
|
|
701
|
-
WorktreeService.pipe(
|
|
702
|
-
Effect.flatMap((service) =>
|
|
703
|
-
service.materialize(fixture.id, undefined, root),
|
|
704
|
-
),
|
|
705
|
-
),
|
|
706
|
-
),
|
|
707
|
-
).rejects.toThrow(fixture.expected)
|
|
708
|
-
await rm(taskDirectory, { recursive: true, force: true })
|
|
709
|
-
}
|
|
710
|
-
})
|
|
711
|
-
|
|
712
|
-
test("compensates a custom command that fails after creating Git state", async () => {
|
|
713
|
-
await Bun.write(
|
|
714
|
-
join(root, "agency.json"),
|
|
715
|
-
JSON.stringify({
|
|
716
|
-
version: 2,
|
|
717
|
-
worktreeCreateCommand: [
|
|
718
|
-
"sh",
|
|
719
|
-
"-c",
|
|
720
|
-
'git -C "$1" worktree add -b "$3" "$2" "$4" >/dev/null 2>&1; exit 7',
|
|
721
|
-
"agency-worktree",
|
|
722
|
-
"{repo}",
|
|
723
|
-
"{worktree}",
|
|
724
|
-
"{branch}",
|
|
725
|
-
"{base}",
|
|
726
|
-
],
|
|
727
|
-
}),
|
|
728
|
-
)
|
|
729
|
-
await runTestEffect(
|
|
730
|
-
TaskService.pipe(
|
|
731
|
-
Effect.flatMap((service) =>
|
|
732
|
-
service.create(
|
|
733
|
-
{
|
|
734
|
-
id: "compensated",
|
|
735
|
-
ticketUrl: "https://example.com/task",
|
|
736
|
-
repo: "agency",
|
|
737
|
-
branch: "task/compensated",
|
|
738
|
-
base: "main",
|
|
739
|
-
},
|
|
740
|
-
root,
|
|
741
|
-
),
|
|
742
|
-
),
|
|
743
|
-
),
|
|
744
|
-
)
|
|
745
|
-
|
|
746
|
-
await expect(
|
|
747
|
-
runTestEffect(
|
|
748
|
-
WorktreeService.pipe(
|
|
749
|
-
Effect.flatMap((service) =>
|
|
750
|
-
service.materialize("compensated", undefined, root),
|
|
751
|
-
),
|
|
752
|
-
),
|
|
753
|
-
),
|
|
754
|
-
).rejects.toThrow("Failed to create worktree for 'agency'")
|
|
755
|
-
expect(
|
|
756
|
-
await Bun.file(join(root, "tasks/compensated/code/agency")).exists(),
|
|
757
|
-
).toBe(false)
|
|
758
|
-
expect(
|
|
759
|
-
Bun.spawnSync([
|
|
760
|
-
"git",
|
|
761
|
-
"-C",
|
|
762
|
-
join(root, "repos/agency"),
|
|
763
|
-
"show-ref",
|
|
764
|
-
"--verify",
|
|
765
|
-
"refs/heads/task/compensated",
|
|
766
|
-
]).exitCode,
|
|
767
|
-
).not.toBe(0)
|
|
768
|
-
})
|
|
769
|
-
|
|
770
|
-
test("reports a planned hook in dry runs without executing it", async () => {
|
|
771
|
-
const marker = join(root, "dry-run-hook")
|
|
772
|
-
await Bun.write(
|
|
773
|
-
join(root, "agency.json"),
|
|
774
|
-
JSON.stringify({
|
|
775
|
-
version: 2,
|
|
776
|
-
repositories: {
|
|
777
|
-
agency: {
|
|
778
|
-
remote: "https://example.com/agency.git",
|
|
779
|
-
postCheckoutCommand: ["sh", "-c", 'touch "$1"', "hook", marker],
|
|
780
|
-
},
|
|
781
|
-
},
|
|
782
|
-
}),
|
|
783
|
-
)
|
|
784
|
-
await runTestEffect(
|
|
785
|
-
TaskService.pipe(
|
|
786
|
-
Effect.flatMap((service) =>
|
|
787
|
-
service.create(
|
|
788
|
-
{
|
|
789
|
-
id: "dry-hook",
|
|
790
|
-
ticketUrl: null,
|
|
791
|
-
repo: "agency",
|
|
792
|
-
branch: "task/dry-hook",
|
|
793
|
-
base: "main",
|
|
794
|
-
},
|
|
795
|
-
root,
|
|
796
|
-
),
|
|
797
|
-
),
|
|
798
|
-
),
|
|
799
|
-
)
|
|
800
|
-
|
|
801
|
-
const materializeDry = () =>
|
|
802
|
-
runTestEffect(
|
|
803
|
-
WorktreeService.pipe(
|
|
804
|
-
Effect.flatMap((service) =>
|
|
805
|
-
service.materialize("dry-hook", undefined, root, {
|
|
806
|
-
dryRun: true,
|
|
807
|
-
verbose: true,
|
|
808
|
-
}),
|
|
809
|
-
),
|
|
810
|
-
),
|
|
811
|
-
)
|
|
812
|
-
let workspace!: Awaited<ReturnType<typeof materializeDry>>
|
|
813
|
-
const logs = await captureErrors(async () => {
|
|
814
|
-
workspace = await materializeDry()
|
|
815
|
-
})
|
|
816
|
-
expect(workspace.operations).toContainEqual({
|
|
817
|
-
action: "post-checkout",
|
|
818
|
-
repo: "agency",
|
|
819
|
-
command: ["sh", "-c", 'touch "$1"', "hook", marker],
|
|
820
|
-
status: "planned",
|
|
821
|
-
})
|
|
822
|
-
expect(await Bun.file(marker).exists()).toBe(false)
|
|
823
|
-
expect(await Bun.file(workspace.writablePath!).exists()).toBe(false)
|
|
824
|
-
expect(logs).toEqual([
|
|
825
|
-
expect.stringContaining("Planning post-checkout command for 'agency':"),
|
|
826
|
-
])
|
|
827
|
-
})
|
|
828
|
-
|
|
829
|
-
test("rolls back a failed hook and runs it again on retry", async () => {
|
|
830
|
-
const retryMarker = join(root, "retry-hook")
|
|
831
|
-
await Bun.write(
|
|
832
|
-
join(root, "agency.json"),
|
|
833
|
-
JSON.stringify({
|
|
834
|
-
version: 2,
|
|
835
|
-
repositories: {
|
|
836
|
-
agency: {
|
|
837
|
-
remote: "https://example.com/agency.git",
|
|
838
|
-
postCheckoutCommand: [
|
|
839
|
-
"sh",
|
|
840
|
-
"-c",
|
|
841
|
-
'if [ ! -f "$1" ]; then touch partial-bootstrap "$1"; echo bootstrap-failed >&2; exit 7; fi',
|
|
842
|
-
"hook",
|
|
843
|
-
retryMarker,
|
|
844
|
-
],
|
|
845
|
-
},
|
|
846
|
-
},
|
|
847
|
-
}),
|
|
848
|
-
)
|
|
849
|
-
await runTestEffect(
|
|
850
|
-
TaskService.pipe(
|
|
851
|
-
Effect.flatMap((service) =>
|
|
852
|
-
service.create(
|
|
853
|
-
{
|
|
854
|
-
id: "retry-hook",
|
|
855
|
-
ticketUrl: null,
|
|
856
|
-
repo: "agency",
|
|
857
|
-
branch: "task/retry-hook",
|
|
858
|
-
base: "main",
|
|
859
|
-
},
|
|
860
|
-
root,
|
|
861
|
-
),
|
|
862
|
-
),
|
|
863
|
-
),
|
|
864
|
-
)
|
|
865
|
-
const checkoutPath = join(root, "tasks/retry-hook/code/agency")
|
|
866
|
-
|
|
867
|
-
await expect(
|
|
868
|
-
runTestEffect(
|
|
869
|
-
WorktreeService.pipe(
|
|
870
|
-
Effect.flatMap((service) =>
|
|
871
|
-
service.materialize("retry-hook", undefined, root),
|
|
872
|
-
),
|
|
873
|
-
),
|
|
874
|
-
),
|
|
875
|
-
).rejects.toThrow("bootstrap-failed")
|
|
876
|
-
expect(await Bun.file(checkoutPath).exists()).toBe(false)
|
|
877
|
-
expect(
|
|
878
|
-
Bun.spawnSync([
|
|
879
|
-
"git",
|
|
880
|
-
"-C",
|
|
881
|
-
join(root, "repos/agency"),
|
|
882
|
-
"show-ref",
|
|
883
|
-
"--verify",
|
|
884
|
-
"refs/heads/task/retry-hook",
|
|
885
|
-
]).exitCode,
|
|
886
|
-
).not.toBe(0)
|
|
887
|
-
|
|
888
|
-
await expect(
|
|
889
|
-
runTestEffect(
|
|
890
|
-
WorktreeService.pipe(
|
|
891
|
-
Effect.flatMap((service) =>
|
|
892
|
-
service.materialize("retry-hook", undefined, root),
|
|
893
|
-
),
|
|
894
|
-
),
|
|
895
|
-
),
|
|
896
|
-
).resolves.toMatchObject({ writablePath: checkoutPath })
|
|
897
|
-
})
|
|
898
|
-
|
|
899
|
-
test("does not run a hook when checkout validation fails", async () => {
|
|
900
|
-
const marker = join(root, "invalid-checkout-hook")
|
|
901
|
-
await Bun.write(
|
|
902
|
-
join(root, "agency.json"),
|
|
903
|
-
JSON.stringify({
|
|
904
|
-
version: 2,
|
|
905
|
-
worktreeCreateCommand: [
|
|
906
|
-
"git",
|
|
907
|
-
"-C",
|
|
908
|
-
"{repo}",
|
|
909
|
-
"worktree",
|
|
910
|
-
"add",
|
|
911
|
-
"--detach",
|
|
912
|
-
"{worktree}",
|
|
913
|
-
"{base}",
|
|
914
|
-
],
|
|
915
|
-
repositories: {
|
|
916
|
-
agency: {
|
|
917
|
-
remote: "https://example.com/agency.git",
|
|
918
|
-
postCheckoutCommand: ["sh", "-c", 'touch "$1"', "hook", marker],
|
|
919
|
-
},
|
|
920
|
-
},
|
|
921
|
-
}),
|
|
922
|
-
)
|
|
923
|
-
await runTestEffect(
|
|
924
|
-
TaskService.pipe(
|
|
925
|
-
Effect.flatMap((service) =>
|
|
926
|
-
service.create(
|
|
927
|
-
{
|
|
928
|
-
id: "invalid-hook-order",
|
|
929
|
-
ticketUrl: null,
|
|
930
|
-
repo: "agency",
|
|
931
|
-
branch: "task/invalid-hook-order",
|
|
932
|
-
base: "main",
|
|
933
|
-
},
|
|
934
|
-
root,
|
|
935
|
-
),
|
|
936
|
-
),
|
|
937
|
-
),
|
|
938
|
-
)
|
|
939
|
-
|
|
940
|
-
await expect(
|
|
941
|
-
runTestEffect(
|
|
942
|
-
WorktreeService.pipe(
|
|
943
|
-
Effect.flatMap((service) =>
|
|
944
|
-
service.materialize("invalid-hook-order", undefined, root),
|
|
945
|
-
),
|
|
946
|
-
),
|
|
947
|
-
),
|
|
948
|
-
).rejects.toThrow("failed validation")
|
|
949
|
-
expect(await Bun.file(marker).exists()).toBe(false)
|
|
950
|
-
})
|
|
951
|
-
|
|
952
|
-
test("rolls back when a hook executable cannot be started", async () => {
|
|
953
|
-
await Bun.write(
|
|
954
|
-
join(root, "agency.json"),
|
|
955
|
-
JSON.stringify({
|
|
956
|
-
version: 2,
|
|
957
|
-
repositories: {
|
|
958
|
-
agency: {
|
|
959
|
-
remote: "https://example.com/agency.git",
|
|
960
|
-
postCheckoutCommand: ["agency-missing-hook-executable"],
|
|
961
|
-
},
|
|
962
|
-
},
|
|
963
|
-
}),
|
|
964
|
-
)
|
|
965
|
-
await runTestEffect(
|
|
966
|
-
TaskService.pipe(
|
|
967
|
-
Effect.flatMap((service) =>
|
|
968
|
-
service.create(
|
|
969
|
-
{
|
|
970
|
-
id: "missing-hook-command",
|
|
971
|
-
ticketUrl: null,
|
|
972
|
-
repo: "agency",
|
|
973
|
-
branch: "task/missing-hook-command",
|
|
974
|
-
base: "main",
|
|
975
|
-
},
|
|
976
|
-
root,
|
|
977
|
-
),
|
|
978
|
-
),
|
|
979
|
-
),
|
|
980
|
-
)
|
|
981
|
-
const checkoutPath = join(root, "tasks/missing-hook-command/code/agency")
|
|
982
|
-
|
|
983
|
-
await expect(
|
|
984
|
-
runTestEffect(
|
|
985
|
-
WorktreeService.pipe(
|
|
986
|
-
Effect.flatMap((service) =>
|
|
987
|
-
service.materialize("missing-hook-command", undefined, root),
|
|
988
|
-
),
|
|
989
|
-
),
|
|
990
|
-
),
|
|
991
|
-
).rejects.toThrow("Failed to start post-checkout command for 'agency'")
|
|
992
|
-
expect(await Bun.file(checkoutPath).exists()).toBe(false)
|
|
993
|
-
})
|
|
994
|
-
|
|
995
|
-
test("moves and repairs an existing worktree when converting a task", async () => {
|
|
996
|
-
await runTestEffect(
|
|
997
|
-
TaskService.pipe(
|
|
998
|
-
Effect.flatMap((service) =>
|
|
999
|
-
service.create(
|
|
1000
|
-
{
|
|
1001
|
-
id: "promoted",
|
|
1002
|
-
ticketUrl: "https://example.com/task",
|
|
1003
|
-
repo: "agency",
|
|
1004
|
-
branch: "task/promoted",
|
|
1005
|
-
base: "main",
|
|
1006
|
-
},
|
|
1007
|
-
root,
|
|
1008
|
-
),
|
|
1009
|
-
),
|
|
1010
|
-
),
|
|
1011
|
-
)
|
|
1012
|
-
const originalWorkspace = await runTestEffect(
|
|
1013
|
-
WorktreeService.pipe(
|
|
1014
|
-
Effect.flatMap((service) =>
|
|
1015
|
-
service.materialize("promoted", undefined, root),
|
|
1016
|
-
),
|
|
1017
|
-
),
|
|
1018
|
-
)
|
|
1019
|
-
|
|
1020
|
-
await runTestEffect(
|
|
1021
|
-
PhaseService.pipe(
|
|
1022
|
-
Effect.flatMap((service) =>
|
|
1023
|
-
service.create(
|
|
1024
|
-
{
|
|
1025
|
-
taskId: "promoted",
|
|
1026
|
-
id: "follow-up",
|
|
1027
|
-
firstPhase: "implementation",
|
|
1028
|
-
repo: "agency",
|
|
1029
|
-
branch: "task/follow-up",
|
|
1030
|
-
base: "main",
|
|
1031
|
-
},
|
|
1032
|
-
root,
|
|
1033
|
-
),
|
|
1034
|
-
),
|
|
1035
|
-
),
|
|
1036
|
-
)
|
|
1037
|
-
|
|
1038
|
-
expect(
|
|
1039
|
-
await Bun.file(
|
|
1040
|
-
join(originalWorkspace.writablePath!, "README.md"),
|
|
1041
|
-
).exists(),
|
|
1042
|
-
).toBe(false)
|
|
1043
|
-
const movedWorkspace = await runTestEffect(
|
|
1044
|
-
WorktreeService.pipe(
|
|
1045
|
-
Effect.flatMap((service) =>
|
|
1046
|
-
service.materialize("promoted", "implementation", root),
|
|
1047
|
-
),
|
|
1048
|
-
),
|
|
1049
|
-
)
|
|
1050
|
-
expect(movedWorkspace.writablePath).toBe(
|
|
1051
|
-
join(root, "tasks/promoted/phases/implementation/code/agency"),
|
|
1052
|
-
)
|
|
1053
|
-
expect(
|
|
1054
|
-
await Bun.file(join(movedWorkspace.writablePath!, "README.md")).text(),
|
|
1055
|
-
).toBe("example\n")
|
|
1056
|
-
const status = Bun.spawnSync(
|
|
1057
|
-
["git", "-C", movedWorkspace.writablePath!, "status", "--porcelain"],
|
|
1058
|
-
{ stdout: "pipe", stderr: "pipe" },
|
|
1059
|
-
)
|
|
1060
|
-
expect(status.exitCode).toBe(0)
|
|
1061
|
-
})
|
|
1062
|
-
|
|
1063
|
-
test("preflights worktree registration before converting a task", async () => {
|
|
1064
|
-
await runTestEffect(
|
|
1065
|
-
TaskService.pipe(
|
|
1066
|
-
Effect.flatMap((service) =>
|
|
1067
|
-
service.create(
|
|
1068
|
-
{
|
|
1069
|
-
id: "unregistered",
|
|
1070
|
-
ticketUrl: null,
|
|
1071
|
-
repo: "agency",
|
|
1072
|
-
branch: "task/unregistered",
|
|
1073
|
-
base: "main",
|
|
1074
|
-
},
|
|
1075
|
-
root,
|
|
1076
|
-
),
|
|
1077
|
-
),
|
|
1078
|
-
),
|
|
1079
|
-
)
|
|
1080
|
-
const checkout = join(root, "tasks/unregistered/code/agency")
|
|
1081
|
-
await mkdir(checkout, { recursive: true })
|
|
1082
|
-
await Bun.write(join(checkout, "keep.txt"), "keep\n")
|
|
1083
|
-
|
|
1084
|
-
await expect(
|
|
1085
|
-
runTestEffect(
|
|
1086
|
-
PhaseService.pipe(
|
|
1087
|
-
Effect.flatMap((service) =>
|
|
1088
|
-
service.create(
|
|
1089
|
-
{
|
|
1090
|
-
taskId: "unregistered",
|
|
1091
|
-
id: "follow-up",
|
|
1092
|
-
firstPhase: "implementation",
|
|
1093
|
-
repo: "agency",
|
|
1094
|
-
branch: "task/follow-up-unregistered",
|
|
1095
|
-
base: "main",
|
|
1096
|
-
},
|
|
1097
|
-
root,
|
|
1098
|
-
),
|
|
1099
|
-
),
|
|
1100
|
-
),
|
|
1101
|
-
),
|
|
1102
|
-
).rejects.toThrow("is not registered as a Git worktree")
|
|
1103
|
-
expect(await Bun.file(join(checkout, "keep.txt")).text()).toBe("keep\n")
|
|
1104
|
-
expect(
|
|
1105
|
-
await Bun.file(
|
|
1106
|
-
join(root, "tasks/unregistered/phases/implementation/PHASE.md"),
|
|
1107
|
-
).exists(),
|
|
1108
|
-
).toBe(false)
|
|
1109
|
-
})
|
|
1110
|
-
|
|
1111
|
-
test("rejects a writable branch checked out in another worktree", async () => {
|
|
1112
|
-
const repository = join(root, "repos/agency")
|
|
1113
|
-
await git(["-C", repository, "branch", "task/shared", "main"])
|
|
1114
|
-
const outside = join(root, "outside")
|
|
1115
|
-
await git(["-C", repository, "worktree", "add", outside, "task/shared"])
|
|
1116
|
-
await runTestEffect(
|
|
1117
|
-
TaskService.pipe(
|
|
1118
|
-
Effect.flatMap((service) =>
|
|
1119
|
-
service.create(
|
|
1120
|
-
{
|
|
1121
|
-
id: "conflict",
|
|
1122
|
-
ticketUrl: "https://example.com/task",
|
|
1123
|
-
repo: "agency",
|
|
1124
|
-
branch: "task/shared",
|
|
1125
|
-
base: "main",
|
|
1126
|
-
},
|
|
1127
|
-
root,
|
|
1128
|
-
),
|
|
1129
|
-
),
|
|
1130
|
-
),
|
|
1131
|
-
)
|
|
1132
|
-
|
|
1133
|
-
await expect(
|
|
1134
|
-
runTestEffect(
|
|
1135
|
-
WorktreeService.pipe(
|
|
1136
|
-
Effect.flatMap((service) =>
|
|
1137
|
-
service.materialize("conflict", undefined, root),
|
|
1138
|
-
),
|
|
1139
|
-
),
|
|
1140
|
-
),
|
|
1141
|
-
).rejects.toThrow("already checked out at")
|
|
1142
|
-
})
|
|
1143
|
-
|
|
1144
|
-
test("rejects duplicate Agency ownership before materializing", async () => {
|
|
1145
|
-
for (const id of ["first-owner", "second-owner"]) {
|
|
1146
|
-
await runTestEffect(
|
|
1147
|
-
TaskService.pipe(
|
|
1148
|
-
Effect.flatMap((service) =>
|
|
1149
|
-
service.create(
|
|
1150
|
-
{
|
|
1151
|
-
id,
|
|
1152
|
-
ticketUrl: `https://example.com/${id}`,
|
|
1153
|
-
repo: "agency",
|
|
1154
|
-
branch: "task/shared-owner",
|
|
1155
|
-
base: "main",
|
|
1156
|
-
},
|
|
1157
|
-
root,
|
|
1158
|
-
),
|
|
1159
|
-
),
|
|
1160
|
-
),
|
|
1161
|
-
)
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
await expect(
|
|
1165
|
-
runTestEffect(
|
|
1166
|
-
WorktreeService.pipe(
|
|
1167
|
-
Effect.flatMap((service) =>
|
|
1168
|
-
service.materialize("first-owner", undefined, root),
|
|
1169
|
-
),
|
|
1170
|
-
),
|
|
1171
|
-
),
|
|
1172
|
-
).rejects.toThrow("also owned by tasks/first-owner/TASK.md")
|
|
1173
|
-
})
|
|
1174
|
-
|
|
1175
|
-
test("rejects an existing Agency checkout on the wrong branch", async () => {
|
|
1176
|
-
const repository = join(root, "repos/agency")
|
|
1177
|
-
await runTestEffect(
|
|
1178
|
-
TaskService.pipe(
|
|
1179
|
-
Effect.flatMap((service) =>
|
|
1180
|
-
service.create(
|
|
1181
|
-
{
|
|
1182
|
-
id: "wrong",
|
|
1183
|
-
ticketUrl: "https://example.com/task",
|
|
1184
|
-
repo: "agency",
|
|
1185
|
-
branch: "task/expected",
|
|
1186
|
-
base: "main",
|
|
1187
|
-
},
|
|
1188
|
-
root,
|
|
1189
|
-
),
|
|
1190
|
-
),
|
|
1191
|
-
),
|
|
1192
|
-
)
|
|
1193
|
-
await git(["-C", repository, "branch", "task/wrong", "main"])
|
|
1194
|
-
const checkout = join(root, "tasks/wrong/code/agency")
|
|
1195
|
-
await mkdir(join(root, "tasks/wrong/code"), { recursive: true })
|
|
1196
|
-
await git(["-C", repository, "worktree", "add", checkout, "task/wrong"])
|
|
1197
|
-
|
|
1198
|
-
await expect(
|
|
1199
|
-
runTestEffect(
|
|
1200
|
-
WorktreeService.pipe(
|
|
1201
|
-
Effect.flatMap((service) =>
|
|
1202
|
-
service.materialize("wrong", undefined, root),
|
|
1203
|
-
),
|
|
1204
|
-
),
|
|
1205
|
-
),
|
|
1206
|
-
).rejects.toThrow("is not registered to branch 'task/expected'")
|
|
1207
|
-
})
|
|
1208
|
-
|
|
1209
|
-
test("fetches a moving ref before checking a reused reference checkout", async () => {
|
|
1210
|
-
await ensureEffectRepository()
|
|
1211
|
-
await runTestEffect(
|
|
1212
|
-
TaskService.pipe(
|
|
1213
|
-
Effect.flatMap((service) =>
|
|
1214
|
-
service.create(
|
|
1215
|
-
{
|
|
1216
|
-
id: "pinned-reference",
|
|
1217
|
-
ticketUrl: "https://example.com/task",
|
|
1218
|
-
repo: "agency",
|
|
1219
|
-
repos: [{ repo: "effect", ref: "origin/main" }],
|
|
1220
|
-
branch: "task/pinned-reference",
|
|
1221
|
-
base: "main",
|
|
1222
|
-
},
|
|
1223
|
-
root,
|
|
1224
|
-
),
|
|
1225
|
-
),
|
|
1226
|
-
),
|
|
1227
|
-
)
|
|
1228
|
-
await runTestEffect(
|
|
1229
|
-
WorktreeService.pipe(
|
|
1230
|
-
Effect.flatMap((service) =>
|
|
1231
|
-
service.materialize("pinned-reference", undefined, root),
|
|
1232
|
-
),
|
|
1233
|
-
),
|
|
1234
|
-
)
|
|
1235
|
-
|
|
1236
|
-
await Bun.write(join(source, "README.md"), "updated\n")
|
|
1237
|
-
await git(["add", "README.md"], source)
|
|
1238
|
-
await git(["-c", "commit.gpgsign=false", "commit", "-m", "update"], source)
|
|
1239
|
-
|
|
1240
|
-
await expect(
|
|
1241
|
-
runTestEffect(
|
|
1242
|
-
WorktreeService.pipe(
|
|
1243
|
-
Effect.flatMap((service) =>
|
|
1244
|
-
service.materialize("pinned-reference", undefined, root),
|
|
1245
|
-
),
|
|
1246
|
-
),
|
|
1247
|
-
),
|
|
1248
|
-
).rejects.toThrow("does not match reference 'origin/main'")
|
|
1249
|
-
})
|
|
1250
|
-
|
|
1251
|
-
test("rejects a reference checkout attached to a branch", async () => {
|
|
1252
|
-
await ensureEffectRepository()
|
|
1253
|
-
await runTestEffect(
|
|
1254
|
-
TaskService.pipe(
|
|
1255
|
-
Effect.flatMap((service) =>
|
|
1256
|
-
service.create(
|
|
1257
|
-
{
|
|
1258
|
-
id: "attached-reference",
|
|
1259
|
-
ticketUrl: "https://example.com/task",
|
|
1260
|
-
repo: "agency",
|
|
1261
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
1262
|
-
branch: "task/attached-reference",
|
|
1263
|
-
base: "main",
|
|
1264
|
-
},
|
|
1265
|
-
root,
|
|
1266
|
-
),
|
|
1267
|
-
),
|
|
1268
|
-
),
|
|
1269
|
-
)
|
|
1270
|
-
const checkout = join(root, "tasks/attached-reference/code/effect")
|
|
1271
|
-
await mkdir(join(root, "tasks/attached-reference/code"), {
|
|
1272
|
-
recursive: true,
|
|
1273
|
-
})
|
|
1274
|
-
await git([
|
|
1275
|
-
"-C",
|
|
1276
|
-
join(root, "repos/effect"),
|
|
1277
|
-
"worktree",
|
|
1278
|
-
"add",
|
|
1279
|
-
checkout,
|
|
1280
|
-
"main",
|
|
1281
|
-
])
|
|
1282
|
-
|
|
1283
|
-
await expect(
|
|
1284
|
-
runTestEffect(
|
|
1285
|
-
WorktreeService.pipe(
|
|
1286
|
-
Effect.flatMap((service) =>
|
|
1287
|
-
service.materialize("attached-reference", undefined, root),
|
|
1288
|
-
),
|
|
1289
|
-
),
|
|
1290
|
-
),
|
|
1291
|
-
).rejects.toThrow("is attached to branch 'main'")
|
|
1292
|
-
expect(
|
|
1293
|
-
await Bun.file(
|
|
1294
|
-
join(root, "tasks/attached-reference/code/agency"),
|
|
1295
|
-
).exists(),
|
|
1296
|
-
).toBe(false)
|
|
1297
|
-
expect(
|
|
1298
|
-
Bun.spawnSync([
|
|
1299
|
-
"git",
|
|
1300
|
-
"-C",
|
|
1301
|
-
join(root, "repos/agency"),
|
|
1302
|
-
"show-ref",
|
|
1303
|
-
"--verify",
|
|
1304
|
-
"refs/heads/task/attached-reference",
|
|
1305
|
-
]).exitCode,
|
|
1306
|
-
).not.toBe(0)
|
|
1307
|
-
})
|
|
1308
|
-
|
|
1309
|
-
test("removes worktrees without deleting branches", async () => {
|
|
1310
|
-
await ensureEffectRepository()
|
|
1311
|
-
await runTestEffect(
|
|
1312
|
-
TaskService.pipe(
|
|
1313
|
-
Effect.flatMap((service) =>
|
|
1314
|
-
service.create(
|
|
1315
|
-
{
|
|
1316
|
-
id: "removable",
|
|
1317
|
-
ticketUrl: "https://example.com/task",
|
|
1318
|
-
repo: "agency",
|
|
1319
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
1320
|
-
branch: "task/removable",
|
|
1321
|
-
base: "main",
|
|
1322
|
-
},
|
|
1323
|
-
root,
|
|
1324
|
-
),
|
|
1325
|
-
),
|
|
1326
|
-
),
|
|
1327
|
-
)
|
|
1328
|
-
const workspace = await runTestEffect(
|
|
1329
|
-
WorktreeService.pipe(
|
|
1330
|
-
Effect.flatMap((service) =>
|
|
1331
|
-
service.materialize("removable", undefined, root),
|
|
1332
|
-
),
|
|
1333
|
-
),
|
|
1334
|
-
)
|
|
1335
|
-
|
|
1336
|
-
const removed = await runTestEffect(
|
|
1337
|
-
WorktreeService.pipe(
|
|
1338
|
-
Effect.flatMap((service) =>
|
|
1339
|
-
service.remove("removable", undefined, root),
|
|
1340
|
-
),
|
|
1341
|
-
),
|
|
1342
|
-
)
|
|
1343
|
-
|
|
1344
|
-
expect(removed.sort()).toEqual(
|
|
1345
|
-
[
|
|
1346
|
-
join(workspace.codePath, "agency"),
|
|
1347
|
-
join(workspace.codePath, "effect"),
|
|
1348
|
-
].sort(),
|
|
1349
|
-
)
|
|
1350
|
-
expect(await Bun.file(workspace.codePath).exists()).toBe(false)
|
|
1351
|
-
const branch = Bun.spawnSync([
|
|
1352
|
-
"git",
|
|
1353
|
-
"-C",
|
|
1354
|
-
join(root, "repos/agency"),
|
|
1355
|
-
"show-ref",
|
|
1356
|
-
"--verify",
|
|
1357
|
-
"refs/heads/task/removable",
|
|
1358
|
-
])
|
|
1359
|
-
expect(branch.exitCode).toBe(0)
|
|
1360
|
-
expect(workspace.checkouts).toEqual([
|
|
1361
|
-
expect.objectContaining({
|
|
1362
|
-
repo: "agency",
|
|
1363
|
-
kind: "writable",
|
|
1364
|
-
action: "created",
|
|
1365
|
-
resolvedCommit: expect.stringMatching(/^[0-9a-f]{40}$/),
|
|
1366
|
-
}),
|
|
1367
|
-
expect.objectContaining({
|
|
1368
|
-
repo: "effect",
|
|
1369
|
-
kind: "reference",
|
|
1370
|
-
action: "created",
|
|
1371
|
-
resolvedCommit: expect.stringMatching(/^[0-9a-f]{40}$/),
|
|
1372
|
-
}),
|
|
1373
|
-
])
|
|
1374
|
-
})
|
|
1375
|
-
|
|
1376
|
-
test("reports dry-run fetch and worktree changes without mutating", async () => {
|
|
1377
|
-
await ensureEffectRepository()
|
|
1378
|
-
await runTestEffect(
|
|
1379
|
-
TaskService.pipe(
|
|
1380
|
-
Effect.flatMap((service) =>
|
|
1381
|
-
service.create(
|
|
1382
|
-
{
|
|
1383
|
-
id: "planned",
|
|
1384
|
-
ticketUrl: "https://example.com/task",
|
|
1385
|
-
repo: "agency",
|
|
1386
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
1387
|
-
branch: "task/planned",
|
|
1388
|
-
base: "main",
|
|
1389
|
-
},
|
|
1390
|
-
root,
|
|
1391
|
-
),
|
|
1392
|
-
),
|
|
1393
|
-
),
|
|
1394
|
-
)
|
|
1395
|
-
|
|
1396
|
-
const workspace = await runTestEffect(
|
|
1397
|
-
WorktreeService.pipe(
|
|
1398
|
-
Effect.flatMap((service) =>
|
|
1399
|
-
service.materialize("planned", undefined, root, { dryRun: true }),
|
|
1400
|
-
),
|
|
1401
|
-
),
|
|
1402
|
-
)
|
|
1403
|
-
|
|
1404
|
-
expect(workspace.dryRun).toBe(true)
|
|
1405
|
-
expect(
|
|
1406
|
-
workspace.checkouts.every(({ resolvedCommit }) => resolvedCommit),
|
|
1407
|
-
).toBe(true)
|
|
1408
|
-
expect(
|
|
1409
|
-
workspace.checkouts.map(({ repo, action }) => ({ repo, action })),
|
|
1410
|
-
).toEqual([
|
|
1411
|
-
{ repo: "agency", action: "created" },
|
|
1412
|
-
{ repo: "effect", action: "created" },
|
|
1413
|
-
])
|
|
1414
|
-
expect(workspace.operations).toEqual(
|
|
1415
|
-
expect.arrayContaining([
|
|
1416
|
-
expect.objectContaining({ action: "fetch", status: "planned" }),
|
|
1417
|
-
expect.objectContaining({
|
|
1418
|
-
action: "create-worktree",
|
|
1419
|
-
status: "planned",
|
|
1420
|
-
}),
|
|
1421
|
-
]),
|
|
1422
|
-
)
|
|
1423
|
-
expect(await Bun.file(workspace.codePath).exists()).toBe(false)
|
|
1424
|
-
expect(
|
|
1425
|
-
Bun.spawnSync([
|
|
1426
|
-
"git",
|
|
1427
|
-
"-C",
|
|
1428
|
-
join(root, "repos/agency"),
|
|
1429
|
-
"show-ref",
|
|
1430
|
-
"--verify",
|
|
1431
|
-
"refs/heads/task/planned",
|
|
1432
|
-
]).exitCode,
|
|
1433
|
-
).not.toBe(0)
|
|
1434
|
-
})
|
|
1435
|
-
|
|
1436
|
-
test("dry-run resolves a reference that exists only on the remote", async () => {
|
|
1437
|
-
await ensureEffectRepository()
|
|
1438
|
-
await git(["checkout", "-b", "remote-only"], source)
|
|
1439
|
-
await Bun.write(join(source, "remote.txt"), "remote\n")
|
|
1440
|
-
await git(["add", "remote.txt"], source)
|
|
1441
|
-
await git(
|
|
1442
|
-
["-c", "commit.gpgsign=false", "commit", "-m", "remote branch"],
|
|
1443
|
-
source,
|
|
1444
|
-
)
|
|
1445
|
-
await runTestEffect(
|
|
1446
|
-
TaskService.pipe(
|
|
1447
|
-
Effect.flatMap((service) =>
|
|
1448
|
-
service.create(
|
|
1449
|
-
{
|
|
1450
|
-
id: "remote-reference",
|
|
1451
|
-
ticketUrl: null,
|
|
1452
|
-
repo: "agency",
|
|
1453
|
-
repos: [{ repo: "effect", ref: "remote-only" }],
|
|
1454
|
-
branch: "task/remote-reference",
|
|
1455
|
-
base: "main",
|
|
1456
|
-
},
|
|
1457
|
-
root,
|
|
1458
|
-
),
|
|
1459
|
-
),
|
|
1460
|
-
),
|
|
1461
|
-
)
|
|
1462
|
-
|
|
1463
|
-
const workspace = await runTestEffect(
|
|
1464
|
-
WorktreeService.pipe(
|
|
1465
|
-
Effect.flatMap((service) =>
|
|
1466
|
-
service.materialize("remote-reference", undefined, root, {
|
|
1467
|
-
dryRun: true,
|
|
1468
|
-
}),
|
|
1469
|
-
),
|
|
1470
|
-
),
|
|
1471
|
-
)
|
|
1472
|
-
expect(
|
|
1473
|
-
workspace.checkouts.find((checkout) => checkout.repo === "effect")
|
|
1474
|
-
?.resolvedCommit,
|
|
1475
|
-
).toMatch(/^[0-9a-f]{40}$/)
|
|
1476
|
-
expect(
|
|
1477
|
-
Bun.spawnSync([
|
|
1478
|
-
"git",
|
|
1479
|
-
"-C",
|
|
1480
|
-
join(root, "repos/effect"),
|
|
1481
|
-
"show-ref",
|
|
1482
|
-
"--verify",
|
|
1483
|
-
"refs/heads/remote-only",
|
|
1484
|
-
]).exitCode,
|
|
1485
|
-
).not.toBe(0)
|
|
1486
|
-
})
|
|
1487
|
-
|
|
1488
|
-
test("refuses to remove a worktree with uncommitted changes", async () => {
|
|
1489
|
-
await runTestEffect(
|
|
1490
|
-
TaskService.pipe(
|
|
1491
|
-
Effect.flatMap((service) =>
|
|
1492
|
-
service.create(
|
|
1493
|
-
{
|
|
1494
|
-
id: "dirty",
|
|
1495
|
-
ticketUrl: "https://example.com/task",
|
|
1496
|
-
repo: "agency",
|
|
1497
|
-
branch: "task/dirty",
|
|
1498
|
-
base: "main",
|
|
1499
|
-
},
|
|
1500
|
-
root,
|
|
1501
|
-
),
|
|
1502
|
-
),
|
|
1503
|
-
),
|
|
1504
|
-
)
|
|
1505
|
-
const workspace = await runTestEffect(
|
|
1506
|
-
WorktreeService.pipe(
|
|
1507
|
-
Effect.flatMap((service) =>
|
|
1508
|
-
service.materialize("dirty", undefined, root),
|
|
1509
|
-
),
|
|
1510
|
-
),
|
|
1511
|
-
)
|
|
1512
|
-
await Bun.write(
|
|
1513
|
-
join(workspace.writablePath!, "uncommitted.txt"),
|
|
1514
|
-
"keep me\n",
|
|
1515
|
-
)
|
|
1516
|
-
|
|
1517
|
-
await expect(
|
|
1518
|
-
runTestEffect(
|
|
1519
|
-
WorktreeService.pipe(
|
|
1520
|
-
Effect.flatMap((service) => service.remove("dirty", undefined, root)),
|
|
1521
|
-
),
|
|
1522
|
-
),
|
|
1523
|
-
).rejects.toThrow("Failed to remove worktree for 'agency'")
|
|
1524
|
-
expect(
|
|
1525
|
-
await Bun.file(join(workspace.writablePath!, "uncommitted.txt")).text(),
|
|
1526
|
-
).toBe("keep me\n")
|
|
1527
|
-
})
|
|
1528
|
-
|
|
1529
|
-
test("refuses to remove worktrees for active work", async () => {
|
|
1530
|
-
await runTestEffect(
|
|
1531
|
-
TaskService.pipe(
|
|
1532
|
-
Effect.flatMap((service) =>
|
|
1533
|
-
service.create(
|
|
1534
|
-
{
|
|
1535
|
-
id: "active-removal",
|
|
1536
|
-
ticketUrl: null,
|
|
1537
|
-
repo: "agency",
|
|
1538
|
-
branch: "task/active-removal",
|
|
1539
|
-
base: "main",
|
|
1540
|
-
},
|
|
1541
|
-
root,
|
|
1542
|
-
),
|
|
1543
|
-
),
|
|
1544
|
-
),
|
|
1545
|
-
)
|
|
1546
|
-
const workspace = await runTestEffect(
|
|
1547
|
-
WorktreeService.pipe(
|
|
1548
|
-
Effect.flatMap((service) =>
|
|
1549
|
-
service.materialize("active-removal", undefined, root),
|
|
1550
|
-
),
|
|
1551
|
-
),
|
|
1552
|
-
)
|
|
1553
|
-
await runTestEffect(
|
|
1554
|
-
TaskService.pipe(
|
|
1555
|
-
Effect.flatMap((service) =>
|
|
1556
|
-
service.setStatus("active-removal", "working", root),
|
|
1557
|
-
),
|
|
1558
|
-
),
|
|
1559
|
-
)
|
|
1560
|
-
|
|
1561
|
-
await expect(
|
|
1562
|
-
runTestEffect(
|
|
1563
|
-
WorktreeService.pipe(
|
|
1564
|
-
Effect.flatMap((service) =>
|
|
1565
|
-
service.remove("active-removal", undefined, root),
|
|
1566
|
-
),
|
|
1567
|
-
),
|
|
1568
|
-
),
|
|
1569
|
-
).rejects.toThrow("active 'working' ownership")
|
|
1570
|
-
expect(
|
|
1571
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).exists(),
|
|
1572
|
-
).toBe(true)
|
|
1573
|
-
})
|
|
1574
|
-
|
|
1575
|
-
test("restores earlier worktrees and preserves the Git failure diagnostic", async () => {
|
|
1576
|
-
await ensureEffectRepository()
|
|
1577
|
-
await runTestEffect(
|
|
1578
|
-
TaskService.pipe(
|
|
1579
|
-
Effect.flatMap((service) =>
|
|
1580
|
-
service.create(
|
|
1581
|
-
{
|
|
1582
|
-
id: "locked-removal",
|
|
1583
|
-
ticketUrl: null,
|
|
1584
|
-
repo: "agency",
|
|
1585
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
1586
|
-
branch: "task/locked-removal",
|
|
1587
|
-
base: "main",
|
|
1588
|
-
},
|
|
1589
|
-
root,
|
|
1590
|
-
),
|
|
1591
|
-
),
|
|
1592
|
-
),
|
|
1593
|
-
)
|
|
1594
|
-
const workspace = await runTestEffect(
|
|
1595
|
-
WorktreeService.pipe(
|
|
1596
|
-
Effect.flatMap((service) =>
|
|
1597
|
-
service.materialize("locked-removal", undefined, root),
|
|
1598
|
-
),
|
|
1599
|
-
),
|
|
1600
|
-
)
|
|
1601
|
-
const referencePath = join(workspace.codePath, "effect")
|
|
1602
|
-
await git([
|
|
1603
|
-
"-C",
|
|
1604
|
-
join(root, "repos/effect"),
|
|
1605
|
-
"worktree",
|
|
1606
|
-
"lock",
|
|
1607
|
-
referencePath,
|
|
1608
|
-
])
|
|
1609
|
-
|
|
1610
|
-
const failure = await runTestEffect(
|
|
1611
|
-
WorktreeService.pipe(
|
|
1612
|
-
Effect.flatMap((service) =>
|
|
1613
|
-
service.remove("locked-removal", undefined, root),
|
|
1614
|
-
),
|
|
1615
|
-
Effect.flip,
|
|
1616
|
-
),
|
|
1617
|
-
)
|
|
1618
|
-
|
|
1619
|
-
expect(failure.message).toContain("locked working tree")
|
|
1620
|
-
expect(failure).toMatchObject({
|
|
1621
|
-
completed: [workspace.writablePath!],
|
|
1622
|
-
rolledBack: [workspace.writablePath!],
|
|
1623
|
-
manualRecovery: [],
|
|
1624
|
-
})
|
|
1625
|
-
for (const checkout of [workspace.writablePath!, referencePath]) {
|
|
1626
|
-
expect(await Bun.file(join(checkout, "README.md")).exists()).toBe(true)
|
|
1627
|
-
}
|
|
1628
|
-
})
|
|
1629
|
-
|
|
1630
|
-
test("handles a missing checkout without deleting its branch", async () => {
|
|
1631
|
-
await runTestEffect(
|
|
1632
|
-
TaskService.pipe(
|
|
1633
|
-
Effect.flatMap((service) =>
|
|
1634
|
-
service.create(
|
|
1635
|
-
{
|
|
1636
|
-
id: "stale",
|
|
1637
|
-
ticketUrl: "https://example.com/task",
|
|
1638
|
-
repo: "agency",
|
|
1639
|
-
branch: "task/stale",
|
|
1640
|
-
base: "main",
|
|
1641
|
-
},
|
|
1642
|
-
root,
|
|
1643
|
-
),
|
|
1644
|
-
),
|
|
1645
|
-
),
|
|
1646
|
-
)
|
|
1647
|
-
const workspace = await runTestEffect(
|
|
1648
|
-
WorktreeService.pipe(
|
|
1649
|
-
Effect.flatMap((service) =>
|
|
1650
|
-
service.materialize("stale", undefined, root),
|
|
1651
|
-
),
|
|
1652
|
-
),
|
|
1653
|
-
)
|
|
1654
|
-
await rm(workspace.codePath, { recursive: true })
|
|
1655
|
-
|
|
1656
|
-
const removed = await runTestEffect(
|
|
1657
|
-
WorktreeService.pipe(
|
|
1658
|
-
Effect.flatMap((service) => service.remove("stale", undefined, root)),
|
|
1659
|
-
),
|
|
1660
|
-
)
|
|
1661
|
-
|
|
1662
|
-
expect(removed).toHaveLength(1)
|
|
1663
|
-
expect(removed[0]).toEndWith("/tasks/stale/code/agency")
|
|
1664
|
-
const worktrees = Bun.spawnSync([
|
|
1665
|
-
"git",
|
|
1666
|
-
"-C",
|
|
1667
|
-
join(root, "repos/agency"),
|
|
1668
|
-
"worktree",
|
|
1669
|
-
"list",
|
|
1670
|
-
"--porcelain",
|
|
1671
|
-
])
|
|
1672
|
-
expect(new TextDecoder().decode(worktrees.stdout)).not.toContain(
|
|
1673
|
-
workspace.writablePath!,
|
|
1674
|
-
)
|
|
1675
|
-
expect(
|
|
1676
|
-
Bun.spawnSync([
|
|
1677
|
-
"git",
|
|
1678
|
-
"-C",
|
|
1679
|
-
join(root, "repos/agency"),
|
|
1680
|
-
"show-ref",
|
|
1681
|
-
"--verify",
|
|
1682
|
-
"refs/heads/task/stale",
|
|
1683
|
-
]).exitCode,
|
|
1684
|
-
).toBe(0)
|
|
1685
|
-
})
|
|
1686
|
-
|
|
1687
|
-
test("does not prune unrelated stale worktree registrations", async () => {
|
|
1688
|
-
for (const id of ["stale-target", "stale-unrelated"]) {
|
|
1689
|
-
await runTestEffect(
|
|
1690
|
-
TaskService.pipe(
|
|
1691
|
-
Effect.flatMap((service) =>
|
|
1692
|
-
service.create(
|
|
1693
|
-
{
|
|
1694
|
-
id,
|
|
1695
|
-
ticketUrl: null,
|
|
1696
|
-
repo: "agency",
|
|
1697
|
-
branch: `task/${id}`,
|
|
1698
|
-
base: "main",
|
|
1699
|
-
},
|
|
1700
|
-
root,
|
|
1701
|
-
),
|
|
1702
|
-
),
|
|
1703
|
-
),
|
|
1704
|
-
)
|
|
1705
|
-
const workspace = await runTestEffect(
|
|
1706
|
-
WorktreeService.pipe(
|
|
1707
|
-
Effect.flatMap((service) => service.materialize(id, undefined, root)),
|
|
1708
|
-
),
|
|
1709
|
-
)
|
|
1710
|
-
await rm(workspace.codePath, { recursive: true })
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
await expect(
|
|
1714
|
-
runTestEffect(
|
|
1715
|
-
WorktreeService.pipe(
|
|
1716
|
-
Effect.flatMap((service) =>
|
|
1717
|
-
service.remove("stale-target", undefined, root),
|
|
1718
|
-
),
|
|
1719
|
-
),
|
|
1720
|
-
),
|
|
1721
|
-
).rejects.toThrow("would also remove unrelated stale registrations")
|
|
1722
|
-
const registered = await gitOutput([
|
|
1723
|
-
"-C",
|
|
1724
|
-
join(root, "repos/agency"),
|
|
1725
|
-
"worktree",
|
|
1726
|
-
"list",
|
|
1727
|
-
"--porcelain",
|
|
1728
|
-
])
|
|
1729
|
-
expect(registered).toContain("tasks/stale-target/code/agency")
|
|
1730
|
-
expect(registered).toContain("tasks/stale-unrelated/code/agency")
|
|
1731
|
-
})
|
|
1732
|
-
|
|
1733
|
-
test("lists and inspects ownership, registration, commits, and dirtiness", async () => {
|
|
1734
|
-
const repository = join(root, "repos/agency")
|
|
1735
|
-
await git(["-C", repository, "branch", "task/inspected", "main"])
|
|
1736
|
-
const outside = join(root, "outside-inspected")
|
|
1737
|
-
await git(["-C", repository, "worktree", "add", outside, "task/inspected"])
|
|
1738
|
-
await Bun.write(join(outside, "dirty.txt"), "keep\n")
|
|
1739
|
-
await runTestEffect(
|
|
1740
|
-
TaskService.pipe(
|
|
1741
|
-
Effect.flatMap((service) =>
|
|
1742
|
-
service.create(
|
|
1743
|
-
{
|
|
1744
|
-
id: "inspected",
|
|
1745
|
-
ticketUrl: null,
|
|
1746
|
-
repo: "agency",
|
|
1747
|
-
branch: "task/inspected",
|
|
1748
|
-
base: "main",
|
|
1749
|
-
},
|
|
1750
|
-
root,
|
|
1751
|
-
),
|
|
1752
|
-
),
|
|
1753
|
-
),
|
|
1754
|
-
)
|
|
1755
|
-
|
|
1756
|
-
const inspections = await runTestEffect(
|
|
1757
|
-
WorktreeService.pipe(Effect.flatMap((service) => service.list(root))),
|
|
1758
|
-
)
|
|
1759
|
-
const inspection = inspections.find(
|
|
1760
|
-
({ owner }) => owner.taskId === "inspected",
|
|
1761
|
-
)!
|
|
1762
|
-
const checkout = inspection.checkouts[0]!
|
|
1763
|
-
expect(inspection.owner).toMatchObject({
|
|
1764
|
-
kind: "task",
|
|
1765
|
-
taskId: "inspected",
|
|
1766
|
-
documentPath: join(root, "tasks/inspected/TASK.md"),
|
|
1767
|
-
})
|
|
1768
|
-
const registeredOutside = await realpath(outside)
|
|
1769
|
-
expect(checkout).toMatchObject({
|
|
1770
|
-
registeredPath: registeredOutside,
|
|
1771
|
-
actualBranch: "task/inspected",
|
|
1772
|
-
actualCommit: expect.stringMatching(/^[0-9a-f]{40}$/),
|
|
1773
|
-
dirty: true,
|
|
1774
|
-
})
|
|
1775
|
-
expect(checkout.conflicts).toContainEqual(
|
|
1776
|
-
expect.objectContaining({
|
|
1777
|
-
kind: "branch-conflict",
|
|
1778
|
-
registeredPath: registeredOutside,
|
|
1779
|
-
branch: "task/inspected",
|
|
1780
|
-
commit: expect.stringMatching(/^[0-9a-f]{40}$/),
|
|
1781
|
-
dirty: true,
|
|
1782
|
-
}),
|
|
1783
|
-
)
|
|
1784
|
-
})
|
|
1785
|
-
|
|
1786
|
-
test("refuses to remove a clean checkout owned by the wrong branch", async () => {
|
|
1787
|
-
await runTestEffect(
|
|
1788
|
-
TaskService.pipe(
|
|
1789
|
-
Effect.flatMap((service) =>
|
|
1790
|
-
service.create(
|
|
1791
|
-
{
|
|
1792
|
-
id: "remove-wrong",
|
|
1793
|
-
ticketUrl: null,
|
|
1794
|
-
repo: "agency",
|
|
1795
|
-
branch: "task/expected-remove",
|
|
1796
|
-
base: "main",
|
|
1797
|
-
},
|
|
1798
|
-
root,
|
|
1799
|
-
),
|
|
1800
|
-
),
|
|
1801
|
-
),
|
|
1802
|
-
)
|
|
1803
|
-
const repository = join(root, "repos/agency")
|
|
1804
|
-
await git(["-C", repository, "branch", "task/actual-remove", "main"])
|
|
1805
|
-
const checkout = join(root, "tasks/remove-wrong/code/agency")
|
|
1806
|
-
await mkdir(join(root, "tasks/remove-wrong/code"), { recursive: true })
|
|
1807
|
-
await git([
|
|
1808
|
-
"-C",
|
|
1809
|
-
repository,
|
|
1810
|
-
"worktree",
|
|
1811
|
-
"add",
|
|
1812
|
-
checkout,
|
|
1813
|
-
"task/actual-remove",
|
|
1814
|
-
])
|
|
1815
|
-
|
|
1816
|
-
await expect(
|
|
1817
|
-
runTestEffect(
|
|
1818
|
-
WorktreeService.pipe(
|
|
1819
|
-
Effect.flatMap((service) =>
|
|
1820
|
-
service.remove("remove-wrong", undefined, root),
|
|
1821
|
-
),
|
|
1822
|
-
),
|
|
1823
|
-
),
|
|
1824
|
-
).rejects.toThrow("not branch 'task/expected-remove'")
|
|
1825
|
-
expect(await Bun.file(join(checkout, "README.md")).exists()).toBe(true)
|
|
1826
|
-
})
|
|
1827
|
-
|
|
1828
|
-
test("does not delete a non-worktree entry named for an expected alias", async () => {
|
|
1829
|
-
await runTestEffect(
|
|
1830
|
-
TaskService.pipe(
|
|
1831
|
-
Effect.flatMap((service) =>
|
|
1832
|
-
service.create(
|
|
1833
|
-
{
|
|
1834
|
-
id: "unexpected-file",
|
|
1835
|
-
ticketUrl: null,
|
|
1836
|
-
repo: "agency",
|
|
1837
|
-
branch: "task/unexpected-file",
|
|
1838
|
-
base: "main",
|
|
1839
|
-
},
|
|
1840
|
-
root,
|
|
1841
|
-
),
|
|
1842
|
-
),
|
|
1843
|
-
),
|
|
1844
|
-
)
|
|
1845
|
-
const codePath = join(root, "tasks/unexpected-file/code")
|
|
1846
|
-
const unexpected = join(codePath, "agency")
|
|
1847
|
-
await mkdir(codePath, { recursive: true })
|
|
1848
|
-
await Bun.write(unexpected, "keep me\n")
|
|
1849
|
-
|
|
1850
|
-
await expect(
|
|
1851
|
-
runTestEffect(
|
|
1852
|
-
WorktreeService.pipe(
|
|
1853
|
-
Effect.flatMap((service) =>
|
|
1854
|
-
service.remove("unexpected-file", undefined, root),
|
|
1855
|
-
),
|
|
1856
|
-
),
|
|
1857
|
-
),
|
|
1858
|
-
).rejects.toThrow("is not a directory")
|
|
1859
|
-
expect(await Bun.file(unexpected).text()).toBe("keep me\n")
|
|
1860
|
-
})
|
|
1861
|
-
|
|
1862
|
-
test("does not follow a symlink named for an expected checkout", async () => {
|
|
1863
|
-
await runTestEffect(
|
|
1864
|
-
TaskService.pipe(
|
|
1865
|
-
Effect.flatMap((service) =>
|
|
1866
|
-
service.create(
|
|
1867
|
-
{
|
|
1868
|
-
id: "symlink-removal",
|
|
1869
|
-
ticketUrl: null,
|
|
1870
|
-
repo: "agency",
|
|
1871
|
-
branch: "task/symlink-removal",
|
|
1872
|
-
base: "main",
|
|
1873
|
-
},
|
|
1874
|
-
root,
|
|
1875
|
-
),
|
|
1876
|
-
),
|
|
1877
|
-
),
|
|
1878
|
-
)
|
|
1879
|
-
const repository = join(root, "repos/agency")
|
|
1880
|
-
await git(["-C", repository, "branch", "task/symlink-removal", "main"])
|
|
1881
|
-
const outside = join(root, "outside-symlink-removal")
|
|
1882
|
-
await git([
|
|
1883
|
-
"-C",
|
|
1884
|
-
repository,
|
|
1885
|
-
"worktree",
|
|
1886
|
-
"add",
|
|
1887
|
-
outside,
|
|
1888
|
-
"task/symlink-removal",
|
|
1889
|
-
])
|
|
1890
|
-
const codePath = join(root, "tasks/symlink-removal/code")
|
|
1891
|
-
await mkdir(codePath, { recursive: true })
|
|
1892
|
-
await symlink(outside, join(codePath, "agency"), "dir")
|
|
1893
|
-
|
|
1894
|
-
await expect(
|
|
1895
|
-
runTestEffect(
|
|
1896
|
-
WorktreeService.pipe(
|
|
1897
|
-
Effect.flatMap((service) =>
|
|
1898
|
-
service.remove("symlink-removal", undefined, root),
|
|
1899
|
-
),
|
|
1900
|
-
),
|
|
1901
|
-
),
|
|
1902
|
-
).rejects.toThrow("is a symbolic link")
|
|
1903
|
-
expect(await Bun.file(join(outside, "README.md")).exists()).toBe(true)
|
|
1904
|
-
})
|
|
1905
|
-
|
|
1906
|
-
test("refuses removal when a branch has duplicate Agency owners", async () => {
|
|
1907
|
-
await runTestEffect(
|
|
1908
|
-
TaskService.pipe(
|
|
1909
|
-
Effect.flatMap((service) =>
|
|
1910
|
-
service.create(
|
|
1911
|
-
{
|
|
1912
|
-
id: "owned-removal",
|
|
1913
|
-
ticketUrl: null,
|
|
1914
|
-
repo: "agency",
|
|
1915
|
-
branch: "task/owned-removal",
|
|
1916
|
-
base: "main",
|
|
1917
|
-
},
|
|
1918
|
-
root,
|
|
1919
|
-
),
|
|
1920
|
-
),
|
|
1921
|
-
),
|
|
1922
|
-
)
|
|
1923
|
-
const workspace = await runTestEffect(
|
|
1924
|
-
WorktreeService.pipe(
|
|
1925
|
-
Effect.flatMap((service) =>
|
|
1926
|
-
service.materialize("owned-removal", undefined, root),
|
|
1927
|
-
),
|
|
1928
|
-
),
|
|
1929
|
-
)
|
|
1930
|
-
await runTestEffect(
|
|
1931
|
-
TaskService.pipe(
|
|
1932
|
-
Effect.flatMap((service) =>
|
|
1933
|
-
service.create(
|
|
1934
|
-
{
|
|
1935
|
-
id: "other-owner",
|
|
1936
|
-
ticketUrl: null,
|
|
1937
|
-
repo: "agency",
|
|
1938
|
-
branch: "task/owned-removal",
|
|
1939
|
-
base: "main",
|
|
1940
|
-
},
|
|
1941
|
-
root,
|
|
1942
|
-
),
|
|
1943
|
-
),
|
|
1944
|
-
),
|
|
1945
|
-
)
|
|
1946
|
-
|
|
1947
|
-
await expect(
|
|
1948
|
-
runTestEffect(
|
|
1949
|
-
WorktreeService.pipe(
|
|
1950
|
-
Effect.flatMap((service) =>
|
|
1951
|
-
service.remove("owned-removal", undefined, root),
|
|
1952
|
-
),
|
|
1953
|
-
),
|
|
1954
|
-
),
|
|
1955
|
-
).rejects.toThrow("multiple Agency owners")
|
|
1956
|
-
expect(
|
|
1957
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).exists(),
|
|
1958
|
-
).toBe(true)
|
|
1959
|
-
})
|
|
1960
|
-
|
|
1961
|
-
test("dry-runs and rebuilds every clean declared checkout", async () => {
|
|
1962
|
-
await ensureEffectRepository()
|
|
1963
|
-
await runTestEffect(
|
|
1964
|
-
TaskService.pipe(
|
|
1965
|
-
Effect.flatMap((service) =>
|
|
1966
|
-
service.create(
|
|
1967
|
-
{
|
|
1968
|
-
id: "rebuilt",
|
|
1969
|
-
ticketUrl: null,
|
|
1970
|
-
repo: "agency",
|
|
1971
|
-
repos: [{ repo: "effect", ref: "main" }],
|
|
1972
|
-
branch: "task/rebuilt",
|
|
1973
|
-
base: "main",
|
|
1974
|
-
},
|
|
1975
|
-
root,
|
|
1976
|
-
),
|
|
1977
|
-
),
|
|
1978
|
-
),
|
|
1979
|
-
)
|
|
1980
|
-
const original = await runTestEffect(
|
|
1981
|
-
WorktreeService.pipe(
|
|
1982
|
-
Effect.flatMap((service) =>
|
|
1983
|
-
service.materialize("rebuilt", undefined, root),
|
|
1984
|
-
),
|
|
1985
|
-
),
|
|
1986
|
-
)
|
|
1987
|
-
const plan = await runTestEffect(
|
|
1988
|
-
WorktreeService.pipe(
|
|
1989
|
-
Effect.flatMap((service) =>
|
|
1990
|
-
service.rebuild("rebuilt", undefined, root, { dryRun: true }),
|
|
1991
|
-
),
|
|
1992
|
-
),
|
|
1993
|
-
)
|
|
1994
|
-
expect(plan.actions).toEqual(
|
|
1995
|
-
expect.arrayContaining([
|
|
1996
|
-
`remove ${join(original.codePath, "agency")}`,
|
|
1997
|
-
`create ${join(original.codePath, "agency")}`,
|
|
1998
|
-
`remove ${join(original.codePath, "effect")}`,
|
|
1999
|
-
`create ${join(original.codePath, "effect")}`,
|
|
2000
|
-
]),
|
|
2001
|
-
)
|
|
2002
|
-
expect(
|
|
2003
|
-
await Bun.file(join(original.writablePath!, "README.md")).exists(),
|
|
2004
|
-
).toBe(true)
|
|
2005
|
-
|
|
2006
|
-
const rebuilt = await runTestEffect(
|
|
2007
|
-
WorktreeService.pipe(
|
|
2008
|
-
Effect.flatMap((service) =>
|
|
2009
|
-
service.rebuild("rebuilt", undefined, root),
|
|
2010
|
-
),
|
|
2011
|
-
),
|
|
2012
|
-
)
|
|
2013
|
-
expect(rebuilt.inspection.conflicts).toEqual([])
|
|
2014
|
-
expect(
|
|
2015
|
-
await Bun.file(join(original.writablePath!, "README.md")).exists(),
|
|
2016
|
-
).toBe(true)
|
|
2017
|
-
})
|
|
2018
|
-
|
|
2019
|
-
test("restores removed worktrees when rebuild creation fails", async () => {
|
|
2020
|
-
await runTestEffect(
|
|
2021
|
-
TaskService.pipe(
|
|
2022
|
-
Effect.flatMap((service) =>
|
|
2023
|
-
service.create(
|
|
2024
|
-
{
|
|
2025
|
-
id: "rebuild-rollback",
|
|
2026
|
-
ticketUrl: null,
|
|
2027
|
-
repo: "agency",
|
|
2028
|
-
branch: "task/rebuild-rollback",
|
|
2029
|
-
base: "main",
|
|
2030
|
-
},
|
|
2031
|
-
root,
|
|
2032
|
-
),
|
|
2033
|
-
),
|
|
2034
|
-
),
|
|
2035
|
-
)
|
|
2036
|
-
const workspace = await runTestEffect(
|
|
2037
|
-
WorktreeService.pipe(
|
|
2038
|
-
Effect.flatMap((service) =>
|
|
2039
|
-
service.materialize("rebuild-rollback", undefined, root),
|
|
2040
|
-
),
|
|
2041
|
-
),
|
|
2042
|
-
)
|
|
2043
|
-
await Bun.write(
|
|
2044
|
-
join(root, "agency.json"),
|
|
2045
|
-
JSON.stringify({
|
|
2046
|
-
version: 2,
|
|
2047
|
-
worktreeCreateCommand: [
|
|
2048
|
-
"sh",
|
|
2049
|
-
"-c",
|
|
2050
|
-
"echo rebuild-failed >&2; exit 7",
|
|
2051
|
-
"{repo}",
|
|
2052
|
-
"{worktree}",
|
|
2053
|
-
],
|
|
2054
|
-
}),
|
|
2055
|
-
)
|
|
2056
|
-
|
|
2057
|
-
await expect(
|
|
2058
|
-
runTestEffect(
|
|
2059
|
-
WorktreeService.pipe(
|
|
2060
|
-
Effect.flatMap((service) =>
|
|
2061
|
-
service.rebuild("rebuild-rollback", undefined, root),
|
|
2062
|
-
),
|
|
2063
|
-
),
|
|
2064
|
-
),
|
|
2065
|
-
).rejects.toThrow("original worktrees were restored")
|
|
2066
|
-
expect(
|
|
2067
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).exists(),
|
|
2068
|
-
).toBe(true)
|
|
2069
|
-
})
|
|
2070
|
-
|
|
2071
|
-
test("repairs a stale registration without deleting the writable branch", async () => {
|
|
2072
|
-
await runTestEffect(
|
|
2073
|
-
TaskService.pipe(
|
|
2074
|
-
Effect.flatMap((service) =>
|
|
2075
|
-
service.create(
|
|
2076
|
-
{
|
|
2077
|
-
id: "repaired",
|
|
2078
|
-
ticketUrl: null,
|
|
2079
|
-
repo: "agency",
|
|
2080
|
-
branch: "task/repaired",
|
|
2081
|
-
base: "main",
|
|
2082
|
-
},
|
|
2083
|
-
root,
|
|
2084
|
-
),
|
|
2085
|
-
),
|
|
2086
|
-
),
|
|
2087
|
-
)
|
|
2088
|
-
const workspace = await runTestEffect(
|
|
2089
|
-
WorktreeService.pipe(
|
|
2090
|
-
Effect.flatMap((service) =>
|
|
2091
|
-
service.materialize("repaired", undefined, root),
|
|
2092
|
-
),
|
|
2093
|
-
),
|
|
2094
|
-
)
|
|
2095
|
-
await rm(workspace.codePath, { recursive: true })
|
|
2096
|
-
|
|
2097
|
-
const plan = await runTestEffect(
|
|
2098
|
-
WorktreeService.pipe(
|
|
2099
|
-
Effect.flatMap((service) =>
|
|
2100
|
-
service.repair("repaired", undefined, root, { dryRun: true }),
|
|
2101
|
-
),
|
|
2102
|
-
),
|
|
2103
|
-
)
|
|
2104
|
-
expect(plan.actions.join("\n")).toContain("worktree prune --expire now")
|
|
2105
|
-
expect(plan.actions).toContain(`prepare ${workspace.writablePath!}`)
|
|
2106
|
-
|
|
2107
|
-
const repaired = await runTestEffect(
|
|
2108
|
-
WorktreeService.pipe(
|
|
2109
|
-
Effect.flatMap((service) =>
|
|
2110
|
-
service.repair("repaired", undefined, root),
|
|
2111
|
-
),
|
|
2112
|
-
),
|
|
2113
|
-
)
|
|
2114
|
-
expect(repaired.inspection.conflicts).toEqual([])
|
|
2115
|
-
expect(
|
|
2116
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).exists(),
|
|
2117
|
-
).toBe(true)
|
|
2118
|
-
expect(
|
|
2119
|
-
Bun.spawnSync([
|
|
2120
|
-
"git",
|
|
2121
|
-
"-C",
|
|
2122
|
-
join(root, "repos/agency"),
|
|
2123
|
-
"show-ref",
|
|
2124
|
-
"--verify",
|
|
2125
|
-
"refs/heads/task/repaired",
|
|
2126
|
-
]).exitCode,
|
|
2127
|
-
).toBe(0)
|
|
2128
|
-
})
|
|
2129
|
-
|
|
2130
|
-
test("refuses to repair an unregistered checkout on the wrong branch", async () => {
|
|
2131
|
-
await runTestEffect(
|
|
2132
|
-
TaskService.pipe(
|
|
2133
|
-
Effect.flatMap((service) =>
|
|
2134
|
-
service.create(
|
|
2135
|
-
{
|
|
2136
|
-
id: "repair-wrong",
|
|
2137
|
-
ticketUrl: null,
|
|
2138
|
-
repo: "agency",
|
|
2139
|
-
branch: "task/repair-expected",
|
|
2140
|
-
base: "main",
|
|
2141
|
-
},
|
|
2142
|
-
root,
|
|
2143
|
-
),
|
|
2144
|
-
),
|
|
2145
|
-
),
|
|
2146
|
-
)
|
|
2147
|
-
const repository = join(root, "repos/agency")
|
|
2148
|
-
await git(["-C", repository, "branch", "task/repair-actual", "main"])
|
|
2149
|
-
const oldPath = join(root, "repair-old-path")
|
|
2150
|
-
const checkout = join(root, "tasks/repair-wrong/code/agency")
|
|
2151
|
-
await git([
|
|
2152
|
-
"-C",
|
|
2153
|
-
repository,
|
|
2154
|
-
"worktree",
|
|
2155
|
-
"add",
|
|
2156
|
-
oldPath,
|
|
2157
|
-
"task/repair-actual",
|
|
2158
|
-
])
|
|
2159
|
-
await mkdir(join(root, "tasks/repair-wrong/code"), { recursive: true })
|
|
2160
|
-
await rename(oldPath, checkout)
|
|
2161
|
-
await Bun.write(join(checkout, "uncommitted.txt"), "keep me\n")
|
|
2162
|
-
|
|
2163
|
-
await expect(
|
|
2164
|
-
runTestEffect(
|
|
2165
|
-
WorktreeService.pipe(
|
|
2166
|
-
Effect.flatMap((service) =>
|
|
2167
|
-
service.repair("repair-wrong", undefined, root),
|
|
2168
|
-
),
|
|
2169
|
-
),
|
|
2170
|
-
),
|
|
2171
|
-
).rejects.toThrow("not branch 'task/repair-expected'")
|
|
2172
|
-
expect(await Bun.file(join(checkout, "uncommitted.txt")).text()).toBe(
|
|
2173
|
-
"keep me\n",
|
|
2174
|
-
)
|
|
2175
|
-
})
|
|
2176
|
-
|
|
2177
|
-
test("repairs a moved checkout without changing its branch or dirty files", async () => {
|
|
2178
|
-
await runTestEffect(
|
|
2179
|
-
TaskService.pipe(
|
|
2180
|
-
Effect.flatMap((service) =>
|
|
2181
|
-
service.create(
|
|
2182
|
-
{
|
|
2183
|
-
id: "repair-moved",
|
|
2184
|
-
ticketUrl: null,
|
|
2185
|
-
repo: "agency",
|
|
2186
|
-
branch: "task/repair-moved",
|
|
2187
|
-
base: "main",
|
|
2188
|
-
},
|
|
2189
|
-
root,
|
|
2190
|
-
),
|
|
2191
|
-
),
|
|
2192
|
-
),
|
|
2193
|
-
)
|
|
2194
|
-
const repository = join(root, "repos/agency")
|
|
2195
|
-
await git(["-C", repository, "branch", "task/repair-moved", "main"])
|
|
2196
|
-
const oldPath = join(root, "repair-moved-old")
|
|
2197
|
-
const checkout = join(root, "tasks/repair-moved/code/agency")
|
|
2198
|
-
await git([
|
|
2199
|
-
"-C",
|
|
2200
|
-
repository,
|
|
2201
|
-
"worktree",
|
|
2202
|
-
"add",
|
|
2203
|
-
oldPath,
|
|
2204
|
-
"task/repair-moved",
|
|
2205
|
-
])
|
|
2206
|
-
await mkdir(join(root, "tasks/repair-moved/code"), { recursive: true })
|
|
2207
|
-
await rename(oldPath, checkout)
|
|
2208
|
-
await Bun.write(join(checkout, "uncommitted.txt"), "keep me\n")
|
|
2209
|
-
|
|
2210
|
-
const repaired = await runTestEffect(
|
|
2211
|
-
WorktreeService.pipe(
|
|
2212
|
-
Effect.flatMap((service) =>
|
|
2213
|
-
service.repair("repair-moved", undefined, root),
|
|
2214
|
-
),
|
|
2215
|
-
),
|
|
2216
|
-
)
|
|
2217
|
-
expect(repaired.inspection.conflicts).toEqual([])
|
|
2218
|
-
expect(repaired.inspection.checkouts[0]).toMatchObject({
|
|
2219
|
-
actualBranch: "task/repair-moved",
|
|
2220
|
-
dirty: true,
|
|
2221
|
-
registered: true,
|
|
2222
|
-
})
|
|
2223
|
-
expect(await Bun.file(join(checkout, "uncommitted.txt")).text()).toBe(
|
|
2224
|
-
"keep me\n",
|
|
2225
|
-
)
|
|
2226
|
-
})
|
|
2227
|
-
|
|
2228
|
-
test("supports Worktrunk as the configured command", async () => {
|
|
2229
|
-
if (Bun.spawnSync(["which", "wt"], { stdout: "ignore" }).exitCode !== 0) {
|
|
2230
|
-
return
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
await Bun.write(
|
|
2234
|
-
join(root, "agency.json"),
|
|
2235
|
-
JSON.stringify({
|
|
2236
|
-
version: 2,
|
|
2237
|
-
worktreeCreateCommand: [
|
|
2238
|
-
"wt",
|
|
2239
|
-
"-C",
|
|
2240
|
-
"{repo}",
|
|
2241
|
-
"-y",
|
|
2242
|
-
"--config-set",
|
|
2243
|
-
'worktree-path="{worktree}"',
|
|
2244
|
-
"switch",
|
|
2245
|
-
"--create",
|
|
2246
|
-
"--base",
|
|
2247
|
-
"{base}",
|
|
2248
|
-
"{branch}",
|
|
2249
|
-
"--no-cd",
|
|
2250
|
-
"--format",
|
|
2251
|
-
"json",
|
|
2252
|
-
],
|
|
2253
|
-
}),
|
|
2254
|
-
)
|
|
2255
|
-
await runTestEffect(
|
|
2256
|
-
TaskService.pipe(
|
|
2257
|
-
Effect.flatMap((service) =>
|
|
2258
|
-
service.create(
|
|
2259
|
-
{
|
|
2260
|
-
id: "worktrunk",
|
|
2261
|
-
ticketUrl: "https://example.com/task",
|
|
2262
|
-
repo: "agency",
|
|
2263
|
-
branch: "task/worktrunk",
|
|
2264
|
-
base: "main",
|
|
2265
|
-
},
|
|
2266
|
-
root,
|
|
2267
|
-
),
|
|
2268
|
-
),
|
|
2269
|
-
),
|
|
2270
|
-
)
|
|
2271
|
-
|
|
2272
|
-
const workspace = await runTestEffect(
|
|
2273
|
-
WorktreeService.pipe(
|
|
2274
|
-
Effect.flatMap((service) =>
|
|
2275
|
-
service.materialize("worktrunk", undefined, root),
|
|
2276
|
-
),
|
|
2277
|
-
),
|
|
2278
|
-
)
|
|
2279
|
-
expect(
|
|
2280
|
-
await Bun.file(join(workspace.writablePath!, "README.md")).text(),
|
|
2281
|
-
).toBe("example\n")
|
|
2282
|
-
expect(
|
|
2283
|
-
await gitOutput(["status", "--porcelain"], workspace.writablePath!),
|
|
2284
|
-
).toBe("")
|
|
2285
|
-
expect(
|
|
2286
|
-
await gitOutput(
|
|
2287
|
-
["check-ignore", "--no-index", ".worktree.lock"],
|
|
2288
|
-
workspace.writablePath!,
|
|
2289
|
-
),
|
|
2290
|
-
).toBe(".worktree.lock")
|
|
2291
|
-
})
|
|
2292
|
-
})
|