@quikit/quikpilot-runner 9.3.0-rc.43 → 9.3.0-rc.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -24773,6 +24773,106 @@ function readTestHistory(input) {
24773
24773
  }
24774
24774
  }
24775
24775
 
24776
+ // src/staleExpectations.ts
24777
+ var MAX_TOKENS = 4;
24778
+ var MAX_TOKEN_CHARS = 60;
24779
+ var MAX_COMMENT_LINES = 6;
24780
+ var MIN_STRING_CHARS = 3;
24781
+ function expectationTokens(code) {
24782
+ const out = /* @__PURE__ */ new Set();
24783
+ for (const m of code.matchAll(/(["'`])((?:\\.|(?!\1)[^\\\n]){3,200})\1/g)) {
24784
+ const value = (m[2] ?? "").trim();
24785
+ if (value.length >= MIN_STRING_CHARS) out.add(value);
24786
+ }
24787
+ for (const m of code.matchAll(/(?<![\w.])(?:\d{3,}|\d+\.\d+)(?![\w.])/g)) out.add(m[0]);
24788
+ return out;
24789
+ }
24790
+ function commentsOf(text2) {
24791
+ const comments = [];
24792
+ let code = "";
24793
+ let line = 0;
24794
+ let i2 = 0;
24795
+ let quote = null;
24796
+ while (i2 < text2.length) {
24797
+ const c = text2[i2];
24798
+ if (quote) {
24799
+ code += c;
24800
+ if (c === "\\" && i2 + 1 < text2.length) {
24801
+ code += text2[i2 + 1];
24802
+ if (text2[i2 + 1] === "\n") line += 1;
24803
+ i2 += 2;
24804
+ continue;
24805
+ }
24806
+ if (c === quote) quote = null;
24807
+ if (c === "\n") line += 1;
24808
+ i2 += 1;
24809
+ continue;
24810
+ }
24811
+ if (c === '"' || c === "'" || c === "`") {
24812
+ quote = c;
24813
+ code += c;
24814
+ i2 += 1;
24815
+ continue;
24816
+ }
24817
+ if (c === "/" && text2[i2 + 1] === "/") {
24818
+ let end = i2;
24819
+ while (end < text2.length && text2[end] !== "\n") end += 1;
24820
+ comments.push({ line, text: text2.slice(i2 + 2, end) });
24821
+ i2 = end;
24822
+ continue;
24823
+ }
24824
+ if (c === "/" && text2[i2 + 1] === "*") {
24825
+ const close = text2.indexOf("*/", i2 + 2);
24826
+ const stop = close === -1 ? text2.length : close + 2;
24827
+ const body = text2.slice(i2 + 2, close === -1 ? text2.length : close);
24828
+ body.split("\n").forEach((part, k) => comments.push({ line: line + k, text: part }));
24829
+ for (const ch of text2.slice(i2, stop)) if (ch === "\n") {
24830
+ code += "\n";
24831
+ line += 1;
24832
+ }
24833
+ i2 = stop;
24834
+ continue;
24835
+ }
24836
+ code += c;
24837
+ if (c === "\n") line += 1;
24838
+ i2 += 1;
24839
+ }
24840
+ return { comments, code };
24841
+ }
24842
+ var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
24843
+ function appearsIn(text2, token) {
24844
+ const isWord = (ch) => ch !== void 0 && /\w/.test(ch);
24845
+ const left = isWord(token[0]) ? "(?<!\\w|\\d\\.)" : "";
24846
+ const right = isWord(token[token.length - 1]) ? "(?!\\w|\\.\\d)" : "";
24847
+ return new RegExp(`${left}${escapeRegExp(token)}${right}`, "i").test(text2);
24848
+ }
24849
+ function staleExpectations(input) {
24850
+ const removed = [...expectationTokens(input.find)].filter((t) => !expectationTokens(input.replace).has(t));
24851
+ if (removed.length === 0) return null;
24852
+ const { comments, code } = commentsOf(input.newTestText);
24853
+ const codeOnly = input.newTitle ? code.replace(input.newTitle, "") : code;
24854
+ const stale = removed.filter((t) => !appearsIn(codeOnly, t));
24855
+ const hits = [];
24856
+ const lines = /* @__PURE__ */ new Set();
24857
+ let inTitle = false;
24858
+ for (const token of stale) {
24859
+ let hit = false;
24860
+ if (input.newTitle && appearsIn(input.newTitle, token)) {
24861
+ inTitle = true;
24862
+ hit = true;
24863
+ }
24864
+ for (const c of comments) {
24865
+ if (appearsIn(c.text, token)) {
24866
+ lines.add(input.firstLine + c.line);
24867
+ hit = true;
24868
+ }
24869
+ }
24870
+ if (hit) hits.push(token.length > MAX_TOKEN_CHARS ? `${token.slice(0, MAX_TOKEN_CHARS - 1)}\u2026` : token);
24871
+ }
24872
+ if (hits.length === 0) return null;
24873
+ return { tokens: hits.slice(0, MAX_TOKENS), inTitle, commentLines: [...lines].sort((a, b) => a - b).slice(0, MAX_COMMENT_LINES) };
24874
+ }
24875
+
24776
24876
  // ../../../qp-slim-runner/node_modules/acorn/dist/acorn.mjs
24777
24877
  var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
24778
24878
  var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
@@ -30592,6 +30692,35 @@ function parseProgram(path, text2) {
30592
30692
  }
30593
30693
 
30594
30694
  // src/testLocate.ts
30695
+ function allTests(file) {
30696
+ return [...file.tests, ...file.generated];
30697
+ }
30698
+ var PLACEHOLDER = /%[sdifjoOp#%]|\$(?:#|[A-Za-z_]\w*(?:\.\w+)*)/g;
30699
+ var escapeRegExp2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
30700
+ function titlePattern(title) {
30701
+ let source = "";
30702
+ let placeholders = false;
30703
+ let at2 = 0;
30704
+ for (const m of title.matchAll(PLACEHOLDER)) {
30705
+ const index = m.index ?? 0;
30706
+ source += escapeRegExp2(title.slice(at2, index));
30707
+ if (m[0] === "%%") {
30708
+ source += "%";
30709
+ } else {
30710
+ source += ".*?";
30711
+ placeholders = true;
30712
+ }
30713
+ at2 = index + m[0].length;
30714
+ }
30715
+ return { source: source + escapeRegExp2(title.slice(at2)), placeholders };
30716
+ }
30717
+ function nameEndsWithTitle(name, title) {
30718
+ return new RegExp(`(?:^|(?: > | \u203A | ))${titlePattern(title).source}$`, "s").test(name);
30719
+ }
30720
+ function rowPattern(test) {
30721
+ const parts = [...test.describes, test.title].map((s) => titlePattern(s).source);
30722
+ return new RegExp(`^(?:${parts.join("(?: > | \u203A | )")}|${parts[parts.length - 1]})$`, "s");
30723
+ }
30595
30724
  var TEST_ROOTS = /* @__PURE__ */ new Set(["it", "test"]);
30596
30725
  var X_ROOTS = /* @__PURE__ */ new Set(["xit", "xtest"]);
30597
30726
  var DESCRIBE_ROOTS = /* @__PURE__ */ new Set(["describe", "context", "suite"]);
@@ -30645,12 +30774,17 @@ function locateTests(path, text2) {
30645
30774
  const call = node;
30646
30775
  const chain = chainOf(call.callee);
30647
30776
  const title = chain ? titleOf(call) : null;
30648
- const each = call.callee.type === "CallExpression" ? chainOf(call.callee.callee) : null;
30777
+ const each = call.callee.type === "CallExpression" ? chainOf(call.callee.callee) : call.callee.type === "TaggedTemplateExpression" ? chainOf(call.callee.tag) : null;
30649
30778
  if (each) {
30650
30779
  innerDynamic = true;
30651
30780
  const eachTitle = titleOf(call);
30652
- if (eachTitle && DESCRIBE_ROOTS.has(each.root)) inner = [...describes, eachTitle.text];
30653
- else if (eachTitle) generated.push(located(call, eachTitle, describes, each.skipped));
30781
+ if (eachTitle && DESCRIBE_ROOTS.has(each.root)) {
30782
+ inner = [...describes, eachTitle.text];
30783
+ } else if (eachTitle) {
30784
+ const test = located(call, eachTitle, describes, each.skipped);
30785
+ const body = call.arguments[1];
30786
+ generated.push(body ? { ...test, bodyStartLine: lineAt(parsed.code, body.start) } : test);
30787
+ }
30654
30788
  }
30655
30789
  if (chain && title) {
30656
30790
  if (DESCRIBE_ROOTS.has(chain.root)) {
@@ -30777,12 +30911,14 @@ function testEditOverreach(input) {
30777
30911
  const after = locateTests(input.path, input.after);
30778
30912
  if (!before) return "the file could not be read before the edit";
30779
30913
  if (!after) return "the file can no longer be read after the edit";
30780
- if (after.tests.length !== before.tests.length) return "a test was added or removed";
30914
+ if (after.tests.length !== before.tests.length || after.generated.length !== before.generated.length) return "a test was added or removed";
30915
+ const beforeAll = allTests(before);
30916
+ const afterAll = allTests(after);
30781
30917
  const wasTests = [];
30782
30918
  const nowTests = [];
30783
30919
  for (const index of input.indexes) {
30784
- const was = before.tests[index];
30785
- const now = after.tests[index];
30920
+ const was = beforeAll[index];
30921
+ const now = afterAll[index];
30786
30922
  if (!was || !now) return "the test could not be found again after the edit";
30787
30923
  wasTests.push(was);
30788
30924
  nowTests.push(now);
@@ -32495,7 +32631,7 @@ var CONFLICT_CASE_FIELDS = ["given", "when", "then"];
32495
32631
  var REJECT_MESSAGES = {
32496
32632
  not_existing_test: "That is not an existing test file of this project that can be reported.",
32497
32633
  unsupported_language: "Only JavaScript and TypeScript test files can be reported.",
32498
- title_not_found: "No test with that title was found in that file. Copy the title exactly as the file writes it.",
32634
+ title_not_found: "No test with that title was found in that file. Copy the title exactly as the file writes it. For a test written once for each row of a table, that is the title in the file with its $name or %s placeholders as they are, not the name of one row.",
32499
32635
  title_not_unique: "More than one test in that file has that title, so it cannot be told which one you mean.",
32500
32636
  no_match: "find was not found in that file. Copy it exactly as read_file shows it.",
32501
32637
  ambiguous: "find matches more than once in that file. Make it longer so it matches once.",
@@ -32506,7 +32642,7 @@ var REJECT_MESSAGES = {
32506
32642
  still_passes_old_code: "With your replacement that test still passes on the code before this run, so it would not show the bug.",
32507
32643
  already_decided: "A person has already decided about that test. Do not report it again.",
32508
32644
  too_many_conflicts: "Too many tests have been reported already. Finish with what you have.",
32509
- generated_test: "That test is written once and run for each row of a table (describe.each or it.each), so a report cannot propose a change to it. Do not report it again: answer CANNOT_COMPLETE, and in your summary name the test and the case it contradicts. A person will change it."
32645
+ generated_test: "That test is written once and run for each row of a table (describe.each or it.each), and its rows were not found in the test run made before your change, so it cannot be checked. Do not report it again: answer CANNOT_COMPLETE, and in your summary name the test and the case it contradicts. A person will change it."
32510
32646
  };
32511
32647
  var RECORDED_MESSAGE = "Recorded. This run will now stop before any code is delivered, and a person will decide about this test. Finish your answer; there is nothing more to do for this test.";
32512
32648
  var BOUNDS = { find: 8e3, replace: 2e4, title: 300, reason: 300, caseText: 1e3, value: 120, why: 300 };
@@ -32533,13 +32669,17 @@ function nameIsTitle(name, title, describes = []) {
32533
32669
  const full = [...describes, title];
32534
32670
  return name === title || name === full.join(" > ") || name === full.join(" ") || name === full.join(" \u203A ");
32535
32671
  }
32536
- function isRowsTitle(sent, title) {
32537
- return sent === title || [" > ", " \u203A ", " "].some((sep) => sent.endsWith(`${sep}${title}`) && sent.length > sep.length + title.length);
32538
- }
32539
32672
  function splitTestId(id) {
32540
32673
  const at2 = id.indexOf("::");
32541
32674
  return at2 === -1 ? { file: null, name: id } : { file: id.slice(0, at2), name: id.slice(at2 + 2) };
32542
32675
  }
32676
+ function matchRows(results, path, test) {
32677
+ const pattern = rowPattern(test);
32678
+ return [...results.entries()].filter(([id]) => {
32679
+ const { file, name } = splitTestId(id);
32680
+ return (file === null || sameFile(file, path)) && pattern.test(name);
32681
+ });
32682
+ }
32543
32683
  function text(v, min, max) {
32544
32684
  return typeof v === "string" && v.length >= min && v.length <= max ? v : null;
32545
32685
  }
@@ -32619,6 +32759,8 @@ var TestConflictTool = class {
32619
32759
  counts = { calls: 0, recorded: 0, rejected: 0 };
32620
32760
  rejectedBy = {};
32621
32761
  generated = /* @__PURE__ */ new Map();
32762
+ /** QUIKTR-1827: every test the AI has reported, whatever the answer was: the tests it has looked at and said something about. */
32763
+ reported = [];
32622
32764
  max;
32623
32765
  /** The reports that stand, one per test, in the order they were first made. */
32624
32766
  recorded() {
@@ -32628,6 +32770,10 @@ var TestConflictTool = class {
32628
32770
  unreportable() {
32629
32771
  return [...this.generated.values()];
32630
32772
  }
32773
+ /** QUIKTR-1827: where each test the AI reported is and the title it gave, answered or rejected. For the check on a give-up; never sent anywhere. */
32774
+ reportedTests() {
32775
+ return this.reported.map((r) => ({ ...r }));
32776
+ }
32631
32777
  /** Counts and closed words only, for the run's log. */
32632
32778
  record() {
32633
32779
  return { ...this.counts, rejectedBy: { ...this.rejectedBy } };
@@ -32649,6 +32795,7 @@ var TestConflictTool = class {
32649
32795
  const parsed = parseConflictReport(call.args, this.deps.caseIds);
32650
32796
  if (!parsed.ok) return finish({ status: "bad_args", message: `${parsed.field} is not valid for report_test_conflict.` });
32651
32797
  const report = parsed.report;
32798
+ if (!this.reported.some((r) => r.path === report.path && r.title === report.testTitle)) this.reported.push({ path: report.path, title: report.testTitle });
32652
32799
  const dupKey = `${call.name}:${JSON.stringify(report)}`;
32653
32800
  const earlier = ledger.seen.get(dupKey);
32654
32801
  if (earlier !== void 0) {
@@ -32680,31 +32827,31 @@ var TestConflictTool = class {
32680
32827
  if (!loaded.ok) return this.reject("not_existing_test");
32681
32828
  const located = locateTests(path.path, loaded.lf);
32682
32829
  if (!located) return this.reject("unsupported_language");
32683
- const matches = located.tests.map((t, index2) => ({ t, index: index2 })).filter(({ t }) => t.title === r.testTitle);
32684
- if (matches.length === 0) {
32685
- const rows = located.generated.find((t) => isRowsTitle(r.testTitle, t.title));
32686
- if (!rows) return this.reject("title_not_found");
32687
- const rowsKey = `${path.path}\0${rows.startLine}`;
32688
- if (!this.generated.has(rowsKey)) this.generated.set(rowsKey, { path: path.path, line: rows.startLine, caseId: r.caseId });
32689
- return this.reject("generated_test");
32690
- }
32830
+ const matches = allTests(located).map((t, index2) => ({ t, index: index2 })).filter(({ t }) => t.title === r.testTitle);
32831
+ if (matches.length === 0) return this.reject("title_not_found");
32691
32832
  if (matches.length > 1) return this.reject("title_not_unique");
32692
32833
  const { t: test, index } = matches[0];
32834
+ const isTable = index >= located.tests.length;
32693
32835
  const applied = applyEdits(loaded.lf, [{ find: r.find, replace: r.replace }]);
32694
32836
  if (!applied.ok) return this.reject(applied.refusals[0]?.kind === "ambiguous" ? "ambiguous" : "no_match");
32695
32837
  const at2 = loaded.lf.indexOf(r.find);
32696
32838
  const changeLine = lineAt(loaded.lf, at2);
32697
32839
  const lastLine = lineAt(loaded.lf, at2 + r.find.length - 1);
32698
- if (changeLine < test.startLine || lastLine > test.endLine) return this.reject("find_outside_test");
32840
+ if (changeLine < (test.bodyStartLine ?? test.startLine) || lastLine > test.endLine) return this.reject("find_outside_test");
32699
32841
  if (testEditOverreach({ path: path.path, before: loaded.lf, after: applied.content, indexes: [index] }) !== null) return this.reject("beyond_expectations");
32700
32842
  const base = await d.baseline().catch(() => null);
32701
32843
  const results = base?.snapshot.results ?? null;
32702
32844
  if (!base || base.snapshot.timedOut === true || !results) return this.reject("baseline_unknown");
32703
- const mine = [...results.entries()].filter(([id]) => {
32845
+ const mine = isTable ? matchRows(results, path.path, test) : [...results.entries()].filter(([id]) => {
32704
32846
  const { file, name } = splitTestId(id);
32705
32847
  return (file === null || sameFile(file, path.path)) && nameIsTitle(name, r.testTitle, test.describes);
32706
32848
  });
32707
- if (mine.length === 0) return this.reject("baseline_unknown");
32849
+ if (mine.length === 0) {
32850
+ if (!isTable) return this.reject("baseline_unknown");
32851
+ const rowsKey = `${path.path}\0${test.startLine}`;
32852
+ if (!this.generated.has(rowsKey)) this.generated.set(rowsKey, { path: path.path, line: test.startLine, caseId: r.caseId });
32853
+ return this.reject("generated_test");
32854
+ }
32708
32855
  if (mine.some(([, passed]) => !passed)) return this.reject("not_passing_before");
32709
32856
  const scrub = d.scrub ?? ((s) => s);
32710
32857
  const history = mapHistory((d.history ?? ((p, title) => readTestHistory({ path: p, title })))(path.path, r.testTitle), scrub);
@@ -32716,6 +32863,7 @@ var TestConflictTool = class {
32716
32863
  endLine: test.endLine,
32717
32864
  changeLine,
32718
32865
  index,
32866
+ ...isTable ? { rows: mine.length } : {},
32719
32867
  history,
32720
32868
  originalLf: loaded.lf,
32721
32869
  ending: loaded.ending,
@@ -32724,7 +32872,7 @@ var TestConflictTool = class {
32724
32872
  };
32725
32873
  this.byTest.set(key, conflict);
32726
32874
  this.counts.recorded += 1;
32727
- d.log?.({ event: "codegen.conflict_recorded", reading: r.reading, phase: d.phase ?? null, historyAvailable: history.available });
32875
+ d.log?.({ event: "codegen.conflict_recorded", reading: r.reading, phase: d.phase ?? null, historyAvailable: history.available, ...isTable ? { rows: mine.length } : {} });
32728
32876
  return { status: "conflict_recorded", message: RECORDED_MESSAGE, output: { history } };
32729
32877
  }
32730
32878
  };
@@ -32756,6 +32904,14 @@ function buildProposalFiles(conflicts) {
32756
32904
  dropped.push(...kept);
32757
32905
  continue;
32758
32906
  }
32907
+ const after = allTests(located);
32908
+ const stale = /* @__PURE__ */ new Map();
32909
+ for (const c of kept) {
32910
+ const t = after[c.index];
32911
+ if (!t) continue;
32912
+ const found = staleExpectations({ find: c.find, replace: c.replace, newTitle: t.title, newTestText: located.code.slice(t.start, t.end), firstLine: t.startLine });
32913
+ if (found) stale.set(c.index, found);
32914
+ }
32759
32915
  files.push({
32760
32916
  path,
32761
32917
  originalLf: first.originalLf,
@@ -32763,7 +32919,8 @@ function buildProposalFiles(conflicts) {
32763
32919
  ending: first.ending,
32764
32920
  bom: first.bom,
32765
32921
  conflicts: kept,
32766
- newTitles: new Map(kept.map((c) => [c.index, located.tests[c.index]?.title ?? c.testTitle]))
32922
+ newTitles: new Map(kept.map((c) => [c.index, after[c.index]?.title ?? c.testTitle])),
32923
+ stale
32767
32924
  });
32768
32925
  }
32769
32926
  return { files, dropped };
@@ -32806,9 +32963,15 @@ function lineOf2(c, file) {
32806
32963
  reason: c.reason,
32807
32964
  correction: c.correction,
32808
32965
  history: c.history,
32809
- oldCodeChecked: c.oldCodeChecked === true
32966
+ oldCodeChecked: c.oldCodeChecked === true,
32967
+ ...c.rows !== void 0 ? { rows: c.rows } : {},
32968
+ ...file.stale.get(c.index) ? { stale: file.stale.get(c.index) } : {}
32810
32969
  };
32811
32970
  }
32971
+ function staleNote(s) {
32972
+ 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
+ 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.`;
32974
+ }
32812
32975
  function oneLine(s) {
32813
32976
  return s.replace(/\s+/g, " ").trim();
32814
32977
  }
@@ -32828,6 +32991,7 @@ function buildProposalMessage(input) {
32828
32991
  ...l.history.available ? [` Added ${l.history.addedAt ?? ""} in ${l.history.addedBySha?.slice(0, 10) ?? "a commit"}${l.history.subject ? `: ${oneLine(l.history.subject)}` : ""}`] : [],
32829
32992
  ...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 ? ", ..." : ""}`] : [],
32830
32993
  ...l.oldCodeChecked ? [" With this change the test fails on the code as it is today, so it shows the bug."] : [],
32994
+ ...l.stale ? [` ${staleNote(l.stale)}`] : [],
32831
32995
  ""
32832
32996
  ]),
32833
32997
  "Machine-readable (read back by QuikPilot; do not edit):",
@@ -32840,6 +33004,11 @@ ${body.join("\n")}
32840
33004
  }
32841
33005
  var isStr = (v, max, min = 1) => typeof v === "string" && v.length >= min && v.length <= max;
32842
33006
  var isLine = (v) => typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 1e7;
33007
+ function isStale(v) {
33008
+ if (typeof v !== "object" || v === null) return false;
33009
+ const s = v;
33010
+ return Array.isArray(s.tokens) && s.tokens.length >= 1 && s.tokens.length <= 4 && s.tokens.every((t) => isStr(t, 60)) && typeof s.inTitle === "boolean" && Array.isArray(s.commentLines) && s.commentLines.length <= 6 && s.commentLines.every(isLine) && (s.inTitle === true || s.commentLines.length > 0);
33011
+ }
32843
33012
  function parseProposalMessage(message) {
32844
33013
  const out = [];
32845
33014
  for (const raw of message.split("\n")) {
@@ -32854,7 +33023,7 @@ function parseProposalMessage(message) {
32854
33023
  const o = j;
32855
33024
  const c = o.correction;
32856
33025
  const h = o.history;
32857
- 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") {
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)) {
32858
33027
  continue;
32859
33028
  }
32860
33029
  out.push(o);
@@ -32901,6 +33070,7 @@ function conflictsReport(p) {
32901
33070
  caseId: l.caseId,
32902
33071
  reading: l.reading,
32903
33072
  oldCodeChecked: l.oldCodeChecked,
33073
+ ...l.rows !== void 0 ? { rows: l.rows } : {},
32904
33074
  ...l.history.available ? {
32905
33075
  history: {
32906
33076
  ...l.history.addedAt ? { addedAt: l.history.addedAt } : {},
@@ -32982,7 +33152,7 @@ function loadApprovedTests(input) {
32982
33152
  continue;
32983
33153
  }
32984
33154
  const before = locateTests(path, toLf(stripBom(current2)));
32985
- const indexes = mine.map((l) => before?.tests.findIndex((t) => t.title === l.title) ?? -1);
33155
+ const indexes = mine.map((l) => (before ? allTests(before) : []).findIndex((t) => t.title === l.title));
32986
33156
  if (!before || indexes.some((i2) => i2 < 0)) {
32987
33157
  warnings.push(`The tests proposed for change in ${path} were not found in it, so that change was not applied.`);
32988
33158
  continue;
@@ -33672,8 +33842,8 @@ async function reportToQuikTest(params) {
33672
33842
  try {
33673
33843
  console.log(`reporting ${report}`);
33674
33844
  const ciUrl = buildCiUrl(githubServerUrl, githubRepository, githubRunId);
33675
- const { readFileSync: readFileSync18 } = await import("node:fs");
33676
- const body = readFileSync18(report);
33845
+ const { readFileSync: readFileSync19 } = await import("node:fs");
33846
+ const body = readFileSync19(report);
33677
33847
  let url = `${resultsUrl}?ciUrl=${encodeURIComponent(ciUrl)}&automationIdFormat=bracket`;
33678
33848
  if (generatedFiles) {
33679
33849
  url += `&generatedFiles=${encodeURIComponent(generatedFiles.join(","))}`;
@@ -33700,6 +33870,66 @@ async function reportToQuikTest(params) {
33700
33870
  }
33701
33871
  }
33702
33872
 
33873
+ // src/giveUpCheck.ts
33874
+ var GIVE_UP_RULE = "give_up_rule";
33875
+ var GIVE_UP_MESSAGE = "Your answer was sent back once: existing tests your change broke are neither reported nor explained. Report each one that expects what a bug case calls wrong with report_test_conflict; otherwise change your code. Read the test file to see what it expects.";
33876
+ var MAX_SENTENCES = 8;
33877
+ var MAX_SENTENCE_CHARS = 300;
33878
+ var MAX_TITLE_CHARS = 150;
33879
+ var MAX_FILE_CHARS = 100;
33880
+ function lastPart(name) {
33881
+ const at2 = Math.max(name.lastIndexOf(" > "), name.lastIndexOf(" \u203A "));
33882
+ return at2 === -1 ? name : name.slice(at2 + 3);
33883
+ }
33884
+ function groupRegressions(ids) {
33885
+ const groups = /* @__PURE__ */ new Map();
33886
+ for (const id of ids) {
33887
+ const { file, name } = splitTestId(id);
33888
+ const title = lastPart(name);
33889
+ const key = `${file ?? ""}\0${title}`;
33890
+ const have = groups.get(key);
33891
+ if (have) have.rows += 1;
33892
+ else groups.set(key, { file: file ?? "", title, rows: 1 });
33893
+ }
33894
+ return [...groups.values()];
33895
+ }
33896
+ var samePlace = (a, b) => {
33897
+ const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
33898
+ const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
33899
+ return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
33900
+ };
33901
+ function unexplainedRegressions(answer, reported) {
33902
+ if (answer.regressions <= 0) return [];
33903
+ const regressed = answer.failingTests.slice(0, answer.regressions);
33904
+ return groupRegressions(regressed).filter(
33905
+ (g) => !reported.some((r) => (g.file === "" || samePlace(g.file, r.path)) && nameEndsWithTitle(g.title, r.title))
33906
+ );
33907
+ }
33908
+ var clip2 = (s, max) => s.length <= max ? s : `${s.slice(0, max - 1)}\u2026`;
33909
+ function sentenceOf(g) {
33910
+ const rows = g.rows > 1 ? ` (${g.rows} rows)` : "";
33911
+ return clip2(`${g.file ? `${clip2(g.file, MAX_FILE_CHARS)}: ` : ""}"${clip2(g.title, MAX_TITLE_CHARS)}"${rows} passed before this run and fails now.`, MAX_SENTENCE_CHARS);
33912
+ }
33913
+ function giveUpSentences(groups) {
33914
+ if (groups.length <= MAX_SENTENCES) return groups.map(sentenceOf);
33915
+ const shown = groups.slice(0, MAX_SENTENCES - 1).map(sentenceOf);
33916
+ return [...shown, `${groups.length - (MAX_SENTENCES - 1)} more existing tests passed before this run and fail now.`];
33917
+ }
33918
+ function oldBehaviourSentence(groups, max = 600) {
33919
+ const parts = groups.map((g) => `${g.file ? `${g.file}: ` : ""}"${g.title}"${g.rows > 1 ? ` (${g.rows} rows)` : ""}`);
33920
+ return clip2(`existing tests that may expect the old behaviour: ${parts.join("; ")}`, max);
33921
+ }
33922
+ function withoutLoop7Words(previous) {
33923
+ if (!previous.steps?.some((s) => s.refused?.includes(GIVE_UP_RULE))) return previous;
33924
+ const steps = previous.steps.map((s) => {
33925
+ if (!s.refused?.includes(GIVE_UP_RULE)) return s;
33926
+ const { refused: refused2, ...rest } = s;
33927
+ const kept = refused2.filter((w) => w !== GIVE_UP_RULE);
33928
+ return kept.length > 0 ? { ...rest, refused: kept } : rest;
33929
+ });
33930
+ return { ...previous, steps };
33931
+ }
33932
+
33703
33933
  // src/regressionCheck.ts
33704
33934
  var import_node_fs7 = require("node:fs");
33705
33935
 
@@ -33958,7 +34188,7 @@ function checkForRegressions(baseline, after) {
33958
34188
  }
33959
34189
  return { blocked: regressions.length > 0 || newFailures.length > 0, regressions, newFailures, preExisting, failureText, failureWhere, failureDetail };
33960
34190
  }
33961
- function describeRegressions(check) {
34191
+ function describeRegressions(check, options = {}) {
33962
34192
  const withText = (id) => {
33963
34193
  const text2 = check.failureText.get(id);
33964
34194
  return text2 ? `${id} (${text2})` : id;
@@ -33966,7 +34196,7 @@ function describeRegressions(check) {
33966
34196
  const parts = [];
33967
34197
  if (check.regressions.length > 0) {
33968
34198
  parts.push(
33969
- `${check.regressions.length} regression(s) (passed before, now fail): ${check.regressions.map(withText).join(", ")}`
34199
+ 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(", ")}`
33970
34200
  );
33971
34201
  }
33972
34202
  if (check.newFailures.length > 0) {
@@ -34457,6 +34687,21 @@ var IMPORTERS_PER_FILE = 20;
34457
34687
  var RELATED_SENTENCE = "Related tests only; the whole suite runs last.";
34458
34688
  var forward2 = (p) => p.split("\\").join("/");
34459
34689
  var unique = (xs) => [...new Set(xs)];
34690
+ function buildTestWorld(d) {
34691
+ const isTest = testRule(d.discoveredTests ?? null);
34692
+ const listing = new Set(d.listing);
34693
+ const corpus = new TestCorpus(
34694
+ listing,
34695
+ (rel) => {
34696
+ const text2 = d.readRel(rel);
34697
+ if (text2 === null) throw new Error("unreadable");
34698
+ return text2;
34699
+ },
34700
+ d.deniedPaths,
34701
+ isTest
34702
+ );
34703
+ return { listing, corpus, mapSpecifier: createAliasMapper({ readText: d.readRel, writeRoot: d.writeRoot }), readRel: d.readRel, isTest };
34704
+ }
34460
34705
  function relatedLimitMs(baselineMs) {
34461
34706
  if (baselineMs === null || !Number.isFinite(baselineMs)) return 3e5;
34462
34707
  return Math.min(RELATED_MAX_LIMIT_MS, Math.max(RELATED_MIN_LIMIT_MS, baselineMs));
@@ -34504,20 +34749,13 @@ function createRelatedPlanner(d) {
34504
34749
  }
34505
34750
  let world = null;
34506
34751
  function theWorld() {
34507
- if (world) return world;
34508
- const readRel = (rel) => readText(abs(rel));
34509
- const listing = new Set(d.listing);
34510
- const corpus = new TestCorpus(
34511
- listing,
34512
- (rel) => {
34513
- const text2 = readRel(rel);
34514
- if (text2 === null) throw new Error("unreadable");
34515
- return text2;
34516
- },
34517
- d.deniedPaths,
34518
- isTest
34519
- );
34520
- world = { listing, corpus, mapSpecifier: createAliasMapper({ readText: readRel, writeRoot: d.writeRoot }), readRel };
34752
+ world ??= buildTestWorld({
34753
+ listing: d.listing,
34754
+ deniedPaths: d.deniedPaths,
34755
+ writeRoot: d.writeRoot,
34756
+ discoveredTests: d.discoveredTests ?? null,
34757
+ readRel: (rel) => readText(abs(rel))
34758
+ });
34521
34759
  return world;
34522
34760
  }
34523
34761
  function findAlwaysRun() {
@@ -35755,7 +35993,7 @@ function wholeFailure(text2, where, max) {
35755
35993
  return `${safe.slice(0, max - 1)}\u2026`;
35756
35994
  }
35757
35995
  var normalisePath = (p) => p.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
35758
- function samePlace(a, b) {
35996
+ function samePlace2(a, b) {
35759
35997
  const x = normalisePath(a);
35760
35998
  const y = normalisePath(b);
35761
35999
  return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
@@ -35766,7 +36004,7 @@ function ownFailureIds(newFailures, changedPaths, requiredIds) {
35766
36004
  const sep = id.indexOf("::");
35767
36005
  const file = sep >= 0 ? id.slice(0, sep) : "";
35768
36006
  const name = sep >= 0 ? id.slice(sep + 2) : id;
35769
- const inChangedFile = file !== "" && changedPaths.some((p) => samePlace(file, p));
36007
+ const inChangedFile = file !== "" && changedPaths.some((p) => samePlace2(file, p));
35770
36008
  const hasToken = requiredIds.some((t) => name.includes(`[${t}]`));
35771
36009
  if (inChangedFile || hasToken) own.add(id);
35772
36010
  }
@@ -40886,7 +41124,7 @@ function withUnreportable(stop, tests) {
40886
41124
  if (stop.summary) carried.summary = stop.summary;
40887
41125
  return carried;
40888
41126
  }
40889
- function samePlace2(a, b) {
41127
+ function samePlace3(a, b) {
40890
41128
  const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
40891
41129
  const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
40892
41130
  return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
@@ -41025,6 +41263,7 @@ async function runCodegenLoop(args, deps) {
41025
41263
  const redRuns = [];
41026
41264
  let redRefusals = 0;
41027
41265
  let importRefusals = 0;
41266
+ let giveUpRefusals = 0;
41028
41267
  let redUnproven;
41029
41268
  const currentRedRuns = () => {
41030
41269
  const now2 = versionOfFiles(filesOnDisk());
@@ -41065,11 +41304,15 @@ async function runCodegenLoop(args, deps) {
41065
41304
  let noProgressStreak = 0;
41066
41305
  let forced = null;
41067
41306
  const started = now();
41307
+ let toCheckList = null;
41308
+ const toCheck = () => toCheckList ??= (args.testsToCheck?.() ?? []).slice(0, 10);
41068
41309
  const buildContext = (turn, isFinal, finalReason) => ({
41069
41310
  ...args.baseContext,
41070
41311
  contractVersion,
41071
41312
  // QUIKTR-1717 (§38.6): what a person has already decided about existing tests. Loop-7 only, and only when there is something to say.
41072
41313
  ...conflictTool && args.conflicts && args.conflicts.decided.length > 0 ? { decidedTests: args.conflicts.decided } : {},
41314
+ // QUIKTR-1827 (§38.8): the existing test files to read first. The tests phase of loop-7 only.
41315
+ ...conflictTool && args.phase === "tests" && toCheck().length > 0 ? { testsToCheck: toCheck() } : {},
41073
41316
  loop: {
41074
41317
  turn,
41075
41318
  maxTurns: limits.maxTurns,
@@ -41077,7 +41320,8 @@ async function runCodegenLoop(args, deps) {
41077
41320
  ...isFinal ? { finalReason } : {},
41078
41321
  // Says this runner can carry a REFUSED answer (24.12a). Without it the runtime fails the request, as it always did.
41079
41322
  acceptsRefused: true,
41080
- ...previousAttempt ? { previousAttempt } : {},
41323
+ // QUIKTR-1827: a request below loop-7 is refused for a rule word only loop-7 raises, so the earlier attempt's steps are told without it.
41324
+ ...previousAttempt ? { previousAttempt: conflictTool ? previousAttempt : withoutLoop7Words(previousAttempt) } : {},
41081
41325
  // QUIKTR-1608 (§33): the phase, and the tests a disagreement step may amend. Harness version only.
41082
41326
  ...harness && args.phase ? { phase: args.phase } : {},
41083
41327
  ...harness && args.phase === "code" && args.lane?.kind === "code" && args.lane.amend ? { amend: args.lane.amend } : {},
@@ -41272,6 +41516,19 @@ async function runCodegenLoop(args, deps) {
41272
41516
  if (conflictTool && conflictTool.unreportable().length > 0) {
41273
41517
  throw unreportableFailure(conflictTool.unreportable(), new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said));
41274
41518
  }
41519
+ const unexplained = conflictTool && lastTestAnswer ? unexplainedRegressions(lastTestAnswer, conflictTool.reportedTests()) : [];
41520
+ if (unexplained.length > 0 && giveUpRefusals < 1 && !isFinal) {
41521
+ giveUpRefusals += 1;
41522
+ const answer = { rules: [GIVE_UP_RULE], violations: giveUpSentences(unexplained), message: GIVE_UP_MESSAGE };
41523
+ refusedStreak += 1;
41524
+ refusedTurns.push({ turn, rules: answer.rules });
41525
+ log({ event: "codegen.give_up_check", turn, outcome: "sent_back", tests: unexplained.length });
41526
+ transcript.push({ turn, toolCalls: [], refused: answer });
41527
+ if (refusedStreak >= REFUSED_STREAK_LIMIT) forced = "refused_repeatedly";
41528
+ forced = settleNextTurn(turn, forced);
41529
+ continue;
41530
+ }
41531
+ if (unexplained.length > 0) log({ event: "codegen.give_up_check", turn, outcome: "gave_up_again", tests: unexplained.length });
41275
41532
  const last = lastTestAnswer;
41276
41533
  const redLeft = harness && args.phase === "tests" ? redProblem() : null;
41277
41534
  if (harness && args.phase === "tests" && currentRedRuns().some((r) => r.failing.length > 0) && handOverRefusal(turn, true) === null && (redLeft === null || redLeft.kind === "passing")) {
@@ -41283,7 +41540,7 @@ async function runCodegenLoop(args, deps) {
41283
41540
  log({ event: "codegen.loop_kept", files: overlay.changedPaths().length, regressions: last.regressions, newFailures: last.newFailures });
41284
41541
  return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary: said ?? "", gaveUp: true, steps: sentSteps(), ...lastTestAnswer ? { lastTestAnswer } : {} };
41285
41542
  }
41286
- throw new CodegenLoopFailure("cannot_complete", void 0, void 0, said, said);
41543
+ throw new CodegenLoopFailure("cannot_complete", void 0, void 0, unexplained.length > 0 ? oldBehaviourSentence(unexplained, MAX_PREVIOUS_DETAIL_CHARS) : said, said);
41287
41544
  }
41288
41545
  if (body.outcome === "DONE") {
41289
41546
  log({ event: "codegen.loop_turn", turn, outcome: "done", requestTokens, elapsedMs: now() - turnStarted, calls: [] });
@@ -41358,7 +41615,7 @@ async function runCodegenLoop(args, deps) {
41358
41615
  const doneSummary = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : "";
41359
41616
  const lane = args.lane;
41360
41617
  if (harness && args.phase === "code" && lane?.kind === "code" && !lane.amend && args.keepOnGiveUp === true) {
41361
- const red2 = currentRedRuns().filter((r) => r.failing.some((name) => lane.frozen.some((p) => samePlace2(name.split("::")[0] ?? "", p)))).at(-1);
41618
+ const red2 = currentRedRuns().filter((r) => r.failing.some((name) => lane.frozen.some((p) => samePlace3(name.split("::")[0] ?? "", p)))).at(-1);
41362
41619
  if (red2) {
41363
41620
  log({ event: "codegen.loop_kept", files: overlay.changedPaths().length, regressions: red2.answer.regressions, newFailures: red2.answer.newFailures, after: "done" });
41364
41621
  return { results: overlay.results(), summary: snapshot("gave_up_kept"), doneSummary, gaveUp: true, steps: sentSteps(), lastTestAnswer: red2.answer };
@@ -41618,11 +41875,11 @@ async function runPhases(i2) {
41618
41875
  }
41619
41876
  const frozenFailing = (d2.lastTestAnswer?.failingTests ?? []).filter((name) => {
41620
41877
  const file2 = name.split("::")[0] ?? "";
41621
- return file2 !== "" && tests.frozen.some((path2) => samePlace2(file2, path2));
41878
+ return file2 !== "" && tests.frozen.some((path2) => samePlace3(file2, path2));
41622
41879
  });
41623
41880
  const token = frozenFailing.length === 1 && d2.lastTestAnswer?.truncated !== true ? QP_TOKEN.exec(frozenFailing[0])?.[0] : void 0;
41624
41881
  const file = token ? frozenFailing[0].split("::")[0] ?? "" : "";
41625
- const amend = token ? tests.frozen.filter((path2) => samePlace2(file, path2)).slice(0, 1) : [];
41882
+ const amend = token ? tests.frozen.filter((path2) => samePlace3(file, path2)).slice(0, 1) : [];
41626
41883
  phases.push(record("code", "gave_up", d2.summary));
41627
41884
  i2.log({ event: "codegen.phase_end", attempt: i2.attempt, phase: "code", outcome: "gave_up", amendFiles: amend.length, frozenFailing: frozenFailing.length });
41628
41885
  if (amend.length === 0 || !token) return { done: d2, tests, phases, summaries };
@@ -41942,8 +42199,8 @@ function pairedTestPaths(codePath, listing, isTest = isTestTarget) {
41942
42199
  const stem = m[1].toLowerCase();
41943
42200
  const dir = dirOf(codePath);
41944
42201
  const parent = parentOf(dir);
41945
- const join14 = (d, leaf) => d === "" ? leaf : `${d}/${leaf}`;
41946
- const homes = /* @__PURE__ */ new Set([dir, join14(dir, "__tests__"), join14(parent, "__tests__"), join14(parent, "tests"), join14(parent, "test")]);
42202
+ const join15 = (d, leaf) => d === "" ? leaf : `${d}/${leaf}`;
42203
+ const homes = /* @__PURE__ */ new Set([dir, join15(dir, "__tests__"), join15(parent, "__tests__"), join15(parent, "tests"), join15(parent, "test")]);
41947
42204
  const found = [];
41948
42205
  for (const path of listing) {
41949
42206
  if (!homes.has(dirOf(path))) continue;
@@ -42122,13 +42379,14 @@ function mapModeMessage(phase, reason) {
42122
42379
  var CUT_AT = 190;
42123
42380
  function failingNameIs(id, file, conflict) {
42124
42381
  const { file: where, name } = splitTestId(id);
42125
- if (where !== null && !samePlace3(where, file.path)) return false;
42382
+ if (where !== null && !samePlace4(where, file.path)) return false;
42126
42383
  const title = file.newTitles.get(conflict.index) ?? conflict.testTitle;
42384
+ if (conflict.rows !== void 0) return rowPattern({ describes: conflict.describes, title }).test(name);
42127
42385
  const full = [...conflict.describes, title];
42128
42386
  const candidates = [title, full.join(" > "), full.join(" "), full.join(" \u203A ")];
42129
42387
  return candidates.includes(name) || name.length >= CUT_AT && candidates.some((c) => c.startsWith(name));
42130
42388
  }
42131
- function samePlace3(a, b) {
42389
+ function samePlace4(a, b) {
42132
42390
  const x = a.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
42133
42391
  const y = b.replace(/\\/g, "/").replace(/^(\.\/)+/, "");
42134
42392
  return x === y || x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
@@ -42168,6 +42426,34 @@ async function verifyOnOldCode(conflicts, run2, log = () => void 0) {
42168
42426
  return { kept, dropped };
42169
42427
  }
42170
42428
 
42429
+ // src/testsToCheck.ts
42430
+ var import_node_fs16 = require("node:fs");
42431
+ var import_node_path18 = require("node:path");
42432
+ var MAX_TESTS_TO_CHECK = 10;
42433
+ function testsToCheck(i2) {
42434
+ const limit = Math.min(MAX_TESTS_TO_CHECK, Math.max(0, i2.limit ?? MAX_TESTS_TO_CHECK));
42435
+ const world = buildTestWorld(i2);
42436
+ const code = i2.targets.filter((t) => t.kind === "EXISTING" && !world.isTest(t.path) && (t.automationIds?.length ?? 0) === 0);
42437
+ if (code.length === 0 || limit === 0) return [];
42438
+ const taken = new Set(i2.targets.map((t) => t.path));
42439
+ const out = [];
42440
+ const add = (path) => {
42441
+ if (out.length < limit && !taken.has(path) && !out.includes(path)) out.push(path);
42442
+ };
42443
+ for (const t of code) for (const path of pairedTestPaths(t.path, world.listing, world.isTest)) add(path);
42444
+ for (const t of code) {
42445
+ for (const path of testsImporting({ target: t.path, listing: world.listing, corpus: world.corpus, mapSpecifier: world.mapSpecifier, limit, isTest: world.isTest })) add(path);
42446
+ }
42447
+ return out;
42448
+ }
42449
+ var readFromRoot = (root) => (rel) => {
42450
+ try {
42451
+ return (0, import_node_fs16.readFileSync)((0, import_node_path18.join)(root, rel), "utf8");
42452
+ } catch {
42453
+ return null;
42454
+ }
42455
+ };
42456
+
42171
42457
  // src/codegenStep.ts
42172
42458
  function testTargetPaths(targets, discoveredTests) {
42173
42459
  const isTest = testRule(discoveredTests);
@@ -42228,6 +42514,26 @@ function orderProtectedForWire(protectedPaths, targetPaths, shownTests) {
42228
42514
  keyed.sort((a, b) => a.tier - b.tier || b.near - a.near || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
42229
42515
  return keyed.map((k) => k.path);
42230
42516
  }
42517
+ function testsToCheckOf(p) {
42518
+ const tests = p.tests;
42519
+ if (!tests) return {};
42520
+ return {
42521
+ testsToCheck: () => {
42522
+ try {
42523
+ const read = p.readFile ? (rel) => {
42524
+ try {
42525
+ return p.readFile(rel);
42526
+ } catch {
42527
+ return null;
42528
+ }
42529
+ } : readFromRoot(tests.root);
42530
+ return testsToCheck({ targets: p.targets, listing: p.workspaceListing, deniedPaths: p.deniedPaths, writeRoot: p.writeRoot ?? "", discoveredTests: discoveredTestsOf(p.testDiscovery) ?? null, readRel: read });
42531
+ } catch {
42532
+ return [];
42533
+ }
42534
+ }
42535
+ };
42536
+ }
42231
42537
  function buildCodegenLoopArgs(p, context = collectLoopContext({
42232
42538
  targets: p.targets,
42233
42539
  listing: p.workspaceListing,
@@ -42284,7 +42590,7 @@ function buildCodegenLoopArgs(p, context = collectLoopContext({
42284
42590
  ...p.mode === "loop-tests" && p.tests && p.harness !== false ? { harness: true } : {},
42285
42591
  ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.tools2 ? { tools2: p.tools2 } : {},
42286
42592
  ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.callFunction ? { callFunction: p.callFunction } : {},
42287
- ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.tools2?.notes === true && p.conflicts ? { conflicts: p.conflicts } : {},
42593
+ ...p.mode === "loop-tests" && p.tests && p.harness !== false && p.tools2?.notes === true && p.conflicts ? { conflicts: p.conflicts, ...testsToCheckOf(p) } : {},
42288
42594
  // An approved test change stands whatever version the AI Runtime speaks: a person decided it.
42289
42595
  ...p.approved && p.approved.length > 0 ? { approved: p.approved.map((r) => ({ targetPath: r.targetPath, newContent: r.newContent })) } : {}
42290
42596
  };
@@ -42348,6 +42654,23 @@ function oldCodeRunner(args, log, now) {
42348
42654
  return isTestAnswer(answer.output) ? answer.output : null;
42349
42655
  };
42350
42656
  }
42657
+ async function settleConflictStop(p, args, stop, clock) {
42658
+ const run2 = args?.tests && clock.now() < clock.hardStopAtMs ? oldCodeRunner(args, clock.log, clock.now) : null;
42659
+ const verified = await verifyOnOldCode(stop.conflicts, run2, clock.log);
42660
+ clock.log({ event: "codegen.conflict_stop", reported: stop.conflicts.length, standing: verified.kept.length, dropped: verified.dropped.length });
42661
+ if (verified.kept.length === 0) return null;
42662
+ const settled = new TestConflictStop(verified.kept, stop.fallback);
42663
+ if (stop.summary) {
42664
+ settled.summary = stop.summary;
42665
+ p.out.loop = buildCodegenLoopRecord({ ...stop.summary, stopReason: "test_conflict" });
42666
+ }
42667
+ return settled;
42668
+ }
42669
+ function warnUnreportable(p, stop) {
42670
+ for (const t of stop.unreportable) {
42671
+ warn(p, `Another existing test, in ${t.path} line ${t.line}, also expects what case ${t.caseId} calls wrong. It is written once for many rows, so no change to it was proposed: look at it before you approve.`);
42672
+ }
42673
+ }
42351
42674
  async function runCodegenStep(p) {
42352
42675
  if (p.mode !== "loop" && p.mode !== "loop-tests") return perFile(p);
42353
42676
  const testSetup = p.mode === "loop-tests" ? p.tests : void 0;
@@ -42423,9 +42746,7 @@ async function runCodegenStep(p) {
42423
42746
  if (err instanceof TestConflictStop) {
42424
42747
  const settled = await settleStop(err);
42425
42748
  if (settled) {
42426
- for (const t of err.unreportable) {
42427
- warn(p, `Another existing test, in ${t.path} line ${t.line}, also expects what case ${t.caseId} calls wrong. It is written once for many rows, so no change to it was proposed: look at it before you approve.`);
42428
- }
42749
+ warnUnreportable(p, err);
42429
42750
  throw settled;
42430
42751
  }
42431
42752
  return { failure: err.fallback instanceof CodegenLoopFailure ? err.fallback : new CodegenLoopFailure("cannot_complete") };
@@ -42435,16 +42756,7 @@ async function runCodegenStep(p) {
42435
42756
  };
42436
42757
  const settleStop = async (stop) => {
42437
42758
  await guardTree();
42438
- const run2 = args?.tests && now() < hardStopAtMs ? oldCodeRunner(args, log, now) : null;
42439
- const verified = await verifyOnOldCode(stop.conflicts, run2, log);
42440
- log({ event: "codegen.conflict_stop", reported: stop.conflicts.length, standing: verified.kept.length, dropped: verified.dropped.length });
42441
- if (verified.kept.length === 0) return null;
42442
- const settled = new TestConflictStop(verified.kept, stop.fallback);
42443
- if (stop.summary) {
42444
- settled.summary = stop.summary;
42445
- p.out.loop = buildCodegenLoopRecord({ ...stop.summary, stopReason: "test_conflict" });
42446
- }
42447
- return settled;
42759
+ return settleConflictStop(p, args, stop, { log, now, hardStopAtMs });
42448
42760
  };
42449
42761
  const finish = (done, attempts) => {
42450
42762
  if (done.steps && done.steps.steps.length > 0) p.out.steps = done.steps;
@@ -42550,7 +42862,7 @@ async function runCodegenStep(p) {
42550
42862
  }
42551
42863
 
42552
42864
  // src/codegenHeal.ts
42553
- var import_node_fs16 = require("node:fs");
42865
+ var import_node_fs17 = require("node:fs");
42554
42866
 
42555
42867
  // src/heal.ts
42556
42868
  var MAX_ATTEMPTS_IN_ALL = 3;
@@ -42616,7 +42928,7 @@ async function runHealAttempt(i2) {
42616
42928
  const created = i2.results.map((r) => r.targetPath).filter((path) => !listed.has(path));
42617
42929
  const workspaceListing = [...p.workspaceListing, ...created];
42618
42930
  const targets = p.targets.map((t) => t.kind === "NEW_FILE" && keptText.has(t.path) ? { ...t, kind: "EXISTING" } : t);
42619
- const disk = p.readFile ?? ((path) => (0, import_node_fs16.readFileSync)(path, "utf8"));
42931
+ const disk = p.readFile ?? ((path) => (0, import_node_fs17.readFileSync)(path, "utf8"));
42620
42932
  const readFile = (path) => keptText.get(path) ?? disk(path);
42621
42933
  const discoveredTests = discoveredTestsOf(p.testDiscovery);
42622
42934
  const context = collectLoopContext({ targets, listing: workspaceListing, deniedPaths: p.deniedPaths, writeRoot: p.writeRoot ?? "", ...discoveredTests ? { discoveredTests } : {}, readFile });
@@ -42625,7 +42937,7 @@ async function runHealAttempt(i2) {
42625
42937
  collectLoopContext({ targets: p.targets, listing: p.workspaceListing, deniedPaths: p.deniedPaths, writeRoot: p.writeRoot ?? "", ...discoveredTests ? { discoveredTests } : {}, readFile: disk })
42626
42938
  );
42627
42939
  const args = buildCodegenLoopArgs({ ...p, targets, workspaceListing }, context);
42628
- delete args.conflicts;
42940
+ if (i2.review !== void 0 || i2.answer.regressions <= 0) delete args.conflicts;
42629
42941
  args.protectedTestPaths = original.protectedTestPaths;
42630
42942
  if (original.baseContext.protectedTestPaths !== void 0) args.baseContext.protectedTestPaths = original.baseContext.protectedTestPaths;
42631
42943
  else delete args.baseContext.protectedTestPaths;
@@ -42658,6 +42970,18 @@ async function runHealAttempt(i2) {
42658
42970
  if (done.steps && done.steps.steps.length > 0) p.out.steps = done.steps;
42659
42971
  return done.results;
42660
42972
  } catch (err) {
42973
+ if (err instanceof TestConflictStop) {
42974
+ i2.out.summary = err.summary;
42975
+ const log = p.deps?.log ?? ((e) => console.log(JSON.stringify(e)));
42976
+ const settled = await settleConflictStop(p, args, err, { log, now, hardStopAtMs: i2.hardStopAtMs });
42977
+ if (settled) {
42978
+ warnUnreportable(p, err);
42979
+ throw settled;
42980
+ }
42981
+ const failure = err.fallback instanceof CodegenLoopFailure ? err.fallback : new CodegenLoopFailure("cannot_complete");
42982
+ i2.out.failure = failure;
42983
+ throw failure;
42984
+ }
42661
42985
  if (err instanceof CodegenLoopFailure) {
42662
42986
  i2.out.failure = err;
42663
42987
  i2.out.summary = err.summary;
@@ -42859,11 +43183,11 @@ async function runVerifyAndFix(p) {
42859
43183
 
42860
43184
  // src/hunkCheck.ts
42861
43185
  var import_node_child_process9 = require("node:child_process");
42862
- var import_node_fs18 = require("node:fs");
42863
- var import_node_path18 = require("node:path");
43186
+ var import_node_fs19 = require("node:fs");
43187
+ var import_node_path19 = require("node:path");
42864
43188
 
42865
43189
  // src/scopeCheck.ts
42866
- var import_node_fs17 = require("node:fs");
43190
+ var import_node_fs18 = require("node:fs");
42867
43191
  var ROUTE_METHOD_RE = /\b(GET|POST|PUT|PATCH|DELETE)\b/i;
42868
43192
  var ROUTE_PATH_RE = /\/[A-Za-z0-9_\-{}[\]]+(?:\/[A-Za-z0-9_\-:{}[\]]+)+/;
42869
43193
  var ROUTE_EXPORT_RE = /\bexport\s+(?:async\s+)?function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/;
@@ -42910,7 +43234,7 @@ function checkApiScope(results, targets, apiChanges) {
42910
43234
  } else {
42911
43235
  let currentContent;
42912
43236
  try {
42913
- currentContent = (0, import_node_fs17.readFileSync)(targetPath, "utf8");
43237
+ currentContent = (0, import_node_fs18.readFileSync)(targetPath, "utf8");
42914
43238
  } catch {
42915
43239
  currentContent = "";
42916
43240
  }
@@ -43006,7 +43330,7 @@ async function runHunkCheck(input) {
43006
43330
  let slowestRunMs = input.baselineMs ?? 3e4;
43007
43331
  const runOnce = async (c) => {
43008
43332
  const reportBefore = findReport(input.root);
43009
- const preserve = reportBefore ? [(0, import_node_path18.relative)(input.root, reportBefore).split("\\").join("/")] : [];
43333
+ const preserve = reportBefore ? [(0, import_node_path19.relative)(input.root, reportBefore).split("\\").join("/")] : [];
43010
43334
  const content = `${c.bom ? "\uFEFF" : ""}${fromLf(revertHunk(c.originalLf, c.currentLf, c.hunk), c.ending)}`;
43011
43335
  const startedWall = Date.now();
43012
43336
  const startedAt = now();
@@ -43016,13 +43340,13 @@ async function runHunkCheck(input) {
43016
43340
  input.root,
43017
43341
  [{ path: c.file, content }],
43018
43342
  async () => {
43019
- if (reportBefore) (0, import_node_fs18.rmSync)(reportBefore, { force: true });
43343
+ if (reportBefore) (0, import_node_fs19.rmSync)(reportBefore, { force: true });
43020
43344
  const run2 = await runCommand2(input.command, perRunMs, input.root);
43021
43345
  if (!run2.started || run2.timedOut) return "unknown";
43022
43346
  const report = findReport(input.root);
43023
43347
  if (!report) return "unknown";
43024
43348
  try {
43025
- if ((0, import_node_fs18.statSync)(report).mtimeMs < startedWall - FRESH_SLACK_MS3) return "unknown";
43349
+ if ((0, import_node_fs19.statSync)(report).mtimeMs < startedWall - FRESH_SLACK_MS3) return "unknown";
43026
43350
  } catch {
43027
43351
  return "unknown";
43028
43352
  }
@@ -43042,7 +43366,7 @@ async function runHunkCheck(input) {
43042
43366
  };
43043
43367
  const runRelated = async (c, plan, limitMs) => {
43044
43368
  const reportBefore = findReport(input.root);
43045
- const preserve = reportBefore ? [(0, import_node_path18.relative)(input.root, reportBefore).split("\\").join("/")] : [];
43369
+ const preserve = reportBefore ? [(0, import_node_path19.relative)(input.root, reportBefore).split("\\").join("/")] : [];
43046
43370
  const content = `${c.bom ? "\uFEFF" : ""}${fromLf(revertHunk(c.originalLf, c.currentLf, c.hunk), c.ending)}`;
43047
43371
  const startedAt = now();
43048
43372
  result.relatedRuns += 1;
@@ -43051,7 +43375,7 @@ async function runHunkCheck(input) {
43051
43375
  input.root,
43052
43376
  [{ path: c.file, content }],
43053
43377
  async () => {
43054
- (0, import_node_fs18.rmSync)(plan.report, { force: true });
43378
+ (0, import_node_fs19.rmSync)(plan.report, { force: true });
43055
43379
  try {
43056
43380
  const run2 = await runCommand2(plan.command, limitMs, plan.cwd);
43057
43381
  if (!run2.started || run2.timedOut) return "unknown";
@@ -43059,7 +43383,7 @@ async function runHunkCheck(input) {
43059
43383
  if (!after.results || after.results.size === 0) return "unknown";
43060
43384
  return checkForRegressions(input.baseline, after).blocked ? "needed" : "unneeded";
43061
43385
  } finally {
43062
- (0, import_node_fs18.rmSync)(plan.report, { force: true });
43386
+ (0, import_node_fs19.rmSync)(plan.report, { force: true });
43063
43387
  }
43064
43388
  },
43065
43389
  { ...input.tree, preserve }
@@ -43186,8 +43510,8 @@ function healFailureSuffix(heal) {
43186
43510
  }
43187
43511
 
43188
43512
  // src/dependencyCheck.ts
43189
- var import_node_fs19 = require("node:fs");
43190
- var import_node_path19 = require("node:path");
43513
+ var import_node_fs20 = require("node:fs");
43514
+ var import_node_path20 = require("node:path");
43191
43515
  var SCANNABLE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"];
43192
43516
  var IMPORT_RE = /(?:\bimport\b[^'"]*?\bfrom\s*|\bimport\s*\(\s*|\bexport\b[^'"]*?\bfrom\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"]+)\1/g;
43193
43517
  var NODE_BUILTINS = /* @__PURE__ */ new Set([
@@ -43275,14 +43599,14 @@ function dependencyNames(pkg) {
43275
43599
  ]);
43276
43600
  }
43277
43601
  function readDeclaredDependencies(results, workspaceRoot) {
43278
- const packageJsonPath = (0, import_node_path19.join)((0, import_node_path19.resolve)(workspaceRoot ?? "."), "package.json");
43279
- const generated = results.find((r) => (0, import_node_path19.resolve)(r.targetPath) === packageJsonPath);
43602
+ const packageJsonPath = (0, import_node_path20.join)((0, import_node_path20.resolve)(workspaceRoot ?? "."), "package.json");
43603
+ const generated = results.find((r) => (0, import_node_path20.resolve)(r.targetPath) === packageJsonPath);
43280
43604
  let raw;
43281
43605
  if (generated) {
43282
43606
  raw = generated.newContent;
43283
43607
  } else {
43284
43608
  try {
43285
- raw = (0, import_node_fs19.readFileSync)(packageJsonPath, "utf8");
43609
+ raw = (0, import_node_fs20.readFileSync)(packageJsonPath, "utf8");
43286
43610
  } catch {
43287
43611
  raw = null;
43288
43612
  }
@@ -43346,16 +43670,16 @@ function stripJsonComments(text2) {
43346
43670
  return out.replace(/,(\s*[}\]])/g, "$1");
43347
43671
  }
43348
43672
  function resolveAliasPrefixes(results, workspaceRoot) {
43349
- const root = (0, import_node_path19.resolve)(workspaceRoot ?? ".");
43673
+ const root = (0, import_node_path20.resolve)(workspaceRoot ?? ".");
43350
43674
  for (const filename of ["tsconfig.json", "jsconfig.json"]) {
43351
- const configPath = (0, import_node_path19.join)(root, filename);
43352
- const generated = results.find((r) => (0, import_node_path19.resolve)(r.targetPath) === configPath);
43675
+ const configPath = (0, import_node_path20.join)(root, filename);
43676
+ const generated = results.find((r) => (0, import_node_path20.resolve)(r.targetPath) === configPath);
43353
43677
  let raw;
43354
43678
  if (generated) {
43355
43679
  raw = generated.newContent;
43356
43680
  } else {
43357
43681
  try {
43358
- raw = (0, import_node_fs19.readFileSync)(configPath, "utf8");
43682
+ raw = (0, import_node_fs20.readFileSync)(configPath, "utf8");
43359
43683
  } catch {
43360
43684
  raw = null;
43361
43685
  }
@@ -43605,13 +43929,13 @@ function describeUnsuppliedInputs(found) {
43605
43929
  }
43606
43930
 
43607
43931
  // src/unsuppliedInputsDisk.ts
43608
- var import_node_fs20 = require("node:fs");
43932
+ var import_node_fs21 = require("node:fs");
43609
43933
  var MAX_READ_BYTES = 1e6;
43610
43934
  function readCheckoutText(path) {
43611
43935
  try {
43612
- const info = (0, import_node_fs20.statSync)(path);
43936
+ const info = (0, import_node_fs21.statSync)(path);
43613
43937
  if (!info.isFile() || info.size > MAX_READ_BYTES) return null;
43614
- const bytes = (0, import_node_fs20.readFileSync)(path);
43938
+ const bytes = (0, import_node_fs21.readFileSync)(path);
43615
43939
  if (bytes.includes(0)) return null;
43616
43940
  return bytes.toString("utf8");
43617
43941
  } catch {
@@ -43641,7 +43965,7 @@ function describeVanishedTests(vanished) {
43641
43965
  }
43642
43966
 
43643
43967
  // src/verifyChange.ts
43644
- var import_node_path20 = require("node:path");
43968
+ var import_node_path21 = require("node:path");
43645
43969
 
43646
43970
  // src/packageUse.ts
43647
43971
  var import_node_child_process10 = require("node:child_process");
@@ -43668,7 +43992,7 @@ function packageImportedInWorkspace(pkg, root, cwd = process.cwd()) {
43668
43992
  }
43669
43993
 
43670
43994
  // src/verifyChange.ts
43671
- var import_node_fs21 = require("node:fs");
43995
+ var import_node_fs22 = require("node:fs");
43672
43996
  async function verifyChange(ctx, results, undoable) {
43673
43997
  const cwd = ctx.cwd ?? process.cwd();
43674
43998
  const now = ctx.now ?? Date.now;
@@ -43703,7 +44027,7 @@ async function verifyChange(ctx, results, undoable) {
43703
44027
  const depCheck = checkImportDependencies(results, readDeclaredDependencies(results, packet.workspaceRoot), resolveAliasPrefixes(results, packet.workspaceRoot), {
43704
44028
  originalOf: (path) => {
43705
44029
  try {
43706
- return (0, import_node_fs21.readFileSync)((0, import_node_path20.join)(cwd, path), "utf8");
44030
+ return (0, import_node_fs22.readFileSync)((0, import_node_path21.join)(cwd, path), "utf8");
43707
44031
  } catch (err) {
43708
44032
  return err.code === "ENOENT" ? "" : null;
43709
44033
  }
@@ -43753,7 +44077,7 @@ async function verifyChange(ctx, results, undoable) {
43753
44077
  flushedAt = now();
43754
44078
  if (undoable) {
43755
44079
  const report = findJUnitReport(cwd);
43756
- const ignore = report ? [(0, import_node_path20.relative)(cwd, report).split("\\").join("/")] : [];
44080
+ const ignore = report ? [(0, import_node_path21.relative)(cwd, report).split("\\").join("/")] : [];
43757
44081
  const flush = undoableFlush(cwd, results, flushCodegenResults, { ignore });
43758
44082
  undo = () => flush.undo();
43759
44083
  } else {
@@ -43800,7 +44124,7 @@ async function verifyChange(ctx, results, undoable) {
43800
44124
  if (check.blocked) {
43801
44125
  const readable = Boolean(baseline.results && after.results);
43802
44126
  const answered = readable ? testAnswerFrom({ baseline, after, changedPaths: results.map((r) => r.targetPath), requiredIds: ctx.requiredAutomationIds, harness: ctx.harness === true }) : null;
43803
- return fail(new Error(`QuikPilot's generated code introduced test failures \u2014 ${describeRegressions(check)}`), {
44127
+ return fail(new Error(`QuikPilot's generated code introduced test failures \u2014 ${describeRegressions(check, { existingTestsMayExpectOldBehaviour: ctx.conflictsOn === true })}`), {
43804
44128
  check,
43805
44129
  bothSnapshotsReadable: readable,
43806
44130
  ...answered ? { answer: answered.output, failingKey: answered.failingKey } : {}
@@ -43829,7 +44153,7 @@ ${violations.join("\n")}`);
43829
44153
  }
43830
44154
 
43831
44155
  // src/run.ts
43832
- var import_node_fs24 = require("node:fs");
44156
+ var import_node_fs25 = require("node:fs");
43833
44157
 
43834
44158
  // src/mapMode.ts
43835
44159
  var MAP_ENV = "QUIKPILOT_MAP";
@@ -43887,7 +44211,7 @@ function buildToolsV2Env(i2) {
43887
44211
  }
43888
44212
 
43889
44213
  // src/repoMap.ts
43890
- var import_node_path21 = require("node:path");
44214
+ var import_node_path22 = require("node:path");
43891
44215
  var MAP_BUDGET_TOKENS = 4e3;
43892
44216
  var MAX_FOLDERS = 200;
43893
44217
  var MAX_LANGUAGES = 12;
@@ -43900,7 +44224,7 @@ var MAX_ENTRY_CHARS = 200;
43900
44224
  var inside = (path, root) => root === "" || path === root || path.startsWith(`${root}/`);
43901
44225
  var cap = (s) => s.length <= MAX_ENTRY_CHARS ? s : `${s.slice(0, MAX_ENTRY_CHARS - 1)}\u2026`;
43902
44226
  var parentOf2 = (d) => d.includes("/") ? d.slice(0, d.lastIndexOf("/")) : "";
43903
- function clip2(text2, max) {
44227
+ function clip3(text2, max) {
43904
44228
  if (text2.length <= max) return { text: text2, truncated: false };
43905
44229
  const cut = text2.slice(0, max);
43906
44230
  const nl = cut.lastIndexOf("\n");
@@ -43918,7 +44242,7 @@ function guidanceFiles(i2, perFile2, total) {
43918
44242
  if (!tracked.has(path) || matchesDeniedPath(path, denied)) continue;
43919
44243
  const raw = i2.readText(path);
43920
44244
  if (raw === null || raw.trim() === "") continue;
43921
- const clipped = clip2(i2.scrub(raw.replace(/\r\n/g, "\n")).trim(), Math.min(perFile2, left));
44245
+ const clipped = clip3(i2.scrub(raw.replace(/\r\n/g, "\n")).trim(), Math.min(perFile2, left));
43922
44246
  out.push({ path, ...clipped });
43923
44247
  left -= clipped.text.length;
43924
44248
  }
@@ -43929,7 +44253,7 @@ function guidanceFiles(i2, perFile2, total) {
43929
44253
  function languages(listing) {
43930
44254
  const counts = /* @__PURE__ */ new Map();
43931
44255
  for (const p of listing) {
43932
- const ext = import_node_path21.posix.extname(p).toLowerCase();
44256
+ const ext = import_node_path22.posix.extname(p).toLowerCase();
43933
44257
  if (ext && ext.length <= 12) counts.set(ext, (counts.get(ext) ?? 0) + 1);
43934
44258
  }
43935
44259
  return [...counts.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, MAX_LANGUAGES).map(([ext, n]) => `${ext} ${n}`);
@@ -43945,7 +44269,7 @@ function testFacts(i2) {
43945
44269
  const depth = i2.writeRoot === "" ? 0 : i2.writeRoot.split("/").length;
43946
44270
  for (const t of tests) {
43947
44271
  const parts = t.split("/");
43948
- const folder = parts.length > depth + 1 ? parts.slice(0, depth + 1).join("/") : import_node_path21.posix.dirname(t);
44272
+ const folder = parts.length > depth + 1 ? parts.slice(0, depth + 1).join("/") : import_node_path22.posix.dirname(t);
43949
44273
  byFolder.set(folder, (byFolder.get(folder) ?? 0) + 1);
43950
44274
  }
43951
44275
  for (const [folder, n] of [...byFolder.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, 3)) {
@@ -44055,7 +44379,7 @@ function buildRepoMap(i2) {
44055
44379
  }
44056
44380
 
44057
44381
  // src/workspacePackages.ts
44058
- var import_node_path22 = require("node:path");
44382
+ var import_node_path23 = require("node:path");
44059
44383
  var MAX_READ_ROOTS = 8;
44060
44384
  function isObject2(x) {
44061
44385
  return typeof x === "object" && x !== null && !Array.isArray(x);
@@ -44117,8 +44441,8 @@ function workspacePackages(readText, packageJsonPaths) {
44117
44441
  const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => globMatcher(p.slice(1)));
44118
44442
  const out = [];
44119
44443
  for (const file of packageJsonPaths) {
44120
- if (import_node_path22.posix.basename(file) !== "package.json" || file === "package.json" || file.split("/").includes("node_modules")) continue;
44121
- const folder = import_node_path22.posix.dirname(file);
44444
+ if (import_node_path23.posix.basename(file) !== "package.json" || file === "package.json" || file.split("/").includes("node_modules")) continue;
44445
+ const folder = import_node_path23.posix.dirname(file);
44122
44446
  if (!include.some((re) => re.test(folder)) || exclude.some((re) => re.test(folder))) continue;
44123
44447
  const text2 = readText(file);
44124
44448
  const json = text2 === null ? null : parseJsonc(text2);
@@ -44387,34 +44711,34 @@ async function fetchPacket(packetUrl, runToken, githubRunId) {
44387
44711
  }
44388
44712
 
44389
44713
  // src/phase0.ts
44390
- var import_node_fs22 = require("node:fs");
44714
+ var import_node_fs23 = require("node:fs");
44391
44715
  function writePhase0Marker(runId) {
44392
- (0, import_node_fs22.mkdirSync)(".quikpilot", { recursive: true });
44393
- (0, import_node_fs22.appendFileSync)(".quikpilot/phase0-marker.txt", `QuikPilot Phase 0 skeleton marker for run ${runId}
44716
+ (0, import_node_fs23.mkdirSync)(".quikpilot", { recursive: true });
44717
+ (0, import_node_fs23.appendFileSync)(".quikpilot/phase0-marker.txt", `QuikPilot Phase 0 skeleton marker for run ${runId}
44394
44718
  `);
44395
44719
  }
44396
44720
 
44397
44721
  // src/failureArtifact.ts
44398
- var import_node_fs23 = require("node:fs");
44399
- var import_node_path23 = require("node:path");
44722
+ var import_node_fs24 = require("node:fs");
44723
+ var import_node_path24 = require("node:path");
44400
44724
  var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
44401
44725
  var REPORT_COPY = "final-test-report.xml";
44402
44726
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
44403
44727
  var MAX_FILES = 200;
44404
- var RUNNER_VERSION = true ? "9.3.0-rc.43" : "dev";
44728
+ var RUNNER_VERSION = true ? "9.3.0-rc.45" : "dev";
44405
44729
  function safeDestination(base, repoPath) {
44406
- if (!repoPath || (0, import_node_path23.isAbsolute)(repoPath)) return null;
44407
- const destination = (0, import_node_path23.resolve)(base, repoPath);
44408
- const rel = (0, import_node_path23.relative)(base, destination);
44409
- if (!rel || rel.startsWith("..") || (0, import_node_path23.isAbsolute)(rel)) return null;
44730
+ if (!repoPath || (0, import_node_path24.isAbsolute)(repoPath)) return null;
44731
+ const destination = (0, import_node_path24.resolve)(base, repoPath);
44732
+ const rel = (0, import_node_path24.relative)(base, destination);
44733
+ if (!rel || rel.startsWith("..") || (0, import_node_path24.isAbsolute)(rel)) return null;
44410
44734
  return destination;
44411
44735
  }
44412
44736
  function writeFailureArtifact(input) {
44413
44737
  if (input.results.length === 0) return { written: false };
44414
44738
  try {
44415
- const base = (0, import_node_path23.resolve)(input.cwd, FAILURE_ARTIFACT_DIR);
44416
- (0, import_node_fs23.rmSync)(base, { recursive: true, force: true });
44417
- (0, import_node_fs23.mkdirSync)(base, { recursive: true });
44739
+ const base = (0, import_node_path24.resolve)(input.cwd, FAILURE_ARTIFACT_DIR);
44740
+ (0, import_node_fs24.rmSync)(base, { recursive: true, force: true });
44741
+ (0, import_node_fs24.mkdirSync)(base, { recursive: true });
44418
44742
  const files = [];
44419
44743
  const skipped = [];
44420
44744
  for (const result of input.results) {
@@ -44423,8 +44747,8 @@ function writeFailureArtifact(input) {
44423
44747
  skipped.push(result.targetPath);
44424
44748
  continue;
44425
44749
  }
44426
- (0, import_node_fs23.mkdirSync)((0, import_node_path23.dirname)(destination), { recursive: true });
44427
- (0, import_node_fs23.writeFileSync)(destination, result.newContent);
44750
+ (0, import_node_fs24.mkdirSync)((0, import_node_path24.dirname)(destination), { recursive: true });
44751
+ (0, import_node_fs24.writeFileSync)(destination, result.newContent);
44428
44752
  files.push({ path: result.targetPath, bytes: Buffer.byteLength(result.newContent) });
44429
44753
  }
44430
44754
  let testReport = "none";
@@ -44432,7 +44756,7 @@ function writeFailureArtifact(input) {
44432
44756
  if (input.testReport.byteLength > MAX_REPORT_BYTES) {
44433
44757
  testReport = "too-large";
44434
44758
  } else {
44435
- (0, import_node_fs23.writeFileSync)((0, import_node_path23.join)(base, REPORT_COPY), input.testReport);
44759
+ (0, import_node_fs24.writeFileSync)((0, import_node_path24.join)(base, REPORT_COPY), input.testReport);
44436
44760
  testReport = "included";
44437
44761
  }
44438
44762
  }
@@ -44452,8 +44776,8 @@ function writeFailureArtifact(input) {
44452
44776
  failureReasons: input.failureReasons
44453
44777
  };
44454
44778
  const text2 = JSON.stringify(manifest, (_key, value) => typeof value === "string" ? scrubSecrets(value, input.secrets) : value, 2);
44455
- (0, import_node_fs23.writeFileSync)((0, import_node_path23.join)(base, "manifest.json"), text2);
44456
- return { written: (0, import_node_fs23.existsSync)((0, import_node_path23.join)(base, "manifest.json")) };
44779
+ (0, import_node_fs24.writeFileSync)((0, import_node_path24.join)(base, "manifest.json"), text2);
44780
+ return { written: (0, import_node_fs24.existsSync)((0, import_node_path24.join)(base, "manifest.json")) };
44457
44781
  } catch (err) {
44458
44782
  console.warn(`::warning::Could not keep the failed run's files: ${err instanceof Error ? err.message : String(err)}`);
44459
44783
  return { written: false };
@@ -45051,7 +45375,7 @@ async function run(env2) {
45051
45375
  const workspaceListing = listWorkspaceFiles(writeRoot === "" ? null : writeRoot);
45052
45376
  const readCheckoutText2 = (path) => {
45053
45377
  try {
45054
- return (0, import_node_fs24.readFileSync)(path, "utf8");
45378
+ return (0, import_node_fs25.readFileSync)(path, "utf8");
45055
45379
  } catch {
45056
45380
  return null;
45057
45381
  }
@@ -45250,6 +45574,8 @@ async function run(env2) {
45250
45574
  requiredAutomationIds: claimedAutomationIds(stepParams),
45251
45575
  // The harness version, unless the AI Runtime refused it during code writing (then every fix speaks loop-2 too).
45252
45576
  harness: codegenMode === "loop-tests" && stepParams.harness !== false,
45577
+ // 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
+ conflictsOn,
45253
45579
  // 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.
45254
45580
  baselineMs: timedBaseline.durationMs,
45255
45581
  jobStopAtMs,
@@ -45259,7 +45585,7 @@ async function run(env2) {
45259
45585
  const at2 = id.indexOf("::");
45260
45586
  const file = at2 === -1 ? "" : id.slice(0, at2);
45261
45587
  const name = at2 === -1 ? id : id.slice(at2 + 2);
45262
- return approved.titles.some((t) => (file === "" || file.endsWith(t.path) || t.path.endsWith(file)) && (name === t.title || name.endsWith(` ${t.title}`) || name.endsWith(`> ${t.title}`)));
45588
+ return approved.titles.some((t) => (file === "" || file.endsWith(t.path) || t.path.endsWith(file)) && nameEndsWithTitle(name, t.title));
45263
45589
  }
45264
45590
  } : {}
45265
45591
  };