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

Commit b9b652d

Browse files
author
Chris McConnell
authored
Fixes #1149 (#1162)
Adds tests to make sure that merge works properly when getting failures. Co-authored-by: Chris McConnell <chrimc>
1 parent edada32 commit b9b652d

File tree

6 files changed

+72
-23
lines changed

6 files changed

+72
-23
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dialog/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@types/seedrandom": "~2.4.28",
7474
"chai": "^4.2.0",
7575
"mocha": "^6.2.2",
76+
"nock": "^13.0.11",
7677
"nyc": "^14.1.1",
7778
"rimraf": "^2.6.3",
7879
"ts-node": "^9.0.0",

packages/dialog/src/library/schemaMerger.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ export class SchemaMerger {
556556
return
557557
}
558558
this.log('Parsing component .schema files')
559+
let triedMetaSchema = false
559560
for (const componentPath of componentPaths) {
560561
try {
561562
const path = componentPath.path
@@ -576,14 +577,17 @@ export class SchemaMerger {
576577
if (!component.$schema) {
577578
this.missingSchemaError()
578579
} else if (!this.metaSchema) {
579-
// Pick up meta-schema from first .dialog file
580-
this.metaSchemaId = component.$schema
581-
this.currentFile = this.metaSchemaId
582-
this.metaSchema = await getJSON(component.$schema)
583-
this.validator.addSchema(this.metaSchema, 'componentSchema')
584-
this.vlog(` Using ${this.metaSchemaId} to define components`)
585-
this.currentFile = path
586-
this.validateSchema(component)
580+
if (!triedMetaSchema) {
581+
// Pick up meta-schema from first .dialog file and if failed don't try again
582+
triedMetaSchema = true
583+
this.metaSchemaId = component.$schema
584+
this.currentFile = this.metaSchemaId
585+
this.metaSchema = await getJSON(component.$schema)
586+
this.validator.addSchema(this.metaSchema, 'componentSchema')
587+
this.vlog(` Using ${this.metaSchemaId} to define components`)
588+
this.currentFile = path
589+
this.validateSchema(component)
590+
}
587591
} else if (component.$schema !== this.metaSchemaId) {
588592
this.parsingWarning(`Component schema ${component.$schema} does not match ${this.metaSchemaId}`)
589593
} else {
@@ -902,13 +906,13 @@ export class SchemaMerger {
902906
}
903907
return exts
904908
}
905-
909+
906910
// Ensure kinds in policies exist and we expand to any extensions
907911
private validateAndExpandPolicies(): void {
908912
walkJSON(this.definitions, (val, _obj, path) => {
909913
if (val.$policies?.requiresKind) {
910914
let expanded: string[] = []
911-
for(const kind of val.$policies.requiresKind) {
915+
for (const kind of val.$policies.requiresKind) {
912916
if (!this.definitions[kind]) {
913917
this.genericError(`Error ${path} has non-existent $kind ${kind}`)
914918
}
@@ -1499,7 +1503,7 @@ export class SchemaMerger {
14991503
* @param canOverride True if definition can override extension.
15001504
*/
15011505
private mergeInto(extensionName: string, definition: any, canOverride?: boolean) {
1502-
const extension = this.definitions[extensionName] || this.metaSchema.definitions[extensionName]
1506+
const extension = this.definitions[extensionName] || this.metaSchema?.definitions[extensionName]
15031507
if (!extension) {
15041508
this.mergingError(`Cannot extend ${extensionName} because it is not included`)
15051509
} else {

packages/dialog/test/commands/dialog/merge.test.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import 'mocha'
1111
import * as os from 'os'
1212
import * as ppath from 'path'
1313
import * as merger from '../../../src/library/schemaMerger'
14+
const nock = require('nock')
15+
1416
let srcDir = ppath.resolve('test/commands/dialog/')
1517
let tempDir = ppath.join(os.tmpdir(), 'test.out')
1618

@@ -142,6 +144,21 @@ describe('dialog:merge', async () => {
142144
await compareToOracle('app.schema')
143145
})
144146

147+
it('missing component schema', async () => {
148+
console.log('Start missing component schema')
149+
let [merged, lines] = await merge(['schemas/badSchemas/missingComponent.schema'], 'app.schema')
150+
assert(!merged, 'Merge should have failed')
151+
assert(countMatches(/file does not exist/i, lines) === 1, 'No missing component schema')
152+
})
153+
154+
it('mismatched component schema', async () => {
155+
console.log('Start missing component schema')
156+
let [merged, lines] = await merge(['schemas/*.schema', 'schemas/badSchemas/missingComponent.schema'], 'app.schema')
157+
assert(merged, 'Could not merge')
158+
assert(countMatches(/error|warning/i, lines) === 1, 'Too many errors or warnings')
159+
assert(countMatches(/does not match/i, lines) === 1, 'No mismatched component schema')
160+
})
161+
145162
it('bad json', async () => {
146163
console.log('\nStart bad json')
147164
let [merged, lines] = await merge(['schemas/*.schema', 'schemas/badSchemas/badJson.schema'])
@@ -441,15 +458,18 @@ describe('dialog:merge', async () => {
441458
}
442459
})
443460

444-
/* Example of invoking library through test because of issues with launch.json
445-
it('botbuilder-schema', async () => {
446-
console.log('\nStart botbuilder-schema')
447-
let [merged, lines] = await merge(['../../../../../../botbuilder-dotnet/libraries/**\*.schema',
448-
'../../../../../../botbuilder-dotnet/tests/**\*.schema'], 'sdk.schema', true)
449-
console.log(merged)
450-
console.log(lines)
461+
it('500 error', async () => {
462+
console.log('Start 500 error')
463+
const scope = nock('https://schemas.botframework.com')
464+
.get(/schemas/)
465+
.reply(500, 'Internal Server Error')
466+
.persist()
467+
let [merged, lines] = await merge(['schemas/*.schema'], 'app.schema')
468+
assert(!merged, 'Merging should fail')
469+
assert(countMatches(/internal server error/i, lines) === 1, 'Did not detect server error')
470+
scope.done()
471+
nock.cleanAll()
451472
})
452-
*/
453473
})
454474

455475
/* TODO: These tests are related to verify and need to be updated and moved there.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema1",
3+
"properties": {
4+
"name": {
5+
"type": "string"
6+
}
7+
}
8+
}

packages/dialog/test/commands/dialog/verify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('dialog:verify', () => {
2929
expect(ctx.stderr.match(/DLG002/)!.length == 3, 'Wrong number of multiple definitions')
3030
expect(ctx.stderr.match(/DLG003/)!.length == 1, 'Wrong number of mising definitions')
3131
expect(ctx.stderr.match(/DLG004/)!.length == 1, 'Wrong number of type mismatches')
32-
expect(ctx.stderr.match(/DLG005/)!.length == 6, 'Wrong number of unsued ids')
32+
expect(ctx.stderr.match(/DLG005/)!.length == 6, 'Wrong number of unused ids')
3333
expect(ctx.stdout).to.contain('4 files')
3434
expect(ctx.stderr)
3535
.to.contain('Warnings: 2', 'Wrong number of warnings')

0 commit comments

Comments
 (0)