Skip to content

Commit

Permalink
[#674] Implement the introspective variant in tcr.revert()
Browse files Browse the repository at this point in the history
- add tcr.introspectiveRevert()
- inject call to introspectiveRevert() in tcr.revert()
- tune and pass test case on revert for introspective variant
  • Loading branch information
mengdaming committed Oct 1, 2024
1 parent ae5e4ce commit 156c29d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 25 additions & 1 deletion src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,11 @@ func (tcr *TCREngine) commit(event events.TCREvent) {
tcr.handleError(tcr.vcsPushAuto(), false, status.VCSError)
}

func (tcr *TCREngine) revert(_ events.TCREvent) {
func (tcr *TCREngine) revert(e events.TCREvent) {
if *tcr.variant == variant.Introspective {
_ = tcr.introspectiveRevert(e)
return
}
diffs, err := tcr.vcs.Diff()
tcr.handleError(err, false, status.VCSError)
if err != nil {
Expand All @@ -618,6 +622,26 @@ func (tcr *TCREngine) revert(_ events.TCREvent) {
}
}

func (tcr *TCREngine) introspectiveRevert(event events.TCREvent) (err error) {
// Commit changes with failure message into VCS index
err = tcr.vcs.Add()
if err != nil {
return err
}
err = tcr.vcs.Commit(false, tcr.wrapCommitMessages(commitMessageFail, &event)...)
if err != nil {
return err
}
// Rollback changes (both in VCS index and working tree)
err = tcr.vcs.RollbackLastCommit()
if err != nil {
return err
}
// Amend commit message on revert operation in VCS index
err = tcr.vcs.Commit(false, tcr.wrapCommitMessages(commitMessageRevert, nil)...)
return err
}

func (tcr *TCREngine) noFilesRevertedMessage() string {
if *tcr.variant == variant.Relaxed {
return "No file reverted (only test files were updated since last commit)"
Expand Down
8 changes: 6 additions & 2 deletions src/engine/tcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ func Test_variant_specific_reverts(t *testing.T) {
}

func Test_introspective_variant(t *testing.T) {
t.Skip("work in progress")
tcr, vcsFake := initTCREngineWithFakesWithFileDiffs(
params.AParamSet(params.WithVariant(variant.Introspective.Name())),
nil, nil, nil, vcs.FileDiffs{
Expand All @@ -321,7 +320,12 @@ func Test_introspective_variant(t *testing.T) {
})

tcr.revert(*events.ATcrEvent())
assert.Equal(t, []fake.Command{fake.CommitCommand, fake.RollbackLastCommitCommand}, vcsFake.GetLastCommands(2))
assert.Equal(t, []fake.Command{
fake.AddCommand,
fake.CommitCommand,
fake.RollbackLastCommitCommand,
fake.CommitCommand,
}, vcsFake.GetLastCommands(4))
}

func Test_tcr_cycle_end_state(t *testing.T) {
Expand Down

0 comments on commit 156c29d

Please sign in to comment.