Skip to content

Commit cb720f7

Browse files
committed
fix(cli): only include root steps with authorization in childIngestionSources
Refine the previous fix to only add matched root steps when they carry authorization metadata, avoiding unnecessary size increase in the generated config files.
1 parent ef0fdf2 commit cb720f7

2 files changed

Lines changed: 71 additions & 19 deletions

File tree

packages/integration-sdk-cli/src/commands/generate-ingestion-sources-config.test.ts

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('#generateIngestionSourcesConfig', () => {
2626
},
2727
};
2828

29-
it('should include the matched step itself in childIngestionSources even when no dependents exist', () => {
29+
it('should not include matched steps without authorization in childIngestionSources', () => {
3030
const integrationSteps: IntegrationStep<IntegrationInstanceConfig>[] = [
3131
{
3232
id: 'fetch-vulnerability-alerts',
@@ -51,16 +51,11 @@ describe('#generateIngestionSourcesConfig', () => {
5151
expect(
5252
ingestionSourcesConfig[INGESTION_SOURCE_IDS.FINDING_ALERTS],
5353
).toMatchObject(ingestionConfig[INGESTION_SOURCE_IDS.FINDING_ALERTS]);
54-
// childIngestionSources includes the matched step itself
54+
// childIngestionSources is empty because the matched step has no authorization
5555
expect(
5656
ingestionSourcesConfig[INGESTION_SOURCE_IDS.FINDING_ALERTS]
5757
.childIngestionSources,
58-
).toEqual([
59-
expect.objectContaining({
60-
id: 'fetch-vulnerability-alerts',
61-
name: 'Fetch Vulnerability Alerts',
62-
}),
63-
]);
58+
).toBeEmpty();
6459
// ingestionSourcesConfig[INGESTION_SOURCE_IDS.FETCH_REPOS] is undefined because there are no steps using that ingestionSourceId
6560
expect(
6661
ingestionSourcesConfig[INGESTION_SOURCE_IDS.FETCH_REPOS],
@@ -142,16 +137,12 @@ describe('#generateIngestionSourcesConfig', () => {
142137
expect(
143138
ingestionSourcesConfig[INGESTION_SOURCE_IDS.FETCH_REPOS],
144139
).toMatchObject(ingestionConfig[INGESTION_SOURCE_IDS.FETCH_REPOS]);
145-
// New property added — includes the matched root step and its dependents
146-
const childSources =
140+
// Only includes dependents (fetch-repos has no authorization so it's excluded)
141+
expect(
147142
ingestionSourcesConfig[INGESTION_SOURCE_IDS.FETCH_REPOS]
148-
.childIngestionSources;
149-
expect(childSources).toEqual(
150-
expect.arrayContaining([
151-
expect.objectContaining({ id: 'fetch-repos', name: 'Fetch Repos' }),
152-
stepFetchVulnerabilityAlerts,
153-
stepFetchIssues,
154-
]),
143+
.childIngestionSources,
144+
).toEqual(
145+
expect.arrayContaining([stepFetchVulnerabilityAlerts, stepFetchIssues]),
155146
);
156147
// For FINDING_ALERTS the ingestionConfig keep exactly the same
157148
expect(
@@ -199,4 +190,62 @@ describe('#generateIngestionSourcesConfig', () => {
199190
ingestionSourcesConfig[INGESTION_SOURCE_IDS.TEST_SOURCE],
200191
).toBeUndefined();
201192
});
193+
194+
it('should include matched root steps that have authorization', () => {
195+
const integrationSteps: IntegrationStep<IntegrationInstanceConfig>[] = [
196+
{
197+
id: 'fetch-repos',
198+
name: 'Fetch Repos',
199+
entities: [
200+
{
201+
resourceName: 'Github Repo',
202+
_type: 'github_repo',
203+
_class: ['CodeRepo'],
204+
},
205+
],
206+
relationships: [],
207+
dependsOn: ['fetch-account'],
208+
ingestionSourceId: INGESTION_SOURCE_IDS.FETCH_REPOS,
209+
authorization: {
210+
permissions: ['repo:read'],
211+
endpoints: ['https://api.example.com/repos'],
212+
},
213+
executionHandler: jest.fn(),
214+
},
215+
{
216+
id: 'fetch-issues',
217+
name: 'Fetch Issues',
218+
entities: [
219+
{
220+
resourceName: 'GitHub Issue',
221+
_type: 'github_issue',
222+
_class: ['Issue'],
223+
},
224+
],
225+
relationships: [],
226+
dependsOn: ['fetch-repos'],
227+
executionHandler: jest.fn(),
228+
},
229+
];
230+
const ingestionSourcesConfig = generateIngestionSourcesConfig(
231+
ingestionConfig,
232+
integrationSteps,
233+
);
234+
const children =
235+
ingestionSourcesConfig[INGESTION_SOURCE_IDS.FETCH_REPOS]
236+
.childIngestionSources;
237+
// Root step with authorization is included
238+
expect(children).toEqual(
239+
expect.arrayContaining([
240+
expect.objectContaining({
241+
id: 'fetch-repos',
242+
authorization: {
243+
permissions: ['repo:read'],
244+
endpoints: ['https://api.example.com/repos'],
245+
},
246+
}),
247+
expect.objectContaining({ id: 'fetch-issues' }),
248+
]),
249+
);
250+
});
202251
});

packages/integration-sdk-cli/src/commands/generate-ingestion-sources-config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ export function generateIngestionSourcesConfig<
110110
matchedIntegrationStepIds.includes(value),
111111
),
112112
);
113-
// Include both the matched steps and their dependents, deduplicating by id
113+
// Include matched steps that carry authorization and all dependents, deduplicating by id
114114
const seenIds = new Set<string>();
115+
const matchedStepsWithAuth = matchedIntegrationSteps.filter(
116+
(step) => step.authorization,
117+
);
115118
const childIngestionSources = [
116-
...matchedIntegrationSteps,
119+
...matchedStepsWithAuth,
117120
...dependentSteps,
118121
].filter((step) => {
119122
if (seenIds.has(step.id)) return false;

0 commit comments

Comments
 (0)