Skip to content

Commit aa35d9a

Browse files
committed
fix(e2e): improve catalog source toggle reliability with API waits and correct configmap precedence
1 parent c07eaa4 commit aa35d9a

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

packages/cypress/cypress/pages/modelCatalogSettings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class ModelCatalogSettings {
5050
findEnableToggle(sourceId: string) {
5151
return cy.findByTestId(`enable-toggle-${sourceId}`);
5252
}
53+
54+
findToggleAlert() {
55+
return cy.findByTestId('toggle-alert');
56+
}
5357
}
5458

5559
export const modelCatalogSettings = new ModelCatalogSettings();

packages/cypress/cypress/tests/e2e/modelCatalog/testSourceEnableDisable.cy.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
waitForModelCatalogCards,
88
waitForModelCatalogAfterDisable,
99
enableModelCatalogSource,
10-
ensureModelCatalogSourceEnabled,
1110
} from '../../../utils/oc_commands/modelCatalog';
1211
import { retryableBefore } from '../../../utils/retryableHooks';
1312
import type { ModelCatalogSourceTestData } from '../../../types';
@@ -22,8 +21,10 @@ describe('[product bug: RHOAIENG-53704] Verify Model Catalog Source Enable/Disab
2221
testData = yaml.load(yamlContent) as ModelCatalogSourceTestData;
2322
})
2423
.then(() => {
25-
ensureModelCatalogSourceEnabled(testData.redhatAiSourceId);
26-
ensureModelCatalogSourceEnabled(testData.redhatAiSourceId2);
24+
enableModelCatalogSource(testData.redhatAiSourceId);
25+
enableModelCatalogSource(testData.redhatAiSourceId2);
26+
verifyModelCatalogSourceEnabled(testData.redhatAiSourceId, true);
27+
verifyModelCatalogSourceEnabled(testData.redhatAiSourceId2, true);
2728
});
2829
});
2930

@@ -58,14 +59,20 @@ describe('[product bug: RHOAIENG-53704] Verify Model Catalog Source Enable/Disab
5859
cy.step('Navigate back to AI catalog sources');
5960
modelCatalogSettings.visit();
6061

62+
cy.intercept('PATCH', '**/source_configs/*').as('toggleSource');
63+
6164
cy.step(`Disable the ${testData.sourceName} source`);
62-
modelCatalogSettings.findEnableToggle(testData.redhatAiSourceId).click({ force: true });
65+
modelCatalogSettings.findEnableToggle(testData.redhatAiSourceId).click();
66+
cy.wait('@toggleSource').its('response.statusCode').should('eq', 200);
67+
modelCatalogSettings.findToggleAlert().should('not.exist');
6368

6469
cy.step('Verify first source is disabled in configmap');
6570
verifyModelCatalogSourceEnabled(testData.redhatAiSourceId, false);
6671

6772
cy.step(`Disable the ${testData.sourceName2} source`);
68-
modelCatalogSettings.findEnableToggle(testData.redhatAiSourceId2).click({ force: true });
73+
modelCatalogSettings.findEnableToggle(testData.redhatAiSourceId2).click();
74+
cy.wait('@toggleSource').its('response.statusCode').should('eq', 200);
75+
modelCatalogSettings.findToggleAlert().should('not.exist');
6976

7077
cy.step('Verify second source is disabled in configmap');
7178
verifyModelCatalogSourceEnabled(testData.redhatAiSourceId2, false);

packages/cypress/cypress/utils/oc_commands/modelCatalog.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,39 @@ export const verifyModelCatalogSourceEnabled = (
240240

241241
/**
242242
* Check if a specific model catalog source is currently enabled.
243-
* Checks the model-catalog-default-sources ConfigMap for the source's enabled status.
243+
* Checks model-catalog-sources (user overrides) first, then falls back to
244+
* model-catalog-default-sources. This mirrors the precedence used by
245+
* verifyModelCatalogSourceEnabled and the BFF itself.
244246
* @param sourceId The ID of the source to check (e.g., 'redhat_ai_models')
245247
* @returns A Cypress chainable that resolves with true if enabled, false otherwise.
246248
*/
247249
export const isModelCatalogSourceEnabled = (sourceId: string): Cypress.Chainable<boolean> => {
248250
const namespace = getModelRegistryNamespace();
249251
const parseCmd = getYamlParseCommand(sourceId);
250-
const command = `oc get configmap model-catalog-default-sources -n ${namespace} -o jsonpath='{.data.sources\\.yaml}' | ${parseCmd}`;
252+
const userCommand = `oc get configmap model-catalog-sources -n ${namespace} -o jsonpath='{.data.sources\\.yaml}' 2>/dev/null | ${parseCmd}`;
253+
const defaultCommand = `oc get configmap model-catalog-default-sources -n ${namespace} -o jsonpath='{.data.sources\\.yaml}' | ${parseCmd}`;
251254

252-
return execWithOutput(command, 30).then((result: CommandLineResult) => {
253-
if (result.code !== 0) {
254-
const maskedStderr = maskSensitiveInfo(result.stderr);
255-
cy.log(`ERROR: Failed to check source enabled status`);
256-
cy.log(`stderr: ${maskedStderr}`);
257-
return cy.wrap(false);
255+
return execWithOutput(userCommand, 30).then((userResult: CommandLineResult) => {
256+
const userValue = userResult.stdout.trim();
257+
258+
if (userResult.code === 0 && (userValue === 'true' || userValue === 'false')) {
259+
const isEnabled = userValue === 'true';
260+
cy.log(`Source ${sourceId} is currently enabled: ${isEnabled} (from user configmap)`);
261+
return cy.wrap(isEnabled);
258262
}
259-
const isEnabled = result.stdout.trim() === 'true';
260-
cy.log(`Source ${sourceId} is currently enabled: ${isEnabled}`);
261-
return cy.wrap(isEnabled);
263+
264+
return execWithOutput(defaultCommand, 30).then((defaultResult: CommandLineResult) => {
265+
if (defaultResult.code !== 0) {
266+
const maskedStderr = maskSensitiveInfo(defaultResult.stderr);
267+
cy.log(`ERROR: Failed to check source enabled status`);
268+
cy.log(`stderr: ${maskedStderr}`);
269+
return cy.wrap(false);
270+
}
271+
const defaultValue = defaultResult.stdout.trim();
272+
const isEnabled = defaultValue === '' ? true : defaultValue === 'true';
273+
cy.log(`Source ${sourceId} is currently enabled: ${isEnabled} (from default configmap)`);
274+
return cy.wrap(isEnabled);
275+
});
262276
});
263277
};
264278

0 commit comments

Comments
 (0)