• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trento-project / agent / 22064031548

16 Feb 2026 01:07PM UTC coverage: 75.429%. First build
22064031548

Pull #548

github

arbulu89
Import and copy operators code from workbench
Pull Request #548: Import and copy operators code from workbench

1917 of 2247 new or added lines in 18 files covered. (85.31%)

6950 of 9214 relevant lines covered (75.43%)

16.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.92
/internal/operations/operator/executor.go
1
package operator
2

3
import (
4
        "context"
5
        "errors"
6
        "log/slog"
7
)
8

9
type phaser interface {
10
        plan(ctx context.Context) (alreadyApplied bool, err error)
11
        commit(ctx context.Context) error
12
        rollback(ctx context.Context) error
13
        verify(ctx context.Context) error
14
        operationDiff(ctx context.Context) map[string]any
15
        after(ctx context.Context)
16
}
17

18
type Executor struct {
19
        currentPhase PhaseName
20
        phaser       phaser
21
        operationID  string
22
        logger       *slog.Logger
23
}
24

25
const (
26
        RUN     = "Executor.Run"
27
        BEGIN   = "BEGIN"
28
        SUCCESS = "SUCCESS"
29
        FAILURE = "FAILURE"
30
)
31

32
func NewExecutor(phaser phaser, operationID string, logger *slog.Logger) *Executor {
7✔
33
        if logger == nil {
7✔
NEW
34
                logger = slog.Default()
×
NEW
35
        }
×
36
        return &Executor{
7✔
37
                currentPhase: PLAN,
7✔
38
                phaser:       phaser,
7✔
39
                operationID:  operationID,
7✔
40
                logger:       logger,
7✔
41
        }
7✔
42
}
43

44
func (e *Executor) Run(ctx context.Context) *ExecutionReport {
173✔
45
        e.currentPhase = PLAN
173✔
46
        e.logger.Info(RUN, "phase", e.currentPhase, "event", BEGIN)
173✔
47
        alreadyApplied, err := e.phaser.plan(ctx)
173✔
48
        if err != nil {
222✔
49
                e.logger.Info(RUN, "phase", e.currentPhase, "event", FAILURE, "error", err)
49✔
50
                return executionReportWithError(err, e.currentPhase, e.operationID)
49✔
51
        }
49✔
52

53
        defer e.phaser.after(ctx)
124✔
54

124✔
55
        if alreadyApplied {
150✔
56
                diff := e.phaser.operationDiff(ctx)
26✔
57
                e.logger.Info(RUN, "phase", e.currentPhase, "event", SUCCESS, "diff", diff)
26✔
58
                return executionReportWithSuccess(diff, e.currentPhase, e.operationID)
26✔
59
        }
26✔
60
        e.logger.Info(RUN, "phase", e.currentPhase, "event", SUCCESS)
98✔
61

98✔
62
        e.currentPhase = COMMIT
98✔
63

98✔
64
        e.logger.Info(RUN, "phase", e.currentPhase, "event", BEGIN)
98✔
65
        err = e.phaser.commit(ctx)
98✔
66
        if err != nil {
131✔
67
                e.logger.Info(RUN, "phase", e.currentPhase, "event", FAILURE, "error", err)
33✔
68
                return e.handleRollback(ctx, err)
33✔
69
        }
33✔
70
        e.logger.Info(RUN, "phase", e.currentPhase, "event", SUCCESS)
65✔
71

65✔
72
        e.currentPhase = VERIFY
65✔
73
        e.logger.Info(RUN, "phase", e.currentPhase, "event", BEGIN)
65✔
74
        err = e.phaser.verify(ctx)
65✔
75
        if err != nil {
95✔
76
                e.logger.Info(RUN, "phase", e.currentPhase, "event", FAILURE, "error", err)
30✔
77
                return e.handleRollback(ctx, err)
30✔
78
        }
30✔
79

80
        diff := e.phaser.operationDiff(ctx)
35✔
81
        e.logger.Info(RUN, "phase", e.currentPhase, "event", SUCCESS, "diff", diff)
35✔
82

35✔
83
        return executionReportWithSuccess(diff, e.currentPhase, e.operationID)
35✔
84
}
85

86
func (e *Executor) handleRollback(ctx context.Context, err error) *ExecutionReport {
63✔
87
        e.logger.Info(RUN, "phase", ROLLBACK, "event", BEGIN)
63✔
88
        rollbackError := e.phaser.rollback(ctx)
63✔
89
        if rollbackError != nil {
91✔
90
                e.currentPhase = ROLLBACK
28✔
91
                e.logger.Info(RUN, "phase", e.currentPhase, "event", FAILURE, "error", rollbackError)
28✔
92
                return executionReportWithError(
28✔
93
                        wrapRollbackError(err, rollbackError),
28✔
94
                        e.currentPhase,
28✔
95
                        e.operationID,
28✔
96
                )
28✔
97
        }
28✔
98
        e.logger.Info(RUN, "phase", ROLLBACK, "event", SUCCESS)
35✔
99
        return executionReportWithError(err, e.currentPhase, e.operationID)
35✔
100
}
101

102
func wrapRollbackError(phaseError error, rollbackError error) error {
28✔
103
        return errors.Join(rollbackError, phaseError)
28✔
104
}
28✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc