11import { $ } from "bun"
22import { afterEach , describe , expect , test } from "bun:test"
3+ import { Effect } from "effect"
34import fs from "fs/promises"
45import path from "path"
56import { tmpdir } from "../fixture/fixture"
@@ -20,8 +21,14 @@ async function withVcs(directory: string, body: () => Promise<void>) {
2021 return Instance . provide ( {
2122 directory,
2223 fn : async ( ) => {
23- void AppRuntime . runPromise ( FileWatcher . Service . use ( ( svc ) => svc . init ( ) ) )
24- Vcs . init ( )
24+ await AppRuntime . runPromise (
25+ Effect . gen ( function * ( ) {
26+ const watcher = yield * FileWatcher . Service
27+ const vcs = yield * Vcs . Service
28+ yield * watcher . init ( )
29+ yield * vcs . init ( )
30+ } ) ,
31+ )
2532 await Bun . sleep ( 500 )
2633 await body ( )
2734 } ,
@@ -32,7 +39,12 @@ function withVcsOnly(directory: string, body: () => Promise<void>) {
3239 return Instance . provide ( {
3340 directory,
3441 fn : async ( ) => {
35- Vcs . init ( )
42+ await AppRuntime . runPromise (
43+ Effect . gen ( function * ( ) {
44+ const vcs = yield * Vcs . Service
45+ yield * vcs . init ( )
46+ } ) ,
47+ )
3648 await body ( )
3749 } ,
3850 } )
@@ -80,7 +92,12 @@ describeVcs("Vcs", () => {
8092 await using tmp = await tmpdir ( { git : true } )
8193
8294 await withVcs ( tmp . path , async ( ) => {
83- const branch = await Vcs . branch ( )
95+ const branch = await AppRuntime . runPromise (
96+ Effect . gen ( function * ( ) {
97+ const vcs = yield * Vcs . Service
98+ return yield * vcs . branch ( )
99+ } ) ,
100+ )
84101 expect ( branch ) . toBeDefined ( )
85102 expect ( typeof branch ) . toBe ( "string" )
86103 } )
@@ -90,7 +107,12 @@ describeVcs("Vcs", () => {
90107 await using tmp = await tmpdir ( )
91108
92109 await withVcs ( tmp . path , async ( ) => {
93- const branch = await Vcs . branch ( )
110+ const branch = await AppRuntime . runPromise (
111+ Effect . gen ( function * ( ) {
112+ const vcs = yield * Vcs . Service
113+ return yield * vcs . branch ( )
114+ } ) ,
115+ )
94116 expect ( branch ) . toBeUndefined ( )
95117 } )
96118 } )
@@ -123,7 +145,12 @@ describeVcs("Vcs", () => {
123145 await fs . writeFile ( head , `ref: refs/heads/${ branch } \n` )
124146
125147 await pending
126- const current = await Vcs . branch ( )
148+ const current = await AppRuntime . runPromise (
149+ Effect . gen ( function * ( ) {
150+ const vcs = yield * Vcs . Service
151+ return yield * vcs . branch ( )
152+ } ) ,
153+ )
127154 expect ( current ) . toBe ( branch )
128155 } )
129156 } )
@@ -139,7 +166,12 @@ describe("Vcs diff", () => {
139166 await $ `git branch -M main` . cwd ( tmp . path ) . quiet ( )
140167
141168 await withVcsOnly ( tmp . path , async ( ) => {
142- const branch = await Vcs . defaultBranch ( )
169+ const branch = await AppRuntime . runPromise (
170+ Effect . gen ( function * ( ) {
171+ const vcs = yield * Vcs . Service
172+ return yield * vcs . defaultBranch ( )
173+ } ) ,
174+ )
143175 expect ( branch ) . toBe ( "main" )
144176 } )
145177 } )
@@ -150,7 +182,12 @@ describe("Vcs diff", () => {
150182 await $ `git config init.defaultBranch trunk` . cwd ( tmp . path ) . quiet ( )
151183
152184 await withVcsOnly ( tmp . path , async ( ) => {
153- const branch = await Vcs . defaultBranch ( )
185+ const branch = await AppRuntime . runPromise (
186+ Effect . gen ( function * ( ) {
187+ const vcs = yield * Vcs . Service
188+ return yield * vcs . defaultBranch ( )
189+ } ) ,
190+ )
154191 expect ( branch ) . toBe ( "trunk" )
155192 } )
156193 } )
@@ -163,7 +200,12 @@ describe("Vcs diff", () => {
163200 await $ `git worktree add -b feature/test ${ dir } HEAD` . cwd ( tmp . path ) . quiet ( )
164201
165202 await withVcsOnly ( dir , async ( ) => {
166- const [ branch , base ] = await Promise . all ( [ Vcs . branch ( ) , Vcs . defaultBranch ( ) ] )
203+ const [ branch , base ] = await AppRuntime . runPromise (
204+ Effect . gen ( function * ( ) {
205+ const vcs = yield * Vcs . Service
206+ return yield * Effect . all ( [ vcs . branch ( ) , vcs . defaultBranch ( ) ] , { concurrency : 2 } )
207+ } ) ,
208+ )
167209 expect ( branch ) . toBe ( "feature/test" )
168210 expect ( base ) . toBe ( "main" )
169211 } )
@@ -177,7 +219,12 @@ describe("Vcs diff", () => {
177219 await fs . writeFile ( path . join ( tmp . path , "file.txt" ) , "changed\n" , "utf-8" )
178220
179221 await withVcsOnly ( tmp . path , async ( ) => {
180- const diff = await Vcs . diff ( "git" )
222+ const diff = await AppRuntime . runPromise (
223+ Effect . gen ( function * ( ) {
224+ const vcs = yield * Vcs . Service
225+ return yield * vcs . diff ( "git" )
226+ } ) ,
227+ )
181228 expect ( diff ) . toEqual (
182229 expect . arrayContaining ( [
183230 expect . objectContaining ( {
@@ -194,7 +241,12 @@ describe("Vcs diff", () => {
194241 await fs . writeFile ( path . join ( tmp . path , weird ) , "hello\n" , "utf-8" )
195242
196243 await withVcsOnly ( tmp . path , async ( ) => {
197- const diff = await Vcs . diff ( "git" )
244+ const diff = await AppRuntime . runPromise (
245+ Effect . gen ( function * ( ) {
246+ const vcs = yield * Vcs . Service
247+ return yield * vcs . diff ( "git" )
248+ } ) ,
249+ )
198250 expect ( diff ) . toEqual (
199251 expect . arrayContaining ( [
200252 expect . objectContaining ( {
@@ -215,7 +267,12 @@ describe("Vcs diff", () => {
215267 await $ `git commit --no-gpg-sign -m "branch file"` . cwd ( tmp . path ) . quiet ( )
216268
217269 await withVcsOnly ( tmp . path , async ( ) => {
218- const diff = await Vcs . diff ( "branch" )
270+ const diff = await AppRuntime . runPromise (
271+ Effect . gen ( function * ( ) {
272+ const vcs = yield * Vcs . Service
273+ return yield * vcs . diff ( "branch" )
274+ } ) ,
275+ )
219276 expect ( diff ) . toEqual (
220277 expect . arrayContaining ( [
221278 expect . objectContaining ( {
0 commit comments