From 7013af28d4996b6efef36a871d0b54541fceb4b5 Mon Sep 17 00:00:00 2001 From: manjari Date: Wed, 25 Feb 2026 01:08:56 +0000 Subject: [PATCH 1/3] feat(entities) Update batch state enum with more states --- entity/BUILD.bazel | 1 + entity/batch.go | 26 +++++++++++++++++++++++++- entity/batch_test.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 entity/batch_test.go diff --git a/entity/BUILD.bazel b/entity/BUILD.bazel index 98ed2138..14bca346 100644 --- a/entity/BUILD.bazel +++ b/entity/BUILD.bazel @@ -18,6 +18,7 @@ go_library( go_test( name = "entity_test", srcs = [ + "batch_test.go", "build_test.go", "queue_config_test.go", "request_test.go", diff --git a/entity/batch.go b/entity/batch.go index 91e102aa..78aa9412 100644 --- a/entity/batch.go +++ b/entity/batch.go @@ -6,9 +6,33 @@ type BatchState string const ( // BatchStateUnknown is the unreachable state. It is set by default when the structure is initialized. It should never be seen in the system. BatchStateUnknown BatchState = "" - // TODO: Add comprehensive list of known batch states. + // BatchStateScheduled is the state of a batch that has been scheduled for processing. + BatchStateScheduled BatchState = "scheduled" + // BatchStateSpeculating is the state of a batch that is undergoing speculative execution. + BatchStateSpeculating BatchState = "speculating" + // BatchStateFinalizing is the state of a batch that is being finalized after speculative execution. + BatchStateFinalizing BatchState = "finalizing" + // BatchStateSucceeded is the terminal state of a batch that has been successfully landed. + BatchStateSucceeded BatchState = "succeeded" + // BatchStateFailed is the terminal state of a batch that has failed to land. + BatchStateFailed BatchState = "failed" + // BatchStateCancelled is the terminal state of a batch that was cancelled before completion. + BatchStateCancelled BatchState = "cancelled" + // BatchStateCancellationFailed is the terminal state of a batch whose cancellation process itself failed. + BatchStateCancellationFailed BatchState = "cancellationfailed" ) +// IsTerminal returns true if the batch state is a terminal state. +// Terminal states are states from which no further transitions are possible. +func (s BatchState) IsTerminal() bool { + switch s { + case BatchStateSucceeded, BatchStateFailed, BatchStateCancelled, BatchStateCancellationFailed: + return true + default: + return false + } +} + // Batch represents a group of requests to land (merge into target branch of the source control repository). type Batch struct { // ID is the globally unique identifier for the batch. Format: "/batch/". diff --git a/entity/batch_test.go b/entity/batch_test.go new file mode 100644 index 00000000..d905ca06 --- /dev/null +++ b/entity/batch_test.go @@ -0,0 +1,31 @@ +package entity + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBatchState_IsTerminal(t *testing.T) { + tests := []struct { + name string + state BatchState + terminal bool + }{ + {name: "unknown", state: BatchStateUnknown, terminal: false}, + {name: "scheduled", state: BatchStateScheduled, terminal: false}, + {name: "speculating", state: BatchStateSpeculating, terminal: false}, + {name: "finalizing", state: BatchStateFinalizing, terminal: false}, + {name: "succeeded", state: BatchStateSucceeded, terminal: true}, + {name: "failed", state: BatchStateFailed, terminal: true}, + {name: "cancelled", state: BatchStateCancelled, terminal: true}, + {name: "cancellationfailed", state: BatchStateCancellationFailed, terminal: true}, + {name: "arbitrary string", state: BatchState("something_else"), terminal: false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.terminal, tt.state.IsTerminal()) + }) + } +} From 92e542ba0fc426c763df7dccb0aa229d81fdc95e Mon Sep 17 00:00:00 2001 From: manjari Date: Wed, 25 Feb 2026 01:37:22 +0000 Subject: [PATCH 2/3] remove cancellationfailed state as it is not required --- entity/batch.go | 4 +--- entity/batch_test.go | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/entity/batch.go b/entity/batch.go index 78aa9412..762f8edb 100644 --- a/entity/batch.go +++ b/entity/batch.go @@ -18,15 +18,13 @@ const ( BatchStateFailed BatchState = "failed" // BatchStateCancelled is the terminal state of a batch that was cancelled before completion. BatchStateCancelled BatchState = "cancelled" - // BatchStateCancellationFailed is the terminal state of a batch whose cancellation process itself failed. - BatchStateCancellationFailed BatchState = "cancellationfailed" ) // IsTerminal returns true if the batch state is a terminal state. // Terminal states are states from which no further transitions are possible. func (s BatchState) IsTerminal() bool { switch s { - case BatchStateSucceeded, BatchStateFailed, BatchStateCancelled, BatchStateCancellationFailed: + case BatchStateSucceeded, BatchStateFailed, BatchStateCancelled: return true default: return false diff --git a/entity/batch_test.go b/entity/batch_test.go index d905ca06..0a923903 100644 --- a/entity/batch_test.go +++ b/entity/batch_test.go @@ -19,7 +19,6 @@ func TestBatchState_IsTerminal(t *testing.T) { {name: "succeeded", state: BatchStateSucceeded, terminal: true}, {name: "failed", state: BatchStateFailed, terminal: true}, {name: "cancelled", state: BatchStateCancelled, terminal: true}, - {name: "cancellationfailed", state: BatchStateCancellationFailed, terminal: true}, {name: "arbitrary string", state: BatchState("something_else"), terminal: false}, } From d642d78eb7d3df2a5dba8e6521b831778ff0cac6 Mon Sep 17 00:00:00 2001 From: manjari Date: Wed, 25 Feb 2026 17:31:24 +0000 Subject: [PATCH 3/3] update statename and comment --- entity/batch.go | 6 +++--- entity/batch_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/entity/batch.go b/entity/batch.go index 762f8edb..fbe155c7 100644 --- a/entity/batch.go +++ b/entity/batch.go @@ -6,15 +6,15 @@ type BatchState string const ( // BatchStateUnknown is the unreachable state. It is set by default when the structure is initialized. It should never be seen in the system. BatchStateUnknown BatchState = "" - // BatchStateScheduled is the state of a batch that has been scheduled for processing. - BatchStateScheduled BatchState = "scheduled" + // BatchStateCreated is the state of a batch that has been created for processing. + BatchStateCreated BatchState = "created" // BatchStateSpeculating is the state of a batch that is undergoing speculative execution. BatchStateSpeculating BatchState = "speculating" // BatchStateFinalizing is the state of a batch that is being finalized after speculative execution. BatchStateFinalizing BatchState = "finalizing" // BatchStateSucceeded is the terminal state of a batch that has been successfully landed. BatchStateSucceeded BatchState = "succeeded" - // BatchStateFailed is the terminal state of a batch that has failed to land. + // BatchStateFailed is the terminal state of a batch that has failed. BatchStateFailed BatchState = "failed" // BatchStateCancelled is the terminal state of a batch that was cancelled before completion. BatchStateCancelled BatchState = "cancelled" diff --git a/entity/batch_test.go b/entity/batch_test.go index 0a923903..084e4b21 100644 --- a/entity/batch_test.go +++ b/entity/batch_test.go @@ -13,7 +13,7 @@ func TestBatchState_IsTerminal(t *testing.T) { terminal bool }{ {name: "unknown", state: BatchStateUnknown, terminal: false}, - {name: "scheduled", state: BatchStateScheduled, terminal: false}, + {name: "created", state: BatchStateCreated, terminal: false}, {name: "speculating", state: BatchStateSpeculating, terminal: false}, {name: "finalizing", state: BatchStateFinalizing, terminal: false}, {name: "succeeded", state: BatchStateSucceeded, terminal: true},