botium-core 1.13.0 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/botium-cjs.js +88 -63
- package/dist/botium-cjs.js.map +1 -1
- package/dist/botium-es.js +107 -82
- package/dist/botium-es.js.map +1 -1
- package/package.json +15 -15
- package/src/helpers/RetryHelper.js +13 -7
- package/src/scripting/Convo.js +20 -0
- package/src/scripting/logichook/LogicHookUtils.js +1 -1
- package/test/convo/retryconvo.spec.js +134 -0
- package/test/logichooks/hookfromsrc.spec.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "botium-core",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "The Selenium for Chatbots",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/botium-es.js",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://www.botium.ai",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@babel/runtime": "^7.18.
|
|
35
|
+
"@babel/runtime": "^7.18.6",
|
|
36
36
|
"async": "^3.2.4",
|
|
37
37
|
"body-parser": "^1.20.0",
|
|
38
38
|
"boolean": "^3.2.0",
|
|
39
39
|
"bottleneck": "^2.19.5",
|
|
40
|
-
"csv-parse": "^5.
|
|
40
|
+
"csv-parse": "^5.3.0",
|
|
41
41
|
"debug": "^4.3.4",
|
|
42
42
|
"esprima": "^4.0.1",
|
|
43
43
|
"express": "^4.18.1",
|
|
44
44
|
"globby": "11.0.4",
|
|
45
|
-
"ioredis": "^5.0
|
|
45
|
+
"ioredis": "^5.1.0",
|
|
46
46
|
"is-class": "^0.0.9",
|
|
47
47
|
"is-json": "^2.0.1",
|
|
48
48
|
"jsonpath": "^1.1.1",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"markdown-it": "^13.0.1",
|
|
51
51
|
"mime-types": "^2.1.35",
|
|
52
52
|
"mkdirp": "^1.0.4",
|
|
53
|
-
"moment": "^2.29.
|
|
53
|
+
"moment": "^2.29.4",
|
|
54
54
|
"mustache": "^4.2.0",
|
|
55
55
|
"promise-retry": "^2.0.1",
|
|
56
56
|
"promise.allsettled": "^1.0.5",
|
|
@@ -65,33 +65,33 @@
|
|
|
65
65
|
"swagger-jsdoc": "^6.2.1",
|
|
66
66
|
"swagger-ui-express": "^4.4.0",
|
|
67
67
|
"uuid": "^8.3.2",
|
|
68
|
-
"vm2": "^3.9.
|
|
68
|
+
"vm2": "^3.9.10",
|
|
69
69
|
"write-yaml": "^1.0.0",
|
|
70
70
|
"xlsx": "^0.18.5",
|
|
71
71
|
"xregexp": "^5.1.1",
|
|
72
72
|
"yaml": "^2.1.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@babel/core": "^7.18.
|
|
76
|
-
"@babel/node": "^7.18.
|
|
77
|
-
"@babel/plugin-transform-runtime": "^7.18.
|
|
78
|
-
"@babel/preset-env": "^7.18.
|
|
75
|
+
"@babel/core": "^7.18.6",
|
|
76
|
+
"@babel/node": "^7.18.6",
|
|
77
|
+
"@babel/plugin-transform-runtime": "^7.18.6",
|
|
78
|
+
"@babel/preset-env": "^7.18.6",
|
|
79
79
|
"chai": "^4.3.6",
|
|
80
80
|
"chai-as-promised": "^7.1.1",
|
|
81
81
|
"cross-env": "^7.0.3",
|
|
82
|
-
"eslint": "^8.
|
|
82
|
+
"eslint": "^8.19.0",
|
|
83
83
|
"eslint-config-standard": "^17.0.0",
|
|
84
84
|
"eslint-plugin-import": "^2.26.0",
|
|
85
|
-
"eslint-plugin-n": "^15.2.
|
|
85
|
+
"eslint-plugin-n": "^15.2.4",
|
|
86
86
|
"eslint-plugin-promise": "^6.0.0",
|
|
87
87
|
"eslint-plugin-standard": "^4.1.0",
|
|
88
88
|
"license-checker": "^25.0.1",
|
|
89
89
|
"license-compatibility-checker": "^0.3.5",
|
|
90
90
|
"mocha": "^10.0.0",
|
|
91
|
-
"nock": "^13.2.
|
|
92
|
-
"npm-check-updates": "^
|
|
91
|
+
"nock": "^13.2.8",
|
|
92
|
+
"npm-check-updates": "^15.2.6",
|
|
93
93
|
"nyc": "^15.1.0",
|
|
94
|
-
"rollup": "^2.
|
|
94
|
+
"rollup": "^2.76.0",
|
|
95
95
|
"rollup-plugin-babel": "^4.4.0",
|
|
96
96
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
97
97
|
"rollup-plugin-json": "^4.0.0",
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
const util = require('util')
|
|
2
2
|
const _ = require('lodash')
|
|
3
|
+
const debug = require('debug')('botium-core-RetryHelper')
|
|
3
4
|
|
|
4
5
|
module.exports = class RetryHelper {
|
|
5
|
-
constructor (caps, section) {
|
|
6
|
-
this.retrySettings = {
|
|
7
|
-
retries: caps[`RETRY_${section.toUpperCase()}_NUMRETRIES`] || 1,
|
|
8
|
-
factor: caps[`RETRY_${section.toUpperCase()}_FACTOR`] || 1,
|
|
9
|
-
minTimeout: caps[`RETRY_${section.toUpperCase()}_MINTIMEOUT`] || 1000
|
|
10
|
-
}
|
|
6
|
+
constructor (caps, section, options = {}) {
|
|
11
7
|
this.retryErrorPatterns = []
|
|
12
8
|
const onErrorRegexp = caps[`RETRY_${section.toUpperCase()}_ONERROR_REGEXP`] || []
|
|
13
9
|
if (onErrorRegexp) {
|
|
@@ -22,10 +18,20 @@ module.exports = class RetryHelper {
|
|
|
22
18
|
this.retryErrorPatterns.push(onErrorRegexp)
|
|
23
19
|
}
|
|
24
20
|
}
|
|
21
|
+
|
|
22
|
+
// to turn on retries, NUMRETRIES or ONERROR_REGEXP has to be set
|
|
23
|
+
this.retrySettings = {
|
|
24
|
+
retries: caps[`RETRY_${section.toUpperCase()}_NUMRETRIES`] || (!_.isNil(options.numRetries) ? options.numRetries : (this.retryErrorPatterns.length === 0) ? 0 : 1),
|
|
25
|
+
factor: caps[`RETRY_${section.toUpperCase()}_FACTOR`] || (_.isNil(options.factor) ? 1 : options.factor),
|
|
26
|
+
minTimeout: caps[`RETRY_${section.toUpperCase()}_MINTIMEOUT`] || (_.isNil(options.minTimeout) ? 1000 : options.minTimeout)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
debug(`Retry for ${section} is ${this.retrySettings.retries > 0 ? 'enabled' : 'disabled'}. Settings: ${JSON.stringify(this.retrySettings)} Patterns: ${JSON.stringify(this.retryErrorPatterns.map(r => r.toString()))}`)
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
shouldRetry (err) {
|
|
28
|
-
if (!err
|
|
33
|
+
if (!err) return false
|
|
34
|
+
if (this.retryErrorPatterns.length === 0) return true
|
|
29
35
|
const errString = util.inspect(err)
|
|
30
36
|
for (const re of this.retryErrorPatterns) {
|
|
31
37
|
if (errString.match(re)) return true
|
package/src/scripting/Convo.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const util = require('util')
|
|
2
2
|
const _ = require('lodash')
|
|
3
3
|
const debug = require('debug')('botium-core-Convo')
|
|
4
|
+
const promiseRetry = require('promise-retry')
|
|
4
5
|
|
|
5
6
|
const BotiumMockMessage = require('../mocks/BotiumMockMessage')
|
|
6
7
|
const Capabilities = require('../Capabilities')
|
|
@@ -8,6 +9,7 @@ const Events = require('../Events')
|
|
|
8
9
|
const ScriptingMemory = require('./ScriptingMemory')
|
|
9
10
|
const { BotiumError, botiumErrorFromErr, botiumErrorFromList } = require('./BotiumError')
|
|
10
11
|
const { normalizeText, toString, removeBuffers, splitStringInNonEmptyLines } = require('./helper')
|
|
12
|
+
const RetryHelper = require('../helpers/RetryHelper')
|
|
11
13
|
|
|
12
14
|
const { LOGIC_HOOK_INCLUDE } = require('./logichook/LogicHookConsts')
|
|
13
15
|
|
|
@@ -210,6 +212,24 @@ class Convo {
|
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
async Run (container) {
|
|
215
|
+
const retryHelper = new RetryHelper(container.caps, 'CONVO')
|
|
216
|
+
return promiseRetry(async (retry, number) => {
|
|
217
|
+
return this.RunImpl(container).catch(err => {
|
|
218
|
+
const retryRemaining = retryHelper.retrySettings.retries - number + 1
|
|
219
|
+
if (retryHelper.shouldRetry(err)) {
|
|
220
|
+
debug(`Convo failed with error "${err.message || JSON.stringify(err)}". Retry ${retryRemaining > 0 ? 'enabled' : 'disabled'} (remaining #${retryRemaining}/${retryHelper.retrySettings.retries}, criterion matches)`)
|
|
221
|
+
retry(err)
|
|
222
|
+
} else {
|
|
223
|
+
if (retryHelper.retryErrorPatterns.length > 0) {
|
|
224
|
+
debug(`Convo failed with error "${err.message || JSON.stringify(err)}". Retry 'disabled' (remaining (#${retryRemaining}/${retryHelper.retrySettings.retries}), criterion does not match)`)
|
|
225
|
+
}
|
|
226
|
+
throw err
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
}, retryHelper.retrySettings)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async RunImpl (container) {
|
|
213
233
|
const transcript = new Transcript({
|
|
214
234
|
steps: [],
|
|
215
235
|
attachments: [],
|
|
@@ -192,7 +192,7 @@ module.exports = class LogicHookUtils {
|
|
|
192
192
|
})
|
|
193
193
|
return vm.run(script)
|
|
194
194
|
} catch (err) {
|
|
195
|
-
throw new Error(
|
|
195
|
+
throw new Error(`Script ${key} is not valid - ${err.message || err}`)
|
|
196
196
|
}
|
|
197
197
|
} else {
|
|
198
198
|
throw new Error(`Script "${key}" is not valid - only functions and javascript code accepted`)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const assert = require('chai').assert
|
|
3
|
+
const BotDriver = require('../../').BotDriver
|
|
4
|
+
const Capabilities = require('../../').Capabilities
|
|
5
|
+
|
|
6
|
+
const echoConnector = (numErrors, errorText) => ({ queueBotSays }) => {
|
|
7
|
+
let errors = 0
|
|
8
|
+
return {
|
|
9
|
+
UserSays (msg) {
|
|
10
|
+
if (errors >= numErrors) {
|
|
11
|
+
const botMsg = { sender: 'bot', sourceData: msg.sourceData, messageText: msg.messageText }
|
|
12
|
+
queueBotSays(botMsg)
|
|
13
|
+
} else {
|
|
14
|
+
errors++
|
|
15
|
+
return Promise.reject(errorText)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('convo.retries', function () {
|
|
22
|
+
beforeEach(async function () {
|
|
23
|
+
this.init = async (numErrors, errorText, errorPatterns, numRetries) => {
|
|
24
|
+
const myCaps = {
|
|
25
|
+
[Capabilities.PROJECTNAME]: 'convo.retry',
|
|
26
|
+
[Capabilities.CONTAINERMODE]: echoConnector(numErrors, errorText),
|
|
27
|
+
RETRY_CONVO_MINTIMEOUT: 10,
|
|
28
|
+
RETRY_CONVO_ONERROR_REGEXP: errorPatterns
|
|
29
|
+
}
|
|
30
|
+
if (!isNaN(numRetries)) {
|
|
31
|
+
myCaps.RETRY_CONVO_NUMRETRIES = numRetries
|
|
32
|
+
}
|
|
33
|
+
this.driver = new BotDriver(myCaps)
|
|
34
|
+
this.compiler = this.driver.BuildCompiler()
|
|
35
|
+
this.container = await this.driver.Build()
|
|
36
|
+
await this.container.Start()
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
afterEach(async function () {
|
|
40
|
+
await this.container.Stop()
|
|
41
|
+
await this.container.Clean()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should fail without retry', async function () {
|
|
45
|
+
await this.init(1, 'myerror')
|
|
46
|
+
|
|
47
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
48
|
+
try {
|
|
49
|
+
await this.compiler.convos[0].Run(this.container)
|
|
50
|
+
} catch (err) {
|
|
51
|
+
assert.isTrue(err.message.indexOf('myerror') >= 0)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
assert.fail('should have failed without retry')
|
|
55
|
+
})
|
|
56
|
+
it('should succeed after one retry with default numRetries', async function () {
|
|
57
|
+
await this.init(1, 'myerror', 'myerror')
|
|
58
|
+
|
|
59
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
60
|
+
await this.compiler.convos[0].Run(this.container)
|
|
61
|
+
})
|
|
62
|
+
it('should succeed after one retry with joker regex', async function () {
|
|
63
|
+
await this.init(1, 'myerror', null, 1)
|
|
64
|
+
|
|
65
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
66
|
+
await this.compiler.convos[0].Run(this.container)
|
|
67
|
+
})
|
|
68
|
+
it('should fail after one retry with default settings', async function () {
|
|
69
|
+
await this.init(2, 'myerror', 'myerror')
|
|
70
|
+
|
|
71
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
72
|
+
try {
|
|
73
|
+
await this.compiler.convos[0].Run(this.container)
|
|
74
|
+
} catch (err) {
|
|
75
|
+
assert.isTrue(err.message.indexOf('myerror') >= 0)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
assert.fail('should have failed after first retry')
|
|
79
|
+
})
|
|
80
|
+
it('should succeed after many retries', async function () {
|
|
81
|
+
await this.init(5, 'myerror', 'myerror', 5)
|
|
82
|
+
|
|
83
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
84
|
+
await this.compiler.convos[0].Run(this.container)
|
|
85
|
+
})
|
|
86
|
+
it('should succeed after too less retries', async function () {
|
|
87
|
+
await this.init(5, 'myerror', 'myerror', 4)
|
|
88
|
+
|
|
89
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
90
|
+
try {
|
|
91
|
+
await this.compiler.convos[0].Run(this.container)
|
|
92
|
+
} catch (err) {
|
|
93
|
+
assert.isTrue(err.message.indexOf('myerror') >= 0)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
assert.fail('should have failed after four retries')
|
|
97
|
+
})
|
|
98
|
+
it('should succeed after one retry with regexp pattern', async function () {
|
|
99
|
+
await this.init(1, 'myerror', /myeRRor/i)
|
|
100
|
+
|
|
101
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
102
|
+
await this.compiler.convos[0].Run(this.container)
|
|
103
|
+
})
|
|
104
|
+
it('should fail after one retry with unmatched regexp pattern', async function () {
|
|
105
|
+
await this.init(1, 'myerror', /myeRRor1/i)
|
|
106
|
+
|
|
107
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
108
|
+
try {
|
|
109
|
+
await this.compiler.convos[0].Run(this.container)
|
|
110
|
+
} catch (err) {
|
|
111
|
+
assert.isTrue(err.message.indexOf('myerror') >= 0)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
assert.fail('should have failed with unmatched retry pattern')
|
|
115
|
+
})
|
|
116
|
+
it('should succeed after one retry with regexp pattern array', async function () {
|
|
117
|
+
await this.init(1, 'myerror', [/myeRRor/i, /myeRRor1/i])
|
|
118
|
+
|
|
119
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
120
|
+
await this.compiler.convos[0].Run(this.container)
|
|
121
|
+
})
|
|
122
|
+
it('should fail after one retry with unmatched regexp pattern array', async function () {
|
|
123
|
+
await this.init(1, 'myerror', [/myeRRor1/i, /myeRRor2/i])
|
|
124
|
+
|
|
125
|
+
this.compiler.ReadScript(path.resolve(__dirname, 'convos'), '1step.convo.txt')
|
|
126
|
+
try {
|
|
127
|
+
await this.compiler.convos[0].Run(this.container)
|
|
128
|
+
} catch (err) {
|
|
129
|
+
assert.isTrue(err.message.indexOf('myerror') >= 0)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
assert.fail('should have failed with unmatched retry pattern')
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -69,7 +69,7 @@ describe('logichooks.hookfromsrc', function () {
|
|
|
69
69
|
await compiler.convos[0].Run(container)
|
|
70
70
|
assert.fail('it should have failed')
|
|
71
71
|
} catch (err) {
|
|
72
|
-
assert.isTrue(err.message.includes('Line 6: assertion error -
|
|
72
|
+
assert.isTrue(err.message.includes('Line 6: assertion error - Script assertConvoStep is not valid'))
|
|
73
73
|
}
|
|
74
74
|
})
|
|
75
75
|
})
|