supercov 4.26.0 → 4.27.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/README.md +1 -0
- package/package.json +10 -10
- package/runtime/javascript/atomic.mjs +101 -3
- package/runtime/javascript/playwright.mjs +21 -7
- package/runtime/javascript/register.mjs +4 -1
- package/runtime/javascript/runtime.mjs +243 -92
- package/runtime/javascript/snapshots.mjs +8 -2
- package/runtime/javascript/vitest.mjs +12 -7
package/README.md
CHANGED
|
@@ -412,3 +412,4 @@ Ask questions, share what you measured, and talk to the people building Supercov
|
|
|
412
412
|
- [@maik-intellicoach](https://github.com/maik-intellicoach)
|
|
413
413
|
- [@untitaker](https://github.com/untitaker)
|
|
414
414
|
- [@artile](https://github.com/artile)
|
|
415
|
+
- [@Fidasek009](https://github.com/Fidasek009)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supercov",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.27.0",
|
|
4
4
|
"description": "Coverage, security and code quality for coding agents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"coverage",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"eval:skill": "claude plugin eval plugins/supercov --scaffold --trust-plugin --no-publish --model claude-sonnet-5 --judge-model claude-haiku-4-5 --threshold 0.66 --tag behavior trigger --allow-tools Bash Edit Write --max-cost-usd 15",
|
|
83
83
|
"eval:skill-triggers": "claude plugin eval plugins/supercov --scaffold --trust-plugin --no-publish --model claude-sonnet-5 --judge-model claude-haiku-4-5 --threshold 0.66 --tag trigger --ablation none --max-cost-usd 5",
|
|
84
84
|
"test:engine": "cargo fmt --all -- --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace && npm run test:runtime && npm run test:rust-assets && npm run test:engine-integrations",
|
|
85
|
-
"test:engine-integrations": "cargo build -p supercov && node scripts/html-report-integration.mjs && node scripts/rust-process-supervision.mjs && node scripts/rust-direct-node-integration.mjs && node scripts/rust-public-run-integration.mjs && node scripts/rust-embedded-runtime-integration.mjs && node scripts/rust-direct-vitest-integration.mjs && node scripts/rust-nested-vitest-integration.mjs && node scripts/rust-direct-jest-integration.mjs && node scripts/mocha-failure-output.mjs && node scripts/failure-output.mjs node ava tap && node scripts/side-by-side.mjs node && node scripts/merge-across.mjs && node scripts/import-line-evidence.mjs && node scripts/mock-reach.mjs && node scripts/rust-direct-playwright-integration.mjs && node scripts/rust-custom-browser-playwright-integration.mjs && node scripts/cross-origin-requests.mjs && node scripts/leaving-page.mjs && node scripts/shared-page.mjs && node scripts/context-headers.mjs && node scripts/context-cookies.mjs && node scripts/hidden-request-emit.mjs && node scripts/js-syntax-zoo.mjs && node scripts/ruby-syntax-zoo.mjs && node scripts/rust-syntax-zoo.mjs && node scripts/python-syntax-zoo.mjs && node scripts/go-syntax-zoo.mjs && node scripts/java-syntax-zoo.mjs && node scripts/background-by-time.mjs && node scripts/python-server-playwright.mjs && node scripts/ruby-server-playwright.mjs && node scripts/go-server-playwright.mjs && node scripts/jvm-server-playwright.mjs && node scripts/docker-server-playwright.mjs && node scripts/docker-clients-playwright.mjs && node scripts/docker-exec-playwright.mjs && node scripts/rust-classic-browser-integration.mjs && node scripts/exec-handover.mjs && node scripts/rust-region-container.mjs && node scripts/rust-top-packages-integration.mjs && node scripts/rust-generic-esbuild-integration.mjs && node scripts/rust-generic-tsc-integration.mjs && node scripts/rust-generic-build-matrix.mjs && node scripts/rust-vite-playwright-integration.mjs && node scripts/workspace-crash-integration.mjs",
|
|
85
|
+
"test:engine-integrations": "cargo build -p supercov && node scripts/html-report-integration.mjs && node scripts/rust-process-supervision.mjs && node scripts/rust-direct-node-integration.mjs && node scripts/rust-public-run-integration.mjs && node scripts/rust-embedded-runtime-integration.mjs && node scripts/rust-direct-vitest-integration.mjs && node scripts/rust-nested-vitest-integration.mjs && node scripts/rust-direct-jest-integration.mjs && node scripts/mocha-failure-output.mjs && node scripts/failure-output.mjs node ava tap && node scripts/side-by-side.mjs node && node scripts/merge-across.mjs && node scripts/import-line-evidence.mjs && node scripts/mock-reach.mjs && node scripts/rust-direct-playwright-integration.mjs && node scripts/rust-custom-browser-playwright-integration.mjs && node scripts/cross-origin-requests.mjs && node scripts/leaving-page.mjs && node scripts/shared-page.mjs && node scripts/context-script-copies.mjs && node scripts/context-headers.mjs && node scripts/context-cookies.mjs && node scripts/hidden-request-emit.mjs && node scripts/js-syntax-zoo.mjs && node scripts/ruby-syntax-zoo.mjs && node scripts/rust-syntax-zoo.mjs && node scripts/python-syntax-zoo.mjs && node scripts/go-syntax-zoo.mjs && node scripts/java-syntax-zoo.mjs && node scripts/background-by-time.mjs && node scripts/python-server-playwright.mjs && node scripts/ruby-server-playwright.mjs && node scripts/go-server-playwright.mjs && node scripts/jvm-server-playwright.mjs && node scripts/docker-server-playwright.mjs && node scripts/docker-clients-playwright.mjs && node scripts/docker-exec-playwright.mjs && node scripts/rust-classic-browser-integration.mjs && node scripts/exec-handover.mjs && node scripts/rust-region-container.mjs && node scripts/rust-top-packages-integration.mjs && node scripts/rust-generic-esbuild-integration.mjs && node scripts/rust-generic-tsc-integration.mjs && node scripts/rust-generic-build-matrix.mjs && node scripts/rust-vite-playwright-integration.mjs && node scripts/workspace-crash-integration.mjs",
|
|
86
86
|
"test:platform": "cargo test --workspace && cargo build -p supercov && node scripts/rust-process-supervision.mjs && node scripts/workspace-crash-integration.mjs",
|
|
87
87
|
"test:native-package": "cargo build --release -p supercov && node scripts/native-package-integration.mjs && node scripts/native-release-set-integration.mjs",
|
|
88
88
|
"test:pypi-wheel": "node scripts/pypi-wheel-integration.mjs",
|
|
@@ -124,14 +124,14 @@
|
|
|
124
124
|
"test:windows-tls": "node scripts/windows-tls-test.mjs"
|
|
125
125
|
},
|
|
126
126
|
"optionalDependencies": {
|
|
127
|
-
"@supercov/cli-darwin-arm64": "4.
|
|
128
|
-
"@supercov/cli-darwin-x64": "4.
|
|
129
|
-
"@supercov/cli-linux-arm64-gnu": "4.
|
|
130
|
-
"@supercov/cli-linux-arm64-musl": "4.
|
|
131
|
-
"@supercov/cli-linux-x64-gnu": "4.
|
|
132
|
-
"@supercov/cli-linux-x64-musl": "4.
|
|
133
|
-
"@supercov/cli-win32-arm64": "4.
|
|
134
|
-
"@supercov/cli-win32-x64": "4.
|
|
127
|
+
"@supercov/cli-darwin-arm64": "4.27.0",
|
|
128
|
+
"@supercov/cli-darwin-x64": "4.27.0",
|
|
129
|
+
"@supercov/cli-linux-arm64-gnu": "4.27.0",
|
|
130
|
+
"@supercov/cli-linux-arm64-musl": "4.27.0",
|
|
131
|
+
"@supercov/cli-linux-x64-gnu": "4.27.0",
|
|
132
|
+
"@supercov/cli-linux-x64-musl": "4.27.0",
|
|
133
|
+
"@supercov/cli-win32-arm64": "4.27.0",
|
|
134
|
+
"@supercov/cli-win32-x64": "4.27.0"
|
|
135
135
|
},
|
|
136
136
|
"peerDependencies": {
|
|
137
137
|
"@playwright/test": ">=1.55.0",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import fs, { appendFileSync, chmodSync, existsSync, mkdirSync, openSync, closeSync, fsyncSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { syncBuiltinESMExports } from "node:module";
|
|
1
|
+
import fs, { appendFileSync, chmodSync, existsSync, mkdirSync, openSync, closeSync, readFileSync, fsyncSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import Module, { syncBuiltinESMExports } from "node:module";
|
|
4
4
|
import { threadId } from "node:worker_threads";
|
|
5
5
|
import { basename, dirname, resolve, sep } from "node:path";
|
|
6
6
|
import { Buffer } from "node:buffer";
|
|
7
|
+
import vm from "node:vm";
|
|
7
8
|
|
|
8
9
|
// In a container Supercov's `docker` launcher mounts the run's directory
|
|
9
10
|
// into, its user (root) owns what it creates there; a directory made with
|
|
@@ -203,3 +204,100 @@ export function writePlaywrightCacheWhole() {
|
|
|
203
204
|
};
|
|
204
205
|
syncBuiltinESMExports();
|
|
205
206
|
}
|
|
207
|
+
|
|
208
|
+
// Compiled code for instrumented modules, kept for the rest of the run.
|
|
209
|
+
//
|
|
210
|
+
// Vitest evaluates every module a test file imports in a fresh worker for
|
|
211
|
+
// each test file, and compiles each again: an instrumented module is several
|
|
212
|
+
// times its source, so most of what Supercov added to a large unit suite was
|
|
213
|
+
// V8 compiling the same instrumented text over and over. V8 can start from
|
|
214
|
+
// code it compiled before (a script's cached data), checks it against the
|
|
215
|
+
// source and its own version and flags, and compiles afresh when it does not
|
|
216
|
+
// match, so a module behaves as it would have either way.
|
|
217
|
+
//
|
|
218
|
+
// `vm.runInThisContext` is what Vitest's module runner calls; it is wrapped
|
|
219
|
+
// for instrumented text alone. Each compiled module's code is written once
|
|
220
|
+
// its test file is done, when it holds the functions the file ran as well as
|
|
221
|
+
// the module's top level, for the workers after it to start from.
|
|
222
|
+
|
|
223
|
+
// The installed wrapper carries its state: where the cache is, and the
|
|
224
|
+
// scripts compiled with no cached data that matched, each with where to keep
|
|
225
|
+
// its code. Any copy of this module saves what the one wrapper compiled.
|
|
226
|
+
const STATE = Symbol.for("supercov.compileCache");
|
|
227
|
+
const MARK = "__supercov";
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Wraps `vm.runInThisContext` in this process to compile instrumented text
|
|
231
|
+
* from what `directory` keeps. Once per process: every copy of the runtime
|
|
232
|
+
* shares the one wrapper.
|
|
233
|
+
*/
|
|
234
|
+
/**
|
|
235
|
+
* Node's own compile cache for every module Node loads in this process --
|
|
236
|
+
* its CommonJS and ES modules, the runtime's among them -- kept in `directory`
|
|
237
|
+
* for the processes after it: a runner that starts a fresh process or worker
|
|
238
|
+
* per test file compiled the same packages again in each. A command that set
|
|
239
|
+
* NODE_COMPILE_CACHE keeps its own. Only how long compiling takes changes.
|
|
240
|
+
* Not on Windows: there `node --test`'s child for a test file never finished
|
|
241
|
+
* once the cache was on.
|
|
242
|
+
*/
|
|
243
|
+
export function enableNodeCompileCache(directory) {
|
|
244
|
+
if (!directory || process.platform === "win32" || process.env.NODE_COMPILE_CACHE !== undefined ||
|
|
245
|
+
typeof Module.enableCompileCache !== "function")
|
|
246
|
+
return;
|
|
247
|
+
Module.enableCompileCache(resolve(directory, "node"));
|
|
248
|
+
}
|
|
249
|
+
export function installCompileCache(directory) {
|
|
250
|
+
if (!directory || vm.runInThisContext[STATE])
|
|
251
|
+
return;
|
|
252
|
+
const original = vm.runInThisContext;
|
|
253
|
+
const state = { directory, unsaved: [] };
|
|
254
|
+
const cached = function runInThisContext(code, options) {
|
|
255
|
+
// The filename-only form and anything not instrumented go as they
|
|
256
|
+
// came.
|
|
257
|
+
if (typeof code !== "string" || (options !== undefined && (options === null || typeof options !== "object")) || !code.includes(MARK))
|
|
258
|
+
return Reflect.apply(original, this, arguments);
|
|
259
|
+
const key = createHash("sha256")
|
|
260
|
+
.update(code)
|
|
261
|
+
.update("\0")
|
|
262
|
+
.update(JSON.stringify([options?.filename, options?.lineOffset, options?.columnOffset]))
|
|
263
|
+
.digest("hex");
|
|
264
|
+
const file = resolve(directory, key);
|
|
265
|
+
let cachedData;
|
|
266
|
+
try {
|
|
267
|
+
cachedData = readFileSync(file);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
cachedData = undefined;
|
|
271
|
+
}
|
|
272
|
+
// What `vm.runInThisContext` does, with the cached data.
|
|
273
|
+
const script = new vm.Script(code, { ...options, cachedData });
|
|
274
|
+
if (cachedData === undefined || script.cachedDataRejected)
|
|
275
|
+
state.unsaved.push([file, script]);
|
|
276
|
+
return script.runInThisContext(options);
|
|
277
|
+
};
|
|
278
|
+
cached[STATE] = state;
|
|
279
|
+
vm.runInThisContext = cached;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Writes the code of each module compiled since the last save without cached
|
|
284
|
+
* data: what V8 holds of it now, the functions run so far included. A file
|
|
285
|
+
* another worker wrote meanwhile is replaced whole, never torn.
|
|
286
|
+
*/
|
|
287
|
+
export function saveCompileCache() {
|
|
288
|
+
const state = vm.runInThisContext[STATE];
|
|
289
|
+
if (!state || state.unsaved.length === 0)
|
|
290
|
+
return;
|
|
291
|
+
const scripts = state.unsaved.splice(0);
|
|
292
|
+
try {
|
|
293
|
+
makeDirectory(state.directory);
|
|
294
|
+
for (const [file, script] of scripts) {
|
|
295
|
+
const partial = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}`;
|
|
296
|
+
writeFileSync(partial, script.createCachedData(), { mode: fileMode() });
|
|
297
|
+
renameSync(partial, file);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
// A cache that cannot be written is compiled again next time.
|
|
302
|
+
}
|
|
303
|
+
}
|
|
@@ -585,12 +585,14 @@ class CoveragePhaseController {
|
|
|
585
585
|
// leaves the others.
|
|
586
586
|
const parts = [];
|
|
587
587
|
// A context that outlives its test (a worker-scoped browser fixture)
|
|
588
|
-
// is registered again by every later test
|
|
589
|
-
//
|
|
590
|
-
//
|
|
591
|
-
//
|
|
592
|
-
//
|
|
593
|
-
//
|
|
588
|
+
// is registered again by every later test. Every copy publishes its
|
|
589
|
+
// own attempt, so the newest wins, and the fetch patch is installed
|
|
590
|
+
// once and reads the attempt at call time: a stale copy can never pin
|
|
591
|
+
// an old scope onto a request. Where Playwright can remove a script
|
|
592
|
+
// (its `addInitScript` returns a disposable), the previous test's copy is
|
|
593
|
+
// removed once this one is in place, so a document runs one copy:
|
|
594
|
+
// they accumulated to some fifty per context on a long suite, each
|
|
595
|
+
// sent to every new page and frame and run by every document.
|
|
594
596
|
parts.push(`(${announceAttempt})(${JSON.stringify({
|
|
595
597
|
attemptId: this.scope.attemptId,
|
|
596
598
|
scopeHeader: COVERAGE_SCOPE_HEADER,
|
|
@@ -606,10 +608,20 @@ class CoveragePhaseController {
|
|
|
606
608
|
phaseCookie: COVERAGE_DOCUMENT_PHASE_COOKIE,
|
|
607
609
|
phaseSiteCookie: COVERAGE_DOCUMENT_PHASE_SITE_COOKIE,
|
|
608
610
|
})});`);
|
|
609
|
-
await Promise.all([
|
|
611
|
+
const [added] = await Promise.all([
|
|
610
612
|
context.addInitScript({ content: separately(parts) }).catch(() => undefined),
|
|
611
613
|
adopted ? undefined : this.updateContextHeaders(context, this.requestPhaseId(), this.lastActionId),
|
|
612
614
|
]);
|
|
615
|
+
if (typeof added?.dispose === "function") {
|
|
616
|
+
const previous = contextInitScripts.get(context);
|
|
617
|
+
contextInitScripts.set(context, added);
|
|
618
|
+
// Not awaited: the test waits for nothing it needs here, and a
|
|
619
|
+
// context closed meanwhile has no script left to remove.
|
|
620
|
+
if (previous)
|
|
621
|
+
void internally(context, () => previous.dispose()).catch(() => undefined);
|
|
622
|
+
if (timingBuckets)
|
|
623
|
+
contextScriptCopies.set(context, 1);
|
|
624
|
+
}
|
|
613
625
|
const register = (page) => {
|
|
614
626
|
const pending = this.registerPage(page).finally(() => this.pendingRegistrations.delete(pending));
|
|
615
627
|
this.pendingRegistrations.add(pending);
|
|
@@ -1148,6 +1160,8 @@ function announceAttempt({ attemptId, scopeHeader, scopeValue, scopeCookie, scop
|
|
|
1148
1160
|
// While timing: how many tests' scripts each context has run (a context
|
|
1149
1161
|
// that outlives its test is registered by every later test).
|
|
1150
1162
|
const contextScriptCopies = new WeakMap();
|
|
1163
|
+
// The disposable of the script each context's newest registration added.
|
|
1164
|
+
const contextInitScripts = new WeakMap();
|
|
1151
1165
|
const LEAVING_BINDING = "__supercovLeaving";
|
|
1152
1166
|
/** Scripts as one, each part run on its own as separate scripts were. */
|
|
1153
1167
|
function separately(parts) {
|
|
@@ -13,7 +13,7 @@ import { fileURLToPath } from "node:url";
|
|
|
13
13
|
import { installLaunchSupervisor, wrapImportedCapability } from "./launchSupervisor.mjs";
|
|
14
14
|
import { __supercovBindCapabilityWrapper } from "./capability.mjs";
|
|
15
15
|
import { adaptRunnerEntry, noteSkippedCoverageThresholds } from "./runnerEntry.mjs";
|
|
16
|
-
import { writePlaywrightCacheWhole } from "./atomic.mjs";
|
|
16
|
+
import { enableNodeCompileCache, writePlaywrightCacheWhole } from "./atomic.mjs";
|
|
17
17
|
// Supercov runs Node with --enable-source-maps so a stack through an
|
|
18
18
|
// instrumented copy names the project's file. The flag also reads the maps
|
|
19
19
|
// every package ships, which a plain run never does: a third of the CPU a
|
|
@@ -24,6 +24,9 @@ if ((process.env.NODE_OPTIONS ?? "").split(/\s+/).filter((option) => option ===
|
|
|
24
24
|
!process.execArgv.includes("--enable-source-maps") &&
|
|
25
25
|
typeof Module.setSourceMapsSupport === "function")
|
|
26
26
|
Module.setSourceMapsSupport(true, { nodeModules: false, generatedCode: true });
|
|
27
|
+
// Before anything else loads: every module after this compiles from the
|
|
28
|
+
// code the run's earlier processes left (atomic.mjs says why).
|
|
29
|
+
enableNodeCompileCache(process.env.SUPERCOV_COMPILE_CACHE);
|
|
27
30
|
installLaunchSupervisor();
|
|
28
31
|
// Playwright's compile cache, written whole (atomic.mjs says why).
|
|
29
32
|
writePlaywrightCacheWhole();
|
|
@@ -138,6 +138,17 @@ function backgroundEvidencePath(runId, processId = typeof process === "undefined
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// dist/runtime.js
|
|
141
|
+
// The collections a probe records into, called through the built-in methods
|
|
142
|
+
// as they were when the runtime loaded: a test that spies on
|
|
143
|
+
// Map.prototype.set counts the calls its own code makes, and Supercov's
|
|
144
|
+
// first hits made three more, failing a test that passes without it.
|
|
145
|
+
var builtinMapGet = Map.prototype.get;
|
|
146
|
+
var builtinMapSet = Map.prototype.set;
|
|
147
|
+
var builtinMapHas = Map.prototype.has;
|
|
148
|
+
var builtinSetAdd = Set.prototype.add;
|
|
149
|
+
var builtinSetHas = Set.prototype.has;
|
|
150
|
+
var builtinWeakMapGet = WeakMap.prototype.get;
|
|
151
|
+
var builtinWeakMapSet = WeakMap.prototype.set;
|
|
141
152
|
var runtimeGlobal = globalThis;
|
|
142
153
|
var runtimeInstanceToken = "__SUPERCOV_RUNTIME_INSTANCE__";
|
|
143
154
|
var runtimeInstance = runtimeInstanceToken === "__SUPERCOV_RUNTIME_INSTANCE__" ? "application" : runtimeInstanceToken;
|
|
@@ -161,12 +172,28 @@ function getFs() {
|
|
|
161
172
|
return void 0;
|
|
162
173
|
}
|
|
163
174
|
}
|
|
175
|
+
function emptyEventLog() {
|
|
176
|
+
return { type: [], id: [], vector: [], timestampMs: [], phaseId: [], environment: [] };
|
|
177
|
+
}
|
|
178
|
+
// The events as they were recorded, each the object hitEvent or
|
|
179
|
+
// decisionEvent built, in their key order.
|
|
180
|
+
function eventObjects(log) {
|
|
181
|
+
const events = new Array(log.id.length);
|
|
182
|
+
for (let position = 0; position < events.length; position += 1) {
|
|
183
|
+
const phaseId = log.phaseId[position];
|
|
184
|
+
events[position] = log.type[position] === "hit" ? hitEvent(log.id[position], log.timestampMs[position], phaseId, log.environment[position]) : decisionEvent(log.id[position], log.vector[position], log.timestampMs[position], phaseId, log.environment[position]);
|
|
185
|
+
}
|
|
186
|
+
return events;
|
|
187
|
+
}
|
|
164
188
|
function createState() {
|
|
165
189
|
var _a8, _b, _c, _d;
|
|
166
190
|
const state2 = {
|
|
167
191
|
decisions: /* @__PURE__ */ new Map(),
|
|
168
192
|
hits: /* @__PURE__ */ new Set(),
|
|
169
|
-
events:
|
|
193
|
+
// The events as columns, one entry per event: a first hit of every point
|
|
194
|
+
// of every test was an object of its own, millions on a large suite,
|
|
195
|
+
// turned into columns again for the evidence (eventColumns).
|
|
196
|
+
eventLog: emptyEventLog(),
|
|
170
197
|
// Per value-position logical expression (`a && b`, `a || b`, `a ?? b`): the distinct
|
|
171
198
|
// (right operand evaluated?, result truthy?) pairs seen, keyed by branch id.
|
|
172
199
|
logicals: /* @__PURE__ */ new Map(),
|
|
@@ -184,8 +211,13 @@ function createState() {
|
|
|
184
211
|
backgroundSequence: 0,
|
|
185
212
|
runtimeSnapshots: false,
|
|
186
213
|
assertionPhases: /* @__PURE__ */ new Map(),
|
|
214
|
+
// Each registered file, held weakly where the engine can: only the
|
|
215
|
+
// epochs' wrap below reads them, to clear what live files remember.
|
|
187
216
|
probeV2Files: /* @__PURE__ */ new Set(),
|
|
188
|
-
|
|
217
|
+
probeV2FilesSweepAt: 1024,
|
|
218
|
+
// `e` is the epoch: every statement probe reads it by name, and a
|
|
219
|
+
// minifier keeps a property's name, so it is one letter in every bundle.
|
|
220
|
+
probeV2Clock: { e: Number.NaN, fast: false },
|
|
189
221
|
probeV2ContextEpochs: /* @__PURE__ */ new Map(),
|
|
190
222
|
probeV2NextEpoch: 1,
|
|
191
223
|
probeV2HookInstalled: false,
|
|
@@ -207,10 +239,8 @@ function createState() {
|
|
|
207
239
|
}
|
|
208
240
|
for (const id of (_c = stored.hits) != null ? _c : [])
|
|
209
241
|
state2.hits.add(id);
|
|
210
|
-
for (const event of (_d = stored.events) != null ? _d : [])
|
|
211
|
-
state2.
|
|
212
|
-
eventSeen(state2.eventKeys, event);
|
|
213
|
-
}
|
|
242
|
+
for (const event of (_d = stored.events) != null ? _d : [])
|
|
243
|
+
recordEvent(state2, event.type, event.id, event.vector, event.timestampMs, event.phaseId, event.environment);
|
|
214
244
|
} catch (e) {
|
|
215
245
|
}
|
|
216
246
|
return state2;
|
|
@@ -250,18 +280,18 @@ function probeV2ContextKey(context) {
|
|
|
250
280
|
return `scope\0${attemptKey(context.scope)}\0${phase}`;
|
|
251
281
|
}
|
|
252
282
|
function activateProbeV2Key(key, force = false) {
|
|
253
|
-
let epoch = force ? void 0 : state.probeV2ContextEpochs
|
|
283
|
+
let epoch = force ? void 0 : builtinMapGet.call(state.probeV2ContextEpochs, key);
|
|
254
284
|
if (epoch === void 0) {
|
|
255
285
|
state.probeV2NextEpoch += 1;
|
|
256
286
|
if (state.probeV2NextEpoch >= 4294967295) {
|
|
257
287
|
state.probeV2NextEpoch = 1;
|
|
258
288
|
state.probeV2ContextEpochs.clear();
|
|
259
289
|
state.probeV2EpochGeneration = (state.probeV2EpochGeneration || 0) + 1;
|
|
260
|
-
for (const
|
|
290
|
+
for (const held of state.probeV2Files) {
|
|
291
|
+
const file = typeof held.deref === "function" ? held.deref() : held;
|
|
292
|
+
if (file === void 0)
|
|
293
|
+
continue;
|
|
261
294
|
file.hitEpochs.fill(0);
|
|
262
|
-
file.decisionObservationEpochs.fill(0);
|
|
263
|
-
file.decisionObservationCounts.fill(0);
|
|
264
|
-
file.decisionCompleteEpochs.fill(0);
|
|
265
295
|
for (const vectors of file.decisionEpochs) {
|
|
266
296
|
if (vectors.size === void 0)
|
|
267
297
|
vectors.fill(0);
|
|
@@ -271,9 +301,9 @@ function activateProbeV2Key(key, force = false) {
|
|
|
271
301
|
}
|
|
272
302
|
}
|
|
273
303
|
epoch = state.probeV2NextEpoch;
|
|
274
|
-
state.probeV2ContextEpochs
|
|
304
|
+
builtinMapSet.call(state.probeV2ContextEpochs, key, epoch);
|
|
275
305
|
}
|
|
276
|
-
state.probeV2Clock.
|
|
306
|
+
state.probeV2Clock.e = epoch;
|
|
277
307
|
return epoch;
|
|
278
308
|
}
|
|
279
309
|
// The async hook activates the current request's context before every
|
|
@@ -294,28 +324,51 @@ function activateProbeV2Context(context) {
|
|
|
294
324
|
state.probeV2ContextEpochCache = /* @__PURE__ */ new WeakMap();
|
|
295
325
|
state.probeV2EpochGeneration = 0;
|
|
296
326
|
}
|
|
297
|
-
const cached = state.probeV2ContextEpochCache
|
|
327
|
+
const cached = builtinWeakMapGet.call(state.probeV2ContextEpochCache, context);
|
|
298
328
|
if (cached !== void 0 && cached.generation === state.probeV2EpochGeneration) {
|
|
299
|
-
state.probeV2Clock.
|
|
329
|
+
state.probeV2Clock.e = cached.epoch;
|
|
300
330
|
return cached.epoch;
|
|
301
331
|
}
|
|
302
332
|
const epoch = activateProbeV2Key(probeV2ContextKey(context));
|
|
303
|
-
state.probeV2ContextEpochCache
|
|
333
|
+
builtinWeakMapSet.call(state.probeV2ContextEpochCache, context, { generation: state.probeV2EpochGeneration, epoch });
|
|
304
334
|
return epoch;
|
|
305
335
|
}
|
|
336
|
+
// While the speed benchmark times a run: how often a server's async hook ran
|
|
337
|
+
// and how often a probe then had to work out its context, said once when the
|
|
338
|
+
// process ends.
|
|
339
|
+
var serverTiming = !isBrowser && typeof process !== "undefined" && process.env && process.env["SUPERCOV_PHASE_TIMING"] === "1" ? { asyncHookCallbacks: 0, contextResolutions: 0 } : void 0;
|
|
340
|
+
if (serverTiming) {
|
|
341
|
+
try {
|
|
342
|
+
process.once("exit", () => {
|
|
343
|
+
if (serverTiming.asyncHookCallbacks || serverTiming.contextResolutions)
|
|
344
|
+
process.stderr.write(`[supercov-timing] server ${process.pid} asyncHookCallbacks=${serverTiming.asyncHookCallbacks} contextResolutions=${serverTiming.contextResolutions}\n`);
|
|
345
|
+
});
|
|
346
|
+
} catch (e) {
|
|
347
|
+
}
|
|
348
|
+
}
|
|
306
349
|
// The context the async hook leaves to a callback's first probe: the
|
|
307
350
|
// request's store, or else the one the environment carries.
|
|
308
351
|
function resolveProbeV2Epoch() {
|
|
309
352
|
var _a8, _b;
|
|
353
|
+
if (serverTiming)
|
|
354
|
+
serverTiming.contextResolutions += 1;
|
|
310
355
|
return activateProbeV2Context((_b = (_a8 = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore()) != null ? _a8 : environmentRequestContext()) != null ? _b : emptyProbeV2Context);
|
|
311
356
|
}
|
|
357
|
+
// A statement probe trusts the clock's epoch with no check of `fast`: while
|
|
358
|
+
// the clock is not fast -- no async hook keeps it -- its epoch is NaN wherever
|
|
359
|
+
// instrumented code can run, which no recorded epoch equals, so every probe
|
|
360
|
+
// takes the slow path and works out its context there, as it did when probes
|
|
361
|
+
// checked `fast` first. What sets the epoch while not fast restores it before
|
|
362
|
+
// instrumented code runs, or does not set it.
|
|
312
363
|
function withProbeV2Context(context, callback) {
|
|
313
|
-
|
|
364
|
+
if (!state.probeV2Clock.fast)
|
|
365
|
+
return callback();
|
|
366
|
+
const previous = state.probeV2Clock.e;
|
|
314
367
|
activateProbeV2Context(context);
|
|
315
368
|
try {
|
|
316
369
|
return callback();
|
|
317
370
|
} finally {
|
|
318
|
-
state.probeV2Clock.
|
|
371
|
+
state.probeV2Clock.e = previous;
|
|
319
372
|
}
|
|
320
373
|
}
|
|
321
374
|
function installProbeV2AsyncHook() {
|
|
@@ -335,12 +388,14 @@ function installProbeV2AsyncHook() {
|
|
|
335
388
|
// environment twice and built a key each time: on a Next app's suite,
|
|
336
389
|
// more of the server's time than any of Supercov's other work.
|
|
337
390
|
before() {
|
|
338
|
-
|
|
339
|
-
|
|
391
|
+
if (serverTiming)
|
|
392
|
+
serverTiming.asyncHookCallbacks += 1;
|
|
393
|
+
epochs.push(state.probeV2Clock.e);
|
|
394
|
+
state.probeV2Clock.e = NaN;
|
|
340
395
|
},
|
|
341
396
|
after() {
|
|
342
397
|
var _a9;
|
|
343
|
-
state.probeV2Clock.
|
|
398
|
+
state.probeV2Clock.e = (_a9 = epochs.pop()) != null ? _a9 : state.probeV2Clock.e;
|
|
344
399
|
}
|
|
345
400
|
}).enable();
|
|
346
401
|
state.probeV2HookInstalled = true;
|
|
@@ -368,19 +423,72 @@ function coverageSnapshot() {
|
|
|
368
423
|
return {
|
|
369
424
|
decisions: decisionSnapshot(),
|
|
370
425
|
hits: [...state.hits],
|
|
371
|
-
events: state.
|
|
426
|
+
events: eventObjects(state.eventLog),
|
|
372
427
|
logicals: logicalSnapshot()
|
|
373
428
|
};
|
|
374
429
|
}
|
|
430
|
+
// coverageSnapshot as snapshots.mjs's columnarEvents gives it, built from the
|
|
431
|
+
// columns the events are kept in rather than from an object per event.
|
|
432
|
+
function coverageSnapshotColumns() {
|
|
433
|
+
const log = state.eventLog;
|
|
434
|
+
const decisions = decisionSnapshot();
|
|
435
|
+
const hits = [...state.hits];
|
|
436
|
+
const logicals = logicalSnapshot();
|
|
437
|
+
if (log.id.length === 0)
|
|
438
|
+
return { decisions, hits, events: [], logicals };
|
|
439
|
+
const tables = { types: /* @__PURE__ */ new Map(), phases: /* @__PURE__ */ new Map(), environments: /* @__PURE__ */ new Map() };
|
|
440
|
+
const index = (table, value) => {
|
|
441
|
+
let found = table.get(value);
|
|
442
|
+
if (found === void 0) {
|
|
443
|
+
found = table.size;
|
|
444
|
+
table.set(value, found);
|
|
445
|
+
}
|
|
446
|
+
return found;
|
|
447
|
+
};
|
|
448
|
+
// An event that is one of the hits names it by its position in `hits`
|
|
449
|
+
// (snapshots.mjs's columnarEvents says why).
|
|
450
|
+
const hitAt = /* @__PURE__ */ new Map();
|
|
451
|
+
for (let position = 0; position < hits.length; position += 1)
|
|
452
|
+
hitAt.set(hits[position], position);
|
|
453
|
+
const columns = { id: [], type: [], phase: [], environment: [], t: [], vector: {} };
|
|
454
|
+
let previous = 0;
|
|
455
|
+
for (let position = 0; position < log.id.length; position += 1) {
|
|
456
|
+
const id = log.id[position];
|
|
457
|
+
const at = hitAt.get(id);
|
|
458
|
+
columns.id.push(at === void 0 ? id : at);
|
|
459
|
+
const phaseId = log.phaseId[position];
|
|
460
|
+
columns.type.push(index(tables.types, log.type[position]));
|
|
461
|
+
// An event built without a phase -- phaseId falsy -- has none.
|
|
462
|
+
columns.phase.push(phaseId ? index(tables.phases, phaseId) : -1);
|
|
463
|
+
columns.environment.push(index(tables.environments, log.environment[position]));
|
|
464
|
+
columns.t.push(log.timestampMs[position] - previous);
|
|
465
|
+
previous = log.timestampMs[position];
|
|
466
|
+
if (log.type[position] !== "hit")
|
|
467
|
+
columns.vector[position] = log.vector[position];
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
decisions,
|
|
471
|
+
hits,
|
|
472
|
+
logicals,
|
|
473
|
+
eventColumns: {
|
|
474
|
+
types: [...tables.types.keys()],
|
|
475
|
+
phases: [...tables.phases.keys()],
|
|
476
|
+
environments: [...tables.environments.keys()],
|
|
477
|
+
...columns
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
375
481
|
function resetCoverage(testId2) {
|
|
376
482
|
state.decisions.clear();
|
|
377
483
|
state.hits.clear();
|
|
378
|
-
state.
|
|
484
|
+
state.eventLog = emptyEventLog();
|
|
379
485
|
state.logicals.clear();
|
|
380
486
|
state.eventKeys.clear();
|
|
381
487
|
state.probeV2ContextEpochs.clear();
|
|
382
488
|
state.probeV2EpochGeneration = (state.probeV2EpochGeneration || 0) + 1;
|
|
383
489
|
activateProbeV2Key(`reset\0${state.probeV2NextEpoch}`, true);
|
|
490
|
+
if (!state.probeV2Clock.fast)
|
|
491
|
+
state.probeV2Clock.e = NaN;
|
|
384
492
|
if (testId2)
|
|
385
493
|
runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__ = testId2;
|
|
386
494
|
if (isBrowser) {
|
|
@@ -543,7 +651,7 @@ var persistBrowserListenersInstalled = false;
|
|
|
543
651
|
// How much evidence the document holds. Every part of it only grows until a
|
|
544
652
|
// reset, so the same size twice is the same evidence.
|
|
545
653
|
function evidenceSize() {
|
|
546
|
-
let size = state.hits.size + state.
|
|
654
|
+
let size = state.hits.size + state.eventLog.id.length;
|
|
547
655
|
for (const decision of state.decisions.values())
|
|
548
656
|
size += decision.vectors.size;
|
|
549
657
|
for (const vectors of state.logicals.values())
|
|
@@ -1174,9 +1282,9 @@ function appendServer(record) {
|
|
|
1174
1282
|
if (state.runtimeSnapshots) {
|
|
1175
1283
|
const timestampMs = (_a8 = record.timestampMs) != null ? _a8 : Date.now();
|
|
1176
1284
|
if (record.type === "decision")
|
|
1177
|
-
recordBrowserEvent(
|
|
1285
|
+
recordBrowserEvent("decision", record.id, record.vector, timestampMs, record.phaseId, "server");
|
|
1178
1286
|
else
|
|
1179
|
-
recordBrowserEvent(
|
|
1287
|
+
recordBrowserEvent("hit", record.id, void 0, timestampMs, record.phaseId, "server");
|
|
1180
1288
|
return;
|
|
1181
1289
|
}
|
|
1182
1290
|
const fs = getFs();
|
|
@@ -1470,13 +1578,16 @@ function enterCoverageCarrier(carrier) {
|
|
|
1470
1578
|
return () => {
|
|
1471
1579
|
};
|
|
1472
1580
|
const previousStore = serverPhaseStorage.getStore();
|
|
1473
|
-
const previousEpoch = state.probeV2Clock.
|
|
1581
|
+
const previousEpoch = state.probeV2Clock.e;
|
|
1582
|
+
const fast = state.probeV2Clock.fast;
|
|
1474
1583
|
const context = __spreadValues(__spreadValues({}, carrier.scope ? { scope: carrier.scope } : {}), carrier.phaseId ? { phaseId: carrier.phaseId } : {});
|
|
1475
1584
|
serverPhaseStorage.enterWith(context);
|
|
1476
|
-
|
|
1585
|
+
if (fast)
|
|
1586
|
+
activateProbeV2Context(context);
|
|
1477
1587
|
return () => {
|
|
1478
1588
|
serverPhaseStorage.enterWith(previousStore);
|
|
1479
|
-
|
|
1589
|
+
if (fast)
|
|
1590
|
+
state.probeV2Clock.e = previousEpoch;
|
|
1480
1591
|
};
|
|
1481
1592
|
}
|
|
1482
1593
|
var inertAssertionPhase = { close: (value) => value, fail: (error) => error };
|
|
@@ -1937,23 +2048,42 @@ function withRequestPhase(handler, event) {
|
|
|
1937
2048
|
// Whether `event` was already recorded, recording it if not. Kept per phase,
|
|
1938
2049
|
// so a first hit looks up its id alone: one key joining the phase, the type
|
|
1939
2050
|
// and the id was built and hashed for every first hit of every test.
|
|
1940
|
-
function eventSeen(seen,
|
|
1941
|
-
const phase =
|
|
1942
|
-
let keys =
|
|
2051
|
+
function eventSeen(seen, type, id, vector, phaseId) {
|
|
2052
|
+
const phase = phaseId != null ? phaseId : "unscoped";
|
|
2053
|
+
let keys = builtinMapGet.call(seen, phase);
|
|
1943
2054
|
if (keys === void 0) {
|
|
1944
2055
|
keys = /* @__PURE__ */ new Set();
|
|
1945
|
-
|
|
2056
|
+
builtinMapSet.call(seen, phase, keys);
|
|
1946
2057
|
}
|
|
1947
|
-
const key =
|
|
1948
|
-
if (
|
|
2058
|
+
const key = type === "hit" ? id : `${type}\0${type === "decision" ? `${id}:${vectorKey(vector)}` : id}`;
|
|
2059
|
+
if (builtinSetHas.call(keys, key))
|
|
1949
2060
|
return true;
|
|
1950
|
-
|
|
2061
|
+
builtinSetAdd.call(keys, key);
|
|
1951
2062
|
return false;
|
|
1952
2063
|
}
|
|
1953
|
-
|
|
1954
|
-
|
|
2064
|
+
// The phase eventSeen keys an event under: an event object built without a
|
|
2065
|
+
// falsy phase (hitEvent, decisionEvent) had none, which is "unscoped".
|
|
2066
|
+
function phaseEventKey(phaseId) {
|
|
2067
|
+
return phaseId ? phaseId : void 0;
|
|
2068
|
+
}
|
|
2069
|
+
// An event's fields into the columns, unless it was recorded already; what
|
|
2070
|
+
// hitEvent or decisionEvent would build of them is what coverageSnapshot
|
|
2071
|
+
// gives back.
|
|
2072
|
+
function recordEvent(into, type, id, vector, timestampMs, phaseId, environment) {
|
|
2073
|
+
if (eventSeen(into.eventKeys, type, id, vector, phaseEventKey(phaseId)))
|
|
2074
|
+
return false;
|
|
2075
|
+
const log = into.eventLog;
|
|
2076
|
+
log.type[log.type.length] = type;
|
|
2077
|
+
log.id[log.id.length] = id;
|
|
2078
|
+
log.vector[log.vector.length] = vector;
|
|
2079
|
+
log.timestampMs[log.timestampMs.length] = timestampMs;
|
|
2080
|
+
log.phaseId[log.phaseId.length] = phaseId;
|
|
2081
|
+
log.environment[log.environment.length] = environment;
|
|
2082
|
+
return true;
|
|
2083
|
+
}
|
|
2084
|
+
function recordBrowserEvent(type, id, vector, timestampMs, phaseId, environment) {
|
|
2085
|
+
if (!recordEvent(state, type, id, vector, timestampMs, phaseId, environment))
|
|
1955
2086
|
return false;
|
|
1956
|
-
state.events.push(event);
|
|
1957
2087
|
workerEvidenceChanged();
|
|
1958
2088
|
return true;
|
|
1959
2089
|
}
|
|
@@ -1963,34 +2093,38 @@ function recordBrowserEvent(event) {
|
|
|
1963
2093
|
// repeat.
|
|
1964
2094
|
function coverageHit(id) {
|
|
1965
2095
|
const clock = state.probeV2Clock;
|
|
1966
|
-
if (clock.fast && state.hitEpochs !== void 0 && state.hitEpochs
|
|
2096
|
+
if (clock.fast && state.hitEpochs !== void 0 && builtinMapGet.call(state.hitEpochs, id) === clock.e)
|
|
1967
2097
|
return;
|
|
1968
2098
|
recordCoverageHit(id);
|
|
1969
2099
|
}
|
|
1970
2100
|
// resetCoverage forces a fresh epoch, so a hit skipped above was recorded in
|
|
1971
2101
|
// this epoch after the last reset and is in state.hits already.
|
|
1972
2102
|
function recordCoverageHit(id) {
|
|
1973
|
-
state.hits
|
|
2103
|
+
builtinSetAdd.call(state.hits, id);
|
|
1974
2104
|
const clock = state.probeV2Clock;
|
|
1975
|
-
let epoch = clock.
|
|
2105
|
+
let epoch = clock.e;
|
|
1976
2106
|
if (!clock.fast) {
|
|
1977
|
-
const previousEpoch = clock.
|
|
2107
|
+
const previousEpoch = clock.e;
|
|
1978
2108
|
activateProbeV2Context(currentRequestContext());
|
|
1979
|
-
epoch = clock.
|
|
1980
|
-
clock.
|
|
2109
|
+
epoch = clock.e;
|
|
2110
|
+
clock.e = previousEpoch;
|
|
1981
2111
|
} else if (epoch !== epoch) {
|
|
1982
2112
|
epoch = resolveProbeV2Epoch();
|
|
1983
2113
|
}
|
|
1984
2114
|
if (!state.hitEpochs)
|
|
1985
2115
|
state.hitEpochs = /* @__PURE__ */ new Map();
|
|
1986
|
-
if (state.hitEpochs
|
|
2116
|
+
if (builtinMapGet.call(state.hitEpochs, id) === epoch)
|
|
1987
2117
|
return;
|
|
1988
|
-
state.hitEpochs
|
|
2118
|
+
builtinMapSet.call(state.hitEpochs, id, epoch);
|
|
1989
2119
|
const timestampMs = Date.now();
|
|
1990
2120
|
const phaseId = currentPhaseId();
|
|
1991
2121
|
if (isBrowser) {
|
|
1992
|
-
if (recordBrowserEvent(
|
|
2122
|
+
if (recordBrowserEvent("hit", id, void 0, timestampMs, phaseId, "browser"))
|
|
1993
2123
|
persistBrowser();
|
|
2124
|
+
} else if (state.runtimeSnapshots) {
|
|
2125
|
+
// What appendServer does with a snapshot-kept run's record, without the
|
|
2126
|
+
// record: an object built per first hit only to be read once.
|
|
2127
|
+
recordBrowserEvent("hit", id, void 0, timestampMs, phaseId, "server");
|
|
1994
2128
|
} else {
|
|
1995
2129
|
appendServer(phaseId ? { type: "hit", id, timestampMs, phaseId } : { type: "hit", id, timestampMs });
|
|
1996
2130
|
}
|
|
@@ -2020,7 +2154,7 @@ function probePlaceName(names, aliases, count, kind, key, place) {
|
|
|
2020
2154
|
return void 0;
|
|
2021
2155
|
let name = names[place];
|
|
2022
2156
|
if (name === void 0) {
|
|
2023
|
-
const first =
|
|
2157
|
+
const first = builtinMapGet.call(aliases, place);
|
|
2024
2158
|
name = names[place] = first === void 0 ? `~${kind}${key}.${place}` : probePlaceName(names, aliases, count, kind, key, first);
|
|
2025
2159
|
}
|
|
2026
2160
|
return name;
|
|
@@ -2034,7 +2168,6 @@ function probeDecisionName(file, place) {
|
|
|
2034
2168
|
function registerProbeV2(definition) {
|
|
2035
2169
|
var _a8, _b;
|
|
2036
2170
|
const pointCount = definition.points;
|
|
2037
|
-
const decisionCount = definition.decisionWidths.length;
|
|
2038
2171
|
const file = {
|
|
2039
2172
|
key: definition.key,
|
|
2040
2173
|
pointCount,
|
|
@@ -2050,13 +2183,6 @@ function registerProbeV2(definition) {
|
|
|
2050
2183
|
// the global on every evaluation, and under Vitest's jsdom environment
|
|
2051
2184
|
// each read is a getter call, most of a canvas app's measured unit time.
|
|
2052
2185
|
decisionEpochs: definition.decisionWidths.map((width) => width <= 6 ? new Uint32Array(2 * 3 ** width) : /* @__PURE__ */ new Map()),
|
|
2053
|
-
decisionVectorCounts: definition.decisionWidths.map((_, index) => {
|
|
2054
|
-
var _a9, _b2;
|
|
2055
|
-
return (_b2 = (_a9 = definition.decisionVectorCounts) == null ? void 0 : _a9[index]) != null ? _b2 : 0;
|
|
2056
|
-
}),
|
|
2057
|
-
decisionObservationEpochs: new Uint32Array(decisionCount),
|
|
2058
|
-
decisionObservationCounts: new Uint16Array(decisionCount),
|
|
2059
|
-
decisionCompleteEpochs: new Uint32Array(decisionCount),
|
|
2060
2186
|
pendingDefaults: new Uint32Array(definition.defaultCount || 0),
|
|
2061
2187
|
// A selection's outcomes -- short falsy, short truthy, right falsy, right
|
|
2062
2188
|
// truthy -- are four consecutive points per site from the first index.
|
|
@@ -2067,7 +2193,18 @@ function registerProbeV2(definition) {
|
|
|
2067
2193
|
selectionChoices: (definition.selectionTrees || []).map((tree) => tree[1]),
|
|
2068
2194
|
none: optionalCallEmptySpread
|
|
2069
2195
|
};
|
|
2070
|
-
|
|
2196
|
+
rememberProbeV2File(file);
|
|
2197
|
+
// What a probe calls: this file's hit, by place alone. Outside a loop the
|
|
2198
|
+
// probe is the call alone and this makes its check, so it stays small
|
|
2199
|
+
// enough for V8 to inline where the code is hot. The epoch is NaN wherever
|
|
2200
|
+
// the clock is not fast, which no recorded epoch equals, so the check needs
|
|
2201
|
+
// no `fast` of its own (coverageHitV2's).
|
|
2202
|
+
const hitEpochs = file.hitEpochs;
|
|
2203
|
+
const clock = file.clock;
|
|
2204
|
+
file.hit = (index) => {
|
|
2205
|
+
if (hitEpochs[index] !== clock.e)
|
|
2206
|
+
recordCoverageHitV2(file, index);
|
|
2207
|
+
};
|
|
2071
2208
|
if (isBrowser) {
|
|
2072
2209
|
state.probeV2Clock.fast = true;
|
|
2073
2210
|
activateProbeV2Key(`browser\0${(_a8 = runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__) != null ? _a8 : testId}\0${(_b = runtimeGlobal.__SUPERCOV_PHASE_ID__) != null ? _b : "unscoped"}`);
|
|
@@ -2077,11 +2214,31 @@ function registerProbeV2(definition) {
|
|
|
2077
2214
|
// before any did -- a script's own top level -- found it NaN, which no
|
|
2078
2215
|
// epoch equals, so every probe there took the slow path every time: a
|
|
2079
2216
|
// million-iteration loop ran 1,700 times slower than without Supercov.
|
|
2080
|
-
if (Number.isNaN(state.probeV2Clock.
|
|
2217
|
+
if (state.probeV2Clock.fast && Number.isNaN(state.probeV2Clock.e))
|
|
2081
2218
|
activateProbeV2Context(currentRequestContext());
|
|
2082
2219
|
}
|
|
2083
2220
|
return file;
|
|
2084
2221
|
}
|
|
2222
|
+
// Vitest evaluates a module again for every test file, and each evaluation
|
|
2223
|
+
// registers its file anew: held strongly, every evaluation's arrays stayed
|
|
2224
|
+
// alive for the worker's life, and the collector walked them all. A file no
|
|
2225
|
+
// module holds runs no probe, so the wrap has nothing of it to clear, and the
|
|
2226
|
+
// set is swept of them as it doubles.
|
|
2227
|
+
function rememberProbeV2File(file) {
|
|
2228
|
+
const files = state.probeV2Files;
|
|
2229
|
+
if (typeof WeakRef !== "function") {
|
|
2230
|
+
files.add(file);
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
files.add(new WeakRef(file));
|
|
2234
|
+
if (files.size < state.probeV2FilesSweepAt)
|
|
2235
|
+
return;
|
|
2236
|
+
for (const held of files) {
|
|
2237
|
+
if (held.deref() === void 0)
|
|
2238
|
+
files.delete(held);
|
|
2239
|
+
}
|
|
2240
|
+
state.probeV2FilesSweepAt = Math.max(1024, 2 * files.size);
|
|
2241
|
+
}
|
|
2085
2242
|
// Every repeat of a probe in the same context ends at the first check, so it
|
|
2086
2243
|
// stays small enough for V8 to inline into the instrumented function; the
|
|
2087
2244
|
// rest runs once per context. minimatch's backtracking guard test needs a
|
|
@@ -2089,7 +2246,7 @@ function registerProbeV2(definition) {
|
|
|
2089
2246
|
// at ten times the uninstrumented time.
|
|
2090
2247
|
function coverageHitV2(file, index) {
|
|
2091
2248
|
const clock = file.clock;
|
|
2092
|
-
if (clock.fast && file.hitEpochs[index] === clock.
|
|
2249
|
+
if (clock.fast && file.hitEpochs[index] === clock.e)
|
|
2093
2250
|
return;
|
|
2094
2251
|
recordCoverageHitV2(file, index);
|
|
2095
2252
|
}
|
|
@@ -2098,23 +2255,25 @@ function recordCoverageHitV2(file, index) {
|
|
|
2098
2255
|
if (!id)
|
|
2099
2256
|
return;
|
|
2100
2257
|
const fallbackEpoch = !file.clock.fast;
|
|
2101
|
-
const previousEpoch = file.clock.
|
|
2258
|
+
const previousEpoch = file.clock.e;
|
|
2102
2259
|
if (fallbackEpoch)
|
|
2103
2260
|
activateProbeV2Context(currentRequestContext());
|
|
2104
2261
|
else if (previousEpoch !== previousEpoch)
|
|
2105
2262
|
resolveProbeV2Epoch();
|
|
2106
2263
|
try {
|
|
2107
|
-
const epoch = file.clock.
|
|
2264
|
+
const epoch = file.clock.e;
|
|
2108
2265
|
if (file.hitEpochs[index] === epoch)
|
|
2109
2266
|
return;
|
|
2110
2267
|
file.hitEpochs[index] = epoch;
|
|
2111
|
-
|
|
2268
|
+
// New in this context for this file: recordCoverageHit makes the check
|
|
2269
|
+
// coverageHit would, across files and aliases, without a second lookup.
|
|
2270
|
+
recordCoverageHit(id);
|
|
2112
2271
|
const selections = file.selectionPoints;
|
|
2113
2272
|
if (selections !== void 0 && index >= selections[0] && index < selections[0] + 4 * selections[1])
|
|
2114
2273
|
recordLogicalOutcome(id, index - selections[0] & 3);
|
|
2115
2274
|
} finally {
|
|
2116
2275
|
if (fallbackEpoch)
|
|
2117
|
-
file.clock.
|
|
2276
|
+
file.clock.e = previousEpoch;
|
|
2118
2277
|
}
|
|
2119
2278
|
}
|
|
2120
2279
|
function decodeProbeV2Vector(conditionCount, encoded, outcome) {
|
|
@@ -2124,7 +2283,7 @@ function decodeProbeV2Vector(conditionCount, encoded, outcome) {
|
|
|
2124
2283
|
let remaining = encoded;
|
|
2125
2284
|
for (let index = 0; index < conditionCount; index += 1) {
|
|
2126
2285
|
const digit = remaining % 3;
|
|
2127
|
-
values
|
|
2286
|
+
values[index] = digit === 0 ? null : digit === 2;
|
|
2128
2287
|
remaining = Math.floor(remaining / 3);
|
|
2129
2288
|
}
|
|
2130
2289
|
return remaining === 0 ? { values, outcome } : void 0;
|
|
@@ -2137,13 +2296,12 @@ function mcdcEndV2(file, decisionIndex, encoded, value) {
|
|
|
2137
2296
|
const clock = file.clock;
|
|
2138
2297
|
if (clock.fast) {
|
|
2139
2298
|
const seen = file.decisionEpochs[decisionIndex];
|
|
2140
|
-
if (seen !== void 0 && seen.size === void 0 && seen[encoded * 2 + (value ? 1 : 0)] === clock.
|
|
2299
|
+
if (seen !== void 0 && seen.size === void 0 && seen[encoded * 2 + (value ? 1 : 0)] === clock.e)
|
|
2141
2300
|
return value;
|
|
2142
2301
|
}
|
|
2143
2302
|
return recordMcdcEndV2(file, decisionIndex, encoded, value);
|
|
2144
2303
|
}
|
|
2145
2304
|
function recordMcdcEndV2(file, decisionIndex, encoded, value) {
|
|
2146
|
-
var _a8, _b;
|
|
2147
2305
|
const id = probeDecisionName(file, decisionIndex);
|
|
2148
2306
|
if (!id || !Number.isSafeInteger(encoded) || encoded < 0)
|
|
2149
2307
|
return value;
|
|
@@ -2152,13 +2310,13 @@ function recordMcdcEndV2(file, decisionIndex, encoded, value) {
|
|
|
2152
2310
|
if (!Number.isSafeInteger(vectorIndex))
|
|
2153
2311
|
return value;
|
|
2154
2312
|
const fallbackEpoch = !file.clock.fast;
|
|
2155
|
-
const previousEpoch = file.clock.
|
|
2313
|
+
const previousEpoch = file.clock.e;
|
|
2156
2314
|
if (fallbackEpoch)
|
|
2157
2315
|
activateProbeV2Context(currentRequestContext());
|
|
2158
2316
|
else if (previousEpoch !== previousEpoch)
|
|
2159
2317
|
resolveProbeV2Epoch();
|
|
2160
2318
|
try {
|
|
2161
|
-
const epoch = file.clock.
|
|
2319
|
+
const epoch = file.clock.e;
|
|
2162
2320
|
const seen = file.decisionEpochs[decisionIndex];
|
|
2163
2321
|
if (!seen)
|
|
2164
2322
|
return value;
|
|
@@ -2167,28 +2325,17 @@ function recordMcdcEndV2(file, decisionIndex, encoded, value) {
|
|
|
2167
2325
|
return value;
|
|
2168
2326
|
seen[vectorIndex] = epoch;
|
|
2169
2327
|
} else {
|
|
2170
|
-
if (
|
|
2328
|
+
if (builtinMapGet.call(seen, vectorIndex) === epoch)
|
|
2171
2329
|
return value;
|
|
2172
|
-
|
|
2173
|
-
}
|
|
2174
|
-
const expectedCount = (_a8 = file.decisionVectorCounts[decisionIndex]) != null ? _a8 : 0;
|
|
2175
|
-
if (expectedCount > 0) {
|
|
2176
|
-
if (file.decisionObservationEpochs[decisionIndex] !== epoch) {
|
|
2177
|
-
file.decisionObservationEpochs[decisionIndex] = epoch;
|
|
2178
|
-
file.decisionObservationCounts[decisionIndex] = 0;
|
|
2179
|
-
}
|
|
2180
|
-
const observedCount = ((_b = file.decisionObservationCounts[decisionIndex]) != null ? _b : 0) + 1;
|
|
2181
|
-
file.decisionObservationCounts[decisionIndex] = observedCount;
|
|
2182
|
-
if (observedCount >= expectedCount)
|
|
2183
|
-
file.decisionCompleteEpochs[decisionIndex] = epoch;
|
|
2330
|
+
builtinMapSet.call(seen, vectorIndex, epoch);
|
|
2184
2331
|
}
|
|
2185
|
-
if (!state.decisions
|
|
2186
|
-
state.decisions
|
|
2332
|
+
if (!builtinMapHas.call(state.decisions, id))
|
|
2333
|
+
builtinMapSet.call(state.decisions, id, { id, vectors: /* @__PURE__ */ new Map() });
|
|
2187
2334
|
const vector = decodeProbeV2Vector(file.decisionWidths[decisionIndex], encoded, outcome);
|
|
2188
2335
|
return vector ? mcdcEnd({ id, values: vector.values }, value) : value;
|
|
2189
2336
|
} finally {
|
|
2190
2337
|
if (fallbackEpoch)
|
|
2191
|
-
file.clock.
|
|
2338
|
+
file.clock.e = previousEpoch;
|
|
2192
2339
|
}
|
|
2193
2340
|
}
|
|
2194
2341
|
function selectionBegin(shortId, rightId) {
|
|
@@ -2242,14 +2389,14 @@ function recordSelectionOutcome(id, outcome) {
|
|
|
2242
2389
|
// The outcomes of a selection by its branch id, or by the name of its point
|
|
2243
2390
|
// that was hit, whose branch the report reads from the point's id.
|
|
2244
2391
|
function recordLogicalOutcome(branchId, outcome) {
|
|
2245
|
-
let vectors = state.logicals
|
|
2392
|
+
let vectors = builtinMapGet.call(state.logicals, branchId);
|
|
2246
2393
|
if (!vectors) {
|
|
2247
2394
|
vectors = /* @__PURE__ */ new Map();
|
|
2248
|
-
state.logicals
|
|
2395
|
+
builtinMapSet.call(state.logicals, branchId, vectors);
|
|
2249
2396
|
}
|
|
2250
2397
|
const key = selectionOutcomeKeys[outcome];
|
|
2251
|
-
if (!
|
|
2252
|
-
|
|
2398
|
+
if (!builtinMapHas.call(vectors, key)) {
|
|
2399
|
+
builtinMapSet.call(vectors, key, { right: outcome >= 2, truthy: (outcome & 1) === 1 });
|
|
2253
2400
|
workerEvidenceChanged();
|
|
2254
2401
|
}
|
|
2255
2402
|
}
|
|
@@ -2490,17 +2637,19 @@ function mcdcCondition(frame, index, value) {
|
|
|
2490
2637
|
return value;
|
|
2491
2638
|
}
|
|
2492
2639
|
function mcdcEnd(frame, value) {
|
|
2493
|
-
const decision = state.decisions
|
|
2640
|
+
const decision = builtinMapGet.call(state.decisions, frame.id);
|
|
2494
2641
|
if (!decision)
|
|
2495
2642
|
return value;
|
|
2496
2643
|
const vector = { values: frame.values, outcome: Boolean(value) };
|
|
2497
2644
|
const key = vectorKey(vector);
|
|
2498
|
-
decision.vectors
|
|
2645
|
+
builtinMapSet.call(decision.vectors, key, vector);
|
|
2499
2646
|
const timestampMs = Date.now();
|
|
2500
2647
|
const phaseId = currentPhaseId();
|
|
2501
2648
|
if (isBrowser) {
|
|
2502
|
-
if (recordBrowserEvent(
|
|
2649
|
+
if (recordBrowserEvent("decision", decision.id, vector, timestampMs, phaseId, "browser"))
|
|
2503
2650
|
persistBrowser();
|
|
2651
|
+
} else if (state.runtimeSnapshots) {
|
|
2652
|
+
recordBrowserEvent("decision", decision.id, vector, timestampMs, phaseId, "server");
|
|
2504
2653
|
} else {
|
|
2505
2654
|
appendServer(phaseId ? { type: "decision", id: decision.id, vector, timestampMs, phaseId } : { type: "decision", id: decision.id, vector, timestampMs });
|
|
2506
2655
|
}
|
|
@@ -2518,6 +2667,7 @@ const directRuntimeApi = {
|
|
|
2518
2667
|
coverageHit,
|
|
2519
2668
|
coverageHitV2,
|
|
2520
2669
|
coverageSnapshot,
|
|
2670
|
+
coverageSnapshotColumns,
|
|
2521
2671
|
decodeProbeV2Vector,
|
|
2522
2672
|
defaultEntered,
|
|
2523
2673
|
defaultEnteredV2,
|
|
@@ -2586,6 +2736,7 @@ export {
|
|
|
2586
2736
|
coverageHit,
|
|
2587
2737
|
coverageHitV2,
|
|
2588
2738
|
coverageSnapshot,
|
|
2739
|
+
coverageSnapshotColumns,
|
|
2589
2740
|
decodeProbeV2Vector,
|
|
2590
2741
|
defaultEntered,
|
|
2591
2742
|
defaultEnteredV2,
|
|
@@ -109,7 +109,10 @@ export function expandSnapshot(value) {
|
|
|
109
109
|
/**
|
|
110
110
|
* A snapshot's events as columns: each event's type, phase and environment
|
|
111
111
|
* as an index into a table of the distinct ones, its time as the difference
|
|
112
|
-
* from the event before it
|
|
112
|
+
* from the event before it, and its id, where it is one of the snapshot's
|
|
113
|
+
* hits, as that hit's position in `hits`: every first hit of a test is in
|
|
114
|
+
* both, and writing each id twice was a third of a test's evidence. The
|
|
115
|
+
* reader gives back the same events.
|
|
113
116
|
*/
|
|
114
117
|
export function columnarEvents(snapshot) {
|
|
115
118
|
const events = snapshot?.events;
|
|
@@ -124,10 +127,13 @@ export function columnarEvents(snapshot) {
|
|
|
124
127
|
}
|
|
125
128
|
return found;
|
|
126
129
|
};
|
|
130
|
+
const hitAt = new Map();
|
|
131
|
+
(snapshot.hits ?? []).forEach((id, position) => hitAt.set(id, position));
|
|
127
132
|
const columns = { id: [], type: [], phase: [], environment: [], t: [], vector: {} };
|
|
128
133
|
let previous = 0;
|
|
129
134
|
events.forEach((event, position) => {
|
|
130
|
-
|
|
135
|
+
const at = hitAt.get(event.id);
|
|
136
|
+
columns.id.push(at === undefined ? event.id : at);
|
|
131
137
|
columns.type.push(index(tables.types, event.type));
|
|
132
138
|
columns.phase.push(event.phaseId == null ? -1 : index(tables.phases, event.phaseId));
|
|
133
139
|
columns.environment.push(index(tables.environments, event.environment));
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { relative, resolve, sep } from "node:path";
|
|
3
|
-
import { afterEach, beforeEach } from "vitest";
|
|
4
|
-
import { coverageSnapshot as localCoverageSnapshot, activateCoverageScope as localActivateCoverageScope, enableRuntimeSnapshotEvidence as localEnableRuntimeSnapshotEvidence, resetCoverage as localResetCoverage, takeNodeAssertionPhases as localTakeNodeAssertionPhases, } from "./runtime.mjs";
|
|
3
|
+
import { afterAll, afterEach, beforeEach } from "vitest";
|
|
4
|
+
import { coverageSnapshot as localCoverageSnapshot, coverageSnapshotColumns as localCoverageSnapshotColumns, activateCoverageScope as localActivateCoverageScope, enableRuntimeSnapshotEvidence as localEnableRuntimeSnapshotEvidence, resetCoverage as localResetCoverage, takeNodeAssertionPhases as localTakeNodeAssertionPhases, } from "./runtime.mjs";
|
|
5
5
|
import { inferTestProvenance, testTags } from "./provenance.mjs";
|
|
6
|
-
import { appendEvidenceRecord } from "./atomic.mjs";
|
|
7
|
-
import { columnarEvents } from "./snapshots.mjs";
|
|
6
|
+
import { appendEvidenceRecord, installCompileCache, saveCompileCache } from "./atomic.mjs";
|
|
8
7
|
const evidenceDirectory = process.env["SUPERCOV_EVIDENCE_DIR"];
|
|
9
8
|
const emittedSetupFiles = new Set();
|
|
10
9
|
const attempts = new Map();
|
|
@@ -13,6 +12,7 @@ const runtimeGlobal = globalThis;
|
|
|
13
12
|
const runtime = runtimeGlobal.__SUPERCOV_DIRECT_RUNTIME__ ?? {
|
|
14
13
|
activateCoverageScope: localActivateCoverageScope,
|
|
15
14
|
coverageSnapshot: localCoverageSnapshot,
|
|
15
|
+
coverageSnapshotColumns: localCoverageSnapshotColumns,
|
|
16
16
|
enableRuntimeSnapshotEvidence: localEnableRuntimeSnapshotEvidence,
|
|
17
17
|
resetCoverage: localResetCoverage,
|
|
18
18
|
takeNodeAssertionPhases: localTakeNodeAssertionPhases,
|
|
@@ -21,6 +21,10 @@ const runtime = runtimeGlobal.__SUPERCOV_DIRECT_RUNTIME__ ?? {
|
|
|
21
21
|
// events through the server JSONL transport would be both redundant and
|
|
22
22
|
// unattributed, and turns hot unit-test loops into synchronous filesystem IO.
|
|
23
23
|
runtime.enableRuntimeSnapshotEvidence();
|
|
24
|
+
// Each worker compiles the instrumented modules from what the workers before
|
|
25
|
+
// it compiled, and leaves what it compiled for the ones after.
|
|
26
|
+
installCompileCache(process.env["SUPERCOV_COMPILE_CACHE"]);
|
|
27
|
+
afterAll(saveCompileCache);
|
|
24
28
|
function attemptStatus(state) {
|
|
25
29
|
if (state === "pass")
|
|
26
30
|
return "passed";
|
|
@@ -51,7 +55,8 @@ beforeEach((context) => {
|
|
|
51
55
|
.join("/");
|
|
52
56
|
if (!emittedSetupFiles.has(testFile)) {
|
|
53
57
|
emittedSetupFiles.add(testFile);
|
|
54
|
-
|
|
58
|
+
// The snapshot as its evidence carries it, its events as columns.
|
|
59
|
+
const setupSnapshot = runtime.coverageSnapshotColumns();
|
|
55
60
|
if (setupSnapshot.hits.length || setupSnapshot.decisions.length) {
|
|
56
61
|
writeEvidence({
|
|
57
62
|
testId: `vitest:${task.file.id}:setup`,
|
|
@@ -67,7 +72,7 @@ beforeEach((context) => {
|
|
|
67
72
|
explicitKind: process.env["SUPERCOV_TEST_KIND"],
|
|
68
73
|
}),
|
|
69
74
|
role: "setup",
|
|
70
|
-
runtime: [
|
|
75
|
+
runtime: [setupSnapshot],
|
|
71
76
|
browser: [],
|
|
72
77
|
server: [],
|
|
73
78
|
});
|
|
@@ -116,7 +121,7 @@ afterEach((context) => {
|
|
|
116
121
|
// Its events as columns, as Playwright's are written: a test's first
|
|
117
122
|
// hits written as objects repeated every key and phase for each, and
|
|
118
123
|
// serializing them was most of what a test's teardown cost.
|
|
119
|
-
runtime: [
|
|
124
|
+
runtime: [runtime.coverageSnapshotColumns()],
|
|
120
125
|
browser: [],
|
|
121
126
|
server: [],
|
|
122
127
|
};
|