-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deployment config for AI command (#137)
Fixes issue #132
- Loading branch information
1 parent
c6d190e
commit 83ff883
Showing
14 changed files
with
146 additions
and
36 deletions.
There are no files selected for viewing
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
117 changes: 117 additions & 0 deletions
117
packages/genesys-web-messaging-tester-cli/__tests__/commands/ai/configSectionLoaded.spec.ts
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,117 @@ | ||
import { readFileSync } from 'fs'; | ||
import { Command } from 'commander'; | ||
import { AiTestCommandDependencies } from '../../../src/commands/aiTest/createAiTestCommand'; | ||
import { createCli } from '../../../src/createCli'; | ||
import { OpenAI } from 'openai'; | ||
|
||
describe('Session Config', () => { | ||
let fsReadFileSync: jest.MockedFunction<typeof readFileSync>; | ||
|
||
let webMessengerSessionFactory: jest.Mocked< | ||
AiTestCommandDependencies['webMessengerSessionFactory'] | ||
>; | ||
let conversationFactory: jest.Mocked<AiTestCommandDependencies['conversationFactory']>; | ||
let mockOpenApiChatCompletions: jest.Mocked<Pick<OpenAI.Chat.Completions, 'create'>>; | ||
|
||
let cli: Command; | ||
|
||
beforeEach(() => { | ||
fsReadFileSync = jest.fn(); | ||
|
||
const webMessengerSession = { on: jest.fn(), close: jest.fn() }; | ||
webMessengerSessionFactory = jest.fn().mockReturnValue(webMessengerSession); | ||
|
||
const conversation = { waitForConversationToStart: jest.fn(), sendText: jest.fn() }; | ||
conversationFactory = jest.fn().mockReturnValue(conversation); | ||
|
||
const cliCommand = new Command().exitOverride(() => { | ||
throw new Error('CLI Command errored'); | ||
}); | ||
|
||
const scenarioTestCommand = new Command().exitOverride(() => { | ||
throw new Error('Scenario Test Command errored'); | ||
}); | ||
|
||
cli = createCli(cliCommand, undefined, { | ||
command: scenarioTestCommand, | ||
fsReadFileSync, | ||
fsAccessSync: jest.fn(), | ||
webMessengerSessionFactory, | ||
openAiChatCompletionFactory: () => mockOpenApiChatCompletions, | ||
conversationFactory, | ||
processEnv: { OPENAI_API_KEY: 'test' }, | ||
}); | ||
}); | ||
|
||
test('session config in Test Script loaded', async () => { | ||
fsReadFileSync.mockReturnValue(` | ||
config: | ||
deploymentId: test-deployment-id-1 | ||
region: test-region-1 | ||
origin: test-origin-1 | ||
scenarios: | ||
Test: | ||
setup: | ||
prompt: Test prompt | ||
terminatingPhrases: | ||
pass: ["PASS"] | ||
fail: ["FAIL"] | ||
`); | ||
const completion: OpenAI.Chat.ChatCompletion = { | ||
choices: [{ message: { role: 'system', content: 'PASS' }, finish_reason: 'stop', index: 0 }], | ||
created: 0, | ||
id: '', | ||
model: '', | ||
object: '', | ||
}; | ||
|
||
mockOpenApiChatCompletions = { create: jest.fn().mockResolvedValue(completion) }; | ||
|
||
await cli.parseAsync([...['node', '/path/to/cli'], 'ai', ...['/test/path']]); | ||
|
||
expect(webMessengerSessionFactory).toHaveBeenCalledWith({ | ||
deploymentId: 'test-deployment-id-1', | ||
region: 'test-region-1', | ||
origin: 'test-origin-1', | ||
}); | ||
}); | ||
|
||
test('session config not necessary if session config args provided', async () => { | ||
fsReadFileSync.mockReturnValue(` | ||
scenarios: | ||
Test: | ||
setup: | ||
prompt: Test prompt | ||
terminatingPhrases: | ||
pass: ["PASS"] | ||
fail: ["FAIL"] | ||
`); | ||
|
||
const completion: OpenAI.Chat.ChatCompletion = { | ||
choices: [{ message: { role: 'system', content: 'PASS' }, finish_reason: 'stop', index: 0 }], | ||
created: 0, | ||
id: '', | ||
model: '', | ||
object: '', | ||
}; | ||
|
||
mockOpenApiChatCompletions = { | ||
create: jest.fn().mockResolvedValue(completion), | ||
}; | ||
|
||
await cli.parseAsync([ | ||
...['node', '/path/to/cli'], | ||
'ai', | ||
...['--deployment-id', 'test-deployment-id-2'], | ||
...['--region', 'test-region-2'], | ||
...['--origin', 'test-origin-2'], | ||
...['/test/path'], | ||
]); | ||
|
||
expect(webMessengerSessionFactory).toHaveBeenCalledWith({ | ||
deploymentId: 'test-deployment-id-2', | ||
region: 'test-region-2', | ||
origin: 'test-origin-2', | ||
}); | ||
}); | ||
}); |
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
4 changes: 2 additions & 2 deletions
4
...amlTestScript/configSectionLoaded.spec.ts → ...amlTestScript/configSectionLoaded.spec.ts
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
2 changes: 1 addition & 1 deletion
2
...TestScript/configSectionValidated.spec.ts → ...TestScript/configSectionValidated.spec.ts
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
2 changes: 1 addition & 1 deletion
2
...cenarios/scenarioSectionValidated.spec.ts → ...cenarios/scenarioSectionValidated.spec.ts
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
2 changes: 1 addition & 1 deletion
2
...Command/yamlTestScript/testScript.spec.ts → ...cripted/yamlTestScript/testScript.spec.ts
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
2 changes: 1 addition & 1 deletion
2
.../yamlTestScript/yamlFileValidated.spec.ts → .../yamlTestScript/yamlFileValidated.spec.ts
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
2 changes: 1 addition & 1 deletion
2
...ages/genesys-web-messaging-tester-cli/src/commands/aiTest/prompt/shouldEndConversation.ts
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