Skip to content

Commit 3f30200

Browse files
perf, consolidation
Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
1 parent c8493bb commit 3f30200

9 files changed

Lines changed: 688 additions & 152 deletions

File tree

common/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ require (
8888
go.uber.org/goleak v1.3.0 // indirect
8989
golang.org/x/crypto v0.53.0 // indirect
9090
golang.org/x/exp v0.0.0-20260508232706-74f9aab9d74a // indirect
91-
golang.org/x/mod v0.36.0 // indirect
91+
golang.org/x/mod v0.37.0 // indirect
9292
golang.org/x/net v0.55.0 // indirect
9393
golang.org/x/sync v0.21.0 // indirect
9494
golang.org/x/sys v0.46.0 // indirect

common/go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
212212
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
213213
golang.org/x/exp v0.0.0-20260508232706-74f9aab9d74a h1:+3jdDGGB8NGb1Zktc737jlt3/A5f6UlwSzmvqUuufxw=
214214
golang.org/x/exp v0.0.0-20260508232706-74f9aab9d74a/go.mod h1:d2fgXJLVs4dYDHUk5lwMIfzRzSrWCfGZb0ZqeLa/Vcw=
215-
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
216-
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
215+
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
217216
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
218217
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
219218
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=

internal/graphapi/controlhelpers.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ func getStandardRefCodes(data []string) (map[string][]string, error) {
149149
controlRefCode := parts[1]
150150

151151
// add the mapping to the result
152-
if _, ok := result[standardShortName]; !ok {
153-
result[standardShortName] = []string{}
154-
}
155-
156152
result[standardShortName] = append(result[standardShortName], controlRefCode)
157153
}
158154

@@ -475,7 +471,7 @@ func findOrganizationControlInfoForMappings(ctx context.Context, controls map[st
475471
}
476472

477473
if len(controlRefCodes) > 0 {
478-
orClauses := make([]predicate.Control, 0, len(subcontrolRefCodes))
474+
orClauses := make([]predicate.Control, 0, len(controlRefCodes))
479475
for fw, refCodes := range controlRefCodes {
480476
orClauses = append(orClauses, control.And(
481477
control.ReferenceFrameworkEQ(fw),

internal/graphapi/controlreport_test.go

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type controlReportTestData struct {
3737
sysMapOrgSourceID string // org control matching sysControlA (the one to query)
3838
sysMapOrgTargetID string // org control matching sysControlB (expected in relatedControls)
3939
sysMapID string // the system-owned MappedControl
40+
41+
// ctrlToSubcontrolRelatedID is a subcontrol mapped directly to primaryControlID;
42+
// it must appear in primary's relatedControls with IsSubcontrol: true
43+
ctrlToSubcontrolRelatedID string
4044
}
4145

4246
// seedControlReportTestData enriches primaryControlID with a subcontrol, linked evidence,
@@ -95,6 +99,14 @@ func seedControlReportTestData(ctx context.Context, t *testing.T, primaryControl
9599
ToControlIDs: []string{tertiaryControlID},
96100
}).MustNew(ctx, t)
97101

102+
// control → subcontrol mapping: a subcontrol of tertiary is mapped directly to primary
103+
scOfTertiary := (&SubcontrolBuilder{client: suite.client, ControlID: tertiaryControlID}).MustNew(ctx, t)
104+
(&MappedControlBuilder{
105+
client: suite.client,
106+
FromControlIDs: []string{primaryControlID},
107+
ToSubcontrolIDs: []string{scOfTertiary.ID},
108+
}).MustNew(ctx, t)
109+
98110
// system mapping scenario: unique refCodes per call prevent cross-test interference
99111
sysRefA := ulids.New().String()
100112
sysRefB := ulids.New().String()
@@ -134,19 +146,20 @@ func seedControlReportTestData(ctx context.Context, t *testing.T, primaryControl
134146
}).MustNew(ctx, t)
135147

136148
return &controlReportTestData{
137-
primaryControlID: primaryControlID,
138-
secondaryControlID: secondaryControlID,
139-
tertiaryControlID: tertiaryControlID,
140-
subcontrolID: sc.ID,
141-
evidenceID: ev.ID,
142-
policyID: policy.ID,
143-
controlOwnerID: controlOwnerGroupID,
144-
forwardMappingID: forward.ID,
145-
reverseMappingID: reverse.ID,
146-
tertiaryMappingID: tertiary.ID,
147-
sysMapOrgSourceID: orgSrc.ID,
148-
sysMapOrgTargetID: orgTgt.ID,
149-
sysMapID: sysMap.ID,
149+
primaryControlID: primaryControlID,
150+
secondaryControlID: secondaryControlID,
151+
tertiaryControlID: tertiaryControlID,
152+
subcontrolID: sc.ID,
153+
evidenceID: ev.ID,
154+
policyID: policy.ID,
155+
controlOwnerID: controlOwnerGroupID,
156+
forwardMappingID: forward.ID,
157+
reverseMappingID: reverse.ID,
158+
tertiaryMappingID: tertiary.ID,
159+
sysMapOrgSourceID: orgSrc.ID,
160+
sysMapOrgTargetID: orgTgt.ID,
161+
sysMapID: sysMap.ID,
162+
ctrlToSubcontrolRelatedID: scOfTertiary.ID,
150163
}
151164
}
152165

@@ -268,10 +281,21 @@ func TestQueryControlReports(t *testing.T) {
268281
assert.Check(t, is.Len(edge.Node.EvidenceStatus.CountByStatus, 2))
269282
assert.Check(t, is.Equal(int64(1), edge.Node.LinkedPolicies.TotalCount))
270283
// secondary appears in both the forward and reverse MappedControl records;
271-
// deduplication collapses it to one entry, plus tertiary = 2 total
272-
assert.Check(t, is.Len(edge.Node.RelatedControls, 2))
284+
// deduplication collapses it to one entry; tertiary and the
285+
// directly-mapped subcontrol each add one more = 3 total
286+
assert.Check(t, is.Len(edge.Node.RelatedControls, 3))
273287
assert.Check(t, edge.Node.ControlOwner != nil)
274288
assert.Check(t, is.Equal(richData.controlOwnerID, edge.Node.ControlOwner.ID))
289+
290+
// the subcontrol mapped directly to primary must appear with IsSubcontrol: true
291+
var foundSubcontrolRelated bool
292+
for _, rc := range edge.Node.RelatedControls {
293+
if rc.ID == richData.ctrlToSubcontrolRelatedID {
294+
foundSubcontrolRelated = true
295+
assert.Check(t, rc.IsSubcontrol)
296+
}
297+
}
298+
assert.Check(t, foundSubcontrolRelated)
275299
}
276300

277301
// org control matching sysControlA should surface sysMapOrgTarget via system mapping
@@ -373,10 +397,21 @@ func TestQueryControlReportsByCategory(t *testing.T) {
373397
assert.Check(t, is.Len(c.EvidenceStatus.CountByStatus, 2))
374398
assert.Check(t, is.Equal(int64(1), c.LinkedPolicies.TotalCount))
375399
// secondary appears in both the forward and reverse MappedControl records;
376-
// deduplication collapses it to one entry, plus tertiary = 2 total
377-
assert.Check(t, is.Len(c.RelatedControls, 2))
400+
// deduplication collapses it to one entry; tertiary and the
401+
// directly-mapped subcontrol each add one more = 3 total
402+
assert.Check(t, is.Len(c.RelatedControls, 3))
378403
assert.Check(t, c.ControlOwner != nil)
379404
assert.Check(t, is.Equal(richData.controlOwnerID, c.ControlOwner.ID))
405+
406+
// the subcontrol mapped directly to primary must appear with IsSubcontrol: true
407+
var foundSubcontrolRelated bool
408+
for _, rc := range c.RelatedControls {
409+
if rc.ID == richData.ctrlToSubcontrolRelatedID {
410+
foundSubcontrolRelated = true
411+
assert.Check(t, rc.IsSubcontrol)
412+
}
413+
}
414+
assert.Check(t, foundSubcontrolRelated)
380415
}
381416

382417
// org control matching sysControlA should surface sysMapOrgTarget via system mapping

0 commit comments

Comments
 (0)