@@ -10,32 +10,51 @@ import { CheckpointService } from "../CheckpointService"
1010
1111describe ( "CheckpointService" , ( ) => {
1212 const taskId = "test-task"
13+
1314 let git : SimpleGit
1415 let testFile : string
1516 let service : CheckpointService
1617
17- beforeEach ( async ( ) => {
18+ const initRepo = async ( {
19+ baseDir,
20+ userName = "Roo Code" ,
21+ 22+ testFileName = "test.txt" ,
23+ textFileContent = "Hello, world!" ,
24+ } : {
25+ baseDir : string
26+ userName ?: string
27+ userEmail ?: string
28+ testFileName ?: string
29+ textFileContent ?: string
30+ } ) => {
1831 // Create a temporary directory for testing.
19- const baseDir = path . join ( os . tmpdir ( ) , `checkpoint-service-test-${ Date . now ( ) } ` )
2032 await fs . mkdir ( baseDir )
2133
2234 // Initialize git repo.
23- git = simpleGit ( baseDir )
35+ const git = simpleGit ( baseDir )
2436 await git . init ( )
25- await git . addConfig ( "user.name" , "Roo Code" )
26- await git . addConfig ( "user.email" , "[email protected] " ) 37+ await git . addConfig ( "user.name" , userName )
38+ await git . addConfig ( "user.email" , userEmail )
2739
2840 // Create test file.
29- testFile = path . join ( baseDir , "test.txt" )
30- await fs . writeFile ( testFile , "Hello, world!" )
41+ const testFile = path . join ( baseDir , testFileName )
42+ await fs . writeFile ( testFile , textFileContent )
3143
3244 // Create initial commit.
3345 await git . add ( "." )
3446 await git . commit ( "Initial commit" ) !
3547
36- // Create service instance.
37- const log = ( ) => { }
38- service = await CheckpointService . create ( { taskId, git, baseDir, log } )
48+ return { git, testFile }
49+ }
50+
51+ beforeEach ( async ( ) => {
52+ const baseDir = path . join ( os . tmpdir ( ) , `checkpoint-service-test-${ Date . now ( ) } ` )
53+ const repo = await initRepo ( { baseDir } )
54+
55+ git = repo . git
56+ testFile = repo . testFile
57+ service = await CheckpointService . create ( { taskId, git, baseDir, log : ( ) => { } } )
3958 } )
4059
4160 afterEach ( async ( ) => {
@@ -333,5 +352,20 @@ describe("CheckpointService", () => {
333352
334353 await fs . rm ( newService . baseDir , { recursive : true , force : true } )
335354 } )
355+
356+ it ( "respects existing git user configuration" , async ( ) => {
357+ const baseDir = path . join ( os . tmpdir ( ) , `checkpoint-service-test-config2-${ Date . now ( ) } ` )
358+ const userName = "Custom User"
359+ const userEmail = "[email protected] " 360+ const repo = await initRepo ( { baseDir, userName, userEmail } )
361+ const newGit = repo . git
362+
363+ await CheckpointService . create ( { taskId, git : newGit , baseDir, log : ( ) => { } } )
364+
365+ expect ( ( await newGit . getConfig ( "user.name" ) ) . value ) . toBe ( userName )
366+ expect ( ( await newGit . getConfig ( "user.email" ) ) . value ) . toBe ( userEmail )
367+
368+ await fs . rm ( baseDir , { recursive : true , force : true } )
369+ } )
336370 } )
337371} )
0 commit comments