Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions services/control-plane/internal/differ/live_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,18 @@ type LiveState struct {
// Outer key is ResourceType, inner key is the resource code/name.
// Resources in this set are excluded from diff planning by filterTenantOwned.
SystemCodes map[ResourceType]map[string]bool

// PlatformRefs tracks resources that are tenant overrides of platform defaults
// (is_system=false with a non-nil platform_ref in the service layer).
// These are tenant-owned resources and must be included in diff planning.
// Outer key is ResourceType, inner key is the resource code/name.
PlatformRefs map[ResourceType]map[string]bool
}

// filterTenantOwned returns a copy of live with platform default resources removed.
// Resources present in SystemCodes (is_system=true) are excluded from all resource slices.
// Resources present in PlatformRefs (is_system=false with platform_ref) are tenant overrides
// and are naturally retained - they are not in SystemCodes and pass through unchanged.
// This function must be called before DiffAgainstLiveState to ensure system resources
// do not appear as CREATE or UPDATE actions.
func filterTenantOwned(live *LiveState) *LiveState {
if live == nil {
return nil
}
return &LiveState{
SystemCodes: live.SystemCodes,
PlatformRefs: live.PlatformRefs,
SystemCodes: live.SystemCodes,
Instruments: filterBySystemCodes(live.Instruments, live.SystemCodes, ResourceInstrument,
func(r *controlplanev1.InstrumentDefinition) string { return r.GetCode() }),
AccountTypes: filterBySystemCodes(live.AccountTypes, live.SystemCodes, ResourceAccountType,
Expand Down
48 changes: 2 additions & 46 deletions services/control-plane/internal/differ/live_state_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,6 @@ func TestFilterTenantOwned_Sagas_SystemFiltered(t *testing.T) {
assert.Equal(t, "tenant_custom_saga", result.Sagas[0].GetName())
}

// TestFilterTenantOwned_SagaOverride_Retained verifies that a tenant override saga
// (is_system=false with platform_ref) is retained after filtering.
// Tenant overrides are not in SystemCodes (they are not platform defaults), so they
// pass through filterTenantOwned and must be included in diff planning.
func TestFilterTenantOwned_SagaOverride_Retained(t *testing.T) {
live := &LiveState{
Sagas: []*controlplanev1.SagaDefinition{
// Platform default: is_system=true, filtered out.
{Name: "platform_saga"},
// Tenant override: is_system=false, has platform_ref (tracked in PlatformRefs).
{Name: "override_saga"},
// Regular tenant saga: no platform_ref.
{Name: "custom_saga"},
},
SystemCodes: map[ResourceType]map[string]bool{
ResourceSaga: {"platform_saga": true},
},
// PlatformRefs documents which sagas are tenant overrides of platform defaults.
PlatformRefs: map[ResourceType]map[string]bool{
ResourceSaga: {"override_saga": true},
},
}
result := filterTenantOwned(live)
require.NotNil(t, result)
require.Len(t, result.Sagas, 2, "both override_saga and custom_saga should be retained")
names := sagaNames(result.Sagas)
assert.Contains(t, names, "override_saga")
assert.Contains(t, names, "custom_saga")
assert.NotContains(t, names, "platform_saga")
}

func TestFilterTenantOwned_MultipleTypes(t *testing.T) {
live := &LiveState{
Instruments: []*controlplanev1.InstrumentDefinition{
Expand Down Expand Up @@ -226,20 +195,15 @@ func TestFilterTenantOwned_AllResourceTypesFiltered(t *testing.T) {
assert.Equal(t, "tenant-route", result.InstructionRoutes[0].GetInstructionType())
}

func TestFilterTenantOwned_PreservesSystemAndPlatformRefMaps(t *testing.T) {
func TestFilterTenantOwned_PreservesSystemCodesMap(t *testing.T) {
systemCodes := map[ResourceType]map[string]bool{
ResourceInstrument: {"SYS_GBP": true},
}
platformRefs := map[ResourceType]map[string]bool{
ResourceSaga: {"override_saga": true},
}
live := &LiveState{
SystemCodes: systemCodes,
PlatformRefs: platformRefs,
SystemCodes: systemCodes,
}
result := filterTenantOwned(live)
assert.Equal(t, systemCodes, result.SystemCodes)
assert.Equal(t, platformRefs, result.PlatformRefs)
}

// --- helpers ---
Expand All @@ -251,11 +215,3 @@ func instrumentCodes(instruments []*controlplanev1.InstrumentDefinition) []strin
}
return codes
}

func sagaNames(sagas []*controlplanev1.SagaDefinition) []string {
names := make([]string, len(sagas))
for i, s := range sagas {
names[i] = s.GetName()
}
return names
}
Loading