Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 7efaf27

Browse files
authored
bf luis:build support to republish luis app if users specify a new publishing mode (#1145)
* support republish for publishing mode changes only * fix typo * optimize
1 parent 52a7916 commit 7efaf27

File tree

2 files changed

+213
-2
lines changed

2 files changed

+213
-2
lines changed

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,14 @@ export class Builder {
236236
const dialogFile = path.join(path.dirname(content.path), `${content.name}.dialog`)
237237
let recognizer = new Recognizer(content.path, content.name, dialogFile, schema)
238238

239+
// found existing app endpoints
240+
let appEndpoints
239241
// find if there is a matched name with current app under current authoring key
240242
if (!recognizer.getAppId()) {
241243
for (let app of apps) {
242244
if (app.name.toLowerCase() === currentApp.name.toLowerCase()) {
243245
recognizer.setAppId(app.id)
246+
appEndpoints = app.endpoints
244247
break
245248
}
246249
}
@@ -252,7 +255,7 @@ export class Builder {
252255
// otherwise create a new application
253256
if (recognizer.getAppId() && recognizer.getAppId() !== '') {
254257
// To see if need update the model
255-
needTrainAndPublish = await this.updateApplication(currentApp, luBuildCore, recognizer, timeBucketOfRequests, keptVersionCount)
258+
needTrainAndPublish = await this.updateApplication(currentApp, luBuildCore, recognizer, timeBucketOfRequests, keptVersionCount) || this.forcePublish(appEndpoints, recognizer.versionId, directVersionPublish, isStaging)
256259
} else {
257260
// create a new application
258261
needTrainAndPublish = await this.createApplication(currentApp, luBuildCore, recognizer, timeBucketOfRequests)
@@ -456,7 +459,7 @@ export class Builder {
456459
this.handler(`${recognizer.getLuPath()} publishing version=${recognizer.versionId}\n`)
457460
await delay(timeBucket)
458461
await luBuildCore.publishApplication(recognizer.getAppId(), recognizer.versionId, isStaging, directVersionPublish)
459-
this.handler(`${recognizer.getLuPath()} publishing finished for ${isStaging ? 'Staging' : 'Production'} slot\n`)
462+
this.handler(`${recognizer.getLuPath()} publishing finished for ${directVersionPublish ? 'directVersionPublish mode' : isStaging ? 'Staging slot' : 'Production slot'}\n`)
460463
}
461464

462465
generateDeclarativeAssets(assets: Array<any>): Array<any> {
@@ -504,4 +507,17 @@ export class Builder {
504507
app.intents = filteredIntents
505508
}
506509
}
510+
511+
forcePublish(endpoints: any, versionId: string, directVersionPublish: boolean, isStaging: boolean) {
512+
let forcePublish = false
513+
if (endpoints !== undefined) {
514+
if (directVersionPublish && !Object.keys(endpoints).find(version => version.includes(versionId))
515+
|| !directVersionPublish && (isStaging && (!endpoints.STAGING || endpoints.STAGING.versionId !== versionId)
516+
|| !isStaging && (!endpoints.PRODUCTION || endpoints.PRODUCTION.versionId !== versionId))) {
517+
forcePublish = true
518+
}
519+
}
520+
521+
return forcePublish
522+
}
507523
}

packages/luis/test/commands/luis/build.test.ts

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,201 @@ describe('luis:build update application succeed when utterances added', () => {
286286
})
287287
})
288288

289+
describe('luis:build update application succeed when only publishing mode changes(Production slot to directVersionPublish mode)', () => {
290+
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.en-us.lu.json')
291+
before(function () {
292+
nock('https://westus.api.cognitive.microsoft.com')
293+
.get(uri => uri.includes('apps'))
294+
.reply(200, [{
295+
name: 'test(development)-sandwich.en-us.lu',
296+
id: 'f8c64e2a-8635-3a09-8f78-39d7adc76ec5',
297+
endpoints: {
298+
PRODUCTION: {
299+
versionId: '0.1'
300+
}
301+
}
302+
}])
303+
304+
nock('https://westus.api.cognitive.microsoft.com')
305+
.get(uri => uri.includes('apps'))
306+
.reply(200, {
307+
name: 'test(development)-sandwich.en-us.lu',
308+
id: 'f8c64e2a-8635-3a09-8f78-39d7adc76ec5',
309+
activeVersion: '0.1'
310+
})
311+
312+
nock('https://westus.api.cognitive.microsoft.com')
313+
.get(uri => uri.includes('export'))
314+
.reply(200, existingLuisApp)
315+
316+
nock('https://westus.api.cognitive.microsoft.com')
317+
.post(uri => uri.includes('train'))
318+
.reply(202, {
319+
statusId: 2,
320+
status: 'UpToDate'
321+
})
322+
323+
nock('https://westus.api.cognitive.microsoft.com')
324+
.get(uri => uri.includes('train'))
325+
.reply(200, [{
326+
modelId: '99999',
327+
details: {
328+
statusId: 0,
329+
status: 'Success',
330+
exampleCount: 0
331+
}
332+
}])
333+
334+
nock('https://westus.api.cognitive.microsoft.com')
335+
.post(uri => uri.includes('publish'))
336+
.reply(201, {
337+
versionId: '0.1',
338+
isStaging: false
339+
})
340+
})
341+
342+
test
343+
.stdout()
344+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--directVersionPublish'])
345+
.it('should update a luis application when only publishing mode changes(Production slot to directVersionPublish mode)', ctx => {
346+
expect(ctx.stdout).to.contain('Handling applications...')
347+
expect(ctx.stdout).to.contain('training version=0.1')
348+
expect(ctx.stdout).to.contain('waiting for training for version=0.1')
349+
expect(ctx.stdout).to.contain('publishing version=0.1')
350+
expect(ctx.stdout).to.contain('publishing finished for directVersionPublish mode')
351+
})
352+
})
353+
354+
describe('luis:build update application succeed when only publishing mode changes(directVersionPublish mode to Production slot)', () => {
355+
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.en-us.lu.json')
356+
before(function () {
357+
nock('https://westus.api.cognitive.microsoft.com')
358+
.get(uri => uri.includes('apps'))
359+
.reply(200, [{
360+
name: 'test(development)-sandwich.en-us.lu',
361+
id: 'f8c64e2a-8635-3a09-8f78-39d7adc76ec5',
362+
endpoints: {
363+
"v0.1": {
364+
versionId: '0.1'
365+
}
366+
}
367+
}])
368+
369+
nock('https://westus.api.cognitive.microsoft.com')
370+
.get(uri => uri.includes('apps'))
371+
.reply(200, {
372+
name: 'test(development)-sandwich.en-us.lu',
373+
id: 'f8c64e2a-8635-3a09-8f78-39d7adc76ec5',
374+
activeVersion: '0.1'
375+
})
376+
377+
nock('https://westus.api.cognitive.microsoft.com')
378+
.get(uri => uri.includes('export'))
379+
.reply(200, existingLuisApp)
380+
381+
nock('https://westus.api.cognitive.microsoft.com')
382+
.post(uri => uri.includes('train'))
383+
.reply(202, {
384+
statusId: 2,
385+
status: 'UpToDate'
386+
})
387+
388+
nock('https://westus.api.cognitive.microsoft.com')
389+
.get(uri => uri.includes('train'))
390+
.reply(200, [{
391+
modelId: '99999',
392+
details: {
393+
statusId: 0,
394+
status: 'Success',
395+
exampleCount: 0
396+
}
397+
}])
398+
399+
nock('https://westus.api.cognitive.microsoft.com')
400+
.post(uri => uri.includes('publish'))
401+
.reply(201, {
402+
versionId: '0.1',
403+
isStaging: false
404+
})
405+
})
406+
407+
test
408+
.stdout()
409+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development'])
410+
.it('should update a luis application when only publishing mode changes(directVersionPublish mode to Production slot)', ctx => {
411+
expect(ctx.stdout).to.contain('Handling applications...')
412+
expect(ctx.stdout).to.contain('training version=0.1')
413+
expect(ctx.stdout).to.contain('waiting for training for version=0.1')
414+
expect(ctx.stdout).to.contain('publishing version=0.1')
415+
expect(ctx.stdout).to.contain('publishing finished for Production slot')
416+
})
417+
})
418+
419+
describe('luis:build update application succeed when only publishing mode changes(Production slot to Staging slot)', () => {
420+
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.en-us.lu.json')
421+
before(function () {
422+
nock('https://westus.api.cognitive.microsoft.com')
423+
.get(uri => uri.includes('apps'))
424+
.reply(200, [{
425+
name: 'test(development)-sandwich.en-us.lu',
426+
id: 'f8c64e2a-8635-3a09-8f78-39d7adc76ec5',
427+
endpoints: {
428+
PRODUCTION: {
429+
versionId: '0.1'
430+
}
431+
}
432+
}])
433+
434+
nock('https://westus.api.cognitive.microsoft.com')
435+
.get(uri => uri.includes('apps'))
436+
.reply(200, {
437+
name: 'test(development)-sandwich.en-us.lu',
438+
id: 'f8c64e2a-8635-3a09-8f78-39d7adc76ec5',
439+
activeVersion: '0.1'
440+
})
441+
442+
nock('https://westus.api.cognitive.microsoft.com')
443+
.get(uri => uri.includes('export'))
444+
.reply(200, existingLuisApp)
445+
446+
nock('https://westus.api.cognitive.microsoft.com')
447+
.post(uri => uri.includes('train'))
448+
.reply(202, {
449+
statusId: 2,
450+
status: 'UpToDate'
451+
})
452+
453+
nock('https://westus.api.cognitive.microsoft.com')
454+
.get(uri => uri.includes('train'))
455+
.reply(200, [{
456+
modelId: '99999',
457+
details: {
458+
statusId: 0,
459+
status: 'Success',
460+
exampleCount: 0
461+
}
462+
}])
463+
464+
nock('https://westus.api.cognitive.microsoft.com')
465+
.post(uri => uri.includes('publish'))
466+
.reply(201, {
467+
versionId: '0.1',
468+
isStaging: false
469+
})
470+
})
471+
472+
test
473+
.stdout()
474+
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/sandwich/lufiles/sandwich.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--isStaging'])
475+
.it('should update a luis application when only publishing mode changes(Production slot to Staging slot)', ctx => {
476+
expect(ctx.stdout).to.contain('Handling applications...')
477+
expect(ctx.stdout).to.contain('training version=0.1')
478+
expect(ctx.stdout).to.contain('waiting for training for version=0.1')
479+
expect(ctx.stdout).to.contain('publishing version=0.1')
480+
expect(ctx.stdout).to.contain('publishing finished for Staging slot')
481+
})
482+
})
483+
289484
describe('luis:build not update application if no changes', () => {
290485
const existingLuisApp = require('./../../fixtures/testcases/lubuild/sandwich/luis/test(development)-sandwich.en-us.lu.json')
291486
before(function () {

0 commit comments

Comments
 (0)