@quikit/quikpilot-runner 9.3.0-rc.89 → 9.3.0-rc.90

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/dist/index.js CHANGED
@@ -144,13 +144,13 @@ var require_web_tree_sitter2 = __commonJS2({
144
144
  }
145
145
  readAsync = /* @__PURE__ */ __name(async (url) => {
146
146
  if (isFileURI(url)) {
147
- return new Promise((resolve6, reject) => {
147
+ return new Promise((resolve7, reject) => {
148
148
  var xhr = new XMLHttpRequest();
149
149
  xhr.open("GET", url, true);
150
150
  xhr.responseType = "arraybuffer";
151
151
  xhr.onload = () => {
152
152
  if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
153
- resolve6(xhr.response);
153
+ resolve7(xhr.response);
154
154
  return;
155
155
  }
156
156
  reject(xhr.status);
@@ -343,9 +343,9 @@ var require_web_tree_sitter2 = __commonJS2({
343
343
  __name(receiveInstantiationResult, "receiveInstantiationResult");
344
344
  var info2 = getWasmImports();
345
345
  if (Module["instantiateWasm"]) {
346
- return new Promise((resolve6, reject) => {
346
+ return new Promise((resolve7, reject) => {
347
347
  Module["instantiateWasm"](info2, (mod, inst) => {
348
- resolve6(receiveInstance(mod, inst));
348
+ resolve7(receiveInstance(mod, inst));
349
349
  });
350
350
  });
351
351
  }
@@ -1678,8 +1678,8 @@ var require_web_tree_sitter2 = __commonJS2({
1678
1678
  if (runtimeInitialized) {
1679
1679
  moduleRtn = Module;
1680
1680
  } else {
1681
- moduleRtn = new Promise((resolve6, reject) => {
1682
- readyPromiseResolve = resolve6;
1681
+ moduleRtn = new Promise((resolve7, reject) => {
1682
+ readyPromiseResolve = resolve7;
1683
1683
  readyPromiseReject = reject;
1684
1684
  });
1685
1685
  }
@@ -16872,7 +16872,7 @@ var require_sourcemap_codec_umd = __commonJS2({
16872
16872
  intToChar[i3] = c;
16873
16873
  charToInt[c] = i3;
16874
16874
  }
16875
- function decodeInteger(reader, relative12) {
16875
+ function decodeInteger(reader, relative14) {
16876
16876
  let value = 0;
16877
16877
  let shift = 0;
16878
16878
  let integer = 0;
@@ -16887,10 +16887,10 @@ var require_sourcemap_codec_umd = __commonJS2({
16887
16887
  if (shouldNegate) {
16888
16888
  value = -2147483648 | -value;
16889
16889
  }
16890
- return relative12 + value;
16890
+ return relative14 + value;
16891
16891
  }
16892
- function encodeInteger(builder, num2, relative12) {
16893
- let delta = num2 - relative12;
16892
+ function encodeInteger(builder, num2, relative14) {
16893
+ let delta = num2 - relative14;
16894
16894
  delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
16895
16895
  do {
16896
16896
  let clamped = delta & 31;
@@ -17394,7 +17394,7 @@ var require_resolve_uri_umd = __commonJS2({
17394
17394
  }
17395
17395
  url.path = path;
17396
17396
  }
17397
- function resolve6(input, base) {
17397
+ function resolve7(input, base) {
17398
17398
  if (!input && !base)
17399
17399
  return "";
17400
17400
  const url = parseUrl(input);
@@ -17447,7 +17447,7 @@ var require_resolve_uri_umd = __commonJS2({
17447
17447
  return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
17448
17448
  }
17449
17449
  }
17450
- return resolve6;
17450
+ return resolve7;
17451
17451
  }));
17452
17452
  }
17453
17453
  });
@@ -17792,8 +17792,8 @@ var require_trace_mapping_umd = __commonJS2({
17792
17792
  this.sources = sources;
17793
17793
  this.sourcesContent = sourcesContent;
17794
17794
  this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
17795
- const resolve6 = resolver(mapUrl, sourceRoot);
17796
- this.resolvedSources = sources.map(resolve6);
17795
+ const resolve7 = resolver(mapUrl, sourceRoot);
17796
+ this.resolvedSources = sources.map(resolve7);
17797
17797
  const { mappings } = parsed;
17798
17798
  if (typeof mappings === "string") {
17799
17799
  this._encoded = mappings;
@@ -29145,17 +29145,25 @@ var PUSH_RETRY_DELAYS_MS = [3e3, 6e3, 12e3];
29145
29145
  var REPOSITORY_NOT_FOUND_RE = /Repository not found/i;
29146
29146
  var SERVER_ERROR_DELAYS_MS = [5e3, 15e3, 3e4, 6e4];
29147
29147
  var SERVER_ERROR_RE = /Internal Server Error|Bad Gateway|Service Unavailable|Gateway Timeout|returned error: 5\d\d/i;
29148
- function sleepSync(ms) {
29149
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
29148
+ var PUSH_TRY_TIMEOUT_MS = 3 * 6e4;
29149
+ var sleepAsync = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
29150
+ function gitPushTry(args2, extraEnv) {
29151
+ return new Promise((resolve7, reject) => {
29152
+ (0, import_node_child_process.execFile)("git", [...NO_HOOKS_ARGS, ...args2], { encoding: "utf8", env: gitEnv(extraEnv), timeout: PUSH_TRY_TIMEOUT_MS }, (err2, _stdout, stderr) => {
29153
+ if (!err2) return resolve7();
29154
+ if (err2.killed) return reject(new Error(`git push did not finish within ${PUSH_TRY_TIMEOUT_MS / 6e4} minutes and was stopped`));
29155
+ reject(Object.assign(err2, { stderr }));
29156
+ });
29157
+ });
29150
29158
  }
29151
- function push(branch, installationToken, sleep = sleepSync) {
29159
+ async function push(branch, installationToken, sleep = sleepAsync) {
29152
29160
  clearCheckoutExtraHeader();
29153
29161
  const basicAuth = Buffer.from(`x-access-token:${installationToken}`).toString("base64");
29154
29162
  let notFoundRetries = 0;
29155
29163
  let serverRetries = 0;
29156
29164
  for (let attempt2 = 0; ; attempt2 += 1) {
29157
29165
  try {
29158
- git(["push", "--set-upstream", "origin", branch], {
29166
+ await gitPushTry(["push", "--set-upstream", "origin", branch], {
29159
29167
  GIT_CONFIG_COUNT: "1",
29160
29168
  GIT_CONFIG_KEY_0: "http.https://github.com/.extraheader",
29161
29169
  GIT_CONFIG_VALUE_0: `AUTHORIZATION: basic ${basicAuth}`
@@ -29179,7 +29187,7 @@ function push(branch, installationToken, sleep = sleepSync) {
29179
29187
  }
29180
29188
  if (delay === void 0) throw err2;
29181
29189
  console.log(JSON.stringify({ event: "git.push_retry", attempt: attempt2 + 1, waitMs: delay, cause }));
29182
- sleep(delay);
29190
+ await sleep(delay);
29183
29191
  }
29184
29192
  }
29185
29193
  }
@@ -37540,8 +37548,8 @@ function resolveImport(fromPath, specifier, listing, mapSpecifier) {
37540
37548
  }
37541
37549
  if (/^(?:@\/|~\/|#|\$|\/)/.test(specifier)) return { kind: "unresolved", reason: "alias" };
37542
37550
  const clean = specifier.replace(/[?#].*$/, "");
37543
- const relative12 = clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
37544
- if (!relative12) return { kind: "external" };
37551
+ const relative14 = clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
37552
+ if (!relative14) return { kind: "external" };
37545
37553
  const base = import_node_path4.posix.normalize(import_node_path4.posix.join(import_node_path4.posix.dirname(fromPath), clean));
37546
37554
  if (base === ".." || base.startsWith("../") || import_node_path4.posix.isAbsolute(base)) return { kind: "unresolved", reason: "not found" };
37547
37555
  return probeBase(base, listing);
@@ -39743,8 +39751,8 @@ function createProposalCommit(input) {
39743
39751
  (0, import_node_fs4.rmSync)(dir, { recursive: true, force: true });
39744
39752
  }
39745
39753
  }
39746
- function pushProposal(branch, installationToken, push2 = push) {
39747
- push2(branch, installationToken);
39754
+ async function pushProposal(branch, installationToken, push2 = push) {
39755
+ await push2(branch, installationToken);
39748
39756
  }
39749
39757
  function conflictsReport(p) {
39750
39758
  return {
@@ -40013,7 +40021,7 @@ async function requestWithoutHeadersLimit(url, init2, signal) {
40013
40021
  const target = new URL(url);
40014
40022
  const client = target.protocol === "http:" ? import_node_http.default : import_node_https.default;
40015
40023
  const headers = Object.fromEntries(new Headers(init2.headers).entries());
40016
- return new Promise((resolve6, reject) => {
40024
+ return new Promise((resolve7, reject) => {
40017
40025
  const fail = (err2) => reject(signal.aborted ? signal.reason : err2);
40018
40026
  const req = client.request(target, { method: init2.method ?? "GET", headers, signal }, (res) => {
40019
40027
  const chunks = [];
@@ -40026,7 +40034,7 @@ async function requestWithoutHeadersLimit(url, init2, signal) {
40026
40034
  for (const one of Array.isArray(value) ? value : value === void 0 ? [] : [value]) responseHeaders.append(name2, one);
40027
40035
  }
40028
40036
  try {
40029
- resolve6(new Response(NULL_BODY_STATUSES.has(status) ? null : Buffer.concat(chunks), { status, statusText: res.statusMessage ?? "", headers: responseHeaders }));
40037
+ resolve7(new Response(NULL_BODY_STATUSES.has(status) ? null : Buffer.concat(chunks), { status, statusText: res.statusMessage ?? "", headers: responseHeaders }));
40030
40038
  } catch (err2) {
40031
40039
  reject(err2);
40032
40040
  }
@@ -40074,7 +40082,7 @@ var REPORT_RETRY_WAITS_MS = [2e3, 5e3, 1e4];
40074
40082
  var URGENT_REPORT_TIMEOUT_MS = 6e3;
40075
40083
  async function reportBack(params) {
40076
40084
  const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, changesNoTestDependsOn, testsCorrected, codegenLoop, unresolved, aiCostUsd, testConflicts, approvedTestsApplied, databaseChange } = params;
40077
- const sleep = params.sleep ?? ((ms) => new Promise((resolve6) => setTimeout(resolve6, ms)));
40085
+ const sleep = params.sleep ?? ((ms) => new Promise((resolve7) => setTimeout(resolve7, ms)));
40078
40086
  const body2 = { status };
40079
40087
  if (branch) body2.branch = branch;
40080
40088
  if (warnings && warnings.length > 0) body2.warnings = warnings;
@@ -40090,7 +40098,8 @@ async function reportBack(params) {
40090
40098
  if (testConflicts) body2.testConflicts = testConflicts;
40091
40099
  if (approvedTestsApplied && approvedTestsApplied.length > 0) body2.approvedTestsApplied = approvedTestsApplied;
40092
40100
  if (databaseChange && status === "completed") body2.databaseChange = databaseChange;
40093
- const payload = JSON.stringify(body2);
40101
+ const secrets = [runToken, ...params.secrets ?? []];
40102
+ const payload = JSON.stringify(body2, (_key, value) => typeof value === "string" ? scrubSecrets(value, secrets) : value);
40094
40103
  const tries = params.urgent ? 1 : REPORT_RETRY_WAITS_MS.length + 1;
40095
40104
  for (let attempt2 = 1; ; attempt2++) {
40096
40105
  let failure;
@@ -40233,22 +40242,30 @@ function runTestCommand(command) {
40233
40242
  return "failure";
40234
40243
  }
40235
40244
  }
40236
- function runTestCommandAsync(command) {
40245
+ function runTestCommandAsync(command, signal) {
40237
40246
  if (!command) return Promise.resolve("success");
40238
- return new Promise((resolve6) => {
40239
- const child = (0, import_node_child_process5.spawn)(command, { shell: "/bin/bash", stdio: "inherit", env: repositoryCommandEnv() });
40240
- child.on("exit", (code) => resolve6(code === 0 ? "success" : "failure"));
40241
- child.on("error", () => resolve6("failure"));
40247
+ return new Promise((resolve7) => {
40248
+ const child = (0, import_node_child_process5.spawn)(command, { shell: "/bin/bash", stdio: "inherit", detached: true, env: repositoryCommandEnv() });
40249
+ track(child);
40250
+ const onAbort = () => killProcessGroup(child);
40251
+ if (signal?.aborted) onAbort();
40252
+ else signal?.addEventListener("abort", onAbort, { once: true });
40253
+ const done = (outcome) => {
40254
+ signal?.removeEventListener("abort", onAbort);
40255
+ resolve7(signal?.aborted ? "failure" : outcome);
40256
+ };
40257
+ child.on("exit", (code) => done(code === 0 ? "success" : "failure"));
40258
+ child.on("error", () => done("failure"));
40242
40259
  });
40243
40260
  }
40244
40261
  function runCommandWithTimeout(command, timeoutMs) {
40245
- return new Promise((resolve6) => {
40262
+ return new Promise((resolve7) => {
40246
40263
  let settled = false;
40247
40264
  const finish = (outcome) => {
40248
40265
  if (settled) return;
40249
40266
  settled = true;
40250
40267
  clearTimeout(timer);
40251
- resolve6(outcome);
40268
+ resolve7(outcome);
40252
40269
  };
40253
40270
  const child = (0, import_node_child_process5.spawn)(command, {
40254
40271
  shell: "/bin/bash",
@@ -40301,7 +40318,7 @@ function killProcessGroup(child) {
40301
40318
  }
40302
40319
  }
40303
40320
  function runCapturedCommand(argv, opts) {
40304
- return new Promise((resolve6) => {
40321
+ return new Promise((resolve7) => {
40305
40322
  let settled = false;
40306
40323
  let timedOut = false;
40307
40324
  let graceTimer;
@@ -40312,7 +40329,7 @@ function runCapturedCommand(argv, opts) {
40312
40329
  settled = true;
40313
40330
  clearTimeout(timer);
40314
40331
  if (graceTimer) clearTimeout(graceTimer);
40315
- resolve6({ stdout: Buffer.concat(chunks).toString("utf8"), timedOut, started });
40332
+ resolve7({ stdout: Buffer.concat(chunks).toString("utf8"), timedOut, started });
40316
40333
  };
40317
40334
  const child = (0, import_node_child_process5.spawn)(argv[0], argv.slice(1), {
40318
40335
  cwd: opts.cwd,
@@ -40339,7 +40356,7 @@ function runCapturedCommand(argv, opts) {
40339
40356
  });
40340
40357
  }
40341
40358
  function runShellCaptured(command, opts) {
40342
- return new Promise((resolve6) => {
40359
+ return new Promise((resolve7) => {
40343
40360
  let settled = false;
40344
40361
  let timedOut = false;
40345
40362
  let graceTimer;
@@ -40354,7 +40371,7 @@ function runShellCaptured(command, opts) {
40354
40371
  clearTimeout(timer);
40355
40372
  if (graceTimer) clearTimeout(graceTimer);
40356
40373
  const kept = tail2.length > opts.maxTailBytes ? tail2.subarray(tail2.length - opts.maxTailBytes) : tail2;
40357
- resolve6({ output: kept.toString("utf8"), exitCode, timedOut, started });
40374
+ resolve7({ output: kept.toString("utf8"), exitCode, timedOut, started });
40358
40375
  };
40359
40376
  const child = (0, import_node_child_process5.spawn)(command, {
40360
40377
  shell: "/bin/bash",
@@ -40376,17 +40393,25 @@ function runShellCaptured(command, opts) {
40376
40393
  });
40377
40394
  }
40378
40395
  var KILL_GRACE_MS = 2e3;
40379
- function runTestCommandWithLimit(command, timeoutMs, cwd) {
40380
- return new Promise((resolve6) => {
40396
+ function runTestCommandWithLimit(command, timeoutMs, cwd, signal) {
40397
+ return new Promise((resolve7) => {
40381
40398
  let settled = false;
40382
40399
  let timedOut = false;
40400
+ let stopped = false;
40383
40401
  let graceTimer;
40384
40402
  const finish = (run3) => {
40385
40403
  if (settled) return;
40386
40404
  settled = true;
40387
40405
  clearTimeout(timer);
40388
40406
  if (graceTimer) clearTimeout(graceTimer);
40389
- resolve6(run3);
40407
+ signal?.removeEventListener("abort", onAbort);
40408
+ resolve7(stopped ? { ...run3, outcome: "failure", stopped: true } : run3);
40409
+ };
40410
+ const onAbort = () => {
40411
+ if (settled || timedOut || stopped) return;
40412
+ stopped = true;
40413
+ killProcessGroup(child);
40414
+ graceTimer = setTimeout(() => finish({ outcome: "failure", timedOut: false, started: true }), KILL_GRACE_MS);
40390
40415
  };
40391
40416
  const child = (0, import_node_child_process5.spawn)(command, {
40392
40417
  shell: "/bin/bash",
@@ -40403,6 +40428,8 @@ function runTestCommandWithLimit(command, timeoutMs, cwd) {
40403
40428
  }, timeoutMs);
40404
40429
  child.on("exit", (code) => finish({ outcome: timedOut || code !== 0 ? "failure" : "success", timedOut, started: true }));
40405
40430
  child.on("error", () => finish({ outcome: "failure", timedOut, started: false }));
40431
+ if (signal?.aborted) onAbort();
40432
+ else signal?.addEventListener("abort", onAbort, { once: true });
40406
40433
  });
40407
40434
  }
40408
40435
 
@@ -40715,10 +40742,10 @@ function previousAttemptFrom(failure, attempt2) {
40715
40742
  }
40716
40743
 
40717
40744
  // src/testPlan.ts
40718
- var import_node_crypto = require("node:crypto");
40719
- var import_node_fs10 = require("node:fs");
40745
+ var import_node_crypto2 = require("node:crypto");
40746
+ var import_node_fs13 = require("node:fs");
40720
40747
  var import_node_os4 = require("node:os");
40721
- var import_node_path14 = require("node:path");
40748
+ var import_node_path17 = require("node:path");
40722
40749
 
40723
40750
  // src/pairedTests.ts
40724
40751
  var import_node_path9 = require("node:path");
@@ -40858,14 +40885,14 @@ function testsThroughOneFile(p) {
40858
40885
  }
40859
40886
 
40860
40887
  // src/testAdapters.ts
40861
- var import_node_fs9 = require("node:fs");
40888
+ var import_node_fs12 = require("node:fs");
40862
40889
  var import_node_module = require("node:module");
40863
- var import_node_path12 = require("node:path");
40890
+ var import_node_path15 = require("node:path");
40864
40891
 
40865
40892
  // src/baselineCheck.ts
40866
- var import_node_child_process7 = require("node:child_process");
40867
- var import_node_fs8 = require("node:fs");
40868
- var import_node_path11 = require("node:path");
40893
+ var import_node_child_process9 = require("node:child_process");
40894
+ var import_node_fs11 = require("node:fs");
40895
+ var import_node_path14 = require("node:path");
40869
40896
 
40870
40897
  // src/quiktest.ts
40871
40898
  var import_node_child_process6 = require("node:child_process");
@@ -41354,10 +41381,11 @@ function snapshotOf(outcome, parsed) {
41354
41381
  unmappedCases: parsed?.unmappedCases
41355
41382
  };
41356
41383
  }
41357
- async function captureLimited(command, cwd, limitMs) {
41384
+ async function captureLimited(command, cwd, limitMs, signal) {
41358
41385
  if (!command) return snapshotOf("success", readJUnitOutcomes(cwd));
41359
41386
  const startedAt = Date.now();
41360
- const run3 = await runTestCommandWithLimit(command, limitMs, cwd);
41387
+ const run3 = await runTestCommandWithLimit(command, limitMs, cwd, signal);
41388
+ if (run3.stopped) return { ...snapshotOf("failure", null), stopped: true };
41361
41389
  if (run3.timedOut) return { ...snapshotOf("failure", null), timedOut: true };
41362
41390
  return snapshotOf(run3.outcome, readJUnitOutcomes(cwd, startedAt - FRESH_SLACK_MS));
41363
41391
  }
@@ -41403,9 +41431,10 @@ function readTestSnapshotAt(outcome, reportPath) {
41403
41431
  return snapshotOf(outcome, parsed);
41404
41432
  }
41405
41433
  async function captureBaselineSnapshot(command, cwd = process.cwd(), opts) {
41406
- if (opts) return captureLimited(command, cwd, opts.limitMs);
41434
+ if (opts?.limitMs !== void 0) return captureLimited(command, cwd, opts.limitMs, opts.signal);
41407
41435
  const startedAt = Date.now();
41408
- const outcome = await runTestCommandAsync(command);
41436
+ const outcome = await runTestCommandAsync(command, opts?.signal);
41437
+ if (opts?.signal?.aborted) return { ...snapshotOf("failure", null), stopped: true };
41409
41438
  const parsed = readJUnitOutcomes(cwd, startedAt - FRESH_SLACK_MS);
41410
41439
  return {
41411
41440
  outcome,
@@ -41478,6 +41507,466 @@ function describeRegressions(check, options = {}) {
41478
41507
  return parts2.join("; ");
41479
41508
  }
41480
41509
 
41510
+ // src/repoPath.ts
41511
+ var import_node_fs10 = require("node:fs");
41512
+ var import_node_path13 = require("node:path");
41513
+
41514
+ // src/overlayOnDisk.ts
41515
+ var import_node_child_process8 = require("node:child_process");
41516
+ var import_node_fs9 = require("node:fs");
41517
+ var import_node_path12 = require("node:path");
41518
+
41519
+ // src/treeFingerprint.ts
41520
+ var import_node_crypto = require("node:crypto");
41521
+ var import_node_child_process7 = require("node:child_process");
41522
+ var import_node_fs8 = require("node:fs");
41523
+ var import_node_path11 = require("node:path");
41524
+ var MAX_HASHED_BYTES = 8 * 1024 * 1024;
41525
+ function defaultGitStatus(root) {
41526
+ try {
41527
+ return (0, import_node_child_process7.execFileSync)("git", [...NO_HOOKS_ARGS, "status", "--porcelain=v1", "-z", "--untracked-files=all"], {
41528
+ env: gitEnv(),
41529
+ cwd: root,
41530
+ encoding: "utf8",
41531
+ stdio: ["ignore", "pipe", "ignore"],
41532
+ maxBuffer: 64 * 1024 * 1024
41533
+ });
41534
+ } catch {
41535
+ return null;
41536
+ }
41537
+ }
41538
+ var STATUS_ENTRY = /^[ MADRCUT?!]{2} /;
41539
+ function isStatusEntry(token) {
41540
+ return STATUS_ENTRY.test(token);
41541
+ }
41542
+ function entryPath(token) {
41543
+ return token.slice(3);
41544
+ }
41545
+ function entryCode(token) {
41546
+ return token.slice(0, 2);
41547
+ }
41548
+ function parseStatus(raw) {
41549
+ return raw.split("\0").filter((t) => t.length > 0).sort();
41550
+ }
41551
+ function hashOf(root, rel) {
41552
+ const abs = (0, import_node_path11.join)(root, rel);
41553
+ let st;
41554
+ try {
41555
+ st = (0, import_node_fs8.lstatSync)(abs);
41556
+ } catch {
41557
+ return null;
41558
+ }
41559
+ try {
41560
+ if (st.isSymbolicLink()) return `link:${(0, import_node_fs8.readlinkSync)(abs)}`;
41561
+ if (st.isDirectory()) return "dir";
41562
+ if (st.size > MAX_HASHED_BYTES) return `big:${st.size}:${Math.trunc(st.mtimeMs)}`;
41563
+ return (0, import_node_crypto.createHash)("sha256").update((0, import_node_fs8.readFileSync)(abs)).digest("hex");
41564
+ } catch {
41565
+ return `unreadable`;
41566
+ }
41567
+ }
41568
+ function captureTree(root, watch, deps = {}) {
41569
+ const raw = (deps.gitStatus ?? defaultGitStatus)(root);
41570
+ if (raw === null) return null;
41571
+ const status = parseStatus(raw);
41572
+ const paths = new Set(watch);
41573
+ for (const token of status) if (isStatusEntry(token)) paths.add(entryPath(token));
41574
+ const hashes = {};
41575
+ for (const p of [...paths].sort()) hashes[p] = hashOf(root, p);
41576
+ const digest = (0, import_node_crypto.createHash)("sha256").update(JSON.stringify([status, hashes])).digest("hex");
41577
+ return { status, hashes, digest };
41578
+ }
41579
+ function treeDifferences(before, after) {
41580
+ const out2 = /* @__PURE__ */ new Set();
41581
+ for (const p of /* @__PURE__ */ new Set([...Object.keys(before.hashes), ...Object.keys(after.hashes)])) {
41582
+ if ((before.hashes[p] ?? null) !== (after.hashes[p] ?? null)) out2.add(p);
41583
+ }
41584
+ const codes = (s) => new Map(s.status.filter(isStatusEntry).map((t) => [entryPath(t), entryCode(t)]));
41585
+ const b = codes(before);
41586
+ const a = codes(after);
41587
+ for (const p of /* @__PURE__ */ new Set([...b.keys(), ...a.keys()])) if (b.get(p) !== a.get(p)) out2.add(p);
41588
+ return [...out2].sort();
41589
+ }
41590
+
41591
+ // src/overlayOnDisk.ts
41592
+ var TreeNotRestoredError = class extends Error {
41593
+ paths;
41594
+ constructor(paths, cause) {
41595
+ super("The checkout could not be restored after a test run.");
41596
+ this.name = "TreeNotRestoredError";
41597
+ this.paths = paths;
41598
+ if (cause !== void 0) this.cause = cause;
41599
+ }
41600
+ };
41601
+ var TreeUnverifiableError = class extends Error {
41602
+ constructor() {
41603
+ super("The checkout could not be verified, so no test run was started.");
41604
+ this.name = "TreeUnverifiableError";
41605
+ }
41606
+ };
41607
+ var DiskWriteRefused = class extends Error {
41608
+ reason;
41609
+ constructor(reason) {
41610
+ super(`A change could not be put on disk (${reason}).`);
41611
+ this.name = "DiskWriteRefused";
41612
+ this.reason = reason;
41613
+ }
41614
+ };
41615
+ function safeRelativePath(rel) {
41616
+ if (typeof rel !== "string" || rel.length === 0 || rel.length > 400 || rel.includes("\0") || rel.includes("\\")) return null;
41617
+ if ((0, import_node_path12.isAbsolute)(rel) || /^[A-Za-z]:/.test(rel)) return null;
41618
+ const parts2 = rel.split("/");
41619
+ if (parts2.some((p) => p === "" || p === "." || p === "..")) return null;
41620
+ return rel;
41621
+ }
41622
+ function isInside(root, abs) {
41623
+ const r = (0, import_node_path12.relative)(root, abs);
41624
+ return r !== "" && !r.startsWith("..") && !(0, import_node_path12.isAbsolute)(r);
41625
+ }
41626
+ function ancestorInside(realRoot, abs) {
41627
+ let dir = (0, import_node_path12.dirname)(abs);
41628
+ for (; ; ) {
41629
+ try {
41630
+ const real = (0, import_node_fs9.realpathSync)(dir);
41631
+ const r = (0, import_node_path12.relative)(realRoot, real);
41632
+ return r === "" || !r.startsWith("..") && !(0, import_node_path12.isAbsolute)(r);
41633
+ } catch {
41634
+ const up = (0, import_node_path12.dirname)(dir);
41635
+ if (up === dir) return false;
41636
+ dir = up;
41637
+ }
41638
+ }
41639
+ }
41640
+ function applyOverlay(root, files) {
41641
+ const realRoot = (0, import_node_fs9.realpathSync)(root);
41642
+ const written = [];
41643
+ const seen = /* @__PURE__ */ new Set();
41644
+ const restore2 = () => {
41645
+ const failed = [];
41646
+ for (const w of [...written].reverse()) {
41647
+ const rel = (0, import_node_path12.relative)(root, w.abs).split("\\").join("/");
41648
+ try {
41649
+ if (w.original !== null) (0, import_node_fs9.writeFileSync)(w.abs, w.original);
41650
+ else (0, import_node_fs9.rmSync)(w.abs, { force: true });
41651
+ for (const d of [...w.createdDirs].reverse()) {
41652
+ try {
41653
+ (0, import_node_fs9.rmdirSync)(d);
41654
+ } catch {
41655
+ }
41656
+ }
41657
+ } catch {
41658
+ failed.push(rel);
41659
+ }
41660
+ }
41661
+ written.length = 0;
41662
+ return { failed: failed.sort() };
41663
+ };
41664
+ try {
41665
+ for (const f of files) {
41666
+ const rel = safeRelativePath(f.path);
41667
+ if (rel === null) throw new DiskWriteRefused("bad_path");
41668
+ if (seen.has(rel)) throw new DiskWriteRefused("duplicate");
41669
+ seen.add(rel);
41670
+ const abs = (0, import_node_path12.resolve)(root, rel);
41671
+ if (!isInside(root, abs) || !ancestorInside(realRoot, abs)) throw new DiskWriteRefused("outside_checkout");
41672
+ let original = null;
41673
+ try {
41674
+ const st = (0, import_node_fs9.lstatSync)(abs);
41675
+ if (st.isSymbolicLink() || !st.isFile()) throw new DiskWriteRefused("not_a_file");
41676
+ original = (0, import_node_fs9.readFileSync)(abs);
41677
+ } catch (err2) {
41678
+ if (err2 instanceof DiskWriteRefused) throw err2;
41679
+ original = null;
41680
+ }
41681
+ const createdDirs = [];
41682
+ if (original === null) {
41683
+ const missing = [];
41684
+ for (let d = (0, import_node_path12.dirname)(abs); !(0, import_node_fs9.existsSync)(d); d = (0, import_node_path12.dirname)(d)) missing.push(d);
41685
+ for (const d of missing.reverse()) {
41686
+ (0, import_node_fs9.mkdirSync)(d);
41687
+ createdDirs.push(d);
41688
+ }
41689
+ }
41690
+ const w = { abs, original, createdDirs };
41691
+ written.push(w);
41692
+ (0, import_node_fs9.writeFileSync)(abs, f.content);
41693
+ }
41694
+ } catch (err2) {
41695
+ restore2();
41696
+ throw err2;
41697
+ }
41698
+ return { restore: restore2 };
41699
+ }
41700
+ function git2(root, args2) {
41701
+ (0, import_node_child_process8.execFileSync)("git", [...NO_HOOKS_ARGS, ...args2], { env: gitEnv(), cwd: root, stdio: ["ignore", "ignore", "ignore"] });
41702
+ }
41703
+ function cleanUpAfterRun(root, beforePaths, afterStatus) {
41704
+ for (const token of afterStatus) {
41705
+ if (!isStatusEntry(token)) continue;
41706
+ const p = entryPath(token);
41707
+ if (beforePaths.has(p) || safeRelativePath(p) === null) continue;
41708
+ const code = entryCode(token);
41709
+ try {
41710
+ if (code === "??") {
41711
+ (0, import_node_fs9.rmSync)((0, import_node_path12.join)(root, p), { recursive: true, force: true });
41712
+ for (let d = (0, import_node_path12.dirname)((0, import_node_path12.join)(root, p)); d !== root && isInside(root, d); d = (0, import_node_path12.dirname)(d)) {
41713
+ try {
41714
+ (0, import_node_fs9.rmdirSync)(d);
41715
+ } catch {
41716
+ break;
41717
+ }
41718
+ }
41719
+ } else if (code[0] === "A") {
41720
+ git2(root, ["rm", "-f", "--", p]);
41721
+ } else {
41722
+ git2(root, ["checkout", "HEAD", "--", p]);
41723
+ }
41724
+ } catch {
41725
+ }
41726
+ }
41727
+ }
41728
+ function snapshotPreserved(root, paths) {
41729
+ const out2 = [];
41730
+ for (const rel of paths ?? []) {
41731
+ if (safeRelativePath(rel) === null) continue;
41732
+ const abs = (0, import_node_path12.resolve)(root, rel);
41733
+ try {
41734
+ const st = (0, import_node_fs9.lstatSync)(abs);
41735
+ if (st.isSymbolicLink() || !st.isFile()) continue;
41736
+ out2.push({ rel, abs, bytes: (0, import_node_fs9.readFileSync)(abs) });
41737
+ } catch {
41738
+ }
41739
+ }
41740
+ return out2;
41741
+ }
41742
+ function restorePreserved(kept) {
41743
+ for (const k of kept) {
41744
+ try {
41745
+ (0, import_node_fs9.writeFileSync)(k.abs, k.bytes);
41746
+ } catch {
41747
+ }
41748
+ }
41749
+ }
41750
+ async function withOverlayOnDisk(root, files, run3, options = {}) {
41751
+ const kept = snapshotPreserved(root, options.preserve);
41752
+ const watch = [...files.map((f) => f.path), ...kept.map((k) => k.rel)];
41753
+ const before = captureTree(root, watch, options);
41754
+ if (before === null) throw new TreeUnverifiableError();
41755
+ const beforePaths = new Set(before.status.filter(isStatusEntry).map(entryPath));
41756
+ const session = applyOverlay(root, files);
41757
+ let value;
41758
+ let runError;
41759
+ let failedRun = false;
41760
+ try {
41761
+ value = await run3();
41762
+ } catch (err2) {
41763
+ failedRun = true;
41764
+ runError = err2;
41765
+ }
41766
+ const { failed } = session.restore();
41767
+ restorePreserved(kept);
41768
+ let remaining = [];
41769
+ const after = captureTree(root, watch, options);
41770
+ if (after === null) {
41771
+ remaining = ["(git could not report the checkout)"];
41772
+ } else {
41773
+ remaining = treeDifferences(before, after);
41774
+ if (remaining.length > 0) {
41775
+ cleanUpAfterRun(root, beforePaths, after.status);
41776
+ const again = captureTree(root, watch, options);
41777
+ remaining = again === null ? ["(git could not report the checkout)"] : treeDifferences(before, again);
41778
+ }
41779
+ }
41780
+ const bad3 = [.../* @__PURE__ */ new Set([...failed, ...remaining])].sort();
41781
+ if (bad3.length > 0) throw new TreeNotRestoredError(bad3, failedRun ? runError : void 0);
41782
+ if (failedRun) throw runError;
41783
+ return value;
41784
+ }
41785
+ function assertTreeUnchanged(root, before, watch, options = {}) {
41786
+ if (before === null) throw new TreeUnverifiableError();
41787
+ const now = captureTree(root, watch, options);
41788
+ if (now === null) throw new TreeUnverifiableError();
41789
+ const differences = treeDifferences(before, now);
41790
+ if (differences.length > 0) throw new TreeNotRestoredError(differences);
41791
+ }
41792
+ function undoableFlush(root, results, flush, options = {}) {
41793
+ const ignore = new Set(options.ignore ?? []);
41794
+ const rels = results.map((r) => r.targetPath).filter((p) => safeRelativePath(p) !== null);
41795
+ const watch = [.../* @__PURE__ */ new Set([...rels, ...ignore])];
41796
+ const before = captureTree(root, watch, options);
41797
+ const beforePaths = new Set((before?.status ?? []).filter(isStatusEntry).map(entryPath));
41798
+ for (const p of ignore) beforePaths.add(p);
41799
+ const originals = rels.map((rel) => {
41800
+ const abs = (0, import_node_path12.resolve)(root, rel);
41801
+ let original = null;
41802
+ let st = null;
41803
+ try {
41804
+ st = (0, import_node_fs9.lstatSync)(abs);
41805
+ } catch {
41806
+ st = null;
41807
+ }
41808
+ if (st !== null && (st.isSymbolicLink() || !st.isFile())) throw new DiskWriteRefused("not_a_file");
41809
+ if (st !== null) original = (0, import_node_fs9.readFileSync)(abs);
41810
+ const createdDirs = [];
41811
+ if (original === null) {
41812
+ const missing = [];
41813
+ for (let d = (0, import_node_path12.dirname)(abs); !(0, import_node_fs9.existsSync)(d) && isInside(root, d); d = (0, import_node_path12.dirname)(d)) missing.push(d);
41814
+ createdDirs.push(...missing.reverse());
41815
+ }
41816
+ return { rel, abs, original, createdDirs };
41817
+ });
41818
+ const putFilesBack = () => {
41819
+ const failed = [];
41820
+ for (const o of [...originals].reverse()) {
41821
+ try {
41822
+ if (o.original !== null) (0, import_node_fs9.writeFileSync)(o.abs, o.original);
41823
+ else (0, import_node_fs9.rmSync)(o.abs, { force: true });
41824
+ for (const d of [...o.createdDirs].reverse()) {
41825
+ try {
41826
+ (0, import_node_fs9.rmdirSync)(d);
41827
+ } catch {
41828
+ }
41829
+ }
41830
+ } catch {
41831
+ failed.push(o.rel);
41832
+ }
41833
+ }
41834
+ return failed;
41835
+ };
41836
+ try {
41837
+ flush(results);
41838
+ } catch (err2) {
41839
+ putFilesBack();
41840
+ throw err2;
41841
+ }
41842
+ let done = false;
41843
+ return {
41844
+ undo() {
41845
+ if (done) return;
41846
+ if (before === null) throw new TreeUnverifiableError();
41847
+ const failed = putFilesBack();
41848
+ const differences = () => {
41849
+ const after = captureTree(root, watch, options);
41850
+ if (after === null) return ["(git could not report the checkout)"];
41851
+ return treeDifferences(before, after).filter((p) => !ignore.has(p));
41852
+ };
41853
+ let remaining = differences();
41854
+ if (remaining.length > 0) {
41855
+ const after = captureTree(root, watch, options);
41856
+ if (after !== null) cleanUpAfterRun(root, beforePaths, after.status);
41857
+ remaining = differences();
41858
+ }
41859
+ const bad3 = [.../* @__PURE__ */ new Set([...failed, ...remaining])].sort();
41860
+ if (bad3.length > 0) throw new TreeNotRestoredError(bad3);
41861
+ done = true;
41862
+ }
41863
+ };
41864
+ }
41865
+
41866
+ // src/repoPath.ts
41867
+ function canonicalPath(raw) {
41868
+ const n = normaliseToolPath(raw);
41869
+ return n.ok ? n.path : null;
41870
+ }
41871
+ function openPath(root, path) {
41872
+ return (0, import_node_path13.resolve)(root) === (0, import_node_path13.resolve)(process.cwd()) ? path : (0, import_node_path13.join)(root, path);
41873
+ }
41874
+ function within(rootReal, real, allowRoot) {
41875
+ const r = (0, import_node_path13.relative)(rootReal, real);
41876
+ if (r === "") return allowRoot;
41877
+ return !r.startsWith("..") && !(0, import_node_path13.isAbsolute)(r);
41878
+ }
41879
+ function readRepoText(rel, root = process.cwd()) {
41880
+ const path = canonicalPath(rel);
41881
+ if (path === null) return { ok: false, reason: "bad_path" };
41882
+ const abs = openPath(root, path);
41883
+ let stat;
41884
+ try {
41885
+ stat = (0, import_node_fs10.lstatSync)(abs);
41886
+ } catch {
41887
+ return { ok: false, reason: "missing" };
41888
+ }
41889
+ if (stat.isSymbolicLink()) return { ok: false, reason: "link" };
41890
+ if (!stat.isFile()) return { ok: false, reason: "not_file" };
41891
+ try {
41892
+ if (!within((0, import_node_fs10.realpathSync)(root), (0, import_node_path13.resolve)((0, import_node_fs10.realpathSync)(abs)), false)) return { ok: false, reason: "outside" };
41893
+ return { ok: true, text: (0, import_node_fs10.readFileSync)(abs, "utf8") };
41894
+ } catch {
41895
+ return { ok: false, reason: "missing" };
41896
+ }
41897
+ }
41898
+ function readRepoTextOrNull(rel, root = process.cwd()) {
41899
+ const read = readRepoText(rel, root);
41900
+ return read.ok ? read.text : null;
41901
+ }
41902
+ var READ_REFUSAL_WORDS = {
41903
+ bad_path: "its path is not a path inside the checkout",
41904
+ link: "it is a link, and QuikPilot never follows a link",
41905
+ outside: "it lies outside the checkout (a folder on its path is a link)",
41906
+ missing: "it does not exist",
41907
+ not_file: "it is not a file"
41908
+ };
41909
+ function readRepoTextOrThrow(rel, root = process.cwd()) {
41910
+ const read = readRepoText(rel, root);
41911
+ if (read.ok) return read.text;
41912
+ throw new Error(`${rel} could not be read: ${READ_REFUSAL_WORDS[read.reason]}.`);
41913
+ }
41914
+ function safeRepoTarget(rel, root = process.cwd()) {
41915
+ const path = canonicalPath(rel);
41916
+ if (path === null) return null;
41917
+ const abs = openPath(root, path);
41918
+ try {
41919
+ const stat = (0, import_node_fs10.lstatSync)(abs);
41920
+ if (stat.isSymbolicLink() || !stat.isFile()) return null;
41921
+ } catch {
41922
+ }
41923
+ const rootReal = (0, import_node_fs10.realpathSync)(root);
41924
+ for (let dir = (0, import_node_path13.dirname)(abs); ; ) {
41925
+ try {
41926
+ return within(rootReal, (0, import_node_path13.resolve)((0, import_node_fs10.realpathSync)(dir)), true) ? abs : null;
41927
+ } catch {
41928
+ const up = (0, import_node_path13.dirname)(dir);
41929
+ if (up === dir) return null;
41930
+ dir = up;
41931
+ }
41932
+ }
41933
+ }
41934
+ function writeRepoFile(rel, content, root = process.cwd()) {
41935
+ const path = canonicalPath(rel);
41936
+ if (path === null) throw new DiskWriteRefused("bad_path");
41937
+ const rootReal = (0, import_node_fs10.realpathSync)(root);
41938
+ const abs = openPath(root, path);
41939
+ const missing = [];
41940
+ let dir = (0, import_node_path13.dirname)(abs);
41941
+ for (; ; ) {
41942
+ let real = null;
41943
+ try {
41944
+ real = (0, import_node_path13.resolve)((0, import_node_fs10.realpathSync)(dir));
41945
+ } catch {
41946
+ real = null;
41947
+ }
41948
+ if (real !== null) {
41949
+ if (!within(rootReal, real, true)) throw new DiskWriteRefused("outside_checkout");
41950
+ break;
41951
+ }
41952
+ missing.unshift(dir);
41953
+ const up = (0, import_node_path13.dirname)(dir);
41954
+ if (up === dir) throw new DiskWriteRefused("outside_checkout");
41955
+ dir = up;
41956
+ }
41957
+ for (const d of missing) {
41958
+ (0, import_node_fs10.mkdirSync)(d);
41959
+ if ((0, import_node_fs10.lstatSync)(d).isSymbolicLink()) throw new DiskWriteRefused("outside_checkout");
41960
+ }
41961
+ try {
41962
+ const stat = (0, import_node_fs10.lstatSync)(abs);
41963
+ if (stat.isSymbolicLink() || !stat.isFile()) throw new DiskWriteRefused("not_a_file");
41964
+ } catch (err2) {
41965
+ if (err2 instanceof DiskWriteRefused) throw err2;
41966
+ }
41967
+ (0, import_node_fs10.writeFileSync)(abs, content);
41968
+ }
41969
+
41481
41970
  // src/baselineCheck.ts
41482
41971
  var BASELINE_CHECK_TIMEOUT_MS = 12e4;
41483
41972
  function shellQuote(value) {
@@ -41497,32 +41986,30 @@ function checkableIds(ids, types2) {
41497
41986
  });
41498
41987
  }
41499
41988
  function insideCheckout(cwd, path) {
41500
- const abs = (0, import_node_path11.resolve)(cwd, path);
41501
- const rel = (0, import_node_path11.relative)(cwd, abs);
41502
- return rel === "" || rel.startsWith("..") || (0, import_node_path11.isAbsolute)(rel) ? null : abs;
41989
+ return safeRepoTarget(path, cwd);
41503
41990
  }
41504
41991
  function writeForCheck(abs, content) {
41505
- const original = (0, import_node_fs8.existsSync)(abs) ? (0, import_node_fs8.readFileSync)(abs) : null;
41992
+ const original = (0, import_node_fs11.existsSync)(abs) ? (0, import_node_fs11.readFileSync)(abs) : null;
41506
41993
  const createdDirs = [];
41507
41994
  if (original === null) {
41508
41995
  const missing = [];
41509
- for (let d = (0, import_node_path11.dirname)(abs); !(0, import_node_fs8.existsSync)(d); d = (0, import_node_path11.dirname)(d)) missing.push(d);
41996
+ for (let d = (0, import_node_path14.dirname)(abs); !(0, import_node_fs11.existsSync)(d); d = (0, import_node_path14.dirname)(d)) missing.push(d);
41510
41997
  for (const d of missing.reverse()) {
41511
- (0, import_node_fs8.mkdirSync)(d);
41998
+ (0, import_node_fs11.mkdirSync)(d);
41512
41999
  createdDirs.push(d);
41513
42000
  }
41514
42001
  }
41515
- (0, import_node_fs8.writeFileSync)(abs, content);
42002
+ (0, import_node_fs11.writeFileSync)(abs, content);
41516
42003
  return { abs, original, createdDirs };
41517
42004
  }
41518
42005
  function restore(written) {
41519
42006
  for (const file of [...written].reverse()) {
41520
42007
  try {
41521
- if (file.original !== null) (0, import_node_fs8.writeFileSync)(file.abs, file.original);
41522
- else (0, import_node_fs8.rmSync)(file.abs, { force: true });
42008
+ if (file.original !== null) (0, import_node_fs11.writeFileSync)(file.abs, file.original);
42009
+ else (0, import_node_fs11.rmSync)(file.abs, { force: true });
41523
42010
  for (const d of [...file.createdDirs].reverse()) {
41524
42011
  try {
41525
- (0, import_node_fs8.rmdirSync)(d);
42012
+ (0, import_node_fs11.rmdirSync)(d);
41526
42013
  } catch {
41527
42014
  }
41528
42015
  }
@@ -41533,7 +42020,7 @@ function restore(written) {
41533
42020
  }
41534
42021
  function untrackedFiles(cwd) {
41535
42022
  try {
41536
- const out2 = (0, import_node_child_process7.execFileSync)("git", [...NO_HOOKS_ARGS, "ls-files", "--others", "--exclude-standard", "-z"], {
42023
+ const out2 = (0, import_node_child_process9.execFileSync)("git", [...NO_HOOKS_ARGS, "ls-files", "--others", "--exclude-standard", "-z"], {
41537
42024
  env: gitEnv(),
41538
42025
  cwd,
41539
42026
  encoding: "utf8",
@@ -41547,7 +42034,7 @@ function untrackedFiles(cwd) {
41547
42034
  }
41548
42035
  var mtimeOf = (path) => {
41549
42036
  try {
41550
- return (0, import_node_fs8.statSync)(path).mtimeMs;
42037
+ return (0, import_node_fs11.statSync)(path).mtimeMs;
41551
42038
  } catch {
41552
42039
  return null;
41553
42040
  }
@@ -41561,7 +42048,7 @@ function decideCause(targets, results, cwd) {
41561
42048
  const abs = insideCheckout(cwd, t.path);
41562
42049
  if (next === void 0 || abs === null) return "ALREADY_TRUE";
41563
42050
  try {
41564
- if ((0, import_node_fs8.readFileSync)(abs, "utf8") !== next) return "ALREADY_TRUE";
42051
+ if ((0, import_node_fs11.readFileSync)(abs, "utf8") !== next) return "ALREADY_TRUE";
41565
42052
  } catch {
41566
42053
  return "ALREADY_TRUE";
41567
42054
  }
@@ -41638,7 +42125,7 @@ async function runBaselineCheck(params) {
41638
42125
  for (const file of untrackedAfter) {
41639
42126
  if (untrackedBefore.has(file)) continue;
41640
42127
  const abs = insideCheckout(cwd, file);
41641
- if (abs) (0, import_node_fs8.rmSync)(abs, { force: true });
42128
+ if (abs) (0, import_node_fs11.rmSync)(abs, { force: true });
41642
42129
  }
41643
42130
  }
41644
42131
  }
@@ -41670,11 +42157,11 @@ var CONFIG_FILES = ["vitest.config.ts", "vitest.config.mts", "vitest.config.cts"
41670
42157
  var WORKSPACE_IN_CONFIG = /\b(?:workspace|projects)\s*:/;
41671
42158
  function defaultResolveVitest(cwd) {
41672
42159
  try {
41673
- const pkgPath = (0, import_node_module.createRequire)((0, import_node_path12.join)(cwd, "package.json")).resolve("vitest/package.json");
41674
- const pkg = JSON.parse((0, import_node_fs9.readFileSync)(pkgPath, "utf8"));
42160
+ const pkgPath = (0, import_node_module.createRequire)((0, import_node_path15.join)(cwd, "package.json")).resolve("vitest/package.json");
42161
+ const pkg = JSON.parse((0, import_node_fs12.readFileSync)(pkgPath, "utf8"));
41675
42162
  const rel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.vitest;
41676
42163
  if (typeof rel !== "string" || typeof pkg.version !== "string") return null;
41677
- return { bin: forward((0, import_node_path12.join)((0, import_node_path12.dirname)(pkgPath), rel)), version: pkg.version };
42164
+ return { bin: forward((0, import_node_path15.join)((0, import_node_path15.dirname)(pkgPath), rel)), version: pkg.version };
41678
42165
  } catch {
41679
42166
  return null;
41680
42167
  }
@@ -41719,9 +42206,9 @@ function detectAdapter(i3) {
41719
42206
  const parsed = parseTestInvocation(rest);
41720
42207
  if ("off" in parsed) return parsed;
41721
42208
  if (parsed.flags.some((f) => !ALLOWED_FLAG.test(f))) return { off: "extra_flags" };
41722
- const cwd = folder ? import_node_path12.posix.join(forward(i3.root), folder) : forward(i3.root);
42209
+ const cwd = folder ? import_node_path15.posix.join(forward(i3.root), folder) : forward(i3.root);
41723
42210
  if (parsed.viaScript) {
41724
- const pkgText = i3.readText(import_node_path12.posix.join(cwd, "package.json"));
42211
+ const pkgText = i3.readText(import_node_path15.posix.join(cwd, "package.json"));
41725
42212
  let script = "";
41726
42213
  try {
41727
42214
  const scripts = JSON.parse(pkgText ?? "{}").scripts;
@@ -41732,9 +42219,9 @@ function detectAdapter(i3) {
41732
42219
  if (!/\bvitest\b/.test(script)) return { off: "not_vitest" };
41733
42220
  if (!PLAIN_VITEST_SCRIPT.test(script)) return { off: "script_not_plain" };
41734
42221
  }
41735
- if (WORKSPACE_FILES.some((f) => i3.exists(import_node_path12.posix.join(cwd, f)))) return { off: "workspace_config" };
42222
+ if (WORKSPACE_FILES.some((f) => i3.exists(import_node_path15.posix.join(cwd, f)))) return { off: "workspace_config" };
41736
42223
  for (const f of CONFIG_FILES) {
41737
- const text3 = i3.exists(import_node_path12.posix.join(cwd, f)) ? i3.readText(import_node_path12.posix.join(cwd, f)) : null;
42224
+ const text3 = i3.exists(import_node_path15.posix.join(cwd, f)) ? i3.readText(import_node_path15.posix.join(cwd, f)) : null;
41738
42225
  if (text3 !== null && WORKSPACE_IN_CONFIG.test(text3)) return { off: "workspace_config" };
41739
42226
  }
41740
42227
  const found = (i3.resolveVitest ?? defaultResolveVitest)(cwd);
@@ -41757,7 +42244,7 @@ var TEST_FILE_NAME = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
41757
42244
  function forceFullReason(paths, setupFiles = []) {
41758
42245
  for (const raw of paths) {
41759
42246
  const p = forward(raw);
41760
- const base = import_node_path12.posix.basename(p);
42247
+ const base = import_node_path15.posix.basename(p);
41761
42248
  if (base === "package.json" || base === "npm-shrinkwrap.json") return "package_manifest";
41762
42249
  if (/^(?:package-lock\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?)$/.test(base)) return "lock_file";
41763
42250
  if (/^[jt]sconfig(?:\.[\w.-]+)?\.json$/.test(base)) return "ts_config";
@@ -41775,7 +42262,7 @@ function setupFilesOf(configText, folderRel) {
41775
42262
  for (const m of configText.matchAll(list2)) {
41776
42263
  for (const s of (m[1] ?? "").matchAll(/["']([^"']+)["']/g)) {
41777
42264
  const rel = forward(s[1] ?? "").replace(/^\.\//, "");
41778
- if (rel) out2.push(import_node_path12.posix.join(folderRel, rel));
42265
+ if (rel) out2.push(import_node_path15.posix.join(folderRel, rel));
41779
42266
  }
41780
42267
  }
41781
42268
  return out2;
@@ -41810,7 +42297,7 @@ function fsReadingTests(i3) {
41810
42297
  }
41811
42298
 
41812
42299
  // src/tsconfigPaths.ts
41813
- var import_node_path13 = require("node:path");
42300
+ var import_node_path16 = require("node:path");
41814
42301
  var MAX_EXTENDS_DEPTH = 5;
41815
42302
  function parseJsonc(text3) {
41816
42303
  let out2 = "";
@@ -41856,12 +42343,12 @@ function resolveConfig(readText, file, depth, seen) {
41856
42343
  if (typeof text3 !== "string") return null;
41857
42344
  const json = parseJsonc(text3);
41858
42345
  if (!isObject(json)) return null;
41859
- const dir = import_node_path13.posix.dirname(file) === "." ? "" : import_node_path13.posix.dirname(file);
42346
+ const dir = import_node_path16.posix.dirname(file) === "." ? "" : import_node_path16.posix.dirname(file);
41860
42347
  let inherited = { paths: null, pathsDir: dir, baseUrl: null };
41861
42348
  const ext = typeof json.extends === "string" ? [json.extends] : stringList(json.extends);
41862
42349
  for (const e of ext) {
41863
42350
  if (!e.startsWith(".")) continue;
41864
- const parent = resolveConfig(readText, import_node_path13.posix.normalize(import_node_path13.posix.join(dir, e.endsWith(".json") ? e : `${e}.json`)), depth + 1, seen);
42351
+ const parent = resolveConfig(readText, import_node_path16.posix.normalize(import_node_path16.posix.join(dir, e.endsWith(".json") ? e : `${e}.json`)), depth + 1, seen);
41865
42352
  if (parent) {
41866
42353
  inherited = {
41867
42354
  paths: parent.paths ?? inherited.paths,
@@ -41871,7 +42358,7 @@ function resolveConfig(readText, file, depth, seen) {
41871
42358
  }
41872
42359
  }
41873
42360
  const co = isObject(json.compilerOptions) ? json.compilerOptions : {};
41874
- const baseUrl = typeof co.baseUrl === "string" ? import_node_path13.posix.normalize(import_node_path13.posix.join(dir, co.baseUrl)) : inherited.baseUrl;
42361
+ const baseUrl = typeof co.baseUrl === "string" ? import_node_path16.posix.normalize(import_node_path16.posix.join(dir, co.baseUrl)) : inherited.baseUrl;
41875
42362
  let paths = inherited.paths;
41876
42363
  let pathsDir = inherited.pathsDir;
41877
42364
  if (isObject(co.paths)) {
@@ -41901,7 +42388,7 @@ function aliasTable(opts) {
41901
42388
  if (!config?.paths) return [];
41902
42389
  const lines = [];
41903
42390
  for (const [key, targets] of Object.entries(config.paths)) {
41904
- const resolved = targets.map((t) => import_node_path13.posix.normalize(import_node_path13.posix.join(config.baseUrl ?? config.pathsDir, t))).filter((p) => p !== ".." && !p.startsWith("../") && !import_node_path13.posix.isAbsolute(p));
42391
+ const resolved = targets.map((t) => import_node_path16.posix.normalize(import_node_path16.posix.join(config.baseUrl ?? config.pathsDir, t))).filter((p) => p !== ".." && !p.startsWith("../") && !import_node_path16.posix.isAbsolute(p));
41905
42392
  if (resolved.length > 0) lines.push(`${key} -> ${resolved.join(", ")}`);
41906
42393
  }
41907
42394
  return lines.sort().slice(0, opts.max ?? 20);
@@ -41928,7 +42415,7 @@ function createAliasMapper(opts) {
41928
42415
  };
41929
42416
  return (fromPath, specifier) => {
41930
42417
  if (specifier.startsWith(".") || specifier.startsWith("/")) return null;
41931
- const dir = import_node_path13.posix.dirname(fromPath) === "." ? "" : import_node_path13.posix.dirname(fromPath);
42418
+ const dir = import_node_path16.posix.dirname(fromPath) === "." ? "" : import_node_path16.posix.dirname(fromPath);
41932
42419
  const config = configFor(dir);
41933
42420
  if (!config?.paths) return null;
41934
42421
  let best = null;
@@ -41939,8 +42426,8 @@ function createAliasMapper(opts) {
41939
42426
  if (!best) return null;
41940
42427
  const bases = [];
41941
42428
  for (const target of config.paths[best.key]) {
41942
- const joined = import_node_path13.posix.normalize(import_node_path13.posix.join(config.baseUrl ?? config.pathsDir, target.replace("*", best.captured)));
41943
- if (joined === ".." || joined.startsWith("../") || import_node_path13.posix.isAbsolute(joined)) continue;
42429
+ const joined = import_node_path16.posix.normalize(import_node_path16.posix.join(config.baseUrl ?? config.pathsDir, target.replace("*", best.captured)));
42430
+ if (joined === ".." || joined.startsWith("../") || import_node_path16.posix.isAbsolute(joined)) continue;
41944
42431
  if (opts.writeRoot !== "" && !matchesPrefix(joined, opts.writeRoot)) continue;
41945
42432
  bases.push(joined === "." ? "" : joined);
41946
42433
  }
@@ -41986,15 +42473,15 @@ function createRelatedPlanner(d) {
41986
42473
  });
41987
42474
  const readText = d.readText ?? ((p) => {
41988
42475
  try {
41989
- return (0, import_node_fs10.readFileSync)(p, "utf8");
42476
+ return (0, import_node_fs13.readFileSync)(p, "utf8");
41990
42477
  } catch {
41991
42478
  return null;
41992
42479
  }
41993
42480
  });
41994
- const exists = d.exists ?? import_node_fs10.existsSync;
42481
+ const exists = d.exists ?? import_node_fs13.existsSync;
41995
42482
  const mode = (env2.QUIKPILOT_RELATED_TESTS ?? "").trim().toLowerCase();
41996
42483
  const minMs = minBaselineMs(env2);
41997
- const abs = (rel) => forward2((0, import_node_path14.join)(d.root, rel));
42484
+ const abs = (rel) => forward2((0, import_node_path17.join)(d.root, rel));
41998
42485
  const isTest = testRule(d.discoveredTests ?? null);
41999
42486
  let detected = null;
42000
42487
  let setupFiles = [];
@@ -42006,9 +42493,9 @@ function createRelatedPlanner(d) {
42006
42493
  function detect() {
42007
42494
  const found = detectAdapter({ command: d.command, root: forward2(d.root), readText, exists, resolveVitest: d.resolveVitest });
42008
42495
  if ("adapter" in found) {
42009
- const folder = forward2((0, import_node_path14.relative)(d.root, found.adapter.cwd));
42496
+ const folder = forward2((0, import_node_path17.relative)(d.root, found.adapter.cwd));
42010
42497
  for (const name2 of CONFIG_FILES) {
42011
- const text3 = exists(import_node_path14.posix.join(found.adapter.cwd, name2)) ? readText(import_node_path14.posix.join(found.adapter.cwd, name2)) : null;
42498
+ const text3 = exists(import_node_path17.posix.join(found.adapter.cwd, name2)) ? readText(import_node_path17.posix.join(found.adapter.cwd, name2)) : null;
42012
42499
  if (text3 !== null) setupFiles.push(...setupFilesOf(text3, folder));
42013
42500
  }
42014
42501
  log({ event: "related.adapter", adapter: found.adapter.kind, version: found.adapter.version });
@@ -42077,7 +42564,7 @@ function createRelatedPlanner(d) {
42077
42564
  limitMs: relatedLimitMs(i3.baselineMs),
42078
42565
  selected: changed.length,
42079
42566
  alwaysRun: alwaysRun.length,
42080
- key: (0, import_node_crypto.createHash)("sha1").update([...changed, ...alwaysRun].sort().join("\0")).digest("hex").slice(0, 12)
42567
+ key: (0, import_node_crypto2.createHash)("sha1").update([...changed, ...alwaysRun].sort().join("\0")).digest("hex").slice(0, 12)
42081
42568
  };
42082
42569
  },
42083
42570
  ran(r) {
@@ -42098,7 +42585,7 @@ function buildCommitMessage(runId, targeted, issueKey, issueTitle) {
42098
42585
  QuikPilot run ${runId}`;
42099
42586
  return `QuikPilot generated changes (run ${runId})`;
42100
42587
  }
42101
- function commitAndPush(branch, runId, installationToken, targeted, issueKey, issueTitle) {
42588
+ async function commitAndPush(branch, runId, installationToken, targeted, issueKey, issueTitle) {
42102
42589
  if (!hasStagedChanges()) return { changed: false };
42103
42590
  if (!branch) {
42104
42591
  throw new Error("packet carried no branch name");
@@ -42106,7 +42593,7 @@ function commitAndPush(branch, runId, installationToken, targeted, issueKey, iss
42106
42593
  configureCommitIdentity();
42107
42594
  checkoutNewBranch(branch);
42108
42595
  commit(buildCommitMessage(runId, targeted, issueKey, issueTitle));
42109
- push(branch, installationToken);
42596
+ await push(branch, installationToken);
42110
42597
  return { changed: true, branch };
42111
42598
  }
42112
42599
 
@@ -42248,10 +42735,6 @@ function spendSoFar() {
42248
42735
  return addTotals(addTotals(byStep.targeting, byStep.codegen), byStep.investigate);
42249
42736
  }
42250
42737
 
42251
- // src/codegen.ts
42252
- var import_node_fs11 = require("node:fs");
42253
- var import_node_path15 = require("node:path");
42254
-
42255
42738
  // src/envelope.ts
42256
42739
  var HARD_FAILURE_CODES = /* @__PURE__ */ new Set(["SEMANTIC_MISMATCH", "CONTRACT_REJECTED"]);
42257
42740
  function checkHardFailure(envelope, useCase, target) {
@@ -42290,7 +42773,7 @@ var NOT_RETRIED_CODES = /* @__PURE__ */ new Set([FILE_TOO_LARGE_CODE, CONTEXT_TO
42290
42773
  var JUDGED_BY_TOO_LARGE_CODE = "CODEGEN_JUDGED_BY_TOO_LARGE";
42291
42774
  var MAX_ADDED_FILE_CHARS = 4e4;
42292
42775
  var MAX_ADDED_CONTEXT_CHARS = 6e4;
42293
- function collectRunContext(target, targets, alreadyNamed, deniedPaths, readFile = (p) => (0, import_node_fs11.readFileSync)(p, "utf8")) {
42776
+ function collectRunContext(target, targets, alreadyNamed, deniedPaths, readFile = (p) => readRepoTextOrThrow(p)) {
42294
42777
  const added = { entries: [], skipped: [] };
42295
42778
  if (!target.automationIds?.length) return added;
42296
42779
  const seen = new Set(alreadyNamed);
@@ -42327,11 +42810,11 @@ var JS_TS_EXTENSION_RE = /\.(?:ts|tsx|js|jsx|mjs|cjs)$/;
42327
42810
  var EXPORTED_SYMBOL_RE = /^export\s+(?:default\s+)?(?:async\s+)?(?:function\*?|class|const|let|var|interface|type|enum)\s+([A-Za-z_$][\w$]*)/gm;
42328
42811
  function countRemovedLines(currentContent, newContent) {
42329
42812
  const remaining = /* @__PURE__ */ new Map();
42330
- for (const line2 of newContent.split("\n")) {
42813
+ for (const line2 of toLf(newContent).split("\n")) {
42331
42814
  remaining.set(line2, (remaining.get(line2) ?? 0) + 1);
42332
42815
  }
42333
42816
  let removed = 0;
42334
- for (const line2 of currentContent.split("\n")) {
42817
+ for (const line2 of toLf(currentContent).split("\n")) {
42335
42818
  const count4 = remaining.get(line2) ?? 0;
42336
42819
  if (count4 > 0) {
42337
42820
  remaining.set(line2, count4 - 1);
@@ -42460,7 +42943,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
42460
42943
  const listing = new Set(workspaceListing);
42461
42944
  for (const target of targets) {
42462
42945
  const isNewFile = target.kind === "NEW_FILE";
42463
- const currentContent = isNewFile ? "" : (0, import_node_fs11.readFileSync)(target.path, "utf8");
42946
+ const currentContent = isNewFile ? "" : readRepoTextOrThrow(target.path);
42464
42947
  const lineEnding = isNewFile ? "LF" : detectLineEnding(currentContent);
42465
42948
  const wantsEdits = !isNewFile && lineEnding !== "mixed";
42466
42949
  const contextPaths = target.contextPaths ?? [];
@@ -42477,7 +42960,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
42477
42960
  );
42478
42961
  }
42479
42962
  }
42480
- const namedContents = contextPaths.map((path2) => ({ path: path2, content: (0, import_node_fs11.readFileSync)(path2, "utf8") }));
42963
+ const namedContents = contextPaths.map((path2) => ({ path: path2, content: readRepoTextOrThrow(path2) }));
42481
42964
  const runFiles = collectRunContext(target, targets, new Set(contextPaths), deniedPaths);
42482
42965
  for (const s of runFiles.skipped) {
42483
42966
  warnings.push(`not shown to the test for ${target.path}: ${s.path} (${s.reason})`);
@@ -42488,7 +42971,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
42488
42971
  alreadyNamed: /* @__PURE__ */ new Set([...contextPaths, ...runFiles.entries.map((e) => e.path)]),
42489
42972
  deniedPaths,
42490
42973
  listing,
42491
- readFile: (p) => (0, import_node_fs11.readFileSync)(p, "utf8"),
42974
+ readFile: (p) => readRepoTextOrThrow(p),
42492
42975
  maxFileChars: MAX_ADDED_FILE_CHARS,
42493
42976
  maxTotalChars: MAX_ADDED_CONTEXT_CHARS,
42494
42977
  spentChars: runFiles.entries.reduce((n, e) => n + e.content.length, 0)
@@ -42655,6 +43138,13 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
42655
43138
  reason = failedEdits.reason;
42656
43139
  }
42657
43140
  if (newContent === null) throw new Error(`Codegen produced no content for ${target.path}`);
43141
+ if (!isNewFile && lineEnding !== "LF") {
43142
+ const after = detectLineEnding(newContent);
43143
+ if (lineEnding === "CRLF" && after !== "CRLF") newContent = fromLf(toLf(newContent), "CRLF");
43144
+ else if (lineEnding === "mixed" && after !== "mixed") {
43145
+ console.log(JSON.stringify({ event: "codegen.line_endings", targetPath: target.path, before: lineEnding, after }));
43146
+ }
43147
+ }
42658
43148
  if (!isNewFile) {
42659
43149
  console.log(
42660
43150
  JSON.stringify({
@@ -42696,10 +43186,7 @@ async function runCodegen(gateway, targets, workspaceListing, requiredTests, den
42696
43186
  return results;
42697
43187
  }
42698
43188
  function flushCodegenResults(results) {
42699
- for (const { targetPath, newContent } of results) {
42700
- (0, import_node_fs11.mkdirSync)((0, import_node_path15.dirname)(targetPath), { recursive: true });
42701
- (0, import_node_fs11.writeFileSync)(targetPath, newContent);
42702
- }
43189
+ for (const { targetPath, newContent } of results) writeRepoFile(targetPath, newContent);
42703
43190
  }
42704
43191
 
42705
43192
  // src/codegenMode.ts
@@ -42745,356 +43232,6 @@ function callFunctionEnabled(githubRepository, mode, env2 = process.env) {
42745
43232
  var import_node_crypto4 = require("node:crypto");
42746
43233
  var import_node_path19 = require("node:path");
42747
43234
 
42748
- // src/overlayOnDisk.ts
42749
- var import_node_child_process9 = require("node:child_process");
42750
- var import_node_fs13 = require("node:fs");
42751
- var import_node_path17 = require("node:path");
42752
-
42753
- // src/treeFingerprint.ts
42754
- var import_node_crypto2 = require("node:crypto");
42755
- var import_node_child_process8 = require("node:child_process");
42756
- var import_node_fs12 = require("node:fs");
42757
- var import_node_path16 = require("node:path");
42758
- var MAX_HASHED_BYTES = 8 * 1024 * 1024;
42759
- function defaultGitStatus(root) {
42760
- try {
42761
- return (0, import_node_child_process8.execFileSync)("git", [...NO_HOOKS_ARGS, "status", "--porcelain=v1", "-z", "--untracked-files=all"], {
42762
- env: gitEnv(),
42763
- cwd: root,
42764
- encoding: "utf8",
42765
- stdio: ["ignore", "pipe", "ignore"],
42766
- maxBuffer: 64 * 1024 * 1024
42767
- });
42768
- } catch {
42769
- return null;
42770
- }
42771
- }
42772
- var STATUS_ENTRY = /^[ MADRCUT?!]{2} /;
42773
- function isStatusEntry(token) {
42774
- return STATUS_ENTRY.test(token);
42775
- }
42776
- function entryPath(token) {
42777
- return token.slice(3);
42778
- }
42779
- function entryCode(token) {
42780
- return token.slice(0, 2);
42781
- }
42782
- function parseStatus(raw) {
42783
- return raw.split("\0").filter((t) => t.length > 0).sort();
42784
- }
42785
- function hashOf(root, rel) {
42786
- const abs = (0, import_node_path16.join)(root, rel);
42787
- let st;
42788
- try {
42789
- st = (0, import_node_fs12.lstatSync)(abs);
42790
- } catch {
42791
- return null;
42792
- }
42793
- try {
42794
- if (st.isSymbolicLink()) return `link:${(0, import_node_fs12.readlinkSync)(abs)}`;
42795
- if (st.isDirectory()) return "dir";
42796
- if (st.size > MAX_HASHED_BYTES) return `big:${st.size}:${Math.trunc(st.mtimeMs)}`;
42797
- return (0, import_node_crypto2.createHash)("sha256").update((0, import_node_fs12.readFileSync)(abs)).digest("hex");
42798
- } catch {
42799
- return `unreadable`;
42800
- }
42801
- }
42802
- function captureTree(root, watch, deps = {}) {
42803
- const raw = (deps.gitStatus ?? defaultGitStatus)(root);
42804
- if (raw === null) return null;
42805
- const status = parseStatus(raw);
42806
- const paths = new Set(watch);
42807
- for (const token of status) if (isStatusEntry(token)) paths.add(entryPath(token));
42808
- const hashes = {};
42809
- for (const p of [...paths].sort()) hashes[p] = hashOf(root, p);
42810
- const digest = (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify([status, hashes])).digest("hex");
42811
- return { status, hashes, digest };
42812
- }
42813
- function treeDifferences(before, after) {
42814
- const out2 = /* @__PURE__ */ new Set();
42815
- for (const p of /* @__PURE__ */ new Set([...Object.keys(before.hashes), ...Object.keys(after.hashes)])) {
42816
- if ((before.hashes[p] ?? null) !== (after.hashes[p] ?? null)) out2.add(p);
42817
- }
42818
- const codes = (s) => new Map(s.status.filter(isStatusEntry).map((t) => [entryPath(t), entryCode(t)]));
42819
- const b = codes(before);
42820
- const a = codes(after);
42821
- for (const p of /* @__PURE__ */ new Set([...b.keys(), ...a.keys()])) if (b.get(p) !== a.get(p)) out2.add(p);
42822
- return [...out2].sort();
42823
- }
42824
-
42825
- // src/overlayOnDisk.ts
42826
- var TreeNotRestoredError = class extends Error {
42827
- paths;
42828
- constructor(paths, cause) {
42829
- super("The checkout could not be restored after a test run.");
42830
- this.name = "TreeNotRestoredError";
42831
- this.paths = paths;
42832
- if (cause !== void 0) this.cause = cause;
42833
- }
42834
- };
42835
- var TreeUnverifiableError = class extends Error {
42836
- constructor() {
42837
- super("The checkout could not be verified, so no test run was started.");
42838
- this.name = "TreeUnverifiableError";
42839
- }
42840
- };
42841
- var DiskWriteRefused = class extends Error {
42842
- reason;
42843
- constructor(reason) {
42844
- super(`A change could not be put on disk (${reason}).`);
42845
- this.name = "DiskWriteRefused";
42846
- this.reason = reason;
42847
- }
42848
- };
42849
- function safeRelativePath(rel) {
42850
- if (typeof rel !== "string" || rel.length === 0 || rel.length > 400 || rel.includes("\0") || rel.includes("\\")) return null;
42851
- if ((0, import_node_path17.isAbsolute)(rel) || /^[A-Za-z]:/.test(rel)) return null;
42852
- const parts2 = rel.split("/");
42853
- if (parts2.some((p) => p === "" || p === "." || p === "..")) return null;
42854
- return rel;
42855
- }
42856
- function isInside(root, abs) {
42857
- const r = (0, import_node_path17.relative)(root, abs);
42858
- return r !== "" && !r.startsWith("..") && !(0, import_node_path17.isAbsolute)(r);
42859
- }
42860
- function ancestorInside(realRoot, abs) {
42861
- let dir = (0, import_node_path17.dirname)(abs);
42862
- for (; ; ) {
42863
- try {
42864
- const real = (0, import_node_fs13.realpathSync)(dir);
42865
- const r = (0, import_node_path17.relative)(realRoot, real);
42866
- return r === "" || !r.startsWith("..") && !(0, import_node_path17.isAbsolute)(r);
42867
- } catch {
42868
- const up = (0, import_node_path17.dirname)(dir);
42869
- if (up === dir) return false;
42870
- dir = up;
42871
- }
42872
- }
42873
- }
42874
- function applyOverlay(root, files) {
42875
- const realRoot = (0, import_node_fs13.realpathSync)(root);
42876
- const written = [];
42877
- const seen = /* @__PURE__ */ new Set();
42878
- const restore2 = () => {
42879
- const failed = [];
42880
- for (const w of [...written].reverse()) {
42881
- const rel = (0, import_node_path17.relative)(root, w.abs).split("\\").join("/");
42882
- try {
42883
- if (w.original !== null) (0, import_node_fs13.writeFileSync)(w.abs, w.original);
42884
- else (0, import_node_fs13.rmSync)(w.abs, { force: true });
42885
- for (const d of [...w.createdDirs].reverse()) {
42886
- try {
42887
- (0, import_node_fs13.rmdirSync)(d);
42888
- } catch {
42889
- }
42890
- }
42891
- } catch {
42892
- failed.push(rel);
42893
- }
42894
- }
42895
- written.length = 0;
42896
- return { failed: failed.sort() };
42897
- };
42898
- try {
42899
- for (const f of files) {
42900
- const rel = safeRelativePath(f.path);
42901
- if (rel === null) throw new DiskWriteRefused("bad_path");
42902
- if (seen.has(rel)) throw new DiskWriteRefused("duplicate");
42903
- seen.add(rel);
42904
- const abs = (0, import_node_path17.resolve)(root, rel);
42905
- if (!isInside(root, abs) || !ancestorInside(realRoot, abs)) throw new DiskWriteRefused("outside_checkout");
42906
- let original = null;
42907
- try {
42908
- const st = (0, import_node_fs13.lstatSync)(abs);
42909
- if (st.isSymbolicLink() || !st.isFile()) throw new DiskWriteRefused("not_a_file");
42910
- original = (0, import_node_fs13.readFileSync)(abs);
42911
- } catch (err2) {
42912
- if (err2 instanceof DiskWriteRefused) throw err2;
42913
- original = null;
42914
- }
42915
- const createdDirs = [];
42916
- if (original === null) {
42917
- const missing = [];
42918
- for (let d = (0, import_node_path17.dirname)(abs); !(0, import_node_fs13.existsSync)(d); d = (0, import_node_path17.dirname)(d)) missing.push(d);
42919
- for (const d of missing.reverse()) {
42920
- (0, import_node_fs13.mkdirSync)(d);
42921
- createdDirs.push(d);
42922
- }
42923
- }
42924
- const w = { abs, original, createdDirs };
42925
- written.push(w);
42926
- (0, import_node_fs13.writeFileSync)(abs, f.content);
42927
- }
42928
- } catch (err2) {
42929
- restore2();
42930
- throw err2;
42931
- }
42932
- return { restore: restore2 };
42933
- }
42934
- function git2(root, args2) {
42935
- (0, import_node_child_process9.execFileSync)("git", [...NO_HOOKS_ARGS, ...args2], { env: gitEnv(), cwd: root, stdio: ["ignore", "ignore", "ignore"] });
42936
- }
42937
- function cleanUpAfterRun(root, beforePaths, afterStatus) {
42938
- for (const token of afterStatus) {
42939
- if (!isStatusEntry(token)) continue;
42940
- const p = entryPath(token);
42941
- if (beforePaths.has(p) || safeRelativePath(p) === null) continue;
42942
- const code = entryCode(token);
42943
- try {
42944
- if (code === "??") {
42945
- (0, import_node_fs13.rmSync)((0, import_node_path17.join)(root, p), { recursive: true, force: true });
42946
- for (let d = (0, import_node_path17.dirname)((0, import_node_path17.join)(root, p)); d !== root && isInside(root, d); d = (0, import_node_path17.dirname)(d)) {
42947
- try {
42948
- (0, import_node_fs13.rmdirSync)(d);
42949
- } catch {
42950
- break;
42951
- }
42952
- }
42953
- } else if (code[0] === "A") {
42954
- git2(root, ["rm", "-f", "--", p]);
42955
- } else {
42956
- git2(root, ["checkout", "HEAD", "--", p]);
42957
- }
42958
- } catch {
42959
- }
42960
- }
42961
- }
42962
- function snapshotPreserved(root, paths) {
42963
- const out2 = [];
42964
- for (const rel of paths ?? []) {
42965
- if (safeRelativePath(rel) === null) continue;
42966
- const abs = (0, import_node_path17.resolve)(root, rel);
42967
- try {
42968
- const st = (0, import_node_fs13.lstatSync)(abs);
42969
- if (st.isSymbolicLink() || !st.isFile()) continue;
42970
- out2.push({ rel, abs, bytes: (0, import_node_fs13.readFileSync)(abs) });
42971
- } catch {
42972
- }
42973
- }
42974
- return out2;
42975
- }
42976
- function restorePreserved(kept) {
42977
- for (const k of kept) {
42978
- try {
42979
- (0, import_node_fs13.writeFileSync)(k.abs, k.bytes);
42980
- } catch {
42981
- }
42982
- }
42983
- }
42984
- async function withOverlayOnDisk(root, files, run3, options = {}) {
42985
- const kept = snapshotPreserved(root, options.preserve);
42986
- const watch = [...files.map((f) => f.path), ...kept.map((k) => k.rel)];
42987
- const before = captureTree(root, watch, options);
42988
- if (before === null) throw new TreeUnverifiableError();
42989
- const beforePaths = new Set(before.status.filter(isStatusEntry).map(entryPath));
42990
- const session = applyOverlay(root, files);
42991
- let value;
42992
- let runError;
42993
- let failedRun = false;
42994
- try {
42995
- value = await run3();
42996
- } catch (err2) {
42997
- failedRun = true;
42998
- runError = err2;
42999
- }
43000
- const { failed } = session.restore();
43001
- restorePreserved(kept);
43002
- let remaining = [];
43003
- const after = captureTree(root, watch, options);
43004
- if (after === null) {
43005
- remaining = ["(git could not report the checkout)"];
43006
- } else {
43007
- remaining = treeDifferences(before, after);
43008
- if (remaining.length > 0) {
43009
- cleanUpAfterRun(root, beforePaths, after.status);
43010
- const again = captureTree(root, watch, options);
43011
- remaining = again === null ? ["(git could not report the checkout)"] : treeDifferences(before, again);
43012
- }
43013
- }
43014
- const bad3 = [.../* @__PURE__ */ new Set([...failed, ...remaining])].sort();
43015
- if (bad3.length > 0) throw new TreeNotRestoredError(bad3, failedRun ? runError : void 0);
43016
- if (failedRun) throw runError;
43017
- return value;
43018
- }
43019
- function assertTreeUnchanged(root, before, watch, options = {}) {
43020
- if (before === null) throw new TreeUnverifiableError();
43021
- const now = captureTree(root, watch, options);
43022
- if (now === null) throw new TreeUnverifiableError();
43023
- const differences = treeDifferences(before, now);
43024
- if (differences.length > 0) throw new TreeNotRestoredError(differences);
43025
- }
43026
- function undoableFlush(root, results, flush, options = {}) {
43027
- const ignore = new Set(options.ignore ?? []);
43028
- const rels = results.map((r) => r.targetPath).filter((p) => safeRelativePath(p) !== null);
43029
- const watch = [.../* @__PURE__ */ new Set([...rels, ...ignore])];
43030
- const before = captureTree(root, watch, options);
43031
- const beforePaths = new Set((before?.status ?? []).filter(isStatusEntry).map(entryPath));
43032
- for (const p of ignore) beforePaths.add(p);
43033
- const originals = rels.map((rel) => {
43034
- const abs = (0, import_node_path17.resolve)(root, rel);
43035
- let original = null;
43036
- try {
43037
- const st = (0, import_node_fs13.lstatSync)(abs);
43038
- if (st.isFile() && !st.isSymbolicLink()) original = (0, import_node_fs13.readFileSync)(abs);
43039
- } catch {
43040
- original = null;
43041
- }
43042
- const createdDirs = [];
43043
- if (original === null) {
43044
- const missing = [];
43045
- for (let d = (0, import_node_path17.dirname)(abs); !(0, import_node_fs13.existsSync)(d) && isInside(root, d); d = (0, import_node_path17.dirname)(d)) missing.push(d);
43046
- createdDirs.push(...missing.reverse());
43047
- }
43048
- return { rel, abs, original, createdDirs };
43049
- });
43050
- const putFilesBack = () => {
43051
- const failed = [];
43052
- for (const o of [...originals].reverse()) {
43053
- try {
43054
- if (o.original !== null) (0, import_node_fs13.writeFileSync)(o.abs, o.original);
43055
- else (0, import_node_fs13.rmSync)(o.abs, { force: true });
43056
- for (const d of [...o.createdDirs].reverse()) {
43057
- try {
43058
- (0, import_node_fs13.rmdirSync)(d);
43059
- } catch {
43060
- }
43061
- }
43062
- } catch {
43063
- failed.push(o.rel);
43064
- }
43065
- }
43066
- return failed;
43067
- };
43068
- try {
43069
- flush(results);
43070
- } catch (err2) {
43071
- putFilesBack();
43072
- throw err2;
43073
- }
43074
- let done = false;
43075
- return {
43076
- undo() {
43077
- if (done) return;
43078
- if (before === null) throw new TreeUnverifiableError();
43079
- const failed = putFilesBack();
43080
- const differences = () => {
43081
- const after = captureTree(root, watch, options);
43082
- if (after === null) return ["(git could not report the checkout)"];
43083
- return treeDifferences(before, after).filter((p) => !ignore.has(p));
43084
- };
43085
- let remaining = differences();
43086
- if (remaining.length > 0) {
43087
- const after = captureTree(root, watch, options);
43088
- if (after !== null) cleanUpAfterRun(root, beforePaths, after.status);
43089
- remaining = differences();
43090
- }
43091
- const bad3 = [.../* @__PURE__ */ new Set([...failed, ...remaining])].sort();
43092
- if (bad3.length > 0) throw new TreeNotRestoredError(bad3);
43093
- done = true;
43094
- }
43095
- };
43096
- }
43097
-
43098
43235
  // src/runTestsTool.ts
43099
43236
  var import_node_crypto3 = require("node:crypto");
43100
43237
  var import_node_fs14 = require("node:fs");
@@ -48153,7 +48290,7 @@ function stepsOf(transcript, toolResults) {
48153
48290
 
48154
48291
  // src/importCheck.ts
48155
48292
  var MAX_REPORTED = 5;
48156
- function resolve3(fromPath, spec, exists) {
48293
+ function resolve4(fromPath, spec, exists) {
48157
48294
  const dir = fromPath.includes("/") ? fromPath.slice(0, fromPath.lastIndexOf("/")) : "";
48158
48295
  const out2 = [];
48159
48296
  for (const part of [...dir ? dir.split("/") : [], ...spec.split("/")]) {
@@ -48261,7 +48398,7 @@ function missingImports(changed, read, exists) {
48261
48398
  const parsed = parseProgram(path, text3);
48262
48399
  if (!parsed || parsed.sourceType !== "module") continue;
48263
48400
  for (const [name2, spec] of relativeImports(parsed.ast)) {
48264
- const target = resolve3(path, spec, exists);
48401
+ const target = resolve4(path, spec, exists);
48265
48402
  if (!target) continue;
48266
48403
  if (!exportsOf.has(target)) {
48267
48404
  const t = read(target);
@@ -51607,9 +51744,6 @@ function buildCodegenLoopRecord(loop) {
51607
51744
  };
51608
51745
  }
51609
51746
 
51610
- // src/codegenLoopContext.ts
51611
- var import_node_fs18 = require("node:fs");
51612
-
51613
51747
  // src/langReach.ts
51614
51748
  var import_node_path22 = require("node:path");
51615
51749
  var LANGUAGE_BY_EXT = {
@@ -51753,7 +51887,7 @@ function pythonImports(file, text3, ix) {
51753
51887
  const lookup = (dotted) => {
51754
51888
  for (const hit of ix.pyModules.get(dotted) ?? []) if (hit !== file) out2.add(hit);
51755
51889
  };
51756
- const relative12 = (dots, rest) => {
51890
+ const relative14 = (dots, rest) => {
51757
51891
  let base = dirOf(file);
51758
51892
  for (let i3 = 1; i3 < dots; i3++) base = dirOf(base);
51759
51893
  const joined = rest ? import_node_path22.posix.join(base, rest.replace(/\./g, "/")) : base;
@@ -51766,8 +51900,8 @@ function pythonImports(file, text3, ix) {
51766
51900
  const mod = from[2];
51767
51901
  const names = from[3].replace(/[()\\]/g, "").split(",").map((s) => s.trim().split(/\s+as\s+/)[0].trim()).filter((s) => /^\w+$/.test(s));
51768
51902
  if (dots > 0) {
51769
- for (const p of relative12(dots, mod)) out2.add(p);
51770
- for (const n of names) for (const p of relative12(dots, mod ? `${mod}.${n}` : n)) out2.add(p);
51903
+ for (const p of relative14(dots, mod)) out2.add(p);
51904
+ for (const n of names) for (const p of relative14(dots, mod ? `${mod}.${n}` : n)) out2.add(p);
51771
51905
  } else {
51772
51906
  lookup(mod);
51773
51907
  for (const n of names) lookup(`${mod}.${n}`);
@@ -52004,7 +52138,7 @@ function asLf(text3) {
52004
52138
  return toLf(text3.charCodeAt(0) === 65279 ? text3.slice(1) : text3);
52005
52139
  }
52006
52140
  function collectLoopContext(p) {
52007
- const readFile = p.readFile ?? ((path) => (0, import_node_fs18.readFileSync)(path, "utf8"));
52141
+ const readFile = p.readFile ?? ((path) => readRepoTextOrThrow(path));
52008
52142
  const listing = new Set(p.listing);
52009
52143
  const mapSpecifier = p.mapSpecifier ?? createAliasMapper({
52010
52144
  readText: (path) => {
@@ -52171,8 +52305,6 @@ function mapModeMessage(phase, reason) {
52171
52305
  }
52172
52306
 
52173
52307
  // src/testsToCheck.ts
52174
- var import_node_fs19 = require("node:fs");
52175
- var import_node_path23 = require("node:path");
52176
52308
  var MAX_TESTS_TO_CHECK = 10;
52177
52309
  var SECOND_HOP_BELOW = 3;
52178
52310
  function testsToCheck(i3) {
@@ -52223,7 +52355,7 @@ function testsToCheck(i3) {
52223
52355
  }
52224
52356
  var readFromRoot = (root) => (rel) => {
52225
52357
  try {
52226
- return (0, import_node_fs19.readFileSync)((0, import_node_path23.join)(root, rel), "utf8");
52358
+ return readRepoTextOrNull(rel, root);
52227
52359
  } catch {
52228
52360
  return null;
52229
52361
  }
@@ -52697,7 +52829,7 @@ async function runCodegenStep(p) {
52697
52829
  }
52698
52830
 
52699
52831
  // src/codegenHeal.ts
52700
- var import_node_fs20 = require("node:fs");
52832
+ var import_node_fs18 = require("node:fs");
52701
52833
 
52702
52834
  // src/heal.ts
52703
52835
  var MAX_ATTEMPTS_IN_ALL = 3;
@@ -52777,7 +52909,7 @@ async function runHealAttempt(i3) {
52777
52909
  const created = i3.results.map((r) => r.targetPath).filter((path) => !listed.has(path));
52778
52910
  const workspaceListing = [...p.workspaceListing, ...created];
52779
52911
  const targets = p.targets.map((t) => t.kind === "NEW_FILE" && keptText.has(t.path) ? { ...t, kind: "EXISTING" } : t);
52780
- const disk = p.readFile ?? ((path) => (0, import_node_fs20.readFileSync)(path, "utf8"));
52912
+ const disk = p.readFile ?? ((path) => (0, import_node_fs18.readFileSync)(path, "utf8"));
52781
52913
  const readFile = (path) => keptText.get(path) ?? disk(path);
52782
52914
  const discoveredTests = discoveredTestsOf(p.testDiscovery);
52783
52915
  const context = collectLoopContext({ targets, listing: workspaceListing, deniedPaths: p.deniedPaths, writeRoot: p.writeRoot ?? "", ...discoveredTests ? { discoveredTests } : {}, readFile });
@@ -52879,6 +53011,7 @@ async function runVerifyAndFix(p) {
52879
53011
  });
52880
53012
  const reviewFix = async (verdict, v) => {
52881
53013
  const before = results;
53014
+ const kept = p.snapshotPassed ? p.snapshotPassed(before) : null;
52882
53015
  try {
52883
53016
  v.undo();
52884
53017
  } catch (err2) {
@@ -52922,7 +53055,10 @@ async function runVerifyAndFix(p) {
52922
53055
  }
52923
53056
  lastAttemptMs = p.now() - startedAt;
52924
53057
  const review = lastReview ? { review: lastReview } : {};
52925
- if (fixed2) {
53058
+ if (fixed2 && p.jobStopAtMs - p.now() < v.gateMs) {
53059
+ p.log({ event: "heal.review_no_time", attempt: attemptsRun, leftSeconds: Math.round((p.jobStopAtMs - p.now()) / 1e3) });
53060
+ if (kept) return keepPassed(kept, v, before, record2("review_reverted", first), review);
53061
+ } else if (fixed2) {
52926
53062
  const v2 = await p.verify(fixed2, true);
52927
53063
  attempts.push({
52928
53064
  n: attemptsRun,
@@ -52939,13 +53075,21 @@ async function runVerifyAndFix(p) {
52939
53075
  }
52940
53076
  p.log({ event: "heal.review_reverted", attempt: attemptsRun });
52941
53077
  }
53078
+ const heal = fixed2 ? record2("review_reverted", first) : record2("heal_failed", { ...first, ...failureReason ? { failureReason } : {} });
53079
+ if (kept) return keepPassed(kept, v, before, heal, review);
52942
53080
  const back = await p.verify(before, false);
52943
- return {
52944
- outcome: back,
52945
- results: before,
52946
- heal: fixed2 ? record2("review_reverted", first) : record2("heal_failed", { ...first, ...failureReason ? { failureReason } : {} }),
52947
- ...review
52948
- };
53081
+ return { outcome: back, results: before, heal, ...review };
53082
+ };
53083
+ const keepPassed = (kept, v, before, heal, review) => {
53084
+ let undo;
53085
+ try {
53086
+ undo = kept.putBack();
53087
+ } catch (err2) {
53088
+ if (err2 instanceof TreeNotRestoredError || err2 instanceof TreeUnverifiableError) p.onStop?.("tree_not_restored");
53089
+ throw err2;
53090
+ }
53091
+ p.log({ event: "heal.review_kept_pass", attempt: attemptsRun });
53092
+ return { outcome: { ...v, undo }, results: before, heal, ...review };
52949
53093
  };
52950
53094
  for (; ; ) {
52951
53095
  const undoable = healAllowance(p.setting, attemptsRun, healsRun, p.mode) > 0;
@@ -53043,8 +53187,8 @@ async function runVerifyAndFix(p) {
53043
53187
 
53044
53188
  // src/hunkCheck.ts
53045
53189
  var import_node_child_process11 = require("node:child_process");
53046
- var import_node_fs21 = require("node:fs");
53047
- var import_node_path24 = require("node:path");
53190
+ var import_node_fs19 = require("node:fs");
53191
+ var import_node_path23 = require("node:path");
53048
53192
  var MAX_REPORTED_HUNKS = 20;
53049
53193
  function toFinding(r) {
53050
53194
  if (r.unnecessary.length === 0) return void 0;
@@ -53122,7 +53266,7 @@ async function runHunkCheck(input) {
53122
53266
  let slowestRunMs = input.baselineMs ?? 3e4;
53123
53267
  const runOnce = async (c) => {
53124
53268
  const reportBefore = findReport(input.root);
53125
- const preserve = reportBefore ? [(0, import_node_path24.relative)(input.root, reportBefore).split("\\").join("/")] : [];
53269
+ const preserve = reportBefore ? [(0, import_node_path23.relative)(input.root, reportBefore).split("\\").join("/")] : [];
53126
53270
  const content = `${c.bom ? "\uFEFF" : ""}${fromLf(revertHunk(c.originalLf, c.currentLf, c.hunk), c.ending)}`;
53127
53271
  const startedWall = Date.now();
53128
53272
  const startedAt = now();
@@ -53132,13 +53276,13 @@ async function runHunkCheck(input) {
53132
53276
  input.root,
53133
53277
  [{ path: c.file, content }],
53134
53278
  async () => {
53135
- if (reportBefore) (0, import_node_fs21.rmSync)(reportBefore, { force: true });
53279
+ if (reportBefore) (0, import_node_fs19.rmSync)(reportBefore, { force: true });
53136
53280
  const run3 = await runCommand2(input.command, perRunMs, input.root);
53137
53281
  if (!run3.started || run3.timedOut) return "unknown";
53138
53282
  const report = findReport(input.root);
53139
53283
  if (!report) return "unknown";
53140
53284
  try {
53141
- if ((0, import_node_fs21.statSync)(report).mtimeMs < startedWall - FRESH_SLACK_MS3) return "unknown";
53285
+ if ((0, import_node_fs19.statSync)(report).mtimeMs < startedWall - FRESH_SLACK_MS3) return "unknown";
53142
53286
  } catch {
53143
53287
  return "unknown";
53144
53288
  }
@@ -53158,7 +53302,7 @@ async function runHunkCheck(input) {
53158
53302
  };
53159
53303
  const runRelated = async (c, plan, limitMs) => {
53160
53304
  const reportBefore = findReport(input.root);
53161
- const preserve = reportBefore ? [(0, import_node_path24.relative)(input.root, reportBefore).split("\\").join("/")] : [];
53305
+ const preserve = reportBefore ? [(0, import_node_path23.relative)(input.root, reportBefore).split("\\").join("/")] : [];
53162
53306
  const content = `${c.bom ? "\uFEFF" : ""}${fromLf(revertHunk(c.originalLf, c.currentLf, c.hunk), c.ending)}`;
53163
53307
  const startedAt = now();
53164
53308
  result.relatedRuns += 1;
@@ -53167,7 +53311,7 @@ async function runHunkCheck(input) {
53167
53311
  input.root,
53168
53312
  [{ path: c.file, content }],
53169
53313
  async () => {
53170
- (0, import_node_fs21.rmSync)(plan.report, { force: true });
53314
+ (0, import_node_fs19.rmSync)(plan.report, { force: true });
53171
53315
  try {
53172
53316
  const run3 = await runCommand2(plan.command, limitMs, plan.cwd);
53173
53317
  if (!run3.started || run3.timedOut) return "unknown";
@@ -53175,7 +53319,7 @@ async function runHunkCheck(input) {
53175
53319
  if (!after.results || after.results.size === 0) return "unknown";
53176
53320
  return checkForRegressions(input.baseline, after).blocked ? "needed" : "unneeded";
53177
53321
  } finally {
53178
- (0, import_node_fs21.rmSync)(plan.report, { force: true });
53322
+ (0, import_node_fs19.rmSync)(plan.report, { force: true });
53179
53323
  }
53180
53324
  },
53181
53325
  { ...input.tree, preserve }
@@ -53302,8 +53446,8 @@ function healFailureSuffix(heal) {
53302
53446
  }
53303
53447
 
53304
53448
  // src/dependencyCheck.ts
53305
- var import_node_fs22 = require("node:fs");
53306
- var import_node_path25 = require("node:path");
53449
+ var import_node_fs20 = require("node:fs");
53450
+ var import_node_path24 = require("node:path");
53307
53451
  var SCANNABLE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"];
53308
53452
  var IMPORT_RE = /(?:\bimport\b[^'"]*?\bfrom\s*|\bimport\s*\(\s*|\bexport\b[^'"]*?\bfrom\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"]+)\1/g;
53309
53453
  var NODE_BUILTINS = /* @__PURE__ */ new Set([
@@ -53391,14 +53535,14 @@ function dependencyNames(pkg) {
53391
53535
  ]);
53392
53536
  }
53393
53537
  function readDeclaredDependencies(results, workspaceRoot) {
53394
- const packageJsonPath = (0, import_node_path25.join)((0, import_node_path25.resolve)(workspaceRoot ?? "."), "package.json");
53395
- const generated = results.find((r) => (0, import_node_path25.resolve)(r.targetPath) === packageJsonPath);
53538
+ const packageJsonPath = (0, import_node_path24.join)((0, import_node_path24.resolve)(workspaceRoot ?? "."), "package.json");
53539
+ const generated = results.find((r) => (0, import_node_path24.resolve)(r.targetPath) === packageJsonPath);
53396
53540
  let raw;
53397
53541
  if (generated) {
53398
53542
  raw = generated.newContent;
53399
53543
  } else {
53400
53544
  try {
53401
- raw = (0, import_node_fs22.readFileSync)(packageJsonPath, "utf8");
53545
+ raw = (0, import_node_fs20.readFileSync)(packageJsonPath, "utf8");
53402
53546
  } catch {
53403
53547
  raw = null;
53404
53548
  }
@@ -53462,16 +53606,16 @@ function stripJsonComments(text3) {
53462
53606
  return out2.replace(/,(\s*[}\]])/g, "$1");
53463
53607
  }
53464
53608
  function resolveAliasPrefixes(results, workspaceRoot) {
53465
- const root = (0, import_node_path25.resolve)(workspaceRoot ?? ".");
53609
+ const root = (0, import_node_path24.resolve)(workspaceRoot ?? ".");
53466
53610
  for (const filename of ["tsconfig.json", "jsconfig.json"]) {
53467
- const configPath = (0, import_node_path25.join)(root, filename);
53468
- const generated = results.find((r) => (0, import_node_path25.resolve)(r.targetPath) === configPath);
53611
+ const configPath = (0, import_node_path24.join)(root, filename);
53612
+ const generated = results.find((r) => (0, import_node_path24.resolve)(r.targetPath) === configPath);
53469
53613
  let raw;
53470
53614
  if (generated) {
53471
53615
  raw = generated.newContent;
53472
53616
  } else {
53473
53617
  try {
53474
- raw = (0, import_node_fs22.readFileSync)(configPath, "utf8");
53618
+ raw = (0, import_node_fs20.readFileSync)(configPath, "utf8");
53475
53619
  } catch {
53476
53620
  raw = null;
53477
53621
  }
@@ -53832,13 +53976,13 @@ function describeUnsuppliedInputs(found) {
53832
53976
  }
53833
53977
 
53834
53978
  // src/unsuppliedInputsDisk.ts
53835
- var import_node_fs23 = require("node:fs");
53979
+ var import_node_fs21 = require("node:fs");
53836
53980
  var MAX_READ_BYTES = 1e6;
53837
53981
  function readCheckoutText(path) {
53838
53982
  try {
53839
- const info2 = (0, import_node_fs23.statSync)(path);
53983
+ const info2 = (0, import_node_fs21.statSync)(path);
53840
53984
  if (!info2.isFile() || info2.size > MAX_READ_BYTES) return null;
53841
- const bytes = (0, import_node_fs23.readFileSync)(path);
53985
+ const bytes = (0, import_node_fs21.readFileSync)(path);
53842
53986
  if (bytes.includes(0)) return null;
53843
53987
  return bytes.toString("utf8");
53844
53988
  } catch {
@@ -53868,7 +54012,7 @@ function describeVanishedTests(vanished) {
53868
54012
  }
53869
54013
 
53870
54014
  // src/verifyChange.ts
53871
- var import_node_path26 = require("node:path");
54015
+ var import_node_path25 = require("node:path");
53872
54016
 
53873
54017
  // src/packageUse.ts
53874
54018
  var import_node_child_process13 = require("node:child_process");
@@ -53896,7 +54040,7 @@ function packageImportedInWorkspace(pkg, root, cwd = process.cwd()) {
53896
54040
  }
53897
54041
 
53898
54042
  // src/verifyChange.ts
53899
- var import_node_fs24 = require("node:fs");
54043
+ var import_node_fs22 = require("node:fs");
53900
54044
  async function verifyChange(ctx, results, undoable) {
53901
54045
  const cwd = ctx.cwd ?? process.cwd();
53902
54046
  const now = ctx.now ?? Date.now;
@@ -53931,7 +54075,7 @@ async function verifyChange(ctx, results, undoable) {
53931
54075
  const depCheck = checkImportDependencies(results, readDeclaredDependencies(results, packet.workspaceRoot), resolveAliasPrefixes(results, packet.workspaceRoot), {
53932
54076
  originalOf: (path) => {
53933
54077
  try {
53934
- return (0, import_node_fs24.readFileSync)((0, import_node_path26.join)(cwd, path), "utf8");
54078
+ return (0, import_node_fs22.readFileSync)((0, import_node_path25.join)(cwd, path), "utf8");
53935
54079
  } catch (err2) {
53936
54080
  return err2.code === "ENOENT" ? "" : null;
53937
54081
  }
@@ -53991,7 +54135,7 @@ async function verifyChange(ctx, results, undoable) {
53991
54135
  flushedAt = now();
53992
54136
  if (undoable) {
53993
54137
  const report = findJUnitReport(cwd);
53994
- const ignore = report ? [(0, import_node_path26.relative)(cwd, report).split("\\").join("/")] : [];
54138
+ const ignore = report ? [(0, import_node_path25.relative)(cwd, report).split("\\").join("/")] : [];
53995
54139
  const flush = undoableFlush(cwd, results, flushCodegenResults, { ignore });
53996
54140
  undo = () => flush.undo();
53997
54141
  } else {
@@ -54104,7 +54248,8 @@ ${violations.join("\n")}`);
54104
54248
  }
54105
54249
 
54106
54250
  // src/run.ts
54107
- var import_node_fs29 = require("node:fs");
54251
+ var import_node_fs27 = require("node:fs");
54252
+ var import_node_path31 = require("node:path");
54108
54253
 
54109
54254
  // src/mapMode.ts
54110
54255
  var MAP_ENV = "QUIKPILOT_MAP";
@@ -54162,7 +54307,7 @@ function buildToolsV2Env(i3) {
54162
54307
  }
54163
54308
 
54164
54309
  // src/repoMap.ts
54165
- var import_node_path27 = require("node:path");
54310
+ var import_node_path26 = require("node:path");
54166
54311
  var MAP_BUDGET_TOKENS = 4e3;
54167
54312
  var MAX_FOLDERS = 200;
54168
54313
  var MAX_LANGUAGES = 12;
@@ -54204,7 +54349,7 @@ function guidanceFiles(i3, perFile2, total) {
54204
54349
  function languages2(listing) {
54205
54350
  const counts = /* @__PURE__ */ new Map();
54206
54351
  for (const p of listing) {
54207
- const ext = import_node_path27.posix.extname(p).toLowerCase();
54352
+ const ext = import_node_path26.posix.extname(p).toLowerCase();
54208
54353
  if (ext && ext.length <= 12) counts.set(ext, (counts.get(ext) ?? 0) + 1);
54209
54354
  }
54210
54355
  return [...counts.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, MAX_LANGUAGES).map(([ext, n]) => `${ext} ${n}`);
@@ -54220,7 +54365,7 @@ function testFacts(i3) {
54220
54365
  const depth = i3.writeRoot === "" ? 0 : i3.writeRoot.split("/").length;
54221
54366
  for (const t of tests) {
54222
54367
  const parts2 = t.split("/");
54223
- const folder = parts2.length > depth + 1 ? parts2.slice(0, depth + 1).join("/") : import_node_path27.posix.dirname(t);
54368
+ const folder = parts2.length > depth + 1 ? parts2.slice(0, depth + 1).join("/") : import_node_path26.posix.dirname(t);
54224
54369
  byFolder.set(folder, (byFolder.get(folder) ?? 0) + 1);
54225
54370
  }
54226
54371
  for (const [folder, n] of [...byFolder.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, 3)) {
@@ -54330,7 +54475,7 @@ function buildRepoMap(i3) {
54330
54475
  }
54331
54476
 
54332
54477
  // src/workspacePackages.ts
54333
- var import_node_path28 = require("node:path");
54478
+ var import_node_path27 = require("node:path");
54334
54479
  var MAX_READ_ROOTS = 8;
54335
54480
  function isObject2(x) {
54336
54481
  return typeof x === "object" && x !== null && !Array.isArray(x);
@@ -54392,8 +54537,8 @@ function workspacePackages(readText, packageJsonPaths) {
54392
54537
  const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => globMatcher(p.slice(1)));
54393
54538
  const out2 = [];
54394
54539
  for (const file of packageJsonPaths) {
54395
- if (import_node_path28.posix.basename(file) !== "package.json" || file === "package.json" || file.split("/").includes("node_modules")) continue;
54396
- const folder = import_node_path28.posix.dirname(file);
54540
+ if (import_node_path27.posix.basename(file) !== "package.json" || file === "package.json" || file.split("/").includes("node_modules")) continue;
54541
+ const folder = import_node_path27.posix.dirname(file);
54397
54542
  if (!include.some((re) => re.test(folder)) || exclude.some((re) => re.test(folder))) continue;
54398
54543
  const text3 = readText(file);
54399
54544
  const json = text3 === null ? null : parseJsonc(text3);
@@ -54707,27 +54852,27 @@ function applyPacketSwitches(fromPacket, env2 = process.env) {
54707
54852
  }
54708
54853
 
54709
54854
  // src/phase0.ts
54710
- var import_node_fs25 = require("node:fs");
54855
+ var import_node_fs23 = require("node:fs");
54711
54856
  function writePhase0Marker(runId) {
54712
- (0, import_node_fs25.mkdirSync)(".quikpilot", { recursive: true });
54713
- (0, import_node_fs25.appendFileSync)(".quikpilot/phase0-marker.txt", `QuikPilot Phase 0 skeleton marker for run ${runId}
54857
+ (0, import_node_fs23.mkdirSync)(".quikpilot", { recursive: true });
54858
+ (0, import_node_fs23.appendFileSync)(".quikpilot/phase0-marker.txt", `QuikPilot Phase 0 skeleton marker for run ${runId}
54714
54859
  `);
54715
54860
  }
54716
54861
 
54717
54862
  // src/failureArtifact.ts
54718
54863
  var import_node_child_process14 = require("node:child_process");
54719
- var import_node_fs26 = require("node:fs");
54720
- var import_node_path29 = require("node:path");
54864
+ var import_node_fs24 = require("node:fs");
54865
+ var import_node_path28 = require("node:path");
54721
54866
  var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
54722
54867
  var REPORT_COPY = "final-test-report.xml";
54723
54868
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
54724
54869
  var MAX_FILES = 200;
54725
- var RUNNER_VERSION = true ? "9.3.0-rc.89" : "dev";
54870
+ var RUNNER_VERSION = true ? "9.3.0-rc.90" : "dev";
54726
54871
  function safeDestination(base, repoPath) {
54727
- if (!repoPath || (0, import_node_path29.isAbsolute)(repoPath)) return null;
54728
- const destination = (0, import_node_path29.resolve)(base, repoPath);
54729
- const rel = (0, import_node_path29.relative)(base, destination);
54730
- if (!rel || rel.startsWith("..") || (0, import_node_path29.isAbsolute)(rel)) return null;
54872
+ if (!repoPath || (0, import_node_path28.isAbsolute)(repoPath)) return null;
54873
+ const destination = (0, import_node_path28.resolve)(base, repoPath);
54874
+ const rel = (0, import_node_path28.relative)(base, destination);
54875
+ if (!rel || rel.startsWith("..") || (0, import_node_path28.isAbsolute)(rel)) return null;
54731
54876
  return destination;
54732
54877
  }
54733
54878
  var BUNDLE_FILE = "quikpilot-change.bundle";
@@ -54737,7 +54882,7 @@ function keepCommitBundle(repo, folder, branch) {
54737
54882
  if (git4(["rev-parse", "--abbrev-ref", "HEAD"]) !== branch) return null;
54738
54883
  if (git4(["diff", "--name-only", "HEAD~1", "HEAD"]) === "") return null;
54739
54884
  const commit2 = git4(["rev-parse", "HEAD"]);
54740
- const file = (0, import_node_path29.join)(folder, BUNDLE_FILE);
54885
+ const file = (0, import_node_path28.join)(folder, BUNDLE_FILE);
54741
54886
  git4(["bundle", "create", file, "HEAD", "^HEAD~1"]);
54742
54887
  let verified = true;
54743
54888
  try {
@@ -54753,9 +54898,9 @@ function keepCommitBundle(repo, folder, branch) {
54753
54898
  function writeFailureArtifact(input) {
54754
54899
  if (input.results.length === 0) return { written: false };
54755
54900
  try {
54756
- const base = (0, import_node_path29.resolve)(input.cwd, FAILURE_ARTIFACT_DIR);
54757
- (0, import_node_fs26.rmSync)(base, { recursive: true, force: true });
54758
- (0, import_node_fs26.mkdirSync)(base, { recursive: true });
54901
+ const base = (0, import_node_path28.resolve)(input.cwd, FAILURE_ARTIFACT_DIR);
54902
+ (0, import_node_fs24.rmSync)(base, { recursive: true, force: true });
54903
+ (0, import_node_fs24.mkdirSync)(base, { recursive: true });
54759
54904
  const files = [];
54760
54905
  const skipped = [];
54761
54906
  for (const result of input.results) {
@@ -54764,8 +54909,8 @@ function writeFailureArtifact(input) {
54764
54909
  skipped.push(result.targetPath);
54765
54910
  continue;
54766
54911
  }
54767
- (0, import_node_fs26.mkdirSync)((0, import_node_path29.dirname)(destination), { recursive: true });
54768
- (0, import_node_fs26.writeFileSync)(destination, result.newContent);
54912
+ (0, import_node_fs24.mkdirSync)((0, import_node_path28.dirname)(destination), { recursive: true });
54913
+ (0, import_node_fs24.writeFileSync)(destination, result.newContent);
54769
54914
  files.push({ path: result.targetPath, bytes: Buffer.byteLength(result.newContent) });
54770
54915
  }
54771
54916
  let testReport = "none";
@@ -54773,7 +54918,7 @@ function writeFailureArtifact(input) {
54773
54918
  if (input.testReport.byteLength > MAX_REPORT_BYTES) {
54774
54919
  testReport = "too-large";
54775
54920
  } else {
54776
- (0, import_node_fs26.writeFileSync)((0, import_node_path29.join)(base, REPORT_COPY), input.testReport);
54921
+ (0, import_node_fs24.writeFileSync)((0, import_node_path28.join)(base, REPORT_COPY), input.testReport);
54777
54922
  testReport = "included";
54778
54923
  }
54779
54924
  }
@@ -54795,8 +54940,8 @@ function writeFailureArtifact(input) {
54795
54940
  bundle
54796
54941
  };
54797
54942
  const text3 = JSON.stringify(manifest, (_key, value) => typeof value === "string" ? scrubSecrets(value, input.secrets) : value, 2);
54798
- (0, import_node_fs26.writeFileSync)((0, import_node_path29.join)(base, "manifest.json"), text3);
54799
- return { written: (0, import_node_fs26.existsSync)((0, import_node_path29.join)(base, "manifest.json")) };
54943
+ (0, import_node_fs24.writeFileSync)((0, import_node_path28.join)(base, "manifest.json"), text3);
54944
+ return { written: (0, import_node_fs24.existsSync)((0, import_node_path28.join)(base, "manifest.json")) };
54800
54945
  } catch (err2) {
54801
54946
  console.warn(`::warning::Could not keep the failed run's files: ${err2 instanceof Error ? err2.message : String(err2)}`);
54802
54947
  return { written: false };
@@ -54805,8 +54950,8 @@ function writeFailureArtifact(input) {
54805
54950
 
54806
54951
  // src/finalChange.ts
54807
54952
  var import_node_child_process15 = require("node:child_process");
54808
- var import_node_fs27 = require("node:fs");
54809
- var import_node_path30 = require("node:path");
54953
+ var import_node_fs25 = require("node:fs");
54954
+ var import_node_path29 = require("node:path");
54810
54955
  function statusPaths(root) {
54811
54956
  const status = (0, import_node_child_process15.execFileSync)("git", [...NO_HOOKS_ARGS, "status", "--porcelain", "-z", "--untracked-files=all", "--no-renames"], {
54812
54957
  env: gitEnv(),
@@ -54820,7 +54965,7 @@ function statusPaths(root) {
54820
54965
  }
54821
54966
  var isFileOnDisk = (root, path) => {
54822
54967
  try {
54823
- return (0, import_node_fs27.statSync)((0, import_node_path30.join)(root, path)).isFile();
54968
+ return (0, import_node_fs25.statSync)((0, import_node_path29.join)(root, path)).isFile();
54824
54969
  } catch {
54825
54970
  return false;
54826
54971
  }
@@ -54841,8 +54986,8 @@ function allChangesAgainstBase(root) {
54841
54986
 
54842
54987
  // src/nameEvidence.ts
54843
54988
  var import_node_child_process16 = require("node:child_process");
54844
- var import_node_fs28 = require("node:fs");
54845
- var import_node_path31 = require("node:path");
54989
+ var import_node_fs26 = require("node:fs");
54990
+ var import_node_path30 = require("node:path");
54846
54991
 
54847
54992
  // src/migrationNames.ts
54848
54993
  var PART = String.raw`(?:"[^"]+"|\x60[^\x60]+\x60|\[[^\]]+\]|[\w$]+)`;
@@ -54922,9 +55067,9 @@ function filesNaming(word, ev, readable, denied) {
54922
55067
  }
54923
55068
  function fileHasWord(cwd, file, word) {
54924
55069
  try {
54925
- const path = (0, import_node_path31.join)(cwd, file);
54926
- if ((0, import_node_fs28.statSync)(path).size > MAX_FILE_BYTES2) return false;
54927
- return new RegExp(`(?<![\\w$])${escapeRegExp5(word)}(?![\\w$])`).test((0, import_node_fs28.readFileSync)(path, "utf8"));
55070
+ const path = (0, import_node_path30.join)(cwd, file);
55071
+ if ((0, import_node_fs26.statSync)(path).size > MAX_FILE_BYTES2) return false;
55072
+ return new RegExp(`(?<![\\w$])${escapeRegExp5(word)}(?![\\w$])`).test((0, import_node_fs26.readFileSync)(path, "utf8"));
54928
55073
  } catch {
54929
55074
  return false;
54930
55075
  }
@@ -54953,24 +55098,24 @@ var slashes = (p) => p.replace(/\\/g, "/");
54953
55098
  var withoutDotSlash = (p) => p.replace(/^(\.\/)+/, "");
54954
55099
  function relativeToRepository(raw, cwd) {
54955
55100
  const path = withoutDotSlash(slashes(raw.trim()));
54956
- let relative12 = path;
55101
+ let relative14 = path;
54957
55102
  if (path.startsWith("/") || DRIVE_RE.test(path)) {
54958
55103
  const root = slashes(cwd).replace(/\/+$/, "");
54959
55104
  const windows = DRIVE_RE.test(path) || DRIVE_RE.test(root);
54960
55105
  const a = windows ? path.toLowerCase() : path;
54961
55106
  const b = windows ? root.toLowerCase() : root;
54962
55107
  if (!a.startsWith(`${b}/`)) return null;
54963
- relative12 = path.slice(root.length + 1);
55108
+ relative14 = path.slice(root.length + 1);
54964
55109
  }
54965
- return relative12;
55110
+ return relative14;
54966
55111
  }
54967
55112
  function inListing(raw, listing, cwd, workspaceRoot) {
54968
- const relative12 = relativeToRepository(raw, cwd);
54969
- if (relative12 === null) return null;
54970
- if (listing.has(relative12)) return relative12;
55113
+ const relative14 = relativeToRepository(raw, cwd);
55114
+ if (relative14 === null) return null;
55115
+ if (listing.has(relative14)) return relative14;
54971
55116
  if (workspaceRoot) {
54972
55117
  const root = slashes(workspaceRoot).replace(/\/+$/, "");
54973
- const joined = `${root}/${relative12}`;
55118
+ const joined = `${root}/${relative14}`;
54974
55119
  if (listing.has(joined)) return joined;
54975
55120
  }
54976
55121
  return null;
@@ -55111,8 +55256,8 @@ async function resolveTestDiscovery(i3) {
55111
55256
  };
55112
55257
  if (!i3.command || i3.command.trim().length === 0) return done(buildTestDiscovery({ ...base, snapshot: null }));
55113
55258
  let timer;
55114
- const timeout = new Promise((resolve6) => {
55115
- timer = setTimeout(() => resolve6("timeout"), i3.waitMs);
55259
+ const timeout = new Promise((resolve7) => {
55260
+ timer = setTimeout(() => resolve7("timeout"), i3.waitMs);
55116
55261
  });
55117
55262
  const settled = i3.baseline.then(
55118
55263
  (b) => b.snapshot,
@@ -55260,11 +55405,13 @@ function finalizeTargeting(body2, workspaceRoot, workspaceListing, deniedPaths)
55260
55405
  }
55261
55406
  const correctedKinds = [];
55262
55407
  const targets = body2.targets.map((target) => {
55263
- if (target.kind === "NEW_FILE" && listing.has(target.path)) {
55264
- correctedKinds.push(target.path);
55265
- return { ...target, kind: "EXISTING" };
55408
+ if (target.kind !== "NEW_FILE") return target;
55409
+ const path = canonicalPath(target.path) ?? target.path;
55410
+ if (listing.has(path)) {
55411
+ correctedKinds.push(path);
55412
+ return { ...target, path, kind: "EXISTING" };
55266
55413
  }
55267
- return target;
55414
+ return path === target.path ? target : { ...target, path };
55268
55415
  });
55269
55416
  return {
55270
55417
  outcome: "TARGETED",
@@ -55683,11 +55830,13 @@ async function runUnderGuard(env2, guard) {
55683
55830
  let runToken;
55684
55831
  const warnings = [];
55685
55832
  let scopeRoot = "";
55833
+ let installationToken;
55834
+ const secrets = () => [runToken, packet?.gateway?.token, installationToken].filter((s) => typeof s === "string" && s.length > 0);
55686
55835
  const failureReasons = [];
55687
55836
  const recordFailure = (err2) => {
55688
55837
  const message = err2 instanceof Error ? err2.message : String(err2);
55689
55838
  console.error(message);
55690
- const reason = describeFailureReason(failureSummary(err2), runToken ? [runToken] : []);
55839
+ const reason = describeFailureReason(failureSummary(err2), secrets());
55691
55840
  if (reason) failureReasons.push(reason);
55692
55841
  };
55693
55842
  let targeted = false;
@@ -55708,6 +55857,9 @@ async function runUnderGuard(env2, guard) {
55708
55857
  const contextLog = [];
55709
55858
  const codegenOut = {};
55710
55859
  let pendingBaseline;
55860
+ const baselineStop = new AbortController();
55861
+ let baselineDone = false;
55862
+ let baselineStopped = false;
55711
55863
  const baselineSettled = async () => {
55712
55864
  try {
55713
55865
  await pendingBaseline;
@@ -55752,7 +55904,7 @@ async function runUnderGuard(env2, guard) {
55752
55904
  } catch {
55753
55905
  body2 = { status: "failed", unresolved: [message], ...branch ? { branch } : {} };
55754
55906
  }
55755
- await reportBack({ callbackUrl: env2.callbackUrl, runToken, ...body2, urgent: true });
55907
+ await reportBack({ callbackUrl: env2.callbackUrl, runToken, ...body2, urgent: true, secrets: secrets() });
55756
55908
  };
55757
55909
  try {
55758
55910
  runToken = await exchangeForRunToken(env2.tokenUrl, await fetchGithubOidcToken());
@@ -55770,7 +55922,7 @@ async function runUnderGuard(env2, guard) {
55770
55922
  await preloadLanguages(workspaceListing);
55771
55923
  const readCheckoutText2 = (path) => {
55772
55924
  try {
55773
- return (0, import_node_fs29.readFileSync)(path, "utf8");
55925
+ return (0, import_node_fs27.readFileSync)(path, "utf8");
55774
55926
  } catch {
55775
55927
  return null;
55776
55928
  }
@@ -55811,7 +55963,8 @@ async function runUnderGuard(env2, guard) {
55811
55963
  if (packet.commands.setup) console.log(JSON.stringify({ event: "timing", phase: "setup", seconds: Math.round((Date.now() - setupStartedAt) / 1e3) }));
55812
55964
  const baselineStartedAt = Date.now();
55813
55965
  const baselineLimit = testLimitsOff() ? null : baselineLimitMs(jobStopAtMs - baselineStartedAt);
55814
- const baselineRun = (baselineLimit === null ? captureBaselineSnapshot(packet.commands.test) : captureBaselineSnapshot(packet.commands.test, process.cwd(), { limitMs: baselineLimit })).then((snapshot) => {
55966
+ const baselineRun = (baselineLimit === null ? captureBaselineSnapshot(packet.commands.test, process.cwd(), { signal: baselineStop.signal }) : captureBaselineSnapshot(packet.commands.test, process.cwd(), { limitMs: baselineLimit, signal: baselineStop.signal })).then((snapshot) => {
55967
+ baselineDone = true;
55815
55968
  baselineDurationMs = Date.now() - baselineStartedAt;
55816
55969
  return { snapshot, durationMs: baselineDurationMs };
55817
55970
  });
@@ -55829,7 +55982,7 @@ async function runUnderGuard(env2, guard) {
55829
55982
  // QUIKTR-2465 item 3: Go's tests are placed by the file that declares them (and go.mod's module). Listing paths are relative to the checkout.
55830
55983
  readText: (p) => {
55831
55984
  try {
55832
- return (0, import_node_fs29.readFileSync)(p, "utf8");
55985
+ return (0, import_node_fs27.readFileSync)(p, "utf8");
55833
55986
  } catch {
55834
55987
  return null;
55835
55988
  }
@@ -55915,7 +56068,7 @@ async function runUnderGuard(env2, guard) {
55915
56068
  );
55916
56069
  }
55917
56070
  const codegenMode = mapMode ? "loop-tests" : resolveCodegenMode(process.env, packet.codegenMode);
55918
- const noteTaken = workspaceListing.includes(DATABASE_CHANGE_PATH) || scope.readListing.includes(DATABASE_CHANGE_PATH) || (0, import_node_fs29.existsSync)(DATABASE_CHANGE_PATH);
56071
+ const noteTaken = workspaceListing.includes(DATABASE_CHANGE_PATH) || scope.readListing.includes(DATABASE_CHANGE_PATH) || (0, import_node_fs27.existsSync)(DATABASE_CHANGE_PATH);
55919
56072
  const proposals = designParts.length > 0 && codegenMode === "loop-tests" && !noteTaken;
55920
56073
  if (designParts.some((p) => p.kind === "stored") && codegenMode === "loop-tests" && noteTaken) console.log(JSON.stringify({ event: "database_change.off", reason: "note_path_taken" }));
55921
56074
  if (designParts.length > 0) {
@@ -56135,6 +56288,19 @@ async function runUnderGuard(env2, guard) {
56135
56288
  jobStopAtMs,
56136
56289
  lastAttemptMs,
56137
56290
  verify: (r, undoable) => verifyChange(verifyCtx, r, undoable),
56291
+ // QUIKTR-2708 (RN-10): a review fix that does not pass puts the passed change back as it was after its checks (Format included),
56292
+ // through the same undoable flush the checks use, instead of running the checks on it again.
56293
+ snapshotPassed: (passed) => {
56294
+ const cwd = process.cwd();
56295
+ const onDisk = passed.map((r) => ({ targetPath: r.targetPath, newContent: readCheckoutText2(r.targetPath) ?? r.newContent }));
56296
+ return {
56297
+ putBack: () => {
56298
+ const report = findJUnitReport(cwd);
56299
+ const ignore = report ? [(0, import_node_path31.relative)(cwd, report).split("\\").join("/")] : [];
56300
+ return undoableFlush(cwd, onDisk, flushCodegenResults, { ignore }).undo;
56301
+ }
56302
+ };
56303
+ },
56138
56304
  ...reviewOn ? {
56139
56305
  review: async (changed, outcome) => {
56140
56306
  const testCount = outcome.outputs.testCount ?? 0;
@@ -56275,6 +56441,11 @@ async function runUnderGuard(env2, guard) {
56275
56441
  } else {
56276
56442
  hardFailure = true;
56277
56443
  recordFailure(err2);
56444
+ if (pendingBaseline && !baselineDone) {
56445
+ baselineStopped = true;
56446
+ baselineStop.abort();
56447
+ console.log(JSON.stringify({ event: "baseline.stopped", reason: "run_failed" }));
56448
+ }
56278
56449
  }
56279
56450
  }
56280
56451
  if (!runToken) {
@@ -56282,7 +56453,7 @@ async function runUnderGuard(env2, guard) {
56282
56453
  return { hardFailure: true };
56283
56454
  }
56284
56455
  await baselineSettled();
56285
- const quikTestReport = conflictStop ? null : await reportToQuikTest({
56456
+ const quikTestReport = conflictStop || baselineStopped ? null : await reportToQuikTest({
56286
56457
  resultsUrl: packet?.quikTest?.resultsUrl,
56287
56458
  runToken,
56288
56459
  githubServerUrl: env2.githubServerUrl,
@@ -56300,11 +56471,11 @@ async function runUnderGuard(env2, guard) {
56300
56471
  }
56301
56472
  if (conflictStop && packet) {
56302
56473
  try {
56303
- const installationToken = await exchangeForInstallationToken(env2.installationTokenUrl, runToken);
56474
+ installationToken = await exchangeForInstallationToken(env2.installationTokenUrl, runToken);
56304
56475
  const proposalBranch = proposalBranchName(packet.issueKey, env2.githubRunId);
56305
56476
  const proposal = createProposalCommit({ conflicts: conflictStop.conflicts, branch: proposalBranch, issueKey: packet.issueKey });
56306
56477
  if (!proposal) throw new Error("None of the changes reported for existing tests could be put together into a proposal.");
56307
- pushProposal(proposalBranch, installationToken);
56478
+ await pushProposal(proposalBranch, installationToken);
56308
56479
  testConflicts = conflictsReport(proposal);
56309
56480
  console.log(JSON.stringify({ event: "conflicts.proposal_pushed", tests: proposal.lines.length, dropped: proposal.dropped.length }));
56310
56481
  } catch (err2) {
@@ -56323,11 +56494,11 @@ async function runUnderGuard(env2, guard) {
56323
56494
  warnings.push(deletionsLeftOutNote(guarded.deletionsLeftOut));
56324
56495
  console.log(JSON.stringify({ event: "commit.deletions_left_out", count: guarded.deletionsLeftOut.count }));
56325
56496
  }
56326
- const installationToken = await exchangeForInstallationToken(
56497
+ installationToken = await exchangeForInstallationToken(
56327
56498
  env2.installationTokenUrl,
56328
56499
  runToken
56329
56500
  );
56330
- const result = commitAndPush(
56501
+ const result = await commitAndPush(
56331
56502
  packet.branch,
56332
56503
  env2.runId,
56333
56504
  installationToken,
@@ -56352,14 +56523,14 @@ async function runUnderGuard(env2, guard) {
56352
56523
  testReport: finalTestReport,
56353
56524
  failureReasons,
56354
56525
  commitBranch: packet?.branch ?? null,
56355
- secrets: runToken ? [runToken] : []
56526
+ secrets: secrets()
56356
56527
  });
56357
56528
  } catch (err2) {
56358
56529
  console.warn(`::warning::Could not keep the failed run's files: ${err2 instanceof Error ? err2.message : String(err2)}`);
56359
56530
  }
56360
56531
  }
56361
56532
  if (!guard.claim()) return { hardFailure: true };
56362
- await reportBack({ callbackUrl: env2.callbackUrl, runToken, ...finalReportBody() });
56533
+ await reportBack({ callbackUrl: env2.callbackUrl, runToken, ...finalReportBody(), secrets: secrets() });
56363
56534
  return { hardFailure };
56364
56535
  }
56365
56536
 
@@ -56871,7 +57042,7 @@ var InvestigationReportError = class extends Error {
56871
57042
  status;
56872
57043
  networkCode;
56873
57044
  };
56874
- async function reportInvestigation(callbackUrl, runToken, body2, sleep = (ms) => new Promise((resolve6) => setTimeout(resolve6, ms))) {
57045
+ async function reportInvestigation(callbackUrl, runToken, body2, sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms))) {
56875
57046
  const payload = JSON.stringify(body2);
56876
57047
  const tries = INVESTIGATION_REPORT_RETRY_WAITS_MS.length + 1;
56877
57048
  for (let attempt2 = 1; ; attempt2++) {