diff --git a/extensions/notebook/src/book/bookTreeView.ts b/extensions/notebook/src/book/bookTreeView.ts index ddf6dc082b..b8fd09a741 100644 --- a/extensions/notebook/src/book/bookTreeView.ts +++ b/extensions/notebook/src/book/bookTreeView.ts @@ -110,10 +110,10 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider { let bookPathToTrust: string = bookTreeItem ? bookTreeItem.root : this.currentBook?.bookPath; if (bookPathToTrust) { - let trustChanged = this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true); + let trustChanged = await this._bookTrustManager.setBookAsTrusted(bookPathToTrust, true); if (trustChanged) { let notebookDocuments = azdata.nb.notebookDocuments; if (notebookDocuments) { diff --git a/extensions/notebook/src/book/bookTrustManager.ts b/extensions/notebook/src/book/bookTrustManager.ts index fb132aff42..b6547cbaa6 100644 --- a/extensions/notebook/src/book/bookTrustManager.ts +++ b/extensions/notebook/src/book/bookTrustManager.ts @@ -11,7 +11,7 @@ import { BookVersion } from './bookVersionHandler'; export interface IBookTrustManager { isNotebookTrustedByDefault(notebookUri: string): boolean; - setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean; + setBookAsTrusted(bookRootPath: string, isTrusted: boolean): Promise; } enum TrustBookOperation { @@ -58,7 +58,7 @@ export class BookTrustManager implements IBookTrustManager { .reduce((accumulator, currentBookItemList) => accumulator.concat(currentBookItemList), []); } - setBookAsTrusted(bookRootPath: string, isTrusted: boolean): boolean { + async setBookAsTrusted(bookRootPath: string, isTrusted: boolean): Promise { if (isTrusted) { return this.updateTrustedBooks(bookRootPath, TrustBookOperation.Add); } @@ -72,11 +72,11 @@ export class BookTrustManager implements IBookTrustManager { return trustedBookDirectories; } - setTrustedBookPathsInConfig(bookPaths: string[]) { + async setTrustedBookPathsInConfig(bookPaths: string[]): Promise { let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey); let storeInWorspace: boolean = this.hasWorkspaceFolders(); - void config.update(constants.trustedBooksConfigKey, bookPaths, storeInWorspace ? false : vscode.ConfigurationTarget.Global); + return config.update(constants.trustedBooksConfigKey, bookPaths, storeInWorspace ? false : vscode.ConfigurationTarget.Global); } hasWorkspaceFolders(): boolean { @@ -84,7 +84,7 @@ export class BookTrustManager implements IBookTrustManager { return workspaceFolders && workspaceFolders.length > 0; } - updateTrustedBooks(bookPath: string, operation: TrustBookOperation) { + async updateTrustedBooks(bookPath: string, operation: TrustBookOperation): Promise { let modifiedTrustedBooks = false; let bookPathToChange: string = path.join(bookPath, path.sep); @@ -110,7 +110,7 @@ export class BookTrustManager implements IBookTrustManager { modifiedTrustedBooks = true; } - this.setTrustedBookPathsInConfig(trustedBooks); + await this.setTrustedBookPathsInConfig(trustedBooks); return modifiedTrustedBooks; } diff --git a/extensions/notebook/src/extension.ts b/extensions/notebook/src/extension.ts index cd62836370..85cf66db79 100644 --- a/extensions/notebook/src/extension.ts +++ b/extensions/notebook/src/extension.ts @@ -51,7 +51,7 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openMarkdown', (resource: string) => bookTreeViewProvider.openMarkdown(resource))); extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openExternalLink', (resource: string) => bookTreeViewProvider.openExternalLink(resource))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.saveBook', () => providedBookTreeViewProvider.saveJupyterBooks())); - extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.trustBook', (item: BookTreeItem) => bookTreeViewProvider.trustBook(item))); + extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.trustBook', async (item: BookTreeItem) => await bookTreeViewProvider.trustBook(item))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchBook', (item: BookTreeItem) => bookTreeViewProvider.searchJupyterBooks(item))); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.searchProvidedBook', () => providedBookTreeViewProvider.searchJupyterBooks())); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.openBook', () => bookTreeViewProvider.openNewBook())); diff --git a/extensions/notebook/src/test/book/book.test.ts b/extensions/notebook/src/test/book/book.test.ts index a3ffd5387d..e886baaa94 100644 --- a/extensions/notebook/src/test/book/book.test.ts +++ b/extensions/notebook/src/test/book/book.test.ts @@ -210,17 +210,15 @@ describe('BooksTreeViewTests', function () { equalBookItems(notebook3, expectedNotebook3); }); - // {{SQL CARBON TODO}} - disable failing test - it.skip('should set notebooks trusted to true on trustBook', async () => { + it('should set notebooks trusted to true on trustBook', async () => { let notebook1Path = notebook1.tooltip; let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books); let isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path); should(isTrusted).equal(false, 'Notebook should not be trusted by default'); - bookTreeViewProvider.trustBook(notebook1); + await bookTreeViewProvider.trustBook(notebook1); isTrusted = bookTrustManager.isNotebookTrustedByDefault(notebook1Path); should(isTrusted).equal(true, 'Failed to set trust on trustBook'); - }); it('getNavigation should get previous and next urls correctly from the bookModel', async () => { diff --git a/extensions/notebook/src/test/book/bookTrustManager.test.ts b/extensions/notebook/src/test/book/bookTrustManager.test.ts index 922df6699b..a3704ddf58 100644 --- a/extensions/notebook/src/test/book/bookTrustManager.test.ts +++ b/extensions/notebook/src/test/book/bookTrustManager.test.ts @@ -182,7 +182,7 @@ describe('BookTrustManagerTests', function () { should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted'); // add another book subfolder - bookTrustManager.setBookAsTrusted('/SubFolder2/', true); + await bookTrustManager.setBookAsTrusted('/SubFolder2/', true); let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri); @@ -211,7 +211,7 @@ describe('BookTrustManagerTests', function () { }); it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => { - bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); let notebookUri = run.book1.notInTocNb; let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); @@ -222,8 +222,7 @@ describe('BookTrustManagerTests', function () { }); }); - // {{SQL CARBON TODO}} - reenable this test suite https://github.com/microsoft/azuredatastudio/issues/23540 - describe.skip('TrustingInFolder', () => { + describe('TrustingInFolder', () => { let bookTrustManager: IBookTrustManager; let books: BookModel[]; @@ -330,7 +329,7 @@ describe('BookTrustManagerTests', function () { }); it('should trust notebooks in a trusted book in a folder', async () => { - bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); let notebookUri1 = run.book1.notebook1; let notebookUri2 = run.book1.notebook2; @@ -345,7 +344,7 @@ describe('BookTrustManagerTests', function () { it('should NOT trust a notebook in an untrusted book in a folder', async () => { //Set book as not trusted before running test - bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false); let notebookUri = run.book2.notebook1; let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); @@ -355,13 +354,13 @@ describe('BookTrustManagerTests', function () { it('should trust notebook after book has been added to a folder', async () => { //Set book as not trusted before running test - bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', false); let notebookUri = run.book2.notebook1; let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri); should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted'); - bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true); let isNotebookTrustedAfterChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri); @@ -369,8 +368,8 @@ describe('BookTrustManagerTests', function () { }); it('should NOT trust a notebook when removing all books from folders', async () => { - bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); - bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder2/', true); let notebookUri = run.book1.notebook1; let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri); let notebook2Uri = run.book2.notebook1; @@ -396,7 +395,7 @@ describe('BookTrustManagerTests', function () { }); it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => { - bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); + await bookTrustManager.setBookAsTrusted('/temp/SubFolder/', true); let notebookUri = run.book1.notInTocNb; let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);