Skip to content

Commit ebd2a2f

Browse files
author
stephanbuettig
committed
fix: restore truncated files (null-byte removal cut content)
The previous null-byte cleanup (9210cb9) used tr -d which stripped null bytes but also truncated content that followed embedded nulls. 6 files were affected and are now restored from the verified local copy (808 tests passing): - ui-worker-api.ts: 288→321 lines (exportAsZip body was missing) - ui-worker.ts: 845→858 lines - zip-export-dialog.tsx: 851→864 lines - zip-export-service.ts: 371→393 lines - zip-manifest.ts: 77→79 lines - zip-export-service.spec.ts: 133→136 lines
1 parent 9210cb9 commit ebd2a2f

6 files changed

Lines changed: 87 additions & 5 deletions

File tree

src/components/view/zip-export-dialog.tsx

100755100644
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,4 +849,17 @@ export class ZipExportDialog extends React.Component<ZipExportDialogProps> {
849849
</PrimaryButton>
850850
: <PrimaryButton
851851
ref={this.submitButtonRef}
852-
on
852+
onClick={this.startExport}
853+
disabled={this.selectedCount === 0 || events.length === 0}
854+
>
855+
<Icon icon={['fas', 'file-archive']} />
856+
Download ZIP
857+
</PrimaryButton>
858+
}
859+
</div>
860+
</ModalFooter>
861+
</Modal>
862+
</Overlay>;
863+
}
864+
}
865+

src/model/ui/zip-export-service.ts

100755100644
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,25 @@ export class ZipExportController {
369369
runInAction(() => {
370370
if (!this.isCurrentRun(runId, runAbortController)) return;
371371
this.state = {
372-
372+
kind: 'error',
373+
message: e && e.message
374+
? String(e.message)
375+
: 'Unknown error during ZIP export.'
376+
};
377+
});
378+
} finally {
379+
if (this.isCurrentRun(runId, runAbortController)) {
380+
this.abortController = undefined;
381+
zipLog('run() finally: abortController cleaned up');
382+
}
383+
}
384+
}
385+
386+
@action.bound
387+
reset() {
388+
this.invalidateActiveRun();
389+
this.abortActiveRun();
390+
this.revokeActiveDownloadUrl();
391+
this.state = { kind: 'idle' };
392+
}
393+
}

src/model/ui/zip-manifest.ts

100755100644
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ export interface ZipExportManifest {
7575
*/
7676
errors: ZipExportErrorRecord[];
7777
/** Name of the HAR file included in the archive, if the HAR was bundled separately. */
78-
78+
harFile: string;
79+
}

src/services/ui-worker-api.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,36 @@ export async function exportAsZip(args: {
286286
snippetBodySizeLimit?: number;
287287
}): Promise<ZipExportResponse> {
288288
try {
289-
289+
return await callApi<ZipExportRequest, ZipExportResponse>(
290+
{
291+
type: 'zip-export',
292+
har: args.har,
293+
formats: args.formats,
294+
toolVersion: args.toolVersion,
295+
snippetBodySizeLimit: args.snippetBodySizeLimit
296+
},
297+
[],
298+
{
299+
signal: args.signal,
300+
onProgress: args.onProgress,
301+
cancelChannel: true,
302+
timeoutMs: ZIP_EXPORT_TIMEOUT_MS
303+
}
304+
);
305+
} catch (error: any) {
306+
// Keep the ZIP API contract stable: callers expect cancellation to
307+
// resolve as a cancelled response, not reject. `callApi` may reject
308+
// immediately on abort to avoid hangs before the worker yields.
309+
if (error?.name === 'AbortError') {
310+
return {
311+
id: -1,
312+
archive: new ArrayBuffer(0),
313+
cancelled: true,
314+
snippetSuccessCount: 0,
315+
snippetErrorCount: 0
316+
};
317+
}
318+
319+
throw error;
320+
}
321+
}

src/services/ui-worker.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,3 +843,16 @@ ctx.addEventListener('message', async (event: { data: BackgroundRequest }) => {
843843

844844
case 'zip-export-prewarm':
845845
prewarmZipExportPath();
846+
ctx.postMessage({ id: event.data.id, warmed: true } as ZipExportPrewarmResponse);
847+
break;
848+
849+
default:
850+
console.error('Unknown worker event', event);
851+
}
852+
} catch (e) {
853+
ctx.postMessage({
854+
id: event.data.id,
855+
error: serializeError(e)
856+
});
857+
}
858+
});

test/unit/model/ui/zip-export-service.spec.ts

100755100644
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,6 @@ describe('ZipExportController', () => {
131131
await runPromise;
132132

133133
expect(controller.state.kind).to.equal('idle');
134-
expect((window.URL.createObjectU
134+
expect((window.URL.createObjectURL as sinon.SinonStub).called).to.equal(false);
135+
});
136+
});

0 commit comments

Comments
 (0)