Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.
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: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"type": "node",
"request": "launch",
"name": "Debug circular dependencies",
"program": "${workspaceFolder}/dist/index.mjs",
"args": ["components", "push", "component-component-whitelist", "--space", "295018", "--from", "295017", "--verbose"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"type": "node",
"request": "launch",
Expand Down
14 changes: 9 additions & 5 deletions src/commands/components/push/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,17 @@ describe('operations', () => {
],
};

// Mock successful responses
vi.mocked(upsertComponent).mockImplementation(async (_space, component) => ({
...component,
id: component.id + 1000,
}));

const results = await handleWhitelists(mockSpace, mockPassword, mockRegion, circularData);

// Verify that circular dependency was detected and handled
expect(results.failed).toHaveLength(1);
expect(results.failed[0].error).toMatchObject({
message: expect.stringContaining('Circular dependency detected'),
});
// Verify that circular dependency was handled by skipping
expect(results.failed).toHaveLength(0); // No failures
expect(results.successful).toHaveLength(2); // Only two components were processed
});

it('should handle missing dependencies gracefully', async () => {
Expand Down
19 changes: 12 additions & 7 deletions src/commands/components/push/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { delay } from '../../../utils/fetch';
function findRelatedResources(
components: SpaceComponent[],
spaceData: SpaceData,
visitedComponents = new Set<string>(), // Track visited components to detect cycles
): {
groups: SpaceComponentGroup[];
presets: SpaceComponentPreset[];
Expand Down Expand Up @@ -147,7 +148,16 @@ function findRelatedResources(
};

if (whitelistedComponents.length > 0) {
additionalResources = findRelatedResources(whitelistedComponents, spaceData);
// Filter out components that would create circular dependencies
const newComponents = whitelistedComponents.filter(component => !visitedComponents.has(component.name));

if (newComponents.length > 0) {
// Add current components to visited set
components.forEach(component => visitedComponents.add(component.name));

// Only process components we haven't seen before
additionalResources = findRelatedResources(newComponents, spaceData, visitedComponents);
}
}

const result = {
Expand Down Expand Up @@ -574,13 +584,8 @@ export async function handleWhitelists(
return;
}

// Check for circular dependencies
// Skip if we detect a circular dependency
if (visited.has(componentName)) {
failedComponents.add(componentName);
results.failed.push({
name: componentName,
error: new Error(`Circular dependency detected for component ${componentName}`),
});
return;
}

Expand Down