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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -150,6 +150,8 @@ it, the callback carries it as `unsuppliedInputs` (at most 10 functions, 5 names
150
150
  noticed" as a check. This is the shape of a change whose new tests pass only because they hand the function the field themselves. It can be
151
151
  wrong (a field that arrives from a database row or a request), so it only warns and never blocks. TypeScript is not covered (QUIKTR-1547).
152
152
 
153
+ **9.3.0-rc.19 — when no old test broke, the test answer says so (test-expectations plan, Part 0).** Checking 11 runs of one pagination bug, every give-up was a test the AI had written itself with a wrong expectation (which item is first, in what order) over code that was already right; where its test data had no explicit date the code stamped the current time, records tied within a millisecond and the order of tied records depended on the clock. The `run_tests` answer for a failed run now carries one more fixed sentence when `regressions` is 0, `newFailures` is above 0 and a baseline was compared with: no test that passed before the change fails now, and the failures counted in `newFailures` are tests that were not in the test run before it. It names no test and quotes no text, changes no key of the answer, and the log line `codegen.run_tests` gains `ownOnly` (a flag). What to do with it is said in the AI Runtime's prompt, which is deployed FIRST (its loop-2 text moved); without that prompt the sentence is only a fact. **Also in rc.19 - a fix may correct a test written in this run, but not empty it (test-expectations plan, Part 4).** The AI Runtime's fix instruction (§24.12f) now lets a fix correct a test the run itself wrote when no test that passed before fails. Wording cannot stop a model from making a test pass by emptying it, so during a fix attempt an edit that removes a test written in this run, renames it away from its `[QP-...]` token, skips it (`it.skip`, `xit`, `it.todo`) or leaves it with fewer `expect`/`assert` checks is refused with the ordinary `protected` answer and the closed reason `test_removed` or `test_emptied`; the AI edits again. Tests that existed before the run stay locked exactly as before, and a first attempt or a clean retry is not touched. JavaScript test files only (like the existing-test rule; TypeScript is QUIKTR-1547); a file it cannot read is never refused. When a fix was made and the change then passed every check, the run also reports which tests written in this run the fix changed, as paths and line numbers only (`testsCorrected`), so the run page and the pull request can say so; `QUIKPILOT_TESTS_CORRECTED=off` stops that report. The rail cannot judge whether a changed expectation is right; it only closes the way of passing by saying nothing. QuikProjects must be deployed first (it validates the new field); an older one ignores it. Nothing else changes, and the sentence about no old test breaking has no switch: a revert of this release restores the old sentence.
154
+
153
155
  **9.3.0-rc.18 — an honest "I cannot finish" no longer throws away a change that is one fix away (QUIKSPL-139).** The AI wrote the fix and its tests, ran the project's tests until its runs were used (4 failing, then 3, then 3) and answered `CANNOT_COMPLETE`; the whole change was thrown away and a second attempt started from nothing, which did worse. Had it said `DONE`, every check would have run and the fix step (QUIKTR-1527) would have continued from the same change. Now a give-up is KEPT when the change would have passed as a `DONE` (something changed, every required test case written, no file cut short or broken) and the AI's LAST test run came back with failing tests that are the change's doing. It is recorded as attempt 1 `kept`, goes through every check like any result, and when only the tests fail the existing fix continues from it (three attempts in all, so at most two fixes). Only in `loop-tests` mode with fixing on (the project's setting above 0); a fix attempt that gives up is not kept again; time-outs, network errors and every other ending behave as before. `QUIKPILOT_KEEP_ON_GIVE_UP=off` restores the clean second attempt without a new release. Nothing new goes to the AI service.
154
156
 
155
157
  **9.3.0-rc.17 — the list of files that hold tests is read from this run's own test run (QUIKTR-1526).** Before the AI picks files, the AI service is given the files the project's test runner discovers and refuses an answer that puts test cases on any other existing file. That list used to come from the last merged QuikPilot run, so a test file added by hand since then was unknown and an honest answer about it was refused (QUIKSPL-140 died at targeting). Now `Setup` and the baseline test run come BEFORE targeting, and the list is built from that run's own report: the files it attributes tests to, put in the form of the file list and kept only if they are in it (the AI service rejects the whole request otherwise); each file that cannot be placed, and each test the report names without a file (a Java class name, a Jest describe title), is counted in `unmappedEntries`, which switches the refusal off. Doubt turns the check off, never on: no test command, no report, a report with no tests, or a wait that ran out sends `ABSENT`. Targeting waits for the baseline at most 90 seconds (`QUIKPILOT_DISCOVERY_WAIT_SECONDS`); past that the run says so in its notes and the baseline carries on beside the code-writing step exactly as before (it is started once). The list QuikProjects stores is no longer used by this runner. The log gets one `test_discovery` line with counts only. No change in the AI service or in QuikProjects.
package/dist/index.js CHANGED
@@ -845,7 +845,7 @@ async function describeQuikTrackFailure(res) {
845
845
 
846
846
  // src/callback.ts
847
847
  async function reportBack(params) {
848
- const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, changesNoTestDependsOn, codegenLoop, unresolved } = params;
848
+ const { callbackUrl, runToken, status, branch, warnings, targeting, baselineFindings, vanishedTests, unsuppliedInputs, changesNoTestDependsOn, testsCorrected, codegenLoop, unresolved } = params;
849
849
  const body = { status };
850
850
  if (branch) body.branch = branch;
851
851
  if (warnings && warnings.length > 0) body.warnings = warnings;
@@ -855,6 +855,7 @@ async function reportBack(params) {
855
855
  if (vanishedTests) body.vanishedTests = vanishedTests;
856
856
  if (unsuppliedInputs && unsuppliedInputs.length > 0) body.unsuppliedInputs = unsuppliedInputs;
857
857
  if (changesNoTestDependsOn && changesNoTestDependsOn.hunks.length > 0) body.changesNoTestDependsOn = changesNoTestDependsOn;
858
+ if (testsCorrected && testsCorrected.files.length > 0) body.testsCorrected = testsCorrected;
858
859
  if (codegenLoop) body.codegenLoop = codegenLoop;
859
860
  const res = await fetch(callbackUrl, {
860
861
  method: "POST",
@@ -10180,6 +10181,153 @@ function protectedAnswer(verdict) {
10180
10181
  return { reason: verdict.why, message: protectedMessage(verdict.why) };
10181
10182
  }
10182
10183
 
10184
+ // src/ownTests.ts
10185
+ var TOKEN = /\[(QP-[^\]\s]+)\]/;
10186
+ var TEST_ROOTS2 = /* @__PURE__ */ new Set(["it", "test"]);
10187
+ var X_ROOTS = /* @__PURE__ */ new Set(["xit", "xtest"]);
10188
+ var SKIP_PROPS = /* @__PURE__ */ new Set(["skip", "todo"]);
10189
+ function walk(node, visit) {
10190
+ visit(node);
10191
+ for (const key of Object.keys(node)) {
10192
+ const value = node[key];
10193
+ if (Array.isArray(value)) {
10194
+ for (const child of value) if (child && typeof child.type === "string") walk(child, visit);
10195
+ } else if (value && typeof value.type === "string") {
10196
+ walk(value, visit);
10197
+ }
10198
+ }
10199
+ }
10200
+ function testChain(callee) {
10201
+ let skipped = false;
10202
+ let e = callee;
10203
+ while (e.type === "MemberExpression") {
10204
+ if (e.property.type === "Identifier" && SKIP_PROPS.has(e.property.name)) skipped = true;
10205
+ e = e.object;
10206
+ }
10207
+ if (e.type !== "Identifier") return null;
10208
+ if (X_ROOTS.has(e.name)) return { root: e.name, skipped: true };
10209
+ if (TEST_ROOTS2.has(e.name)) return { root: e.name, skipped };
10210
+ return null;
10211
+ }
10212
+ function titleOf(call) {
10213
+ const a = call.arguments[0];
10214
+ if (!a) return null;
10215
+ if (a.type === "Literal" && typeof a.value === "string") return a.value;
10216
+ if (a.type === "TemplateLiteral" && a.expressions.length === 0) return a.quasis.map((q) => q.value.cooked ?? "").join("");
10217
+ return null;
10218
+ }
10219
+ function isCheck(call) {
10220
+ const callee = call.callee;
10221
+ if (callee.type === "Identifier") return callee.name === "assert";
10222
+ if (callee.type !== "MemberExpression") return false;
10223
+ let o = callee.object;
10224
+ while (o.type === "MemberExpression") o = o.object;
10225
+ if (o.type === "Identifier") return o.name === "assert";
10226
+ return o.type === "CallExpression" && o.callee.type === "Identifier" && o.callee.name === "expect";
10227
+ }
10228
+ function lineAt2(text, offset2) {
10229
+ let line = 1;
10230
+ for (let i2 = 0; i2 < offset2 && i2 < text.length; i2++) if (text.charCodeAt(i2) === 10) line++;
10231
+ return line;
10232
+ }
10233
+ function findTests(path, text) {
10234
+ const parsed = parseProgram(path, text);
10235
+ if (!parsed) return null;
10236
+ const out = [];
10237
+ walk(parsed.ast, (n) => {
10238
+ if (n.type !== "CallExpression") return;
10239
+ const call = n;
10240
+ const chain = testChain(call.callee);
10241
+ if (!chain) return;
10242
+ const title = titleOf(call);
10243
+ if (title === null) return;
10244
+ const token = TOKEN.exec(title);
10245
+ let checks = 0;
10246
+ for (const arg of call.arguments) {
10247
+ if (arg.type !== "ArrowFunctionExpression" && arg.type !== "FunctionExpression") continue;
10248
+ walk(arg.body, (m) => {
10249
+ if (m.type === "CallExpression" && isCheck(m)) checks++;
10250
+ });
10251
+ }
10252
+ out.push({
10253
+ id: token ? `token:${token[1]}` : `title:${title}`,
10254
+ line: lineAt2(text, call.start),
10255
+ text: text.slice(call.start, call.end).replace(/\s+/g, " "),
10256
+ checks,
10257
+ skipped: chain.skipped
10258
+ });
10259
+ });
10260
+ return out;
10261
+ }
10262
+ function groupById(tests) {
10263
+ const map = /* @__PURE__ */ new Map();
10264
+ for (const t of tests) map.set(t.id, [...map.get(t.id) ?? [], t]);
10265
+ return map;
10266
+ }
10267
+ function ownTestsOf(seed, baseline) {
10268
+ const had = new Set(baseline.map((t) => t.id));
10269
+ const seen = /* @__PURE__ */ new Map();
10270
+ const out = [];
10271
+ for (const t of seed) {
10272
+ const nth = seen.get(t.id) ?? 0;
10273
+ seen.set(t.id, nth + 1);
10274
+ if (!had.has(t.id)) out.push({ test: t, nth });
10275
+ }
10276
+ return out;
10277
+ }
10278
+ function ownTestFloor(input) {
10279
+ try {
10280
+ const seedTests = findTests(input.path, input.seed);
10281
+ const afterTests = findTests(input.path, input.after);
10282
+ if (!seedTests || seedTests.length === 0 || !afterTests) return { ok: true };
10283
+ const baseTests = input.baseline === "" ? [] : findTests(input.path, input.baseline);
10284
+ if (!baseTests) return { ok: true };
10285
+ const own = ownTestsOf(seedTests, baseTests);
10286
+ if (!own || own.length === 0) return { ok: true };
10287
+ const after = groupById(afterTests);
10288
+ const before = input.before !== void 0 ? findTests(input.path, input.before) : null;
10289
+ const beforeById = before ? groupById(before) : null;
10290
+ for (const { test, nth } of own) {
10291
+ const found = after.get(test.id)?.[nth];
10292
+ const line = beforeById?.get(test.id)?.[nth]?.line ?? test.line;
10293
+ if (!found) return { ok: false, why: "test_removed", line };
10294
+ if (found.skipped && !test.skipped || found.checks < test.checks) return { ok: false, why: "test_emptied", line };
10295
+ }
10296
+ return { ok: true };
10297
+ } catch {
10298
+ return { ok: true };
10299
+ }
10300
+ }
10301
+ function ownTestMessage(why, line) {
10302
+ const keep = "Correct its expectation instead, and keep its name, its [id] and a real check of the case.";
10303
+ if (why === "test_removed") return `Your edit removes a test that was written earlier in this run (line ${line}). ${keep}`;
10304
+ return `Your edit leaves a test that was written earlier in this run with fewer checks, or skips it (line ${line}). ${keep}`;
10305
+ }
10306
+ var MAX_PATHS = 10;
10307
+ var MAX_LINES = 20;
10308
+ function correctedOwnTests(input) {
10309
+ const keptByPath = new Map(input.kept.map((r) => [r.targetPath, r.newContent]));
10310
+ const out = [];
10311
+ for (const f of input.final) {
10312
+ try {
10313
+ const keptText = keptByPath.get(f.targetPath);
10314
+ if (keptText === void 0) continue;
10315
+ const keptTests = findTests(f.targetPath, keptText);
10316
+ const finalTests = findTests(f.targetPath, f.newContent);
10317
+ const baseText = input.baselineOf(f.targetPath);
10318
+ const baseTests = baseText === null || baseText === "" ? [] : findTests(f.targetPath, baseText);
10319
+ if (!keptTests || !finalTests || !baseTests) continue;
10320
+ const own = ownTestsOf(keptTests, baseTests);
10321
+ if (!own) continue;
10322
+ const finalById = groupById(finalTests);
10323
+ const lines = own.map(({ test, nth }) => ({ test, found: finalById.get(test.id)?.[nth] })).filter((x) => x.found !== void 0 && x.found.text !== x.test.text).map((x) => x.found.line).sort((a, b) => a - b).slice(0, MAX_LINES);
10324
+ if (lines.length > 0) out.push({ path: f.targetPath, lines });
10325
+ } catch {
10326
+ }
10327
+ }
10328
+ return out.sort((a, b) => a.path.localeCompare(b.path)).slice(0, MAX_PATHS);
10329
+ }
10330
+
10183
10331
  // src/nameScope.ts
10184
10332
  var estraverse4 = __toESM(require_estraverse());
10185
10333
 
@@ -11825,6 +11973,7 @@ function createCodegenWorkspace(args) {
11825
11973
  if (key.startsWith("read_file:") || key.startsWith("grep:") || key.startsWith("list_files:")) ledger.seen.delete(key);
11826
11974
  }
11827
11975
  };
11976
+ const seedTexts = /* @__PURE__ */ new Map();
11828
11977
  for (const kept of args.seed ?? []) {
11829
11978
  const n = normaliseToolPath(kept.targetPath);
11830
11979
  if (!n.ok || matchesDeniedPath(n.path, args.deniedPaths)) throw new SeedRefused();
@@ -11833,8 +11982,10 @@ function createCodegenWorkspace(args) {
11833
11982
  if (!loaded.ok) throw new SeedRefused();
11834
11983
  const text = kept.newContent.charCodeAt(0) === 65279 ? kept.newContent.slice(1) : kept.newContent;
11835
11984
  overlay.setEdited(n.path, toLf(text), { ending: loaded.ending, bom: loaded.bom, originalLf: loaded.lf });
11985
+ seedTexts.set(n.path, toLf(text));
11836
11986
  } else {
11837
11987
  overlay.setCreated(n.path, toLf(kept.newContent));
11988
+ seedTexts.set(n.path, toLf(kept.newContent));
11838
11989
  noteCreated(n.path);
11839
11990
  }
11840
11991
  }
@@ -11897,6 +12048,11 @@ function createCodegenWorkspace(args) {
11897
12048
  return { result: { status: "protected", reason: answer.reason, message: answer.message } };
11898
12049
  }
11899
12050
  }
12051
+ const seeded = seedTexts.get(path);
12052
+ if (seeded !== void 0) {
12053
+ const floor = ownTestFloor({ path, baseline: overlay.isCreated(path) ? "" : base.originalLf, seed: seeded, after: applied.content, before: lf });
12054
+ if (!floor.ok) return { result: { status: "protected", reason: floor.why, message: ownTestMessage(floor.why, floor.line) } };
12055
+ }
11900
12056
  overlay.setEdited(path, applied.content, base);
11901
12057
  cl.writeChars += replace.length;
11902
12058
  edits.set(path, (edits.get(path) ?? 0) + 1);
@@ -11932,6 +12088,11 @@ function createCodegenWorkspace(args) {
11932
12088
  return { result: { status: "budget_exhausted", reason: "write_chars", message: "The limit on text written has been reached; finish with what you have." } };
11933
12089
  }
11934
12090
  const lf = toLf(content);
12091
+ const seeded = seedTexts.get(path);
12092
+ if (seeded !== void 0) {
12093
+ const floor = ownTestFloor({ path, baseline: "", seed: seeded, after: lf, before: overlay.get(path)?.lf });
12094
+ if (!floor.ok) return { result: { status: "protected", reason: floor.why, message: ownTestMessage(floor.why, floor.line) } };
12095
+ }
11935
12096
  overlay.setCreated(path, lf);
11936
12097
  noteCreated(path);
11937
12098
  cl.writeChars += content.length;
@@ -12678,6 +12839,7 @@ var MESSAGES = {
12678
12839
  tests_unavailable: "The tests could not be run here.",
12679
12840
  tests_too_slow: "This project's test suite is too slow to run inside this loop."
12680
12841
  };
12842
+ var TESTS_FAILED_NO_OLD_TEST_BROKE = "Some tests failed. No test that passed before your change fails now: the failures counted in newFailures are tests that were not in the test run before your change. For a test you wrote in this run, messages gives the first line of why it failed.";
12681
12843
  var sha = (s) => (0, import_node_crypto2.createHash)("sha256").update(s).digest("hex");
12682
12844
  function firstLine(text) {
12683
12845
  const line = text.split(LINE_BREAK).map((l) => l.replace(CONTROL_CHARS, "").trim()).find((l) => l.length > 0);
@@ -12761,7 +12923,7 @@ function testAnswerFrom(args) {
12761
12923
  timedOut: false,
12762
12924
  truncated: ordered.length > names.length
12763
12925
  };
12764
- return { output, failingKey: failingKeyOf(ordered, messages, failed), messageCount };
12926
+ return { output, failingKey: failingKeyOf(ordered, messages, failed), messageCount, comparable: Boolean(args.baseline?.results) };
12765
12927
  }
12766
12928
  var RunTestsTool = class {
12767
12929
  constructor(deps) {
@@ -12795,7 +12957,7 @@ var RunTestsTool = class {
12795
12957
  name: RUN_TESTS_TOOL,
12796
12958
  status,
12797
12959
  ...parts.reason ? { reason: parts.reason } : {},
12798
- message: MESSAGES[status] ?? "",
12960
+ message: parts.ownOnly === true ? TESTS_FAILED_NO_OLD_TEST_BROKE : MESSAGES[status] ?? "",
12799
12961
  ...parts.output !== void 0 ? { output: parts.output } : {}
12800
12962
  };
12801
12963
  if (status !== "no_change_since_last_run" && status !== "tests_exhausted") {
@@ -12824,6 +12986,8 @@ var RunTestsTool = class {
12824
12986
  newFailures: entry.newFailures,
12825
12987
  // How many failure messages the AI was shown: a COUNT, never the text.
12826
12988
  messages: parts.messageCount ?? 0,
12989
+ // Whether the answer said that no old test broke (a flag, never a name): so the effect of saying it can be counted.
12990
+ ownOnly: parts.ownOnly === true,
12827
12991
  timedOut: entry.timedOut,
12828
12992
  seconds: entry.seconds
12829
12993
  });
@@ -12896,7 +13060,7 @@ var RunTestsTool = class {
12896
13060
  this.lastFailingKey = null;
12897
13061
  return this.answer(callId, "no_report", { seconds });
12898
13062
  }
12899
- const { output, failingKey, messageCount } = testAnswerFrom({
13063
+ const { output, failingKey, messageCount, comparable } = testAnswerFrom({
12900
13064
  baseline: baseline?.snapshot ?? null,
12901
13065
  after: ran.snapshot,
12902
13066
  changedPaths: files.map((f) => f.path),
@@ -12910,7 +13074,8 @@ var RunTestsTool = class {
12910
13074
  return this.answer(callId, "no_progress", { output, counts, seconds, messageCount });
12911
13075
  }
12912
13076
  this.lastFailingKey = failingKey;
12913
- return this.answer(callId, green ? "tests_passed" : "tests_failed", { output, counts, seconds, messageCount });
13077
+ const ownOnly = comparable && output.regressions === 0 && output.newFailures > 0;
13078
+ return this.answer(callId, green ? "tests_passed" : "tests_failed", { output, counts, seconds, messageCount, ownOnly });
12914
13079
  }
12915
13080
  };
12916
13081
  async function executeRunTestsCall(call, tool, ledger, limits) {
@@ -15151,7 +15316,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
15151
15316
  var REPORT_COPY = "final-test-report.xml";
15152
15317
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
15153
15318
  var MAX_FILES = 200;
15154
- var RUNNER_VERSION = true ? "9.3.0-rc.18" : "dev";
15319
+ var RUNNER_VERSION = true ? "9.3.0-rc.19" : "dev";
15155
15320
  function safeDestination(base, repoPath) {
15156
15321
  if (!repoPath || (0, import_node_path14.isAbsolute)(repoPath)) return null;
15157
15322
  const destination = (0, import_node_path14.resolve)(base, repoPath);
@@ -15708,6 +15873,7 @@ async function run(env2) {
15708
15873
  let vanishedTests;
15709
15874
  let unsuppliedInputs;
15710
15875
  let changesNoTestDependsOn;
15876
+ let testsCorrected;
15711
15877
  const contextLog = [];
15712
15878
  const codegenOut = {};
15713
15879
  let pendingBaseline;
@@ -15882,6 +16048,14 @@ async function run(env2) {
15882
16048
  const suffix = healFailureSuffix(fixed.heal);
15883
16049
  throw suffix ? new Error(`${final.error.message}${suffix}`) : final.error;
15884
16050
  }
16051
+ if (codegenMode === "loop-tests" && fixed.heal && fixed.heal.made > 0 && process.env.QUIKPILOT_TESTS_CORRECTED?.trim().toLowerCase() !== "off") {
16052
+ try {
16053
+ const files = correctedOwnTests({ kept: results, final: fixed.results, baselineOf: (path) => readCommittedText(process.cwd(), path) });
16054
+ console.log(JSON.stringify({ event: "tests_corrected", files: files.length, tests: files.reduce((n, f) => n + f.lines.length, 0) }));
16055
+ if (files.length > 0) testsCorrected = { files };
16056
+ } catch {
16057
+ }
16058
+ }
15885
16059
  if (codegenMode === "loop-tests" && process.env.QUIKPILOT_HUNK_CHECK?.trim().toLowerCase() !== "off") {
15886
16060
  const deadlineAtMs = Math.min(jobStopAtMs - HUNK_CHECK_END_BEFORE_STOP_MS, Date.now() + HUNK_CHECK_MAX_MS);
15887
16061
  if (deadlineAtMs - Date.now() >= HUNK_CHECK_MIN_BUDGET_MS) {
@@ -15986,6 +16160,7 @@ async function run(env2) {
15986
16160
  vanishedTests,
15987
16161
  unsuppliedInputs,
15988
16162
  changesNoTestDependsOn,
16163
+ testsCorrected,
15989
16164
  codegenLoop: codegenOut.loop,
15990
16165
  unresolved: failureReasons.length > 0 ? failureReasons : void 0
15991
16166
  });