@@ -933,6 +933,38 @@ describe('workers/repository/update/branch/index', () => {
933933 expect ( prWorker . ensurePr ) . toHaveBeenCalledTimes ( 0 ) ;
934934 } ) ;
935935
936+ it ( 'updates branch when forceRebase=true' , async ( ) => {
937+ expect . assertions ( 3 ) ;
938+ getUpdated . getUpdatedPackageFiles . mockResolvedValueOnce (
939+ partial < PackageFilesResult > ( {
940+ updatedPackageFiles : [ partial < FileChange > ( ) ] ,
941+ } ) ,
942+ ) ;
943+ npmPostExtract . getAdditionalFiles . mockResolvedValueOnce ( {
944+ artifactErrors : [ ] ,
945+ updatedArtifacts : [ partial < FileChange > ( ) ] ,
946+ } ) ;
947+ const inconfig = {
948+ ...config ,
949+ ignoreTests : true ,
950+ prCreation : 'not-pending' ,
951+ commitBody : '[skip-ci]' ,
952+ fetchChangeLogs : 'branch' ,
953+ cacheFingerprintMatch : 'no-match' ,
954+ } satisfies BranchConfig ;
955+ scm . getBranchCommit . mockResolvedValue ( '123test' as LongCommitSha ) ; //TODO:not needed?
956+ expect ( await branchWorker . processBranch ( inconfig , true ) ) . toEqual ( {
957+ branchExists : true ,
958+ updatesVerified : true ,
959+ prNo : undefined ,
960+ result : 'pending' ,
961+ commitSha : '123test' ,
962+ } ) ;
963+
964+ expect ( automerge . tryBranchAutomerge ) . toHaveBeenCalledTimes ( 0 ) ;
965+ expect ( prWorker . ensurePr ) . toHaveBeenCalledTimes ( 0 ) ;
966+ } ) ;
967+
936968 it ( 'ensures PR and comments notice' , async ( ) => {
937969 getUpdated . getUpdatedPackageFiles . mockResolvedValueOnce (
938970 partial < PackageFilesResult > ( {
@@ -1350,6 +1382,79 @@ describe('workers/repository/update/branch/index', () => {
13501382 expect ( prWorker . ensurePr ) . toHaveBeenCalledTimes ( 1 ) ;
13511383 } ) ;
13521384
1385+ it ( 'rebases branch onto new basebranch if no fingerprint found' , async ( ) => {
1386+ const updatedPackageFile : FileChange = {
1387+ type : 'addition' ,
1388+ path : 'pom.xml' ,
1389+ contents : 'pom.xml file contents' ,
1390+ } ;
1391+ const pr = partial < Pr > ( {
1392+ state : 'open' ,
1393+ targetBranch : 'old_base' ,
1394+ bodyStruct : partial < PrBodyStruct > ( {
1395+ debugData : partial < PrDebugData > ( { targetBranch : 'old_base' } ) ,
1396+ } ) ,
1397+ } ) ;
1398+ getUpdated . getUpdatedPackageFiles . mockResolvedValue (
1399+ partial < PackageFilesResult > ( {
1400+ updatedPackageFiles : [ updatedPackageFile ] ,
1401+ } ) ,
1402+ ) ;
1403+ npmPostExtract . getAdditionalFiles . mockResolvedValue ( {
1404+ artifactErrors : [ partial < ArtifactError > ( ) ] ,
1405+ updatedArtifacts : [ partial < FileChange > ( ) ] ,
1406+ } ) ;
1407+ scm . branchExists . mockResolvedValue ( true ) ;
1408+ commit . commitFilesToBranch . mockResolvedValueOnce ( null ) ;
1409+ platform . getBranchPr . mockResolvedValue ( pr ) ;
1410+ await branchWorker . processBranch ( {
1411+ ...config ,
1412+ baseBranch : 'old_base' ,
1413+ reuseExistingBranch : true ,
1414+ cacheFingerprintMatch : 'no-fingerprint' ,
1415+ } ) ;
1416+ expect ( logger . debug ) . toHaveBeenCalledWith (
1417+ 'Existing branch needs updating. Restarting processBranch() with a clean branch' ,
1418+ ) ;
1419+ expect ( commit . commitFilesToBranch ) . toHaveBeenCalled ( ) ;
1420+ expect ( prWorker . ensurePr ) . toHaveBeenCalledTimes ( 1 ) ;
1421+ } ) ;
1422+
1423+ // for coverage
1424+ it ( 'rebases branch onto new basebranch if no fingerprint found - 2' , async ( ) => {
1425+ const pr = partial < Pr > ( {
1426+ state : 'open' ,
1427+ targetBranch : 'old_base' ,
1428+ bodyStruct : partial < PrBodyStruct > ( {
1429+ debugData : partial < PrDebugData > ( { targetBranch : 'old_base' } ) ,
1430+ } ) ,
1431+ } ) ;
1432+ getUpdated . getUpdatedPackageFiles . mockResolvedValue (
1433+ partial < PackageFilesResult > ( {
1434+ updatedPackageFiles : [ ] ,
1435+ } ) ,
1436+ ) ;
1437+ npmPostExtract . getAdditionalFiles . mockResolvedValue ( {
1438+ artifactErrors : [ partial < ArtifactError > ( ) ] ,
1439+ updatedArtifacts : [ partial < FileChange > ( ) ] ,
1440+ } ) ;
1441+ scm . branchExists . mockResolvedValue ( true ) ;
1442+ commit . commitFilesToBranch . mockResolvedValueOnce ( null ) ;
1443+ platform . getBranchPr . mockResolvedValue ( pr ) ;
1444+ await branchWorker . processBranch ( {
1445+ ...config ,
1446+ baseBranch : 'old_base' ,
1447+ reuseExistingBranch : true ,
1448+ updatedArtifacts : [ { type : 'deletion' , path : 'dummy' } ] ,
1449+ cacheFingerprintMatch : 'no-fingerprint' ,
1450+ } ) ;
1451+ expect ( logger . debug ) . toHaveBeenCalledWith (
1452+ 'Existing branch needs updating. Restarting processBranch() with a clean branch' ,
1453+ ) ;
1454+ expect ( commit . commitFilesToBranch ) . toHaveBeenCalled ( ) ;
1455+ expect ( prWorker . ensurePr ) . toHaveBeenCalledTimes ( 1 ) ;
1456+ } ) ;
1457+
13531458 it ( 'swallows pr errors' , async ( ) => {
13541459 getUpdated . getUpdatedPackageFiles . mockResolvedValueOnce (
13551460 partial < PackageFilesResult > ( {
0 commit comments