Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FileUpdateType } from '../../../src/models/bot/interface';
import { Path } from '../../../src/utility/path';

import { LuPublisher } from './../../../src/models/bot/luPublisher';
Expand All @@ -20,7 +21,7 @@ describe('luis status management', () => {
await luPublisher.loadStatus(['bot1/a.lu', 'bot1/b.lu', 'bot1/Main.lu']);
const oldUpdateTime = luPublisher.status['bot1/a.lu'].lastUpdateTime;

await luPublisher.onFileChange('bot1/a.lu', 'update');
await luPublisher.onFileChange('bot1/a.lu', FileUpdateType.UPDATE);
const newUpdateTime = luPublisher.status['bot1/a.lu'].lastUpdateTime;
// update should increase the update time
expect(newUpdateTime).toBeGreaterThan(oldUpdateTime);
Expand All @@ -33,14 +34,32 @@ describe('get unpublishedFiles', () => {
{
diagnostics: [],
id: 'a',
relativePath: '/bot1/a.lu',
relativePath: 'bot1/a.lu',
content: '',
parsedContent: {},
},
{
diagnostics: [],
id: 'b',
relativePath: 'bot1/b.lu',
content: '',
parsedContent: {},
},
];

const luPublisher = new LuPublisher(botDir, storage);
luPublisher.loadStatus(['/bot1/a.lu']); // relative path is key
const files = await luPublisher.getUnpublisedFiles(lufiles);
await luPublisher.loadStatus(['bot1/a.lu', 'bot1/b.lu']); // relative path is key

let files = await luPublisher.getUnpublisedFiles(lufiles);
expect(files.length).toBe(2);
const curTime = Date.now();
luPublisher.status['bot1/a.lu'].lastPublishTime = curTime; // assumming we publish a.lu
luPublisher.status['bot1/b.lu'].lastPublishTime = curTime; // and b.lu
files = await luPublisher.getUnpublisedFiles(lufiles);
expect(files.length).toBe(0);

await luPublisher.onFileChange('bot1/a.lu', FileUpdateType.UPDATE);
files = await luPublisher.getUnpublisedFiles(lufiles);
expect(files.length).toBe(1);
});
});
18 changes: 9 additions & 9 deletions Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { copyDir } from '../../utility/storage';
import StorageService from '../../services/storage';

import { IFileStorage } from './../storage/interface';
import { LocationRef, FileInfo, LGFile, Dialog, LUFile, ILuisConfig, LuisStatus } from './interface';
import { LocationRef, FileInfo, LGFile, Dialog, LUFile, ILuisConfig, LuisStatus, FileUpdateType } from './interface';
import { DialogIndexer } from './indexers/dialogIndexers';
import { LGIndexer } from './indexers/lgIndexer';
import { LUIndexer } from './indexers/luIndexer';
Expand Down Expand Up @@ -219,7 +219,7 @@ export class BotProject {
if (!isUpdate) return this.luIndexer.getLuFiles();

await this._updateFile(luFile.relativePath, content);
await this.luPublisher.onFileChange(luFile.relativePath, 'update');
await this.luPublisher.onFileChange(luFile.relativePath, FileUpdateType.UPDATE);

return this.mergeLuStatus(this.luIndexer.getLuFiles(), this.luPublisher.status);
};
Expand All @@ -233,7 +233,7 @@ export class BotProject {

// TODO: validate before save
await this._createFile(relativePath, content);
await this.luPublisher.onFileChange(relativePath, 'create'); // let publisher know that some files changed
await this.luPublisher.onFileChange(relativePath, FileUpdateType.CREATE); // let publisher know that some files changed
return this.mergeLuStatus(this.luIndexer.getLuFiles(), this.luPublisher.status); // return a merged LUFile always
};

Expand All @@ -242,8 +242,8 @@ export class BotProject {
if (luFile === undefined) {
throw new Error(`no such lu file ${id}`);
}
this._removeFile(luFile.relativePath);
await this.luPublisher.onFileChange(luFile.relativePath, 'delete');
await this._removeFile(luFile.relativePath);
await this.luPublisher.onFileChange(luFile.relativePath, FileUpdateType.DELETE);
return this.mergeLuStatus(this.luIndexer.getLuFiles(), this.luPublisher.status);
};

Expand All @@ -252,8 +252,8 @@ export class BotProject {
};

public publishLuis = async () => {
const refered = this.luIndexer.getLuFiles().filter(this.isReferred);
const unpublished = await this.luPublisher.getUnpublisedFiles(refered);
const referred = this.luIndexer.getLuFiles().filter(this.isReferred);
const unpublished = await this.luPublisher.getUnpublisedFiles(referred);

const invalidLuFile = unpublished.filter(file => file.diagnostics.length !== 0);
if (invalidLuFile.length !== 0) {
Expand All @@ -271,7 +271,7 @@ export class BotProject {
await this.luPublisher.publish(unpublished);
}
} catch (error) {
throw new Error(error);
throw error;
}
return this.mergeLuStatus(this.luIndexer.getLuFiles(), this.luPublisher.status);
};
Expand Down Expand Up @@ -480,7 +480,7 @@ export class BotProject {
};

private generateErrorMessage = (invalidLuFile: LUFile[]) => {
invalidLuFile.reduce((msg, file) => {
return invalidLuFile.reduce((msg, file) => {
const fileErrorText = file.diagnostics.reduce((text, diagnostic) => {
text += `\n ${diagnostic.text}`;
return text;
Expand Down
6 changes: 5 additions & 1 deletion Composer/packages/server/src/models/bot/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export interface LuisStatus {
}

// we will probably also use this interface to consolidate the processing of lu\lg\dialog
export type FileUpdateType = 'create' | 'update' | 'delete';
export enum FileUpdateType {
CREATE = 'create',
UPDATE = 'update',
DELETE = 'delete',
}

export interface ILuisConfig {
name: string;
Expand Down
9 changes: 4 additions & 5 deletions Composer/packages/server/src/models/bot/luPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class LuPublisher {
};
}
});

return this.status;
};

Expand All @@ -55,16 +54,16 @@ export class LuPublisher {

public onFileChange = async (relativePath: string, type: FileUpdateType) => {
switch (type) {
case 'create':
case FileUpdateType.CREATE:
this.status[relativePath] = {
lastUpdateTime: Date.now(),
lastPublishTime: 0, // unpublished
};
break;
case 'update':
case FileUpdateType.UPDATE:
this.status[relativePath].lastUpdateTime = Date.now();
break;
case 'delete':
case FileUpdateType.DELETE:
delete this.status[relativePath];
break;
}
Expand Down Expand Up @@ -100,7 +99,7 @@ export class LuPublisher {
return files.filter(f => {
return (
!this.status[f.relativePath] ||
this.status[f.relativePath].lastPublishTime < this.status[f.relativePath].lastUpdateTime
this.status[f.relativePath].lastPublishTime <= this.status[f.relativePath].lastUpdateTime
);
});
};
Expand Down