Skip to content

Commit

Permalink
fix: support import sections check when publishing luis (#3154)
Browse files Browse the repository at this point in the history
* fix: support import section s check when publishing luis

* use empty flag to detect lu file content empty

* fix lint

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
Co-authored-by: Dong Lei <donglei@microsoft.com>
  • Loading branch information
3 people authored Jun 2, 2020
1 parent da45182 commit 74299ee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
13 changes: 12 additions & 1 deletion Composer/packages/client/__tests__/utils/luUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('getReferredFiles', () => {
const dialogs = [{ luFile: 'a' }] as DialogInfo[];
const diagnostics: Diagnostic[] = [];
const luFiles = [
{ id: 'a.en-us', diagnostics, content: 'test', intents: [{ Name: '1', Body: '1' }] },
{ id: 'a.en-us', diagnostics, content: 'test', intents: [{ Name: '1', Body: '1' }], empty: false },
{ id: 'b.en-us', diagnostics },
{ id: 'c.en-us', diagnostics },
] as LuFile[];
Expand All @@ -111,5 +111,16 @@ describe('getReferredFiles', () => {
expect(() => {
checkLuisPublish(luFiles, dialogs);
}).toThrowError(/wrong/);

luFiles[0].diagnostics = [];
luFiles[0].intents = [];
luFiles[0].empty = true;
expect(() => {
checkLuisPublish(luFiles, dialogs);
}).toThrowError('You have the following empty LuFile(s): a.en-us');

luFiles[0].empty = false;

expect(checkLuisPublish(luFiles, dialogs)[0].id).toEqual('a.en-us');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { LuActionType } from './../types';
const ctx: Worker = self as any;

const parse = (id: string, content: string) => {
const { intents, diagnostics } = luIndexer.parse(content, id);

return { id, content, intents, diagnostics };
return { id, content, ...luIndexer.parse(content, id) };
};

ctx.onmessage = function (msg) {
Expand Down
10 changes: 1 addition & 9 deletions Composer/packages/client/src/utils/luUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ function generateErrorMessage(invalidLuFile: LuFile[]) {
}, '');
}

function isLuFileEmpty(file: LuFile) {
const { content, intents } = file;
if (content && intents?.length) {
return false;
}
return true;
}

export function checkLuisPublish(luFiles: LuFile[], dialogs: DialogInfo[]) {
const referred = getReferredFiles(luFiles, dialogs);
const invalidLuFile = referred.filter(
Expand All @@ -170,7 +162,7 @@ export function checkLuisPublish(luFiles: LuFile[], dialogs: DialogInfo[]) {
const msg = generateErrorMessage(invalidLuFile);
throw new Error(`The Following LuFile(s) are invalid: \n` + msg);
}
const emptyLuFiles = referred.filter(isLuFileEmpty);
const emptyLuFiles = referred.filter((file) => file.empty);
if (emptyLuFiles.length !== 0) {
const msg = emptyLuFiles.map((file) => file.id).join(' ');
throw new Error(`You have the following empty LuFile(s): ` + msg);
Expand Down
4 changes: 2 additions & 2 deletions Composer/packages/lib/indexers/src/luIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function parse(content: string, id = ''): LuParsed {
});
const diagnostics = Errors.map((e) => convertLuDiagnostic(e, id));
return {
empty: !Sections.length,
intents,
diagnostics,
};
Expand All @@ -99,8 +100,7 @@ function index(files: FileInfo[]): LuFile[] {
const luFiles = filtered.map((file) => {
const { name, content } = file;
const id = getBaseName(name);
const { intents, diagnostics } = parse(content, id);
return { id, content, intents, diagnostics };
return { id, content, ...parse(content, id) };
});

return luFiles;
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/lib/shared/src/types/indexers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface LuIntentSection {
}

export interface LuParsed {
empty: boolean;
intents: LuIntentSection[];
diagnostics: Diagnostic[];
}
Expand All @@ -81,6 +82,7 @@ export interface LuFile {
content: string;
diagnostics: Diagnostic[];
intents: LuIntentSection[];
empty: boolean;
[key: string]: any;
}
export interface CodeRange {
Expand Down

0 comments on commit 74299ee

Please sign in to comment.