@@ -58,7 +58,7 @@ function createDebugFetch(args: { debugDir: string; replay?: boolean }): {
58
58
console . error ( ` Local size: ${ localData . length } , Upload size: ${ uploadData . length } ` ) ;
59
59
throw new Error ( `Xorb validation failed for ${ xorbFilename } ` ) ;
60
60
}
61
- console . log ( `✅ Xorb validation passed: ${ xorbFilename } ` ) ;
61
+ console . log ( `✅ Xorb validation passed: ${ xorbFilename } - xorb file is the same as generated previously ` ) ;
62
62
return new Response ( null , { status : 200 } ) ;
63
63
} else {
64
64
// In normal mode, save the data
@@ -85,13 +85,36 @@ function createDebugFetch(args: { debugDir: string; replay?: boolean }): {
85
85
if ( args . replay ) {
86
86
// In replay mode, compare with existing local file
87
87
const localData = await readFile ( shardPath ) ;
88
- if ( localData . length !== uploadData . length || ! localData . every ( ( byte , i ) => byte === uploadData [ i ] ) ) {
88
+ if ( localData . length !== uploadData . length ) {
89
89
console . error ( `❌ Shard data mismatch: ${ shardFilename } ` ) ;
90
90
console . error ( ` Local size: ${ localData . length } , Upload size: ${ uploadData . length } ` ) ;
91
91
throw new Error ( `Shard validation failed for ${ shardFilename } ` ) ;
92
92
}
93
- console . log ( `✅ Shard validation passed: ${ shardFilename } ` ) ;
94
- return new Response ( null , { status : 200 } ) ;
93
+
94
+ // Compare all bytes except footer bytes 104-112 (9 bytes from positions 104-112 inclusive)
95
+ const footerStart = Number (
96
+ new DataView ( localData . buffer ) . getBigUint64 ( localData . buffer . byteLength - 8 , true )
97
+ ) ;
98
+ // This is the shard timestamp
99
+ const toIgnoreStart = footerStart + 104 ;
100
+ const toIgnoreEnd = footerStart + 112 ;
101
+
102
+ const mismatch = localData . some ( ( byte , i ) => {
103
+ if ( i >= toIgnoreStart && i < toIgnoreEnd ) {
104
+ return false ;
105
+ }
106
+ return byte !== uploadData [ i ] ;
107
+ } ) ;
108
+
109
+ if ( mismatch ) {
110
+ console . error ( `❌ Shard data mismatch: ${ shardFilename } ` ) ;
111
+ console . error ( ` Local size: ${ localData . length } , Upload size: ${ uploadData . length } ` ) ;
112
+ throw new Error ( `Shard validation failed for ${ shardFilename } ` ) ;
113
+ }
114
+ console . log ( `✅ Shard validation passed: ${ shardFilename } - shard file is the same as generated previously` ) ;
115
+
116
+ // Do not mock the shard call
117
+ //return new Response(null, { status: 200 });
95
118
} else {
96
119
// In normal mode, save the data
97
120
await writeFile ( shardPath , uploadData ) ;
@@ -263,10 +286,6 @@ async function main() {
263
286
fetch : debugFetchObj . fetch ,
264
287
repo,
265
288
rev : "main" ,
266
- yieldCallback : ( event : { event : "fileProgress" ; path : string ; progress : number } ) => {
267
- const progress = ( event . progress * 100 ) . toFixed ( 1 ) ;
268
- console . log ( `📈 Progress for ${ event . path } : ${ progress } %` ) ;
269
- } ,
270
289
} ;
271
290
272
291
console . log ( `\n=== Starting debug upload for ${ filename } ===` ) ;
0 commit comments