Skip to content

Commit 1bc670e

Browse files
committed
refactor: Remove PlatformRefs field from LiveState struct
PlatformRefs was a documentation-only field tracking tenant override sagas. Since tenant overrides are not in SystemCodes, they pass through filterTenantOwned without any special handling. The field added no behavioural value and is removed along with the associated test cases.
1 parent 28e0e04 commit 1bc670e

2 files changed

Lines changed: 3 additions & 56 deletions

File tree

services/control-plane/internal/differ/live_state.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,18 @@ type LiveState struct {
2929
// Outer key is ResourceType, inner key is the resource code/name.
3030
// Resources in this set are excluded from diff planning by filterTenantOwned.
3131
SystemCodes map[ResourceType]map[string]bool
32-
33-
// PlatformRefs tracks resources that are tenant overrides of platform defaults
34-
// (is_system=false with a non-nil platform_ref in the service layer).
35-
// These are tenant-owned resources and must be included in diff planning.
36-
// Outer key is ResourceType, inner key is the resource code/name.
37-
PlatformRefs map[ResourceType]map[string]bool
3832
}
3933

4034
// filterTenantOwned returns a copy of live with platform default resources removed.
4135
// Resources present in SystemCodes (is_system=true) are excluded from all resource slices.
42-
// Resources present in PlatformRefs (is_system=false with platform_ref) are tenant overrides
43-
// and are naturally retained - they are not in SystemCodes and pass through unchanged.
4436
// This function must be called before DiffAgainstLiveState to ensure system resources
4537
// do not appear as CREATE or UPDATE actions.
4638
func filterTenantOwned(live *LiveState) *LiveState {
4739
if live == nil {
4840
return nil
4941
}
5042
return &LiveState{
51-
SystemCodes: live.SystemCodes,
52-
PlatformRefs: live.PlatformRefs,
43+
SystemCodes: live.SystemCodes,
5344
Instruments: filterBySystemCodes(live.Instruments, live.SystemCodes, ResourceInstrument,
5445
func(r *controlplanev1.InstrumentDefinition) string { return r.GetCode() }),
5546
AccountTypes: filterBySystemCodes(live.AccountTypes, live.SystemCodes, ResourceAccountType,

services/control-plane/internal/differ/live_state_filter_test.go

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -88,37 +88,6 @@ func TestFilterTenantOwned_Sagas_SystemFiltered(t *testing.T) {
8888
assert.Equal(t, "tenant_custom_saga", result.Sagas[0].GetName())
8989
}
9090

91-
// TestFilterTenantOwned_SagaOverride_Retained verifies that a tenant override saga
92-
// (is_system=false with platform_ref) is retained after filtering.
93-
// Tenant overrides are not in SystemCodes (they are not platform defaults), so they
94-
// pass through filterTenantOwned and must be included in diff planning.
95-
func TestFilterTenantOwned_SagaOverride_Retained(t *testing.T) {
96-
live := &LiveState{
97-
Sagas: []*controlplanev1.SagaDefinition{
98-
// Platform default: is_system=true, filtered out.
99-
{Name: "platform_saga"},
100-
// Tenant override: is_system=false, has platform_ref (tracked in PlatformRefs).
101-
{Name: "override_saga"},
102-
// Regular tenant saga: no platform_ref.
103-
{Name: "custom_saga"},
104-
},
105-
SystemCodes: map[ResourceType]map[string]bool{
106-
ResourceSaga: {"platform_saga": true},
107-
},
108-
// PlatformRefs documents which sagas are tenant overrides of platform defaults.
109-
PlatformRefs: map[ResourceType]map[string]bool{
110-
ResourceSaga: {"override_saga": true},
111-
},
112-
}
113-
result := filterTenantOwned(live)
114-
require.NotNil(t, result)
115-
require.Len(t, result.Sagas, 2, "both override_saga and custom_saga should be retained")
116-
names := sagaNames(result.Sagas)
117-
assert.Contains(t, names, "override_saga")
118-
assert.Contains(t, names, "custom_saga")
119-
assert.NotContains(t, names, "platform_saga")
120-
}
121-
12291
func TestFilterTenantOwned_MultipleTypes(t *testing.T) {
12392
live := &LiveState{
12493
Instruments: []*controlplanev1.InstrumentDefinition{
@@ -226,20 +195,15 @@ func TestFilterTenantOwned_AllResourceTypesFiltered(t *testing.T) {
226195
assert.Equal(t, "tenant-route", result.InstructionRoutes[0].GetInstructionType())
227196
}
228197

229-
func TestFilterTenantOwned_PreservesSystemAndPlatformRefMaps(t *testing.T) {
198+
func TestFilterTenantOwned_PreservesSystemCodesMap(t *testing.T) {
230199
systemCodes := map[ResourceType]map[string]bool{
231200
ResourceInstrument: {"SYS_GBP": true},
232201
}
233-
platformRefs := map[ResourceType]map[string]bool{
234-
ResourceSaga: {"override_saga": true},
235-
}
236202
live := &LiveState{
237-
SystemCodes: systemCodes,
238-
PlatformRefs: platformRefs,
203+
SystemCodes: systemCodes,
239204
}
240205
result := filterTenantOwned(live)
241206
assert.Equal(t, systemCodes, result.SystemCodes)
242-
assert.Equal(t, platformRefs, result.PlatformRefs)
243207
}
244208

245209
// --- helpers ---
@@ -251,11 +215,3 @@ func instrumentCodes(instruments []*controlplanev1.InstrumentDefinition) []strin
251215
}
252216
return codes
253217
}
254-
255-
func sagaNames(sagas []*controlplanev1.SagaDefinition) []string {
256-
names := make([]string, len(sagas))
257-
for i, s := range sagas {
258-
names[i] = s.GetName()
259-
}
260-
return names
261-
}

0 commit comments

Comments
 (0)