From 64ac7302cd8771fbc0ce12601d9d452d24e59070 Mon Sep 17 00:00:00 2001 From: Sudharshan Muralidharan Date: Fri, 6 Nov 2026 14:19:00 +0530 Subject: [PATCH] test: add IBM Bob provider smoke coverage Exercise provider selection, bundle injection, authenticated inference, and a shell-created file in a workspace. Skip without Bob credentials, preserve pre-existing provider keys, and explicitly target the development container without changing shared container selection behavior. Signed-off-by: Sudharshan Muralidharan --- tests/e2e/README.md | 17 ++ .../pageobjects/dashboard/CreateWorkspace.ts | 14 + tests/e2e/pageobjects/dashboard/Dashboard.ts | 4 +- .../BobProviderSmokeTest.spec.ts | 241 ++++++++++++++++++ 4 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/specs/miscellaneous/BobProviderSmokeTest.spec.ts diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 6b6c78f0a9c..5b6f46d2ab5 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -84,3 +84,20 @@ The `'quay.io/eclipse/che-e2e'` docker image has VNC server installed inside. Fo **Execute the npm command:** - perform command `export USERSTORY=$TS_SELENIUM_HAPPY_PATH_WORKSPACE_NAME && npm run test-all-devfiles` + +## IBM Bob provider smoke test + +Deploy the Bob injector image and register `ibm/bob` in the AI tool registry +before running this test. Configure the cluster login variables above, then run: + +```sh +export TS_AI_PROVIDER_API_KEY='' +export USERSTORY=BobProviderSmokeTest +npm run test +``` + +The test skips when `TS_AI_PROVIDER_API_KEY` is unset. It preserves an existing +Bob key and removes only a key it created. It creates a workspace with a `4Gi` +development-container memory limit, accepts Bob's license for the test session, +and makes authenticated inference and shell-tool requests before deleting the +workspace. Use a dedicated test account with access to Bob inference. diff --git a/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts b/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts index d92e77f098e..22da3668787 100644 --- a/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts +++ b/tests/e2e/pageobjects/dashboard/CreateWorkspace.ts @@ -203,6 +203,15 @@ export class CreateWorkspace { await this.driverHelper.waitAttributeValue(toggle, 'aria-expanded', 'true', TIMEOUT_CONSTANTS.TS_COMMON_DASHBOARD_WAIT_TIMEOUT); } + async selectAiProvider(providerId: string): Promise { + Logger.debug(`providerId: "${providerId}"`); + + const checkbox: By = this.getAiProviderCheckboxLocator(providerId); + if (!(await this.driverHelper.getDriver().findElement(checkbox).isSelected())) { + await this.driverHelper.waitAndClick(this.getAiProviderCardLocator(providerId)); + } + } + async isAiProviderSectionVisible(): Promise { Logger.debug(); @@ -267,6 +276,11 @@ export class CreateWorkspace { return By.xpath(`//div[contains(@id, 'sample-card') and text()='${sampleName}']`); } + private getAiProviderCheckboxLocator(providerId: string): By { + const cardId: string = providerId.replace(/\//g, '-'); + return By.css(`#ai-provider-card-${cardId} input[type="checkbox"]`); + } + private getAiProviderCardLocator(providerId: string): By { const cardId: string = providerId.replace(/\//g, '-'); return By.id(`ai-provider-card-${cardId}`); diff --git a/tests/e2e/pageobjects/dashboard/Dashboard.ts b/tests/e2e/pageobjects/dashboard/Dashboard.ts index 0d83309f3f4..e4ba292b581 100644 --- a/tests/e2e/pageobjects/dashboard/Dashboard.ts +++ b/tests/e2e/pageobjects/dashboard/Dashboard.ts @@ -19,8 +19,8 @@ import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; @injectable() export class Dashboard { - private static readonly WORKSPACES_BUTTON: By = By.xpath('//div[@id="page-sidebar"]//a[contains(text(), "Workspaces (")]'); - private static readonly CREATE_WORKSPACE_BUTTON: By = By.xpath('//div[@id="page-sidebar"]//a[text()="Create Workspace"]'); + private static readonly WORKSPACES_BUTTON: By = By.css('nav a[href="#/workspaces"]'); + private static readonly CREATE_WORKSPACE_BUTTON: By = By.css('nav a[href="#/create-workspace"]'); private static readonly LOADER_PAGE_STEP_TITLES: By = By.xpath('//*[@data-testid="step-title"]'); private static readonly STARTING_PAGE_LOADER: By = By.css('.main-page-loader'); private static readonly LOADER_ALERT: By = By.xpath('//*[@data-testid="loader-alert"]'); diff --git a/tests/e2e/specs/miscellaneous/BobProviderSmokeTest.spec.ts b/tests/e2e/specs/miscellaneous/BobProviderSmokeTest.spec.ts new file mode 100644 index 00000000000..7fe9eda135d --- /dev/null +++ b/tests/e2e/specs/miscellaneous/BobProviderSmokeTest.spec.ts @@ -0,0 +1,241 @@ +/** ******************************************************************* + * copyright (c) 2026 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ +import { e2eContainer } from '../../configs/inversify.config'; +import { CLASSES, TYPES } from '../../configs/inversify.types'; +import { WorkspaceHandlingTests } from '../../tests-library/WorkspaceHandlingTests'; +import { ProjectAndFileTests } from '../../tests-library/ProjectAndFileTests'; +import { LoginTests } from '../../tests-library/LoginTests'; +import { registerRunningWorkspace } from '../MochaHooks'; +import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil'; +import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS'; + +import { UserPreferences } from '../../pageobjects/dashboard/UserPreferences'; +import { CreateWorkspace } from '../../pageobjects/dashboard/CreateWorkspace'; +import { Dashboard } from '../../pageobjects/dashboard/Dashboard'; +import { ITestWorkspaceUtil } from '../../utils/workspace/ITestWorkspaceUtil'; +import { KubernetesCommandLineToolsExecutor, ContainerTerminal } from '../../utils/KubernetesCommandLineToolsExecutor'; +import { ShellString } from 'shelljs'; +import { expect } from 'chai'; +import { Logger } from '../../utils/Logger'; +import { ApiUrlResolver } from '../../utils/workspace/ApiUrlResolver'; +import { CheApiRequestHandler } from '../../utils/request-handlers/CheApiRequestHandler'; +import { AxiosResponse } from 'axios'; +import { V1alpha2DevWorkspaceSpecTemplateComponents } from '@devfile/api'; + +interface BobRunResult { + status: string; + last_message: string; + stats: { tool_calls: number }; +} + +suite(`IBM Bob Provider Smoke Test ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void { + const stackName: string = 'Empty Workspace'; + const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); + const apiUrlResolver: ApiUrlResolver = e2eContainer.get(CLASSES.ApiUrlResolver); + const requestHandler: CheApiRequestHandler = e2eContainer.get(CLASSES.CheApiRequestHandler); + const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); + const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); + const browserTabsUtil: BrowserTabsUtil = e2eContainer.get(CLASSES.BrowserTabsUtil); + const userPreferences: UserPreferences = e2eContainer.get(CLASSES.UserPreferences); + const createWorkspace: CreateWorkspace = e2eContainer.get(CLASSES.CreateWorkspace); + const dashboard: Dashboard = e2eContainer.get(CLASSES.Dashboard); + const testWorkspaceUtil: ITestWorkspaceUtil = e2eContainer.get(TYPES.WorkspaceUtil); + const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get( + CLASSES.KubernetesCommandLineToolsExecutor + ); + const containerTerminal: ContainerTerminal = e2eContainer.get(CLASSES.ContainerTerminal); + + const providerName: string = 'IBM Bob CLI'; + const providerId: string = 'ibm/bob'; + const apiKey: string = BASE_TEST_CONSTANTS.TS_AI_PROVIDER_API_KEY; + const envVarName: string = 'BOB_API_KEY'; + + let loggedIn: boolean = false; + let providerKeyAlreadyPresent: boolean = false; + let createdProviderKey: boolean = false; + let workspaceName: string = ''; + let workspaceContainer: string = ''; + + suiteSetup('Login', async function (): Promise { + if (!apiKey) { + this.skip(); + } + await loginTests.loginIntoChe(); + loggedIn = true; + await userPreferences.openUserPreferencesPage(); + await userPreferences.openAiProviderKeysTab(); + providerKeyAlreadyPresent = await userPreferences.isAiProviderKeyPresent(providerId); + if (providerKeyAlreadyPresent) { + Logger.info('Using the existing Bob key without replacing it'); + } + }); + + suite('Add AI Provider API key', function (): void { + test('Navigate to AI Provider Keys tab', async function (): Promise { + await userPreferences.openUserPreferencesPage(); + await userPreferences.waitAiProviderKeysTab(); + await userPreferences.openAiProviderKeysTab(); + }); + + test(`Add ${providerName} API key`, async function (): Promise { + if (providerKeyAlreadyPresent) { + this.skip(); + } + await userPreferences.addAiProviderKey(providerName, apiKey); + createdProviderKey = true; + }); + + test(`Verify ${providerName} key is present in the list`, async function (): Promise { + await userPreferences.waitAiProviderKeyPresent(providerId); + + const actualEnvVarName: string = await userPreferences.getAiProviderEnvVarName(providerId); + expect(actualEnvVarName).to.equal(envVarName); + }); + }); + + suite('Verify AI Provider on Create Workspace page', function (): void { + test('Navigate to Create Workspace page', async function (): Promise { + await dashboard.clickCreateWorkspaceButton(); + await createWorkspace.waitPage(); + }); + + test('Verify AI Provider section is visible', async function (): Promise { + await createWorkspace.waitAiProviderSectionVisible(); + }); + + test('Expand "Choose an AI Provider" section', async function (): Promise { + await createWorkspace.expandChooseAiProviderSection(); + }); + + test(`Verify ${providerName} provider card is visible`, async function (): Promise { + await createWorkspace.waitAiProviderCardVisible(providerId); + }); + + test('Verify "Key configured" badge is displayed', async function (): Promise { + await createWorkspace.waitAiProviderKeyConfiguredBadgeVisible(providerId); + }); + }); + + suite('Create workspace and verify AI tool', function (): void { + test(`Create and open ${stackName}`, async function (): Promise { + const workspaceApiUrl: string = await apiUrlResolver.getWorkspacesApiUrl(); + kubernetesCommandLineToolsExecutor.namespace = workspaceApiUrl.split('/').slice(-2)[0]; + containerTerminal.namespace = kubernetesCommandLineToolsExecutor.namespace; + await createWorkspace.setCreateNewWorkspaceCheckbox(true); + await createWorkspace.selectAiProvider(providerId); + const parentHandle: string = await browserTabsUtil.getCurrentWindowHandle(); + await createWorkspace.clickOnSampleNoEditorSelection(stackName); + await browserTabsUtil.waitAndSwitchToAnotherWindow(parentHandle); + }); + + test('Obtain workspace name from workspace loader page', async function (): Promise { + await workspaceHandlingTests.obtainWorkspaceNameFromStartingPage(); + workspaceName = WorkspaceHandlingTests.getWorkspaceName(); + }); + + test('Register running workspace', function (): void { + registerRunningWorkspace(workspaceName); + }); + + test('Allocate the memory required by Bob', async function (): Promise { + const url: string = await apiUrlResolver.getWorkspaceApiUrl(workspaceName); + const response: AxiosResponse = await requestHandler.get(url); + const components: V1alpha2DevWorkspaceSpecTemplateComponents[] = response.data.spec.template.components; + const index: number = components.findIndex( + (component: V1alpha2DevWorkspaceSpecTemplateComponents): boolean => + component.container !== undefined && !component.name.endsWith('-injector') + ); + expect(index, 'a workspace development container should exist').to.be.greaterThan(-1); + workspaceContainer = components[index].name; + await requestHandler.patch(url, [ + { op: 'add', path: `/spec/template/components/${index}/container/memoryLimit`, value: '4Gi' } + ]); + }); + + test('Wait workspace readiness', async function (): Promise { + await projectAndFileTests.waitWorkspaceReadinessForCheCodeEditor(); + }); + + test('Connect to workspace container', function (): void { + kubernetesCommandLineToolsExecutor.workspaceName = workspaceName; + kubernetesCommandLineToolsExecutor.loginToOcp(); + kubernetesCommandLineToolsExecutor.getPodAndContainerNames(); + }); + + test('Verify bob binary is available in workspace', function (): void { + const output: ShellString = containerTerminal.execInContainerCommand( + 'command -v bob && test -x /injected-tools/bob-cli/bin/node', + workspaceContainer + ); + expect(output.code, 'bob binary should be present in the workspace').to.equal(0); + }); + + test(`Verify ${envVarName} environment variable is set`, function (): void { + const output: ShellString = containerTerminal.execInContainerCommand(`test -n "$${envVarName}"`, workspaceContainer); + expect(output.code, `${envVarName} environment variable should be set`).to.equal(0); + }); + + test('Verify bob starts and reports version', function (): void { + const output: ShellString = containerTerminal.execInContainerCommandWithTimeout('bob --version 2>&1', workspaceContainer, '30'); + expect(output.code, 'bob --version should exit with code 0').to.equal(0); + expect(output.stdout, 'bob should return version info').to.match(/\d+\.\d+\.\d+/); + expect(output.stdout.toLowerCase(), 'bob --version should not contain errors').to.not.contain('error'); + }); + + test('Verify Bob completes an authenticated request', function (): void { + // bob run reads stdin until EOF; oc exec -i otherwise keeps it open. + const command: string = + 'bob run --accept-license --trust --disable-mcp --disable-subagents --format json --max-turns 1 "Reply with exactly BOB_WORKSPACE_OK. Do not use tools." ${resultFile}" { + if (loggedIn) { + await dashboard.openDashboard(); + await browserTabsUtil.closeAllTabsExceptCurrent(); + } + }); + + suiteTeardown('Stop and delete the workspace by API', async function (): Promise { + if (workspaceName) { + await testWorkspaceUtil.stopAndDeleteWorkspaceByName(workspaceName); + } + }); + + suiteTeardown('Delete only the key created by this test', async function (): Promise { + if (createdProviderKey) { + await userPreferences.openUserPreferencesPage(); + await userPreferences.openAiProviderKeysTab(); + await userPreferences.deleteAiProviderKeys(providerName); + } + }); + + suiteTeardown('Unregister running workspace', function (): void { + registerRunningWorkspace(''); + }); +});