@quikit/quikpilot-runner 9.3.0-rc.45 → 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
@@ -162,6 +162,10 @@ wrong (a field that arrives from a database row or a request), so it only warns
162
162
 
163
163
  **9.3.0-rc.45 — a changed test that still says the old behaviour is noted on the decision page (QUIKTR-1832).** On 25 Oct the approved proposal for the "logged-in users get 401" bug changed what a test expects (`toBe(401)` to `toBe(200)`) and left its title, "returns 401 when there's no bearer token at all", and a comment saying the old behaviour. The runner already lets a proposal change a test's title and comments, so it cannot refuse that; it now notices. For each changed test it takes the string and number values (numbers of three digits or more, or with a decimal point) that the edit removes, drops any the new test still uses in its own code or that the replacement itself writes, and checks whether one is still in the test's new title or in a comment inside it. When one is, the proposal commit gets a readable `Note:` line and an optional `stale` key (`tokens`, `inTitle`, `commentLines`, at most 4 values of 60 characters and 6 lines) on that test's machine-readable line; an older reader ignores it, and a line whose note is malformed is dropped like any other malformed line. It is a note for the person who approves, never a rejection, and nothing is added to the report back to QuikProjects. The AI Runtime of QUIKTR-1832 also asks the AI to change the title and comments in the same edit. Also in rc.45: everything in rc.44. Nothing else changes.
164
164
 
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
+
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
+
165
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.
166
170
 
167
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
  };
@@ -33697,6 +33752,9 @@ var MAX_TESTS_PER_TARGET = 3;
33697
33752
  var MAX_REVERSE_TEST_CHARS = 24e3;
33698
33753
  var MAX_TEST_FILE_CHARS = 2e5;
33699
33754
  var MAX_CORPUS_CHARS = 4e7;
33755
+ var MAX_FILES_IN_BETWEEN = 150;
33756
+ var COMMON_IMPORTER_LIMIT = 12;
33757
+ var ROUTE_FILE_NAMES = /* @__PURE__ */ new Set(["route", "page", "layout", "index", "default", "loading", "error"]);
33700
33758
  var TestCorpus = class {
33701
33759
  constructor(listing, readFile, deniedPaths, isTest = isTestTarget) {
33702
33760
  this.listing = listing;
@@ -33741,6 +33799,18 @@ function sharedPrefix(a, b) {
33741
33799
  while (n < x.length && n < y.length && x[n] === y[n]) n++;
33742
33800
  return n;
33743
33801
  }
33802
+ function namesOf(path) {
33803
+ const base = import_node_path7.posix.basename(path).replace(/\.[cm]?[jt]sx?$/i, "").toLowerCase();
33804
+ const names = base.length >= 2 ? [base] : [];
33805
+ if (ROUTE_FILE_NAMES.has(base)) {
33806
+ const parts = import_node_path7.posix.dirname(path).split("/").filter(Boolean);
33807
+ while (parts.length > 0 && /^[[(]/.test(parts[parts.length - 1])) parts.pop();
33808
+ const folder = parts[parts.length - 1];
33809
+ if (folder && folder.length >= 3) names.push(folder.toLowerCase());
33810
+ }
33811
+ return names;
33812
+ }
33813
+ var namedAfter = (test, path) => namesOf(path).some((n) => import_node_path7.posix.basename(test).toLowerCase().startsWith(n));
33744
33814
  function testsImporting(p) {
33745
33815
  if (p.limit <= 0 || (p.isTest ?? isTestTarget)(p.target) || !supportsImportScan(p.target)) return [];
33746
33816
  const stem = stemOf(p.target);
@@ -33759,6 +33829,59 @@ function testsImporting(p) {
33759
33829
  hits.sort((a, b) => Number(b.named) - Number(a.named) || b.near - a.near || a.size - b.size || (a.path < b.path ? -1 : 1));
33760
33830
  return hits.slice(0, p.limit).map((h) => h.path);
33761
33831
  }
33832
+ function testsThroughOneFile(p) {
33833
+ const isTest = p.isTest ?? isTestTarget;
33834
+ if (p.limit <= 0 || isTest(p.target) || !supportsImportScan(p.target)) return [];
33835
+ const importsOf = /* @__PURE__ */ new Map();
33836
+ const shared = /* @__PURE__ */ new Map();
33837
+ for (const file of p.corpus.files()) {
33838
+ const seen = /* @__PURE__ */ new Set();
33839
+ for (const spec of extractImportSpecifiers(file.text)) {
33840
+ const r = resolveImport(file.path, spec, p.listing, p.mapSpecifier);
33841
+ if (r.kind === "repo" && r.path !== file.path) seen.add(r.path);
33842
+ }
33843
+ importsOf.set(file.path, seen);
33844
+ for (const q of seen) {
33845
+ if (q === p.target || isTest(q) || !supportsImportScan(q) || matchesDeniedPath(q, p.deniedPaths ?? [])) continue;
33846
+ shared.set(q, (shared.get(q) ?? 0) + 1);
33847
+ }
33848
+ }
33849
+ const between = [...shared.entries()].sort((a, b) => b[1] - a[1] || sharedPrefix(b[0], p.target) - sharedPrefix(a[0], p.target) || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)).slice(0, MAX_FILES_IN_BETWEEN).map(([q]) => q);
33850
+ const via = /* @__PURE__ */ new Set();
33851
+ for (const q of between) {
33852
+ let text2;
33853
+ try {
33854
+ text2 = p.readRel(q);
33855
+ } catch {
33856
+ text2 = null;
33857
+ }
33858
+ if (text2 === null || text2.length > MAX_TEST_FILE_CHARS) continue;
33859
+ const reaches = extractImportSpecifiers(text2).some((spec) => {
33860
+ const r = resolveImport(q, spec, p.listing, p.mapSpecifier);
33861
+ return r.kind === "repo" && r.path === p.target;
33862
+ });
33863
+ if (reaches) via.add(q);
33864
+ }
33865
+ if (via.size === 0) return [];
33866
+ const importers = /* @__PURE__ */ new Map();
33867
+ for (const [test, imports] of importsOf) {
33868
+ if (p.exclude?.has(test) || test === p.target || imports.has(p.target)) continue;
33869
+ for (const q of imports) if (via.has(q)) importers.set(q, [...importers.get(q) ?? [], test]);
33870
+ }
33871
+ const textOf = new Map(p.corpus.files().map((f) => [f.path, f.text]));
33872
+ const hits = /* @__PURE__ */ new Map();
33873
+ for (const [q, tests] of importers) {
33874
+ const common = tests.length > COMMON_IMPORTER_LIMIT;
33875
+ for (const test of tests) {
33876
+ const named = namedAfter(test, q) || namedAfter(test, p.target);
33877
+ if (common && !named) continue;
33878
+ const prev = hits.get(test);
33879
+ const near = sharedPrefix(test, q);
33880
+ hits.set(test, { path: test, named: named || (prev?.named ?? false), near: Math.max(near, prev?.near ?? 0), size: textOf.get(test)?.length ?? 0 });
33881
+ }
33882
+ }
33883
+ return [...hits.values()].sort((a, b) => Number(b.named) - Number(a.named) || b.near - a.near || a.size - b.size || (a.path < b.path ? -1 : 1)).slice(0, p.limit).map((h) => h.path);
33884
+ }
33762
33885
 
33763
33886
  // src/testAdapters.ts
33764
33887
  var import_node_fs9 = require("node:fs");
@@ -34194,6 +34317,7 @@ function describeRegressions(check, options = {}) {
34194
34317
  return text2 ? `${id} (${text2})` : id;
34195
34318
  };
34196
34319
  const parts = [];
34320
+ if (options.approvedMisfits) parts.push(options.approvedMisfits);
34197
34321
  if (check.regressions.length > 0) {
34198
34322
  parts.push(
34199
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(", ")}`
@@ -36038,8 +36162,9 @@ function testAnswerFrom(args) {
36038
36162
  let failureDetail = /* @__PURE__ */ new Map();
36039
36163
  if (args.baseline?.results) {
36040
36164
  const check = checkForRegressions(args.baseline, after);
36041
- regressions = check.regressions;
36042
- 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);
36043
36168
  alreadyFailing = check.preExisting;
36044
36169
  own = ownFailureIds(newFailures, [...args.changedPaths], args.requiredIds);
36045
36170
  failureText = check.failureText;
@@ -36057,7 +36182,16 @@ function testAnswerFrom(args) {
36057
36182
  let left = MAX_MESSAGES_TOTAL_CHARS;
36058
36183
  let ownToCome = listed.filter((id) => own.has(id)).length;
36059
36184
  listed.forEach((id, i2) => {
36060
- 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
+ }
36061
36195
  ownToCome -= 1;
36062
36196
  const where = failureWhere.get(id);
36063
36197
  const allowance = Math.min(MAX_WHOLE_MESSAGE_CHARS, left - ownToCome * MAX_MESSAGE_CHARS);
@@ -41078,6 +41212,14 @@ var MAP_SOFT_HEADROOM_TOKENS = 2e4;
41078
41212
  function mapSoftTarget(firstRequestTokens, ceiling) {
41079
41213
  return Math.min(ceiling, Math.max(MAP_SOFT_REQUEST_TOKENS, firstRequestTokens + MAP_SOFT_HEADROOM_TOKENS));
41080
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
+ }
41081
41223
  var CodegenLoopFailure = class extends Error {
41082
41224
  reason;
41083
41225
  runtimeCode;
@@ -41228,6 +41370,8 @@ async function runCodegenLoop(args, deps) {
41228
41370
  writeRoot: args.writeRoot ?? "",
41229
41371
  caseIds: args.requiredAutomationIds,
41230
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 ?? []) } : {},
41231
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.
41232
41376
  fs: deps.fs ?? createNodeWriteFs(),
41233
41377
  fileBytesMax: limits.fileBytesMax,
@@ -42430,6 +42574,7 @@ async function verifyOnOldCode(conflicts, run2, log = () => void 0) {
42430
42574
  var import_node_fs16 = require("node:fs");
42431
42575
  var import_node_path18 = require("node:path");
42432
42576
  var MAX_TESTS_TO_CHECK = 10;
42577
+ var SECOND_HOP_BELOW = 3;
42433
42578
  function testsToCheck(i2) {
42434
42579
  const limit = Math.min(MAX_TESTS_TO_CHECK, Math.max(0, i2.limit ?? MAX_TESTS_TO_CHECK));
42435
42580
  const world = buildTestWorld(i2);
@@ -42444,6 +42589,23 @@ function testsToCheck(i2) {
42444
42589
  for (const t of code) {
42445
42590
  for (const path of testsImporting({ target: t.path, listing: world.listing, corpus: world.corpus, mapSpecifier: world.mapSpecifier, limit, isTest: world.isTest })) add(path);
42446
42591
  }
42592
+ if (out.length < SECOND_HOP_BELOW) {
42593
+ for (const t of code) {
42594
+ const exclude = new Set(out);
42595
+ for (const path of testsThroughOneFile({
42596
+ target: t.path,
42597
+ listing: world.listing,
42598
+ corpus: world.corpus,
42599
+ mapSpecifier: world.mapSpecifier,
42600
+ limit,
42601
+ isTest: world.isTest,
42602
+ exclude,
42603
+ readRel: i2.readRel,
42604
+ deniedPaths: i2.deniedPaths
42605
+ }))
42606
+ add(path);
42607
+ }
42608
+ }
42447
42609
  return out;
42448
42610
  }
42449
42611
  var readFromRoot = (root) => (rel) => {
@@ -42921,6 +43083,20 @@ function healReviewPreviousAttempt(attempt2, blocks, answer) {
42921
43083
  }
42922
43084
 
42923
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
+ }
42924
43100
  async function runHealAttempt(i2) {
42925
43101
  const p = i2.step;
42926
43102
  const keptText = new Map(i2.results.map((r) => [r.targetPath, r.newContent]));
@@ -42938,6 +43114,7 @@ async function runHealAttempt(i2) {
42938
43114
  );
42939
43115
  const args = buildCodegenLoopArgs({ ...p, targets, workspaceListing }, context);
42940
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);
42941
43118
  args.protectedTestPaths = original.protectedTestPaths;
42942
43119
  if (original.baseContext.protectedTestPaths !== void 0) args.baseContext.protectedTestPaths = original.baseContext.protectedTestPaths;
42943
43120
  else delete args.baseContext.protectedTestPaths;
@@ -43157,7 +43334,13 @@ async function runVerifyAndFix(p) {
43157
43334
  p.log({ event: "heal.start", attempt: attemptsRun, healsRun, ...countsOf(v.answer) });
43158
43335
  const startedAt = p.now();
43159
43336
  try {
43160
- 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
+ });
43161
43344
  } catch (err) {
43162
43345
  if (err instanceof SafetyRefusalError) {
43163
43346
  p.onStop?.("refused");
@@ -43700,6 +43883,50 @@ function describeDependencyViolations(check) {
43700
43883
  return check.violations.map((v) => `${v.file} imports ${v.packages.join(", ")}, not a dependency of this repository`).join("; ");
43701
43884
  }
43702
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
+
43703
43930
  // src/testPlacementCheck.ts
43704
43931
  function isDiscovered(targetPath, discoveredFiles) {
43705
43932
  const normalized = targetPath.replace(/\\/g, "/");
@@ -44123,11 +44350,25 @@ async function verifyChange(ctx, results, undoable) {
44123
44350
  const check = checkForRegressions(baseline, after);
44124
44351
  if (check.blocked) {
44125
44352
  const readable = Boolean(baseline.results && after.results);
44126
- const answered = readable ? testAnswerFrom({ baseline, after, changedPaths: results.map((r) => r.targetPath), requiredIds: ctx.requiredAutomationIds, harness: ctx.harness === true }) : null;
44127
- 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}`), {
44128
44368
  check,
44129
44369
  bothSnapshotsReadable: readable,
44130
- ...answered ? { answer: answered.output, failingKey: answered.failingKey } : {}
44370
+ ...answered ? { answer: answered.output, failingKey: answered.failingKey } : {},
44371
+ ...misfits.length > 0 ? { misfits } : {}
44131
44372
  });
44132
44373
  }
44133
44374
  stage = "coverage";
@@ -44224,7 +44465,7 @@ var MAX_ENTRY_CHARS = 200;
44224
44465
  var inside = (path, root) => root === "" || path === root || path.startsWith(`${root}/`);
44225
44466
  var cap = (s) => s.length <= MAX_ENTRY_CHARS ? s : `${s.slice(0, MAX_ENTRY_CHARS - 1)}\u2026`;
44226
44467
  var parentOf2 = (d) => d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "";
44227
- function clip3(text2, max) {
44468
+ function clip4(text2, max) {
44228
44469
  if (text2.length <= max) return { text: text2, truncated: false };
44229
44470
  const cut = text2.slice(0, max);
44230
44471
  const nl = cut.lastIndexOf("\n");
@@ -44242,7 +44483,7 @@ function guidanceFiles(i2, perFile2, total) {
44242
44483
  if (!tracked.has(path) || matchesDeniedPath(path, denied)) continue;
44243
44484
  const raw = i2.readText(path);
44244
44485
  if (raw === null || raw.trim() === "") continue;
44245
- 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));
44246
44487
  out.push({ path, ...clipped });
44247
44488
  left -= clipped.text.length;
44248
44489
  }
@@ -44725,7 +44966,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
44725
44966
  var REPORT_COPY = "final-test-report.xml";
44726
44967
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
44727
44968
  var MAX_FILES = 200;
44728
- var RUNNER_VERSION = true ? "9.3.0-rc.45" : "dev";
44969
+ var RUNNER_VERSION = true ? "9.3.0-rc.47" : "dev";
44729
44970
  function safeDestination(base, repoPath) {
44730
44971
  if (!repoPath || (0, import_node_path24.isAbsolute)(repoPath)) return null;
44731
44972
  const destination = (0, import_node_path24.resolve)(base, repoPath);
@@ -45519,7 +45760,7 @@ async function run(env2) {
45519
45760
  const stepParams = {
45520
45761
  mode: codegenMode,
45521
45762
  ...keepOnGiveUp ? { keepOnGiveUp: true } : {},
45522
- ...conflictsOn ? { conflicts: { decided, titles: approved?.titles ?? [] } } : {},
45763
+ ...conflictsOn ? { conflicts: { decided, titles: approved?.titles ?? [], approvedTests: approved?.approvedTests ?? [] } } : {},
45523
45764
  ...approved && approved.files.length > 0 ? { approved: approved.files } : {},
45524
45765
  ...callFunction ? { callFunction } : {},
45525
45766
  ...twoPhase ? { twoPhase: true, ...packet.requiredTestTypes ? { requiredTestTypes: packet.requiredTestTypes } : {} } : {},
@@ -45576,6 +45817,8 @@ async function run(env2) {
45576
45817
  harness: codegenMode === "loop-tests" && stepParams.harness !== false,
45577
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.
45578
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") } : {},
45579
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.
45580
45823
  baselineMs: timedBaseline.durationMs,
45581
45824
  jobStopAtMs,
@@ -45641,10 +45884,19 @@ async function run(env2) {
45641
45884
  return { blocks: checked.unnecessary, testCount, raw: checked };
45642
45885
  }
45643
45886
  } : {},
45644
- heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs, review }) => {
45887
+ heal: async ({ results: kept, answer, attempt: attempt2, hardStopAtMs, review, misfits }) => {
45645
45888
  const out = {};
45646
45889
  try {
45647
- 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
+ });
45648
45900
  } finally {
45649
45901
  healCalls.push({ ...out.summary ? { summary: out.summary } : {}, ...out.failure ? { failureReason: out.failure.reason } : {} });
45650
45902
  }