Skip to content

Commit e9bd2c5

Browse files
authored
refactor(stovepipe): retire entity JSON queue serializers (CODEM-306) (#515)
## Summary - Remove unused `ToBytes`/`FromBytes` helpers from `stovepipe/entity/request.go` and `stovepipe/entity/build.go`, including the dead `RequestID` wrapper type - Update `BuildID` docs to describe its BuildRunner role only (no queue serialization) - Drop the entity serialization unit tests; queue wire format is already covered by `stovepipe/core/messagequeue` proto contract tests Closes #357 All stovepipe queue topics already use proto contracts (`ProcessRequest`, `BuildRequest`, `BuildSignal`, `Record`); this removes the misleading entity JSON helpers that could steer new stages toward the wrong pattern. ## Test plan - [x] `bazel test //stovepipe/entity/... //stovepipe/core/messagequeue/...` - [x] CI green
1 parent d90bee3 commit e9bd2c5

4 files changed

Lines changed: 2 additions & 214 deletions

File tree

stovepipe/entity/build.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package entity
1616

17-
import "encoding/json"
18-
1917
// BuildStatus defines the possible states of a build. Shaped the same as
2018
// SubmitQueue's own BuildStatus (submitqueue/entity/build.go), but defined
2119
// locally rather than shared — see build.md's "Alternatives considered for
@@ -74,38 +72,13 @@ type Build struct {
7472
Version int32 `json:"version"`
7573
}
7674

77-
// ToBytes serializes the Build to JSON bytes for queue message payload.
78-
func (b Build) ToBytes() ([]byte, error) {
79-
return json.Marshal(b)
80-
}
81-
82-
// BuildFromBytes deserializes a Build from JSON bytes.
83-
func BuildFromBytes(data []byte) (Build, error) {
84-
var build Build
85-
err := json.Unmarshal(data, &build)
86-
return build, err
87-
}
88-
89-
// BuildID is a lightweight entity for publishing and consuming just the
90-
// build identifier via the queue, and for the BuildRunner Status/Cancel
91-
// parameter. It wraps the one runner-assigned id everywhere it appears.
75+
// BuildID wraps the runner-assigned build identifier for BuildRunner
76+
// Status/Cancel/Trigger parameters.
9277
type BuildID struct {
9378
// ID is the runner-assigned identifier for the build.
9479
ID string `json:"id"`
9580
}
9681

97-
// ToBytes serializes the BuildID to JSON bytes for queue message payload.
98-
func (b BuildID) ToBytes() ([]byte, error) {
99-
return json.Marshal(b)
100-
}
101-
102-
// BuildIDFromBytes deserializes a BuildID from JSON bytes.
103-
func BuildIDFromBytes(data []byte) (BuildID, error) {
104-
var bid BuildID
105-
err := json.Unmarshal(data, &bid)
106-
return bid, err
107-
}
108-
10982
// BuildMetadata carries caller-supplied, provider-echoed free-form metadata
11083
// about a build. The runner must not depend on its contents. Empty today;
11184
// expected to carry real data eventually (e.g. conflict-graph info, or other

stovepipe/entity/build_test.go

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/assert"
21-
"github.com/stretchr/testify/require"
2221
)
2322

2423
func TestBuildStatus_IsTerminal(t *testing.T) {
@@ -41,82 +40,3 @@ func TestBuildStatus_IsTerminal(t *testing.T) {
4140
})
4241
}
4342
}
44-
45-
func TestBuild_SerializationRoundTrip(t *testing.T) {
46-
tests := []struct {
47-
name string
48-
build Build
49-
}{
50-
{
51-
name: "accepted incremental build",
52-
build: Build{
53-
ID: "bk-1001",
54-
RequestID: "request/monorepo/main/42",
55-
Status: BuildStatusAccepted,
56-
Version: 1,
57-
},
58-
},
59-
{
60-
name: "succeeded full build with no baseline",
61-
build: Build{
62-
ID: "bk-1002",
63-
RequestID: "request/monorepo/main/43",
64-
Status: BuildStatusSucceeded,
65-
Version: 3,
66-
},
67-
},
68-
{
69-
name: "failed build",
70-
build: Build{
71-
ID: "bk-1003",
72-
RequestID: "request/monorepo/main/44",
73-
Status: BuildStatusFailed,
74-
Version: 2,
75-
},
76-
},
77-
}
78-
79-
for _, tt := range tests {
80-
t.Run(tt.name, func(t *testing.T) {
81-
data, err := tt.build.ToBytes()
82-
require.NoError(t, err)
83-
84-
deserialized, err := BuildFromBytes(data)
85-
require.NoError(t, err)
86-
87-
assert.Equal(t, tt.build, deserialized)
88-
})
89-
}
90-
}
91-
92-
func TestBuildFromBytes_InvalidJSON(t *testing.T) {
93-
_, err := BuildFromBytes([]byte(`{"invalid": json"}`))
94-
assert.Error(t, err)
95-
}
96-
97-
func TestBuildFromBytes_EmptyData(t *testing.T) {
98-
build, err := BuildFromBytes([]byte(`{}`))
99-
require.NoError(t, err)
100-
101-
assert.Empty(t, build.ID)
102-
assert.Empty(t, build.RequestID)
103-
assert.Equal(t, BuildStatusUnknown, build.Status)
104-
assert.Equal(t, int32(0), build.Version)
105-
}
106-
107-
func TestBuildID_SerializationRoundTrip(t *testing.T) {
108-
original := BuildID{ID: "bk-1001"}
109-
110-
data, err := original.ToBytes()
111-
require.NoError(t, err)
112-
113-
deserialized, err := BuildIDFromBytes(data)
114-
require.NoError(t, err)
115-
116-
assert.Equal(t, original, deserialized)
117-
}
118-
119-
func TestBuildIDFromBytes_InvalidJSON(t *testing.T) {
120-
_, err := BuildIDFromBytes([]byte(`{"invalid": json"}`))
121-
assert.Error(t, err)
122-
}

stovepipe/entity/request.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
package entity
1616

17-
import (
18-
"encoding/json"
19-
)
20-
2117
// RequestState defines the internal state of a Stovepipe validation request as it moves
2218
// through the pipeline. States are internal and used to implement a state machine; a
2319
// customer-facing status type may be layered on top later, as in SubmitQueue.
@@ -124,33 +120,3 @@ type Request struct {
124120
// Versioning starts at 1 and is incremented for each change to the object.
125121
Version int32 `json:"version"`
126122
}
127-
128-
// ToBytes serializes the Request to JSON bytes for queue message payload.
129-
func (r Request) ToBytes() ([]byte, error) {
130-
return json.Marshal(r)
131-
}
132-
133-
// RequestFromBytes deserializes a Request from JSON bytes.
134-
func RequestFromBytes(data []byte) (Request, error) {
135-
var req Request
136-
err := json.Unmarshal(data, &req)
137-
return req, err
138-
}
139-
140-
// RequestID is a lightweight entity for publishing and consuming just the request identifier via the queue.
141-
type RequestID struct {
142-
// ID is the globally unique identifier for the request.
143-
ID string `json:"id"`
144-
}
145-
146-
// ToBytes serializes the RequestID to JSON bytes for queue message payload.
147-
func (r RequestID) ToBytes() ([]byte, error) {
148-
return json.Marshal(r)
149-
}
150-
151-
// RequestIDFromBytes deserializes a RequestID from JSON bytes.
152-
func RequestIDFromBytes(data []byte) (RequestID, error) {
153-
var rid RequestID
154-
err := json.Unmarshal(data, &rid)
155-
return rid, err
156-
}

stovepipe/entity/request_test.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,8 @@ import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/assert"
21-
"github.com/stretchr/testify/require"
2221
)
2322

24-
func TestRequest_SerializationRoundTrip(t *testing.T) {
25-
tests := []struct {
26-
name string
27-
req Request
28-
}{
29-
{
30-
name: "accepted with resolved uri",
31-
req: Request{
32-
ID: "request/monorepo/main/100",
33-
Queue: "monorepo/main",
34-
URI: "git://remote/monorepo/main/abcdef0123456789",
35-
State: RequestStateAccepted,
36-
Version: 1,
37-
},
38-
},
39-
{
40-
name: "processing with strategy and baseline",
41-
req: Request{
42-
ID: "request/monorepo/main/101",
43-
Queue: "monorepo/main",
44-
URI: "git://remote/monorepo/main/bbbb2222",
45-
State: RequestStateProcessing,
46-
BuildStrategy: BuildStrategyIncrementalSinceGreen,
47-
BaseURI: "git://remote/monorepo/main/green-aaaa",
48-
Version: 2,
49-
},
50-
},
51-
}
52-
53-
for _, tt := range tests {
54-
t.Run(tt.name, func(t *testing.T) {
55-
data, err := tt.req.ToBytes()
56-
require.NoError(t, err)
57-
58-
deserialized, err := RequestFromBytes(data)
59-
require.NoError(t, err)
60-
61-
assert.Equal(t, tt.req, deserialized)
62-
})
63-
}
64-
}
65-
66-
func TestRequestFromBytes_InvalidJSON(t *testing.T) {
67-
_, err := RequestFromBytes([]byte(`{"invalid": json"}`))
68-
assert.Error(t, err)
69-
}
70-
71-
func TestRequestFromBytes_EmptyData(t *testing.T) {
72-
req, err := RequestFromBytes([]byte(`{}`))
73-
require.NoError(t, err)
74-
75-
assert.Empty(t, req.ID)
76-
assert.Empty(t, req.Queue)
77-
assert.Empty(t, req.URI)
78-
assert.Equal(t, RequestStateUnknown, req.State)
79-
assert.Equal(t, int32(0), req.Version)
80-
}
81-
8223
func TestRequestState_IsTerminal(t *testing.T) {
8324
tests := []struct {
8425
name string
@@ -122,15 +63,3 @@ func TestRequestState_HasBuildOutcome(t *testing.T) {
12263
})
12364
}
12465
}
125-
126-
func TestRequestID_SerializationRoundTrip(t *testing.T) {
127-
original := RequestID{ID: "request/monorepo/main/100"}
128-
129-
data, err := original.ToBytes()
130-
require.NoError(t, err)
131-
132-
deserialized, err := RequestIDFromBytes(data)
133-
require.NoError(t, err)
134-
135-
assert.Equal(t, original, deserialized)
136-
}

0 commit comments

Comments
 (0)