@quikit/quikpilot-runner 9.3.0-rc.16 → 9.3.0-rc.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -150,6 +150,10 @@ it, the callback carries it as `unsuppliedInputs` (at most 10 functions, 5 names
150
150
  noticed" as a check. This is the shape of a change whose new tests pass only because they hand the function the field themselves. It can be
151
151
  wrong (a field that arrives from a database row or a request), so it only warns and never blocks. TypeScript is not covered (QUIKTR-1547).
152
152
 
153
+ **9.3.0-rc.18 — an honest "I cannot finish" no longer throws away a change that is one fix away (QUIKSPL-139).** The AI wrote the fix and its tests, ran the project's tests until its runs were used (4 failing, then 3, then 3) and answered `CANNOT_COMPLETE`; the whole change was thrown away and a second attempt started from nothing, which did worse. Had it said `DONE`, every check would have run and the fix step (QUIKTR-1527) would have continued from the same change. Now a give-up is KEPT when the change would have passed as a `DONE` (something changed, every required test case written, no file cut short or broken) and the AI's LAST test run came back with failing tests that are the change's doing. It is recorded as attempt 1 `kept`, goes through every check like any result, and when only the tests fail the existing fix continues from it (three attempts in all, so at most two fixes). Only in `loop-tests` mode with fixing on (the project's setting above 0); a fix attempt that gives up is not kept again; time-outs, network errors and every other ending behave as before. `QUIKPILOT_KEEP_ON_GIVE_UP=off` restores the clean second attempt without a new release. Nothing new goes to the AI service.
154
+
155
+ **9.3.0-rc.17 — the list of files that hold tests is read from this run's own test run (QUIKTR-1526).** Before the AI picks files, the AI service is given the files the project's test runner discovers and refuses an answer that puts test cases on any other existing file. That list used to come from the last merged QuikPilot run, so a test file added by hand since then was unknown and an honest answer about it was refused (QUIKSPL-140 died at targeting). Now `Setup` and the baseline test run come BEFORE targeting, and the list is built from that run's own report: the files it attributes tests to, put in the form of the file list and kept only if they are in it (the AI service rejects the whole request otherwise); each file that cannot be placed, and each test the report names without a file (a Java class name, a Jest describe title), is counted in `unmappedEntries`, which switches the refusal off. Doubt turns the check off, never on: no test command, no report, a report with no tests, or a wait that ran out sends `ABSENT`. Targeting waits for the baseline at most 90 seconds (`QUIKPILOT_DISCOVERY_WAIT_SECONDS`); past that the run says so in its notes and the baseline carries on beside the code-writing step exactly as before (it is started once). The list QuikProjects stores is no longer used by this runner. The log gets one `test_discovery` line with counts only. No change in the AI service or in QuikProjects.
156
+
153
157
  **9.3.0-rc.16 — changes no test depends on are named (QUIKTR-1569).** A green test run only proves what the tests check (QUIKSPL-138: the pagination fix also rewrote the neighbouring `hasMore` line, wrongly, and all 75 tests stayed green). In `loop-tests` mode, after a change has passed every check, each changed block of an existing code file that is not a test is put back as it was, ON ITS OWN, and the project's tests run once more (a block that looks unneeded is run a second time before it is flagged). A block with every test still passing is reported under "What QuikPilot noticed" as a file and line numbers only, never the code: it is a statement about the tests, not about the code, since a block can be right and untested. It warns and never blocks. A run that times out, leaves no report or a stale one counts as unknown and is never flagged; a block put back that makes tests vanish counts as needed; at most 8 blocks are checked, for at most 6 minutes and never in the last 2 minutes before the job's stop; a suite too slow to run again, or a project with no readable baseline, is skipped. Files the run created, tests, documents and configuration are not looked at. The checkout and the final test report are put back after every run; a checkout that does not come back ends the run, as for `run_tests`. Switch it off with `QUIKPILOT_HUNK_CHECK=off`. An older QuikProjects ignores the new field.
154
158
 
155
159
  **9.3.0-rc.15 — QuikPilot fixes its own change when the project's final tests fail (QUIKTR-1527).** In `loop-tests` mode, when the final comparison of the project's tests finds tests that passed before and fail now (or new tests that fail), the run no longer ends Failed at once. It takes the checkout back, starts another attempt FROM the change it just wrote (kept in memory), tells the AI which tests failed (names, and for tests it wrote itself the first line of the error: exactly what `run_tests` shows it), and then runs EVERY check again from scratch (dependencies, scope, placement, format, lint, the project's tests, coverage). At most three attempts at writing the change per run in all (an ordinary retry counts as one); `maxHealIterations` (the project's "fix attempts" setting) can lower it, and 0 turns fixing off. A fix is made only for a failing test comparison (never for lint, scope, dependency, placement or coverage), never after the same tests fail the same way twice in a row, and only if the time left fits it (the job limit less seven minutes for pushing and reporting). Nothing is pushed unless the final code passes every check; an existing test is never edited to make code pass. A run that still fails ends Failed as before, with "; QuikPilot tried to fix it N times (stopped: …)" added to the reason, and the run's record gains the fix attempts and a stop word. Needs the AI service with contract 24.12d (otherwise the fix is refused and the run fails exactly as before). Other modes and a run whose tests pass are unchanged.
package/dist/index.js CHANGED
@@ -12464,6 +12464,14 @@ async function reportToQuikTest(params) {
12464
12464
 
12465
12465
  // src/regressionCheck.ts
12466
12466
  var import_node_fs8 = require("node:fs");
12467
+
12468
+ // src/pathShape.ts
12469
+ var PATH_EXTENSION_RE = /\.(ts|tsx|js|jsx|mjs|cjs|py|rb|go)$/i;
12470
+ function looksLikeFilePath(value) {
12471
+ return value.includes("/") || PATH_EXTENSION_RE.test(value);
12472
+ }
12473
+
12474
+ // src/regressionCheck.ts
12467
12475
  var TESTCASE_RE = /<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g;
12468
12476
  var NAME_ATTR_RE = /\bname="([^"]*)"/;
12469
12477
  var CLASSNAME_ATTR_RE = /\bclassname="([^"]*)"/;
@@ -12510,6 +12518,7 @@ function parseJUnitOutcomes(xml) {
12510
12518
  const failureText = /* @__PURE__ */ new Map();
12511
12519
  const discoveredFiles = /* @__PURE__ */ new Set();
12512
12520
  const discoveredAutomationIds = /* @__PURE__ */ new Set();
12521
+ let unmappedEntries = 0;
12513
12522
  TESTSUITE_OPEN_RE.lastIndex = 0;
12514
12523
  let suiteMatch;
12515
12524
  while (suiteMatch = TESTSUITE_OPEN_RE.exec(xml)) {
@@ -12535,6 +12544,7 @@ function parseJUnitOutcomes(xml) {
12535
12544
  const file = FILE_ATTR_RE.exec(attrs)?.[1];
12536
12545
  if (file) discoveredFiles.add(normalizeSlashes(file));
12537
12546
  if (classname) discoveredFiles.add(normalizeSlashes(classname));
12547
+ if (!file?.trim() && !(classname && looksLikeFilePath(classname.trim()))) unmappedEntries += 1;
12538
12548
  const bracket = QP_TOKEN_BRACKET_RE.exec(name)?.[1];
12539
12549
  if (bracket) {
12540
12550
  discoveredAutomationIds.add(bracket);
@@ -12543,7 +12553,7 @@ function parseJUnitOutcomes(xml) {
12543
12553
  if (!seen || RESULT_RANK[result] > RESULT_RANK[seen]) automationIdResults.set(bracket, result);
12544
12554
  }
12545
12555
  }
12546
- return { outcomes, automationIdResults, failureText, discoveredFiles, discoveredAutomationIds };
12556
+ return { outcomes, automationIdResults, failureText, discoveredFiles, discoveredAutomationIds, unmappedEntries };
12547
12557
  }
12548
12558
  function readJUnitOutcomes(cwd) {
12549
12559
  const report = findJUnitReport(cwd);
@@ -12565,7 +12575,8 @@ function captureTestSnapshot(command, cwd = process.cwd()) {
12565
12575
  results: parsed?.outcomes ?? null,
12566
12576
  failureText: parsed?.failureText,
12567
12577
  discoveredFiles: parsed?.discoveredFiles ?? null,
12568
- discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null
12578
+ discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
12579
+ unmappedEntries: parsed?.unmappedEntries
12569
12580
  };
12570
12581
  }
12571
12582
  function readTestSnapshot(outcome, cwd = process.cwd()) {
@@ -12575,7 +12586,8 @@ function readTestSnapshot(outcome, cwd = process.cwd()) {
12575
12586
  results: parsed?.outcomes ?? null,
12576
12587
  failureText: parsed?.failureText,
12577
12588
  discoveredFiles: parsed?.discoveredFiles ?? null,
12578
- discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null
12589
+ discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
12590
+ unmappedEntries: parsed?.unmappedEntries
12579
12591
  };
12580
12592
  }
12581
12593
  async function captureBaselineSnapshot(command, cwd = process.cwd()) {
@@ -12586,7 +12598,8 @@ async function captureBaselineSnapshot(command, cwd = process.cwd()) {
12586
12598
  results: parsed?.outcomes ?? null,
12587
12599
  failureText: parsed?.failureText,
12588
12600
  discoveredFiles: parsed?.discoveredFiles ?? null,
12589
- discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null
12601
+ discoveredAutomationIds: parsed?.discoveredAutomationIds ?? null,
12602
+ unmappedEntries: parsed?.unmappedEntries
12590
12603
  };
12591
12604
  }
12592
12605
  function checkForRegressions(baseline, after) {
@@ -13380,6 +13393,36 @@ async function runCodegenLoop(args, deps) {
13380
13393
  if (!fits) throw new CodegenLoopFailure("token_ceiling");
13381
13394
  return reason;
13382
13395
  };
13396
+ const handOverRefusal = (turn, quiet) => {
13397
+ const changed = overlay.changedPaths();
13398
+ if (changed.length === 0 || changed.length === seededText.size && changed.every((p) => seededText.get(p) === overlay.get(p)?.lf)) {
13399
+ return new CodegenLoopFailure("no_writes");
13400
+ }
13401
+ const texts = changed.map((p) => overlay.get(p)?.lf ?? "");
13402
+ const missing = args.requiredAutomationIds.filter((id) => !texts.some((t) => t.includes(`[${id}]`)));
13403
+ if (missing.length > 0) {
13404
+ if (!quiet) log({ event: "codegen.loop_refused", turn, reason: "coverage_missing", missing: missing.length });
13405
+ return new CodegenLoopFailure("coverage_missing", void 0, void 0, `${missing.length} required test case(s) not written`, coverageSentence(missing));
13406
+ }
13407
+ const planSteps = args.targets.flatMap((t) => t.planStepsImplemented);
13408
+ for (const path of changed) {
13409
+ const entry = overlay.get(path);
13410
+ if (!entry || entry.created || entry.originalLf === null) continue;
13411
+ const pseudo = { path, kind: "EXISTING", planStepsImplemented: planSteps };
13412
+ const suspect = looksLikeTruncatedRewrite(pseudo, entry.originalLf, entry.lf);
13413
+ if (suspect) {
13414
+ if (!quiet) log({ event: "codegen.loop_refused", turn, reason: "truncation_guard", path });
13415
+ return new CodegenLoopFailure("truncation_guard", void 0, void 0, `${path}: ${suspect}`, truncationSentence(path, suspect));
13416
+ }
13417
+ }
13418
+ const broken = ws.syntaxProblems()[0];
13419
+ if (broken) {
13420
+ if (!quiet) log({ event: "codegen.loop_refused", turn, reason: "syntax_error", path: broken.path, kind: broken.problem.kind, line: broken.problem.line });
13421
+ const sentence = `${broken.path}: ${describeSyntaxProblem(broken.problem)}`;
13422
+ return new CodegenLoopFailure("syntax_error", void 0, void 0, sentence, sentence.slice(0, MAX_PREVIOUS_DETAIL_CHARS));
13423
+ }
13424
+ return null;
13425
+ };
13383
13426
  log({ event: "codegen.loop_start", maxTurns: limits.maxTurns, maxToolCalls: limits.maxToolCalls, listingFiles: args.listing.length });
13384
13427
  try {
13385
13428
  for (let turn = 1; turn <= limits.maxTurns; turn++) {
@@ -13443,37 +13486,17 @@ async function runCodegenLoop(args, deps) {
13443
13486
  if (body.outcome === "CANNOT_COMPLETE") {
13444
13487
  log({ event: "codegen.loop_turn", turn, outcome: "cannot_complete", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
13445
13488
  const said = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : void 0;
13489
+ const last = lastTestAnswer;
13490
+ if (args.keepOnGiveUp === true && last !== void 0 && last.regressions + last.newFailures > 0 && handOverRefusal(turn, true) === null) {
13491
+ log({ event: "codegen.loop_kept", files: overlay.changedPaths().length, regressions: last.regressions, newFailures: last.newFailures });
13492
+ return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary: said ?? "", gaveUp: true };
13493
+ }
13446
13494
  throw new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said);
13447
13495
  }
13448
13496
  if (body.outcome === "DONE") {
13449
13497
  log({ event: "codegen.loop_turn", turn, outcome: "done", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
13450
- const changed = overlay.changedPaths();
13451
- if (changed.length === 0 || changed.length === seededText.size && changed.every((p) => seededText.get(p) === overlay.get(p)?.lf)) {
13452
- throw new CodegenLoopFailure("no_writes");
13453
- }
13454
- const texts = changed.map((p) => overlay.get(p)?.lf ?? "");
13455
- const missing = args.requiredAutomationIds.filter((id) => !texts.some((t) => t.includes(`[${id}]`)));
13456
- if (missing.length > 0) {
13457
- log({ event: "codegen.loop_refused", turn, reason: "coverage_missing", missing: missing.length });
13458
- throw new CodegenLoopFailure("coverage_missing", void 0, void 0, `${missing.length} required test case(s) not written`, coverageSentence(missing));
13459
- }
13460
- const planSteps = args.targets.flatMap((t) => t.planStepsImplemented);
13461
- for (const path of changed) {
13462
- const entry = overlay.get(path);
13463
- if (!entry || entry.created || entry.originalLf === null) continue;
13464
- const pseudo = { path, kind: "EXISTING", planStepsImplemented: planSteps };
13465
- const suspect = looksLikeTruncatedRewrite(pseudo, entry.originalLf, entry.lf);
13466
- if (suspect) {
13467
- log({ event: "codegen.loop_refused", turn, reason: "truncation_guard", path });
13468
- throw new CodegenLoopFailure("truncation_guard", void 0, void 0, `${path}: ${suspect}`, truncationSentence(path, suspect));
13469
- }
13470
- }
13471
- const broken = ws.syntaxProblems()[0];
13472
- if (broken) {
13473
- log({ event: "codegen.loop_refused", turn, reason: "syntax_error", path: broken.path, kind: broken.problem.kind, line: broken.problem.line });
13474
- const sentence = `${broken.path}: ${describeSyntaxProblem(broken.problem)}`;
13475
- throw new CodegenLoopFailure("syntax_error", void 0, void 0, sentence, sentence.slice(0, MAX_PREVIOUS_DETAIL_CHARS));
13476
- }
13498
+ const refusal = handOverRefusal(turn, false);
13499
+ if (refusal) throw refusal;
13477
13500
  const stopReason = isFinal ? `forced_${finalReason}` : "model_done";
13478
13501
  const doneSummary = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : "";
13479
13502
  log({ event: "codegen.loop_done", turns, toolCalls: ledger.toolCalls, edits: ws.edits.size, created: ws.created.size, stopReason });
@@ -13570,10 +13593,10 @@ async function postCodegenTurn(gateway, contextData, signal) {
13570
13593
  return res.json();
13571
13594
  }
13572
13595
  function protectedTestFiles(listing, testDiscovery) {
13573
- const inListing = new Set(listing);
13596
+ const inListing2 = new Set(listing);
13574
13597
  const found = new Set(listing.filter((p) => isTestTarget(p)));
13575
13598
  if (testDiscovery.report === "PRESENT") {
13576
- for (const p of testDiscovery.discoveredTestFiles) if (inListing.has(p)) found.add(p);
13599
+ for (const p of testDiscovery.discoveredTestFiles) if (inListing2.has(p)) found.add(p);
13577
13600
  }
13578
13601
  return [...found].sort();
13579
13602
  }
@@ -13613,7 +13636,8 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({ targets: p.targe
13613
13636
  protectedTestPaths,
13614
13637
  // The files already shown are evidence for the parse check that the project parses (`syntaxCheck.ts`).
13615
13638
  syntaxSeed: context.entries.map((e) => ({ path: e.path, text: e.content })),
13616
- ...p.mode === "loop-tests" && p.tests ? { tests: p.tests } : {}
13639
+ ...p.mode === "loop-tests" && p.tests ? { tests: p.tests } : {},
13640
+ ...p.mode === "loop-tests" && p.tests && p.keepOnGiveUp ? { keepOnGiveUp: true } : {}
13617
13641
  };
13618
13642
  }
13619
13643
  var NO_SUMMARY = {
@@ -13650,6 +13674,10 @@ async function oneTestRunMs(tests) {
13650
13674
  const limit = testTimeLimitMs(timed?.durationMs ?? null);
13651
13675
  return limit === "too_slow" ? MAX_TEST_LIMIT_MS : limit;
13652
13676
  }
13677
+ function keptAttempt(n, summary) {
13678
+ return { n, outcome: "kept", reason: "cannot_complete", turns: summary.turns, toolCalls: summary.toolCalls };
13679
+ }
13680
+ var keptWarning = (n) => `The ${n === 1 ? "first" : "second"} attempt said it could not finish, but its change passed every check the AI is held to apart from the project's tests, so QuikPilot kept it and let the checks decide.`;
13653
13681
  function failedAttempt(n, failure) {
13654
13682
  return { n, outcome: "failed", reason: failure.reason, turns: failure.summary?.turns ?? 0, toolCalls: failure.summary?.toolCalls ?? 0 };
13655
13683
  }
@@ -13711,6 +13739,11 @@ async function runCodegenStep(p) {
13711
13739
  const first = await attempt2();
13712
13740
  const firstMs = now() - firstStarted;
13713
13741
  if ("done" in first) {
13742
+ if (first.done.gaveUp) {
13743
+ log({ event: "codegen.attempt_end", attempt: 1, outcome: "kept", reason: "cannot_complete", turns: first.done.summary.turns, toolCalls: first.done.summary.toolCalls, durationMs: firstMs });
13744
+ warn(p, keptWarning(1));
13745
+ return finish(first.done, [keptAttempt(1, first.done.summary)]);
13746
+ }
13714
13747
  log({ event: "codegen.attempt_end", attempt: 1, outcome: "finished", turns: first.done.summary.turns, toolCalls: first.done.summary.toolCalls, durationMs: firstMs });
13715
13748
  return finish(first.done);
13716
13749
  }
@@ -13746,6 +13779,11 @@ async function runCodegenStep(p) {
13746
13779
  const second = await attempt2(previous);
13747
13780
  const secondMs = now() - secondStarted;
13748
13781
  if ("done" in second) {
13782
+ if (second.done.gaveUp) {
13783
+ log({ event: "codegen.attempt_end", attempt: 2, outcome: "kept", reason: "cannot_complete", turns: second.done.summary.turns, toolCalls: second.done.summary.toolCalls, durationMs: secondMs });
13784
+ warn(p, keptWarning(2));
13785
+ return finish(second.done, [firstRecord, keptAttempt(2, second.done.summary)]);
13786
+ }
13749
13787
  log({ event: "codegen.attempt_end", attempt: 2, outcome: "finished", turns: second.done.summary.turns, toolCalls: second.done.summary.toolCalls, durationMs: secondMs });
13750
13788
  return finish(second.done, [firstRecord, { n: 2, outcome: "finished", turns: second.done.summary.turns, toolCalls: second.done.summary.toolCalls }]);
13751
13789
  }
@@ -13809,7 +13847,9 @@ async function runHealAttempt(i2) {
13809
13847
  const now = p.deps?.now ?? Date.now;
13810
13848
  try {
13811
13849
  const done = await runCodegenLoop(
13812
- { ...args, seed: i2.results, previousAttempt: healPreviousAttempt(i2.attempt, i2.answer) },
13850
+ // `keepOnGiveUp` is off on purpose, whatever the step says: only a first attempt keeps a give-up. A fix that gives up ends as `heal_failed`
13851
+ // with the earlier failure, so a hopeless change cannot be carried from fix to fix.
13852
+ { ...args, keepOnGiveUp: false, seed: i2.results, previousAttempt: healPreviousAttempt(i2.attempt, i2.answer) },
13813
13853
  {
13814
13854
  post: (contextData, signal) => postCodegenTurn(p.gateway, contextData, signal),
13815
13855
  ...p.deps,
@@ -15111,7 +15151,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
15111
15151
  var REPORT_COPY = "final-test-report.xml";
15112
15152
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
15113
15153
  var MAX_FILES = 200;
15114
- var RUNNER_VERSION = true ? "9.3.0-rc.16" : "dev";
15154
+ var RUNNER_VERSION = true ? "9.3.0-rc.18" : "dev";
15115
15155
  function safeDestination(base, repoPath) {
15116
15156
  if (!repoPath || (0, import_node_path14.isAbsolute)(repoPath)) return null;
15117
15157
  const destination = (0, import_node_path14.resolve)(base, repoPath);
@@ -15170,6 +15210,98 @@ function writeFailureArtifact(input) {
15170
15210
  }
15171
15211
  }
15172
15212
 
15213
+ // src/testDiscovery.ts
15214
+ var ABSENT = { report: "ABSENT" };
15215
+ var DRIVE_RE = /^[A-Za-z]:\//;
15216
+ function absent(reason) {
15217
+ return { value: { ...ABSENT }, source: "absent", reason, files: 0, unmapped: 0 };
15218
+ }
15219
+ var slashes = (p) => p.replace(/\\/g, "/");
15220
+ var withoutDotSlash = (p) => p.replace(/^(\.\/)+/, "");
15221
+ function relativeToRepository(raw, cwd) {
15222
+ const path = withoutDotSlash(slashes(raw.trim()));
15223
+ let relative10 = path;
15224
+ if (path.startsWith("/") || DRIVE_RE.test(path)) {
15225
+ const root = slashes(cwd).replace(/\/+$/, "");
15226
+ const windows = DRIVE_RE.test(path) || DRIVE_RE.test(root);
15227
+ const a = windows ? path.toLowerCase() : path;
15228
+ const b = windows ? root.toLowerCase() : root;
15229
+ if (!a.startsWith(`${b}/`)) return null;
15230
+ relative10 = path.slice(root.length + 1);
15231
+ }
15232
+ return relative10;
15233
+ }
15234
+ function inListing(raw, listing, cwd, workspaceRoot) {
15235
+ const relative10 = relativeToRepository(raw, cwd);
15236
+ if (relative10 === null) return null;
15237
+ if (listing.has(relative10)) return relative10;
15238
+ if (workspaceRoot) {
15239
+ const root = slashes(workspaceRoot).replace(/\/+$/, "");
15240
+ const joined = `${root}/${relative10}`;
15241
+ if (listing.has(joined)) return joined;
15242
+ }
15243
+ return null;
15244
+ }
15245
+ function buildTestDiscovery(i2) {
15246
+ if (!i2.command || i2.command.trim().length === 0) return absent("no_command");
15247
+ const snapshot = i2.snapshot;
15248
+ if (!snapshot || !snapshot.results || !snapshot.discoveredFiles) return absent("no_report");
15249
+ if (snapshot.results.size === 0) return absent("no_tests");
15250
+ if (snapshot.unmappedEntries === void 0) return absent("no_report");
15251
+ const listing = new Set(i2.listing);
15252
+ const found = /* @__PURE__ */ new Set();
15253
+ const dropped = /* @__PURE__ */ new Set();
15254
+ for (const raw of snapshot.discoveredFiles) {
15255
+ if (!looksLikeFilePath(slashes(raw).trim())) continue;
15256
+ const match = inListing(raw, listing, i2.cwd, i2.workspaceRoot);
15257
+ if (match) found.add(match);
15258
+ else dropped.add(withoutDotSlash(slashes(raw.trim())));
15259
+ }
15260
+ const unmapped = snapshot.unmappedEntries + dropped.size;
15261
+ const files = [...found].sort();
15262
+ return {
15263
+ value: { report: "PRESENT", discoveredTestFiles: files, unmappedEntries: unmapped },
15264
+ source: "live",
15265
+ reason: "ok",
15266
+ files: files.length,
15267
+ unmapped
15268
+ };
15269
+ }
15270
+ var DEFAULT_DISCOVERY_WAIT_MS = 9e4;
15271
+ var MAX_DISCOVERY_WAIT_MS = 36e5;
15272
+ function discoveryWaitMs(env2 = process.env) {
15273
+ const raw = env2.QUIKPILOT_DISCOVERY_WAIT_SECONDS?.trim();
15274
+ if (!raw || !/^\d+(\.\d+)?$/.test(raw)) return DEFAULT_DISCOVERY_WAIT_MS;
15275
+ return Math.min(MAX_DISCOVERY_WAIT_MS, Math.round(Number(raw) * 1e3));
15276
+ }
15277
+ var TIMEOUT_WARNING = "QuikPilot could not list the project's test files in time, so it skipped the early check of where tests are placed.";
15278
+ async function resolveTestDiscovery(i2) {
15279
+ const now = i2.now ?? Date.now;
15280
+ const started = now();
15281
+ const base = { command: i2.command, listing: i2.listing, workspaceRoot: i2.workspaceRoot, cwd: i2.cwd };
15282
+ const done = (result, warning) => {
15283
+ const waitedMs = now() - started;
15284
+ i2.log?.({ event: "test_discovery", source: result.source, reason: result.reason, files: result.files, unmapped: result.unmapped, waitedMs });
15285
+ return { result, waitedMs, ...warning ? { warning } : {} };
15286
+ };
15287
+ if (!i2.command || i2.command.trim().length === 0) return done(buildTestDiscovery({ ...base, snapshot: null }));
15288
+ let timer;
15289
+ const timeout = new Promise((resolve6) => {
15290
+ timer = setTimeout(() => resolve6("timeout"), i2.waitMs);
15291
+ });
15292
+ const settled = i2.baseline.then(
15293
+ (b) => b.snapshot,
15294
+ () => null
15295
+ );
15296
+ try {
15297
+ const first = await Promise.race([settled, timeout]);
15298
+ if (first === "timeout") return done(absent("timeout"), TIMEOUT_WARNING);
15299
+ return done(buildTestDiscovery({ ...base, snapshot: first }));
15300
+ } finally {
15301
+ if (timer !== void 0) clearTimeout(timer);
15302
+ }
15303
+ }
15304
+
15173
15305
  // src/targeting.ts
15174
15306
  var import_node_path15 = require("node:path");
15175
15307
 
@@ -15578,12 +15710,39 @@ async function run(env2) {
15578
15710
  let changesNoTestDependsOn;
15579
15711
  const contextLog = [];
15580
15712
  const codegenOut = {};
15713
+ let pendingBaseline;
15714
+ const baselineSettled = async () => {
15715
+ try {
15716
+ await pendingBaseline;
15717
+ } catch {
15718
+ }
15719
+ };
15581
15720
  try {
15582
15721
  runToken = await exchangeForRunToken(env2.tokenUrl, await fetchGithubOidcToken());
15583
15722
  packet = await fetchPacket(env2.packetUrl, runToken, env2.githubRunId);
15584
15723
  checkoutTargetBranch(packet.targetBranch);
15585
15724
  const workspaceListing = listWorkspaceFiles(packet.workspaceRoot);
15586
15725
  const outOfScope = (packet.outOfScope ?? []).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
15726
+ runCommand(packet.commands.setup, "Setup");
15727
+ const baselineStartedAt = Date.now();
15728
+ const baselineRun = captureBaselineSnapshot(packet.commands.test).then((snapshot) => ({
15729
+ snapshot,
15730
+ durationMs: Date.now() - baselineStartedAt
15731
+ }));
15732
+ pendingBaseline = baselineRun;
15733
+ const discovery = await resolveTestDiscovery({
15734
+ command: packet.commands.test,
15735
+ baseline: baselineRun,
15736
+ listing: workspaceListing,
15737
+ workspaceRoot: packet.workspaceRoot,
15738
+ cwd: process.cwd(),
15739
+ waitMs: discoveryWaitMs(),
15740
+ log: (e) => console.log(JSON.stringify(e))
15741
+ });
15742
+ if (discovery.warning) {
15743
+ warnings.push(discovery.warning);
15744
+ console.warn(`QuikPilot targeting warning (not blocking): ${discovery.warning}`);
15745
+ }
15587
15746
  const targeting = await runTargeting(
15588
15747
  packet.gateway,
15589
15748
  packet.design,
@@ -15591,7 +15750,7 @@ async function run(env2) {
15591
15750
  workspaceListing,
15592
15751
  packet.requiredTests,
15593
15752
  packet.guardrails.deniedPaths,
15594
- packet.testDiscovery,
15753
+ discovery.result.value,
15595
15754
  outOfScope,
15596
15755
  ...packet.findings ? [{ findings: packet.findings }] : []
15597
15756
  );
@@ -15612,8 +15771,8 @@ async function run(env2) {
15612
15771
  if (packet.issueKey !== null) {
15613
15772
  throw new Error(`QuikPilot found no file to change for this request \u2014 ${targeting.reason?.trim() || "no reason was given."}`);
15614
15773
  }
15774
+ await baselineSettled();
15615
15775
  writePhase0Marker(env2.runId);
15616
- runCommand(packet.commands.setup, "Setup");
15617
15776
  runCommand(packet.commands.lint, "Lint");
15618
15777
  runTestCommand(packet.commands.test);
15619
15778
  } else {
@@ -15640,20 +15799,16 @@ async function run(env2) {
15640
15799
  `QuikPilot's generated plan gives two files identical instructions \u2014 ${describeOverlapWarnings(blockingOverlaps).join("; ")}`
15641
15800
  );
15642
15801
  }
15643
- runCommand(packet.commands.setup, "Setup");
15644
15802
  const judgedByPool = buildJudgedByPool(
15645
15803
  packet.requiredTests,
15646
15804
  targeting.targets,
15647
15805
  targeting.skippedCases ?? []
15648
15806
  );
15649
- const baselineStartedAt = Date.now();
15650
- const baselineRun = captureBaselineSnapshot(packet.commands.test).then((snapshot) => ({
15651
- snapshot,
15652
- durationMs: Date.now() - baselineStartedAt
15653
- }));
15654
15807
  const codegenMode = resolveCodegenMode();
15808
+ const keepOnGiveUp = codegenMode === "loop-tests" && packet.guardrails.maxHealIterations > 0 && process.env.QUIKPILOT_KEEP_ON_GIVE_UP?.trim().toLowerCase() !== "off";
15655
15809
  const stepParams = {
15656
15810
  mode: codegenMode,
15811
+ ...keepOnGiveUp ? { keepOnGiveUp: true } : {},
15657
15812
  tests: {
15658
15813
  root: process.cwd(),
15659
15814
  command: packet.commands.test,
@@ -15768,6 +15923,7 @@ async function run(env2) {
15768
15923
  console.error("No run token \u2014 the OIDC exchange failed before QuikTrack could be reached.");
15769
15924
  return { hardFailure: true };
15770
15925
  }
15926
+ await baselineSettled();
15771
15927
  const quikTestReport = await reportToQuikTest({
15772
15928
  resultsUrl: packet?.quikTest?.resultsUrl,
15773
15929
  runToken,