@@ -3267,3 +3267,57 @@ fn apply_remote_pattern() -> Result<()> {
3267
3267
3268
3268
Ok ( ( ) )
3269
3269
}
3270
+
3271
+ #[ test]
3272
+ fn large_file_fails ( ) -> Result < ( ) > {
3273
+ let tempdir = tempfile:: tempdir ( ) ?;
3274
+ let large_file = tempdir. path ( ) . join ( "large.js" ) ;
3275
+
3276
+ // Create a large file with many console.log statements
3277
+ // Each line is about 50 bytes, so 25,000 lines = ~1.25MB
3278
+ let mut content = String :: with_capacity ( 1_250_000 ) ;
3279
+ for i in 0 ..25_000 {
3280
+ content. push_str ( & format ! ( "console.log('This is log message number {i} which should make the file quite large');\n " ) ) ;
3281
+ }
3282
+ content. push_str ( "console.error('This is an error message, at the end');" ) ;
3283
+ fs_err:: write ( & large_file, content) ?;
3284
+
3285
+ let mut apply_cmd = get_test_cmd ( ) ?;
3286
+ apply_cmd. current_dir ( tempdir. path ( ) ) ;
3287
+ apply_cmd
3288
+ . arg ( "apply" )
3289
+ . arg ( "`console.error` => `console.warn`" )
3290
+ . arg ( "large.js" ) ;
3291
+
3292
+ let output = apply_cmd. output ( ) ?;
3293
+ let stdout = String :: from_utf8 ( output. stdout ) ?;
3294
+ let stderr = String :: from_utf8 ( output. stderr ) ?;
3295
+
3296
+ println ! ( "stdout first time: {:?}" , stdout) ;
3297
+ println ! ( "stderr first time: {:?}" , stderr) ;
3298
+
3299
+ // Command should succeed but with a warning about file size
3300
+ assert ! ( output. status. success( ) ) ;
3301
+ assert ! ( stdout. contains( "Processed 1 files and found 0 matches" ) ) ;
3302
+
3303
+ // Verify that the file is unmodified
3304
+ let content: String = fs_err:: read_to_string ( large_file. clone ( ) ) ?;
3305
+ assert ! ( !content. contains( "console.warn" ) ) ;
3306
+
3307
+ println ! ( "Successfully ran the command the first time" ) ;
3308
+
3309
+ // Now run the command again, but with GRIT_MAX_FILE_SIZE=0
3310
+ let new_command = apply_cmd. env ( "GRIT_MAX_FILE_SIZE_BYTES" , "0" ) ;
3311
+ let output = new_command. output ( ) ?;
3312
+ let stdout = String :: from_utf8 ( output. stdout ) ?;
3313
+ let stderr = String :: from_utf8 ( output. stderr ) ?;
3314
+
3315
+ println ! ( "stdout second time: {:?}" , stdout) ;
3316
+ println ! ( "stderr second time: {:?}" , stderr) ;
3317
+
3318
+ // Verify that the file is modified
3319
+ let content: String = fs_err:: read_to_string ( large_file) ?;
3320
+ assert ! ( content. contains( "console.warn" ) ) ;
3321
+
3322
+ Ok ( ( ) )
3323
+ }
0 commit comments