staysfixed 0.12.0 → 0.13.0

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/src/v2/check.js CHANGED
@@ -51,6 +51,7 @@ import {
51
51
  } from './watch/window.js';
52
52
  import { onAppStarted, stillOpen } from './adapters/isolate.js';
53
53
 
54
+ import { isAnAnswerJourney, journeysFromExports, splitAnswerSheet } from './journeys/from-exports.js';
54
55
  import { processAdapter } from './adapters/process.js';
55
56
  import { sourceAdapter } from './adapters/source.js';
56
57
  import { httpAdapter } from './adapters/http.js';
@@ -582,6 +583,7 @@ async function countTheDoors(verdict, project) {
582
583
  const { ledger, toCoverage } = await import('./coverage.js');
583
584
  const led = await ledger(project.store, project.product, {
584
585
  root: project.root,
586
+ folders: project.sourceFolders,
585
587
  journeys: project.journeys,
586
588
  builds: [project.candidate.id],
587
589
  });
@@ -1085,28 +1087,34 @@ async function stopWhateverIsStillRunningIn(dir) {
1085
1087
  function noScratchFolder(e) {
1086
1088
  const tmp = os.tmpdir();
1087
1089
  const code = String(/** @type {any} */ (e)?.code ?? '');
1090
+ // The setting is not called the same thing everywhere, and naming the wrong one is advice
1091
+ // that cannot be followed. Windows reads TEMP and TMP; everything else reads TMPDIR. All
1092
+ // three sentences below said "TMPDIR" on every machine, so on Windows the only instruction
1093
+ // a stuck person was given named a setting their operating system does not read. Measured
1094
+ // on a real Windows 11 machine, 2026-08-31.
1095
+ const setting = process.platform === 'win32' ? 'TEMP' : 'TMPDIR';
1096
+ const trailing = process.platform === 'win32' ? /[\\/]$/ : /\/$/;
1088
1097
  // Worth naming only when a setting in this shell is what chose the folder. On a machine
1089
- // where nothing set it, saying "TMPDIR" sends somebody looking for a setting they have not
1098
+ // where nothing set it, saying the name sends somebody looking for a setting they have not
1090
1099
  // got, and the folder is the operating system's own.
1091
- const yours = (process.env.TMPDIR ?? '').replace(/\/$/, '') === tmp.replace(/\/$/, '')
1092
- ? ' That folder is whatever TMPDIR is set to in this shell.'
1093
- : '';
1100
+ const chosenHere = (process.env[setting] ?? '').replace(trailing, '') === tmp.replace(trailing, '');
1101
+ const yours = chosenHere ? ` That folder is whatever ${setting} is set to in this shell.` : '';
1094
1102
  /** @type {{why: string, hint: string}} */
1095
1103
  const said =
1096
1104
  code === 'ENOENT'
1097
1105
  ? {
1098
1106
  why: `There is no folder at ${tmp}, so there was nowhere to put it.`,
1099
- hint: `Make that folder, or point TMPDIR at one that exists — or unset TMPDIR to fall back to this machine's own — and run the check again.${yours}`,
1107
+ hint: `Make that folder, or point ${setting} at one that exists — or unset ${setting} to fall back to this machine's own — and run the check again.${yours}`,
1100
1108
  }
1101
1109
  : code === 'EACCES' || code === 'EPERM'
1102
1110
  ? {
1103
1111
  why: `${tmp} is there, but this user is not allowed to write in it.`,
1104
- hint: `Give yourself write access to that folder, or point TMPDIR at one you can write to, and run the check again.${yours}`,
1112
+ hint: `Give yourself write access to that folder, or point ${setting} at one you can write to, and run the check again.${yours}`,
1105
1113
  }
1106
1114
  : code === 'EROFS'
1107
1115
  ? {
1108
1116
  why: `${tmp} is on a disk that is mounted read-only, so nothing can be written there at all.`,
1109
- hint: `Point TMPDIR at a folder on a disk that takes writes and run the check again.${yours}`,
1117
+ hint: `Point ${setting} at a folder on a disk that takes writes and run the check again.${yours}`,
1110
1118
  }
1111
1119
  : code === 'ENOSPC'
1112
1120
  ? {
@@ -1214,7 +1222,7 @@ function blocked(options, e, storeTrouble) {
1214
1222
  * for itself.
1215
1223
  *
1216
1224
  * @param {CheckOptions & {finding?: string, revert?: string[]}} options
1217
- * @returns {Promise<{gone: boolean, detail?: string, verdict?: string, escalates?: boolean}>}
1225
+ * @returns {Promise<{gone: boolean, detail?: string, verdict?: string, escalates?: boolean, reran?: number, checked?: number}>}
1218
1226
  */
1219
1227
  export async function prove(options = {}) {
1220
1228
  const root = projectRootFor(options);
@@ -1225,6 +1233,12 @@ export async function prove(options = {}) {
1225
1233
  if (!finding) {
1226
1234
  return {
1227
1235
  gone: false,
1236
+ // Said out loud rather than left absent. An absent verdict resolves to "could not test"
1237
+ // at the surface, deliberately, but a reader of this function should not have to know
1238
+ // that to see which of the three answers this is.
1239
+ verdict: 'could not test',
1240
+ reran: 0,
1241
+ checked: 0,
1228
1242
  detail: `The last check has no finding called "${options.finding ?? ''}". Run a check first, then prove one of the ids it gives you.`,
1229
1243
  };
1230
1244
  }
@@ -1240,6 +1254,27 @@ export async function prove(options = {}) {
1240
1254
  ? { ...changed, hunks: changed.hunks.filter((h) => wanted.some((w) => h.file === w || h.file.startsWith(`${w}/`))) }
1241
1255
  : changed;
1242
1256
 
1257
+ // A file named for reverting that is not among the changes is NOT "nothing has changed".
1258
+ // With an empty narrowing, proveCause said "Nothing has changed between the build you were
1259
+ // happy with and this one" — about a working tree with two edited files in it — which
1260
+ // sends somebody to debug their tree instead of the filename they just typed. Measured
1261
+ // 2026-08-31.
1262
+ if (wanted.length > 0 && narrowed.hunks.length === 0 && changed.hunks.length > 0) {
1263
+ const names = [...new Set(changed.hunks.map((h) => h.file))];
1264
+ return {
1265
+ gone: false,
1266
+ verdict: /** @type {const} */ ('could not test'),
1267
+ escalates: false,
1268
+ reran: 0,
1269
+ checked: 0,
1270
+ detail:
1271
+ `Nothing was re-run: ${wanted.join(', ')} ${wanted.length === 1 ? 'is' : 'are'} not among the files that changed `
1272
+ + `between the build you were happy with and this one, so there was no change in ${wanted.length === 1 ? 'it' : 'them'} `
1273
+ + `to undo. What did change: ${names.slice(0, 10).join(', ')}${names.length > 10 ? `, and ${names.length - 10} more` : ''}. `
1274
+ + 'Name one of those and the claim can actually be tested.',
1275
+ };
1276
+ }
1277
+
1243
1278
  const proof = await proveCause(finding, {
1244
1279
  cwd: project.root,
1245
1280
  walk: project.walk,
@@ -1253,7 +1288,13 @@ export async function prove(options = {}) {
1253
1288
  gone: proof.verdict === 'caused by that change',
1254
1289
  verdict: proof.verdict,
1255
1290
  escalates: proof.escalates,
1256
- detail: proof.why ? `${proof.what} ${proof.why}` : proof.what,
1291
+ // How much was really walked again, carried through rather than left in a number the
1292
+ // reader never sees. A reply that took a second must never read like one that took ten
1293
+ // minutes, and the only way to tell them apart is to say so.
1294
+ reran: proof.reran,
1295
+ checked: proof.checked,
1296
+ // `proof.what` already ends with the reason. Gluing `why` on printed it twice.
1297
+ detail: proof.what,
1257
1298
  };
1258
1299
  } finally {
1259
1300
  await project.close();
@@ -1588,6 +1629,9 @@ async function waitForItsWindow(pid, stopped) {
1588
1629
  * @property {import('./types.js').Store} store
1589
1630
  * @property {BuildFingerprint} candidate
1590
1631
  * @property {string} [against] The reference build's own id, once a name has been resolved.
1632
+ * @property {string[]} [sourceFolders] The folders this run reads code from, straight from
1633
+ * the settings it was given, so nothing downstream has
1634
+ * to find them a second time and find different ones.
1591
1635
  * @property {number} keepBuilds How many builds of this product other than the reference keep
1592
1636
  * their full record. Everything older is thinned out at the end of a run.
1593
1637
  * @property {string} [referenceSha] The commit the build you were happy with is at. It is
@@ -1800,6 +1844,112 @@ export function suiteBudgetFrom(config) {
1800
1844
  return Number.isFinite(asked) && asked >= 0 ? Math.floor(asked) : null;
1801
1845
  }
1802
1846
 
1847
+ /**
1848
+ * How long the harvest gets when NOBODY asked for it.
1849
+ *
1850
+ * A quarter of what somebody who typed `--journeys suite` gets, and that gap is the whole
1851
+ * design. Measured on this machine on 2026-08-31: twelve near-empty test files harvested in
1852
+ * 3.1 seconds. Twenty seconds therefore covers a small suite outright and takes a useful bite
1853
+ * out of a large one, and every file it does not reach is named in the coverage list with the
1854
+ * command that would reach it. The alternative — deciding from a file count whether to run at
1855
+ * all — guesses at how slow somebody's tests are and is wrong in both directions.
1856
+ */
1857
+ const AUTO_HARVEST_BUDGET_MS = 20_000;
1858
+
1859
+ /**
1860
+ * How many harvested test files an unasked-for run will then WALK.
1861
+ *
1862
+ * The harvest budget bounds the harvest and not what comes after it: each harvested journey
1863
+ * is walked twice on the new build and again on the old one. Measured on this machine on
1864
+ * 2026-08-31, twelve harvested journeys took a check from 1.4 seconds to 8.2. Twelve is
1865
+ * therefore the cap, and the files past it are named rather than dropped in silence.
1866
+ */
1867
+ const AUTO_HARVEST_JOURNEY_CAP = 12;
1868
+
1869
+ /**
1870
+ * How long ONE test file gets on an unasked-for run, harvesting and walking alike.
1871
+ *
1872
+ * The budget above is checked before a file STARTS, never in the middle of one, so without
1873
+ * this a single slow test file could walk straight through a twenty-second budget and spend
1874
+ * the runner's default two minutes doing it — turning a bounded default into an unbounded
1875
+ * one on exactly the projects where that hurts most. Thirty seconds is generous for one file
1876
+ * of a suite somebody runs on every change, and a file that needs longer is named as a hole
1877
+ * with the reason, which is the honest outcome rather than a silent wait.
1878
+ */
1879
+ const AUTO_FILE_TIMEOUT_MS = 30_000;
1880
+
1881
+ /**
1882
+ * Should this run harvest the project's own tests without being asked?
1883
+ *
1884
+ * The question is only ever "can this be done at all", never "is this project's suite worth
1885
+ * it" — a suite that is too slow is handled by the budget and the cap above, not by refusing
1886
+ * to look. Everything here is cheap: package.json is read, a few filenames are tested for
1887
+ * existence, and nothing is run.
1888
+ *
1889
+ * IT CAN BE SWITCHED OFF, in two ways, because a default that cannot be turned off is a
1890
+ * default somebody works around by uninstalling. `--journeys code` says "read the source and
1891
+ * nothing else" for one run; `suite: { auto: false }` in the settings says it for good. Both
1892
+ * are reported as a hole in that run's coverage, so switching it off never quietly turns into
1893
+ * believing a check that no longer looks.
1894
+ *
1895
+ * @param {string} root
1896
+ * @param {Record<string, any>} config
1897
+ * @returns {Promise<{run: boolean, gap?: CoverageGap}>}
1898
+ */
1899
+ async function suiteWorthRunningByDefault(root, config) {
1900
+ if (config?.suite?.auto === false) {
1901
+ return {
1902
+ run: false,
1903
+ gap: {
1904
+ what: "This project's own tests were not run, because the settings switch that off.",
1905
+ why: 'suite: { auto: false } in your settings file. Nothing your tests can see is being compared on this run, which on a library is most of what there is to see.',
1906
+ unlockedBy: 'Remove that line, or run `staysfixed check --journeys suite` once to see what it would find.',
1907
+ },
1908
+ };
1909
+ }
1910
+ try {
1911
+ const { detectRunner } = await import('./journeys/from-suite.js');
1912
+ const found = await detectRunner(root);
1913
+ if (found.runner === 'none') {
1914
+ // Said out loud, on every run, rather than passed over as "there was nothing to do".
1915
+ // A project with no tests is not a project where the tests are fine — it is a project
1916
+ // where a whole channel is empty, and on a library that channel is most of what there
1917
+ // is to look at. The reader is told which it is.
1918
+ return {
1919
+ run: false,
1920
+ gap: {
1921
+ what: "None of this project's own tests were run, because there are none this tool can find.",
1922
+ why: `${found.why} A test suite is the only source that walks this product with the arguments somebody actually thought about, so without one the check compares what it can read and call for itself, and no more.`,
1923
+ unlockedBy: "Point the project at vitest or Node's own test runner and every test file becomes a journey, run twice on each build and compared.",
1924
+ },
1925
+ };
1926
+ }
1927
+ const blocking = (found.missing ?? []).filter((m) => m.blocking);
1928
+ if (blocking.length > 0) {
1929
+ return {
1930
+ run: false,
1931
+ gap: {
1932
+ what: "This project has a test suite and none of it was run, so nothing here says anything about what those tests cover.",
1933
+ why: `${blocking.map((m) => m.what).join(', ')} ${blocking.length === 1 ? 'is' : 'are'} missing, and the harvest cannot run one test file at a time without ${blocking.length === 1 ? 'it' : 'them'}.`,
1934
+ unlockedBy: blocking.map((m) => m.howToGet).join(' '),
1935
+ },
1936
+ };
1937
+ }
1938
+ return { run: true };
1939
+ } catch (e) {
1940
+ // Being unable to work out whether a suite exists is a hole like any other. It must never
1941
+ // read as "this project has no tests", which is the same silence wearing a different hat.
1942
+ return {
1943
+ run: false,
1944
+ gap: {
1945
+ what: "Nothing could work out whether this project has a test suite, so none of it was run.",
1946
+ why: messageOf(e),
1947
+ unlockedBy: 'Run `staysfixed check --journeys suite` to see what it says, or `staysfixed doctor` for what this folder is missing.',
1948
+ },
1949
+ };
1950
+ }
1951
+ }
1952
+
1803
1953
  /**
1804
1954
  * Thin out the record of builds nobody is going to ask about again.
1805
1955
  *
@@ -2139,6 +2289,12 @@ async function openProject(options) {
2139
2289
  store,
2140
2290
  candidate,
2141
2291
  keepBuilds: keepBuildsFrom(config),
2292
+ // The folders THIS run is reading, carried so the coverage ledger counts the doors of the
2293
+ // same product the run walked. The ledger can find the settings itself, and does — but it
2294
+ // finds them by looking beside the project, and a run started with `--config elsewhere`
2295
+ // is reading a different file. Two answers to "what is in this project" is how the
2296
+ // ledger came to measure "78 of 78 doors" from 8 of 20 files. Measured 2026-08-31.
2297
+ sourceFolders: Array.isArray(config.source?.folders) ? config.source.folders : undefined,
2142
2298
  referenceSha,
2143
2299
  against: reference ? reference.id : options.against,
2144
2300
  journeys,
@@ -2340,6 +2496,14 @@ async function walkOne(req, where) {
2340
2496
  ctx,
2341
2497
  );
2342
2498
  observations = await adapter.run(req.journey, prepared, ctx);
2499
+ // An answer sheet arrives as one wall of text at one address, because that is what the
2500
+ // process adapter does with anything a command prints. Left that way, a library whose
2501
+ // every return value changed produced ONE finding, worded as a window onto the middle of
2502
+ // a string: "…eserved(\"admin\") -> false…" where it read "…eserved(\"admin\") -> true…".
2503
+ // True, and useless to the person who has to decide whether to ship. Taken apart, every
2504
+ // call gets the exported name's own address and the finding names the function, the
2505
+ // input and both answers. Measured 2026-08-31 — see `splitAnswerSheet`.
2506
+ if (isAnAnswerJourney(req.journey)) observations = splitAnswerSheet(observations, req.journey);
2343
2507
  } catch (e) {
2344
2508
  // A journey that fell over is a hole in the coverage, never a silent pass and never
2345
2509
  // the end of the run — the other journeys' work is worth keeping.
@@ -2540,29 +2704,64 @@ async function gatherJourneys({ root, config, options }) {
2540
2704
 
2541
2705
  if (named) journeys.push(...(await readJourneyFile(path.resolve(root, named))));
2542
2706
 
2543
- // The project's own test suite, when somebody asked for it in those words and never
2544
- // otherwise. This RUNS their tests — twice each, inside the same scratch clone everything
2545
- // else uses, under a time budget and that is a cost nobody gets charged by accident, so
2546
- // it is off unless `--journeys suite` says so.
2707
+ // ---- The project's own test suite.
2708
+ //
2709
+ // WHY THIS USED TO BE OFF BY DEFAULT, and the reasoning was right as far as it went: this
2710
+ // RUNS somebody else's tests every file twice to harvest, and then every harvested
2711
+ // journey twice more on each build — and charging a stranger for that on a command they
2712
+ // ran to get a fast answer is how a tool gets uninstalled. So it waited for
2713
+ // `--journeys suite`.
2714
+ //
2715
+ // WHY IT IS NOW ON BY DEFAULT ANYWAY. The cost was measured against the wrong thing. It was
2716
+ // weighed against a slower check; it should have been weighed against a WRONG one. Measured
2717
+ // 2026-08-31 on a four-line library: two exported functions were rewritten so that every
2718
+ // web address the product produces came out different, and the default check answered
2719
+ // "Nothing that worked has changed" and exited 0, because no default channel had ever
2720
+ // called a function. A flag that is off by default cannot save anybody, and a false
2721
+ // all-clear is not a cheaper answer than a slow one — it is the one answer this tool may
2722
+ // never give.
2547
2723
  //
2548
- // It is worth switching on because it sees what walking a product cannot. On the fixture
2549
- // where a total quietly stops rounding pennies, and the command line only ever adds whole
2550
- // pounds, the discovered journeys produce nothing at all the output does not move by one
2551
- // character and the harvested ones produce five findings.
2724
+ // WHERE THE LINE IS DRAWN, and the measurement that drew it. Default-on is held to a
2725
+ // TIGHTER budget than an explicit `--journeys suite`, and to a cap on how many harvested
2726
+ // journeys are then walked, so the cost of a check nobody asked to slow down is bounded by
2727
+ // construction instead of by a guess about somebody's suite. Measured on this machine on
2728
+ // 2026-08-31, with twelve near-empty test files: harvesting them took 3.1 seconds, and the
2729
+ // whole check went from 1.4 seconds to 8.2 — about 570ms per test file, and that is the
2730
+ // FLOOR, because those tests did nothing. So the automatic path gets 20 seconds of harvest
2731
+ // and walks at most 12 of what comes out, which lands a default check at well under half a
2732
+ // minute on a project of that shape. Everything the budget or the cap left out is named as
2733
+ // a hole with the command that would reach it — never dropped quietly.
2734
+ //
2735
+ // Asking for it by name still gets the full, uncapped ninety seconds, because somebody who
2736
+ // typed `--journeys suite` has said what they are willing to wait for.
2552
2737
  //
2553
2738
  // Loaded here rather than at the top of the file: a copy of this tool without the harvest
2554
2739
  // in it still runs every other kind of check, and saying so is better than failing to start.
2555
- if (options.journeys === 'suite') {
2740
+ const askedForTheSuite = options.journeys === 'suite';
2741
+ let autoSuite = null;
2742
+ if (!askedForTheSuite && !named && options.journeys !== 'recorded' && options.journeys !== 'code') {
2743
+ autoSuite = await suiteWorthRunningByDefault(root, config);
2744
+ if (autoSuite.gap) gaps.push(autoSuite.gap);
2745
+ }
2746
+ if (askedForTheSuite || autoSuite?.run) {
2747
+ const automatic = !askedForTheSuite;
2556
2748
  try {
2557
2749
  const { journeysFromSuite, DEFAULT_HARVEST_BUDGET_MS } = await import('./journeys/index.js');
2558
2750
  // The settings file gets a say in how long this is allowed to take. Left out, the
2559
2751
  // harvest applies its own default, which is why nothing is passed rather than the
2560
- // default being copied to here — see `suiteBudgetFrom`.
2561
- const budgetMs = suiteBudgetFrom(config);
2752
+ // default being copied to here — see `suiteBudgetFrom`. On the automatic path the
2753
+ // tighter budget is used unless the settings ask for something of their own, because a
2754
+ // number somebody wrote down beats a number this file guessed.
2755
+ const asked = suiteBudgetFrom(config);
2756
+ const budgetMs = asked ?? (automatic ? AUTO_HARVEST_BUDGET_MS : null);
2757
+ const suiteOptions = {
2758
+ ...(budgetMs === null ? {} : { budgetMs }),
2759
+ ...(automatic ? { timeoutMs: AUTO_FILE_TIMEOUT_MS } : {}),
2760
+ };
2562
2761
  const suite = await journeysFromSuite({
2563
2762
  root,
2564
2763
  surface: options.surface === 'auto' ? undefined : options.surface,
2565
- ...(budgetMs === null ? {} : { suite: { budgetMs } }),
2764
+ ...(Object.keys(suiteOptions).length === 0 ? {} : { suite: suiteOptions }),
2566
2765
  // The harvest talks while it works, and it can take most of a minute. Its sentences
2567
2766
  // go into the same stream as everything else rather than nowhere.
2568
2767
  log: (message) => options.events?.emit({ type: 'note', at: options.events.elapsed(), message }),
@@ -2578,9 +2777,24 @@ async function gatherJourneys({ root, config, options }) {
2578
2777
  message:
2579
2778
  applied === 0
2580
2779
  ? 'The test-suite harvest was given no time budget at all, so every test file was run however long it took. Your settings asked for that with suite.budgetMs: 0.'
2581
- : `The test-suite harvest was held to ${Math.round(applied / 1000)} seconds${budgetMs === null ? ', which is the default' : ', which your settings asked for'}. Anything it did not reach in that time is named below rather than skipped quietly; change it with suite.budgetMs.`,
2780
+ : `The test-suite harvest was held to ${Math.round(applied / 1000)} seconds${
2781
+ asked !== null ? ', which your settings asked for' : automatic ? ', which is what an automatic run gets' : ', which is the default'
2782
+ }. Anything it did not reach in that time is named below rather than skipped quietly; change it with suite.budgetMs.`,
2582
2783
  });
2583
- journeys.push(...suite.journeys);
2784
+ // The cap, and only on the automatic path. Somebody who typed the flag gets everything
2785
+ // their suite produced. Whoever did not type anything gets a bounded run and a list of
2786
+ // exactly which of their test files are therefore not being watched.
2787
+ let kept = suite.journeys;
2788
+ if (automatic && kept.length > AUTO_HARVEST_JOURNEY_CAP) {
2789
+ const dropped = kept.slice(AUTO_HARVEST_JOURNEY_CAP);
2790
+ kept = kept.slice(0, AUTO_HARVEST_JOURNEY_CAP);
2791
+ gaps.push({
2792
+ what: `${dropped.length} of this project's test files were harvested and then not walked, so nothing here says anything about what they cover: ${dropped.map((j) => j.name).join(', ')}.`,
2793
+ why: `A check nobody asked to slow down walks at most ${AUTO_HARVEST_JOURNEY_CAP} harvested test files, because each one is run twice on every build and the bill for a big suite would land on somebody who only wanted a quick answer.`,
2794
+ unlockedBy: 'Run `staysfixed check --journeys suite` to walk all of them, or narrow the suite to the files that matter.',
2795
+ });
2796
+ }
2797
+ journeys.push(...kept);
2584
2798
  gaps.push(...suite.gaps);
2585
2799
  } catch (e) {
2586
2800
  // A harvest that fell over is a hole, never a pass. Everything else this project has is
@@ -2593,13 +2807,37 @@ async function gatherJourneys({ root, config, options }) {
2593
2807
  }
2594
2808
  }
2595
2809
 
2810
+ // ---- Calling what a library exports, rather than only reading its labels.
2811
+ //
2812
+ // See `from-exports.js` for the false all-clear that put this here. In one sentence: a
2813
+ // library was checked, shipped, rewritten so that every value it returns came out
2814
+ // different, and checked again — and the check passed, because every channel in the tool
2815
+ // compared the NAMES and SHAPES of the exports and none of them had ever called one.
2816
+ //
2817
+ // It costs one extra process per configured module per build, which is the cheapest thing
2818
+ // on this page, and it needs nothing configured that is not configured already: `init`
2819
+ // writes `process.imports` for every library it sets up.
2820
+ if (!named && options.journeys !== 'recorded') {
2821
+ const answers = journeysFromExports({ config: config.process });
2822
+ journeys.push(...answers.journeys);
2823
+ gaps.push(...answers.gaps);
2824
+ }
2825
+
2596
2826
  for (const adapter of ADAPTERS) {
2597
2827
  if (adapter === sourceAdapter && named && options.journeys !== 'code') {
2598
2828
  // A journeys file names exactly what to walk. The contract read is still added,
2599
2829
  // because it cannot break anything and it sees what no journey does.
2600
2830
  }
2601
2831
  /** @type {import('./adapters/contract.js').AdapterProject} */
2602
- const project = { root, config: config[adapter.name] ?? {} };
2832
+ // The folders the settings name, handed to every adapter alongside its own block.
2833
+ //
2834
+ // An adapter is given only the settings under its own name, so `http` could see
2835
+ // `http.folders` and never `source.folders` — which is where `init` actually writes them.
2836
+ // Route discovery therefore read the folders it guesses at, and a route outside them was
2837
+ // never found on a project that had said, in its own settings, exactly where its code is.
2838
+ // The adapter's own block still wins, because a project that overrode this meant it.
2839
+ // Measured 2026-08-31.
2840
+ const project = { root, config: { folders: config.source?.folders, ...(config[adapter.name] ?? {}) } };
2603
2841
  let detection;
2604
2842
  try {
2605
2843
  detection = await adapter.detect(project);
@@ -2825,6 +3063,69 @@ function nameOfReference(reference, asked) {
2825
3063
  return asked && asked.trim() !== '' ? `${asked} (${reference.id})` : reference.id;
2826
3064
  }
2827
3065
 
3066
+ /**
3067
+ * Put one commit's files into a folder, without a shell and without touching the repository.
3068
+ *
3069
+ * `git archive` writes a tar to its standard output and `tar` reads one from its standard
3070
+ * input, so the two are joined here directly. The archive never reaches the disk, which is why
3071
+ * a big repository does not cost twice the space to look at — the reason the shell pipeline was
3072
+ * there in the first place. Both programs are on every machine this runs on: Windows has
3073
+ * shipped `tar.exe` since Windows 10, and git is already required for anything here to work.
3074
+ *
3075
+ * @param {string} root The repository.
3076
+ * @param {string} sha The commit to put back.
3077
+ * @param {string} dir An empty folder to put it in.
3078
+ * @returns {Promise<void>}
3079
+ */
3080
+ function gitArchiveInto(root, sha, dir) {
3081
+ return new Promise((resolve, reject) => {
3082
+ const git = spawn('git', ['-C', root, 'archive', '--format=tar', sha], {
3083
+ stdio: ['ignore', 'pipe', 'pipe'],
3084
+ windowsHide: true,
3085
+ });
3086
+ const untar = spawn('tar', ['-x', '-f', '-', '-C', dir], {
3087
+ stdio: ['pipe', 'ignore', 'pipe'],
3088
+ windowsHide: true,
3089
+ });
3090
+
3091
+ let said = '';
3092
+ for (const stream of [git.stderr, untar.stderr]) {
3093
+ stream?.setEncoding('utf8');
3094
+ stream?.on('data', (chunk) => { said = (said + chunk).slice(0, 4000); });
3095
+ }
3096
+
3097
+ let done = false;
3098
+ /** @param {Error|null} e */
3099
+ const finish = (e) => {
3100
+ if (done) return;
3101
+ done = true;
3102
+ clearTimeout(giveUp);
3103
+ try { git.kill('SIGKILL'); } catch { /* already gone */ }
3104
+ try { untar.kill('SIGKILL'); } catch { /* already gone */ }
3105
+ if (e) reject(e);
3106
+ else resolve();
3107
+ };
3108
+ const giveUp = setTimeout(
3109
+ () => finish(new Error(`putting ${sha.slice(0, 7)} back took longer than two minutes.`)),
3110
+ 120_000,
3111
+ );
3112
+
3113
+ git.on('error', finish);
3114
+ untar.on('error', finish);
3115
+ git.stdout.pipe(untar.stdin);
3116
+ // A pipe that breaks because the other end has died is not news worth an unhandled error.
3117
+ git.stdout.on('error', () => {});
3118
+ untar.stdin.on('error', () => {});
3119
+
3120
+ git.on('exit', (code) => {
3121
+ if (code !== 0) finish(new Error(said.trim() || `git archive stopped with code ${code}`));
3122
+ });
3123
+ untar.on('exit', (code) => {
3124
+ finish(code === 0 ? null : new Error(said.trim() || `tar stopped with code ${code}`));
3125
+ });
3126
+ });
3127
+ }
3128
+
2828
3129
  /**
2829
3130
  * Put the old build back on this machine so it can be walked live.
2830
3131
  *
@@ -2857,12 +3158,13 @@ async function exportBuild(root, reference, scratch) {
2857
3158
  const dir = path.join(scratch, `reference-${sha.slice(0, 12)}`);
2858
3159
  await fsp.mkdir(dir, { recursive: true });
2859
3160
  try {
2860
- // Straight through a pipe: the archive is never written to disk, so a big repository
2861
- // does not cost twice the space to look at.
2862
- await exec('/bin/sh', ['-c', `git -C ${quote(root)} archive --format=tar ${quote(sha)} | tar -x -C ${quote(dir)}`], {
2863
- timeout: 120_000,
2864
- maxBuffer: 8 * 1024 * 1024,
2865
- });
3161
+ // Straight through a pipe: the archive is never written to disk, so a big repository does
3162
+ // not cost twice the space to look at. The two programs are joined below rather than by a
3163
+ // shell, because there is no `/bin/sh` on Windows and that one word was the whole of
3164
+ // paired mode there. Measured on a real Windows 11 machine on 2026-08-31: every `--paired`
3165
+ // run answered "<sha> cannot be built here" and fell back to the stored record, which is
3166
+ // the weaker comparison. The tool's strongest mode had never once run on Windows.
3167
+ await gitArchiveInto(root, sha, dir);
2866
3168
  } catch (e) {
2867
3169
  await fsp.rm(dir, { recursive: true, force: true });
2868
3170
  throw new StaysFixedError(`${sha.slice(0, 7)} could not be put back on this machine, so it cannot be walked live. ${messageOf(e)}`, {
@@ -2983,10 +3285,6 @@ async function packageVersion(root) {
2983
3285
  return typeof pkg?.version === 'string' ? pkg.version : null;
2984
3286
  }
2985
3287
 
2986
- /** @param {string} text */
2987
- function quote(text) {
2988
- return `'${text.split("'").join(`'\\''`)}'`;
2989
- }
2990
3288
 
2991
3289
  /** @param {string} name */
2992
3290
  function safeSegment(name) {
package/src/v2/cli.js CHANGED
@@ -259,7 +259,7 @@ export const V2_COMMANDS = {
259
259
  summary: 'Test whether your own edit really caused a finding, by undoing it.',
260
260
  usage: 'staysfixed prove <finding> --revert <file> [--revert <file>]',
261
261
  describe:
262
- 'You believe your change to a particular file caused a difference. This puts that file\nback to the reference build, runs again, and says whether the difference went away.\nIf it survives, your edit did not cause it and you were about to fix the wrong thing.\n\nNothing is left reverted: the working tree is put back exactly as it was.\n\nIt answers 0 when it could test the claim and 2 when it could not. The answer itself —\ncaused it, or did not — is in the words, not the exit code, because "your edit was\ninnocent" is not a failure and must not be read as one.',
262
+ 'You believe your change to a particular file caused a difference. This puts that file\nback to the reference build, runs again, and says whether the difference went away.\n\nIt gives you one of THREE answers, and only two of them are answers:\n PROVEN CAUSED undoing your change made the difference go away.\n PROVEN NOT CAUSED it was re-run without your change and the difference is still there,\n so you were about to fix the wrong file.\n NOT TESTED nothing was measured — the file you named was not among your changes,\n the old build would not build, or nothing was re-run at all. This\n never means your edit is innocent. It means nobody looked.\n\nIt is a real re-run, not a lookup: expect it to take about as long as a check.\nNothing is left reverted: the working tree is put back exactly as it was.\n\nIt answers 0 when it could test the claim and 2 when it could not. Which way it came out —\ncaused it, or did not — is in the words, not the exit code, because "your edit was\ninnocent" is not a failure and must not be read as one.',
263
263
  options: [
264
264
  ['--revert <file>', 'A file to put back to the reference for one run. Repeat it for several.'],
265
265
  ],
@@ -475,8 +475,26 @@ export async function proveRun(ctx) {
475
475
  });
476
476
  }
477
477
 
478
+ // The price, said before it is charged rather than after.
479
+ //
480
+ // Proving a cause is not a lookup. It checks out the old build into a scratch copy, undoes
481
+ // the one change, and WALKS THE JOURNEYS AGAIN - on a real website that is eleven to
482
+ // twenty minutes, and somebody who thinks they typed a query sits watching a blank screen
483
+ // and kills it. On 2026-08-31 the opposite also happened and is worse: an answer came back
484
+ // in five seconds, having started no build and walked nothing, and read exactly like a
485
+ // measurement. Saying what this is about to cost is half of what stops a fast reply being
486
+ // mistaken for a cheap one - the reply itself now says what it actually ran.
487
+ say(paint.grey(`Undoing ${revert.join(', ')} in a scratch copy and walking this product again. That is a full re-run of the journeys this finding came from, so it costs about what a check costs. Nothing of yours is touched and nothing is left reverted.`));
488
+ blank();
489
+
478
490
  const reply = await askTheToolSet(ctx, 'staysfixed_prove', { finding, revert });
479
491
  sayReply(reply);
492
+ // Non-zero means "could not test", never "your edit was innocent". `staysfixed_prove`
493
+ // marks exactly one of its three answers as an error - the one that is not an answer -
494
+ // which is the promise this command's own help has always made: 0 when it could test the
495
+ // claim, 2 when it could not. Until 2026-08-31 it exited 0 on all three, so a CI step or
496
+ // an agent reading the code alone was told a question nobody had answered had come back
497
+ // clean.
480
498
  return reply.isError ? EXIT.error : EXIT.ok;
481
499
  }
482
500