@@ -15,10 +15,11 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
15
15
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
16
16
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock' ;
17
17
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel' ;
18
- import { CellKind , NotebookData , TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
18
+ import { CellKind , IOutputDto , NotebookData , NotebookSetting , TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
19
19
import { NotebookFileWorkingCopyModel } from 'vs/workbench/contrib/notebook/common/notebookEditorModel' ;
20
20
import { INotebookSerializer , INotebookService , SimpleNotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookService' ;
21
21
import { setupInstantiationService } from 'vs/workbench/contrib/notebook/test/browser/testNotebookEditor' ;
22
+ import { SnapshotContext } from 'vs/workbench/services/workingCopy/common/fileWorkingCopy' ;
22
23
23
24
suite ( 'NotebookFileWorkingCopyModel' , function ( ) {
24
25
@@ -63,7 +64,7 @@ suite('NotebookFileWorkingCopyModel', function () {
63
64
configurationService
64
65
) ) ;
65
66
66
- await model . snapshot ( CancellationToken . None ) ;
67
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
67
68
assert . strictEqual ( callCount , 1 ) ;
68
69
}
69
70
@@ -84,7 +85,7 @@ suite('NotebookFileWorkingCopyModel', function () {
84
85
) ,
85
86
configurationService
86
87
) ) ;
87
- await model . snapshot ( CancellationToken . None ) ;
88
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
88
89
assert . strictEqual ( callCount , 1 ) ;
89
90
}
90
91
} ) ;
@@ -119,7 +120,7 @@ suite('NotebookFileWorkingCopyModel', function () {
119
120
configurationService
120
121
) ) ;
121
122
122
- await model . snapshot ( CancellationToken . None ) ;
123
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
123
124
assert . strictEqual ( callCount , 1 ) ;
124
125
}
125
126
@@ -140,7 +141,7 @@ suite('NotebookFileWorkingCopyModel', function () {
140
141
) ,
141
142
configurationService
142
143
) ) ;
143
- await model . snapshot ( CancellationToken . None ) ;
144
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
144
145
assert . strictEqual ( callCount , 1 ) ;
145
146
}
146
147
} ) ;
@@ -174,7 +175,7 @@ suite('NotebookFileWorkingCopyModel', function () {
174
175
configurationService
175
176
) ) ;
176
177
177
- await model . snapshot ( CancellationToken . None ) ;
178
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
178
179
assert . strictEqual ( callCount , 1 ) ;
179
180
}
180
181
@@ -195,10 +196,52 @@ suite('NotebookFileWorkingCopyModel', function () {
195
196
) ,
196
197
configurationService
197
198
) ) ;
198
- await model . snapshot ( CancellationToken . None ) ;
199
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
199
200
assert . strictEqual ( callCount , 1 ) ;
200
201
}
201
202
} ) ;
203
+
204
+ test ( 'Notebooks with outputs beyond the size threshold will throw for backup snapshots' , async function ( ) {
205
+ const outputLimit = 100 ;
206
+ await configurationService . setUserConfiguration ( NotebookSetting . outputBackupSizeLimit , outputLimit * 1.0 / 1024 ) ;
207
+ const largeOutput : IOutputDto = { outputId : '123' , outputs : [ { mime : Mimes . text , data : VSBuffer . fromString ( 'a' . repeat ( outputLimit + 1 ) ) } ] } ;
208
+ const notebook = instantiationService . createInstance ( NotebookTextModel ,
209
+ 'notebook' ,
210
+ URI . file ( 'test' ) ,
211
+ [ { cellKind : CellKind . Code , language : 'foo' , mime : 'foo' , source : 'foo' , outputs : [ largeOutput ] , metadata : { foo : 123 , bar : 456 } } ] ,
212
+ { } ,
213
+ { transientCellMetadata : { } , transientDocumentMetadata : { } , cellContentMetadata : { } , transientOutputs : false , }
214
+ ) ;
215
+ disposables . add ( notebook ) ;
216
+
217
+ let callCount = 0 ;
218
+ const model = disposables . add ( new NotebookFileWorkingCopyModel (
219
+ notebook ,
220
+ mockNotebookService ( notebook ,
221
+ new class extends mock < INotebookSerializer > ( ) {
222
+ override options : TransientOptions = { transientOutputs : true , transientDocumentMetadata : { } , transientCellMetadata : { bar : true } , cellContentMetadata : { } } ;
223
+ override async notebookToData ( notebook : NotebookData ) {
224
+ callCount += 1 ;
225
+ assert . strictEqual ( notebook . cells [ 0 ] . metadata ! . foo , 123 ) ;
226
+ assert . strictEqual ( notebook . cells [ 0 ] . metadata ! . bar , undefined ) ;
227
+ return VSBuffer . fromString ( '' ) ;
228
+ }
229
+ }
230
+ ) ,
231
+ configurationService
232
+ ) ) ;
233
+
234
+ try {
235
+ await model . snapshot ( SnapshotContext . Backup , CancellationToken . None ) ;
236
+ assert . fail ( 'Expected snapshot to throw an error for large output' ) ;
237
+ } catch ( e ) {
238
+ assert . notEqual ( e . code , 'ERR_ASSERTION' , e . message ) ;
239
+ }
240
+
241
+ await model . snapshot ( SnapshotContext . Save , CancellationToken . None ) ;
242
+ assert . strictEqual ( callCount , 1 ) ;
243
+
244
+ } ) ;
202
245
} ) ;
203
246
204
247
function mockNotebookService ( notebook : NotebookTextModel , notebookSerializer : INotebookSerializer ) {
0 commit comments