-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new validation pipeline - schema existence validation (#6645)
* add placeholder for schema validator * add schema validator pipeline with mocked fn * add schema visitor * display diagnostics data in debug panel * revert sdk.ts * decrease schema diagnostic severity to 'Warning' * optmize path join logic * impl a unified walker covers SwitchCondition * fix lint error: use BaseSchema * feat: disable actions without schema * wrap in useEffect * optimization: avoid frequent recoil submission * optimization: aggregate paths rather than updatedDialog to reduce time complexity * chore: comments & var name * lint * add comments Co-authored-by: Chris Whitten <[email protected]>
- Loading branch information
Showing
13 changed files
with
660 additions
and
2 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
79 changes: 79 additions & 0 deletions
79
...er/packages/client/src/pages/design/DebugPanel/TabExtensions/DiagnosticsTab/useAutoFix.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,79 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import get from 'lodash/get'; | ||
import set from 'lodash/set'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { useEffect } from 'react'; | ||
|
||
import { DiagnosticType, SchemaDiagnostic } from '../../../../diagnostics/types'; | ||
import { botProjectSpaceSelector, dispatcherState } from '../../../../../recoilModel'; | ||
|
||
import { useDiagnosticsData } from './useDiagnostics'; | ||
|
||
export const useAutoFix = () => { | ||
const diagnostics = useDiagnosticsData(); | ||
const botProjectSpace = useRecoilValue(botProjectSpaceSelector); | ||
const { updateDialog } = useRecoilValue(dispatcherState); | ||
|
||
// Auto fix schema absence by setting 'disabled' to true. | ||
useEffect(() => { | ||
const schemaDiagnostics = diagnostics.filter((d) => d.type === DiagnosticType.SCHEMA) as SchemaDiagnostic[]; | ||
/** | ||
* Aggregated diagnostic paths where contains schema problem | ||
* | ||
* Example: | ||
* { | ||
* // projectId | ||
* '2096.637': { | ||
* // dialogId | ||
* 'dialog-1': [ | ||
* 'triggers[0].actions[1]', // diagnostics.dialogPath | ||
* 'triggers[2].actions[3]' | ||
* ] | ||
* } | ||
* } | ||
*/ | ||
const aggregatedPaths: { [projectId: string]: { [dialogId: string]: string[] } } = {}; | ||
|
||
// Aggregates schema diagnostics by projectId, dialogId | ||
schemaDiagnostics.forEach((d) => { | ||
const { projectId, id: dialogId, dialogPath } = d; | ||
if (!dialogPath) return; | ||
const currentPaths = get(aggregatedPaths, [projectId, dialogId]); | ||
if (currentPaths) { | ||
currentPaths.push(dialogPath); | ||
} else { | ||
set(aggregatedPaths, [projectId, dialogId], [dialogPath]); | ||
} | ||
}); | ||
|
||
// Consumes aggregatedPaths to update dialogs in recoil store | ||
for (const [projectId, pathsByDialogId] of Object.entries(aggregatedPaths)) { | ||
// Locates dialogs in current project | ||
const dialogsInProject = botProjectSpace.find((bot) => bot.projectId === projectId)?.dialogs; | ||
if (!Array.isArray(dialogsInProject)) continue; | ||
|
||
for (const [dialogId, paths] of Object.entries(pathsByDialogId)) { | ||
// Queries out current dialog data | ||
const dialogData = dialogsInProject.find((dialog) => dialog.id === dialogId)?.content; | ||
if (!dialogData) continue; | ||
|
||
// Filters out those paths where action exists and action.disabled !== true | ||
const pathsToUpdate = paths.filter((p) => { | ||
const data = get(dialogData, p); | ||
return data && !get(data, 'disabled'); | ||
}); | ||
if (!pathsToUpdate.length) continue; | ||
|
||
// Manipulates the 'disabled' property and then submit to Recoil store. | ||
const copy = cloneDeep(dialogData); | ||
for (const p of pathsToUpdate) { | ||
set(copy, `${p}.disabled`, true); | ||
} | ||
updateDialog({ id: dialogId, projectId, content: copy }); | ||
} | ||
} | ||
}, [diagnostics]); | ||
}; |
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
50 changes: 50 additions & 0 deletions
50
...ser/packages/lib/indexers/__tests__/validations/schemaValidation/__mocks__/dialogMocks.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,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
export const sendActivityStub = { | ||
$kind: 'Microsoft.SendActivity', | ||
$designer: { | ||
id: 'AwT1u7', | ||
}, | ||
}; | ||
|
||
export const switchConditionStub = { | ||
$kind: 'Microsoft.SwitchCondition', | ||
$designer: { | ||
id: 'sJzdQm', | ||
}, | ||
default: [sendActivityStub], | ||
cases: [ | ||
{ | ||
value: 'case1', | ||
actions: [sendActivityStub], | ||
}, | ||
], | ||
}; | ||
|
||
export const onConversationUpdateActivityStub = { | ||
$kind: 'Microsoft.OnConversationUpdateActivity', | ||
$designer: { | ||
id: '376720', | ||
}, | ||
actions: [switchConditionStub], | ||
}; | ||
|
||
export const simpleGreetingDialog: any = { | ||
$kind: 'Microsoft.AdaptiveDialog', | ||
$designer: { | ||
$designer: { | ||
name: 'EmptyBot-1', | ||
description: '', | ||
id: '47yxe0', | ||
}, | ||
}, | ||
autoEndDialog: true, | ||
defaultResultProperty: 'dialog.result', | ||
triggers: [onConversationUpdateActivityStub], | ||
$schema: | ||
'https://raw.githubusercontent.com/microsoft/BotFramework-Composer/stable/Composer/packages/server/schemas/sdk.schema', | ||
generator: 'EmptyBot-1.lg', | ||
id: 'EmptyBot-1', | ||
recognizer: 'EmptyBot-1.lu.qna', | ||
}; |
20 changes: 20 additions & 0 deletions
20
Composer/packages/lib/indexers/__tests__/validations/schemaValidation/__mocks__/sdkSchema.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,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { SDKKinds } from '@botframework-composer/types'; | ||
|
||
import { | ||
AdaptiveDialogSchema, | ||
IfConditionSchema, | ||
OnConvUpdateSchema, | ||
OnDialogEventSchema, | ||
SwitchConditionSchema, | ||
} from './sdkSchemaMocks'; | ||
|
||
export const sdkSchemaDefinitionMock = { | ||
[SDKKinds.SwitchCondition]: SwitchConditionSchema, | ||
[SDKKinds.IfCondition]: IfConditionSchema, | ||
[SDKKinds.AdaptiveDialog]: AdaptiveDialogSchema, | ||
[SDKKinds.OnDialogEvent]: OnDialogEventSchema, | ||
[SDKKinds.OnConversationUpdateActivity]: OnConvUpdateSchema, | ||
}; |
Oops, something went wrong.