@empiricalrun/test-gen 0.79.2 → 0.79.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/agent/chat/exports.d.ts +1 -0
- package/dist/agent/chat/exports.d.ts.map +1 -1
- package/dist/agent/chat/exports.js +3 -1
- package/dist/agent/chat/index.js +1 -1
- package/dist/agent/chat/prompt/repo.d.ts.map +1 -1
- package/dist/agent/chat/prompt/repo.js +4 -3
- package/dist/agent/fast-triage/index.d.ts +8 -0
- package/dist/agent/fast-triage/index.d.ts.map +1 -0
- package/dist/agent/fast-triage/index.js +51 -0
- package/dist/agent/index.d.ts +2 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +4 -1
- package/dist/agent/triage/index.js +2 -2
- package/dist/bin/index.js +5 -3
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +3 -2
- package/dist/dashboard/client.d.ts +11 -1
- package/dist/dashboard/client.d.ts.map +1 -1
- package/dist/dashboard/client.js +22 -9
- package/dist/file-info/adapters/github/index.d.ts.map +1 -1
- package/dist/file-info/adapters/github/index.js +1 -1
- package/dist/generate-summary/frame-sampling.d.ts +12 -0
- package/dist/generate-summary/frame-sampling.d.ts.map +1 -0
- package/dist/generate-summary/frame-sampling.js +72 -0
- package/dist/generate-summary/generate-error-stack-summary.d.ts +11 -0
- package/dist/generate-summary/generate-error-stack-summary.d.ts.map +1 -0
- package/dist/generate-summary/generate-error-stack-summary.js +44 -0
- package/dist/generate-summary/generate-failed-step-screenshot-diff-summary.d.ts +58 -0
- package/dist/generate-summary/generate-failed-step-screenshot-diff-summary.d.ts.map +1 -0
- package/dist/generate-summary/generate-failed-step-screenshot-diff-summary.js +460 -0
- package/dist/generate-summary/generate-grouped-summary.d.ts +18 -0
- package/dist/generate-summary/generate-grouped-summary.d.ts.map +1 -0
- package/dist/generate-summary/generate-grouped-summary.js +91 -0
- package/dist/generate-summary/merge-summary.d.ts +16 -0
- package/dist/generate-summary/merge-summary.d.ts.map +1 -0
- package/dist/generate-summary/merge-summary.js +46 -0
- package/dist/generate-summary/pick-videos-for-comparison.d.ts +9 -0
- package/dist/generate-summary/pick-videos-for-comparison.d.ts.map +1 -0
- package/dist/generate-summary/pick-videos-for-comparison.js +54 -0
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +3 -1
- package/dist/tools/definitions/delete-file.js +1 -1
- package/dist/tools/definitions/grep.d.ts.map +1 -1
- package/dist/tools/definitions/grep.js +1 -1
- package/dist/tools/definitions/rename-file.js +2 -2
- package/dist/tools/definitions/safe-bash.d.ts.map +1 -1
- package/dist/tools/definitions/safe-bash.js +10 -8
- package/dist/tools/definitions/str_replace_editor.d.ts.map +1 -1
- package/dist/tools/definitions/str_replace_editor.js +12 -4
- package/dist/tools/definitions/trace-dot-zip.d.ts +7 -0
- package/dist/tools/definitions/trace-dot-zip.d.ts.map +1 -0
- package/dist/tools/definitions/trace-dot-zip.js +16 -0
- package/dist/tools/definitions/utils.js +1 -1
- package/dist/tools/delete-file/index.d.ts.map +1 -1
- package/dist/tools/delete-file/index.js +9 -6
- package/dist/tools/diagnosis-fetcher.d.ts.map +1 -1
- package/dist/tools/diagnosis-fetcher.js +40 -2
- package/dist/tools/fetch-file/index.d.ts.map +1 -1
- package/dist/tools/fetch-file/index.js +102 -3
- package/dist/tools/file-operations/index.d.ts.map +1 -1
- package/dist/tools/file-operations/index.js +7 -5
- package/dist/tools/file-operations/shared/helpers.d.ts +13 -0
- package/dist/tools/file-operations/shared/helpers.d.ts.map +1 -1
- package/dist/tools/file-operations/shared/helpers.js +24 -0
- package/dist/tools/file-operations/view/index.d.ts.map +1 -1
- package/dist/tools/file-operations/view/index.js +9 -3
- package/dist/tools/grep/index.d.ts.map +1 -1
- package/dist/tools/grep/index.js +7 -2
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +6 -6
- package/dist/tools/merge-conflicts/index.d.ts.map +1 -1
- package/dist/tools/merge-conflicts/index.js +8 -8
- package/dist/tools/rename-file/index.d.ts.map +1 -1
- package/dist/tools/rename-file/index.js +11 -7
- package/dist/tools/run-test.d.ts.map +1 -1
- package/dist/tools/run-test.js +12 -7
- package/dist/tools/safe-bash/index.d.ts.map +1 -1
- package/dist/tools/safe-bash/index.js +18 -2
- package/dist/tools/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/test-gen-browser.js +12 -9
- package/dist/tools/trace-dot-zip/index.d.ts +3 -1
- package/dist/tools/trace-dot-zip/index.d.ts.map +1 -1
- package/dist/tools/trace-dot-zip/index.js +8 -20
- package/dist/tools/trace-dot-zip/utils/console-trace.d.ts.map +1 -1
- package/dist/tools/trace-dot-zip/utils/console-trace.js +11 -5
- package/dist/tools/trace-dot-zip/utils/extract-screenshots.d.ts +27 -0
- package/dist/tools/trace-dot-zip/utils/extract-screenshots.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/utils/extract-screenshots.js +128 -0
- package/dist/tools/trace-dot-zip/utils/extract-steps.d.ts +12 -0
- package/dist/tools/trace-dot-zip/utils/extract-steps.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/utils/extract-steps.js +130 -0
- package/dist/tools/trace-dot-zip/utils/extract-zip.d.ts +13 -16
- package/dist/tools/trace-dot-zip/utils/extract-zip.d.ts.map +1 -1
- package/dist/tools/trace-dot-zip/utils/extract-zip.js +27 -167
- package/dist/tools/trace-dot-zip/utils/network-trace.d.ts.map +1 -1
- package/dist/tools/trace-dot-zip/utils/network-trace.js +136 -105
- package/dist/trace-utils/cli.d.ts +3 -0
- package/dist/trace-utils/cli.d.ts.map +1 -0
- package/dist/trace-utils/cli.js +302 -0
- package/dist/trace-utils/console.d.ts +11 -0
- package/dist/trace-utils/console.d.ts.map +1 -0
- package/dist/trace-utils/console.js +74 -0
- package/dist/trace-utils/dom-snapshot.d.ts +19 -0
- package/dist/trace-utils/dom-snapshot.d.ts.map +1 -0
- package/dist/trace-utils/dom-snapshot.js +328 -0
- package/dist/trace-utils/index.d.ts +8 -0
- package/dist/trace-utils/index.d.ts.map +1 -1
- package/dist/trace-utils/index.js +19 -1
- package/dist/trace-utils/network.d.ts +16 -0
- package/dist/trace-utils/network.d.ts.map +1 -0
- package/dist/trace-utils/network.js +178 -0
- package/dist/trace-utils/normalize-trace-url.d.ts +2 -0
- package/dist/trace-utils/normalize-trace-url.d.ts.map +1 -0
- package/dist/trace-utils/normalize-trace-url.js +15 -0
- package/dist/trace-utils/screenshots.d.ts +24 -0
- package/dist/trace-utils/screenshots.d.ts.map +1 -0
- package/dist/trace-utils/screenshots.js +197 -0
- package/dist/trace-utils/steps.d.ts +10 -0
- package/dist/trace-utils/steps.d.ts.map +1 -0
- package/dist/trace-utils/steps.js +126 -0
- package/dist/trace-utils/types.d.ts +51 -0
- package/dist/trace-utils/types.d.ts.map +1 -0
- package/dist/trace-utils/types.js +2 -0
- package/dist/utils/playwright-report-parser.d.ts +1 -12
- package/dist/utils/playwright-report-parser.d.ts.map +1 -1
- package/dist/utils/playwright-report-parser.js +8 -136
- package/dist/video-core/index.d.ts.map +1 -1
- package/dist/video-core/index.js +17 -33
- package/package.json +12 -6
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractScreenshotsAroundStep = extractScreenshotsAroundStep;
|
|
7
|
+
exports.extractScreenshotsInRange = extractScreenshotsInRange;
|
|
8
|
+
exports.parseTimeToMs = parseTimeToMs;
|
|
9
|
+
exports.saveScreenshotsToDir = saveScreenshotsToDir;
|
|
10
|
+
const buffer_1 = require("buffer");
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const extract_steps_1 = require("./extract-steps");
|
|
14
|
+
const extract_zip_1 = require("./extract-zip");
|
|
15
|
+
async function extractScreenshotsAroundStep(opts) {
|
|
16
|
+
const { zipUrl, stepId, beforeMs = 2000, afterMs = 2000, maxScreenshots = 10, } = opts;
|
|
17
|
+
const steps = await (0, extract_steps_1.extractStepsFromTrace)(zipUrl);
|
|
18
|
+
const step = steps.find((s) => s.callId === stepId);
|
|
19
|
+
if (!step) {
|
|
20
|
+
return { step: undefined, screenshots: [] };
|
|
21
|
+
}
|
|
22
|
+
const startTime = step.startTime - beforeMs;
|
|
23
|
+
const endTime = (step.endTime ?? step.startTime) + afterMs;
|
|
24
|
+
const screenshots = await extractScreenshotsInRange({
|
|
25
|
+
zipUrl,
|
|
26
|
+
startTime,
|
|
27
|
+
endTime,
|
|
28
|
+
maxScreenshots,
|
|
29
|
+
});
|
|
30
|
+
return { step, screenshots };
|
|
31
|
+
}
|
|
32
|
+
async function extractScreenshotsInRange(opts) {
|
|
33
|
+
const { zipUrl, startTime, endTime, maxScreenshots = 10 } = opts;
|
|
34
|
+
const frames = await extractScreencastFrames(zipUrl);
|
|
35
|
+
const relevantFrames = frames.filter((f) => f.timestamp >= startTime && f.timestamp <= endTime);
|
|
36
|
+
let selectedFrames = relevantFrames;
|
|
37
|
+
if (relevantFrames.length > maxScreenshots) {
|
|
38
|
+
selectedFrames = sampleFrames(relevantFrames, maxScreenshots);
|
|
39
|
+
}
|
|
40
|
+
const screenshots = await extractScreenshotImages(zipUrl, selectedFrames.map((f) => f.sha1));
|
|
41
|
+
return selectedFrames.map((f) => ({
|
|
42
|
+
sha1: f.sha1,
|
|
43
|
+
timestamp: f.timestamp,
|
|
44
|
+
width: f.width,
|
|
45
|
+
height: f.height,
|
|
46
|
+
base64: screenshots.get(f.sha1) || "",
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
function parseTimeToMs(timeStr) {
|
|
50
|
+
const match = timeStr.match(/^(\d{2}):(\d{2}):(\d{2})\.(\d{3})$/);
|
|
51
|
+
if (!match) {
|
|
52
|
+
throw new Error(`Invalid time format: ${timeStr}. Expected HH:MM:SS.mmm (e.g., 00:02:06.434)`);
|
|
53
|
+
}
|
|
54
|
+
const [, hours, minutes, seconds, ms] = match;
|
|
55
|
+
return (parseInt(hours, 10) * 3600000 +
|
|
56
|
+
parseInt(minutes, 10) * 60000 +
|
|
57
|
+
parseInt(seconds, 10) * 1000 +
|
|
58
|
+
parseInt(ms, 10));
|
|
59
|
+
}
|
|
60
|
+
async function extractScreencastFrames(zipUrl) {
|
|
61
|
+
const frames = [];
|
|
62
|
+
await (0, extract_zip_1.extractFileFromZipFromUrl)({
|
|
63
|
+
zipUrl,
|
|
64
|
+
fileNames: ["0-trace.trace"],
|
|
65
|
+
chunkProcessor: () => {
|
|
66
|
+
let tempBuffer = "";
|
|
67
|
+
return (chunk) => {
|
|
68
|
+
tempBuffer += chunk;
|
|
69
|
+
const lines = tempBuffer.split("\n");
|
|
70
|
+
lines.slice(0, -1).forEach((line) => {
|
|
71
|
+
try {
|
|
72
|
+
const event = JSON.parse(line);
|
|
73
|
+
if (event.type === "screencast-frame") {
|
|
74
|
+
frames.push(event);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// skip malformed lines
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
tempBuffer = lines[lines.length - 1] || "";
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
return frames;
|
|
86
|
+
}
|
|
87
|
+
async function extractScreenshotImages(zipUrl, sha1s) {
|
|
88
|
+
const results = new Map();
|
|
89
|
+
const fileNames = sha1s.map((sha1) => `resources/${sha1}`);
|
|
90
|
+
await (0, extract_zip_1.extractFileFromZipFromUrl)({
|
|
91
|
+
zipUrl,
|
|
92
|
+
fileNames,
|
|
93
|
+
chunkProcessor: (_, currentFile) => {
|
|
94
|
+
const sha1 = currentFile.replace("resources/", "");
|
|
95
|
+
const chunks = [];
|
|
96
|
+
return (chunk) => {
|
|
97
|
+
chunks.push(chunk);
|
|
98
|
+
const combined = buffer_1.Buffer.concat(chunks);
|
|
99
|
+
results.set(sha1, combined.toString("base64"));
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
function sampleFrames(frames, count) {
|
|
106
|
+
if (frames.length <= count)
|
|
107
|
+
return frames;
|
|
108
|
+
const result = [];
|
|
109
|
+
const step = (frames.length - 1) / (count - 1);
|
|
110
|
+
for (let i = 0; i < count; i++) {
|
|
111
|
+
const idx = Math.round(i * step);
|
|
112
|
+
result.push(frames[idx]);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
async function saveScreenshotsToDir(screenshots, outputDir, stepId) {
|
|
117
|
+
await fs_1.promises.mkdir(outputDir, { recursive: true });
|
|
118
|
+
const savedPaths = [];
|
|
119
|
+
for (let i = 0; i < screenshots.length; i++) {
|
|
120
|
+
const s = screenshots[i];
|
|
121
|
+
const ext = s.sha1.endsWith(".jpeg") || s.sha1.endsWith(".jpg") ? "jpg" : "png";
|
|
122
|
+
const filename = `${stepId.replace(/[@:]/g, "-")}_${i + 1}.${ext}`;
|
|
123
|
+
const filePath = path_1.default.join(outputDir, filename);
|
|
124
|
+
await fs_1.promises.writeFile(filePath, buffer_1.Buffer.from(s.base64, "base64"));
|
|
125
|
+
savedPaths.push(filePath);
|
|
126
|
+
}
|
|
127
|
+
return savedPaths;
|
|
128
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type TraceStep = {
|
|
2
|
+
callId: string;
|
|
3
|
+
apiName: string;
|
|
4
|
+
params?: Record<string, any>;
|
|
5
|
+
startTime: number;
|
|
6
|
+
endTime?: number;
|
|
7
|
+
parentId?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function extractStepsFromTrace(zipUrl: string): Promise<TraceStep[]>;
|
|
11
|
+
export declare function formatStepsForDisplay(steps: TraceStep[]): string[];
|
|
12
|
+
//# sourceMappingURL=extract-steps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-steps.d.ts","sourceRoot":"","sources":["../../../../src/tools/trace-dot-zip/utils/extract-steps.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAeF,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,SAAS,EAAE,CAAC,CAqDtB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CA4ClE"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractStepsFromTrace = extractStepsFromTrace;
|
|
4
|
+
exports.formatStepsForDisplay = formatStepsForDisplay;
|
|
5
|
+
const extract_zip_1 = require("./extract-zip");
|
|
6
|
+
async function extractStepsFromTrace(zipUrl) {
|
|
7
|
+
const beforeEvents = new Map();
|
|
8
|
+
const afterEvents = new Map();
|
|
9
|
+
const errorEvents = [];
|
|
10
|
+
await (0, extract_zip_1.extractFileFromZipFromUrl)({
|
|
11
|
+
zipUrl,
|
|
12
|
+
fileNames: ["test.trace"],
|
|
13
|
+
chunkProcessor: () => {
|
|
14
|
+
let tempBuffer = "";
|
|
15
|
+
return (chunk) => {
|
|
16
|
+
tempBuffer += chunk;
|
|
17
|
+
const lines = tempBuffer.split("\n");
|
|
18
|
+
lines.slice(0, -1).forEach((line) => {
|
|
19
|
+
try {
|
|
20
|
+
const event = JSON.parse(line);
|
|
21
|
+
if (event.type === "before" && event.callId) {
|
|
22
|
+
beforeEvents.set(event.callId, event);
|
|
23
|
+
}
|
|
24
|
+
else if (event.type === "after" && event.callId) {
|
|
25
|
+
afterEvents.set(event.callId, event);
|
|
26
|
+
}
|
|
27
|
+
else if (event.type === "error") {
|
|
28
|
+
errorEvents.push(event);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// skip malformed lines
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
tempBuffer = lines[lines.length - 1] || "";
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
const steps = [];
|
|
40
|
+
for (const [callId, before] of beforeEvents) {
|
|
41
|
+
const after = afterEvents.get(callId);
|
|
42
|
+
const apiName = before.apiName || before.title;
|
|
43
|
+
if (apiName) {
|
|
44
|
+
steps.push({
|
|
45
|
+
callId,
|
|
46
|
+
apiName,
|
|
47
|
+
params: before.params,
|
|
48
|
+
startTime: before.startTime ?? 0,
|
|
49
|
+
endTime: after?.endTime,
|
|
50
|
+
parentId: before.parentId,
|
|
51
|
+
error: after?.error?.message,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// sort by startTime
|
|
56
|
+
steps.sort((a, b) => a.startTime - b.startTime);
|
|
57
|
+
return steps;
|
|
58
|
+
}
|
|
59
|
+
function formatStepsForDisplay(steps) {
|
|
60
|
+
const lines = [];
|
|
61
|
+
const parentMap = new Map();
|
|
62
|
+
for (const step of steps) {
|
|
63
|
+
const key = step.parentId || "root";
|
|
64
|
+
if (!parentMap.has(key))
|
|
65
|
+
parentMap.set(key, []);
|
|
66
|
+
parentMap.get(key).push(step);
|
|
67
|
+
}
|
|
68
|
+
function renderStep(step, depth) {
|
|
69
|
+
const indent = " ".repeat(depth);
|
|
70
|
+
const failed = step.error ? " [FAILED]" : "";
|
|
71
|
+
const timeRange = formatTimeRange(step.startTime, step.endTime);
|
|
72
|
+
const mainParam = getMainParam(step);
|
|
73
|
+
const paramSuffix = mainParam ? ` ${mainParam}` : "";
|
|
74
|
+
lines.push(`${indent}[${step.callId}] ${step.apiName}${paramSuffix}${failed}`);
|
|
75
|
+
lines.push(`${indent} ${timeRange}`);
|
|
76
|
+
if (step.params) {
|
|
77
|
+
const extraParams = formatExtraParams(step.params);
|
|
78
|
+
if (extraParams.length > 0) {
|
|
79
|
+
for (const param of extraParams) {
|
|
80
|
+
lines.push(`${indent} ${param}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const children = parentMap.get(step.callId) || [];
|
|
85
|
+
for (const child of children) {
|
|
86
|
+
renderStep(child, depth + 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const rootSteps = parentMap.get("root") || [];
|
|
90
|
+
for (const step of rootSteps) {
|
|
91
|
+
renderStep(step, 0);
|
|
92
|
+
}
|
|
93
|
+
return lines;
|
|
94
|
+
}
|
|
95
|
+
function formatTimeRange(startTime, endTime) {
|
|
96
|
+
const start = new Date(startTime).toISOString().slice(11, 23);
|
|
97
|
+
if (endTime) {
|
|
98
|
+
const end = new Date(endTime).toISOString().slice(11, 23);
|
|
99
|
+
const duration = Math.round(endTime - startTime);
|
|
100
|
+
return `${start} → ${end} (${duration}ms)`;
|
|
101
|
+
}
|
|
102
|
+
return `${start}`;
|
|
103
|
+
}
|
|
104
|
+
function getMainParam(step) {
|
|
105
|
+
if (!step.params)
|
|
106
|
+
return undefined;
|
|
107
|
+
const p = step.params;
|
|
108
|
+
if (p.url)
|
|
109
|
+
return p.url;
|
|
110
|
+
if (p.selector)
|
|
111
|
+
return p.selector;
|
|
112
|
+
if (p.text)
|
|
113
|
+
return `"${p.text}"`;
|
|
114
|
+
if (p.value)
|
|
115
|
+
return `"${p.value}"`;
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
function formatExtraParams(params) {
|
|
119
|
+
const mainKeys = ["url", "selector", "text", "value"];
|
|
120
|
+
const lines = [];
|
|
121
|
+
for (const [key, value] of Object.entries(params)) {
|
|
122
|
+
if (mainKeys.includes(key))
|
|
123
|
+
continue;
|
|
124
|
+
if (value === undefined || value === null)
|
|
125
|
+
continue;
|
|
126
|
+
const formatted = typeof value === "string" ? value : JSON.stringify(value);
|
|
127
|
+
lines.push(`${key}: ${formatted}`);
|
|
128
|
+
}
|
|
129
|
+
return lines;
|
|
130
|
+
}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
export type { ChunkProcessor } from "@empiricalrun/r2-uploader/zip";
|
|
2
|
+
export { getZipEntryNames, readZipResourcesBySha1, streamZipEntries, withZipFile, } from "@empiricalrun/r2-uploader/zip";
|
|
3
|
+
import type { ChunkProcessor } from "@empiricalrun/r2-uploader/zip";
|
|
4
|
+
export declare function extractFilesFromZipPath({ zipPath, fileNames, chunkProcessor, }: {
|
|
5
|
+
zipPath: string;
|
|
6
|
+
fileNames: string[];
|
|
7
|
+
chunkProcessor: ChunkProcessor;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function getFilenamesInZip(zipUrl: string, { recursive, }?: {
|
|
10
|
+
recursive?: boolean;
|
|
11
|
+
}): Promise<string[]>;
|
|
12
|
+
export declare const extractFileFromZipFromUrl: ({ zipUrl, fileNames, chunkProcessor, }: {
|
|
3
13
|
zipUrl: string;
|
|
4
14
|
fileNames: string[];
|
|
5
|
-
chunkProcessor:
|
|
15
|
+
chunkProcessor: ChunkProcessor;
|
|
6
16
|
withCache?: boolean;
|
|
7
17
|
}) => Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* Returns a list of file names contained in a zip file located at `zipUrl`.
|
|
10
|
-
*
|
|
11
|
-
* @param zipUrl - The URL or file path (file://...) of the zip file.
|
|
12
|
-
* @param options.withCache - Whether to use cached fetch logic (if available).
|
|
13
|
-
* @param options.recursive - If `false`, only return top-level files (files with no slash).
|
|
14
|
-
* If `true`, return all files in any subdirectory.
|
|
15
|
-
* @returns An array of file names in the ZIP.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getFilenamesInZip(zipUrl: string, { withCache, recursive, }?: {
|
|
18
|
-
withCache?: boolean;
|
|
19
|
-
recursive?: boolean;
|
|
20
|
-
}): Promise<string[]>;
|
|
21
18
|
//# sourceMappingURL=extract-zip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-zip.d.ts","sourceRoot":"","sources":["../../../../src/tools/trace-dot-zip/utils/extract-zip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract-zip.d.ts","sourceRoot":"","sources":["../../../../src/tools/trace-dot-zip/utils/extract-zip.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,GACZ,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAGpE,wBAAsB,uBAAuB,CAAC,EAC5C,OAAO,EACP,SAAS,EACT,cAAc,GACf,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,cAAc,CAAC;CAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhB;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,EACE,SAAgB,GACjB,GAAE;IACD,SAAS,CAAC,EAAE,OAAO,CAAC;CAChB,GACL,OAAO,CAAC,MAAM,EAAE,CAAC,CAcnB;AAED,eAAO,MAAM,yBAAyB,GAAU,wCAI7C;IACD,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,KAAG,OAAO,CAAC,IAAI,CAIf,CAAC"}
|
|
@@ -1,174 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractFileFromZipFromUrl = void 0;
|
|
3
|
+
exports.extractFileFromZipFromUrl = exports.withZipFile = exports.streamZipEntries = exports.readZipResourcesBySha1 = exports.getZipEntryNames = void 0;
|
|
4
|
+
exports.extractFilesFromZipPath = extractFilesFromZipPath;
|
|
7
5
|
exports.getFilenamesInZip = getFilenamesInZip;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
read() { },
|
|
17
|
-
});
|
|
18
|
-
const reader = webReadableStream.getReader();
|
|
19
|
-
void (async function readStream() {
|
|
20
|
-
try {
|
|
21
|
-
while (true) {
|
|
22
|
-
const { done, value } = await reader.read();
|
|
23
|
-
if (done) {
|
|
24
|
-
nodeReadableStream.push(null);
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
nodeReadableStream.push(value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
nodeReadableStream.destroy(error);
|
|
32
|
-
}
|
|
33
|
-
})();
|
|
34
|
-
return nodeReadableStream;
|
|
35
|
-
};
|
|
36
|
-
async function streamToBuffer(webStream) {
|
|
37
|
-
const chunks = [];
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
const nodeStream = convertToNodeReadableStream(webStream);
|
|
40
|
-
nodeStream.on("data", (chunk) => chunks.push(chunk));
|
|
41
|
-
nodeStream.on("end", () => resolve(buffer_1.Buffer.concat(chunks)));
|
|
42
|
-
nodeStream.on("error", reject);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const cache = {};
|
|
46
|
-
const cachedFetch = async (url) => {
|
|
47
|
-
if (url in cache) {
|
|
48
|
-
return cache[url];
|
|
49
|
-
}
|
|
50
|
-
const response = await fetch(url);
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
53
|
-
}
|
|
54
|
-
// Convert the stream to a buffer
|
|
55
|
-
const buffer = await streamToBuffer(response.body);
|
|
56
|
-
cache[url] = buffer;
|
|
57
|
-
return buffer;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Fetches or reads a zip file from URL or file path, then returns a Buffer.
|
|
61
|
-
*/
|
|
62
|
-
async function getZipBuffer(zipUrl, withCache) {
|
|
63
|
-
if (zipUrl.startsWith("file://")) {
|
|
64
|
-
const filePath = zipUrl.replace(/^file:\/\//, "");
|
|
65
|
-
return fs_1.promises.readFile(filePath);
|
|
66
|
-
}
|
|
67
|
-
else if (withCache) {
|
|
68
|
-
return await cachedFetch(zipUrl);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const response = await fetch(zipUrl);
|
|
72
|
-
if (!response.ok) {
|
|
73
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
74
|
-
}
|
|
75
|
-
return streamToBuffer(response.body);
|
|
76
|
-
}
|
|
6
|
+
var zip_1 = require("@empiricalrun/r2-uploader/zip");
|
|
7
|
+
Object.defineProperty(exports, "getZipEntryNames", { enumerable: true, get: function () { return zip_1.getZipEntryNames; } });
|
|
8
|
+
Object.defineProperty(exports, "readZipResourcesBySha1", { enumerable: true, get: function () { return zip_1.readZipResourcesBySha1; } });
|
|
9
|
+
Object.defineProperty(exports, "streamZipEntries", { enumerable: true, get: function () { return zip_1.streamZipEntries; } });
|
|
10
|
+
Object.defineProperty(exports, "withZipFile", { enumerable: true, get: function () { return zip_1.withZipFile; } });
|
|
11
|
+
const zip_2 = require("@empiricalrun/r2-uploader/zip");
|
|
12
|
+
async function extractFilesFromZipPath({ zipPath, fileNames, chunkProcessor, }) {
|
|
13
|
+
await (0, zip_2.streamZipEntries)({ zipPath, fileNames, chunkProcessor });
|
|
77
14
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
await new Promise((resolve) => {
|
|
90
|
-
zipfile.on("entry", (entry) => {
|
|
91
|
-
if (fileNames.includes(entry.fileName)) {
|
|
92
|
-
const filePromise = new Promise((fileResolve) => {
|
|
93
|
-
zipfile.openReadStream(entry, (err, readStream) => {
|
|
94
|
-
if (err) {
|
|
95
|
-
console.error(`error reading file - ${entry.fileName}`, err);
|
|
96
|
-
fileResolve();
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const done = () => {
|
|
100
|
-
fileResolve();
|
|
101
|
-
};
|
|
102
|
-
const processChunk = chunkProcessor(done, entry.fileName);
|
|
103
|
-
readStream.on("data", processChunk);
|
|
104
|
-
readStream.on("end", () => {
|
|
105
|
-
fileResolve();
|
|
106
|
-
});
|
|
107
|
-
readStream.on("error", (error) => {
|
|
108
|
-
console.error(`error reading file - ${entry.fileName}`, error);
|
|
109
|
-
fileResolve();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
// Push each file's promise to the array
|
|
114
|
-
fileProcessingPromises.push(filePromise);
|
|
115
|
-
}
|
|
116
|
-
zipfile.readEntry();
|
|
117
|
-
});
|
|
118
|
-
zipfile.on("end", () => {
|
|
119
|
-
resolve();
|
|
120
|
-
});
|
|
121
|
-
zipfile.on("error", (error) => {
|
|
122
|
-
console.error(`Error reading entry`, error);
|
|
123
|
-
resolve();
|
|
124
|
-
});
|
|
125
|
-
zipfile.readEntry();
|
|
15
|
+
async function getFilenamesInZip(zipUrl, { recursive = true, } = {}) {
|
|
16
|
+
const { getZipEntryNames } = await import("@empiricalrun/r2-uploader/zip");
|
|
17
|
+
return (0, zip_2.withZipFile)(zipUrl, async (zipPath) => {
|
|
18
|
+
const allNames = await getZipEntryNames(zipPath);
|
|
19
|
+
return allNames.filter((name) => {
|
|
20
|
+
const isDirectory = name.endsWith("/");
|
|
21
|
+
if (isDirectory)
|
|
22
|
+
return false;
|
|
23
|
+
if (recursive)
|
|
24
|
+
return true;
|
|
25
|
+
return !name.includes("/");
|
|
126
26
|
});
|
|
127
|
-
await Promise.all(fileProcessingPromises);
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
console.error(`Error fetching or processing the zip file url - "${zipUrl}"`, error);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
exports.extractFileFromZipFromUrl = extractFileFromZipFromUrl;
|
|
134
|
-
/**
|
|
135
|
-
* Returns a list of file names contained in a zip file located at `zipUrl`.
|
|
136
|
-
*
|
|
137
|
-
* @param zipUrl - The URL or file path (file://...) of the zip file.
|
|
138
|
-
* @param options.withCache - Whether to use cached fetch logic (if available).
|
|
139
|
-
* @param options.recursive - If `false`, only return top-level files (files with no slash).
|
|
140
|
-
* If `true`, return all files in any subdirectory.
|
|
141
|
-
* @returns An array of file names in the ZIP.
|
|
142
|
-
*/
|
|
143
|
-
async function getFilenamesInZip(zipUrl, { withCache = false, recursive = true, } = {}) {
|
|
144
|
-
// 1. Get the zip contents as a Buffer
|
|
145
|
-
const buffer = await getZipBuffer(zipUrl, withCache);
|
|
146
|
-
// 2. Parse the zip file with yauzl
|
|
147
|
-
const zipfile = await fromBuffer(buffer, { lazyEntries: true });
|
|
148
|
-
const fileNames = [];
|
|
149
|
-
await new Promise((resolve, reject) => {
|
|
150
|
-
zipfile.on("entry", (entry) => {
|
|
151
|
-
// Identify directories by trailing slash
|
|
152
|
-
const isDirectory = entry.fileName.endsWith("/");
|
|
153
|
-
// We don't list directories, only files
|
|
154
|
-
if (!isDirectory) {
|
|
155
|
-
if (recursive) {
|
|
156
|
-
// Include all files
|
|
157
|
-
fileNames.push(entry.fileName);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
// Only include top-level files (no slash in the path)
|
|
161
|
-
if (!entry.fileName.includes("/")) {
|
|
162
|
-
fileNames.push(entry.fileName);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// Proceed to the next entry
|
|
167
|
-
zipfile.readEntry();
|
|
168
|
-
});
|
|
169
|
-
zipfile.on("error", (err) => reject(err));
|
|
170
|
-
zipfile.on("end", () => resolve());
|
|
171
|
-
zipfile.readEntry();
|
|
172
27
|
});
|
|
173
|
-
return fileNames;
|
|
174
28
|
}
|
|
29
|
+
const extractFileFromZipFromUrl = async ({ zipUrl, fileNames, chunkProcessor, }) => {
|
|
30
|
+
await (0, zip_2.withZipFile)(zipUrl, async (zipPath) => {
|
|
31
|
+
await extractFilesFromZipPath({ zipPath, fileNames, chunkProcessor });
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
exports.extractFileFromZipFromUrl = extractFileFromZipFromUrl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-trace.d.ts","sourceRoot":"","sources":["../../../../src/tools/trace-dot-zip/utils/network-trace.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"network-trace.d.ts","sourceRoot":"","sources":["../../../../src/tools/trace-dot-zip/utils/network-trace.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,UAAU,CAAC;AAelB,KAAK,KAAK,GAAG;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,EACJ;YACE,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,MAAM,CAAC;SAChB,GACD,SAAS,CAAC;KACf,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,8BAIxC,KAAK,KAAG,OAAO,CAAC;IACjB,cAAc,EAAE,sBAAsB,EAAE,CAAC;IACzC,0BAA0B,EAAE,sBAAsB,EAAE,CAAC;CACtD,CAiLA,CAAC;AAEF,eAAO,MAAM,8BAA8B,GAAU,UAElD,KAAK,KAAG,OAAO,CAAC;IACjB,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;IAC9C,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C,CAmBA,CAAC;AAsGF,eAAO,MAAM,0CAA0C,GACrD,UAAU,sBAAsB,EAAE,KACjC,OAAO,CAAC,sBAAsB,CAAC,EAoBjC,CAAC;AAmEF,eAAO,MAAM,iBAAiB,GAC5B,UAAU,sBAAsB,EAAE,EAClC,QAAQ,MAAM,KACb,OAAO,CAAC,sBAAsB,EAAE,CAIlC,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,0CAA0C,sBAAsB,EAAE,KACjE,sBAAsB,EA0BxB,CAAC"}
|