Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@assistant/conversation-testing
Advanced tools
This is an end-to-end testing library for developers building actions
This library provides an easy way to write automated tests for your Action. The library wraps the Actions API, enabling you to define a test suite, send queries to your Action, and make assertions on the output to verify information specific to your Action's conversational state.
The latest version of this library requires Node v10.13.0 or later. You can install the library with
npm install @assistant/conversation-testing --save
GOOGLE_APPLICATION_CREDENTIALS
environment variable: export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
Note: The examples below use Mocha as a testing framework. You can change the report style by overriding the Mocha report style. See more information in Mocha's reporter docs
Create file for your tests and define a test suite.
import 'mocha';
import {ActionsOnGoogleTestManager} from '@assistant/conversation-testing';
const PROJECT_ID = '<ACTION_PROJECT_ID>';
const TRIGGER_PHRASE = 'Talk to <ACTION_DISPLAY_NAME>';
describe('Test Suite', function() {
// Set the timeout for each test run to 60s.
this.timeout(60000);
let testManager;
before('Before all setup', async function() {
testManager = new ActionsOnGoogleTestManager({ projectId: PROJECT_ID });
await test.writePreviewFromDraft();
testManager.setSuiteLocale(DEFAULT_LOCALE);
testManager.setSuiteSurface(DEFAULT_SURFACE);
});
afterEach(function() {
testManager.cleanUpAfterTest();
});
});
Update the test suite to include various tests with queries and assertions related to your Action. Examples of updates include:
actions.intent.MAIN
intent, the correct scene is initialized, and the prompt for the scene is sent....
it('trigger only test', async function() {
await testManager.sendQuery(TRIGGER_PHRASE);
testManager.assertIntent('actions.intent.MAIN');
testManager.assertScene('Welcome');
testManager.assertSpeech('Welcome to Facts about Google!');
});
...
...
it('main functionality', async function() {
testManager.setTestLocale('en-GB');
await testManager.sendQuery(TRIGGER_PHRASE);
testManager.assertIntent('actions.intent.MAIN');
testManager.assertScene('Welcome');
testManager.assertSpeech('Welcome to Facts about Google!');
testManager.assertText(
'Welcome to .* about Google!', {isRegexp: true, isExact: true});
await testManager.sendQuery('Cats');
testManager.assertSpeech(['Oh great, cats!', 'Good choice cats!']);
testManager.assertIntent('cats');
testManager.assertSessionParam('categoryType', 'Cats');
await testManager.sendQuery('stop');
testManager.assertConversationEnded();
});
...
...
it('intent match testing', async function() {
await testManager.assertTopMatchedIntent('yes, I do', 'yes', 3, 'en');
});
...
Ensure you have set your service account key file to the GOOGLE_APPLICATION_CREDENTIALS
environment variable: export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
Run: npm install && npm run build && npm test
Note: You can use "npm test -- --bail" if you want to stop after the first failure.
This library provides functions to control your conversation, easily assert aspects of the response, setting Suite and Test level defaults, and more.
sendQuery(queryText)
- Sends a query to your action.sendStop()
- Sends a 'stop' query, to exit the action.assertSpeech(expected, assertParams?, response?)
- Asserts the expected
text is contained in the response Speech (concatenation of the first_simple
and last_simple Speech). Note: Through optional assertParams
it is
possible to require exact match, and/or allow regexp matching.assertText(expected, assertParams?, response?)
- Asserts the response Text
(concatenation of the first_simple and last_simple Text)assertScene(expected, response?)
- Asserts the response Scene, i.e. the
scene that is currently active in the conversationassertIntent(expected, response?)
- Asserts the response Intent, i.e. the
intent that was matched by the query phraseassertConversationEnded(response?)
- Asserts that the conversation ended
in the response.assertConversationNotEnded(response?)
- Asserts that the conversation did
not end in the response.assertSessionParam(name, expected, response?)
- Asserts the response
session storage parameter value.assertUserParam(name, expected, response?)
- Asserts the response user
storage parameter value.assertHomeParam(name, expected, response?)
- Asserts the response home
storage parameter value.assertCanvasURL(expected, response?)
- Asserts the Canvas URL.assertCanvasData(expected, requireExact?, response?)
- Asserts the Canvas
Data.assertCard(expected, requireExact?, response?)
- Asserts the Card
response.assertImage(expected, requireExact?, response?)
- Asserts the Image
response.assertCollection(expected, requireExact?, response?)
- Asserts the
Collection response.assertTable(expected, requireExact?, response?)
- Asserts the Table
response.assertList(expected, requireExact?, response?)
- Asserts the List
response.assertMedia(expected, requireExact?, response?)
- Asserts the Media
response.Note: All assertXXX
and getXXX
functions get optional response as a last
argument. If the response is not passed, the last turn response is used.
Note: You can use your own custom assertions on values using
Chai
, or any other node.js package, but the builtin
assertions are likely to be more convenient for you. You can also access the
full last turn response by calling getLatestResponse()
, and run any custom
checks on it.
getLatestResponse()
- Gets the latest turn full response.getSpeech(response?)
- Gets the response Speech (concatenation of the
first_simple and last_simple Speech)getText(response?)
- Gets the response Text (concatenation of the
first_simple and last_simple Text)getScene(response?)
- Gets the response Scene.getIntent(response?)
- Gets the response Intent.getIsConversationEnded(response?)
- Returns whether the conversation ended
in the response.getSessionParam(name, response?)
- Gets the response value of a session
storage parameter.getUserParam(name, response?)
- Gets the response value of a user storage
parameter.getHomeParam(name, response?)
- Gets the response value of a home storage
parameter.getCanvasURL(response?)
- Gets the Canvas URL.getCanvasData(response?)
- Gets the Canvas Data.getContent(response?)
- Gets the Prompt Content, if exists.getCard(response?)
- Gets the Prompt Card, if exists.getCollection(response?)
- Gets the Prompt Collection, if exists.getImage(response?)
- Gets the Prompt Image, if exists.getTable(response?)
- Gets the Prompt Table, if exists.getList(response?)
- Gets the Prompt List, if exists.getMedia(response?)
- Gets the Prompt Media, if exists.This are assertions that are run as standalone NLU versification (not in the context of conversation):
assertTopMatchedIntent(query, expectedIntent, place, queryLanguage)
-
Asserts the expected intent is in the top N matched intent to a given query,
in the given language.assertMatchIntentsFromYamlFile(yamlFile, queriesLanguage?)
- Checks all
the queries intent assertions in the yaml file.getMatchIntentsList(query, queryLanguage)
- Gets the matched intents'
names using the matchIntents API call.getMatchIntentsList(query, queryLanguage)
- Gets the intents for the
checked query using the matchIntents API call.Note: Make sure to set the language code and NOT locale code as the queryLanguage.
updatePreview
is failing on 'callUpdatePreview: Precondition check
failed', verify that you are able to simulate your Action in the console simulator.NO_INPUT
events is not supported.Please read and follow the steps in the CONTRIBUTING.md.
See LICENSE.
FAQs
This is an end-to-end testing library for developers building actions
We found that @assistant/conversation-testing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.