@quikit/quikpilot-runner 9.3.0-rc.46 → 9.3.0-rc.47

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
@@ -164,6 +164,8 @@ wrong (a field that arrives from a database row or a request), so it only warns
164
164
 
165
165
  **9.3.0-rc.46 — the existing tests to read first include the ones that reach the code through one file in between (QUIKTR-1845).** On the live bug-6 run (QTRIA-17) the design changed `lib/services/issueFilters.ts`, and the two tests that assert the bug import `app/api/issues/route.ts`, which imports it, so the list of existing tests the AI reads before writing (`testsToCheck`, rc.44) was empty. When fewer than 3 test files are found by name or a direct import, the runner now takes one more step: of the files the tests import (code, not a test, not under a denied path; the 150 most shared first) it keeps the ones that import a changed file, and adds the tests that import them, after the others and up to 10 in all. A file in between imported by more than 12 tests only brings the tests named after it (a route by its folder) or after the changed file. Paths only, as before. With 3 or more found the list is exactly as in rc.45. Also in rc.46: everything in rc.45. Nothing else changes.
166
166
 
167
+ **9.3.0-rc.47 — an approved test change that does not fit is named, and can go back to a person (QUIKTR-1844).** On the live bug-3 re-run (QTRIA-16, 26 Oct) a person approved one change to a table test (`toBe(401)` became `toBe(200)` for all 11 rows); with the code complete, 10 rows still failed, the failure said only "existing tests that may expect the old behaviour", and the fix turn, seeing names only, took the approval as proof the test was right and gave up with a stop left. Now, when rows of a test a person approved changing still fail at the final check: the failure message says so first (`the test change approved for <file>: "<title>" does not fit 10 of its 11 rows (now: "expected 404 to be 200")`); the fix turn lists those rows first and shows the first line of each failure (scrubbed, at most 120 characters; approved tests only, every other existing test is still shown by name only); the test is sent as `stillFailing: true` in `decidedTests` (contract §38.12); and, while stops remain, the AI may report that test once more with a change written against the approved text. The revised proposal's line carries `revises` (the commit it replaces) and `misfit` (counts and up to 3 short lines), its message says "This revises the change approved in <sha>", and when approved it replaces the earlier change instead of being merged with it. A revision is checked like any report (inside the test, expectations only). Needs the AI service with §38.12 (it refuses `stillFailing` otherwise, so release that first). A run with no approved test changes, or whose approved tests pass, is exactly as in rc.46. Also in rc.47: everything in rc.46.
168
+
167
169
  **9.3.0-rc.42 — the review check runs only the related tests first (QUIKTR-1812).** After a change passes every check, each changed block is put back on its own to ask whether any test notices. Every one of those runs was the whole suite (on QuikIT about 4 min 50 s, so the 6-minute review checked one block in bug 5's run). Now, where the S4 planner trusts related tests (a suite of three minutes or more, a vitest project), a block's first run is only the tests related to its file: a related test that fails settles "needed" in tens of seconds; anything else goes on exactly as before (the whole suite, and once more before "unneeded"), so every verdict, warning and fix attempt is the same. Each related run gets no more than the time left before the review's deadline, a related run that took as long as the whole suite switches related runs off for the rest of the check, and the `hunk_check` line counts `relatedRuns` and `wholeRuns`. `QUIKPILOT_RELATED_TESTS=off` restores whole-suite runs. Nothing else changes.
168
170
 
169
171
  **9.3.0-rc.41 — a test written once for many rows is said plainly, and the run stops (QUIKTR-1823).** Live run QTRIA-12: after a person approved one test change, the fix broke `still rejects an unauthenticated request`, ONE test inside `describe.each` that runs for 11 routes. The AI reported it four times and was told `title_not_found` each time, because tests inside `describe.each` / `it.each` are left out of the title search on purpose (their names are made at run time); the AI had copied the title right, guessed the shape of its report was wrong, and gave up, and the run said only that the AI could not make the change. Now such a report is turned away with its own word, `generated_test`, whose message tells the AI to answer CANNOT_COMPLETE and name the test. However the loop then ends, it ends `test_conflict_unreportable`: no change is kept for the checks and no second attempt is made (it would meet the same test), and the run says where the test is and which case it contradicts (file, line, case id; never a title) and that a person must change that test or correct the case. If a report of another test stands, the run stops for a decision as before and warns about the generated test. A title in no test of the file is still `title_not_found`. Also in rc.41 (QUIKTR-1824): an answer the AI Service cut off at the output limit (`CODEGEN_OUTPUT_TOO_LARGE`, `OUTPUT_TRUNCATED`) ends the attempt `output_too_large`, "the AI's answer was too long and was cut off", in the code-writing and the targeting loops, instead of `runtime_failed`, "the AI service failed" (live run QTRIA-12: a turn wrote to the limit for 193 s). Every failed attempt keeps the AI Service's own error code in the run's record (`runtimeCode`, a closed word; `other` when it is not shaped like a code), and the run's message names it. Nothing else changes.
package/dist/index.js CHANGED
@@ -32817,7 +32817,8 @@ var TestConflictTool = class {
32817
32817
  async check(r) {
32818
32818
  const d = this.deps;
32819
32819
  const key = `${r.path}\0${r.testTitle}`;
32820
- if (d.decided.some((x) => sameFile(x.path, r.path) && x.title === r.testTitle)) return this.reject("already_decided");
32820
+ const revision = d.revisable?.find((x) => sameFile(x.path, r.path) && x.title === r.testTitle);
32821
+ if (!revision && d.decided.some((x) => sameFile(x.path, r.path) && x.title === r.testTitle)) return this.reject("already_decided");
32821
32822
  if (!this.byTest.has(key) && this.byTest.size >= this.max) return this.reject("too_many_conflicts");
32822
32823
  const path = normaliseToolPath(r.path);
32823
32824
  if (!path.ok || !d.existingTests.has(path.path) || !insideWriteRoot(path.path, d.writeRoot) || matchesDeniedPath(path.path, d.deniedPaths) !== null) {
@@ -32825,20 +32826,22 @@ var TestConflictTool = class {
32825
32826
  }
32826
32827
  const loaded = loadTextForEdit(d.fs, path.path, d.fileBytesMax);
32827
32828
  if (!loaded.ok) return this.reject("not_existing_test");
32828
- const located = locateTests(path.path, loaded.lf);
32829
+ const lf = revision ? revision.text : loaded.lf;
32830
+ const located = locateTests(path.path, lf);
32829
32831
  if (!located) return this.reject("unsupported_language");
32830
32832
  const matches = allTests(located).map((t, index2) => ({ t, index: index2 })).filter(({ t }) => t.title === r.testTitle);
32831
32833
  if (matches.length === 0) return this.reject("title_not_found");
32832
32834
  if (matches.length > 1) return this.reject("title_not_unique");
32833
32835
  const { t: test, index } = matches[0];
32834
32836
  const isTable = index >= located.tests.length;
32835
- const applied = applyEdits(loaded.lf, [{ find: r.find, replace: r.replace }]);
32837
+ const applied = applyEdits(lf, [{ find: r.find, replace: r.replace }]);
32836
32838
  if (!applied.ok) return this.reject(applied.refusals[0]?.kind === "ambiguous" ? "ambiguous" : "no_match");
32837
- const at2 = loaded.lf.indexOf(r.find);
32838
- const changeLine = lineAt(loaded.lf, at2);
32839
- const lastLine = lineAt(loaded.lf, at2 + r.find.length - 1);
32839
+ const at2 = lf.indexOf(r.find);
32840
+ const changeLine = lineAt(lf, at2);
32841
+ const lastLine = lineAt(lf, at2 + r.find.length - 1);
32840
32842
  if (changeLine < (test.bodyStartLine ?? test.startLine) || lastLine > test.endLine) return this.reject("find_outside_test");
32841
- if (testEditOverreach({ path: path.path, before: loaded.lf, after: applied.content, indexes: [index] }) !== null) return this.reject("beyond_expectations");
32843
+ if (testEditOverreach({ path: path.path, before: lf, after: applied.content, indexes: [index] }) !== null) return this.reject("beyond_expectations");
32844
+ if (revision) return this.recordRevision(r, revision, { path: path.path, test, index, isTable, changeLine, lf, ending: loaded.ending, bom: loaded.bom }, key);
32842
32845
  const base = await d.baseline().catch(() => null);
32843
32846
  const results = base?.snapshot.results ?? null;
32844
32847
  if (!base || base.snapshot.timedOut === true || !results) return this.reject("baseline_unknown");
@@ -32875,6 +32878,34 @@ var TestConflictTool = class {
32875
32878
  d.log?.({ event: "codegen.conflict_recorded", reading: r.reading, phase: d.phase ?? null, historyAvailable: history.available, ...isTable ? { rows: mine.length } : {} });
32876
32879
  return { status: "conflict_recorded", message: RECORDED_MESSAGE, output: { history } };
32877
32880
  }
32881
+ /** QUIKTR-1844: record a revision of an approved test change that does not fit. */
32882
+ recordRevision(r, revision, at2, key) {
32883
+ const d = this.deps;
32884
+ const scrub = d.scrub ?? ((s) => s);
32885
+ const history = mapHistory((d.history ?? ((p, title) => readTestHistory({ path: p, title })))(at2.path, revision.diskTitle), scrub);
32886
+ const conflict = {
32887
+ ...r,
32888
+ path: at2.path,
32889
+ describes: at2.test.describes,
32890
+ startLine: at2.test.startLine,
32891
+ endLine: at2.test.endLine,
32892
+ changeLine: at2.changeLine,
32893
+ index: at2.index,
32894
+ ...at2.isTable ? { rows: revision.rows } : {},
32895
+ revises: revision.sha,
32896
+ diskTitle: revision.diskTitle,
32897
+ misfit: revision.misfit,
32898
+ history,
32899
+ originalLf: at2.lf,
32900
+ ending: at2.ending,
32901
+ bom: at2.bom,
32902
+ ...d.phase ? { phase: d.phase } : {}
32903
+ };
32904
+ this.byTest.set(key, conflict);
32905
+ this.counts.recorded += 1;
32906
+ d.log?.({ event: "codegen.conflict_recorded", reading: r.reading, phase: d.phase ?? null, historyAvailable: history.available, revision: true, ...at2.isTable ? { rows: revision.rows } : {} });
32907
+ return { status: "conflict_recorded", message: RECORDED_MESSAGE, output: { history } };
32908
+ }
32878
32909
  };
32879
32910
  function fileText(lf, ending, bom) {
32880
32911
  return `${bom ? "\uFEFF" : ""}${fromLf(lf, ending)}`;
@@ -32950,11 +32981,12 @@ function proposalBranchName(issueKey, githubRunId) {
32950
32981
  }
32951
32982
  function lineOf2(c, file) {
32952
32983
  const newTitle = file.newTitles.get(c.index);
32984
+ const title = c.diskTitle ?? c.testTitle;
32953
32985
  return {
32954
32986
  v: 1,
32955
32987
  path: c.path,
32956
- title: c.testTitle,
32957
- ...newTitle !== void 0 && newTitle !== c.testTitle ? { newTitle } : {},
32988
+ title,
32989
+ ...newTitle !== void 0 && newTitle !== title ? { newTitle } : {},
32958
32990
  caseId: c.caseId,
32959
32991
  reading: c.reading,
32960
32992
  startLine: c.startLine,
@@ -32965,9 +32997,16 @@ function lineOf2(c, file) {
32965
32997
  history: c.history,
32966
32998
  oldCodeChecked: c.oldCodeChecked === true,
32967
32999
  ...c.rows !== void 0 ? { rows: c.rows } : {},
32968
- ...file.stale.get(c.index) ? { stale: file.stale.get(c.index) } : {}
33000
+ ...file.stale.get(c.index) ? { stale: file.stale.get(c.index) } : {},
33001
+ ...c.revises !== void 0 ? { revises: c.revises } : {},
33002
+ ...c.misfit !== void 0 ? { misfit: c.misfit } : {}
32969
33003
  };
32970
33004
  }
33005
+ function revisionNote(sha2, m) {
33006
+ const rows = m ? m.totalRows > 1 ? ` It did not fit ${m.failingRows} of the test's ${m.totalRows} rows` : " The test still failed with it" : "";
33007
+ const now = m?.examples[0] ? ` (now: "${oneLine(m.examples[0])}")` : "";
33008
+ return `This revises the change approved in ${sha2.slice(0, 10)}.${rows}${now}${rows ? "." : ""}`;
33009
+ }
32971
33010
  function staleNote(s) {
32972
33011
  const where = [s.inTitle ? "the title" : null, s.commentLines.length > 0 ? `a comment (line${s.commentLines.length === 1 ? "" : "s"} ${s.commentLines.join(", ")})` : null].filter((x) => x !== null).join(" and ");
32973
33012
  return `Note: ${where} of this test still ${s.inTitle || s.commentLines.length === 1 ? "says" : "say"} ${s.tokens.map((t) => `"${oneLine(t)}"`).join(", ")}, which this change replaces. Fix the wording in the repository, or reject the change.`;
@@ -32992,6 +33031,7 @@ function buildProposalMessage(input) {
32992
33031
  ...l.history.sameCommitPaths && l.history.sameCommitPaths.length > 0 ? [` The same change also touched: ${l.history.sameCommitPaths.slice(0, 5).join(", ")}${l.history.sameCommitPaths.length > 5 || l.history.sameCommitMore ? ", ..." : ""}`] : [],
32993
33032
  ...l.oldCodeChecked ? [" With this change the test fails on the code as it is today, so it shows the bug."] : [],
32994
33033
  ...l.stale ? [` ${staleNote(l.stale)}`] : [],
33034
+ ...l.revises ? [` ${revisionNote(l.revises, l.misfit)}`] : [],
32995
33035
  ""
32996
33036
  ]),
32997
33037
  "Machine-readable (read back by QuikPilot; do not edit):",
@@ -33004,6 +33044,12 @@ ${body.join("\n")}
33004
33044
  }
33005
33045
  var isStr = (v, max, min = 1) => typeof v === "string" && v.length >= min && v.length <= max;
33006
33046
  var isLine = (v) => typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 1e7;
33047
+ function isMisfit(v) {
33048
+ if (typeof v !== "object" || v === null) return false;
33049
+ const m = v;
33050
+ const count3 = (n) => typeof n === "number" && Number.isInteger(n) && n >= 0 && n <= 1e4;
33051
+ return count3(m.failingRows) && count3(m.totalRows) && m.failingRows <= m.totalRows && Array.isArray(m.examples) && m.examples.length <= 3 && m.examples.every((e) => isStr(e, 120));
33052
+ }
33007
33053
  function isStale(v) {
33008
33054
  if (typeof v !== "object" || v === null) return false;
33009
33055
  const s = v;
@@ -33023,7 +33069,7 @@ function parseProposalMessage(message) {
33023
33069
  const o = j;
33024
33070
  const c = o.correction;
33025
33071
  const h = o.history;
33026
- if (o.v !== 1 || !isStr(o.path, 300) || !isStr(o.title, 300) || o.newTitle !== void 0 && !isStr(o.newTitle, 300) || !isStr(o.caseId, 64) || !CONFLICT_READINGS.includes(o.reading) || !isLine(o.startLine) || !isLine(o.endLine) || !isLine(o.changeLine) || !isStr(o.reason, 300) || typeof c !== "object" || c === null || !CONFLICT_CASE_FIELDS.includes(c.field) || !isStr(c.text, 1e3) || !isStr(c.why, 300) || typeof h !== "object" || h === null || typeof h.available !== "boolean" || typeof o.oldCodeChecked !== "boolean" || o.rows !== void 0 && !(typeof o.rows === "number" && Number.isInteger(o.rows) && o.rows >= 1 && o.rows <= 1e4) || o.stale !== void 0 && !isStale(o.stale)) {
33072
+ if (o.v !== 1 || !isStr(o.path, 300) || !isStr(o.title, 300) || o.newTitle !== void 0 && !isStr(o.newTitle, 300) || !isStr(o.caseId, 64) || !CONFLICT_READINGS.includes(o.reading) || !isLine(o.startLine) || !isLine(o.endLine) || !isLine(o.changeLine) || !isStr(o.reason, 300) || typeof c !== "object" || c === null || !CONFLICT_CASE_FIELDS.includes(c.field) || !isStr(c.text, 1e3) || !isStr(c.why, 300) || typeof h !== "object" || h === null || typeof h.available !== "boolean" || typeof o.oldCodeChecked !== "boolean" || o.rows !== void 0 && !(typeof o.rows === "number" && Number.isInteger(o.rows) && o.rows >= 1 && o.rows <= 1e4) || o.stale !== void 0 && !isStale(o.stale) || o.revises !== void 0 && !(typeof o.revises === "string" && /^[0-9a-f]{40}$/.test(o.revises)) || o.misfit !== void 0 && (o.revises === void 0 || !isMisfit(o.misfit))) {
33027
33073
  continue;
33028
33074
  }
33029
33075
  out.push(o);
@@ -33124,7 +33170,7 @@ function loadApprovedTests(input) {
33124
33170
  const decided = (use) => use.map((l) => ({ path: l.path, testTitle: l.newTitle ?? l.title, caseId: l.caseId, decision }));
33125
33171
  const titlesOf = (use) => use.flatMap((l) => [{ path: l.path, title: l.title }, ...l.newTitle !== void 0 ? [{ path: l.path, title: l.newTitle }] : []]);
33126
33172
  if (decision === "TEST_RIGHT") {
33127
- return { approved: { decision, files: [], decided: decided(lines), titles: titlesOf(lines), proposals: [] }, warnings };
33173
+ return { approved: { decision, files: [], decided: decided(lines), titles: titlesOf(lines), proposals: [], approvedTests: [], revises: [] }, warnings };
33128
33174
  }
33129
33175
  const readCurrent = input.readCurrent ?? ((path) => {
33130
33176
  try {
@@ -33171,7 +33217,9 @@ function loadApprovedTests(input) {
33171
33217
  }
33172
33218
  log({ event: "codegen.approval_loaded", decision, files: files.length, tests: kept.length, dropped: lines.length - kept.length });
33173
33219
  const tests = kept.map((l) => ({ path: l.path, line: l.changeLine, caseId: l.caseId }));
33174
- return { approved: { decision, files, decided: decided(kept), titles: titlesOf(kept), proposals: [{ branch, sha: sha2, tests }] }, warnings };
33220
+ const approvedTests = kept.map((l) => ({ path: l.path, diskTitle: l.title, title: l.newTitle ?? l.title, caseId: l.caseId, sha: sha2 }));
33221
+ const revises = [...new Set(kept.filter((l) => l.revises !== void 0).map((l) => l.path))];
33222
+ return { approved: { decision, files, decided: decided(kept), titles: titlesOf(kept), proposals: [{ branch, sha: sha2, tests }], approvedTests, revises }, warnings };
33175
33223
  }
33176
33224
  var gitMergeText = ({ ours, base, theirs }) => {
33177
33225
  const dir = (0, import_node_fs5.mkdtempSync)((0, import_node_path6.join)((0, import_node_os2.tmpdir)(), "qp-merge-"));
@@ -33200,9 +33248,10 @@ function loadApprovals(input) {
33200
33248
  }
33201
33249
  });
33202
33250
  const merge2 = input.merge ?? gitMergeText;
33203
- const decided = [];
33251
+ let decided = [];
33204
33252
  const titles = [];
33205
33253
  const proposals = [];
33254
+ let approvedTests = [];
33206
33255
  const files = /* @__PURE__ */ new Map();
33207
33256
  let any = false;
33208
33257
  for (const change of input.changes.slice(0, MAX_CHANGES_APPLIED)) {
@@ -33211,9 +33260,10 @@ function loadApprovals(input) {
33211
33260
  const a = one.approved;
33212
33261
  if (!a) continue;
33213
33262
  const leftOut = /* @__PURE__ */ new Set();
33263
+ const revising = new Set(a.revises ?? []);
33214
33264
  for (const f of a.files) {
33215
33265
  const earlier = files.get(f.targetPath);
33216
- if (earlier === void 0) {
33266
+ if (earlier === void 0 || revising.has(f.targetPath)) {
33217
33267
  files.set(f.targetPath, f.newContent);
33218
33268
  continue;
33219
33269
  }
@@ -33228,6 +33278,10 @@ function loadApprovals(input) {
33228
33278
  files.set(f.targetPath, `${disk.charCodeAt(0) === 65279 ? "\uFEFF" : ""}${fromLf(merged, ending)}`);
33229
33279
  }
33230
33280
  any = true;
33281
+ const revisedCases = new Set(a.decided.filter((d) => revising.has(d.path)).map((d) => `${d.path}\0${d.caseId}`));
33282
+ decided = decided.filter((d) => !revisedCases.has(`${d.path}\0${d.caseId}`));
33283
+ approvedTests = approvedTests.filter((t) => !revisedCases.has(`${t.path}\0${t.caseId}`));
33284
+ approvedTests.push(...(a.approvedTests ?? []).filter((t) => !leftOut.has(t.path)));
33231
33285
  decided.push(...a.decided.filter((d) => !leftOut.has(d.path)));
33232
33286
  titles.push(...a.titles.filter((t) => !leftOut.has(t.path)));
33233
33287
  for (const p of a.proposals) {
@@ -33243,7 +33297,8 @@ function loadApprovals(input) {
33243
33297
  files: [...files.entries()].map(([targetPath, newContent]) => ({ targetPath, newContent })),
33244
33298
  decided: decided.slice(-MAX_DECIDED_TESTS),
33245
33299
  titles,
33246
- proposals
33300
+ proposals,
33301
+ approvedTests
33247
33302
  },
33248
33303
  warnings
33249
33304
  };
@@ -34262,6 +34317,7 @@ function describeRegressions(check, options = {}) {
34262
34317
  return text2 ? `${id} (${text2})` : id;
34263
34318
  };
34264
34319
  const parts = [];
34320
+ if (options.approvedMisfits) parts.push(options.approvedMisfits);
34265
34321
  if (check.regressions.length > 0) {
34266
34322
  parts.push(
34267
34323
  options.existingTestsMayExpectOldBehaviour === true ? `${check.regressions.length} regression(s) (passed before, now fail), ${oldBehaviourSentence(groupRegressions(check.regressions), 700)}` : `${check.regressions.length} regression(s) (passed before, now fail): ${check.regressions.map(withText).join(", ")}`
@@ -36106,8 +36162,9 @@ function testAnswerFrom(args) {
36106
36162
  let failureDetail = /* @__PURE__ */ new Map();
36107
36163
  if (args.baseline?.results) {
36108
36164
  const check = checkForRegressions(args.baseline, after);
36109
- regressions = check.regressions;
36110
- newFailures = check.newFailures;
36165
+ const approvedFirst = (ids) => args.approvedIds && args.approvedIds.size > 0 ? [...ids.filter((id) => args.approvedIds.has(id)), ...ids.filter((id) => !args.approvedIds.has(id))] : ids;
36166
+ regressions = approvedFirst(check.regressions);
36167
+ newFailures = approvedFirst(check.newFailures);
36111
36168
  alreadyFailing = check.preExisting;
36112
36169
  own = ownFailureIds(newFailures, [...args.changedPaths], args.requiredIds);
36113
36170
  failureText = check.failureText;
@@ -36125,7 +36182,16 @@ function testAnswerFrom(args) {
36125
36182
  let left = MAX_MESSAGES_TOTAL_CHARS;
36126
36183
  let ownToCome = listed.filter((id) => own.has(id)).length;
36127
36184
  listed.forEach((id, i2) => {
36128
- if (!own.has(id)) return;
36185
+ if (!own.has(id)) {
36186
+ if (args.approvedIds?.has(id) === true) {
36187
+ const line2 = firstLine(failureText.get(id) ?? "", failureWhere.get(id));
36188
+ if (line2 && line2.length <= left) {
36189
+ messages[names[i2]] = line2;
36190
+ left -= line2.length;
36191
+ }
36192
+ }
36193
+ return;
36194
+ }
36129
36195
  ownToCome -= 1;
36130
36196
  const where = failureWhere.get(id);
36131
36197
  const allowance = Math.min(MAX_WHOLE_MESSAGE_CHARS, left - ownToCome * MAX_MESSAGE_CHARS);
@@ -41146,6 +41212,14 @@ var MAP_SOFT_HEADROOM_TOKENS = 2e4;
41146
41212
  function mapSoftTarget(firstRequestTokens, ceiling) {
41147
41213
  return Math.min(ceiling, Math.max(MAP_SOFT_REQUEST_TOKENS, firstRequestTokens + MAP_SOFT_HEADROOM_TOKENS));
41148
41214
  }
41215
+ function withApprovedText(revisable, approved) {
41216
+ return revisable.flatMap((r) => {
41217
+ const file = approved.find((f) => f.targetPath === r.path);
41218
+ if (!file) return [];
41219
+ const body = file.newContent.charCodeAt(0) === 65279 ? file.newContent.slice(1) : file.newContent;
41220
+ return [{ ...r, text: body.replace(/\r\n/g, "\n") }];
41221
+ });
41222
+ }
41149
41223
  var CodegenLoopFailure = class extends Error {
41150
41224
  reason;
41151
41225
  runtimeCode;
@@ -41296,6 +41370,8 @@ async function runCodegenLoop(args, deps) {
41296
41370
  writeRoot: args.writeRoot ?? "",
41297
41371
  caseIds: args.requiredAutomationIds,
41298
41372
  decided: args.conflicts.titles,
41373
+ // QUIKTR-1844: a test whose approved change does not fit may be reported once more, against its approved text.
41374
+ ...args.conflicts.revisable && args.conflicts.revisable.length > 0 ? { revisable: withApprovedText(args.conflicts.revisable, args.approved ?? []) } : {},
41299
41375
  // The checkout as it is on disk: a report is made against the file as it was before the run, never against this attempt's overlay.
41300
41376
  fs: deps.fs ?? createNodeWriteFs(),
41301
41377
  fileBytesMax: limits.fileBytesMax,
@@ -43007,6 +43083,20 @@ function healReviewPreviousAttempt(attempt2, blocks, answer) {
43007
43083
  }
43008
43084
 
43009
43085
  // src/codegenHeal.ts
43086
+ var samePlace5 = (a, b) => {
43087
+ const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
43088
+ const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
43089
+ return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
43090
+ };
43091
+ function withMisfits(conflicts, misfits) {
43092
+ const misfitOf = (path, title) => misfits.find((m) => samePlace5(m.path, path) && m.testTitle === title);
43093
+ const decided = conflicts.decided.map((d) => d.decision === "TEST_CHANGED" && misfitOf(d.path, d.testTitle) ? { ...d, stillFailing: true } : d);
43094
+ const revisable = (conflicts.approvedTests ?? []).flatMap((t) => {
43095
+ const m = misfitOf(t.path, t.title);
43096
+ return m ? [{ path: t.path, title: t.title, diskTitle: t.diskTitle, sha: t.sha, rows: m.totalRows, misfit: { failingRows: m.failingRows, totalRows: m.totalRows, examples: m.examples } }] : [];
43097
+ });
43098
+ return { ...conflicts, decided, revisable };
43099
+ }
43010
43100
  async function runHealAttempt(i2) {
43011
43101
  const p = i2.step;
43012
43102
  const keptText = new Map(i2.results.map((r) => [r.targetPath, r.newContent]));
@@ -43024,6 +43114,7 @@ async function runHealAttempt(i2) {
43024
43114
  );
43025
43115
  const args = buildCodegenLoopArgs({ ...p, targets, workspaceListing }, context);
43026
43116
  if (i2.review !== void 0 || i2.answer.regressions <= 0) delete args.conflicts;
43117
+ if (args.conflicts && i2.misfits && i2.misfits.length > 0) args.conflicts = withMisfits(args.conflicts, i2.misfits);
43027
43118
  args.protectedTestPaths = original.protectedTestPaths;
43028
43119
  if (original.baseContext.protectedTestPaths !== void 0) args.baseContext.protectedTestPaths = original.baseContext.protectedTestPaths;
43029
43120
  else delete args.baseContext.protectedTestPaths;
@@ -43243,7 +43334,13 @@ async function runVerifyAndFix(p) {
43243
43334
  p.log({ event: "heal.start", attempt: attemptsRun, healsRun, ...countsOf(v.answer) });
43244
43335
  const startedAt = p.now();
43245
43336
  try {
43246
- results = await p.heal({ results, answer: v.answer, attempt: attemptsRun - 1, hardStopAtMs: p.jobStopAtMs - v.gateMs });
43337
+ results = await p.heal({
43338
+ results,
43339
+ answer: v.answer,
43340
+ attempt: attemptsRun - 1,
43341
+ hardStopAtMs: p.jobStopAtMs - v.gateMs,
43342
+ ...v.misfits && v.misfits.length > 0 ? { misfits: v.misfits } : {}
43343
+ });
43247
43344
  } catch (err) {
43248
43345
  if (err instanceof SafetyRefusalError) {
43249
43346
  p.onStop?.("refused");
@@ -43786,6 +43883,50 @@ function describeDependencyViolations(check) {
43786
43883
  return check.violations.map((v) => `${v.file} imports ${v.packages.join(", ")}, not a dependency of this repository`).join("; ");
43787
43884
  }
43788
43885
 
43886
+ // src/approvedMisfit.ts
43887
+ var MAX_MISFIT_EXAMPLES = 3;
43888
+ var MAX_MISFIT_EXAMPLE_CHARS = 120;
43889
+ var samePlace6 = (a, b) => {
43890
+ const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
43891
+ const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
43892
+ return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
43893
+ };
43894
+ function isRowOf(id, test) {
43895
+ const { file, name } = splitTestId(id);
43896
+ return (file === null || samePlace6(file, test.path)) && nameEndsWithTitle(name, test.testTitle);
43897
+ }
43898
+ function approvedTestsFailing(input) {
43899
+ const approved = input.decided.filter((d) => d.decision === "TEST_CHANGED");
43900
+ if (approved.length === 0) return [];
43901
+ const failing = [...input.check.regressions, ...input.check.newFailures];
43902
+ const after = [...input.afterIds];
43903
+ const out = [];
43904
+ const taken = /* @__PURE__ */ new Set();
43905
+ for (const d of approved) {
43906
+ const failingIds = failing.filter((id) => !taken.has(id) && isRowOf(id, d));
43907
+ if (failingIds.length === 0) continue;
43908
+ for (const id of failingIds) taken.add(id);
43909
+ const totalRows = Math.max(failingIds.length, after.filter((id) => isRowOf(id, d)).length);
43910
+ const examples = [];
43911
+ for (const id of failingIds) {
43912
+ if (examples.length >= MAX_MISFIT_EXAMPLES) break;
43913
+ const line = firstLine(input.check.failureText.get(id) ?? "", void 0, MAX_MISFIT_EXAMPLE_CHARS);
43914
+ if (line && !examples.includes(line)) examples.push(line);
43915
+ }
43916
+ out.push({ path: d.path, testTitle: d.testTitle, caseId: d.caseId, failingIds, failingRows: failingIds.length, totalRows, examples });
43917
+ }
43918
+ return out;
43919
+ }
43920
+ var clip3 = (s, max) => s.length <= max ? s : `${s.slice(0, max - 1)}\u2026`;
43921
+ function misfitSentence(misfits, max = 600) {
43922
+ const parts = misfits.map((m) => {
43923
+ const rows = m.totalRows > 1 ? ` does not fit ${m.failingRows} of its ${m.totalRows} rows` : " does not fit: the test still fails";
43924
+ const now = m.examples[0] ? ` (now: "${m.examples[0]}")` : "";
43925
+ return `the test change approved for ${m.path}: "${clip3(m.testTitle, 120)}"${rows}${now}`;
43926
+ });
43927
+ return clip3(parts.join("; "), max);
43928
+ }
43929
+
43789
43930
  // src/testPlacementCheck.ts
43790
43931
  function isDiscovered(targetPath, discoveredFiles) {
43791
43932
  const normalized = targetPath.replace(/\\/g, "/");
@@ -44209,11 +44350,25 @@ async function verifyChange(ctx, results, undoable) {
44209
44350
  const check = checkForRegressions(baseline, after);
44210
44351
  if (check.blocked) {
44211
44352
  const readable = Boolean(baseline.results && after.results);
44212
- const answered = readable ? testAnswerFrom({ baseline, after, changedPaths: results.map((r) => r.targetPath), requiredIds: ctx.requiredAutomationIds, harness: ctx.harness === true }) : null;
44213
- return fail(new Error(`QuikPilot's generated code introduced test failures \u2014 ${describeRegressions(check, { existingTestsMayExpectOldBehaviour: ctx.conflictsOn === true })}`), {
44353
+ const misfits = readable && ctx.approvedDecided && ctx.approvedDecided.length > 0 ? approvedTestsFailing({ check, afterIds: after.results.keys(), decided: ctx.approvedDecided }) : [];
44354
+ const approvedIds = new Set(misfits.flatMap((m) => m.failingIds));
44355
+ const answered = readable ? testAnswerFrom({
44356
+ baseline,
44357
+ after,
44358
+ changedPaths: results.map((r) => r.targetPath),
44359
+ requiredIds: ctx.requiredAutomationIds,
44360
+ harness: ctx.harness === true,
44361
+ ...approvedIds.size > 0 ? { approvedIds } : {}
44362
+ }) : null;
44363
+ const wording = describeRegressions(check, {
44364
+ existingTestsMayExpectOldBehaviour: ctx.conflictsOn === true,
44365
+ ...misfits.length > 0 ? { approvedMisfits: misfitSentence(misfits) } : {}
44366
+ });
44367
+ return fail(new Error(`QuikPilot's generated code introduced test failures \u2014 ${wording}`), {
44214
44368
  check,
44215
44369
  bothSnapshotsReadable: readable,
44216
- ...answered ? { answer: answered.output, failingKey: answered.failingKey } : {}
44370
+ ...answered ? { answer: answered.output, failingKey: answered.failingKey } : {},
44371
+ ...misfits.length > 0 ? { misfits } : {}
44217
44372
  });
44218
44373
  }
44219
44374
  stage = "coverage";
@@ -44310,7 +44465,7 @@ var MAX_ENTRY_CHARS = 200;
44310
44465
  var inside = (path, root) => root === "" || path === root || path.startsWith(`${root}/`);
44311
44466
  var cap = (s) => s.length <= MAX_ENTRY_CHARS ? s : `${s.slice(0, MAX_ENTRY_CHARS - 1)}\u2026`;
44312
44467
  var parentOf2 = (d) => d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "";
44313
- function clip3(text2, max) {
44468
+ function clip4(text2, max) {
44314
44469
  if (text2.length <= max) return { text: text2, truncated: false };
44315
44470
  const cut = text2.slice(0, max);
44316
44471
  const nl = cut.lastIndexOf("\n");
@@ -44328,7 +44483,7 @@ function guidanceFiles(i2, perFile2, total) {
44328
44483
  if (!tracked.has(path) || matchesDeniedPath(path, denied)) continue;
44329
44484
  const raw = i2.readText(path);
44330
44485
  if (raw === null || raw.trim() === "") continue;
44331
- const clipped = clip3(i2.scrub(raw.replace(/\r\n/g, "\n")).trim(), Math.min(perFile2, left));
44486
+ const clipped = clip4(i2.scrub(raw.replace(/\r\n/g, "\n")).trim(), Math.min(perFile2, left));
44332
44487
  out.push({ path, ...clipped });
44333
44488
  left -= clipped.text.length;
44334
44489
  }
@@ -44811,7 +44966,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
44811
44966
  var REPORT_COPY = "final-test-report.xml";
44812
44967
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
44813
44968
  var MAX_FILES = 200;
44814
- var RUNNER_VERSION = true ? "9.3.0-rc.46" : "dev";
44969
+ var RUNNER_VERSION = true ? "9.3.0-rc.47" : "dev";
44815
44970
  function safeDestination(base, repoPath) {
44816
44971
  if (!repoPath || (0, import_node_path24.isAbsolute)(repoPath)) return null;
44817
44972
  const destination = (0, import_node_path24.resolve)(base, repoPath);
@@ -45605,7 +45760,7 @@ async function run(env2) {
45605
45760
  const stepParams = {
45606
45761
  mode: codegenMode,
45607
45762
  ...keepOnGiveUp ? { keepOnGiveUp: true } : {},
45608
- ...conflictsOn ? { conflicts: { decided, titles: approved?.titles ?? [] } } : {},
45763
+ ...conflictsOn ? { conflicts: { decided, titles: approved?.titles ?? [], approvedTests: approved?.approvedTests ?? [] } } : {},
45609
45764
  ...approved && approved.files.length > 0 ? { approved: approved.files } : {},
45610
45765
  ...callFunction ? { callFunction } : {},
45611
45766
  ...twoPhase ? { twoPhase: true, ...packet.requiredTestTypes ? { requiredTestTypes: packet.requiredTestTypes } : {} } : {},
@@ -45662,6 +45817,8 @@ async function run(env2) {
45662
45817
  harness: codegenMode === "loop-tests" && stepParams.harness !== false,
45663
45818
  // QUIKTR-1827: a regression of an existing test is worded as a test that may expect the old behaviour where a person can be asked.
45664
45819
  conflictsOn,
45820
+ // QUIKTR-1844: and a test a person approved changing that still fails is named as an approved change that does not fit.
45821
+ ...decided.some((d) => d.decision === "TEST_CHANGED") ? { approvedDecided: decided.filter((d) => d.decision === "TEST_CHANGED") } : {},
45665
45822
  // S4: the final run of the project's tests has a clock sized from how long the baseline took and from what is left of the job.
45666
45823
  baselineMs: timedBaseline.durationMs,
45667
45824
  jobStopAtMs,
@@ -45727,10 +45884,19 @@ async function run(env2) {
45727
45884
  return { blocks: checked.unnecessary, testCount, raw: checked };
45728
45885
  }
45729
45886
  } : {},
45730
- heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs, review }) => {
45887
+ heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs, review, misfits }) => {
45731
45888
  const out = {};
45732
45889
  try {
45733
- return await runHealAttempt({ step: stepParams, results: kept, answer, attempt: attempt2, hardStopAtMs, out, ...review ? { review: { blocks: review.blocks } } : {} });
45890
+ return await runHealAttempt({
45891
+ step: stepParams,
45892
+ results: kept,
45893
+ answer,
45894
+ attempt: attempt2,
45895
+ hardStopAtMs,
45896
+ out,
45897
+ ...review ? { review: { blocks: review.blocks } } : {},
45898
+ ...misfits ? { misfits } : {}
45899
+ });
45734
45900
  } finally {
45735
45901
  healCalls.push({ ...out.summary ? { summary: out.summary } : {}, ...out.failure ? { failureReason: out.failure.reason } : {} });
45736
45902
  }