@quikit/quikpilot-runner 9.3.0-rc.15 → 9.3.0-rc.17
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/README.md +4 -0
- package/dist/index.js +545 -147
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -845,7 +845,7 @@ async function describeQuikTrackFailure(res) {
|
|
|
845
845
|
|
|
846
846
|
// src/callback.ts
|
|
847
847
|
async function reportBack(params) {
|
|
848
|
-
const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, codegenLoop, unresolved } = params;
|
|
848
|
+
const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, changesNoTestDependsOn, codegenLoop, unresolved } = params;
|
|
849
849
|
const body = { status };
|
|
850
850
|
if (branch) body.branch = branch;
|
|
851
851
|
if (warnings && warnings.length > 0) body.warnings = warnings;
|
|
@@ -854,6 +854,7 @@ async function reportBack(params) {
|
|
|
854
854
|
if (baselineFindings) body.baselineFindings = baselineFindings;
|
|
855
855
|
if (vanishedTests) body.vanishedTests = vanishedTests;
|
|
856
856
|
if (unsuppliedInputs && unsuppliedInputs.length > 0) body.unsuppliedInputs = unsuppliedInputs;
|
|
857
|
+
if (changesNoTestDependsOn && changesNoTestDependsOn.hunks.length > 0) body.changesNoTestDependsOn = changesNoTestDependsOn;
|
|
857
858
|
if (codegenLoop) body.codegenLoop = codegenLoop;
|
|
858
859
|
const res = await fetch(callbackUrl, {
|
|
859
860
|
method: "POST",
|
|
@@ -1579,8 +1580,8 @@ var TS_SIBLINGS = { ".js": [".ts", ".tsx"], ".jsx": [".tsx"], ".mjs": [".mts"],
|
|
|
1579
1580
|
function resolveImport(fromPath, specifier, listing) {
|
|
1580
1581
|
if (/^(?:@\/|~\/|#|\$|\/)/.test(specifier)) return { kind: "unresolved", reason: "alias" };
|
|
1581
1582
|
const clean = specifier.replace(/[?#].*$/, "");
|
|
1582
|
-
const
|
|
1583
|
-
if (!
|
|
1583
|
+
const relative10 = clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
|
|
1584
|
+
if (!relative10) return { kind: "external" };
|
|
1584
1585
|
const base = import_node_path.posix.normalize(import_node_path.posix.join(import_node_path.posix.dirname(fromPath), clean));
|
|
1585
1586
|
if (base === ".." || base.startsWith("../") || import_node_path.posix.isAbsolute(base)) return { kind: "unresolved", reason: "not found" };
|
|
1586
1587
|
const ext = import_node_path.posix.extname(base);
|
|
@@ -12463,6 +12464,14 @@ async function reportToQuikTest(params) {
|
|
|
12463
12464
|
|
|
12464
12465
|
// src/regressionCheck.ts
|
|
12465
12466
|
var import_node_fs8 = require("node:fs");
|
|
12467
|
+
|
|
12468
|
+
// src/pathShape.ts
|
|
12469
|
+
var PATH_EXTENSION_RE = /\.(ts|tsx|js|jsx|mjs|cjs|py|rb|go)$/i;
|
|
12470
|
+
function looksLikeFilePath(value) {
|
|
12471
|
+
return value.includes("/") || PATH_EXTENSION_RE.test(value);
|
|
12472
|
+
}
|
|
12473
|
+
|
|
12474
|
+
// src/regressionCheck.ts
|
|
12466
12475
|
var TESTCASE_RE = /<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g;
|
|
12467
12476
|
var NAME_ATTR_RE = /\bname="([^"]*)"/;
|
|
12468
12477
|
var CLASSNAME_ATTR_RE = /\bclassname="([^"]*)"/;
|
|
@@ -12509,6 +12518,7 @@ function parseJUnitOutcomes(xml) {
|
|
|
12509
12518
|
const failureText = /* @__PURE__ */ new Map();
|
|
12510
12519
|
const discoveredFiles = /* @__PURE__ */ new Set();
|
|
12511
12520
|
const discoveredAutomationIds = /* @__PURE__ */ new Set();
|
|
12521
|
+
let unmappedEntries = 0;
|
|
12512
12522
|
TESTSUITE_OPEN_RE.lastIndex = 0;
|
|
12513
12523
|
let suiteMatch;
|
|
12514
12524
|
while (suiteMatch = TESTSUITE_OPEN_RE.exec(xml)) {
|
|
@@ -12534,6 +12544,7 @@ function parseJUnitOutcomes(xml) {
|
|
|
12534
12544
|
const file = FILE_ATTR_RE.exec(attrs)?.[1];
|
|
12535
12545
|
if (file) discoveredFiles.add(normalizeSlashes(file));
|
|
12536
12546
|
if (classname) discoveredFiles.add(normalizeSlashes(classname));
|
|
12547
|
+
if (!file?.trim() && !(classname && looksLikeFilePath(classname.trim()))) unmappedEntries += 1;
|
|
12537
12548
|
const bracket = QP_TOKEN_BRACKET_RE.exec(name)?.[1];
|
|
12538
12549
|
if (bracket) {
|
|
12539
12550
|
discoveredAutomationIds.add(bracket);
|
|
@@ -12542,7 +12553,7 @@ function parseJUnitOutcomes(xml) {
|
|
|
12542
12553
|
if (!seen || RESULT_RANK[result] > RESULT_RANK[seen]) automationIdResults.set(bracket, result);
|
|
12543
12554
|
}
|
|
12544
12555
|
}
|
|
12545
|
-
return { outcomes, automationIdResults, failureText, discoveredFiles, discoveredAutomationIds };
|
|
12556
|
+
return { outcomes, automationIdResults, failureText, discoveredFiles, discoveredAutomationIds, unmappedEntries };
|
|
12546
12557
|
}
|
|
12547
12558
|
function readJUnitOutcomes(cwd) {
|
|
12548
12559
|
const report = findJUnitReport(cwd);
|
|
@@ -12564,7 +12575,8 @@ function captureTestSnapshot(command, cwd = process.cwd()) {
|
|
|
12564
12575
|
results: parsed?.outcomes ?? null,
|
|
12565
12576
|
failureText: parsed?.failureText,
|
|
12566
12577
|
discoveredFiles: parsed?.discoveredFiles ?? null,
|
|
12567
|
-
discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null
|
|
12578
|
+
discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
|
|
12579
|
+
unmappedEntries: parsed?.unmappedEntries
|
|
12568
12580
|
};
|
|
12569
12581
|
}
|
|
12570
12582
|
function readTestSnapshot(outcome, cwd = process.cwd()) {
|
|
@@ -12574,7 +12586,8 @@ function readTestSnapshot(outcome, cwd = process.cwd()) {
|
|
|
12574
12586
|
results: parsed?.outcomes ?? null,
|
|
12575
12587
|
failureText: parsed?.failureText,
|
|
12576
12588
|
discoveredFiles: parsed?.discoveredFiles ?? null,
|
|
12577
|
-
discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null
|
|
12589
|
+
discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
|
|
12590
|
+
unmappedEntries: parsed?.unmappedEntries
|
|
12578
12591
|
};
|
|
12579
12592
|
}
|
|
12580
12593
|
async function captureBaselineSnapshot(command, cwd = process.cwd()) {
|
|
@@ -12585,7 +12598,8 @@ async function captureBaselineSnapshot(command, cwd = process.cwd()) {
|
|
|
12585
12598
|
results: parsed?.outcomes ?? null,
|
|
12586
12599
|
failureText: parsed?.failureText,
|
|
12587
12600
|
discoveredFiles: parsed?.discoveredFiles ?? null,
|
|
12588
|
-
discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null
|
|
12601
|
+
discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
|
|
12602
|
+
unmappedEntries: parsed?.unmappedEntries
|
|
12589
12603
|
};
|
|
12590
12604
|
}
|
|
12591
12605
|
function checkForRegressions(baseline, after) {
|
|
@@ -13569,10 +13583,10 @@ async function postCodegenTurn(gateway, contextData, signal) {
|
|
|
13569
13583
|
return res.json();
|
|
13570
13584
|
}
|
|
13571
13585
|
function protectedTestFiles(listing, testDiscovery) {
|
|
13572
|
-
const
|
|
13586
|
+
const inListing2 = new Set(listing);
|
|
13573
13587
|
const found = new Set(listing.filter((p) => isTestTarget(p)));
|
|
13574
13588
|
if (testDiscovery.report === "PRESENT") {
|
|
13575
|
-
for (const p of testDiscovery.discoveredTestFiles) if (
|
|
13589
|
+
for (const p of testDiscovery.discoveredTestFiles) if (inListing2.has(p)) found.add(p);
|
|
13576
13590
|
}
|
|
13577
13591
|
return [...found].sort();
|
|
13578
13592
|
}
|
|
@@ -13923,6 +13937,313 @@ async function runVerifyAndFix(p) {
|
|
|
13923
13937
|
}
|
|
13924
13938
|
}
|
|
13925
13939
|
|
|
13940
|
+
// src/hunkCheck.ts
|
|
13941
|
+
var import_node_child_process5 = require("node:child_process");
|
|
13942
|
+
var import_node_fs12 = require("node:fs");
|
|
13943
|
+
var import_node_path10 = require("node:path");
|
|
13944
|
+
|
|
13945
|
+
// src/lineDiff.ts
|
|
13946
|
+
var DEFAULT_MAX_LINES = 4e3;
|
|
13947
|
+
var DEFAULT_MAX_CELLS = 4e6;
|
|
13948
|
+
function diffHunks(oldLf, newLf, limits = {}) {
|
|
13949
|
+
const maxLines = limits.maxLines ?? DEFAULT_MAX_LINES;
|
|
13950
|
+
const maxCells = limits.maxCells ?? DEFAULT_MAX_CELLS;
|
|
13951
|
+
const a = oldLf.split("\n");
|
|
13952
|
+
const b = newLf.split("\n");
|
|
13953
|
+
if (a.length > maxLines || b.length > maxLines) return null;
|
|
13954
|
+
let prefix = 0;
|
|
13955
|
+
while (prefix < a.length && prefix < b.length && a[prefix] === b[prefix]) prefix++;
|
|
13956
|
+
let suffix = 0;
|
|
13957
|
+
while (suffix < a.length - prefix && suffix < b.length - prefix && a[a.length - 1 - suffix] === b[b.length - 1 - suffix]) suffix++;
|
|
13958
|
+
const am = a.slice(prefix, a.length - suffix);
|
|
13959
|
+
const bm = b.slice(prefix, b.length - suffix);
|
|
13960
|
+
if (am.length === 0 && bm.length === 0) return [];
|
|
13961
|
+
if ((am.length + 1) * (bm.length + 1) > maxCells) return null;
|
|
13962
|
+
const n = am.length;
|
|
13963
|
+
const m = bm.length;
|
|
13964
|
+
const width = m + 1;
|
|
13965
|
+
const table = new Uint32Array((n + 1) * width);
|
|
13966
|
+
for (let i3 = n - 1; i3 >= 0; i3--) {
|
|
13967
|
+
for (let j2 = m - 1; j2 >= 0; j2--) {
|
|
13968
|
+
table[i3 * width + j2] = am[i3] === bm[j2] ? table[(i3 + 1) * width + j2 + 1] + 1 : Math.max(table[(i3 + 1) * width + j2], table[i3 * width + j2 + 1]);
|
|
13969
|
+
}
|
|
13970
|
+
}
|
|
13971
|
+
const raw = [];
|
|
13972
|
+
let i2 = 0;
|
|
13973
|
+
let j = 0;
|
|
13974
|
+
let open = null;
|
|
13975
|
+
const close = () => {
|
|
13976
|
+
if (!open) return;
|
|
13977
|
+
raw.push({ oldStart: prefix + open.oi + 1, oldLen: i2 - open.oi, newStart: prefix + open.nj + 1, newLen: j - open.nj });
|
|
13978
|
+
open = null;
|
|
13979
|
+
};
|
|
13980
|
+
while (i2 < n && j < m) {
|
|
13981
|
+
if (am[i2] === bm[j]) {
|
|
13982
|
+
close();
|
|
13983
|
+
i2++;
|
|
13984
|
+
j++;
|
|
13985
|
+
} else {
|
|
13986
|
+
open ??= { oi: i2, nj: j };
|
|
13987
|
+
if (table[(i2 + 1) * width + j] >= table[i2 * width + j + 1]) i2++;
|
|
13988
|
+
else j++;
|
|
13989
|
+
}
|
|
13990
|
+
}
|
|
13991
|
+
if (i2 < n || j < m) {
|
|
13992
|
+
open ??= { oi: i2, nj: j };
|
|
13993
|
+
i2 = n;
|
|
13994
|
+
j = m;
|
|
13995
|
+
}
|
|
13996
|
+
close();
|
|
13997
|
+
const merged = [];
|
|
13998
|
+
for (const h of raw) {
|
|
13999
|
+
const last = merged[merged.length - 1];
|
|
14000
|
+
if (last && h.oldStart - (last.oldStart + last.oldLen) <= 1) {
|
|
14001
|
+
last.oldLen = h.oldStart + h.oldLen - last.oldStart;
|
|
14002
|
+
last.newLen = h.newStart + h.newLen - last.newStart;
|
|
14003
|
+
} else {
|
|
14004
|
+
merged.push({ ...h });
|
|
14005
|
+
}
|
|
14006
|
+
}
|
|
14007
|
+
return merged;
|
|
14008
|
+
}
|
|
14009
|
+
function revertHunk(oldLf, newLf, hunk) {
|
|
14010
|
+
const a = oldLf.split("\n");
|
|
14011
|
+
const b = newLf.split("\n");
|
|
14012
|
+
b.splice(hunk.newStart - 1, hunk.newLen, ...a.slice(hunk.oldStart - 1, hunk.oldStart - 1 + hunk.oldLen));
|
|
14013
|
+
return b.join("\n");
|
|
14014
|
+
}
|
|
14015
|
+
function lineCount(lf) {
|
|
14016
|
+
if (lf === "") return 0;
|
|
14017
|
+
const n = lf.split("\n").length;
|
|
14018
|
+
return lf.endsWith("\n") ? n - 1 : n;
|
|
14019
|
+
}
|
|
14020
|
+
function hunkLines(hunk, totalLines) {
|
|
14021
|
+
const last = Math.max(1, totalLines);
|
|
14022
|
+
const startLine = Math.min(last, Math.max(1, hunk.newStart));
|
|
14023
|
+
const endLine = hunk.newLen > 0 ? Math.min(last, Math.max(startLine, hunk.newStart + hunk.newLen - 1)) : startLine;
|
|
14024
|
+
return { startLine, endLine };
|
|
14025
|
+
}
|
|
14026
|
+
function isWhitespaceOnly(oldLf, newLf, hunk) {
|
|
14027
|
+
const strip = (lines) => lines.join("").replace(/\s+/g, "");
|
|
14028
|
+
const before = strip(oldLf.split("\n").slice(hunk.oldStart - 1, hunk.oldStart - 1 + hunk.oldLen));
|
|
14029
|
+
const after = strip(newLf.split("\n").slice(hunk.newStart - 1, hunk.newStart - 1 + hunk.newLen));
|
|
14030
|
+
return before === after;
|
|
14031
|
+
}
|
|
14032
|
+
|
|
14033
|
+
// src/scopeCheck.ts
|
|
14034
|
+
var import_node_fs11 = require("node:fs");
|
|
14035
|
+
var ROUTE_METHOD_RE = /\b(GET|POST|PUT|PATCH|DELETE)\b/i;
|
|
14036
|
+
var ROUTE_PATH_RE = /\/[A-Za-z0-9_\-{}[\]]+(?:\/[A-Za-z0-9_\-:{}[\]]+)+/;
|
|
14037
|
+
var ROUTE_EXPORT_RE = /\bexport\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/;
|
|
14038
|
+
var NO_PATH = "(this file's route)";
|
|
14039
|
+
function detectMentions(text) {
|
|
14040
|
+
const found = [];
|
|
14041
|
+
for (const line of text.split("\n")) {
|
|
14042
|
+
const methodMatch = ROUTE_METHOD_RE.exec(line);
|
|
14043
|
+
const pathMatch = ROUTE_PATH_RE.exec(line);
|
|
14044
|
+
if (methodMatch && pathMatch) {
|
|
14045
|
+
found.push({ method: methodMatch[1].toUpperCase(), path: pathMatch[0] });
|
|
14046
|
+
}
|
|
14047
|
+
const exportMatch = ROUTE_EXPORT_RE.exec(line);
|
|
14048
|
+
if (exportMatch) {
|
|
14049
|
+
found.push({ method: exportMatch[1].toUpperCase(), path: NO_PATH });
|
|
14050
|
+
}
|
|
14051
|
+
}
|
|
14052
|
+
return found;
|
|
14053
|
+
}
|
|
14054
|
+
function normalizePath(path) {
|
|
14055
|
+
return path.replace(/:[A-Za-z0-9_]+|\{[^}]+\}|\[[^\]]+\]/g, "*");
|
|
14056
|
+
}
|
|
14057
|
+
function surfaceCovers(surface, mention) {
|
|
14058
|
+
if (!new RegExp(`\\b${mention.method}\\b`, "i").test(surface)) return false;
|
|
14059
|
+
if (mention.path === NO_PATH) return true;
|
|
14060
|
+
const declaredPath = normalizePath(surface);
|
|
14061
|
+
const mentionPath = normalizePath(mention.path);
|
|
14062
|
+
return declaredPath.includes(mentionPath) || mentionPath.includes(declaredPath);
|
|
14063
|
+
}
|
|
14064
|
+
function addedLines(before, after) {
|
|
14065
|
+
const beforeLines = new Set(before.split("\n"));
|
|
14066
|
+
return after.split("\n").filter((line) => !beforeLines.has(line)).join("\n");
|
|
14067
|
+
}
|
|
14068
|
+
var TEST_FILE_RES = [
|
|
14069
|
+
/(^|\/)(__tests__|__mocks__|tests?|specs?)\//i,
|
|
14070
|
+
/\.(test|spec)\.[^/.]+$/i,
|
|
14071
|
+
/(^|\/)test_[^/]+\.py$/i,
|
|
14072
|
+
/_test\.(py|go)$/i,
|
|
14073
|
+
/Tests?\.(java|kt|cs)$/
|
|
14074
|
+
];
|
|
14075
|
+
function isTestFile(path) {
|
|
14076
|
+
return TEST_FILE_RES.some((re) => re.test(path));
|
|
14077
|
+
}
|
|
14078
|
+
function checkApiScope(results, targets, apiChanges) {
|
|
14079
|
+
const targetsByPath = new Map(targets.map((t) => [t.path, t]));
|
|
14080
|
+
const violations = [];
|
|
14081
|
+
for (const { targetPath, newContent } of results) {
|
|
14082
|
+
if (isTestFile(targetPath)) continue;
|
|
14083
|
+
const target = targetsByPath.get(targetPath);
|
|
14084
|
+
const isNewFile = target?.kind === "NEW_FILE";
|
|
14085
|
+
let scanned;
|
|
14086
|
+
if (isNewFile) {
|
|
14087
|
+
scanned = newContent;
|
|
14088
|
+
} else {
|
|
14089
|
+
let currentContent;
|
|
14090
|
+
try {
|
|
14091
|
+
currentContent = (0, import_node_fs11.readFileSync)(targetPath, "utf8");
|
|
14092
|
+
} catch {
|
|
14093
|
+
currentContent = "";
|
|
14094
|
+
}
|
|
14095
|
+
scanned = addedLines(currentContent, newContent);
|
|
14096
|
+
}
|
|
14097
|
+
for (const mention of detectMentions(scanned)) {
|
|
14098
|
+
if (!apiChanges.some((c) => surfaceCovers(c.surface, mention))) {
|
|
14099
|
+
violations.push({ file: targetPath, method: mention.method, path: mention.path });
|
|
14100
|
+
}
|
|
14101
|
+
}
|
|
14102
|
+
}
|
|
14103
|
+
return { blocked: violations.length > 0, violations };
|
|
14104
|
+
}
|
|
14105
|
+
function describeScopeViolations(check) {
|
|
14106
|
+
return check.violations.map((v) => `${v.file} adds ${v.method} ${v.path}, not declared in the design's API changes`).join("; ");
|
|
14107
|
+
}
|
|
14108
|
+
|
|
14109
|
+
// src/hunkCheck.ts
|
|
14110
|
+
var MAX_REPORTED_HUNKS = 20;
|
|
14111
|
+
function toFinding(r) {
|
|
14112
|
+
if (r.unnecessary.length === 0) return void 0;
|
|
14113
|
+
return { hunks: r.unnecessary.slice(0, MAX_REPORTED_HUNKS), total: r.unnecessary.length, checked: r.checked };
|
|
14114
|
+
}
|
|
14115
|
+
var DEFAULT_MAX_HUNKS = 8;
|
|
14116
|
+
var MAX_FILE_BYTES = 1e6;
|
|
14117
|
+
var FRESH_SLACK_MS2 = 2e3;
|
|
14118
|
+
var SAFETY_MS = 6e4;
|
|
14119
|
+
var CODE_EXTENSIONS = /\.(?:[cm]?[jt]sx?|py|go|java|rb|rs|cs|php|kt)$/i;
|
|
14120
|
+
function eligibleForHunkCheck(path) {
|
|
14121
|
+
return CODE_EXTENSIONS.test(path) && !isTestFile(path);
|
|
14122
|
+
}
|
|
14123
|
+
function collectHunkCheckFiles(results, root, readHead = readCommittedText) {
|
|
14124
|
+
const files = [];
|
|
14125
|
+
for (const r of results) {
|
|
14126
|
+
if (safeRelativePath(r.targetPath) === null || !eligibleForHunkCheck(r.targetPath)) continue;
|
|
14127
|
+
const raw = readHead(root, r.targetPath);
|
|
14128
|
+
if (raw === null) continue;
|
|
14129
|
+
files.push({ path: r.targetPath, originalLf: toLf(raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw) });
|
|
14130
|
+
}
|
|
14131
|
+
return files;
|
|
14132
|
+
}
|
|
14133
|
+
function readCommittedText(root, path) {
|
|
14134
|
+
try {
|
|
14135
|
+
return (0, import_node_child_process5.execFileSync)("git", ["show", `HEAD:${path}`], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 8 * 1024 * 1024 });
|
|
14136
|
+
} catch {
|
|
14137
|
+
return null;
|
|
14138
|
+
}
|
|
14139
|
+
}
|
|
14140
|
+
async function runHunkCheck(input) {
|
|
14141
|
+
const now = input.now ?? Date.now;
|
|
14142
|
+
const log = input.log ?? (() => {
|
|
14143
|
+
});
|
|
14144
|
+
const result = { unnecessary: [], checked: 0, total: 0, skipped: { whitespace: 0, tooBig: 0, cap: 0, time: 0, unknown: 0, files: 0 } };
|
|
14145
|
+
if (!input.baseline.results || input.baseline.results.size === 0) return { ...result, stopped: "no_baseline" };
|
|
14146
|
+
const limit = testTimeLimitMs(input.baselineMs);
|
|
14147
|
+
if (limit === "too_slow") return { ...result, stopped: "too_slow" };
|
|
14148
|
+
const perRunMs = input.baselineMs === null ? limit : Math.min(limit, Math.max(3e4, 2 * input.baselineMs));
|
|
14149
|
+
const fs = createNodeWriteFs(input.root);
|
|
14150
|
+
const candidates = [];
|
|
14151
|
+
for (const f of input.files) {
|
|
14152
|
+
const loaded = loadTextForEdit(fs, f.path, MAX_FILE_BYTES);
|
|
14153
|
+
if (!loaded.ok) {
|
|
14154
|
+
result.skipped.files += 1;
|
|
14155
|
+
continue;
|
|
14156
|
+
}
|
|
14157
|
+
const hunks = diffHunks(f.originalLf, loaded.lf, input.maxLines !== void 0 ? { maxLines: input.maxLines } : {});
|
|
14158
|
+
if (hunks === null) {
|
|
14159
|
+
result.skipped.tooBig += 1;
|
|
14160
|
+
continue;
|
|
14161
|
+
}
|
|
14162
|
+
const totalLines = lineCount(loaded.lf);
|
|
14163
|
+
for (const hunk of hunks) {
|
|
14164
|
+
if (isWhitespaceOnly(f.originalLf, loaded.lf, hunk)) {
|
|
14165
|
+
result.skipped.whitespace += 1;
|
|
14166
|
+
continue;
|
|
14167
|
+
}
|
|
14168
|
+
candidates.push({ file: f.path, ending: loaded.ending, bom: loaded.bom, originalLf: f.originalLf, currentLf: loaded.lf, hunk, totalLines });
|
|
14169
|
+
}
|
|
14170
|
+
}
|
|
14171
|
+
result.total = candidates.length;
|
|
14172
|
+
const findReport = input.findReport ?? findJUnitReport;
|
|
14173
|
+
const readSnapshot = input.readSnapshot ?? readTestSnapshot;
|
|
14174
|
+
const runCommand2 = input.runCommand ?? runTestCommandWithLimit;
|
|
14175
|
+
let slowestRunMs = input.baselineMs ?? 3e4;
|
|
14176
|
+
const runOnce = async (c) => {
|
|
14177
|
+
const reportBefore = findReport(input.root);
|
|
14178
|
+
const preserve = reportBefore ? [(0, import_node_path10.relative)(input.root, reportBefore).split("\\").join("/")] : [];
|
|
14179
|
+
const content = `${c.bom ? "\uFEFF" : ""}${fromLf(revertHunk(c.originalLf, c.currentLf, c.hunk), c.ending)}`;
|
|
14180
|
+
const startedWall = Date.now();
|
|
14181
|
+
const startedAt = now();
|
|
14182
|
+
try {
|
|
14183
|
+
const verdict = await withOverlayOnDisk(
|
|
14184
|
+
input.root,
|
|
14185
|
+
[{ path: c.file, content }],
|
|
14186
|
+
async () => {
|
|
14187
|
+
if (reportBefore) (0, import_node_fs12.rmSync)(reportBefore, { force: true });
|
|
14188
|
+
const run2 = await runCommand2(input.command, perRunMs, input.root);
|
|
14189
|
+
if (!run2.started || run2.timedOut) return "unknown";
|
|
14190
|
+
const report = findReport(input.root);
|
|
14191
|
+
if (!report) return "unknown";
|
|
14192
|
+
try {
|
|
14193
|
+
if ((0, import_node_fs12.statSync)(report).mtimeMs < startedWall - FRESH_SLACK_MS2) return "unknown";
|
|
14194
|
+
} catch {
|
|
14195
|
+
return "unknown";
|
|
14196
|
+
}
|
|
14197
|
+
const after = readSnapshot(run2.outcome, input.root);
|
|
14198
|
+
if (!after.results || after.results.size === 0) return "unknown";
|
|
14199
|
+
if (after.results.size < input.finalTestCount) return "needed";
|
|
14200
|
+
return checkForRegressions(input.baseline, after).blocked ? "needed" : "unneeded";
|
|
14201
|
+
},
|
|
14202
|
+
{ ...input.tree, preserve }
|
|
14203
|
+
);
|
|
14204
|
+
slowestRunMs = Math.max(slowestRunMs, now() - startedAt);
|
|
14205
|
+
return verdict;
|
|
14206
|
+
} catch (err) {
|
|
14207
|
+
if (err instanceof DiskWriteRefused) return "unknown";
|
|
14208
|
+
throw err;
|
|
14209
|
+
}
|
|
14210
|
+
};
|
|
14211
|
+
const queue = candidates.slice(0, input.maxHunks ?? DEFAULT_MAX_HUNKS);
|
|
14212
|
+
result.skipped.cap = candidates.length - queue.length;
|
|
14213
|
+
let handled = 0;
|
|
14214
|
+
try {
|
|
14215
|
+
for (const c of queue) {
|
|
14216
|
+
if (now() + slowestRunMs + SAFETY_MS > input.deadlineAtMs) {
|
|
14217
|
+
result.stopped = "out_of_time";
|
|
14218
|
+
break;
|
|
14219
|
+
}
|
|
14220
|
+
handled += 1;
|
|
14221
|
+
result.checked += 1;
|
|
14222
|
+
let verdict = await runOnce(c);
|
|
14223
|
+
if (verdict === "unneeded") verdict = await runOnce(c);
|
|
14224
|
+
log({ event: "hunk_check.block", verdict });
|
|
14225
|
+
if (verdict === "unknown") result.skipped.unknown += 1;
|
|
14226
|
+
else if (verdict === "unneeded") {
|
|
14227
|
+
const { startLine, endLine } = hunkLines(c.hunk, c.totalLines);
|
|
14228
|
+
result.unnecessary.push({ file: c.file, startLine, endLine });
|
|
14229
|
+
}
|
|
14230
|
+
}
|
|
14231
|
+
} catch (err) {
|
|
14232
|
+
if (err instanceof TreeUnverifiableError) {
|
|
14233
|
+
result.checked -= 1;
|
|
14234
|
+
return { ...result, stopped: "tree_unverifiable" };
|
|
14235
|
+
}
|
|
14236
|
+
throw err;
|
|
14237
|
+
}
|
|
14238
|
+
result.skipped.time = queue.length - handled;
|
|
14239
|
+
result.unnecessary.sort((a, b) => a.file.localeCompare(b.file) || a.startLine - b.startLine);
|
|
14240
|
+
return result;
|
|
14241
|
+
}
|
|
14242
|
+
function describeHunkCheck(r) {
|
|
14243
|
+
const n = r.unnecessary.length;
|
|
14244
|
+
return `${n} ${n === 1 ? "change" : "changes"} QuikPilot made ${n === 1 ? "has" : "have"} no test that depends on ${n === 1 ? "it" : "them"} (checked ${r.checked} of ${r.total}). See "What QuikPilot noticed".`;
|
|
14245
|
+
}
|
|
14246
|
+
|
|
13926
14247
|
// src/healRecord.ts
|
|
13927
14248
|
var ZERO = {
|
|
13928
14249
|
turns: 0,
|
|
@@ -13980,9 +14301,9 @@ function healFailureSuffix(heal) {
|
|
|
13980
14301
|
}
|
|
13981
14302
|
|
|
13982
14303
|
// src/baselineCheck.ts
|
|
13983
|
-
var
|
|
13984
|
-
var
|
|
13985
|
-
var
|
|
14304
|
+
var import_node_child_process6 = require("node:child_process");
|
|
14305
|
+
var import_node_fs13 = require("node:fs");
|
|
14306
|
+
var import_node_path11 = require("node:path");
|
|
13986
14307
|
var BASELINE_CHECK_TIMEOUT_MS = 12e4;
|
|
13987
14308
|
function shellQuote(value) {
|
|
13988
14309
|
return `'${value.split("'").join("'\\''")}'`;
|
|
@@ -14001,32 +14322,32 @@ function checkableIds(ids, types2) {
|
|
|
14001
14322
|
});
|
|
14002
14323
|
}
|
|
14003
14324
|
function insideCheckout(cwd, path) {
|
|
14004
|
-
const abs = (0,
|
|
14005
|
-
const rel = (0,
|
|
14006
|
-
return rel === "" || rel.startsWith("..") || (0,
|
|
14325
|
+
const abs = (0, import_node_path11.resolve)(cwd, path);
|
|
14326
|
+
const rel = (0, import_node_path11.relative)(cwd, abs);
|
|
14327
|
+
return rel === "" || rel.startsWith("..") || (0, import_node_path11.isAbsolute)(rel) ? null : abs;
|
|
14007
14328
|
}
|
|
14008
14329
|
function writeForCheck(abs, content) {
|
|
14009
|
-
const original = (0,
|
|
14330
|
+
const original = (0, import_node_fs13.existsSync)(abs) ? (0, import_node_fs13.readFileSync)(abs) : null;
|
|
14010
14331
|
const createdDirs = [];
|
|
14011
14332
|
if (original === null) {
|
|
14012
14333
|
const missing = [];
|
|
14013
|
-
for (let d = (0,
|
|
14334
|
+
for (let d = (0, import_node_path11.dirname)(abs); !(0, import_node_fs13.existsSync)(d); d = (0, import_node_path11.dirname)(d)) missing.push(d);
|
|
14014
14335
|
for (const d of missing.reverse()) {
|
|
14015
|
-
(0,
|
|
14336
|
+
(0, import_node_fs13.mkdirSync)(d);
|
|
14016
14337
|
createdDirs.push(d);
|
|
14017
14338
|
}
|
|
14018
14339
|
}
|
|
14019
|
-
(0,
|
|
14340
|
+
(0, import_node_fs13.writeFileSync)(abs, content);
|
|
14020
14341
|
return { abs, original, createdDirs };
|
|
14021
14342
|
}
|
|
14022
14343
|
function restore(written) {
|
|
14023
14344
|
for (const file of [...written].reverse()) {
|
|
14024
14345
|
try {
|
|
14025
|
-
if (file.original !== null) (0,
|
|
14026
|
-
else (0,
|
|
14346
|
+
if (file.original !== null) (0, import_node_fs13.writeFileSync)(file.abs, file.original);
|
|
14347
|
+
else (0, import_node_fs13.rmSync)(file.abs, { force: true });
|
|
14027
14348
|
for (const d of [...file.createdDirs].reverse()) {
|
|
14028
14349
|
try {
|
|
14029
|
-
(0,
|
|
14350
|
+
(0, import_node_fs13.rmdirSync)(d);
|
|
14030
14351
|
} catch {
|
|
14031
14352
|
}
|
|
14032
14353
|
}
|
|
@@ -14037,7 +14358,7 @@ function restore(written) {
|
|
|
14037
14358
|
}
|
|
14038
14359
|
function untrackedFiles(cwd) {
|
|
14039
14360
|
try {
|
|
14040
|
-
const out = (0,
|
|
14361
|
+
const out = (0, import_node_child_process6.execFileSync)("git", ["ls-files", "--others", "--exclude-standard", "-z"], {
|
|
14041
14362
|
cwd,
|
|
14042
14363
|
encoding: "utf8",
|
|
14043
14364
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -14050,7 +14371,7 @@ function untrackedFiles(cwd) {
|
|
|
14050
14371
|
}
|
|
14051
14372
|
var mtimeOf = (path) => {
|
|
14052
14373
|
try {
|
|
14053
|
-
return (0,
|
|
14374
|
+
return (0, import_node_fs13.statSync)(path).mtimeMs;
|
|
14054
14375
|
} catch {
|
|
14055
14376
|
return null;
|
|
14056
14377
|
}
|
|
@@ -14064,7 +14385,7 @@ function decideCause(targets, results, cwd) {
|
|
|
14064
14385
|
const abs = insideCheckout(cwd, t.path);
|
|
14065
14386
|
if (next === void 0 || abs === null) return "ALREADY_TRUE";
|
|
14066
14387
|
try {
|
|
14067
|
-
if ((0,
|
|
14388
|
+
if ((0, import_node_fs13.readFileSync)(abs, "utf8") !== next) return "ALREADY_TRUE";
|
|
14068
14389
|
} catch {
|
|
14069
14390
|
return "ALREADY_TRUE";
|
|
14070
14391
|
}
|
|
@@ -14140,7 +14461,7 @@ async function runBaselineCheck(params) {
|
|
|
14140
14461
|
for (const file of untrackedAfter) {
|
|
14141
14462
|
if (untrackedBefore.has(file)) continue;
|
|
14142
14463
|
const abs = insideCheckout(cwd, file);
|
|
14143
|
-
if (abs) (0,
|
|
14464
|
+
if (abs) (0, import_node_fs13.rmSync)(abs, { force: true });
|
|
14144
14465
|
}
|
|
14145
14466
|
}
|
|
14146
14467
|
}
|
|
@@ -14161,8 +14482,8 @@ async function runBaselineCheck(params) {
|
|
|
14161
14482
|
}
|
|
14162
14483
|
|
|
14163
14484
|
// src/dependencyCheck.ts
|
|
14164
|
-
var
|
|
14165
|
-
var
|
|
14485
|
+
var import_node_fs14 = require("node:fs");
|
|
14486
|
+
var import_node_path12 = require("node:path");
|
|
14166
14487
|
var SCANNABLE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"];
|
|
14167
14488
|
var IMPORT_RE = /(?:\bimport\b[^'"]*?\bfrom\s*|\bimport\s*\(\s*|\bexport\b[^'"]*?\bfrom\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"]+)\1/g;
|
|
14168
14489
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
@@ -14241,14 +14562,14 @@ function dependencyNames(pkg) {
|
|
|
14241
14562
|
]);
|
|
14242
14563
|
}
|
|
14243
14564
|
function readDeclaredDependencies(results, workspaceRoot) {
|
|
14244
|
-
const packageJsonPath = (0,
|
|
14245
|
-
const generated = results.find((r) => (0,
|
|
14565
|
+
const packageJsonPath = (0, import_node_path12.join)((0, import_node_path12.resolve)(workspaceRoot ?? "."), "package.json");
|
|
14566
|
+
const generated = results.find((r) => (0, import_node_path12.resolve)(r.targetPath) === packageJsonPath);
|
|
14246
14567
|
let raw;
|
|
14247
14568
|
if (generated) {
|
|
14248
14569
|
raw = generated.newContent;
|
|
14249
14570
|
} else {
|
|
14250
14571
|
try {
|
|
14251
|
-
raw = (0,
|
|
14572
|
+
raw = (0, import_node_fs14.readFileSync)(packageJsonPath, "utf8");
|
|
14252
14573
|
} catch {
|
|
14253
14574
|
raw = null;
|
|
14254
14575
|
}
|
|
@@ -14312,16 +14633,16 @@ function stripJsonComments(text) {
|
|
|
14312
14633
|
return out.replace(/,(\s*[}\]])/g, "$1");
|
|
14313
14634
|
}
|
|
14314
14635
|
function resolveAliasPrefixes(results, workspaceRoot) {
|
|
14315
|
-
const root = (0,
|
|
14636
|
+
const root = (0, import_node_path12.resolve)(workspaceRoot ?? ".");
|
|
14316
14637
|
for (const filename of ["tsconfig.json", "jsconfig.json"]) {
|
|
14317
|
-
const configPath = (0,
|
|
14318
|
-
const generated = results.find((r) => (0,
|
|
14638
|
+
const configPath = (0, import_node_path12.join)(root, filename);
|
|
14639
|
+
const generated = results.find((r) => (0, import_node_path12.resolve)(r.targetPath) === configPath);
|
|
14319
14640
|
let raw;
|
|
14320
14641
|
if (generated) {
|
|
14321
14642
|
raw = generated.newContent;
|
|
14322
14643
|
} else {
|
|
14323
14644
|
try {
|
|
14324
|
-
raw = (0,
|
|
14645
|
+
raw = (0, import_node_fs14.readFileSync)(configPath, "utf8");
|
|
14325
14646
|
} catch {
|
|
14326
14647
|
raw = null;
|
|
14327
14648
|
}
|
|
@@ -14342,82 +14663,6 @@ function describeDependencyViolations(check) {
|
|
|
14342
14663
|
return check.violations.map((v) => `${v.file} imports ${v.packages.join(", ")}, not a dependency of this repository`).join("; ");
|
|
14343
14664
|
}
|
|
14344
14665
|
|
|
14345
|
-
// src/scopeCheck.ts
|
|
14346
|
-
var import_node_fs13 = require("node:fs");
|
|
14347
|
-
var ROUTE_METHOD_RE = /\b(GET|POST|PUT|PATCH|DELETE)\b/i;
|
|
14348
|
-
var ROUTE_PATH_RE = /\/[A-Za-z0-9_\-{}[\]]+(?:\/[A-Za-z0-9_\-:{}[\]]+)+/;
|
|
14349
|
-
var ROUTE_EXPORT_RE = /\bexport\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/;
|
|
14350
|
-
var NO_PATH = "(this file's route)";
|
|
14351
|
-
function detectMentions(text) {
|
|
14352
|
-
const found = [];
|
|
14353
|
-
for (const line of text.split("\n")) {
|
|
14354
|
-
const methodMatch = ROUTE_METHOD_RE.exec(line);
|
|
14355
|
-
const pathMatch = ROUTE_PATH_RE.exec(line);
|
|
14356
|
-
if (methodMatch && pathMatch) {
|
|
14357
|
-
found.push({ method: methodMatch[1].toUpperCase(), path: pathMatch[0] });
|
|
14358
|
-
}
|
|
14359
|
-
const exportMatch = ROUTE_EXPORT_RE.exec(line);
|
|
14360
|
-
if (exportMatch) {
|
|
14361
|
-
found.push({ method: exportMatch[1].toUpperCase(), path: NO_PATH });
|
|
14362
|
-
}
|
|
14363
|
-
}
|
|
14364
|
-
return found;
|
|
14365
|
-
}
|
|
14366
|
-
function normalizePath(path) {
|
|
14367
|
-
return path.replace(/:[A-Za-z0-9_]+|\{[^}]+\}|\[[^\]]+\]/g, "*");
|
|
14368
|
-
}
|
|
14369
|
-
function surfaceCovers(surface, mention) {
|
|
14370
|
-
if (!new RegExp(`\\b${mention.method}\\b`, "i").test(surface)) return false;
|
|
14371
|
-
if (mention.path === NO_PATH) return true;
|
|
14372
|
-
const declaredPath = normalizePath(surface);
|
|
14373
|
-
const mentionPath = normalizePath(mention.path);
|
|
14374
|
-
return declaredPath.includes(mentionPath) || mentionPath.includes(declaredPath);
|
|
14375
|
-
}
|
|
14376
|
-
function addedLines(before, after) {
|
|
14377
|
-
const beforeLines = new Set(before.split("\n"));
|
|
14378
|
-
return after.split("\n").filter((line) => !beforeLines.has(line)).join("\n");
|
|
14379
|
-
}
|
|
14380
|
-
var TEST_FILE_RES = [
|
|
14381
|
-
/(^|\/)(__tests__|__mocks__|tests?|specs?)\//i,
|
|
14382
|
-
/\.(test|spec)\.[^/.]+$/i,
|
|
14383
|
-
/(^|\/)test_[^/]+\.py$/i,
|
|
14384
|
-
/_test\.(py|go)$/i,
|
|
14385
|
-
/Tests?\.(java|kt|cs)$/
|
|
14386
|
-
];
|
|
14387
|
-
function isTestFile(path) {
|
|
14388
|
-
return TEST_FILE_RES.some((re) => re.test(path));
|
|
14389
|
-
}
|
|
14390
|
-
function checkApiScope(results, targets, apiChanges) {
|
|
14391
|
-
const targetsByPath = new Map(targets.map((t) => [t.path, t]));
|
|
14392
|
-
const violations = [];
|
|
14393
|
-
for (const { targetPath, newContent } of results) {
|
|
14394
|
-
if (isTestFile(targetPath)) continue;
|
|
14395
|
-
const target = targetsByPath.get(targetPath);
|
|
14396
|
-
const isNewFile = target?.kind === "NEW_FILE";
|
|
14397
|
-
let scanned;
|
|
14398
|
-
if (isNewFile) {
|
|
14399
|
-
scanned = newContent;
|
|
14400
|
-
} else {
|
|
14401
|
-
let currentContent;
|
|
14402
|
-
try {
|
|
14403
|
-
currentContent = (0, import_node_fs13.readFileSync)(targetPath, "utf8");
|
|
14404
|
-
} catch {
|
|
14405
|
-
currentContent = "";
|
|
14406
|
-
}
|
|
14407
|
-
scanned = addedLines(currentContent, newContent);
|
|
14408
|
-
}
|
|
14409
|
-
for (const mention of detectMentions(scanned)) {
|
|
14410
|
-
if (!apiChanges.some((c) => surfaceCovers(c.surface, mention))) {
|
|
14411
|
-
violations.push({ file: targetPath, method: mention.method, path: mention.path });
|
|
14412
|
-
}
|
|
14413
|
-
}
|
|
14414
|
-
}
|
|
14415
|
-
return { blocked: violations.length > 0, violations };
|
|
14416
|
-
}
|
|
14417
|
-
function describeScopeViolations(check) {
|
|
14418
|
-
return check.violations.map((v) => `${v.file} adds ${v.method} ${v.path}, not declared in the design's API changes`).join("; ");
|
|
14419
|
-
}
|
|
14420
|
-
|
|
14421
14666
|
// src/testPlacementCheck.ts
|
|
14422
14667
|
function isDiscovered(targetPath, discoveredFiles) {
|
|
14423
14668
|
const normalized = targetPath.replace(/\\/g, "/");
|
|
@@ -14647,13 +14892,13 @@ function describeUnsuppliedInputs(found) {
|
|
|
14647
14892
|
}
|
|
14648
14893
|
|
|
14649
14894
|
// src/unsuppliedInputsDisk.ts
|
|
14650
|
-
var
|
|
14895
|
+
var import_node_fs15 = require("node:fs");
|
|
14651
14896
|
var MAX_READ_BYTES = 1e6;
|
|
14652
14897
|
function readCheckoutText(path) {
|
|
14653
14898
|
try {
|
|
14654
|
-
const info = (0,
|
|
14899
|
+
const info = (0, import_node_fs15.statSync)(path);
|
|
14655
14900
|
if (!info.isFile() || info.size > MAX_READ_BYTES) return null;
|
|
14656
|
-
const bytes = (0,
|
|
14901
|
+
const bytes = (0, import_node_fs15.readFileSync)(path);
|
|
14657
14902
|
if (bytes.includes(0)) return null;
|
|
14658
14903
|
return bytes.toString("utf8");
|
|
14659
14904
|
} catch {
|
|
@@ -14682,7 +14927,7 @@ function describeVanishedTests(vanished) {
|
|
|
14682
14927
|
}
|
|
14683
14928
|
|
|
14684
14929
|
// src/verifyChange.ts
|
|
14685
|
-
var
|
|
14930
|
+
var import_node_path13 = require("node:path");
|
|
14686
14931
|
async function verifyChange(ctx, results, undoable) {
|
|
14687
14932
|
const cwd = ctx.cwd ?? process.cwd();
|
|
14688
14933
|
const now = ctx.now ?? Date.now;
|
|
@@ -14751,7 +14996,7 @@ async function verifyChange(ctx, results, undoable) {
|
|
|
14751
14996
|
flushedAt = now();
|
|
14752
14997
|
if (undoable) {
|
|
14753
14998
|
const report = findJUnitReport(cwd);
|
|
14754
|
-
const ignore = report ? [(0,
|
|
14999
|
+
const ignore = report ? [(0, import_node_path13.relative)(cwd, report).split("\\").join("/")] : [];
|
|
14755
15000
|
const flush = undoableFlush(cwd, results, flushCodegenResults, { ignore });
|
|
14756
15001
|
undo = () => flush.undo();
|
|
14757
15002
|
} else {
|
|
@@ -14768,6 +15013,7 @@ async function verifyChange(ctx, results, undoable) {
|
|
|
14768
15013
|
stage = "gate";
|
|
14769
15014
|
const after = captureTestSnapshot(packet.commands.test);
|
|
14770
15015
|
outputs.finalTestReport = readTestReportBytes();
|
|
15016
|
+
outputs.testCount = after.results?.size;
|
|
14771
15017
|
outputs.vanishedTests = findVanishedTests(baseline, after) ?? void 0;
|
|
14772
15018
|
if (outputs.vanishedTests) {
|
|
14773
15019
|
const w = describeVanishedTests(outputs.vanishedTests);
|
|
@@ -14864,34 +15110,34 @@ async function fetchPacket(packetUrl, runToken, githubRunId) {
|
|
|
14864
15110
|
}
|
|
14865
15111
|
|
|
14866
15112
|
// src/phase0.ts
|
|
14867
|
-
var
|
|
15113
|
+
var import_node_fs16 = require("node:fs");
|
|
14868
15114
|
function writePhase0Marker(runId) {
|
|
14869
|
-
(0,
|
|
14870
|
-
(0,
|
|
15115
|
+
(0, import_node_fs16.mkdirSync)(".quikpilot", { recursive: true });
|
|
15116
|
+
(0, import_node_fs16.appendFileSync)(".quikpilot/phase0-marker.txt", `QuikPilot Phase 0 skeleton marker for run ${runId}
|
|
14871
15117
|
`);
|
|
14872
15118
|
}
|
|
14873
15119
|
|
|
14874
15120
|
// src/failureArtifact.ts
|
|
14875
|
-
var
|
|
14876
|
-
var
|
|
15121
|
+
var import_node_fs17 = require("node:fs");
|
|
15122
|
+
var import_node_path14 = require("node:path");
|
|
14877
15123
|
var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
|
|
14878
15124
|
var REPORT_COPY = "final-test-report.xml";
|
|
14879
15125
|
var MAX_REPORT_BYTES = 5 * 1024 * 1024;
|
|
14880
15126
|
var MAX_FILES = 200;
|
|
14881
|
-
var RUNNER_VERSION = true ? "9.3.0-rc.
|
|
15127
|
+
var RUNNER_VERSION = true ? "9.3.0-rc.17" : "dev";
|
|
14882
15128
|
function safeDestination(base, repoPath) {
|
|
14883
|
-
if (!repoPath || (0,
|
|
14884
|
-
const destination = (0,
|
|
14885
|
-
const rel = (0,
|
|
14886
|
-
if (!rel || rel.startsWith("..") || (0,
|
|
15129
|
+
if (!repoPath || (0, import_node_path14.isAbsolute)(repoPath)) return null;
|
|
15130
|
+
const destination = (0, import_node_path14.resolve)(base, repoPath);
|
|
15131
|
+
const rel = (0, import_node_path14.relative)(base, destination);
|
|
15132
|
+
if (!rel || rel.startsWith("..") || (0, import_node_path14.isAbsolute)(rel)) return null;
|
|
14887
15133
|
return destination;
|
|
14888
15134
|
}
|
|
14889
15135
|
function writeFailureArtifact(input) {
|
|
14890
15136
|
if (input.results.length === 0) return { written: false };
|
|
14891
15137
|
try {
|
|
14892
|
-
const base = (0,
|
|
14893
|
-
(0,
|
|
14894
|
-
(0,
|
|
15138
|
+
const base = (0, import_node_path14.resolve)(input.cwd, FAILURE_ARTIFACT_DIR);
|
|
15139
|
+
(0, import_node_fs17.rmSync)(base, { recursive: true, force: true });
|
|
15140
|
+
(0, import_node_fs17.mkdirSync)(base, { recursive: true });
|
|
14895
15141
|
const files = [];
|
|
14896
15142
|
const skipped = [];
|
|
14897
15143
|
for (const result of input.results) {
|
|
@@ -14900,8 +15146,8 @@ function writeFailureArtifact(input) {
|
|
|
14900
15146
|
skipped.push(result.targetPath);
|
|
14901
15147
|
continue;
|
|
14902
15148
|
}
|
|
14903
|
-
(0,
|
|
14904
|
-
(0,
|
|
15149
|
+
(0, import_node_fs17.mkdirSync)((0, import_node_path14.dirname)(destination), { recursive: true });
|
|
15150
|
+
(0, import_node_fs17.writeFileSync)(destination, result.newContent);
|
|
14905
15151
|
files.push({ path: result.targetPath, bytes: Buffer.byteLength(result.newContent) });
|
|
14906
15152
|
}
|
|
14907
15153
|
let testReport = "none";
|
|
@@ -14909,7 +15155,7 @@ function writeFailureArtifact(input) {
|
|
|
14909
15155
|
if (input.testReport.byteLength > MAX_REPORT_BYTES) {
|
|
14910
15156
|
testReport = "too-large";
|
|
14911
15157
|
} else {
|
|
14912
|
-
(0,
|
|
15158
|
+
(0, import_node_fs17.writeFileSync)((0, import_node_path14.join)(base, REPORT_COPY), input.testReport);
|
|
14913
15159
|
testReport = "included";
|
|
14914
15160
|
}
|
|
14915
15161
|
}
|
|
@@ -14929,16 +15175,108 @@ function writeFailureArtifact(input) {
|
|
|
14929
15175
|
failureReasons: input.failureReasons
|
|
14930
15176
|
};
|
|
14931
15177
|
const text = JSON.stringify(manifest, (_key, value) => typeof value === "string" ? scrubSecrets(value, input.secrets) : value, 2);
|
|
14932
|
-
(0,
|
|
14933
|
-
return { written: (0,
|
|
15178
|
+
(0, import_node_fs17.writeFileSync)((0, import_node_path14.join)(base, "manifest.json"), text);
|
|
15179
|
+
return { written: (0, import_node_fs17.existsSync)((0, import_node_path14.join)(base, "manifest.json")) };
|
|
14934
15180
|
} catch (err) {
|
|
14935
15181
|
console.warn(`::warning::Could not keep the failed run's files: ${err instanceof Error ? err.message : String(err)}`);
|
|
14936
15182
|
return { written: false };
|
|
14937
15183
|
}
|
|
14938
15184
|
}
|
|
14939
15185
|
|
|
15186
|
+
// src/testDiscovery.ts
|
|
15187
|
+
var ABSENT = { report: "ABSENT" };
|
|
15188
|
+
var DRIVE_RE = /^[A-Za-z]:\//;
|
|
15189
|
+
function absent(reason) {
|
|
15190
|
+
return { value: { ...ABSENT }, source: "absent", reason, files: 0, unmapped: 0 };
|
|
15191
|
+
}
|
|
15192
|
+
var slashes = (p) => p.replace(/\\/g, "/");
|
|
15193
|
+
var withoutDotSlash = (p) => p.replace(/^(\.\/)+/, "");
|
|
15194
|
+
function relativeToRepository(raw, cwd) {
|
|
15195
|
+
const path = withoutDotSlash(slashes(raw.trim()));
|
|
15196
|
+
let relative10 = path;
|
|
15197
|
+
if (path.startsWith("/") || DRIVE_RE.test(path)) {
|
|
15198
|
+
const root = slashes(cwd).replace(/\/+$/, "");
|
|
15199
|
+
const windows = DRIVE_RE.test(path) || DRIVE_RE.test(root);
|
|
15200
|
+
const a = windows ? path.toLowerCase() : path;
|
|
15201
|
+
const b = windows ? root.toLowerCase() : root;
|
|
15202
|
+
if (!a.startsWith(`${b}/`)) return null;
|
|
15203
|
+
relative10 = path.slice(root.length + 1);
|
|
15204
|
+
}
|
|
15205
|
+
return relative10;
|
|
15206
|
+
}
|
|
15207
|
+
function inListing(raw, listing, cwd, workspaceRoot) {
|
|
15208
|
+
const relative10 = relativeToRepository(raw, cwd);
|
|
15209
|
+
if (relative10 === null) return null;
|
|
15210
|
+
if (listing.has(relative10)) return relative10;
|
|
15211
|
+
if (workspaceRoot) {
|
|
15212
|
+
const root = slashes(workspaceRoot).replace(/\/+$/, "");
|
|
15213
|
+
const joined = `${root}/${relative10}`;
|
|
15214
|
+
if (listing.has(joined)) return joined;
|
|
15215
|
+
}
|
|
15216
|
+
return null;
|
|
15217
|
+
}
|
|
15218
|
+
function buildTestDiscovery(i2) {
|
|
15219
|
+
if (!i2.command || i2.command.trim().length === 0) return absent("no_command");
|
|
15220
|
+
const snapshot = i2.snapshot;
|
|
15221
|
+
if (!snapshot || !snapshot.results || !snapshot.discoveredFiles) return absent("no_report");
|
|
15222
|
+
if (snapshot.results.size === 0) return absent("no_tests");
|
|
15223
|
+
if (snapshot.unmappedEntries === void 0) return absent("no_report");
|
|
15224
|
+
const listing = new Set(i2.listing);
|
|
15225
|
+
const found = /* @__PURE__ */ new Set();
|
|
15226
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
15227
|
+
for (const raw of snapshot.discoveredFiles) {
|
|
15228
|
+
if (!looksLikeFilePath(slashes(raw).trim())) continue;
|
|
15229
|
+
const match = inListing(raw, listing, i2.cwd, i2.workspaceRoot);
|
|
15230
|
+
if (match) found.add(match);
|
|
15231
|
+
else dropped.add(withoutDotSlash(slashes(raw.trim())));
|
|
15232
|
+
}
|
|
15233
|
+
const unmapped = snapshot.unmappedEntries + dropped.size;
|
|
15234
|
+
const files = [...found].sort();
|
|
15235
|
+
return {
|
|
15236
|
+
value: { report: "PRESENT", discoveredTestFiles: files, unmappedEntries: unmapped },
|
|
15237
|
+
source: "live",
|
|
15238
|
+
reason: "ok",
|
|
15239
|
+
files: files.length,
|
|
15240
|
+
unmapped
|
|
15241
|
+
};
|
|
15242
|
+
}
|
|
15243
|
+
var DEFAULT_DISCOVERY_WAIT_MS = 9e4;
|
|
15244
|
+
var MAX_DISCOVERY_WAIT_MS = 36e5;
|
|
15245
|
+
function discoveryWaitMs(env2 = process.env) {
|
|
15246
|
+
const raw = env2.QUIKPILOT_DISCOVERY_WAIT_SECONDS?.trim();
|
|
15247
|
+
if (!raw || !/^\d+(\.\d+)?$/.test(raw)) return DEFAULT_DISCOVERY_WAIT_MS;
|
|
15248
|
+
return Math.min(MAX_DISCOVERY_WAIT_MS, Math.round(Number(raw) * 1e3));
|
|
15249
|
+
}
|
|
15250
|
+
var TIMEOUT_WARNING = "QuikPilot could not list the project's test files in time, so it skipped the early check of where tests are placed.";
|
|
15251
|
+
async function resolveTestDiscovery(i2) {
|
|
15252
|
+
const now = i2.now ?? Date.now;
|
|
15253
|
+
const started = now();
|
|
15254
|
+
const base = { command: i2.command, listing: i2.listing, workspaceRoot: i2.workspaceRoot, cwd: i2.cwd };
|
|
15255
|
+
const done = (result, warning) => {
|
|
15256
|
+
const waitedMs = now() - started;
|
|
15257
|
+
i2.log?.({ event: "test_discovery", source: result.source, reason: result.reason, files: result.files, unmapped: result.unmapped, waitedMs });
|
|
15258
|
+
return { result, waitedMs, ...warning ? { warning } : {} };
|
|
15259
|
+
};
|
|
15260
|
+
if (!i2.command || i2.command.trim().length === 0) return done(buildTestDiscovery({ ...base, snapshot: null }));
|
|
15261
|
+
let timer;
|
|
15262
|
+
const timeout = new Promise((resolve6) => {
|
|
15263
|
+
timer = setTimeout(() => resolve6("timeout"), i2.waitMs);
|
|
15264
|
+
});
|
|
15265
|
+
const settled = i2.baseline.then(
|
|
15266
|
+
(b) => b.snapshot,
|
|
15267
|
+
() => null
|
|
15268
|
+
);
|
|
15269
|
+
try {
|
|
15270
|
+
const first = await Promise.race([settled, timeout]);
|
|
15271
|
+
if (first === "timeout") return done(absent("timeout"), TIMEOUT_WARNING);
|
|
15272
|
+
return done(buildTestDiscovery({ ...base, snapshot: first }));
|
|
15273
|
+
} finally {
|
|
15274
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
15275
|
+
}
|
|
15276
|
+
}
|
|
15277
|
+
|
|
14940
15278
|
// src/targeting.ts
|
|
14941
|
-
var
|
|
15279
|
+
var import_node_path15 = require("node:path");
|
|
14942
15280
|
|
|
14943
15281
|
// src/targetingFindings.ts
|
|
14944
15282
|
var isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -15005,9 +15343,9 @@ function validateTarget(target, workspaceRoot, workspaceListing, deniedPaths) {
|
|
|
15005
15343
|
}
|
|
15006
15344
|
return;
|
|
15007
15345
|
}
|
|
15008
|
-
const root = (0,
|
|
15009
|
-
const rel = (0,
|
|
15010
|
-
if (rel.startsWith("..") || (0,
|
|
15346
|
+
const root = (0, import_node_path15.resolve)(workspaceRoot ?? ".");
|
|
15347
|
+
const rel = (0, import_node_path15.relative)(root, (0, import_node_path15.resolve)(target.path));
|
|
15348
|
+
if (rel.startsWith("..") || (0, import_node_path15.isAbsolute)(rel)) {
|
|
15011
15349
|
throw new Error(
|
|
15012
15350
|
`pilot.targeting named a NEW_FILE path that escapes the workspace root: ${target.path}`
|
|
15013
15351
|
);
|
|
@@ -15317,6 +15655,9 @@ async function exchangeForRunToken(tokenUrl, oidcToken) {
|
|
|
15317
15655
|
|
|
15318
15656
|
// src/run.ts
|
|
15319
15657
|
var JOB_RESERVE_MS = 7 * 6e4;
|
|
15658
|
+
var HUNK_CHECK_MAX_MS = 6 * 6e4;
|
|
15659
|
+
var HUNK_CHECK_MIN_BUDGET_MS = 3 * 6e4;
|
|
15660
|
+
var HUNK_CHECK_END_BEFORE_STOP_MS = 2 * 6e4;
|
|
15320
15661
|
async function run(env2) {
|
|
15321
15662
|
const runStartedAt = Date.now();
|
|
15322
15663
|
let hardFailure = false;
|
|
@@ -15339,14 +15680,42 @@ async function run(env2) {
|
|
|
15339
15680
|
let baselineFindings;
|
|
15340
15681
|
let vanishedTests;
|
|
15341
15682
|
let unsuppliedInputs;
|
|
15683
|
+
let changesNoTestDependsOn;
|
|
15342
15684
|
const contextLog = [];
|
|
15343
15685
|
const codegenOut = {};
|
|
15686
|
+
let pendingBaseline;
|
|
15687
|
+
const baselineSettled = async () => {
|
|
15688
|
+
try {
|
|
15689
|
+
await pendingBaseline;
|
|
15690
|
+
} catch {
|
|
15691
|
+
}
|
|
15692
|
+
};
|
|
15344
15693
|
try {
|
|
15345
15694
|
runToken = await exchangeForRunToken(env2.tokenUrl, await fetchGithubOidcToken());
|
|
15346
15695
|
packet = await fetchPacket(env2.packetUrl, runToken, env2.githubRunId);
|
|
15347
15696
|
checkoutTargetBranch(packet.targetBranch);
|
|
15348
15697
|
const workspaceListing = listWorkspaceFiles(packet.workspaceRoot);
|
|
15349
15698
|
const outOfScope = (packet.outOfScope ?? []).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
15699
|
+
runCommand(packet.commands.setup, "Setup");
|
|
15700
|
+
const baselineStartedAt = Date.now();
|
|
15701
|
+
const baselineRun = captureBaselineSnapshot(packet.commands.test).then((snapshot) => ({
|
|
15702
|
+
snapshot,
|
|
15703
|
+
durationMs: Date.now() - baselineStartedAt
|
|
15704
|
+
}));
|
|
15705
|
+
pendingBaseline = baselineRun;
|
|
15706
|
+
const discovery = await resolveTestDiscovery({
|
|
15707
|
+
command: packet.commands.test,
|
|
15708
|
+
baseline: baselineRun,
|
|
15709
|
+
listing: workspaceListing,
|
|
15710
|
+
workspaceRoot: packet.workspaceRoot,
|
|
15711
|
+
cwd: process.cwd(),
|
|
15712
|
+
waitMs: discoveryWaitMs(),
|
|
15713
|
+
log: (e) => console.log(JSON.stringify(e))
|
|
15714
|
+
});
|
|
15715
|
+
if (discovery.warning) {
|
|
15716
|
+
warnings.push(discovery.warning);
|
|
15717
|
+
console.warn(`QuikPilot targeting warning (not blocking): ${discovery.warning}`);
|
|
15718
|
+
}
|
|
15350
15719
|
const targeting = await runTargeting(
|
|
15351
15720
|
packet.gateway,
|
|
15352
15721
|
packet.design,
|
|
@@ -15354,7 +15723,7 @@ async function run(env2) {
|
|
|
15354
15723
|
workspaceListing,
|
|
15355
15724
|
packet.requiredTests,
|
|
15356
15725
|
packet.guardrails.deniedPaths,
|
|
15357
|
-
|
|
15726
|
+
discovery.result.value,
|
|
15358
15727
|
outOfScope,
|
|
15359
15728
|
...packet.findings ? [{ findings: packet.findings }] : []
|
|
15360
15729
|
);
|
|
@@ -15375,8 +15744,8 @@ async function run(env2) {
|
|
|
15375
15744
|
if (packet.issueKey !== null) {
|
|
15376
15745
|
throw new Error(`QuikPilot found no file to change for this request \u2014 ${targeting.reason?.trim() || "no reason was given."}`);
|
|
15377
15746
|
}
|
|
15747
|
+
await baselineSettled();
|
|
15378
15748
|
writePhase0Marker(env2.runId);
|
|
15379
|
-
runCommand(packet.commands.setup, "Setup");
|
|
15380
15749
|
runCommand(packet.commands.lint, "Lint");
|
|
15381
15750
|
runTestCommand(packet.commands.test);
|
|
15382
15751
|
} else {
|
|
@@ -15403,17 +15772,11 @@ async function run(env2) {
|
|
|
15403
15772
|
`QuikPilot's generated plan gives two files identical instructions \u2014 ${describeOverlapWarnings(blockingOverlaps).join("; ")}`
|
|
15404
15773
|
);
|
|
15405
15774
|
}
|
|
15406
|
-
runCommand(packet.commands.setup, "Setup");
|
|
15407
15775
|
const judgedByPool = buildJudgedByPool(
|
|
15408
15776
|
packet.requiredTests,
|
|
15409
15777
|
targeting.targets,
|
|
15410
15778
|
targeting.skippedCases ?? []
|
|
15411
15779
|
);
|
|
15412
|
-
const baselineStartedAt = Date.now();
|
|
15413
|
-
const baselineRun = captureBaselineSnapshot(packet.commands.test).then((snapshot) => ({
|
|
15414
|
-
snapshot,
|
|
15415
|
-
durationMs: Date.now() - baselineStartedAt
|
|
15416
|
-
}));
|
|
15417
15780
|
const codegenMode = resolveCodegenMode();
|
|
15418
15781
|
const stepParams = {
|
|
15419
15782
|
mode: codegenMode,
|
|
@@ -15446,6 +15809,7 @@ async function run(env2) {
|
|
|
15446
15809
|
baseline,
|
|
15447
15810
|
requiredAutomationIds: claimedAutomationIds(stepParams)
|
|
15448
15811
|
};
|
|
15812
|
+
const jobStopAtMs = runStartedAt + packet.guardrails.maxWallClockMinutes * 6e4 - JOB_RESERVE_MS;
|
|
15449
15813
|
const healCalls = [];
|
|
15450
15814
|
let healStop;
|
|
15451
15815
|
let fixed;
|
|
@@ -15456,7 +15820,7 @@ async function run(env2) {
|
|
|
15456
15820
|
mode: codegenMode,
|
|
15457
15821
|
setting: packet.guardrails.maxHealIterations,
|
|
15458
15822
|
now: Date.now,
|
|
15459
|
-
jobStopAtMs
|
|
15823
|
+
jobStopAtMs,
|
|
15460
15824
|
lastAttemptMs,
|
|
15461
15825
|
verify: (r, undoable) => verifyChange(verifyCtx, r, undoable),
|
|
15462
15826
|
heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs }) => {
|
|
@@ -15489,6 +15853,38 @@ async function run(env2) {
|
|
|
15489
15853
|
const suffix = healFailureSuffix(fixed.heal);
|
|
15490
15854
|
throw suffix ? new Error(`${final.error.message}${suffix}`) : final.error;
|
|
15491
15855
|
}
|
|
15856
|
+
if (codegenMode === "loop-tests" && process.env.QUIKPILOT_HUNK_CHECK?.trim().toLowerCase() !== "off") {
|
|
15857
|
+
const deadlineAtMs = Math.min(jobStopAtMs - HUNK_CHECK_END_BEFORE_STOP_MS, Date.now() + HUNK_CHECK_MAX_MS);
|
|
15858
|
+
if (deadlineAtMs - Date.now() >= HUNK_CHECK_MIN_BUDGET_MS) {
|
|
15859
|
+
try {
|
|
15860
|
+
const files = collectHunkCheckFiles(fixed.results, process.cwd());
|
|
15861
|
+
if (files.length > 0) {
|
|
15862
|
+
const checked = await runHunkCheck({
|
|
15863
|
+
root: process.cwd(),
|
|
15864
|
+
command: packet.commands.test,
|
|
15865
|
+
baseline,
|
|
15866
|
+
baselineMs: timedBaseline.durationMs,
|
|
15867
|
+
finalTestCount: final.outputs.testCount ?? 0,
|
|
15868
|
+
files,
|
|
15869
|
+
deadlineAtMs,
|
|
15870
|
+
log: (e) => console.log(JSON.stringify(e))
|
|
15871
|
+
});
|
|
15872
|
+
console.log(JSON.stringify({ event: "hunk_check", checked: checked.checked, total: checked.total, flagged: checked.unnecessary.length, skipped: checked.skipped, stopped: checked.stopped ?? null }));
|
|
15873
|
+
changesNoTestDependsOn = toFinding(checked);
|
|
15874
|
+
if (checked.unnecessary.length > 0) {
|
|
15875
|
+
const w = describeHunkCheck(checked);
|
|
15876
|
+
warnings.push(w);
|
|
15877
|
+
console.warn(`QuikPilot change warning (not blocking): ${w}`);
|
|
15878
|
+
}
|
|
15879
|
+
}
|
|
15880
|
+
} catch (err) {
|
|
15881
|
+
if (err instanceof TreeNotRestoredError) throw err;
|
|
15882
|
+
const message = `The check for changes no test depends on could not run: ${err instanceof Error ? err.message : String(err)}`;
|
|
15883
|
+
console.error(message);
|
|
15884
|
+
warnings.push(message);
|
|
15885
|
+
}
|
|
15886
|
+
}
|
|
15887
|
+
}
|
|
15492
15888
|
}
|
|
15493
15889
|
} catch (err) {
|
|
15494
15890
|
hardFailure = true;
|
|
@@ -15498,6 +15894,7 @@ async function run(env2) {
|
|
|
15498
15894
|
console.error("No run token \u2014 the OIDC exchange failed before QuikTrack could be reached.");
|
|
15499
15895
|
return { hardFailure: true };
|
|
15500
15896
|
}
|
|
15897
|
+
await baselineSettled();
|
|
15501
15898
|
const quikTestReport = await reportToQuikTest({
|
|
15502
15899
|
resultsUrl: packet?.quikTest?.resultsUrl,
|
|
15503
15900
|
runToken,
|
|
@@ -15559,6 +15956,7 @@ async function run(env2) {
|
|
|
15559
15956
|
baselineFindings,
|
|
15560
15957
|
vanishedTests,
|
|
15561
15958
|
unsuppliedInputs,
|
|
15959
|
+
changesNoTestDependsOn,
|
|
15562
15960
|
codegenLoop: codegenOut.loop,
|
|
15563
15961
|
unresolved: failureReasons.length > 0 ? failureReasons : void 0
|
|
15564
15962
|
});
|