@wix/evalforge-evaluator 0.41.0 → 0.43.0
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/build/index.js +586 -43
- package/build/index.js.map +4 -4
- package/build/index.mjs +588 -45
- package/build/index.mjs.map +4 -4
- package/build/types/run-scenario/environment.d.ts +4 -2
- package/package.json +6 -4
package/build/index.js
CHANGED
|
@@ -232,6 +232,7 @@ var import_eval_assertions = require("@wix/eval-assertions");
|
|
|
232
232
|
|
|
233
233
|
// src/run-scenario/environment.ts
|
|
234
234
|
var import_fs5 = require("fs");
|
|
235
|
+
var import_os = require("os");
|
|
235
236
|
var import_stream = require("stream");
|
|
236
237
|
var import_promises2 = require("stream/promises");
|
|
237
238
|
var import_zlib2 = require("zlib");
|
|
@@ -6079,19 +6080,25 @@ async function downloadAndExtractTemplate(template, workDir) {
|
|
|
6079
6080
|
}
|
|
6080
6081
|
cleanAppleDoubleFiles(workDir);
|
|
6081
6082
|
}
|
|
6082
|
-
async function prepareWorkingDirectory(config, evalRunId2, targetId, template) {
|
|
6083
|
-
|
|
6084
|
-
|
|
6083
|
+
async function prepareWorkingDirectory(config, evalRunId2, targetId, scenarioId, template) {
|
|
6084
|
+
const baseDir = config.evaluationsDir ?? import_path4.default.join((0, import_os.tmpdir)(), "evalforge-evaluations");
|
|
6085
|
+
if (template) {
|
|
6086
|
+
if (!config.evaluationsDir) {
|
|
6087
|
+
console.warn(
|
|
6088
|
+
"Template specified but EVALUATIONS_DIR not set, using temp directory"
|
|
6089
|
+
);
|
|
6090
|
+
}
|
|
6091
|
+
const workDir2 = import_path4.default.join(baseDir, `${evalRunId2}_${targetId}`);
|
|
6092
|
+
await downloadAndExtractTemplate(template, workDir2);
|
|
6093
|
+
console.log(`Template extracted to ${workDir2}`);
|
|
6094
|
+
return workDir2;
|
|
6085
6095
|
}
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
);
|
|
6090
|
-
return void 0;
|
|
6096
|
+
const workDir = import_path4.default.join(baseDir, `${evalRunId2}_${targetId}_${scenarioId}`);
|
|
6097
|
+
if ((0, import_fs5.existsSync)(workDir)) {
|
|
6098
|
+
(0, import_fs5.rmSync)(workDir, { recursive: true });
|
|
6091
6099
|
}
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
console.log(`Template extracted to ${workDir}`);
|
|
6100
|
+
(0, import_fs5.mkdirSync)(workDir, { recursive: true });
|
|
6101
|
+
console.log(`Empty working directory created at ${workDir}`);
|
|
6095
6102
|
return workDir;
|
|
6096
6103
|
}
|
|
6097
6104
|
|
|
@@ -7217,6 +7224,561 @@ defaultRegistry.register(claudeCodeAdapter);
|
|
|
7217
7224
|
// src/run-scenario/file-diff.ts
|
|
7218
7225
|
var import_fs6 = require("fs");
|
|
7219
7226
|
var import_path6 = require("path");
|
|
7227
|
+
|
|
7228
|
+
// ../../node_modules/diff/lib/index.mjs
|
|
7229
|
+
function Diff() {
|
|
7230
|
+
}
|
|
7231
|
+
Diff.prototype = {
|
|
7232
|
+
diff: function diff(oldString, newString) {
|
|
7233
|
+
var _options$timeout;
|
|
7234
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
7235
|
+
var callback = options.callback;
|
|
7236
|
+
if (typeof options === "function") {
|
|
7237
|
+
callback = options;
|
|
7238
|
+
options = {};
|
|
7239
|
+
}
|
|
7240
|
+
var self = this;
|
|
7241
|
+
function done(value) {
|
|
7242
|
+
value = self.postProcess(value, options);
|
|
7243
|
+
if (callback) {
|
|
7244
|
+
setTimeout(function() {
|
|
7245
|
+
callback(value);
|
|
7246
|
+
}, 0);
|
|
7247
|
+
return true;
|
|
7248
|
+
} else {
|
|
7249
|
+
return value;
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7252
|
+
oldString = this.castInput(oldString, options);
|
|
7253
|
+
newString = this.castInput(newString, options);
|
|
7254
|
+
oldString = this.removeEmpty(this.tokenize(oldString, options));
|
|
7255
|
+
newString = this.removeEmpty(this.tokenize(newString, options));
|
|
7256
|
+
var newLen = newString.length, oldLen = oldString.length;
|
|
7257
|
+
var editLength = 1;
|
|
7258
|
+
var maxEditLength = newLen + oldLen;
|
|
7259
|
+
if (options.maxEditLength != null) {
|
|
7260
|
+
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
7261
|
+
}
|
|
7262
|
+
var maxExecutionTime = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : Infinity;
|
|
7263
|
+
var abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
7264
|
+
var bestPath = [{
|
|
7265
|
+
oldPos: -1,
|
|
7266
|
+
lastComponent: void 0
|
|
7267
|
+
}];
|
|
7268
|
+
var newPos = this.extractCommon(bestPath[0], newString, oldString, 0, options);
|
|
7269
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
7270
|
+
return done(buildValues(self, bestPath[0].lastComponent, newString, oldString, self.useLongestToken));
|
|
7271
|
+
}
|
|
7272
|
+
var minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
7273
|
+
function execEditLength() {
|
|
7274
|
+
for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
7275
|
+
var basePath = void 0;
|
|
7276
|
+
var removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
7277
|
+
if (removePath) {
|
|
7278
|
+
bestPath[diagonalPath - 1] = void 0;
|
|
7279
|
+
}
|
|
7280
|
+
var canAdd = false;
|
|
7281
|
+
if (addPath) {
|
|
7282
|
+
var addPathNewPos = addPath.oldPos - diagonalPath;
|
|
7283
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
7284
|
+
}
|
|
7285
|
+
var canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
7286
|
+
if (!canAdd && !canRemove) {
|
|
7287
|
+
bestPath[diagonalPath] = void 0;
|
|
7288
|
+
continue;
|
|
7289
|
+
}
|
|
7290
|
+
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
7291
|
+
basePath = self.addToPath(addPath, true, false, 0, options);
|
|
7292
|
+
} else {
|
|
7293
|
+
basePath = self.addToPath(removePath, false, true, 1, options);
|
|
7294
|
+
}
|
|
7295
|
+
newPos = self.extractCommon(basePath, newString, oldString, diagonalPath, options);
|
|
7296
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
7297
|
+
return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken));
|
|
7298
|
+
} else {
|
|
7299
|
+
bestPath[diagonalPath] = basePath;
|
|
7300
|
+
if (basePath.oldPos + 1 >= oldLen) {
|
|
7301
|
+
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
7302
|
+
}
|
|
7303
|
+
if (newPos + 1 >= newLen) {
|
|
7304
|
+
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
7305
|
+
}
|
|
7306
|
+
}
|
|
7307
|
+
}
|
|
7308
|
+
editLength++;
|
|
7309
|
+
}
|
|
7310
|
+
if (callback) {
|
|
7311
|
+
(function exec() {
|
|
7312
|
+
setTimeout(function() {
|
|
7313
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
7314
|
+
return callback();
|
|
7315
|
+
}
|
|
7316
|
+
if (!execEditLength()) {
|
|
7317
|
+
exec();
|
|
7318
|
+
}
|
|
7319
|
+
}, 0);
|
|
7320
|
+
})();
|
|
7321
|
+
} else {
|
|
7322
|
+
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
7323
|
+
var ret = execEditLength();
|
|
7324
|
+
if (ret) {
|
|
7325
|
+
return ret;
|
|
7326
|
+
}
|
|
7327
|
+
}
|
|
7328
|
+
}
|
|
7329
|
+
},
|
|
7330
|
+
addToPath: function addToPath(path9, added, removed, oldPosInc, options) {
|
|
7331
|
+
var last = path9.lastComponent;
|
|
7332
|
+
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
7333
|
+
return {
|
|
7334
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
7335
|
+
lastComponent: {
|
|
7336
|
+
count: last.count + 1,
|
|
7337
|
+
added,
|
|
7338
|
+
removed,
|
|
7339
|
+
previousComponent: last.previousComponent
|
|
7340
|
+
}
|
|
7341
|
+
};
|
|
7342
|
+
} else {
|
|
7343
|
+
return {
|
|
7344
|
+
oldPos: path9.oldPos + oldPosInc,
|
|
7345
|
+
lastComponent: {
|
|
7346
|
+
count: 1,
|
|
7347
|
+
added,
|
|
7348
|
+
removed,
|
|
7349
|
+
previousComponent: last
|
|
7350
|
+
}
|
|
7351
|
+
};
|
|
7352
|
+
}
|
|
7353
|
+
},
|
|
7354
|
+
extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath, options) {
|
|
7355
|
+
var newLen = newString.length, oldLen = oldString.length, oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
7356
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldString[oldPos + 1], newString[newPos + 1], options)) {
|
|
7357
|
+
newPos++;
|
|
7358
|
+
oldPos++;
|
|
7359
|
+
commonCount++;
|
|
7360
|
+
if (options.oneChangePerToken) {
|
|
7361
|
+
basePath.lastComponent = {
|
|
7362
|
+
count: 1,
|
|
7363
|
+
previousComponent: basePath.lastComponent,
|
|
7364
|
+
added: false,
|
|
7365
|
+
removed: false
|
|
7366
|
+
};
|
|
7367
|
+
}
|
|
7368
|
+
}
|
|
7369
|
+
if (commonCount && !options.oneChangePerToken) {
|
|
7370
|
+
basePath.lastComponent = {
|
|
7371
|
+
count: commonCount,
|
|
7372
|
+
previousComponent: basePath.lastComponent,
|
|
7373
|
+
added: false,
|
|
7374
|
+
removed: false
|
|
7375
|
+
};
|
|
7376
|
+
}
|
|
7377
|
+
basePath.oldPos = oldPos;
|
|
7378
|
+
return newPos;
|
|
7379
|
+
},
|
|
7380
|
+
equals: function equals(left, right, options) {
|
|
7381
|
+
if (options.comparator) {
|
|
7382
|
+
return options.comparator(left, right);
|
|
7383
|
+
} else {
|
|
7384
|
+
return left === right || options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
7385
|
+
}
|
|
7386
|
+
},
|
|
7387
|
+
removeEmpty: function removeEmpty(array) {
|
|
7388
|
+
var ret = [];
|
|
7389
|
+
for (var i = 0; i < array.length; i++) {
|
|
7390
|
+
if (array[i]) {
|
|
7391
|
+
ret.push(array[i]);
|
|
7392
|
+
}
|
|
7393
|
+
}
|
|
7394
|
+
return ret;
|
|
7395
|
+
},
|
|
7396
|
+
castInput: function castInput(value) {
|
|
7397
|
+
return value;
|
|
7398
|
+
},
|
|
7399
|
+
tokenize: function tokenize(value) {
|
|
7400
|
+
return Array.from(value);
|
|
7401
|
+
},
|
|
7402
|
+
join: function join3(chars) {
|
|
7403
|
+
return chars.join("");
|
|
7404
|
+
},
|
|
7405
|
+
postProcess: function postProcess(changeObjects) {
|
|
7406
|
+
return changeObjects;
|
|
7407
|
+
}
|
|
7408
|
+
};
|
|
7409
|
+
function buildValues(diff2, lastComponent, newString, oldString, useLongestToken) {
|
|
7410
|
+
var components = [];
|
|
7411
|
+
var nextComponent;
|
|
7412
|
+
while (lastComponent) {
|
|
7413
|
+
components.push(lastComponent);
|
|
7414
|
+
nextComponent = lastComponent.previousComponent;
|
|
7415
|
+
delete lastComponent.previousComponent;
|
|
7416
|
+
lastComponent = nextComponent;
|
|
7417
|
+
}
|
|
7418
|
+
components.reverse();
|
|
7419
|
+
var componentPos = 0, componentLen = components.length, newPos = 0, oldPos = 0;
|
|
7420
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
7421
|
+
var component = components[componentPos];
|
|
7422
|
+
if (!component.removed) {
|
|
7423
|
+
if (!component.added && useLongestToken) {
|
|
7424
|
+
var value = newString.slice(newPos, newPos + component.count);
|
|
7425
|
+
value = value.map(function(value2, i) {
|
|
7426
|
+
var oldValue = oldString[oldPos + i];
|
|
7427
|
+
return oldValue.length > value2.length ? oldValue : value2;
|
|
7428
|
+
});
|
|
7429
|
+
component.value = diff2.join(value);
|
|
7430
|
+
} else {
|
|
7431
|
+
component.value = diff2.join(newString.slice(newPos, newPos + component.count));
|
|
7432
|
+
}
|
|
7433
|
+
newPos += component.count;
|
|
7434
|
+
if (!component.added) {
|
|
7435
|
+
oldPos += component.count;
|
|
7436
|
+
}
|
|
7437
|
+
} else {
|
|
7438
|
+
component.value = diff2.join(oldString.slice(oldPos, oldPos + component.count));
|
|
7439
|
+
oldPos += component.count;
|
|
7440
|
+
}
|
|
7441
|
+
}
|
|
7442
|
+
return components;
|
|
7443
|
+
}
|
|
7444
|
+
var characterDiff = new Diff();
|
|
7445
|
+
function longestCommonPrefix(str1, str2) {
|
|
7446
|
+
var i;
|
|
7447
|
+
for (i = 0; i < str1.length && i < str2.length; i++) {
|
|
7448
|
+
if (str1[i] != str2[i]) {
|
|
7449
|
+
return str1.slice(0, i);
|
|
7450
|
+
}
|
|
7451
|
+
}
|
|
7452
|
+
return str1.slice(0, i);
|
|
7453
|
+
}
|
|
7454
|
+
function longestCommonSuffix(str1, str2) {
|
|
7455
|
+
var i;
|
|
7456
|
+
if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) {
|
|
7457
|
+
return "";
|
|
7458
|
+
}
|
|
7459
|
+
for (i = 0; i < str1.length && i < str2.length; i++) {
|
|
7460
|
+
if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) {
|
|
7461
|
+
return str1.slice(-i);
|
|
7462
|
+
}
|
|
7463
|
+
}
|
|
7464
|
+
return str1.slice(-i);
|
|
7465
|
+
}
|
|
7466
|
+
function replacePrefix(string, oldPrefix, newPrefix) {
|
|
7467
|
+
if (string.slice(0, oldPrefix.length) != oldPrefix) {
|
|
7468
|
+
throw Error("string ".concat(JSON.stringify(string), " doesn't start with prefix ").concat(JSON.stringify(oldPrefix), "; this is a bug"));
|
|
7469
|
+
}
|
|
7470
|
+
return newPrefix + string.slice(oldPrefix.length);
|
|
7471
|
+
}
|
|
7472
|
+
function replaceSuffix(string, oldSuffix, newSuffix) {
|
|
7473
|
+
if (!oldSuffix) {
|
|
7474
|
+
return string + newSuffix;
|
|
7475
|
+
}
|
|
7476
|
+
if (string.slice(-oldSuffix.length) != oldSuffix) {
|
|
7477
|
+
throw Error("string ".concat(JSON.stringify(string), " doesn't end with suffix ").concat(JSON.stringify(oldSuffix), "; this is a bug"));
|
|
7478
|
+
}
|
|
7479
|
+
return string.slice(0, -oldSuffix.length) + newSuffix;
|
|
7480
|
+
}
|
|
7481
|
+
function removePrefix(string, oldPrefix) {
|
|
7482
|
+
return replacePrefix(string, oldPrefix, "");
|
|
7483
|
+
}
|
|
7484
|
+
function removeSuffix(string, oldSuffix) {
|
|
7485
|
+
return replaceSuffix(string, oldSuffix, "");
|
|
7486
|
+
}
|
|
7487
|
+
function maximumOverlap(string1, string2) {
|
|
7488
|
+
return string2.slice(0, overlapCount(string1, string2));
|
|
7489
|
+
}
|
|
7490
|
+
function overlapCount(a, b) {
|
|
7491
|
+
var startA = 0;
|
|
7492
|
+
if (a.length > b.length) {
|
|
7493
|
+
startA = a.length - b.length;
|
|
7494
|
+
}
|
|
7495
|
+
var endB = b.length;
|
|
7496
|
+
if (a.length < b.length) {
|
|
7497
|
+
endB = a.length;
|
|
7498
|
+
}
|
|
7499
|
+
var map = Array(endB);
|
|
7500
|
+
var k = 0;
|
|
7501
|
+
map[0] = 0;
|
|
7502
|
+
for (var j = 1; j < endB; j++) {
|
|
7503
|
+
if (b[j] == b[k]) {
|
|
7504
|
+
map[j] = map[k];
|
|
7505
|
+
} else {
|
|
7506
|
+
map[j] = k;
|
|
7507
|
+
}
|
|
7508
|
+
while (k > 0 && b[j] != b[k]) {
|
|
7509
|
+
k = map[k];
|
|
7510
|
+
}
|
|
7511
|
+
if (b[j] == b[k]) {
|
|
7512
|
+
k++;
|
|
7513
|
+
}
|
|
7514
|
+
}
|
|
7515
|
+
k = 0;
|
|
7516
|
+
for (var i = startA; i < a.length; i++) {
|
|
7517
|
+
while (k > 0 && a[i] != b[k]) {
|
|
7518
|
+
k = map[k];
|
|
7519
|
+
}
|
|
7520
|
+
if (a[i] == b[k]) {
|
|
7521
|
+
k++;
|
|
7522
|
+
}
|
|
7523
|
+
}
|
|
7524
|
+
return k;
|
|
7525
|
+
}
|
|
7526
|
+
var extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
|
|
7527
|
+
var tokenizeIncludingWhitespace = new RegExp("[".concat(extendedWordChars, "]+|\\s+|[^").concat(extendedWordChars, "]"), "ug");
|
|
7528
|
+
var wordDiff = new Diff();
|
|
7529
|
+
wordDiff.equals = function(left, right, options) {
|
|
7530
|
+
if (options.ignoreCase) {
|
|
7531
|
+
left = left.toLowerCase();
|
|
7532
|
+
right = right.toLowerCase();
|
|
7533
|
+
}
|
|
7534
|
+
return left.trim() === right.trim();
|
|
7535
|
+
};
|
|
7536
|
+
wordDiff.tokenize = function(value) {
|
|
7537
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
7538
|
+
var parts;
|
|
7539
|
+
if (options.intlSegmenter) {
|
|
7540
|
+
if (options.intlSegmenter.resolvedOptions().granularity != "word") {
|
|
7541
|
+
throw new Error('The segmenter passed must have a granularity of "word"');
|
|
7542
|
+
}
|
|
7543
|
+
parts = Array.from(options.intlSegmenter.segment(value), function(segment) {
|
|
7544
|
+
return segment.segment;
|
|
7545
|
+
});
|
|
7546
|
+
} else {
|
|
7547
|
+
parts = value.match(tokenizeIncludingWhitespace) || [];
|
|
7548
|
+
}
|
|
7549
|
+
var tokens = [];
|
|
7550
|
+
var prevPart = null;
|
|
7551
|
+
parts.forEach(function(part) {
|
|
7552
|
+
if (/\s/.test(part)) {
|
|
7553
|
+
if (prevPart == null) {
|
|
7554
|
+
tokens.push(part);
|
|
7555
|
+
} else {
|
|
7556
|
+
tokens.push(tokens.pop() + part);
|
|
7557
|
+
}
|
|
7558
|
+
} else if (/\s/.test(prevPart)) {
|
|
7559
|
+
if (tokens[tokens.length - 1] == prevPart) {
|
|
7560
|
+
tokens.push(tokens.pop() + part);
|
|
7561
|
+
} else {
|
|
7562
|
+
tokens.push(prevPart + part);
|
|
7563
|
+
}
|
|
7564
|
+
} else {
|
|
7565
|
+
tokens.push(part);
|
|
7566
|
+
}
|
|
7567
|
+
prevPart = part;
|
|
7568
|
+
});
|
|
7569
|
+
return tokens;
|
|
7570
|
+
};
|
|
7571
|
+
wordDiff.join = function(tokens) {
|
|
7572
|
+
return tokens.map(function(token, i) {
|
|
7573
|
+
if (i == 0) {
|
|
7574
|
+
return token;
|
|
7575
|
+
} else {
|
|
7576
|
+
return token.replace(/^\s+/, "");
|
|
7577
|
+
}
|
|
7578
|
+
}).join("");
|
|
7579
|
+
};
|
|
7580
|
+
wordDiff.postProcess = function(changes, options) {
|
|
7581
|
+
if (!changes || options.oneChangePerToken) {
|
|
7582
|
+
return changes;
|
|
7583
|
+
}
|
|
7584
|
+
var lastKeep = null;
|
|
7585
|
+
var insertion = null;
|
|
7586
|
+
var deletion = null;
|
|
7587
|
+
changes.forEach(function(change) {
|
|
7588
|
+
if (change.added) {
|
|
7589
|
+
insertion = change;
|
|
7590
|
+
} else if (change.removed) {
|
|
7591
|
+
deletion = change;
|
|
7592
|
+
} else {
|
|
7593
|
+
if (insertion || deletion) {
|
|
7594
|
+
dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
|
|
7595
|
+
}
|
|
7596
|
+
lastKeep = change;
|
|
7597
|
+
insertion = null;
|
|
7598
|
+
deletion = null;
|
|
7599
|
+
}
|
|
7600
|
+
});
|
|
7601
|
+
if (insertion || deletion) {
|
|
7602
|
+
dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
|
|
7603
|
+
}
|
|
7604
|
+
return changes;
|
|
7605
|
+
};
|
|
7606
|
+
function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep) {
|
|
7607
|
+
if (deletion && insertion) {
|
|
7608
|
+
var oldWsPrefix = deletion.value.match(/^\s*/)[0];
|
|
7609
|
+
var oldWsSuffix = deletion.value.match(/\s*$/)[0];
|
|
7610
|
+
var newWsPrefix = insertion.value.match(/^\s*/)[0];
|
|
7611
|
+
var newWsSuffix = insertion.value.match(/\s*$/)[0];
|
|
7612
|
+
if (startKeep) {
|
|
7613
|
+
var commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
|
|
7614
|
+
startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
|
|
7615
|
+
deletion.value = removePrefix(deletion.value, commonWsPrefix);
|
|
7616
|
+
insertion.value = removePrefix(insertion.value, commonWsPrefix);
|
|
7617
|
+
}
|
|
7618
|
+
if (endKeep) {
|
|
7619
|
+
var commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
|
|
7620
|
+
endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
|
|
7621
|
+
deletion.value = removeSuffix(deletion.value, commonWsSuffix);
|
|
7622
|
+
insertion.value = removeSuffix(insertion.value, commonWsSuffix);
|
|
7623
|
+
}
|
|
7624
|
+
} else if (insertion) {
|
|
7625
|
+
if (startKeep) {
|
|
7626
|
+
insertion.value = insertion.value.replace(/^\s*/, "");
|
|
7627
|
+
}
|
|
7628
|
+
if (endKeep) {
|
|
7629
|
+
endKeep.value = endKeep.value.replace(/^\s*/, "");
|
|
7630
|
+
}
|
|
7631
|
+
} else if (startKeep && endKeep) {
|
|
7632
|
+
var newWsFull = endKeep.value.match(/^\s*/)[0], delWsStart = deletion.value.match(/^\s*/)[0], delWsEnd = deletion.value.match(/\s*$/)[0];
|
|
7633
|
+
var newWsStart = longestCommonPrefix(newWsFull, delWsStart);
|
|
7634
|
+
deletion.value = removePrefix(deletion.value, newWsStart);
|
|
7635
|
+
var newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
|
|
7636
|
+
deletion.value = removeSuffix(deletion.value, newWsEnd);
|
|
7637
|
+
endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
|
|
7638
|
+
startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
|
|
7639
|
+
} else if (endKeep) {
|
|
7640
|
+
var endKeepWsPrefix = endKeep.value.match(/^\s*/)[0];
|
|
7641
|
+
var deletionWsSuffix = deletion.value.match(/\s*$/)[0];
|
|
7642
|
+
var overlap = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
|
|
7643
|
+
deletion.value = removeSuffix(deletion.value, overlap);
|
|
7644
|
+
} else if (startKeep) {
|
|
7645
|
+
var startKeepWsSuffix = startKeep.value.match(/\s*$/)[0];
|
|
7646
|
+
var deletionWsPrefix = deletion.value.match(/^\s*/)[0];
|
|
7647
|
+
var _overlap = maximumOverlap(startKeepWsSuffix, deletionWsPrefix);
|
|
7648
|
+
deletion.value = removePrefix(deletion.value, _overlap);
|
|
7649
|
+
}
|
|
7650
|
+
}
|
|
7651
|
+
var wordWithSpaceDiff = new Diff();
|
|
7652
|
+
wordWithSpaceDiff.tokenize = function(value) {
|
|
7653
|
+
var regex = new RegExp("(\\r?\\n)|[".concat(extendedWordChars, "]+|[^\\S\\n\\r]+|[^").concat(extendedWordChars, "]"), "ug");
|
|
7654
|
+
return value.match(regex) || [];
|
|
7655
|
+
};
|
|
7656
|
+
var lineDiff = new Diff();
|
|
7657
|
+
lineDiff.tokenize = function(value, options) {
|
|
7658
|
+
if (options.stripTrailingCr) {
|
|
7659
|
+
value = value.replace(/\r\n/g, "\n");
|
|
7660
|
+
}
|
|
7661
|
+
var retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
7662
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
7663
|
+
linesAndNewlines.pop();
|
|
7664
|
+
}
|
|
7665
|
+
for (var i = 0; i < linesAndNewlines.length; i++) {
|
|
7666
|
+
var line = linesAndNewlines[i];
|
|
7667
|
+
if (i % 2 && !options.newlineIsToken) {
|
|
7668
|
+
retLines[retLines.length - 1] += line;
|
|
7669
|
+
} else {
|
|
7670
|
+
retLines.push(line);
|
|
7671
|
+
}
|
|
7672
|
+
}
|
|
7673
|
+
return retLines;
|
|
7674
|
+
};
|
|
7675
|
+
lineDiff.equals = function(left, right, options) {
|
|
7676
|
+
if (options.ignoreWhitespace) {
|
|
7677
|
+
if (!options.newlineIsToken || !left.includes("\n")) {
|
|
7678
|
+
left = left.trim();
|
|
7679
|
+
}
|
|
7680
|
+
if (!options.newlineIsToken || !right.includes("\n")) {
|
|
7681
|
+
right = right.trim();
|
|
7682
|
+
}
|
|
7683
|
+
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
7684
|
+
if (left.endsWith("\n")) {
|
|
7685
|
+
left = left.slice(0, -1);
|
|
7686
|
+
}
|
|
7687
|
+
if (right.endsWith("\n")) {
|
|
7688
|
+
right = right.slice(0, -1);
|
|
7689
|
+
}
|
|
7690
|
+
}
|
|
7691
|
+
return Diff.prototype.equals.call(this, left, right, options);
|
|
7692
|
+
};
|
|
7693
|
+
function diffLines(oldStr, newStr, callback) {
|
|
7694
|
+
return lineDiff.diff(oldStr, newStr, callback);
|
|
7695
|
+
}
|
|
7696
|
+
var sentenceDiff = new Diff();
|
|
7697
|
+
sentenceDiff.tokenize = function(value) {
|
|
7698
|
+
return value.split(/(\S.+?[.!?])(?=\s+|$)/);
|
|
7699
|
+
};
|
|
7700
|
+
var cssDiff = new Diff();
|
|
7701
|
+
cssDiff.tokenize = function(value) {
|
|
7702
|
+
return value.split(/([{}:;,]|\s+)/);
|
|
7703
|
+
};
|
|
7704
|
+
function _typeof(o) {
|
|
7705
|
+
"@babel/helpers - typeof";
|
|
7706
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
|
|
7707
|
+
return typeof o2;
|
|
7708
|
+
} : function(o2) {
|
|
7709
|
+
return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
|
|
7710
|
+
}, _typeof(o);
|
|
7711
|
+
}
|
|
7712
|
+
var jsonDiff = new Diff();
|
|
7713
|
+
jsonDiff.useLongestToken = true;
|
|
7714
|
+
jsonDiff.tokenize = lineDiff.tokenize;
|
|
7715
|
+
jsonDiff.castInput = function(value, options) {
|
|
7716
|
+
var undefinedReplacement = options.undefinedReplacement, _options$stringifyRep = options.stringifyReplacer, stringifyReplacer = _options$stringifyRep === void 0 ? function(k, v) {
|
|
7717
|
+
return typeof v === "undefined" ? undefinedReplacement : v;
|
|
7718
|
+
} : _options$stringifyRep;
|
|
7719
|
+
return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, " ");
|
|
7720
|
+
};
|
|
7721
|
+
jsonDiff.equals = function(left, right, options) {
|
|
7722
|
+
return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"), options);
|
|
7723
|
+
};
|
|
7724
|
+
function canonicalize(obj, stack, replacementStack, replacer, key) {
|
|
7725
|
+
stack = stack || [];
|
|
7726
|
+
replacementStack = replacementStack || [];
|
|
7727
|
+
if (replacer) {
|
|
7728
|
+
obj = replacer(key, obj);
|
|
7729
|
+
}
|
|
7730
|
+
var i;
|
|
7731
|
+
for (i = 0; i < stack.length; i += 1) {
|
|
7732
|
+
if (stack[i] === obj) {
|
|
7733
|
+
return replacementStack[i];
|
|
7734
|
+
}
|
|
7735
|
+
}
|
|
7736
|
+
var canonicalizedObj;
|
|
7737
|
+
if ("[object Array]" === Object.prototype.toString.call(obj)) {
|
|
7738
|
+
stack.push(obj);
|
|
7739
|
+
canonicalizedObj = new Array(obj.length);
|
|
7740
|
+
replacementStack.push(canonicalizedObj);
|
|
7741
|
+
for (i = 0; i < obj.length; i += 1) {
|
|
7742
|
+
canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
|
|
7743
|
+
}
|
|
7744
|
+
stack.pop();
|
|
7745
|
+
replacementStack.pop();
|
|
7746
|
+
return canonicalizedObj;
|
|
7747
|
+
}
|
|
7748
|
+
if (obj && obj.toJSON) {
|
|
7749
|
+
obj = obj.toJSON();
|
|
7750
|
+
}
|
|
7751
|
+
if (_typeof(obj) === "object" && obj !== null) {
|
|
7752
|
+
stack.push(obj);
|
|
7753
|
+
canonicalizedObj = {};
|
|
7754
|
+
replacementStack.push(canonicalizedObj);
|
|
7755
|
+
var sortedKeys = [], _key;
|
|
7756
|
+
for (_key in obj) {
|
|
7757
|
+
if (Object.prototype.hasOwnProperty.call(obj, _key)) {
|
|
7758
|
+
sortedKeys.push(_key);
|
|
7759
|
+
}
|
|
7760
|
+
}
|
|
7761
|
+
sortedKeys.sort();
|
|
7762
|
+
for (i = 0; i < sortedKeys.length; i += 1) {
|
|
7763
|
+
_key = sortedKeys[i];
|
|
7764
|
+
canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
|
|
7765
|
+
}
|
|
7766
|
+
stack.pop();
|
|
7767
|
+
replacementStack.pop();
|
|
7768
|
+
} else {
|
|
7769
|
+
canonicalizedObj = obj;
|
|
7770
|
+
}
|
|
7771
|
+
return canonicalizedObj;
|
|
7772
|
+
}
|
|
7773
|
+
var arrayDiff = new Diff();
|
|
7774
|
+
arrayDiff.tokenize = function(value) {
|
|
7775
|
+
return value.slice();
|
|
7776
|
+
};
|
|
7777
|
+
arrayDiff.join = arrayDiff.removeEmpty = function(value) {
|
|
7778
|
+
return value;
|
|
7779
|
+
};
|
|
7780
|
+
|
|
7781
|
+
// src/run-scenario/file-diff.ts
|
|
7220
7782
|
var IGNORED_PATTERNS = [
|
|
7221
7783
|
"node_modules",
|
|
7222
7784
|
".git",
|
|
@@ -7305,38 +7867,18 @@ function snapshotDirectory(dir, baseDir) {
|
|
|
7305
7867
|
return snapshot;
|
|
7306
7868
|
}
|
|
7307
7869
|
function generateDiffLines(before, after) {
|
|
7308
|
-
const
|
|
7309
|
-
const afterLines = after.split("\n");
|
|
7870
|
+
const changes = diffLines(before, after);
|
|
7310
7871
|
const result = [];
|
|
7311
7872
|
let lineNumber = 1;
|
|
7312
|
-
const
|
|
7313
|
-
|
|
7314
|
-
const
|
|
7315
|
-
const
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
lineNumber: lineNumber++
|
|
7322
|
-
});
|
|
7323
|
-
}
|
|
7324
|
-
} else {
|
|
7325
|
-
if (beforeLine !== void 0) {
|
|
7326
|
-
result.push({
|
|
7327
|
-
type: "removed",
|
|
7328
|
-
content: beforeLine,
|
|
7329
|
-
lineNumber
|
|
7330
|
-
});
|
|
7331
|
-
}
|
|
7332
|
-
if (afterLine !== void 0) {
|
|
7333
|
-
result.push({
|
|
7334
|
-
type: "added",
|
|
7335
|
-
content: afterLine,
|
|
7336
|
-
lineNumber
|
|
7337
|
-
});
|
|
7338
|
-
}
|
|
7339
|
-
lineNumber++;
|
|
7873
|
+
for (const change of changes) {
|
|
7874
|
+
const lines = change.value.replace(/\n$/, "").split("\n");
|
|
7875
|
+
const type = change.added ? "added" : change.removed ? "removed" : "unchanged";
|
|
7876
|
+
for (const content of lines) {
|
|
7877
|
+
result.push({
|
|
7878
|
+
type,
|
|
7879
|
+
content,
|
|
7880
|
+
lineNumber: lineNumber++
|
|
7881
|
+
});
|
|
7340
7882
|
}
|
|
7341
7883
|
}
|
|
7342
7884
|
return result;
|
|
@@ -7350,12 +7892,12 @@ function diffSnapshots(before, after) {
|
|
|
7350
7892
|
if (before[path9] !== void 0 && beforeContent === afterContent) {
|
|
7351
7893
|
continue;
|
|
7352
7894
|
}
|
|
7353
|
-
const
|
|
7895
|
+
const diffLines2 = generateDiffLines(beforeContent, afterContent);
|
|
7354
7896
|
diffs.push({
|
|
7355
7897
|
path: path9,
|
|
7356
7898
|
expected: beforeContent,
|
|
7357
7899
|
actual: afterContent,
|
|
7358
|
-
diffLines
|
|
7900
|
+
diffLines: diffLines2
|
|
7359
7901
|
});
|
|
7360
7902
|
}
|
|
7361
7903
|
const deletedPaths = [...allPaths].filter((p) => after[p] === void 0);
|
|
@@ -7473,6 +8015,7 @@ async function runScenario(config, evalRunId2, scenario, target, template) {
|
|
|
7473
8015
|
config,
|
|
7474
8016
|
evalRunId2,
|
|
7475
8017
|
targetId,
|
|
8018
|
+
scenario.id,
|
|
7476
8019
|
template
|
|
7477
8020
|
);
|
|
7478
8021
|
let partialResult;
|