Skip to content

Commit

Permalink
- доработана фича выявления изменений файлов интеграционных тестов (s…
Browse files Browse the repository at this point in the history
…pecial thanks @bobyboba18).
  • Loading branch information
DmitryOffsec committed Jul 19, 2024
1 parent cfd3733 commit a06f706
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 3.17.17 (Pre-Release)

- доработана фича выявления изменений файлов интеграционных тестов (special thanks @Bobyboba18).

## 3.17.16 (Pre-Release)

- добавлен провайдер Microsoft-Windows-Bits-Client для заполнения метаинформации (special thanks @d3f0x0).
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Language client",
"author": "Dmitry Fedosov (@DmitryOffsec)",
"license": "MIT",
"version": "3.17.16",
"version": "3.17.17",
"repository": {
"type": "git",
"url": "https://github.com/Security-Experts-Community/vscode-xp"
Expand Down
27 changes: 17 additions & 10 deletions client/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,27 @@ export class Logger extends ILogger {
}

public setLogLevel (logLevel: LogLevel) : void {
this._level = logLevel;
this.level = logLevel;
}

debug(message: string, ...params: any[]): void {
const logLevel = LogLevel.Debug;
if (this._level < logLevel) return;
if (this.level < logLevel) return;

this.writeLog(logLevel, message, ...params);
}

trace(message: string, ...params: any[]): void {
const logLevel = LogLevel.Trace;
if (this.level < logLevel) return;

this.writeLog(logLevel, message, ...params);
}

error(message: string, ...params: any[]): void
error(message: string, ex: Error, ...params: any[]): void {
const logLevel = LogLevel.Error;
if (this._level < logLevel) return;
if (this.level < logLevel) return;

if(ex) {
console.error(this.timestamp, message ?? "", ...params, ex);
Expand All @@ -70,14 +77,14 @@ export class Logger extends ILogger {
warn(message: string, ex?: Error, ...params: any[]): void
warn(message: string, ...params: any[]): void {
const logLevel = LogLevel.Warn;
if (this._level < logLevel) return;
if (this.level < logLevel) return;

this.writeLog(logLevel, message, ...params);
}

info(message: string, ...params: any[]): void {
const logLevel = LogLevel.Info;
if (this._level < logLevel) return;
if (this.level < logLevel) return;

this.writeLog(logLevel, message, ...params);
}
Expand Down Expand Up @@ -167,15 +174,15 @@ export class Logger extends ILogger {

public static init(config: Configuration) : Logger {
const log = new Logger(config);
// if(config.getExtensionMode() === vscode.ExtensionMode.Development) {
// log.setLogLevel(LogLevel.Debug);
// return log;
// }
if(config.getExtensionMode() === vscode.ExtensionMode.Development) {
log.setLogLevel(LogLevel.Trace);
return log;
}

log.setLogLevel(config.getLogLevel());
return log;
}

private _level: LogLevel;
private level: LogLevel;
private _output: vscode.OutputChannel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export class IntegrationTestEditorViewProvider {
);

this.config.getContext().subscriptions.push(this.testFilesWatcher);
this.testFilesWatcher.onDidChange(this.onExternalTestFilesModification);
this.testFilesWatcher.onDidCreate(this.onExternalTestFilesModification);
this.testFilesWatcher.onDidDelete(this.onExternalTestFilesModification);
this.testFilesWatcher.onDidChange(this.onExternalTestFilesModification, this);
this.testFilesWatcher.onDidCreate(this.onExternalTestFilesModification, this);
this.testFilesWatcher.onDidDelete(this.onExternalTestFilesModification, this);

this.directoriesFilesWatcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
Expand All @@ -131,7 +131,7 @@ export class IntegrationTestEditorViewProvider {
)
);
this.config.getContext().subscriptions.push(this.directoriesFilesWatcher);
this.directoriesFilesWatcher.onDidDelete(this.onExternalTestFilesModification);
this.directoriesFilesWatcher.onDidDelete(this.onExternalTestFilesModification, this);

this.view.webview.options = {
enableScripts: true
Expand All @@ -157,11 +157,14 @@ export class IntegrationTestEditorViewProvider {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
private async onExternalTestFilesModification(uri: vscode.Uri) : Promise<void>{
if(this.savingInProgress) {
private async onExternalTestFilesModification(uri: vscode.Uri) : Promise<void> {
if(IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS) {
Log.trace(`A file ${uri.fsPath} modification detected when working through the extension modification`);
return;
}

Log.trace(`A file ${uri.fsPath} modification detected by external programs modification has been detected`);

// Правило удалили
if(!fs.existsSync(this.rule.getDirectoryPath())) {
const usersResponse = await DialogHelper.showInfo(
Expand Down Expand Up @@ -338,7 +341,7 @@ export class IntegrationTestEditorViewProvider {
switch (message.command) {
case 'saveAllTests': {
try {
this.savingInProgress = true;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = true;
this.rule = await this.saveAllTests(message);
Log.info(`All tests of the rule are ${this.rule.getName()} saved`);
}
Expand All @@ -347,7 +350,7 @@ export class IntegrationTestEditorViewProvider {
return true;
}
finally {
this.savingInProgress = false;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = false;
}

break;
Expand Down Expand Up @@ -380,7 +383,7 @@ export class IntegrationTestEditorViewProvider {
// Команды с запуском утилит.
case "NormalizeRawEventsCommand": {
try {
this.savingInProgress = true;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = true;
if (typeof message?.isEnrichmentRequired !== "boolean" ) {
DialogHelper.showInfo("The event enrichment parameter is not set");
return true;
Expand All @@ -404,7 +407,7 @@ export class IntegrationTestEditorViewProvider {
ExceptionHelper.show(error, this.config.getMessage("View.IntegrationTests.Message.DefaultErrorEventsNormalization"));
}
finally {
this.savingInProgress = false;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = false;
}
break;
}
Expand Down Expand Up @@ -448,7 +451,7 @@ export class IntegrationTestEditorViewProvider {
}

try {
this.savingInProgress = true;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = true;
const selectedTestNumber = parseInt(message?.selectedTestNumber);
if (!selectedTestNumber) {
throw new XpException(`Переданное значение ${message?.activeTestNumber} не является номером интеграционного теста`);
Expand All @@ -470,7 +473,7 @@ export class IntegrationTestEditorViewProvider {
ExceptionHelper.show(error, 'Ошибка обновления ожидаемого события');
}
finally {
this.savingInProgress = false;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = false;
}
break;
}
Expand All @@ -483,6 +486,7 @@ export class IntegrationTestEditorViewProvider {
}

try {
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = true;
const selectedTestNumber = parseInt(message?.selectedTestNumber);
if (!selectedTestNumber) {
throw new XpException(`Переданное значение ${message?.activeTestNumber} не является номером интеграционного теста`);
Expand All @@ -504,14 +508,17 @@ export class IntegrationTestEditorViewProvider {
catch(error) {
ExceptionHelper.show(error, 'Ошибка обновления ожидаемого события');
}
finally {
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = false;
}
break;
}

case "RunIntegrationTestsCommand": {
// Сохраняем актуальное состояние тестов из вьюшки.
let rule: RuleBaseItem;
try {
this.savingInProgress = true;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = true;
rule = await this.saveAllTests(message);
Log.info(`All tests of the rule are ${this.rule.getName()} saved`);
}
Expand All @@ -520,11 +527,11 @@ export class IntegrationTestEditorViewProvider {
return true;
}
finally {
this.savingInProgress = false;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = false;
}

try {
this.savingInProgress = true;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = true;
await FileSystemHelper.recursivelyDeleteDirectory(this.testsTmpFilesPath);

const command = new RunIntegrationTestsCommand({
Expand All @@ -543,7 +550,7 @@ export class IntegrationTestEditorViewProvider {
ExceptionHelper.show(error, this.config.getMessage("View.IntegrationTests.Message.FailedToExecutionTests"));
}
finally {
this.savingInProgress = false;
IntegrationTestEditorViewProvider.SAVING_IN_PROGRESS = false;
}

return true;
Expand Down Expand Up @@ -649,7 +656,7 @@ export class IntegrationTestEditorViewProvider {
private directoriesFilesWatcher: vscode.FileSystemWatcher;

private testsTmpFilesPath: string;
private savingInProgress = false;

public static SAVING_IN_PROGRESS = false;
public static TEXTAREA_END_OF_LINE = "\n";
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Dmitry Fedosov (@DmitryOffsec)",
"icon": "resources/xp.png",
"license": "MIT",
"version": "3.17.16",
"version": "3.17.17",
"repository": {
"type": "git",
"url": "https://github.com/Security-Experts-Community/vscode-xp"
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "server",
"description": "Language server",
"version": "3.17.16",
"version": "3.17.17",
"author": "Dmitry Fedosov (@DmitryOffsec)",
"license": "MIT",
"engines": {
Expand Down

0 comments on commit a06f706

Please sign in to comment.