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

Commit 405c178

Browse files
authored
fix for 1316 -- bf orchestrator:create error when passing in .dispatch file as input (#1317) (#1319)
* fix for bug 1316 fix for bug 1316 * fixed failed test
1 parent 2bd0fb9 commit 405c178

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

packages/orchestrator/src/commands/orchestrator/create.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ export default class OrchestratorCreate extends Command {
6363
const hasDataSources: boolean = settings.DataSources?.inputs?.length > 0 ?? false;
6464
if (hasDataSources) {
6565
hierarchical = true;
66-
// do not override the input folder from the --in parameter
67-
const inputPathSpecified: boolean = !Utility.isEmptyString(flags.in);
68-
if (!inputPathSpecified && !Utility.isEmptyString(settings.DataSources.path)) {
69-
input = settings.DataSources.path;
70-
} else {
71-
settings.DataSources.path = flags.in;
72-
}
66+
input = DataSourceHelper.getInputFolderPath(flags.in, cwd, settings.DataSources);
7367
}
7468

7569
if (refresh) {

packages/orchestratorlib/src/datasourcehelper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ export class DataSourceHelper {
7575
return path.extname(input) === '.dispatch';
7676
}
7777

78+
public static getInputFolderPath(input: string, currentWorkingDir: string, dataSources: OrchestratorDataSourceSettings): string {
79+
// do not override the input folder from the --in parameter
80+
input = path.resolve(input);
81+
if (Utility.isEmptyString(input) && !Utility.isEmptyString(dataSources.path)) {
82+
input = dataSources.path;
83+
} else if (OrchestratorHelper.isDirectory(input)) {
84+
dataSources.path = input;
85+
} else {
86+
input = path.join(currentWorkingDir, 'dataSources');
87+
dataSources.path = input;
88+
}
89+
return input;
90+
}
91+
7892
public static async getQnAFileFromQnaKb(input: OrchestratorDataSource, endpoint: string = ''): Promise<any> {
7993
const qna: any = await LuisQnaHelper.getQnaFromKb(input.Id, input.Key, endpoint);
8094
return qna;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {} from 'mocha';
7+
import {DataSourceHelper} from '../src/datasourcehelper';
8+
import {OrchestratorDataSourceSettings} from '../src/settings';
9+
import * as path from 'path';
10+
import * as fs from 'fs-extra';
11+
import assert = require('assert');
12+
13+
describe('DataSourceHelperTests', () => {
14+
const cwd: string = process.cwd();
15+
it('getInputFolderPathWithDispatchFileInput', () => {
16+
const dataSourceSettings: OrchestratorDataSourceSettings = new OrchestratorDataSourceSettings([], true, '');
17+
const input: string = DataSourceHelper.getInputFolderPath(path.join(cwd, 'test.Dispatch'), cwd, dataSourceSettings);
18+
assert(input === path.join(cwd, 'dataSources'));
19+
});
20+
21+
it('getInputFolderPathWithNoInputAndWithExistingOrchestratorSettingsFile', () => {
22+
const dataSourceSettings: OrchestratorDataSourceSettings = new OrchestratorDataSourceSettings([], true, path.join(cwd, 'dataSources'));
23+
const input: string = DataSourceHelper.getInputFolderPath('', cwd, dataSourceSettings);
24+
assert(input === dataSourceSettings.path);
25+
});
26+
27+
it('getInputFolderPathWithInputAndWithExistingOrchestratorSettingsFile', () => {
28+
const inputPath: string = path.resolve('./test/fixtures/output/dataSources');
29+
fs.mkdirSync(inputPath, {recursive: true});
30+
const dataSourceSettings: OrchestratorDataSourceSettings = new OrchestratorDataSourceSettings([], true, path.join(cwd, 'dataSources'));
31+
const input: string = DataSourceHelper.getInputFolderPath(inputPath, cwd, dataSourceSettings);
32+
assert(input === inputPath);
33+
assert(dataSourceSettings.path === inputPath);
34+
});
35+
});

0 commit comments

Comments
 (0)