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
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ CredentialCache.hasCredentials(this.id); // BUG!
- **`AzureClusterModel`** - Azure/Discovery Views (has Azure `id`)
- **`BaseClusterModel`** - Shared interface (use for generic code)

For Discovery View, `treeId` is sanitized (no `/`), but `clusterId` keeps the original Azure Resource ID.
For Discovery View, both `treeId` and `clusterId` are sanitized (all `/` replaced with `_`). The original Azure Resource ID is stored in `AzureClusterModel.id` for Azure API calls.

> 💡 **Extensibility**: If adding a non-Azure discovery source (e.g., AWS, GCP), consider creating a new model type (e.g., `AwsClusterModel`) extending `BaseClusterModel` with source-specific metadata.

Expand Down
2 changes: 1 addition & 1 deletion src/documentdb/CredentialCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Credential Cache Stability', () => {
});

it('should allow treeId === clusterId for Azure resources (both sanitized)', () => {
// Azure views: both IDs are the sanitized Azure Resource ID
// Azure views: both IDs are the sanitized Azure Resource ID (/ replaced with _)
const azureResourceId =
'/subscriptions/sub1/resourceGroups/rg1/providers/Microsoft.DocumentDB/mongoClusters/mycluster';
const sanitizedId = azureResourceId.replace(/\//g, '_');
Expand Down
8 changes: 5 additions & 3 deletions src/tree/azure-views/models/AzureClusterModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('AzureClusterModel', () => {
const azureResourceId =
'/subscriptions/sub1/resourceGroups/rg1/providers/Microsoft.DocumentDB/mongoClusters/cluster1';

it('should sanitize treeId for Discovery View', () => {
it('should sanitize both clusterId and treeId for Discovery View', () => {
const sanitizedId = sanitizeAzureResourceIdForTreeId(azureResourceId);
const discoveryCluster: TreeCluster<AzureClusterModel> = {
name: 'discovery-cluster',
Expand All @@ -131,7 +131,7 @@ describe('AzureClusterModel', () => {
expect(discoveryCluster.id).toContain('/');
});

it('should sanitize clusterId for Azure Resources View', () => {
it('should sanitize both clusterId and treeId for Azure Resources View', () => {
const sanitizedId = sanitizeAzureResourceIdForTreeId(azureResourceId);
const azureResourcesCluster: TreeCluster<AzureClusterModel> = {
name: 'azure-resources-cluster',
Expand All @@ -143,14 +143,16 @@ describe('AzureClusterModel', () => {
viewId: Views.AzureResourcesView,
};

// clusterId and treeId are both sanitized
// clusterId and treeId are both sanitized and equal
expect(azureResourcesCluster.clusterId).toBe(sanitizedId);
expect(azureResourcesCluster.treeId).toBe(sanitizedId);
expect(azureResourcesCluster.clusterId).toBe(azureResourcesCluster.treeId);
expect(azureResourcesCluster.clusterId).not.toContain('/');
expect(azureResourcesCluster.treeId).not.toContain('/');

// Original Azure Resource ID preserved in 'id' for Azure API calls
expect(azureResourcesCluster.id).toBe(azureResourceId);
expect(azureResourcesCluster.id).toContain('/');
});
});
});
6 changes: 1 addition & 5 deletions src/tree/discovery-view/DiscoveryBranchDataProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,11 @@ describe('DiscoveryBranchDataProvider - addDiscoveryProviderPromotionIfNeeded',

describe('DiscoveryBranchDataProvider - Cluster ID Validation', () => {
let dataProvider: DiscoveryBranchDataProvider;
let outputChannelWarnMock: jest.Mock;

beforeEach(() => {
// Clear all mocks
jest.clearAllMocks();

// eslint-disable-next-line @typescript-eslint/unbound-method
outputChannelWarnMock = ext.outputChannel.warn as jest.Mock;

// Create a new instance for each test
dataProvider = new DiscoveryBranchDataProvider();
});
Expand Down Expand Up @@ -640,7 +636,7 @@ describe('DiscoveryBranchDataProvider - Cluster ID Validation', () => {

// Should throw an error about unexpected prefix
await expect(dataProvider.getChildren(mockParentElement)).rejects.toThrow(
expect.stringMatching(/must start with provider ID.*azure-mongo-vcore-discovery/),
/must start with provider ID.*azure-mongo-vcore-discovery/,
);
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/tree/models/BaseClusterModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('BaseClusterModel', () => {
name: 'azure-cluster',
connectionString: undefined,
dbExperience: DocumentDBExperience,
clusterId: sanitizedId,
clusterId: sanitizedId, // Sanitized - clusterId must NEVER contain '/'
};

expect(model.connectionString).toBeUndefined();
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('BaseClusterModel', () => {
});

it('should have clusterId === treeId for Discovery View (both sanitized)', () => {
// In Discovery View, both clusterId and treeId are sanitized
// In Discovery View, both clusterId and treeId are sanitized (/ replaced with _)
// The original Azure Resource ID is stored in AzureClusterModel.id
const azureResourceId =
'/subscriptions/sub1/resourceGroups/rg1/providers/Microsoft.DocumentDB/mongoClusters/cluster1';
Expand All @@ -121,7 +121,7 @@ describe('BaseClusterModel', () => {
});

it('should have clusterId === treeId for Azure Resources View (both sanitized)', () => {
// In Azure Resources View, both clusterId and treeId are sanitized
// In Azure Resources View, both clusterId and treeId are sanitized (/ replaced with _)
const azureResourceId =
'/subscriptions/sub1/resourceGroups/rg1/providers/Microsoft.DocumentDB/mongoClusters/cluster1';
const sanitizedId = azureResourceId.replace(/\//g, '_');
Expand Down
3 changes: 3 additions & 0 deletions src/tree/models/BaseClusterModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export interface BaseClusterModel {
* Values:
* - Connections View: `storageId` (UUID from ConnectionStorageService)
* - Discovery/Azure Views: Sanitized Azure Resource ID (no '/' - replaced with '_')
*
* Note: For Azure Views, the clusterId is sanitized (all '/' replaced with '_').
* The original Azure Resource ID is stored in AzureClusterModel.id.
*/
clusterId: string;
}
Expand Down