@quikit/quikpilot-runner 9.3.0-rc.25 → 9.3.0-rc.26

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.26 — no pull request from tests that prove nothing, and no import of a name that does not exist (QUIKTR-1608, live runs QUIKSPL-220 and QUIKSPL-226).** On rc.24 and rc.25 two pull requests (#118, #123) went out with every test green and the bug not fixed: none of the AI's tests had failed on the code before the change, so they tested nothing. #123 also imported `scaleShares` from `./splits.js`, which does not export it: plain Node cannot load that module, but vitest gives the name as `undefined`. (1) In phase `tests`, when none of the tests for the cases held to the red check has been seen failing on the code before any change, the one send-back says so ("None of your tests fails on the code before any change ... At least one case describes the bug"), and if the next DONE is the same the attempt fails `no_test_shows_bug` (log `codegen.red_check` `no_test_shows_bug`); the second attempt writes the tests again, and if it ends the same way no pull request is opened. A phase 1 whose tests were never run on the change as it stands ends the same way. (2) At DONE outside phase `tests` (the code phase, a fix, the review fix), the runner parses each changed JavaScript file (`importCheck.ts`) and names any name imported, or re-exported, from a module of the repository that the module does not export. The first time the DONE is sent back naming the file and the name (log `codegen.import_check`); after that the attempt ends `syntax_error`. ES modules only, relative imports only, and nothing is reported when it cannot be told for sure (`export *` from elsewhere, a destructured export, CommonJS, a module that cannot be found). Phase `tests` is not checked: a test may import what phase 2 is to write. Runner only.
154
+
153
155
  **9.3.0-rc.25 — a corrected test must still show the bug (QUIKTR-1608, live run QUIKSPL-220).** On rc.24 the code phase of Bug 4 could not fix the bug and gave up with exactly one frozen test failing: the one test that proved the bug. The one correction, kept to that test's expected value as rc.24 requires, made it expect what the old code returns, so every test passed and PR #118 fixed nothing. After the correction the runner now runs the tests twice on the code before any change, once with the test as phase 1 froze it and once corrected (its own check, outside the AI's allowances; log `codegen.amend_old_code`). A test that failed there before its correction and passes after it no longer shows the bug: the run fails `test_case_disagree` and no pull request is opened. A test that passed on the old code by design is not held to it, and when either run gives no answer the correction stands. Runner only.
154
156
 
155
157
  **9.3.0-rc.24 — cases that must keep working, a tighter amendment, and a stop for loops that change nothing (QUIKTR-1608, live batch of 15 Oct).** On rc.23 no pull request of bugs 1 to 7 was fully right. Six bugs had an approved case that passes on the old code by design ("splits that already divide cleanly must not change"); the red check told the AI to make it fail, and the AI broke a correct test. (1) Phase 1's DONE is sent back once, not twice, and the sentence says a case that must keep working may stay as it is; the second DONE is accepted and the reviewer warned about the cases seen passing. A phase-1 give-up with at least one own test failing on the untouched code is phase 1 done, the passing ones warned the same way. (2) A phase-2 DONE whose latest run still fails a frozen test is handed over as a give-up (live run QUIKSPL-210). (3) The amendment runs only when exactly one frozen test fails (QUIKSPL-209 rewrote three to match wrong code), and afterwards the runner checks that only that test's expected values changed: its set-up, its inputs and the rest of the file must be as phase 2 left them, or the run fails `test_case_disagree`. (4) Under the harness version, three replies in a row that change nothing (repeats, no-op or missed edits, unchanged test runs) make the next turn the last (`no_progress`). The AI Runtime's three phase paragraphs (contract §33.6) say the same; deploy them first.
package/dist/index.js CHANGED
@@ -1027,20 +1027,20 @@ function runTestCommand(command) {
1027
1027
  }
1028
1028
  function runTestCommandAsync(command) {
1029
1029
  if (!command) return Promise.resolve("success");
1030
- return new Promise((resolve6) => {
1030
+ return new Promise((resolve7) => {
1031
1031
  const child = (0, import_node_child_process.spawn)(command, { shell: "/bin/bash", stdio: "inherit", env: repositoryCommandEnv() });
1032
- child.on("exit", (code) => resolve6(code === 0 ? "success" : "failure"));
1033
- child.on("error", () => resolve6("failure"));
1032
+ child.on("exit", (code) => resolve7(code === 0 ? "success" : "failure"));
1033
+ child.on("error", () => resolve7("failure"));
1034
1034
  });
1035
1035
  }
1036
1036
  function runCommandWithTimeout(command, timeoutMs) {
1037
- return new Promise((resolve6) => {
1037
+ return new Promise((resolve7) => {
1038
1038
  let settled = false;
1039
1039
  const finish = (outcome) => {
1040
1040
  if (settled) return;
1041
1041
  settled = true;
1042
1042
  clearTimeout(timer);
1043
- resolve6(outcome);
1043
+ resolve7(outcome);
1044
1044
  };
1045
1045
  const child = (0, import_node_child_process.spawn)(command, {
1046
1046
  shell: "/bin/bash",
@@ -1068,7 +1068,7 @@ function killProcessGroup(child) {
1068
1068
  }
1069
1069
  }
1070
1070
  function runCapturedCommand(argv, opts) {
1071
- return new Promise((resolve6) => {
1071
+ return new Promise((resolve7) => {
1072
1072
  let settled = false;
1073
1073
  let timedOut = false;
1074
1074
  let graceTimer;
@@ -1079,7 +1079,7 @@ function runCapturedCommand(argv, opts) {
1079
1079
  settled = true;
1080
1080
  clearTimeout(timer);
1081
1081
  if (graceTimer) clearTimeout(graceTimer);
1082
- resolve6({ stdout: Buffer.concat(chunks).toString("utf8"), timedOut, started });
1082
+ resolve7({ stdout: Buffer.concat(chunks).toString("utf8"), timedOut, started });
1083
1083
  };
1084
1084
  const child = (0, import_node_child_process.spawn)(argv[0], argv.slice(1), {
1085
1085
  cwd: opts.cwd,
@@ -1106,7 +1106,7 @@ function runCapturedCommand(argv, opts) {
1106
1106
  }
1107
1107
  var KILL_GRACE_MS = 2e3;
1108
1108
  function runTestCommandWithLimit(command, timeoutMs, cwd) {
1109
- return new Promise((resolve6) => {
1109
+ return new Promise((resolve7) => {
1110
1110
  let settled = false;
1111
1111
  let timedOut = false;
1112
1112
  let graceTimer;
@@ -1115,7 +1115,7 @@ function runTestCommandWithLimit(command, timeoutMs, cwd) {
1115
1115
  settled = true;
1116
1116
  clearTimeout(timer);
1117
1117
  if (graceTimer) clearTimeout(graceTimer);
1118
- resolve6(run2);
1118
+ resolve7(run2);
1119
1119
  };
1120
1120
  const child = (0, import_node_child_process.spawn)(command, {
1121
1121
  shell: "/bin/bash",
@@ -2782,6 +2782,7 @@ function secondAttemptFloorMs(a) {
2782
2782
  var REASON_WORDS = {
2783
2783
  contract_rejected: "the AI service did not accept the request (it may be switched off)",
2784
2784
  test_case_disagree: "its code and its own test for an approved case still disagreed after one correction of the test",
2785
+ no_test_shows_bug: "none of its tests failed on the code before the change, so none of them showed the bug",
2785
2786
  semantic_mismatch: "the AI service and the runner disagreed about the request",
2786
2787
  http_error: "the AI service returned an error",
2787
2788
  transport: "the AI service could not be reached",
@@ -13865,6 +13866,113 @@ function stepsOf(transcript, toolResults) {
13865
13866
  return trimmed > 0 ? { steps, stepsTrimmed: trimmed } : { steps };
13866
13867
  }
13867
13868
 
13869
+ // src/importCheck.ts
13870
+ var MAX_REPORTED = 5;
13871
+ function resolve3(fromPath, spec, exists) {
13872
+ const dir = fromPath.includes("/") ? fromPath.slice(0, fromPath.lastIndexOf("/")) : "";
13873
+ const out = [];
13874
+ for (const part of [...dir ? dir.split("/") : [], ...spec.split("/")]) {
13875
+ if (part === "" || part === ".") continue;
13876
+ if (part === "..") {
13877
+ if (out.length === 0) return null;
13878
+ out.pop();
13879
+ } else out.push(part);
13880
+ }
13881
+ const base = out.join("/");
13882
+ for (const candidate of [base, `${base}.js`, `${base}.mjs`, `${base}.cjs`, `${base}/index.js`]) {
13883
+ if (isCheckablePath(candidate) && exists(candidate)) return candidate;
13884
+ }
13885
+ return null;
13886
+ }
13887
+ function nameOf(n) {
13888
+ const x = n;
13889
+ if (!x) return null;
13890
+ if (x.type === "Identifier") return x.name;
13891
+ if (x.type === "Literal" && typeof x.value === "string") return x.value;
13892
+ return null;
13893
+ }
13894
+ function exportedNames(ast) {
13895
+ const names = /* @__PURE__ */ new Set();
13896
+ for (const node of ast.body) {
13897
+ if (node.type === "ExportDefaultDeclaration") names.add("default");
13898
+ else if (node.type === "ExportAllDeclaration") {
13899
+ const as = nameOf(node.exported);
13900
+ if (!as) return null;
13901
+ names.add(as);
13902
+ } else if (node.type === "ExportNamedDeclaration") {
13903
+ const d = node.declaration;
13904
+ if (d?.type === "FunctionDeclaration" || d?.type === "ClassDeclaration") {
13905
+ const n = nameOf(d.id);
13906
+ if (!n) return null;
13907
+ names.add(n);
13908
+ } else if (d?.type === "VariableDeclaration") {
13909
+ for (const v of d.declarations) {
13910
+ const n = nameOf(v.id);
13911
+ if (!n) return null;
13912
+ names.add(n);
13913
+ }
13914
+ }
13915
+ for (const s of node.specifiers ?? []) {
13916
+ const n = nameOf(s.exported);
13917
+ if (!n) return null;
13918
+ names.add(n);
13919
+ }
13920
+ }
13921
+ }
13922
+ return names;
13923
+ }
13924
+ function relativeImports(ast) {
13925
+ const out = [];
13926
+ for (const node of ast.body) {
13927
+ const spec = node.source && typeof node.source.value === "string" ? node.source.value : null;
13928
+ if (!spec || !spec.startsWith(".")) continue;
13929
+ if (node.type === "ImportDeclaration") {
13930
+ for (const s of node.specifiers ?? []) {
13931
+ if (s.type === "ImportSpecifier") {
13932
+ const n = nameOf(s.imported);
13933
+ if (n) out.push([n, spec]);
13934
+ } else if (s.type === "ImportDefaultSpecifier") out.push(["default", spec]);
13935
+ }
13936
+ } else if (node.type === "ExportNamedDeclaration") {
13937
+ for (const s of node.specifiers ?? []) {
13938
+ const n = nameOf(s.local);
13939
+ if (n) out.push([n, spec]);
13940
+ }
13941
+ }
13942
+ }
13943
+ return out;
13944
+ }
13945
+ function missingImports(changed, read, exists) {
13946
+ const out = [];
13947
+ const exportsOf = /* @__PURE__ */ new Map();
13948
+ for (const path of changed) {
13949
+ const text = read(path);
13950
+ if (text === null) continue;
13951
+ const parsed = parseProgram(path, text);
13952
+ if (!parsed || parsed.sourceType !== "module") continue;
13953
+ for (const [name, spec] of relativeImports(parsed.ast)) {
13954
+ const target = resolve3(path, spec, exists);
13955
+ if (!target) continue;
13956
+ if (!exportsOf.has(target)) {
13957
+ const t = read(target);
13958
+ const p = t === null ? null : parseProgram(target, t);
13959
+ exportsOf.set(target, p && p.sourceType === "module" ? exportedNames(p.ast) : null);
13960
+ }
13961
+ const names = exportsOf.get(target);
13962
+ if (names && !names.has(name)) {
13963
+ out.push({ path, name, from: spec });
13964
+ if (out.length >= MAX_REPORTED) return out;
13965
+ }
13966
+ }
13967
+ }
13968
+ return out;
13969
+ }
13970
+ function missingImportSentence(m) {
13971
+ const first = m[0];
13972
+ const more = m.length > 1 ? ` (and ${m.length - 1} more)` : "";
13973
+ return `${first.path} imports ${first.name} from ${first.from}, which does not export it${more}: export it there, or change the import.`.slice(0, 300);
13974
+ }
13975
+
13868
13976
  // src/targetingErrors.ts
13869
13977
  var DeniedPathError = class extends Error {
13870
13978
  constructor(message) {
@@ -14302,6 +14410,7 @@ async function runCodegenLoop(args, deps) {
14302
14410
  let sent = { entries: 0, results: 0 };
14303
14411
  const redRuns = [];
14304
14412
  let redRefusals = 0;
14413
+ let importRefusals = 0;
14305
14414
  let redUnproven;
14306
14415
  const currentRedRuns = () => {
14307
14416
  const now2 = versionOfFiles(filesOnDisk());
@@ -14323,7 +14432,7 @@ async function runCodegenLoop(args, deps) {
14323
14432
  if (passing.length > 0) {
14324
14433
  const one = passing.length === 1;
14325
14434
  const named = passing.slice(0, 4).map((id) => `[${id}]`).join(", ");
14326
- const sentence = `${named} ${one ? "passes" : "pass"} on the code before any change. A case that shows the bug: make its test fail for the reason the case gives. A case that must keep working: leave its test as it is and answer DONE again.`;
14435
+ const sentence = passing.length + unrun.length === ids.length ? `None of your tests fails on the code before any change (${named} ${one ? "passes" : "pass"}), so none shows the bug. At least one case describes the bug: make its test fail for the reason the case gives.` : `${named} ${one ? "passes" : "pass"} on the code before any change. A case that shows the bug: make its test fail for the reason the case gives. A case that must keep working: leave its test as it is and answer DONE again.`;
14327
14436
  return { ids: passing, sentence: sentence.slice(0, 300), kind: "passing" };
14328
14437
  }
14329
14438
  if (unrun.length > 0) {
@@ -14537,9 +14646,56 @@ async function runCodegenLoop(args, deps) {
14537
14646
  forced = settleNextTurn(turn, forced);
14538
14647
  continue;
14539
14648
  }
14649
+ const ids = args.redCheckIds ?? [];
14650
+ const runs = currentRedRuns();
14651
+ if (ids.length > 0 && !ids.some((id) => runs.some((r) => r.failing.some((name) => name.includes(`[${id}]`))))) {
14652
+ log({ event: "codegen.red_check", turn, outcome: "no_test_shows_bug", cases: ids.length });
14653
+ const said = "None of the tests failed on the code before any change, so none showed the bug.";
14654
+ throw new CodegenLoopFailure("no_test_shows_bug", void 0, void 0, said, said);
14655
+ }
14540
14656
  if (red.kind === "passing") redUnproven = red.ids;
14541
14657
  log({ event: "codegen.red_check", turn, outcome: red.kind === "passing" ? "ended_unproven" : "ended_unrun", cases: red.ids.length });
14542
14658
  }
14659
+ if (harness && args.phase !== "tests") {
14660
+ const onDisk = (p) => {
14661
+ if (matchesDeniedPath(p, args.deniedPaths) !== null) return false;
14662
+ try {
14663
+ const s = env2.fs.lstat(p);
14664
+ return s.isFile && !s.isSymlink && env2.fs.realpathInside(p);
14665
+ } catch {
14666
+ return false;
14667
+ }
14668
+ };
14669
+ const missing = missingImports(
14670
+ overlay.changedPaths(),
14671
+ (p) => {
14672
+ const own = overlay.get(p)?.lf;
14673
+ if (own !== void 0) return own;
14674
+ try {
14675
+ return onDisk(p) ? new TextDecoder().decode(env2.fs.readBytes(p)) : null;
14676
+ } catch {
14677
+ return null;
14678
+ }
14679
+ },
14680
+ (p) => overlay.has(p) || onDisk(p)
14681
+ );
14682
+ if (missing.length > 0) {
14683
+ const sentence = missingImportSentence(missing);
14684
+ if (importRefusals < 1 && !isFinal) {
14685
+ importRefusals += 1;
14686
+ const answer = { rules: ["done_rule"], violations: [sentence], message: sentence };
14687
+ refusedStreak += 1;
14688
+ refusedTurns.push({ turn, rules: answer.rules });
14689
+ log({ event: "codegen.import_check", turn, outcome: "sent_back", missing: missing.length });
14690
+ transcript.push({ turn, toolCalls: [], refused: answer });
14691
+ if (refusedStreak >= REFUSED_STREAK_LIMIT) forced = "refused_repeatedly";
14692
+ forced = settleNextTurn(turn, forced);
14693
+ continue;
14694
+ }
14695
+ log({ event: "codegen.import_check", turn, outcome: "failed", missing: missing.length });
14696
+ throw new CodegenLoopFailure("syntax_error", void 0, void 0, sentence, sentence.slice(0, MAX_PREVIOUS_DETAIL_CHARS));
14697
+ }
14698
+ }
14543
14699
  const doneSummary = typeof body.summary === "string" ? body.summary.slice(0, MAX_SUMMARY_CHARS) : "";
14544
14700
  const lane = args.lane;
14545
14701
  if (harness && args.phase === "code" && lane?.kind === "code" && !lane.amend && args.keepOnGiveUp === true) {
@@ -16283,7 +16439,7 @@ function keyName(key, computed) {
16283
16439
  if (key.type === "Identifier" && !computed) return key.name;
16284
16440
  return null;
16285
16441
  }
16286
- function nameOf({ node, parent }) {
16442
+ function nameOf2({ node, parent }) {
16287
16443
  if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression") {
16288
16444
  const id = node.id;
16289
16445
  if (id?.name) return id.name;
@@ -16406,7 +16562,7 @@ function findUnsuppliedInputs(input) {
16406
16562
  names.push(name);
16407
16563
  }
16408
16564
  if (names.length === 0) continue;
16409
- found.push({ file: file.path, function: nameOf(site).slice(0, MAX_FUNCTION_CHARS), names: names.slice(0, MAX_UNSUPPLIED_NAMES) });
16565
+ found.push({ file: file.path, function: nameOf2(site).slice(0, MAX_FUNCTION_CHARS), names: names.slice(0, MAX_UNSUPPLIED_NAMES) });
16410
16566
  if (found.length >= MAX_UNSUPPLIED_ENTRIES) return found;
16411
16567
  }
16412
16568
  }
@@ -16676,7 +16832,7 @@ var FAILURE_ARTIFACT_DIR = "quikpilot-failure";
16676
16832
  var REPORT_COPY = "final-test-report.xml";
16677
16833
  var MAX_REPORT_BYTES = 5 * 1024 * 1024;
16678
16834
  var MAX_FILES = 200;
16679
- var RUNNER_VERSION = true ? "9.3.0-rc.25" : "dev";
16835
+ var RUNNER_VERSION = true ? "9.3.0-rc.26" : "dev";
16680
16836
  function safeDestination(base, repoPath) {
16681
16837
  if (!repoPath || (0, import_node_path15.isAbsolute)(repoPath)) return null;
16682
16838
  const destination = (0, import_node_path15.resolve)(base, repoPath);
@@ -16811,8 +16967,8 @@ async function resolveTestDiscovery(i2) {
16811
16967
  };
16812
16968
  if (!i2.command || i2.command.trim().length === 0) return done(buildTestDiscovery({ ...base, snapshot: null }));
16813
16969
  let timer;
16814
- const timeout = new Promise((resolve6) => {
16815
- timer = setTimeout(() => resolve6("timeout"), i2.waitMs);
16970
+ const timeout = new Promise((resolve7) => {
16971
+ timer = setTimeout(() => resolve7("timeout"), i2.waitMs);
16816
16972
  });
16817
16973
  const settled = i2.baseline.then(
16818
16974
  (b) => b.snapshot,