Skip to content

Commit

Permalink
fix for 1316 -- bf orchestrator:create error when passing in .dispatc…
Browse files Browse the repository at this point in the history
…h file as input (#1317) (#1319)

* fix for bug 1316

fix for bug 1316

* fixed failed test
  • Loading branch information
tsuwandy committed Nov 10, 2021
1 parent 2bd0fb9 commit 405c178
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
8 changes: 1 addition & 7 deletions packages/orchestrator/src/commands/orchestrator/create.ts
Expand Up @@ -63,13 +63,7 @@ export default class OrchestratorCreate extends Command {
const hasDataSources: boolean = settings.DataSources?.inputs?.length > 0 ?? false;
if (hasDataSources) {
hierarchical = true;
// do not override the input folder from the --in parameter
const inputPathSpecified: boolean = !Utility.isEmptyString(flags.in);
if (!inputPathSpecified && !Utility.isEmptyString(settings.DataSources.path)) {
input = settings.DataSources.path;
} else {
settings.DataSources.path = flags.in;
}
input = DataSourceHelper.getInputFolderPath(flags.in, cwd, settings.DataSources);
}

if (refresh) {
Expand Down
14 changes: 14 additions & 0 deletions packages/orchestratorlib/src/datasourcehelper.ts
Expand Up @@ -75,6 +75,20 @@ export class DataSourceHelper {
return path.extname(input) === '.dispatch';
}

public static getInputFolderPath(input: string, currentWorkingDir: string, dataSources: OrchestratorDataSourceSettings): string {
// do not override the input folder from the --in parameter
input = path.resolve(input);
if (Utility.isEmptyString(input) && !Utility.isEmptyString(dataSources.path)) {
input = dataSources.path;
} else if (OrchestratorHelper.isDirectory(input)) {
dataSources.path = input;
} else {
input = path.join(currentWorkingDir, 'dataSources');
dataSources.path = input;
}
return input;
}

public static async getQnAFileFromQnaKb(input: OrchestratorDataSource, endpoint: string = ''): Promise<any> {
const qna: any = await LuisQnaHelper.getQnaFromKb(input.Id, input.Key, endpoint);
return qna;
Expand Down
35 changes: 35 additions & 0 deletions packages/orchestratorlib/test/datasourcehelper.test.ts
@@ -0,0 +1,35 @@
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

import {} from 'mocha';
import {DataSourceHelper} from '../src/datasourcehelper';
import {OrchestratorDataSourceSettings} from '../src/settings';
import * as path from 'path';
import * as fs from 'fs-extra';
import assert = require('assert');

describe('DataSourceHelperTests', () => {
const cwd: string = process.cwd();
it('getInputFolderPathWithDispatchFileInput', () => {
const dataSourceSettings: OrchestratorDataSourceSettings = new OrchestratorDataSourceSettings([], true, '');
const input: string = DataSourceHelper.getInputFolderPath(path.join(cwd, 'test.Dispatch'), cwd, dataSourceSettings);
assert(input === path.join(cwd, 'dataSources'));
});

it('getInputFolderPathWithNoInputAndWithExistingOrchestratorSettingsFile', () => {
const dataSourceSettings: OrchestratorDataSourceSettings = new OrchestratorDataSourceSettings([], true, path.join(cwd, 'dataSources'));
const input: string = DataSourceHelper.getInputFolderPath('', cwd, dataSourceSettings);
assert(input === dataSourceSettings.path);
});

it('getInputFolderPathWithInputAndWithExistingOrchestratorSettingsFile', () => {
const inputPath: string = path.resolve('./test/fixtures/output/dataSources');
fs.mkdirSync(inputPath, {recursive: true});
const dataSourceSettings: OrchestratorDataSourceSettings = new OrchestratorDataSourceSettings([], true, path.join(cwd, 'dataSources'));
const input: string = DataSourceHelper.getInputFolderPath(inputPath, cwd, dataSourceSettings);
assert(input === inputPath);
assert(dataSourceSettings.path === inputPath);
});
});

0 comments on commit 405c178

Please sign in to comment.