Skip to content

Commit 3f74abc

Browse files
authored
test: simplify Effect migration follow-ups (anomalyco#27136)
1 parent e0d0fe1 commit 3f74abc

3 files changed

Lines changed: 31 additions & 43 deletions

File tree

packages/opencode/test/fixture/fixture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function tmpdirScoped(options?: { git?: boolean; config?: Partial<Config.
135135
yield* git("config", "commit.gpgsign", "false")
136136
yield* git("config", "user.email", "test@opencode.test")
137137
yield* git("config", "user.name", "Test")
138-
yield* git("commit", "--allow-empty", "-m", "root commit")
138+
yield* git("commit", "--allow-empty", "-m", `root commit ${dir}`)
139139
}
140140

141141
if (options?.config) {

packages/opencode/test/project/project.test.ts

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@ function run<A>(fn: (svc: Project.Interface) => Effect.Effect<A>) {
2828
})
2929
}
3030

31-
function gitTmpdir() {
32-
return Effect.gen(function* () {
33-
const tmp = yield* tmpdirScoped()
34-
yield* Effect.promise(() => $`git init`.cwd(tmp).quiet())
35-
yield* Effect.promise(() => $`git config core.fsmonitor false`.cwd(tmp).quiet())
36-
yield* Effect.promise(() => $`git config commit.gpgsign false`.cwd(tmp).quiet())
37-
yield* Effect.promise(() => $`git config user.email "test@opencode.test"`.cwd(tmp).quiet())
38-
yield* Effect.promise(() => $`git config user.name "Test"`.cwd(tmp).quiet())
39-
yield* Effect.promise(() => $`git commit --allow-empty -m ${`root commit ${tmp}`}`.cwd(tmp).quiet())
40-
return tmp
41-
})
42-
}
43-
4431
/**
4532
* Creates a mock ChildProcessSpawner layer that intercepts git subcommands
4633
* matching `failArg` and returns exit code 128, while delegating everything
@@ -108,7 +95,7 @@ describe("Project.fromDirectory", () => {
10895

10996
it.live("should handle git repository with commits", () =>
11097
Effect.gen(function* () {
111-
const tmp = yield* gitTmpdir()
98+
const tmp = yield* tmpdirScoped({ git: true })
11299

113100
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
114101

@@ -132,7 +119,7 @@ describe("Project.fromDirectory", () => {
132119

133120
it.live("derives stable project ID from root commit", () =>
134121
Effect.gen(function* () {
135-
const tmp = yield* gitTmpdir()
122+
const tmp = yield* tmpdirScoped({ git: true })
136123
const { project: a } = yield* run((svc) => svc.fromDirectory(tmp))
137124
const { project: b } = yield* run((svc) => svc.fromDirectory(tmp))
138125
expect(b.id).toBe(a.id)
@@ -156,7 +143,7 @@ describe("Project.fromDirectory git failure paths", () => {
156143

157144
failureIt("--show-toplevel").live("handles show-toplevel failure gracefully", () =>
158145
Effect.gen(function* () {
159-
const tmp = yield* gitTmpdir()
146+
const tmp = yield* tmpdirScoped({ git: true })
160147

161148
const { project, sandbox } = yield* run((svc) => svc.fromDirectory(tmp))
162149
expect(project.worktree).toBe(tmp)
@@ -166,7 +153,7 @@ describe("Project.fromDirectory git failure paths", () => {
166153

167154
failureIt("--git-common-dir").live("handles git-common-dir failure gracefully", () =>
168155
Effect.gen(function* () {
169-
const tmp = yield* gitTmpdir()
156+
const tmp = yield* tmpdirScoped({ git: true })
170157

171158
const { project, sandbox } = yield* run((svc) => svc.fromDirectory(tmp))
172159
expect(project.worktree).toBe(tmp)
@@ -178,7 +165,7 @@ describe("Project.fromDirectory git failure paths", () => {
178165
describe("Project.fromDirectory with worktrees", () => {
179166
it.live("should set worktree to root when called from root", () =>
180167
Effect.gen(function* () {
181-
const tmp = yield* gitTmpdir()
168+
const tmp = yield* tmpdirScoped({ git: true })
182169

183170
const { project, sandbox } = yield* run((svc) => svc.fromDirectory(tmp))
184171

@@ -190,7 +177,7 @@ describe("Project.fromDirectory with worktrees", () => {
190177

191178
it.live("should set worktree to root when called from a worktree", () =>
192179
Effect.gen(function* () {
193-
const tmp = yield* gitTmpdir()
180+
const tmp = yield* tmpdirScoped({ git: true })
194181

195182
const worktreePath = path.join(tmp, "..", path.basename(tmp) + "-worktree")
196183
yield* Effect.addFinalizer(() =>
@@ -214,7 +201,7 @@ describe("Project.fromDirectory with worktrees", () => {
214201

215202
it.live("worktree should share project ID with main repo", () =>
216203
Effect.gen(function* () {
217-
const tmp = yield* gitTmpdir()
204+
const tmp = yield* tmpdirScoped({ git: true })
218205

219206
const { project: main } = yield* run((svc) => svc.fromDirectory(tmp))
220207

@@ -242,7 +229,7 @@ describe("Project.fromDirectory with worktrees", () => {
242229

243230
it.live("separate clones of the same repo should share project ID", () =>
244231
Effect.gen(function* () {
245-
const tmp = yield* gitTmpdir()
232+
const tmp = yield* tmpdirScoped({ git: true })
246233

247234
// Create a bare remote, push, then clone into a second directory
248235
const bare = tmp + "-bare"
@@ -262,7 +249,7 @@ describe("Project.fromDirectory with worktrees", () => {
262249

263250
it.live("should accumulate multiple worktrees in sandboxes", () =>
264251
Effect.gen(function* () {
265-
const tmp = yield* gitTmpdir()
252+
const tmp = yield* tmpdirScoped({ git: true })
266253

267254
const worktree1 = path.join(tmp, "..", path.basename(tmp) + "-wt1")
268255
const worktree2 = path.join(tmp, "..", path.basename(tmp) + "-wt2")
@@ -299,7 +286,7 @@ describe("Project.fromDirectory with worktrees", () => {
299286
describe("Project.discover", () => {
300287
it.live("should discover favicon.png in root", () =>
301288
Effect.gen(function* () {
302-
const tmp = yield* gitTmpdir()
289+
const tmp = yield* tmpdirScoped({ git: true })
303290
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
304291

305292
const pngData = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
@@ -318,7 +305,7 @@ describe("Project.discover", () => {
318305

319306
it.live("should not discover non-image files", () =>
320307
Effect.gen(function* () {
321-
const tmp = yield* gitTmpdir()
308+
const tmp = yield* tmpdirScoped({ git: true })
322309
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
323310

324311
yield* Effect.promise(() => Bun.write(path.join(tmp, "favicon.txt"), "not an image"))
@@ -333,7 +320,7 @@ describe("Project.discover", () => {
333320

334321
it.live("should not discover favicon when override is set", () =>
335322
Effect.gen(function* () {
336-
const tmp = yield* gitTmpdir()
323+
const tmp = yield* tmpdirScoped({ git: true })
337324
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
338325

339326
yield* run((svc) =>
@@ -362,7 +349,7 @@ describe("Project.discover", () => {
362349
describe("Project.update", () => {
363350
it.live("should update name", () =>
364351
Effect.gen(function* () {
365-
const tmp = yield* gitTmpdir()
352+
const tmp = yield* tmpdirScoped({ git: true })
366353
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
367354

368355
const updated = yield* run((svc) =>
@@ -381,7 +368,7 @@ describe("Project.update", () => {
381368

382369
it.live("should update icon url", () =>
383370
Effect.gen(function* () {
384-
const tmp = yield* gitTmpdir()
371+
const tmp = yield* tmpdirScoped({ git: true })
385372
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
386373

387374
const updated = yield* run((svc) =>
@@ -400,7 +387,7 @@ describe("Project.update", () => {
400387

401388
it.live("should update icon color", () =>
402389
Effect.gen(function* () {
403-
const tmp = yield* gitTmpdir()
390+
const tmp = yield* tmpdirScoped({ git: true })
404391
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
405392

406393
const updated = yield* run((svc) =>
@@ -419,7 +406,7 @@ describe("Project.update", () => {
419406

420407
it.live("should update icon override", () =>
421408
Effect.gen(function* () {
422-
const tmp = yield* gitTmpdir()
409+
const tmp = yield* tmpdirScoped({ git: true })
423410
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
424411

425412
const updated = yield* run((svc) =>
@@ -438,7 +425,7 @@ describe("Project.update", () => {
438425

439426
it.live("should update commands", () =>
440427
Effect.gen(function* () {
441-
const tmp = yield* gitTmpdir()
428+
const tmp = yield* tmpdirScoped({ git: true })
442429
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
443430

444431
const updated = yield* run((svc) =>
@@ -475,7 +462,7 @@ describe("Project.update", () => {
475462

476463
it.live("should emit GlobalBus event on update", () =>
477464
Effect.gen(function* () {
478-
const tmp = yield* gitTmpdir()
465+
const tmp = yield* tmpdirScoped({ git: true })
479466
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
480467

481468
let eventPayload: any = null
@@ -495,7 +482,7 @@ describe("Project.update", () => {
495482

496483
it.live("should update multiple fields at once", () =>
497484
Effect.gen(function* () {
498-
const tmp = yield* gitTmpdir()
485+
const tmp = yield* tmpdirScoped({ git: true })
499486
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
500487

501488
const updated = yield* run((svc) =>
@@ -519,7 +506,7 @@ describe("Project.update", () => {
519506
describe("Project.list and Project.get", () => {
520507
it.live("list returns all projects", () =>
521508
Effect.gen(function* () {
522-
const tmp = yield* gitTmpdir()
509+
const tmp = yield* tmpdirScoped({ git: true })
523510
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
524511

525512
const all = Project.list()
@@ -530,7 +517,7 @@ describe("Project.list and Project.get", () => {
530517

531518
it.live("get returns project by id", () =>
532519
Effect.gen(function* () {
533-
const tmp = yield* gitTmpdir()
520+
const tmp = yield* tmpdirScoped({ git: true })
534521
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
535522

536523
const found = Project.get(project.id)
@@ -548,7 +535,7 @@ describe("Project.list and Project.get", () => {
548535
describe("Project.setInitialized", () => {
549536
it.live("sets time_initialized on project", () =>
550537
Effect.gen(function* () {
551-
const tmp = yield* gitTmpdir()
538+
const tmp = yield* tmpdirScoped({ git: true })
552539
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
553540

554541
expect(project.time.initialized).toBeUndefined()
@@ -564,7 +551,7 @@ describe("Project.setInitialized", () => {
564551
describe("Project.addSandbox and Project.removeSandbox", () => {
565552
it.live("addSandbox adds directory and removeSandbox removes it", () =>
566553
Effect.gen(function* () {
567-
const tmp = yield* gitTmpdir()
554+
const tmp = yield* tmpdirScoped({ git: true })
568555
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
569556
const sandboxDir = path.join(tmp, "sandbox-test")
570557

@@ -582,7 +569,7 @@ describe("Project.addSandbox and Project.removeSandbox", () => {
582569

583570
it.live("addSandbox emits GlobalBus event", () =>
584571
Effect.gen(function* () {
585-
const tmp = yield* gitTmpdir()
572+
const tmp = yield* tmpdirScoped({ git: true })
586573
const { project } = yield* run((svc) => svc.fromDirectory(tmp))
587574
const sandboxDir = path.join(tmp, "sandbox-event")
588575

@@ -601,7 +588,7 @@ describe("Project.addSandbox and Project.removeSandbox", () => {
601588
describe("Project.fromDirectory with bare repos", () => {
602589
it.live("worktree from bare repo should cache in bare repo, not parent", () =>
603590
Effect.gen(function* () {
604-
const tmp = yield* gitTmpdir()
591+
const tmp = yield* tmpdirScoped({ git: true })
605592

606593
const parentDir = path.dirname(tmp)
607594
const barePath = path.join(parentDir, `bare-${Date.now()}.git`)
@@ -628,8 +615,8 @@ describe("Project.fromDirectory with bare repos", () => {
628615

629616
it.live("different bare repos under same parent should not share project ID", () =>
630617
Effect.gen(function* () {
631-
const tmp1 = yield* gitTmpdir()
632-
const tmp2 = yield* gitTmpdir()
618+
const tmp1 = yield* tmpdirScoped({ git: true })
619+
const tmp2 = yield* tmpdirScoped({ git: true })
633620

634621
const parentDir = path.dirname(tmp1)
635622
const bareA = path.join(parentDir, `bare-a-${Date.now()}.git`)
@@ -664,7 +651,7 @@ describe("Project.fromDirectory with bare repos", () => {
664651

665652
it.live("bare repo without .git suffix is still detected via core.bare", () =>
666653
Effect.gen(function* () {
667-
const tmp = yield* gitTmpdir()
654+
const tmp = yield* tmpdirScoped({ git: true })
668655

669656
const parentDir = path.dirname(tmp)
670657
const barePath = path.join(parentDir, `bare-no-suffix-${Date.now()}`)

packages/opencode/test/question/question.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ it.live("pending question rejects on instance dispose", () =>
397397
}).pipe(provideInstance(dir), Effect.forkScoped)
398398

399399
expect(yield* waitForPending(1).pipe(provideInstance(dir))).toHaveLength(1)
400-
yield* Effect.promise(() => InstanceRuntime.disposeInstance(Instance.current)).pipe(provideInstance(dir))
400+
const ctx = yield* Effect.sync(() => Instance.current).pipe(provideInstance(dir))
401+
yield* Effect.promise(() => InstanceRuntime.disposeInstance(ctx))
401402

402403
const exit = yield* Fiber.await(fiber)
403404
expect(Exit.isFailure(exit)).toBe(true)

0 commit comments

Comments
 (0)