@@ -3757,6 +3757,93 @@ describe("workflow", () => {
37573757 }
37583758 } ) ;
37593759
3760+ it ( "creates first PR branches from the recorded patch base" , async ( ) => {
3761+ const root = await fixtureRoot ( "clawpatch-open-pr-recorded-base-" ) ;
3762+ await writeFixture (
3763+ root ,
3764+ "package.json" ,
3765+ JSON . stringify ( { name : "open-pr-recorded-base" , bin : { open : "src/index.ts" } } ) ,
3766+ ) ;
3767+ await writeFixture ( root , "src/index.ts" , "export const value = 'TODO_BUG';\n" ) ;
3768+ await initGit ( root ) ;
3769+ await checkCommand ( root , "git add package.json src/index.ts" ) ;
3770+ await checkCommand ( root , 'git -c commit.gpgsign=false commit -q -m "base"' ) ;
3771+ const baseSha = ( await runCommand ( "git rev-parse HEAD" , root ) ) . stdout . trim ( ) ;
3772+ const origin = await fixtureRoot ( "clawpatch-open-pr-recorded-base-origin-" ) ;
3773+ await checkCommand ( root , `git init --bare -q ${ origin } ` ) ;
3774+ await checkCommand ( root , `git remote add origin ${ origin } ` ) ;
3775+ const context = await makeContext ( testOptions ( root ) ) ;
3776+ const paths = statePaths ( join ( root , ".clawpatch" ) ) ;
3777+ await initCommand ( context , { } ) ;
3778+ await writeFixture ( root , "src/index.ts" , "export const value = 'fixed';\n" ) ;
3779+ await writeFixture ( root , "src/unrelated.ts" , "export const unrelated = true;\n" ) ;
3780+ await checkCommand ( root , "git add src/unrelated.ts" ) ;
3781+ await checkCommand ( root , 'git -c commit.gpgsign=false commit -q -m "unrelated"' ) ;
3782+ const advancedHead = ( await runCommand ( "git rev-parse HEAD" , root ) ) . stdout . trim ( ) ;
3783+ expect ( advancedHead ) . not . toBe ( baseSha ) ;
3784+ const now = new Date ( ) . toISOString ( ) ;
3785+ await writePatchAttempt ( paths , {
3786+ schemaVersion : 1 ,
3787+ patchAttemptId : "pat_open_pr_recorded_base" ,
3788+ findingIds : [ ] ,
3789+ featureIds : [ ] ,
3790+ status : "applied" ,
3791+ plan : "Replace the marker value." ,
3792+ filesChanged : [ "src/index.ts" ] ,
3793+ commandsRun : [ ] ,
3794+ testResults : [
3795+ {
3796+ command : "pnpm test" ,
3797+ cwd : root ,
3798+ exitCode : 0 ,
3799+ durationMs : 1 ,
3800+ stdout : "" ,
3801+ stderr : "" ,
3802+ } ,
3803+ ] ,
3804+ provider : null ,
3805+ git : {
3806+ baseSha,
3807+ commitSha : null ,
3808+ branchName : null ,
3809+ prUrl : null ,
3810+ } ,
3811+ createdAt : now ,
3812+ updatedAt : now ,
3813+ } ) ;
3814+ const ghScripts = await fixtureRoot ( "clawpatch-open-pr-recorded-base-gh-" ) ;
3815+ const successGh = join ( ghScripts , "success-gh.sh" ) ;
3816+ await writeFixture (
3817+ ghScripts ,
3818+ "success-gh.sh" ,
3819+ "#!/bin/sh\necho https://github.com/openclaw/clawpatch/pull/1005\n" ,
3820+ ) ;
3821+ await chmod ( successGh , 0o755 ) ;
3822+ const previousGh = process . env [ "CLAWPATCH_GH" ] ;
3823+ try {
3824+ process . env [ "CLAWPATCH_GH" ] = successGh ;
3825+ const opened = ( await openPrCommand ( context , {
3826+ patch : "pat_open_pr_recorded_base" ,
3827+ base : "main" ,
3828+ branch : "clawpatch/pat_open_pr_recorded_base" ,
3829+ } ) ) as { commit : string ; pr : string } ;
3830+ const parent = (
3831+ await runCommand ( `git show -s --format=%P ${ opened . commit } ` , root )
3832+ ) . stdout . trim ( ) ;
3833+ const committed = await runCommand ( `git show --name-only --format= ${ opened . commit } ` , root ) ;
3834+
3835+ expect ( opened . pr ) . toBe ( "https://github.com/openclaw/clawpatch/pull/1005" ) ;
3836+ expect ( parent ) . toBe ( baseSha ) ;
3837+ expect ( committed . stdout . trim ( ) . split ( "\n" ) ) . toEqual ( [ "src/index.ts" ] ) ;
3838+ } finally {
3839+ if ( previousGh === undefined ) {
3840+ delete process . env [ "CLAWPATCH_GH" ] ;
3841+ } else {
3842+ process . env [ "CLAWPATCH_GH" ] = previousGh ;
3843+ }
3844+ }
3845+ } ) ;
3846+
37603847 it ( "switches to an existing patch branch when opening a PR" , async ( ) => {
37613848 const root = await fixtureRoot ( "clawpatch-open-pr-existing-branch-" ) ;
37623849 await writeFixture (
0 commit comments