@@ -324,6 +324,42 @@ func TestRunGitHistoryReport_BasePathUsesRevisionScopedSiblingRefs(t *testing.T)
324324 assert .Contains (t , content , `"path":"$.paths['/thing'].get.responses['200'].content['application/json'].schema"` )
325325}
326326
327+ func TestRunGitHistoryReport_LimitOneComparesAgainstParent (t * testing.T ) {
328+ repoDir := createGitSpecRepoForFile (t , "openapi.yaml" )
329+
330+ report , err := runGitHistoryReport (repoDir , "openapi.yaml" , summaryOpts {
331+ base : repoDir ,
332+ noColor : true ,
333+ limit : 1 ,
334+ limitTime : - 1 ,
335+ }, nil )
336+
337+ require .NoError (t , err )
338+ require .NotNil (t , report )
339+ require .Len (t , report .Reports , 1 )
340+ assert .Equal (t , gitOutputInDir (t , repoDir , "rev-parse" , "--short" , "HEAD" ), report .Reports [0 ].Commit .Hash )
341+ assert .NotEmpty (t , report .Reports [0 ].Changes )
342+ }
343+
344+ func TestRunGitHistoryReport_BaseCommitUsesExcludedParentAsBaseline (t * testing.T ) {
345+ repoDir := createGitSpecRepoForFile (t , "openapi.yaml" )
346+ baseCommit := gitOutputInDir (t , repoDir , "rev-parse" , "--short" , "HEAD~2" )
347+
348+ report , err := runGitHistoryReport (repoDir , "openapi.yaml" , summaryOpts {
349+ base : repoDir ,
350+ baseCommit : baseCommit ,
351+ noColor : true ,
352+ limitTime : - 1 ,
353+ }, nil )
354+
355+ require .NoError (t , err )
356+ require .NotNil (t , report )
357+ require .Len (t , report .Reports , 2 )
358+ assert .Equal (t , gitOutputInDir (t , repoDir , "rev-parse" , "--short" , "HEAD" ), report .Reports [0 ].Commit .Hash )
359+ assert .Equal (t , gitOutputInDir (t , repoDir , "rev-parse" , "--short" , "HEAD~1" ), report .Reports [1 ].Commit .Hash )
360+ assert .NotEmpty (t , report .Reports [1 ].Changes )
361+ }
362+
327363func TestRunGitHistoryReport_PartialHistoryIncludesMetaData (t * testing.T ) {
328364 fixture := testutil .CreateInvalidHistoryGitSpecRepo (t )
329365
@@ -343,6 +379,23 @@ func TestRunGitHistoryReport_PartialHistoryIncludesMetaData(t *testing.T) {
343379 assert .Contains (t , string (encoded ), fixture .InvalidHash )
344380}
345381
382+ func TestRunGitHistoryReport_PartialHistoryWithoutChangesReturnsEmptyPartialReport (t * testing.T ) {
383+ fixture := testutil .CreateRevertedHistoryGitSpecRepo (t )
384+
385+ report , err := runGitHistoryReport (fixture .RepoDir , fixture .FileName , summaryOpts {
386+ base : fixture .RepoDir ,
387+ noColor : true ,
388+ limitTime : - 1 ,
389+ }, nil )
390+
391+ require .NoError (t , err )
392+ require .NotNil (t , report )
393+ assert .Empty (t , report .Reports )
394+ require .NotNil (t , report .MetaData )
395+ assert .True (t , report .MetaData .Partial )
396+ assert .Equal (t , []string {fixture .InvalidHash }, report .MetaData .SkippedCommits )
397+ }
398+
346399func TestRunGitHistoryReport_AllInvalidHistoryFails (t * testing.T ) {
347400 repoDir := t .TempDir ()
348401 runGitInDir (t , repoDir , "init" )
@@ -412,6 +465,44 @@ paths:
412465 assert .Equal (t , []string {"bbb222" }, report .MetaData .SkippedCommits )
413466}
414467
468+ func TestRunGithubHistoryReport_PartialHistoryWithoutChangesReturnsEmptyPartialReport (t * testing.T ) {
469+ originalProcess := processGithubRepoDetailed
470+ t .Cleanup (func () {
471+ processGithubRepoDetailed = originalProcess
472+ })
473+
474+ processGithubRepoDetailed = func (username , repo , filePath string ,
475+ progressChan chan * model.ProgressUpdate , errorChan chan model.ProgressError ,
476+ opts git.HistoryOptions , breakingConfig * whatChangedModel.BreakingRulesConfig ,
477+ ) (* git.HistoryBuildResult , []error ) {
478+ return & git.HistoryBuildResult {
479+ Commits : []* model.Commit {
480+ mustMakeDoctorOnlyCommitFromSpecs (t , "ccc333" , `openapi: 3.0.3
481+ info:
482+ title: test
483+ version: "1.0.0"
484+ paths: {}
485+ ` , `openapi: 3.0.3
486+ info:
487+ title: test
488+ version: "1.0.0"
489+ paths: {}
490+ ` ),
491+ },
492+ SkippedCommits : []string {"bbb222" },
493+ }, nil
494+ }
495+
496+ report , err := runGithubHistoryReport ("https://github.com/oai/openapi-specification/blob/main/examples/v3.0/petstore.yaml" , summaryOpts {}, nil )
497+
498+ require .NoError (t , err )
499+ require .NotNil (t , report )
500+ assert .Empty (t , report .Reports )
501+ require .NotNil (t , report .MetaData )
502+ assert .True (t , report .MetaData .Partial )
503+ assert .Equal (t , []string {"bbb222" }, report .MetaData .SkippedCommits )
504+ }
505+
415506func TestReportCommand_GitRefUsesLeftRightMode (t * testing.T ) {
416507 wd , err := os .Getwd ()
417508 require .NoError (t , err )
0 commit comments