@diffci.com/diffci 0.3.37 → 0.3.38
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-client/src/client/check-plan-junit.js +12 -3
- package/dist-client/src/client/command-batches.d.ts +6 -0
- package/dist-client/src/client/command-batches.js +7 -1
- package/dist-client/src/client/node-bin-launch.d.ts +10 -0
- package/dist-client/src/client/node-bin-launch.js +71 -0
- package/dist-client/src/client/verify-savings.js +18 -11
- package/package.json +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
import { posix, win32 } from "node:path";
|
|
3
3
|
import { SaxesParser } from "saxes";
|
|
4
|
+
/** A frame that may directly contain testsuite and testcase elements. */
|
|
5
|
+
function isSuiteContainer(frame) {
|
|
6
|
+
return frame?.name === "testsuite" || frame?.name === "testsuites" || frame?.nodeRoot === true;
|
|
7
|
+
}
|
|
4
8
|
const MAX_BYTES = 16 * 1024 * 1024;
|
|
5
9
|
const MAX_DEPTH = 128;
|
|
6
10
|
const MAX_TAGS = 100_000;
|
|
@@ -78,8 +82,13 @@ export function readJunit(xml, onCase) {
|
|
|
78
82
|
if (!parent && name !== "testsuite" && name !== "testsuites") {
|
|
79
83
|
invalid("The root must be testsuite or testsuites.");
|
|
80
84
|
}
|
|
81
|
-
if (name === "
|
|
82
|
-
|
|
85
|
+
if (name === "undefined" && attributes.name === "root" && parent?.name === "testsuites" && frames.length === 1) {
|
|
86
|
+
// Node's built-in junit reporter (verified on 24.16.0) writes the root test as this tag when a
|
|
87
|
+
// root-level hook fails, and nests the rest of the report inside it. It names no suite or file.
|
|
88
|
+
frame.nodeRoot = true;
|
|
89
|
+
}
|
|
90
|
+
else if (name === "testsuite" || name === "testsuites") {
|
|
91
|
+
if (parent && !isSuiteContainer(parent)) {
|
|
83
92
|
invalid("A test suite must be inside a suite container.");
|
|
84
93
|
}
|
|
85
94
|
const outer = inherited();
|
|
@@ -103,7 +112,7 @@ export function readJunit(xml, onCase) {
|
|
|
103
112
|
suites.push(suite);
|
|
104
113
|
}
|
|
105
114
|
else if (name === "testcase") {
|
|
106
|
-
if (parent
|
|
115
|
+
if (!isSuiteContainer(parent))
|
|
107
116
|
invalid("A testcase must be inside a testsuite.");
|
|
108
117
|
frame.testCase = {
|
|
109
118
|
skipped: false,
|
|
@@ -11,6 +11,12 @@ import { type CommandMeasurement } from "./verify-savings.js";
|
|
|
11
11
|
* listing a share of the files, run one after another and reported as one verification. Splitting only
|
|
12
12
|
* happens when the command ends in exactly the selected paths as plain tokens; anything else is left
|
|
13
13
|
* whole, because rewriting a command that is not understood could change what it runs.
|
|
14
|
+
*
|
|
15
|
+
* The Windows budget is 6,000 rather than 8,191 (2026-11-09): a part that still goes through `.cmd`
|
|
16
|
+
* shims (`npx.cmd`, then the runner's own) is re-expanded into further cmd.exe lines that add the node
|
|
17
|
+
* and shim paths and npm's `^` escapes. A 7,989-character part of a 282-file DentalPresence selection
|
|
18
|
+
* failed that way; measureCommand now also starts JavaScript runners with node directly
|
|
19
|
+
* (node-bin-launch.ts), and the margin covers the runners it cannot.
|
|
14
20
|
*/
|
|
15
21
|
export declare const COMMAND_LINE_LIMIT: number;
|
|
16
22
|
/**
|
|
@@ -13,8 +13,14 @@ import { measureCommand } from "./verify-savings.js";
|
|
|
13
13
|
* listing a share of the files, run one after another and reported as one verification. Splitting only
|
|
14
14
|
* happens when the command ends in exactly the selected paths as plain tokens; anything else is left
|
|
15
15
|
* whole, because rewriting a command that is not understood could change what it runs.
|
|
16
|
+
*
|
|
17
|
+
* The Windows budget is 6,000 rather than 8,191 (2026-11-09): a part that still goes through `.cmd`
|
|
18
|
+
* shims (`npx.cmd`, then the runner's own) is re-expanded into further cmd.exe lines that add the node
|
|
19
|
+
* and shim paths and npm's `^` escapes. A 7,989-character part of a 282-file DentalPresence selection
|
|
20
|
+
* failed that way; measureCommand now also starts JavaScript runners with node directly
|
|
21
|
+
* (node-bin-launch.ts), and the margin covers the runners it cannot.
|
|
16
22
|
*/
|
|
17
|
-
export const COMMAND_LINE_LIMIT = process.platform === "win32" ?
|
|
23
|
+
export const COMMAND_LINE_LIMIT = process.platform === "win32" ? 6000 : 100_000;
|
|
18
24
|
/**
|
|
19
25
|
* The runner prefix and the selected paths `command` ends with, one token each, or undefined when it does
|
|
20
26
|
* not end in exactly selected paths. Every rewrite here (batching, reordering, splitting) needs this shape.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `command` as Windows should launch it from `cwd`: `npx --no-install <bin> ...` becomes
|
|
3
|
+
* `node <script> ...` with the extra PATH entry, or `command` unchanged when that is not safe.
|
|
4
|
+
*/
|
|
5
|
+
export declare function windowsLaunch(command: string, cwd: string): {
|
|
6
|
+
command: string;
|
|
7
|
+
pathEntry?: string;
|
|
8
|
+
};
|
|
9
|
+
/** `env` with `entry` first on PATH, keeping Windows' own spelling of the key (usually `Path`). */
|
|
10
|
+
export declare function withPathEntry(env: NodeJS.ProcessEnv, entry: string): NodeJS.ProcessEnv;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { delimiter, dirname, join, relative, resolve } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Repository-local runners launched without Windows `.cmd` shims (2026-11-09).
|
|
5
|
+
*
|
|
6
|
+
* WHY. Selected TypeScript tests run as `npx --no-install tsx --test <files>`. On Windows `npx` is
|
|
7
|
+
* `npx.cmd`, which hands its arguments to node in a second cmd.exe line, and npx then starts `tsx.cmd`,
|
|
8
|
+
* a third. Each line adds the node and shim paths, and npm escapes arguments with `^`, and cmd.exe
|
|
9
|
+
* rejects any line over 8,191 characters. A DentalPresence selection of 282 files, batched into parts
|
|
10
|
+
* of at most 8,000 characters, still failed before any test ran with exit 255 and "The syntax of the
|
|
11
|
+
* command is incorrect"; `node node_modules/tsx/dist/cli.mjs` with the same files ran all 1,260 tests.
|
|
12
|
+
*
|
|
13
|
+
* WHAT. On Windows a command starting `npx --no-install <bin>` runs as `node <script>` when the
|
|
14
|
+
* package's bin is a JavaScript file reached through the repository's node_modules, with
|
|
15
|
+
* node_modules/.bin on PATH as npx would put it. Anything else (a native binary, a bin that cannot be
|
|
16
|
+
* resolved, other platforms) runs unchanged.
|
|
17
|
+
*/
|
|
18
|
+
const NPX_PREFIX = /^npx --no-install ([\w@./-]+)(?=\s|$)/;
|
|
19
|
+
const SAFE_PATH = /^[\w./@+-]+$/;
|
|
20
|
+
/** The `.bin` directory npx would use for `bin`: the nearest one at or above `cwd` that has it. */
|
|
21
|
+
function binDirectory(cwd, bin) {
|
|
22
|
+
for (let dir = resolve(cwd);; dir = dirname(dir)) {
|
|
23
|
+
const candidate = join(dir, "node_modules", ".bin");
|
|
24
|
+
if (existsSync(join(candidate, bin)) || existsSync(join(candidate, `${bin}.cmd`)))
|
|
25
|
+
return candidate;
|
|
26
|
+
if (dirname(dir) === dir)
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The JavaScript file the npm/pnpm `sh` shim for `bin` runs with node, or undefined. */
|
|
31
|
+
function shimScript(binDir, bin) {
|
|
32
|
+
const shim = join(binDir, bin);
|
|
33
|
+
if (!existsSync(shim))
|
|
34
|
+
return undefined;
|
|
35
|
+
let text;
|
|
36
|
+
try {
|
|
37
|
+
text = readFileSync(shim, "utf8");
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
// npm: exec node "$basedir/../tsx/dist/cli.mjs" "$@" pnpm: exec node "$basedir/../tsx/dist/cli.mjs" "$@"
|
|
43
|
+
const match = /exec\s+(?:"\$basedir\/node"|node)\s+"\$basedir\/([^"$]+)"\s+"\$@"/.exec(text);
|
|
44
|
+
if (!match)
|
|
45
|
+
return undefined;
|
|
46
|
+
const script = resolve(binDir, match[1]);
|
|
47
|
+
return /\.(?:c|m)?js$/.test(script) && existsSync(script) ? script : undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `command` as Windows should launch it from `cwd`: `npx --no-install <bin> ...` becomes
|
|
51
|
+
* `node <script> ...` with the extra PATH entry, or `command` unchanged when that is not safe.
|
|
52
|
+
*/
|
|
53
|
+
export function windowsLaunch(command, cwd) {
|
|
54
|
+
const match = NPX_PREFIX.exec(command);
|
|
55
|
+
if (!match)
|
|
56
|
+
return { command };
|
|
57
|
+
const binDir = binDirectory(cwd, match[1]);
|
|
58
|
+
const script = binDir ? shimScript(binDir, match[1]) : undefined;
|
|
59
|
+
if (!binDir || !script)
|
|
60
|
+
return { command };
|
|
61
|
+
const path = relative(cwd, script).replace(/\\/g, "/");
|
|
62
|
+
if (!SAFE_PATH.test(path))
|
|
63
|
+
return { command };
|
|
64
|
+
return { command: `node ${path}${command.slice(match[0].length)}`, pathEntry: binDir };
|
|
65
|
+
}
|
|
66
|
+
/** `env` with `entry` first on PATH, keeping Windows' own spelling of the key (usually `Path`). */
|
|
67
|
+
export function withPathEntry(env, entry) {
|
|
68
|
+
const key = Object.keys(env).find((name) => name.toUpperCase() === "PATH") ?? "PATH";
|
|
69
|
+
const current = env[key];
|
|
70
|
+
return { ...env, [key]: current ? `${entry}${delimiter}${current}` : entry };
|
|
71
|
+
}
|
|
@@ -4,6 +4,7 @@ import { existsSync, lstatSync, mkdirSync, readFileSync, writeFileSync } from "n
|
|
|
4
4
|
import { arch, cpus, platform, release, totalmem } from "node:os";
|
|
5
5
|
import { basename, dirname, resolve } from "node:path";
|
|
6
6
|
import { failingTestNames } from "./failure-baseline.js";
|
|
7
|
+
import { windowsLaunch, withPathEntry } from "./node-bin-launch.js";
|
|
7
8
|
import { runnerTestCount } from "./selected-coverage.js";
|
|
8
9
|
import { parseTestFileResults } from "./test-results.js";
|
|
9
10
|
import { classifyFailureFromEvidence, computeFailureFingerprint } from "../preflight/fingerprint.js";
|
|
@@ -252,23 +253,29 @@ export function measureCommand(command, options) {
|
|
|
252
253
|
const started = Date.now();
|
|
253
254
|
// Match the shell used by Windows package scripts, including && short-circuiting
|
|
254
255
|
// and native exit codes; Windows PowerShell 5 cannot execute those chains.
|
|
255
|
-
const
|
|
256
|
-
const
|
|
256
|
+
const windows = process.platform === "win32";
|
|
257
|
+
const shellCommand = windows ? "cmd.exe" : "sh";
|
|
258
|
+
// On Windows a repository-local runner starts as `node <script>`, not through `npx.cmd` and its bin's
|
|
259
|
+
// `.cmd` shim, each of which re-expands the arguments into another cmd.exe line (node-bin-launch.ts).
|
|
260
|
+
// The measurement still reports the command as planned.
|
|
261
|
+
const launch = windows ? windowsLaunch(command, options.cwd) : { command };
|
|
262
|
+
const shellArgv = windows ? ["/d", "/s", "/c", launch.command] : ["-c", command];
|
|
263
|
+
const env = {
|
|
264
|
+
...withoutTestRunnerContext(process.env),
|
|
265
|
+
...options.env,
|
|
266
|
+
CI: "1",
|
|
267
|
+
FORCE_COLOR: "0",
|
|
268
|
+
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|
|
269
|
+
npm_config_yes: "true",
|
|
270
|
+
};
|
|
257
271
|
const result = spawnSync(shellCommand, shellArgv, {
|
|
258
272
|
cwd: options.cwd,
|
|
259
273
|
encoding: "utf8",
|
|
260
274
|
timeout: options.timeoutMs,
|
|
261
275
|
maxBuffer: 256 * 1024 * 1024,
|
|
262
276
|
shell: false,
|
|
263
|
-
windowsVerbatimArguments:
|
|
264
|
-
env:
|
|
265
|
-
...withoutTestRunnerContext(process.env),
|
|
266
|
-
...options.env,
|
|
267
|
-
CI: "1",
|
|
268
|
-
FORCE_COLOR: "0",
|
|
269
|
-
COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
|
|
270
|
-
npm_config_yes: "true",
|
|
271
|
-
},
|
|
277
|
+
windowsVerbatimArguments: windows,
|
|
278
|
+
env: launch.pathEntry ? withPathEntry(env, launch.pathEntry) : env,
|
|
272
279
|
});
|
|
273
280
|
const finishedAt = new Date().toISOString();
|
|
274
281
|
const failingTests = result.status === 0 ? [] : failingTestNames(`${result.stdout ?? ""}
|