generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add AI Core e2e tests #128
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
334708d
init
shibeshduw 2cb350a
Merge remote-tracking branch 'origin/main' into aicore-e2e-tests
shibeshduw 4f6a002
Added e2e tests
shibeshduw e163d42
increase timeout
shibeshduw 6a3883b
changes to error msg
shibeshduw 7f8cf16
Merge remote-tracking branch 'origin/main' into aicore-e2e-tests
shibeshduw bf650a8
Merge remote-tracking branch 'origin/main' into aicore-e2e-tests
shibeshduw 87793a2
use native approach
shibeshduw 4f69da8
Merge remote-tracking branch 'origin/main' into aicore-e2e-tests
shibeshduw 748e921
remove unused deps
shibeshduw 85b9af2
small changes
shibeshduw a876bb4
Merge remote-tracking branch 'origin/main' into aicore-e2e-tests
shibeshduw 21a655f
create utils
shibeshduw 650e2c7
separate tests
shibeshduw cc018f4
update libs
shibeshduw 425330e
merge
shibeshduw 388401b
fix lint issues
shibeshduw 1524acb
whoops
shibeshduw e2aabab
Merge remote-tracking branch 'origin/main' into aicore-e2e-tests
shibeshduw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import retry from 'async-retry'; | ||
import { | ||
AiDeployment, | ||
AiDeploymentList, | ||
DeploymentApi | ||
} from '@sap-ai-sdk/ai-api'; | ||
import { loadEnv } from './utils/load-env.js'; | ||
import { resourceGroup } from './utils/ai-api-utils.js'; | ||
|
||
loadEnv(); | ||
|
||
describe('DeploymentApi', () => { | ||
let createdDeploymentId: string | undefined; | ||
let initialState: AiDeploymentList | undefined; | ||
|
||
beforeAll(async () => { | ||
const queryResponse = await DeploymentApi.deploymentQuery( | ||
{}, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
expect(queryResponse).toBeDefined(); | ||
initialState = queryResponse; | ||
}); | ||
|
||
it('should create a deployment and wait for it to run', async () => { | ||
const createResponse = await DeploymentApi.deploymentCreate( | ||
{ configurationId: '54cc966d-8bc1-44ab-a9dc-658d59ef205d' }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
|
||
expect(createResponse).toEqual( | ||
expect.objectContaining({ | ||
message: 'Deployment scheduled.', | ||
id: expect.anything() | ||
}) | ||
); | ||
|
||
const runningDeployment = await waitForDeploymentToReachStatus( | ||
createResponse.id, | ||
'RUNNING' | ||
); | ||
|
||
expect(runningDeployment).toEqual( | ||
expect.objectContaining({ | ||
status: 'RUNNING', | ||
deploymentUrl: expect.any(String) | ||
}) | ||
); | ||
|
||
createdDeploymentId = runningDeployment.id; | ||
}, 180000); | ||
|
||
it('should modify the deployment to stop it', async () => { | ||
const deploymentId = getDeploymentId(createdDeploymentId); | ||
|
||
const modifyResponse = await DeploymentApi.deploymentModify( | ||
deploymentId, | ||
{ targetStatus: 'STOPPED' }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
|
||
expect(modifyResponse).toEqual( | ||
expect.objectContaining({ | ||
message: 'Deployment modification scheduled' | ||
}) | ||
); | ||
|
||
const stoppedDeployment = await waitForDeploymentToReachStatus( | ||
deploymentId, | ||
'STOPPED' | ||
); | ||
|
||
expect(stoppedDeployment).toEqual( | ||
expect.objectContaining({ | ||
status: 'STOPPED' | ||
}) | ||
); | ||
}, 180000); | ||
|
||
it('should delete the deployment', async () => { | ||
const deploymentId = getDeploymentId(createdDeploymentId); | ||
const deleteResponse = await DeploymentApi.deploymentDelete(deploymentId, { | ||
'AI-Resource-Group': resourceGroup | ||
}).execute(); | ||
|
||
expect(deleteResponse).toEqual( | ||
expect.objectContaining({ | ||
message: 'Deletion scheduled' | ||
}) | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
getDeploymentId(createdDeploymentId); | ||
// Wait for deletion to complete | ||
await new Promise(r => setTimeout(r, 15000)); | ||
const queryResponse = await DeploymentApi.deploymentQuery( | ||
{}, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
expect(queryResponse).toBeDefined(); | ||
|
||
const sanitizedInitialState = sanitizedState(initialState); | ||
const sanitizedEndState = sanitizedState(queryResponse); | ||
expect(sanitizedEndState).toStrictEqual(sanitizedInitialState); | ||
}, 30000); | ||
}); | ||
|
||
const sanitizedState = (state: AiDeploymentList | undefined) => ({ | ||
...state, | ||
resources: state?.resources.map( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
({ modifiedAt, ...rest }) => rest | ||
) | ||
}); | ||
|
||
function getDeploymentId(id: string | undefined): string { | ||
if (id === undefined) { | ||
throw new Error('deploymentId is not defined.'); | ||
} | ||
return id; | ||
} | ||
|
||
async function waitForDeploymentToReachStatus( | ||
deploymentId: string, | ||
targetStatus: 'RUNNING' | 'STOPPED' | ||
): Promise<AiDeployment> { | ||
return retry( | ||
async () => { | ||
const deploymentDetail = await DeploymentApi.deploymentGet( | ||
deploymentId, | ||
{}, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
|
||
if (deploymentDetail.status === targetStatus) { | ||
return deploymentDetail; | ||
} | ||
throw new Error(`Deployment has not yet reached ${targetStatus} status.`); | ||
}, | ||
{ | ||
retries: 30, | ||
minTimeout: 5000 | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ScenarioApi } from '@sap-ai-sdk/ai-api'; | ||
import { loadEnv } from './utils/load-env.js'; | ||
import { resourceGroup } from './utils/ai-api-utils.js'; | ||
|
||
loadEnv(); | ||
|
||
describe('ScenarioApi', () => { | ||
it('should get list of available scenarios', async () => { | ||
const scenarios = await ScenarioApi.scenarioQuery({ | ||
'AI-Resource-Group': resourceGroup | ||
}).execute(); | ||
|
||
expect(scenarios).toBeDefined(); | ||
const foundationModel = scenarios.resources.find( | ||
scenario => scenario.id === 'foundation-models' | ||
); | ||
expect(foundationModel).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* @internal | ||
*/ | ||
export const resourceGroup = 'ai-sdk-js-e2e'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import dotenv from 'dotenv'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const loadEnv = (): void => { | ||
// Pick .env file from e2e root directory | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
dotenv.config({ path: path.resolve(__dirname, '../../.env') }); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the idea here is that later on this can be used to fetch a deployment ID in case it does not exist, right?