supercov 0.0.7 → 0.0.8

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.
Files changed (44) hide show
  1. package/README.md +4 -0
  2. package/dist/agentJson.d.ts +1 -1
  3. package/dist/agentJson.d.ts.map +1 -1
  4. package/dist/agentJson.js.map +1 -1
  5. package/dist/cli.js +49 -9
  6. package/dist/cli.js.map +1 -1
  7. package/dist/directInstrumenter.d.ts +1 -1
  8. package/dist/directInstrumenter.d.ts.map +1 -1
  9. package/dist/directInstrumenter.js +30 -6
  10. package/dist/directInstrumenter.js.map +1 -1
  11. package/dist/nodeTest.d.ts.map +1 -1
  12. package/dist/nodeTest.js +5 -1
  13. package/dist/nodeTest.js.map +1 -1
  14. package/dist/playwright.d.ts.map +1 -1
  15. package/dist/playwright.js +8 -18
  16. package/dist/playwright.js.map +1 -1
  17. package/dist/project.d.ts +1 -0
  18. package/dist/project.d.ts.map +1 -1
  19. package/dist/project.js +4 -0
  20. package/dist/project.js.map +1 -1
  21. package/dist/query.d.ts +3 -2
  22. package/dist/query.d.ts.map +1 -1
  23. package/dist/query.js +74 -11
  24. package/dist/query.js.map +1 -1
  25. package/dist/resolve-loader.d.mts.map +1 -1
  26. package/dist/resolve-loader.mjs +12 -0
  27. package/dist/resolve-loader.mjs.map +1 -1
  28. package/dist/runAnalysis.d.ts.map +1 -1
  29. package/dist/runAnalysis.js +37 -18
  30. package/dist/runAnalysis.js.map +1 -1
  31. package/dist/runnerEvidence.d.ts +1 -1
  32. package/dist/runnerEvidence.d.ts.map +1 -1
  33. package/dist/runnerEvidence.js +2 -2
  34. package/dist/runnerEvidence.js.map +1 -1
  35. package/dist/runtime.d.ts +15 -0
  36. package/dist/runtime.d.ts.map +1 -1
  37. package/dist/runtime.js +633 -534
  38. package/dist/runtime.js.map +1 -1
  39. package/dist/sourceDiscovery.d.ts.map +1 -1
  40. package/dist/sourceDiscovery.js +10 -0
  41. package/dist/sourceDiscovery.js.map +1 -1
  42. package/dist/types.d.ts +2 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +2 -2
package/dist/runtime.js CHANGED
@@ -1,591 +1,690 @@
1
- import { backgroundEvidenceDirectory, backgroundEvidencePath, COVERAGE_CARRIER_ENV, COVERAGE_PHASE_HEADER, COVERAGE_PHASE_COOKIE, COVERAGE_SCOPE_COOKIE, COVERAGE_SCOPE_HEADER, decodeCoverageCarrier, decodeCoverageScope, encodeCoverageCarrier, encodeCoverageScope, serverEvidenceDirectory, serverEvidencePath, } from "./transport.js";
2
- const runtimeGlobal = globalThis;
3
- const runtimeInstanceToken = "__SUPERCOV_RUNTIME_INSTANCE__";
4
- const runtimeInstance = runtimeInstanceToken === "__SUPERCOV_" + "RUNTIME_INSTANCE__"
5
- ? "application"
6
- : runtimeInstanceToken;
7
- const isBrowser = !(typeof process !== "undefined" &&
8
- typeof process.versions?.node === "string");
9
- const testId = runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__ ?? "unscoped";
10
- const storageKey = "__supercov_coverage_" + testId;
11
- const phaseStorageKey = "__supercov_phase";
12
- const pendingDefaults = new Map();
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // dist/transport.js
22
+ var COVERAGE_SCOPE_HEADER = "x-supercov-scope";
23
+ var COVERAGE_PHASE_HEADER = "x-supercov-phase";
24
+ var COVERAGE_SCOPE_COOKIE = "__supercov_scope";
25
+ var COVERAGE_PHASE_COOKIE = "__supercov_phase";
26
+ var COVERAGE_CARRIER_ENV = "SUPERCOV_CONTEXT";
27
+ var DEFAULT_SERVER_EVIDENCE_ROOT = "/tmp/supercov-server-evidence";
28
+ function configuredServerEvidenceRoot() {
29
+ var _a8;
30
+ return typeof process !== "undefined" && ((_a8 = process.env) == null ? void 0 : _a8["SUPERCOV_SERVER_EVIDENCE_ROOT"]) ? process.env["SUPERCOV_SERVER_EVIDENCE_ROOT"] : DEFAULT_SERVER_EVIDENCE_ROOT;
31
+ }
32
+ function nonEmpty(value) {
33
+ return typeof value === "string" && value.length > 0;
34
+ }
35
+ function safeKey(value) {
36
+ return /^[a-zA-Z0-9_-]+$/.test(value);
37
+ }
38
+ function pathComponent(value) {
39
+ const safe = value.replace(/[^a-zA-Z0-9_-]/g, "_");
40
+ return safe || "unscoped";
41
+ }
42
+ function encodeCoverageScope(scope) {
43
+ return new URLSearchParams({
44
+ v: String(scope.version),
45
+ r: scope.runId,
46
+ w: scope.workerId,
47
+ t: scope.testId,
48
+ k: scope.testKey,
49
+ a: String(scope.retry),
50
+ i: scope.attemptId
51
+ }).toString();
52
+ }
53
+ function decodeCoverageScope(encoded) {
54
+ if (!encoded)
55
+ return void 0;
56
+ try {
57
+ const values = new URLSearchParams(encoded);
58
+ const runId = values.get("r");
59
+ const workerId = values.get("w");
60
+ const testId2 = values.get("t");
61
+ const testKey = values.get("k");
62
+ const attemptId = values.get("i");
63
+ const retry = Number(values.get("a"));
64
+ if (values.get("v") !== "1" || !nonEmpty(runId) || !nonEmpty(workerId) || !nonEmpty(testId2) || !nonEmpty(testKey) || !safeKey(testKey) || !nonEmpty(attemptId) || !safeKey(attemptId) || !Number.isSafeInteger(retry) || retry < 0)
65
+ return void 0;
66
+ return {
67
+ version: 1,
68
+ runId,
69
+ workerId,
70
+ testId: testId2,
71
+ testKey,
72
+ retry,
73
+ attemptId
74
+ };
75
+ } catch (e) {
76
+ return void 0;
77
+ }
78
+ }
79
+ function encodeCoverageCarrier(carrier) {
80
+ return Buffer.from(JSON.stringify(carrier), "utf8").toString("base64url");
81
+ }
82
+ function decodeCoverageCarrier(encoded) {
83
+ if (!encoded)
84
+ return void 0;
85
+ try {
86
+ const value = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
87
+ if (value.version !== 1)
88
+ return void 0;
89
+ if (value.scope) {
90
+ const roundTrip = decodeCoverageScope(encodeCoverageScope(value.scope));
91
+ if (!roundTrip)
92
+ return void 0;
93
+ }
94
+ if (value.phaseId !== void 0 && value.phaseId.length === 0)
95
+ return void 0;
96
+ return value;
97
+ } catch (e) {
98
+ return void 0;
99
+ }
100
+ }
101
+ function serverRunEvidenceDirectory(runId, root = configuredServerEvidenceRoot()) {
102
+ return `${root.replace(/\/+$/, "")}/${pathComponent(runId)}`;
103
+ }
104
+ function serverEvidenceDirectory(scope, root = configuredServerEvidenceRoot()) {
105
+ return `${serverRunEvidenceDirectory(scope.runId, root)}/${pathComponent(scope.workerId)}/${scope.testKey}/${scope.retry}`;
106
+ }
107
+ function serverEvidencePath(scope, root = configuredServerEvidenceRoot()) {
108
+ return `${serverEvidenceDirectory(scope, root)}/server.jsonl`;
109
+ }
110
+ function backgroundEvidenceDirectory(runId, root = configuredServerEvidenceRoot()) {
111
+ return `${serverRunEvidenceDirectory(runId, root)}/background`;
112
+ }
113
+ function backgroundEvidencePath(runId, processId = typeof process === "undefined" ? "unknown" : String(process.pid), root = configuredServerEvidenceRoot()) {
114
+ return `${backgroundEvidenceDirectory(runId, root)}/${pathComponent(processId)}.jsonl`;
115
+ }
116
+
117
+ // dist/runtime.js
118
+ var runtimeGlobal = globalThis;
119
+ var runtimeInstanceToken = "__SUPERCOV_RUNTIME_INSTANCE__";
120
+ var runtimeInstance = runtimeInstanceToken === "__SUPERCOV_RUNTIME_INSTANCE__" ? "application" : runtimeInstanceToken;
121
+ var _a;
122
+ var isBrowser = !(typeof process !== "undefined" && typeof ((_a = process.versions) == null ? void 0 : _a.node) === "string");
123
+ var _a2;
124
+ var testId = (_a2 = runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__) != null ? _a2 : "unscoped";
125
+ var storageKey = "__supercov_coverage_" + testId;
126
+ var phaseStorageKey = "__supercov_phase";
127
+ var pendingDefaults = /* @__PURE__ */ new Map();
13
128
  function vectorKey(vector) {
14
- return (vector.values
15
- .map((value) => (value === null ? "-" : value ? "T" : "F"))
16
- .join("") +
17
- ":" +
18
- (vector.outcome ? "T" : "F"));
129
+ return vector.values.map((value) => value === null ? "-" : value ? "T" : "F").join("") + ":" + (vector.outcome ? "T" : "F");
19
130
  }
20
131
  function getFs() {
21
- if (isBrowser || typeof process === "undefined")
22
- return undefined;
23
- try {
24
- const getBuiltinModule = process.getBuiltinModule;
25
- return getBuiltinModule?.("node:fs");
26
- }
27
- catch {
28
- return undefined;
29
- }
132
+ if (isBrowser || typeof process === "undefined")
133
+ return void 0;
134
+ try {
135
+ const getBuiltinModule = process.getBuiltinModule;
136
+ return getBuiltinModule == null ? void 0 : getBuiltinModule("node:fs");
137
+ } catch (e) {
138
+ return void 0;
139
+ }
30
140
  }
31
141
  function createState() {
32
- const state = {
33
- decisions: new Map(),
34
- hits: new Set(),
35
- events: [],
36
- eventKeys: new Set(),
37
- bufferedAttempts: new Set(),
38
- serverBuffers: new Map(),
39
- runtimeSnapshots: false,
40
- };
41
- if (!isBrowser)
42
- return state;
43
- try {
44
- const stored = JSON.parse(localStorage.getItem(storageKey) ?? "{}");
45
- for (const snapshot of stored.decisions ?? []) {
46
- state.decisions.set(snapshot.meta.id, {
47
- meta: snapshot.meta,
48
- vectors: new Map(snapshot.vectors.map((vector) => [vectorKey(vector), vector])),
49
- });
50
- }
51
- for (const id of stored.hits ?? [])
52
- state.hits.add(id);
53
- for (const event of stored.events ?? []) {
54
- state.events.push(event);
55
- state.eventKeys.add(eventKey(event));
56
- }
142
+ var _a8, _b, _c, _d;
143
+ const state2 = {
144
+ decisions: /* @__PURE__ */ new Map(),
145
+ hits: /* @__PURE__ */ new Set(),
146
+ events: [],
147
+ eventKeys: /* @__PURE__ */ new Set(),
148
+ bufferedAttempts: /* @__PURE__ */ new Set(),
149
+ serverBuffers: /* @__PURE__ */ new Map(),
150
+ persistedServerRecords: /* @__PURE__ */ new Set(),
151
+ backgroundSequence: 0,
152
+ runtimeSnapshots: false
153
+ };
154
+ if (!isBrowser)
155
+ return state2;
156
+ try {
157
+ const stored = JSON.parse((_a8 = localStorage.getItem(storageKey)) != null ? _a8 : "{}");
158
+ for (const snapshot of (_b = stored.decisions) != null ? _b : []) {
159
+ state2.decisions.set(snapshot.meta.id, {
160
+ meta: snapshot.meta,
161
+ vectors: new Map(snapshot.vectors.map((vector) => [vectorKey(vector), vector]))
162
+ });
57
163
  }
58
- catch {
59
- // Corrupt or unavailable storage must not affect application execution.
164
+ for (const id of (_c = stored.hits) != null ? _c : [])
165
+ state2.hits.add(id);
166
+ for (const event of (_d = stored.events) != null ? _d : []) {
167
+ state2.events.push(event);
168
+ state2.eventKeys.add(eventKey(event));
60
169
  }
61
- return state;
170
+ } catch (e) {
171
+ }
172
+ return state2;
62
173
  }
63
- const runtimeStates = runtimeGlobal.__SUPERCOV_MCDC_STATES__ ?? new Map();
174
+ var _a3;
175
+ var runtimeStates = (_a3 = runtimeGlobal.__SUPERCOV_MCDC_STATES__) != null ? _a3 : /* @__PURE__ */ new Map();
64
176
  runtimeGlobal.__SUPERCOV_MCDC_STATES__ = runtimeStates;
65
- const state = runtimeStates.get(runtimeInstance) ?? createState();
177
+ var _a4;
178
+ var state = (_a4 = runtimeStates.get(runtimeInstance)) != null ? _a4 : createState();
66
179
  runtimeStates.set(runtimeInstance, state);
67
180
  function createServerPhaseStorage() {
68
- if (isBrowser || typeof process === "undefined")
69
- return undefined;
70
- try {
71
- const getBuiltinModule = process.getBuiltinModule;
72
- const AsyncLocalStorage = getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage;
73
- return AsyncLocalStorage ? new AsyncLocalStorage() : undefined;
74
- }
75
- catch {
76
- return undefined;
77
- }
78
- }
79
- const serverPhaseStorages = runtimeGlobal.__SUPERCOV_SERVER_PHASE_STORAGES__ ?? new Map();
181
+ var _a8;
182
+ if (isBrowser || typeof process === "undefined")
183
+ return void 0;
184
+ try {
185
+ const getBuiltinModule = process.getBuiltinModule;
186
+ const AsyncLocalStorage = (_a8 = getBuiltinModule == null ? void 0 : getBuiltinModule("node:async_hooks")) == null ? void 0 : _a8.AsyncLocalStorage;
187
+ return AsyncLocalStorage ? new AsyncLocalStorage() : void 0;
188
+ } catch (e) {
189
+ return void 0;
190
+ }
191
+ }
192
+ var _a5;
193
+ var serverPhaseStorages = (_a5 = runtimeGlobal.__SUPERCOV_SERVER_PHASE_STORAGES__) != null ? _a5 : /* @__PURE__ */ new Map();
80
194
  runtimeGlobal.__SUPERCOV_SERVER_PHASE_STORAGES__ = serverPhaseStorages;
81
- const serverPhaseStorage = serverPhaseStorages.get(runtimeInstance) ?? createServerPhaseStorage();
195
+ var _a6;
196
+ var serverPhaseStorage = (_a6 = serverPhaseStorages.get(runtimeInstance)) != null ? _a6 : createServerPhaseStorage();
82
197
  if (serverPhaseStorage)
83
- serverPhaseStorages.set(runtimeInstance, serverPhaseStorage);
198
+ serverPhaseStorages.set(runtimeInstance, serverPhaseStorage);
84
199
  function decisionSnapshot() {
85
- return [...state.decisions.values()].map((decision) => ({
86
- meta: decision.meta,
87
- vectors: [...decision.vectors.values()],
88
- }));
89
- }
90
- export function coverageSnapshot() {
91
- return {
92
- decisions: decisionSnapshot(),
93
- hits: [...state.hits],
94
- events: state.events,
95
- };
96
- }
97
- export function resetCoverage(testId) {
98
- state.decisions.clear();
99
- state.hits.clear();
100
- state.events.length = 0;
101
- state.eventKeys.clear();
102
- if (testId)
103
- runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__ = testId;
104
- if (isBrowser) {
105
- try {
106
- localStorage.removeItem(storageKey);
107
- }
108
- catch {
109
- // Storage is optional in test environments.
110
- }
200
+ return [...state.decisions.values()].map((decision) => ({
201
+ meta: decision.meta,
202
+ vectors: [...decision.vectors.values()]
203
+ }));
204
+ }
205
+ function coverageSnapshot() {
206
+ return {
207
+ decisions: decisionSnapshot(),
208
+ hits: [...state.hits],
209
+ events: state.events
210
+ };
211
+ }
212
+ function resetCoverage(testId2) {
213
+ state.decisions.clear();
214
+ state.hits.clear();
215
+ state.events.length = 0;
216
+ state.eventKeys.clear();
217
+ if (testId2)
218
+ runtimeGlobal.__SUPERCOV_MCDC_TEST_ID__ = testId2;
219
+ if (isBrowser) {
220
+ try {
221
+ localStorage.removeItem(storageKey);
222
+ } catch (e) {
111
223
  }
224
+ }
112
225
  }
113
226
  runtimeGlobal.__SUPERCOV_MCDC_SNAPSHOT__ = decisionSnapshot;
114
227
  runtimeGlobal.__SUPERCOV_COVERAGE_SNAPSHOT__ = coverageSnapshot;
115
228
  runtimeGlobal.__SUPERCOV_RESET__ = resetCoverage;
116
229
  function persistBrowser() {
117
- if (!isBrowser)
118
- return;
119
- try {
120
- localStorage.setItem(storageKey, JSON.stringify(coverageSnapshot()));
121
- }
122
- catch {
123
- // Coverage persistence is best-effort and must never change app behavior.
124
- }
230
+ if (!isBrowser)
231
+ return;
232
+ try {
233
+ localStorage.setItem(storageKey, JSON.stringify(coverageSnapshot()));
234
+ } catch (e) {
235
+ }
125
236
  }
126
237
  function attemptKey(scope) {
127
- return `${scope.runId}\0${scope.workerId}\0${scope.attemptId}`;
238
+ return `${scope.runId}\0${scope.workerId}\0${scope.attemptId}`;
128
239
  }
129
240
  function serverRecordKey(record) {
130
- const suffix = record.type === "decision"
131
- ? `${record.meta.id}:${vectorKey(record.vector)}`
132
- : record.id;
133
- return `${record.phaseId ?? "unscoped"}:${record.type}:${suffix}`;
134
- }
135
- /** Buffer and de-duplicate local Node evidence until its test attempt ends. */
136
- export function beginBufferedServerEvidence(scope) {
137
- if (isBrowser)
138
- return;
139
- state.bufferedAttempts.add(attemptKey(scope));
140
- }
141
- /** Publish one local test attempt with one filesystem append. */
142
- export function flushBufferedServerEvidence(scope) {
143
- if (isBrowser)
144
- return;
145
- const key = attemptKey(scope);
146
- state.bufferedAttempts.delete(key);
147
- const buffered = state.serverBuffers.get(key);
148
- if (!buffered)
149
- return;
150
- state.serverBuffers.delete(key);
151
- const fs = getFs();
152
- if (!fs || buffered.records.size === 0)
153
- return;
154
- try {
155
- fs.mkdirSync(buffered.directory, { recursive: true });
156
- fs.appendFileSync(buffered.path, [...buffered.records.values()]
157
- .map((record) => JSON.stringify(record))
158
- .join("\n") + "\n");
159
- }
160
- catch {
161
- // Collection is best-effort and must never change test behavior.
162
- }
163
- }
164
- /** A local runner will persist coverageSnapshot(), so avoid duplicate files. */
165
- export function enableRuntimeSnapshotEvidence() {
166
- state.runtimeSnapshots = true;
241
+ var _a8;
242
+ const suffix = record.type === "decision" ? `${record.meta.id}:${vectorKey(record.vector)}` : record.id;
243
+ return `${(_a8 = record.phaseId) != null ? _a8 : "unscoped"}:${record.type}:${suffix}`;
244
+ }
245
+ function beginBufferedServerEvidence(scope) {
246
+ if (isBrowser)
247
+ return;
248
+ state.bufferedAttempts.add(attemptKey(scope));
249
+ }
250
+ function flushBufferedServerEvidence(scope) {
251
+ if (isBrowser)
252
+ return;
253
+ const key = attemptKey(scope);
254
+ state.bufferedAttempts.delete(key);
255
+ const buffered = state.serverBuffers.get(key);
256
+ if (!buffered)
257
+ return;
258
+ state.serverBuffers.delete(key);
259
+ const fs = getFs();
260
+ if (!fs || buffered.records.size === 0)
261
+ return;
262
+ try {
263
+ fs.mkdirSync(buffered.directory, { recursive: true });
264
+ fs.appendFileSync(buffered.path, [...buffered.records.values()].map((record) => JSON.stringify(record)).join("\n") + "\n");
265
+ } catch (e) {
266
+ }
267
+ }
268
+ function enableRuntimeSnapshotEvidence() {
269
+ state.runtimeSnapshots = true;
167
270
  }
168
271
  function flushAllBufferedServerEvidence() {
169
- for (const buffered of [...state.serverBuffers.values()])
170
- flushBufferedServerEvidence(buffered.scope);
272
+ for (const buffered of [...state.serverBuffers.values()])
273
+ flushBufferedServerEvidence(buffered.scope);
171
274
  }
172
- if (!isBrowser) {
173
- const flushers = runtimeGlobal.__SUPERCOV_BUFFER_FLUSHERS__ ?? new Set();
174
- runtimeGlobal.__SUPERCOV_BUFFER_FLUSHERS__ = flushers;
175
- flushers.add(flushAllBufferedServerEvidence);
176
- if (!runtimeGlobal.__SUPERCOV_BUFFER_EXIT_INSTALLED__) {
177
- process.once("exit", () => {
178
- for (const flush of runtimeGlobal.__SUPERCOV_BUFFER_FLUSHERS__ ?? [])
179
- flush();
180
- });
181
- runtimeGlobal.__SUPERCOV_BUFFER_EXIT_INSTALLED__ = true;
275
+ function writeExclusiveBackgroundRecord(fs, runId, writer, initialSequence, payload) {
276
+ let sequence = initialSequence;
277
+ for (let attempt = 0; attempt < 1e4; attempt += 1) {
278
+ const candidate = backgroundEvidencePath(runId, `${writer}-${sequence++}`);
279
+ try {
280
+ fs.writeFileSync(candidate, payload, { flag: "wx" });
281
+ return sequence;
282
+ } catch (error) {
283
+ if (error.code === "EEXIST")
284
+ continue;
285
+ throw error;
182
286
  }
287
+ }
288
+ throw Object.assign(new Error("Could not allocate a collision-free Supercov background evidence record"), { code: "SUPERCOV_BACKGROUND_COLLISION_LIMIT" });
289
+ }
290
+ var _a7;
291
+ if (!isBrowser) {
292
+ const flushers = (_a7 = runtimeGlobal.__SUPERCOV_BUFFER_FLUSHERS__) != null ? _a7 : /* @__PURE__ */ new Set();
293
+ runtimeGlobal.__SUPERCOV_BUFFER_FLUSHERS__ = flushers;
294
+ flushers.add(flushAllBufferedServerEvidence);
295
+ if (!runtimeGlobal.__SUPERCOV_BUFFER_EXIT_INSTALLED__) {
296
+ process.once("exit", () => {
297
+ var _a8;
298
+ for (const flush of (_a8 = runtimeGlobal.__SUPERCOV_BUFFER_FLUSHERS__) != null ? _a8 : [])
299
+ flush();
300
+ });
301
+ runtimeGlobal.__SUPERCOV_BUFFER_EXIT_INSTALLED__ = true;
302
+ }
183
303
  }
184
304
  function appendServer(record) {
185
- if (state.runtimeSnapshots)
186
- return;
187
- const fs = getFs();
188
- if (!fs)
189
- return;
190
- const context = currentRequestContext();
191
- const scope = context.scope;
192
- const runId = scope?.runId ??
193
- (typeof process !== "undefined"
194
- ? process.env["SUPERCOV_RUN_ID"]
195
- : undefined);
196
- if (!runId)
197
- return;
198
- try {
199
- const directory = scope
200
- ? serverEvidenceDirectory(scope)
201
- : backgroundEvidenceDirectory(runId);
202
- const path = scope
203
- ? serverEvidencePath(scope)
204
- : backgroundEvidencePath(runId);
205
- const serialized = { ...record, ...(scope ? { scope } : {}) };
206
- if (scope && state.bufferedAttempts.has(attemptKey(scope))) {
207
- const key = attemptKey(scope);
208
- const buffered = state.serverBuffers.get(key) ?? {
209
- scope,
210
- directory,
211
- path,
212
- records: new Map(),
213
- };
214
- buffered.records.set(serverRecordKey(serialized), serialized);
215
- state.serverBuffers.set(key, buffered);
216
- return;
217
- }
218
- fs.mkdirSync(directory, { recursive: true });
219
- fs.appendFileSync(path, JSON.stringify(serialized) + "\n");
305
+ var _a8, _b, _c;
306
+ if (state.runtimeSnapshots)
307
+ return;
308
+ const fs = getFs();
309
+ if (!fs)
310
+ return;
311
+ const context = currentRequestContext();
312
+ const scope = context.scope;
313
+ const runId = (_a8 = scope == null ? void 0 : scope.runId) != null ? _a8 : typeof process !== "undefined" ? process.env["SUPERCOV_RUN_ID"] : void 0;
314
+ if (!runId)
315
+ return;
316
+ try {
317
+ const directory = scope ? serverEvidenceDirectory(scope) : backgroundEvidenceDirectory(runId);
318
+ const path = scope ? serverEvidencePath(scope) : void 0;
319
+ const serialized = __spreadValues(__spreadValues({}, record), scope ? { scope } : {});
320
+ if (scope && state.bufferedAttempts.has(attemptKey(scope))) {
321
+ const key = attemptKey(scope);
322
+ const buffered = (_b = state.serverBuffers.get(key)) != null ? _b : {
323
+ scope,
324
+ directory,
325
+ path,
326
+ records: /* @__PURE__ */ new Map()
327
+ };
328
+ buffered.records.set(serverRecordKey(serialized), serialized);
329
+ state.serverBuffers.set(key, buffered);
330
+ return;
220
331
  }
221
- catch {
222
- // The instrumented build must remain behaviorally identical if collection fails.
332
+ const deduplicationKey = scope && serialized.phaseId ? `${attemptKey(scope)}:${serverRecordKey(serialized)}` : void 0;
333
+ if (deduplicationKey && state.persistedServerRecords.has(deduplicationKey))
334
+ return;
335
+ fs.mkdirSync(directory, { recursive: true });
336
+ if (!path) {
337
+ const shard = (_c = process.env["SUPERCOV_EXECUTION_LOG_SHARD"]) != null ? _c : "process";
338
+ const writer = `${shard}-${process.pid}`;
339
+ const payload = JSON.stringify(serialized) + "\n";
340
+ state.backgroundSequence = writeExclusiveBackgroundRecord(fs, runId, writer, state.backgroundSequence, payload);
341
+ return;
223
342
  }
343
+ fs.appendFileSync(path, JSON.stringify(serialized) + "\n");
344
+ if (deduplicationKey)
345
+ state.persistedServerRecords.add(deduplicationKey);
346
+ } catch (e) {
347
+ }
224
348
  }
225
349
  function environmentRequestContext() {
226
- if (isBrowser || typeof process === "undefined")
227
- return undefined;
228
- const carrier = decodeCoverageCarrier(process.env[COVERAGE_CARRIER_ENV]);
229
- return carrier
230
- ? {
231
- ...(carrier.scope ? { scope: carrier.scope } : {}),
232
- ...(carrier.phaseId ? { phaseId: carrier.phaseId } : {}),
233
- }
234
- : undefined;
350
+ if (isBrowser || typeof process === "undefined")
351
+ return void 0;
352
+ const carrier = decodeCoverageCarrier(process.env[COVERAGE_CARRIER_ENV]);
353
+ return carrier ? __spreadValues(__spreadValues({}, carrier.scope ? { scope: carrier.scope } : {}), carrier.phaseId ? { phaseId: carrier.phaseId } : {}) : void 0;
235
354
  }
236
355
  function currentRequestContext() {
237
- return serverPhaseStorage?.getStore() ?? environmentRequestContext() ?? {};
238
- }
239
- export function coverageCarrier() {
240
- const context = currentRequestContext();
241
- return {
242
- version: 1,
243
- ...(context.scope ? { scope: context.scope } : {}),
244
- ...(context.phaseId ? { phaseId: context.phaseId } : {}),
245
- };
246
- }
247
- export function withCoverageCarrier(carrier, callback) {
248
- const decoded = typeof carrier === "string" ? decodeCoverageCarrier(carrier) : carrier;
249
- if (!serverPhaseStorage || !decoded)
250
- return callback();
251
- return serverPhaseStorage.run({
252
- ...(decoded.scope ? { scope: decoded.scope } : {}),
253
- ...(decoded.phaseId ? { phaseId: decoded.phaseId } : {}),
254
- }, callback);
255
- }
256
- export function bindCoverageContext(callback, carrier = coverageCarrier()) {
257
- return function boundCoverageContext(...args) {
258
- return withCoverageCarrier(carrier, () => Reflect.apply(callback, this, args));
259
- };
260
- }
261
- export function coverageContextHeaders() {
262
- const context = currentRequestContext();
263
- if (!context.scope)
264
- return {};
265
- return {
266
- [COVERAGE_SCOPE_HEADER]: encodeCoverageScope(context.scope),
267
- ...(context.phaseId
268
- ? { [COVERAGE_PHASE_HEADER]: context.phaseId }
269
- : {}),
270
- };
271
- }
272
- export function coverageContextEnvironment() {
273
- return { [COVERAGE_CARRIER_ENV]: encodeCoverageCarrier(coverageCarrier()) };
356
+ var _a8, _b;
357
+ return (_b = (_a8 = serverPhaseStorage == null ? void 0 : serverPhaseStorage.getStore()) != null ? _a8 : environmentRequestContext()) != null ? _b : {};
358
+ }
359
+ function coverageCarrier() {
360
+ const context = currentRequestContext();
361
+ return __spreadValues(__spreadValues({
362
+ version: 1
363
+ }, context.scope ? { scope: context.scope } : {}), context.phaseId ? { phaseId: context.phaseId } : {});
364
+ }
365
+ function withCoverageCarrier(carrier, callback) {
366
+ const decoded = typeof carrier === "string" ? decodeCoverageCarrier(carrier) : carrier;
367
+ if (!serverPhaseStorage || !decoded)
368
+ return callback();
369
+ return serverPhaseStorage.run(__spreadValues(__spreadValues({}, decoded.scope ? { scope: decoded.scope } : {}), decoded.phaseId ? { phaseId: decoded.phaseId } : {}), callback);
370
+ }
371
+ function bindCoverageContext(callback, carrier = coverageCarrier()) {
372
+ return function boundCoverageContext(...args) {
373
+ return withCoverageCarrier(carrier, () => Reflect.apply(callback, this, args));
374
+ };
375
+ }
376
+ function coverageContextHeaders() {
377
+ const context = currentRequestContext();
378
+ if (!context.scope)
379
+ return {};
380
+ return __spreadValues({
381
+ [COVERAGE_SCOPE_HEADER]: encodeCoverageScope(context.scope)
382
+ }, context.phaseId ? { [COVERAGE_PHASE_HEADER]: context.phaseId } : {});
383
+ }
384
+ function coverageContextEnvironment() {
385
+ return { [COVERAGE_CARRIER_ENV]: encodeCoverageCarrier(coverageCarrier()) };
274
386
  }
275
387
  function installServerFetchPropagation() {
276
- if (isBrowser ||
277
- runtimeGlobal.__SUPERCOV_FETCH_PATCHED__ ||
278
- typeof globalThis.fetch !== "function")
279
- return;
280
- const originalFetch = globalThis.fetch.bind(globalThis);
281
- globalThis.fetch = ((input, init) => {
282
- const coverage = coverageContextHeaders();
283
- if (Object.keys(coverage).length === 0)
284
- return originalFetch(input, init);
285
- const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
286
- for (const [name, value] of Object.entries(coverage))
287
- headers.set(name, value);
288
- return originalFetch(input, { ...init, headers });
289
- });
290
- runtimeGlobal.__SUPERCOV_FETCH_PATCHED__ = true;
388
+ if (isBrowser || runtimeGlobal.__SUPERCOV_FETCH_PATCHED__ || typeof globalThis.fetch !== "function")
389
+ return;
390
+ const originalFetch = globalThis.fetch.bind(globalThis);
391
+ globalThis.fetch = ((input, init) => {
392
+ var _a8;
393
+ const coverage = coverageContextHeaders();
394
+ if (Object.keys(coverage).length === 0)
395
+ return originalFetch(input, init);
396
+ const headers = new Headers((_a8 = init == null ? void 0 : init.headers) != null ? _a8 : input instanceof Request ? input.headers : void 0);
397
+ for (const [name, value] of Object.entries(coverage))
398
+ headers.set(name, value);
399
+ return originalFetch(input, __spreadProps(__spreadValues({}, init), { headers }));
400
+ });
401
+ runtimeGlobal.__SUPERCOV_FETCH_PATCHED__ = true;
291
402
  }
292
403
  installServerFetchPropagation();
293
404
  function installServerChildPropagation() {
294
- if (isBrowser ||
295
- runtimeGlobal.__SUPERCOV_CHILD_PATCHED__ ||
296
- typeof process === "undefined")
297
- return;
298
- const getBuiltinModule = process.getBuiltinModule;
299
- const child = getBuiltinModule?.("node:child_process");
300
- if (!child)
301
- return;
302
- const mutableChild = child;
303
- const optionIndex = (method, args) => {
304
- if (method === "spawn" ||
305
- method === "spawnSync" ||
306
- method === "fork" ||
307
- method === "execFile" ||
308
- method === "execFileSync")
309
- return Array.isArray(args[1]) || (args.length > 2 && args[2] !== undefined)
310
- ? 2
311
- : 1;
312
- return 1;
405
+ var _a8;
406
+ if (isBrowser || runtimeGlobal.__SUPERCOV_CHILD_PATCHED__ || typeof process === "undefined")
407
+ return;
408
+ const getBuiltinModule = process.getBuiltinModule;
409
+ const child = getBuiltinModule == null ? void 0 : getBuiltinModule("node:child_process");
410
+ if (!child)
411
+ return;
412
+ const mutableChild = child;
413
+ const optionIndex = (method, args) => {
414
+ if (method === "spawn" || method === "spawnSync" || method === "fork" || method === "execFile" || method === "execFileSync")
415
+ return Array.isArray(args[1]) || args.length > 2 && args[2] !== void 0 ? 2 : 1;
416
+ return 1;
417
+ };
418
+ for (const method of [
419
+ "exec",
420
+ "execFile",
421
+ "execFileSync",
422
+ "execSync",
423
+ "fork",
424
+ "spawn",
425
+ "spawnSync"
426
+ ]) {
427
+ const original = mutableChild[method];
428
+ if (typeof original !== "function")
429
+ continue;
430
+ mutableChild[method] = function(...args) {
431
+ var _a9;
432
+ const index = optionIndex(method, args);
433
+ const existing = args[index] && typeof args[index] === "object" ? args[index] : {};
434
+ const options = __spreadProps(__spreadValues({}, existing), {
435
+ env: __spreadValues(__spreadValues(__spreadValues({}, process.env), (_a9 = existing.env) != null ? _a9 : {}), coverageContextEnvironment())
436
+ });
437
+ const scoped = [...args];
438
+ if (typeof scoped[index] === "function")
439
+ scoped.splice(index, 0, options);
440
+ else
441
+ scoped[index] = options;
442
+ return Reflect.apply(original, child, scoped);
313
443
  };
314
- for (const method of [
315
- "exec",
316
- "execFile",
317
- "execFileSync",
318
- "execSync",
319
- "fork",
320
- "spawn",
321
- "spawnSync",
322
- ]) {
323
- const original = mutableChild[method];
324
- if (typeof original !== "function")
325
- continue;
326
- mutableChild[method] = function (...args) {
327
- const index = optionIndex(method, args);
328
- const existing = args[index] && typeof args[index] === "object"
329
- ? args[index]
330
- : {};
331
- const options = {
332
- ...existing,
333
- env: {
334
- ...process.env,
335
- ...(existing.env ?? {}),
336
- ...coverageContextEnvironment(),
337
- },
338
- };
339
- const scoped = [...args];
340
- if (typeof scoped[index] === "function")
341
- scoped.splice(index, 0, options);
342
- else
343
- scoped[index] = options;
344
- return Reflect.apply(original, child, scoped);
345
- };
346
- }
347
- const moduleBuiltin = getBuiltinModule?.("node:module");
348
- moduleBuiltin?.syncBuiltinESMExports?.();
349
- runtimeGlobal.__SUPERCOV_CHILD_PATCHED__ = true;
444
+ }
445
+ const moduleBuiltin = getBuiltinModule == null ? void 0 : getBuiltinModule("node:module");
446
+ (_a8 = moduleBuiltin == null ? void 0 : moduleBuiltin.syncBuiltinESMExports) == null ? void 0 : _a8.call(moduleBuiltin);
447
+ runtimeGlobal.__SUPERCOV_CHILD_PATCHED__ = true;
350
448
  }
351
449
  installServerChildPropagation();
352
450
  function currentPhaseId() {
353
- if (runtimeGlobal.__SUPERCOV_PHASE_ID__)
354
- return runtimeGlobal.__SUPERCOV_PHASE_ID__;
355
- if (!isBrowser)
356
- return currentRequestContext().phaseId;
357
- try {
358
- const local = localStorage.getItem(phaseStorageKey);
359
- if (local)
360
- return local;
361
- return undefined;
362
- }
363
- catch {
364
- return undefined;
365
- }
451
+ if (runtimeGlobal.__SUPERCOV_PHASE_ID__)
452
+ return runtimeGlobal.__SUPERCOV_PHASE_ID__;
453
+ if (!isBrowser)
454
+ return currentRequestContext().phaseId;
455
+ try {
456
+ const local = localStorage.getItem(phaseStorageKey);
457
+ if (local)
458
+ return local;
459
+ return void 0;
460
+ } catch (e) {
461
+ return void 0;
462
+ }
366
463
  }
367
464
  function requestHeaders(value) {
368
- if (!value || typeof value !== "object")
369
- return undefined;
370
- const directHeaders = value.headers;
371
- const request = directHeaders && typeof directHeaders === "object"
372
- ? value
373
- : value.request;
374
- if (!request || typeof request !== "object")
375
- return undefined;
376
- const headers = request.headers;
377
- if (!headers || typeof headers !== "object")
378
- return undefined;
379
- const get = headers.get;
380
- if (typeof get === "function")
381
- return {
382
- get(name) {
383
- return Reflect.apply(get, headers, [name]);
384
- },
385
- };
386
- const values = headers;
387
- return Object.keys(values).length > 0
388
- ? {
389
- get(name) {
390
- return values[name] ?? values[name.toLowerCase()];
391
- },
392
- }
393
- : undefined;
394
- }
395
- function requestCoverageContext(value) {
396
- const headers = requestHeaders(value);
397
- if (!headers)
398
- return {};
399
- const rawCookie = headers.get("cookie");
400
- const cookies = new Map();
401
- if (typeof rawCookie === "string") {
402
- for (const part of rawCookie.split(";")) {
403
- const separator = part.indexOf("=");
404
- if (separator < 0)
405
- continue;
406
- const name = part.slice(0, separator).trim();
407
- const encoded = part.slice(separator + 1).trim();
408
- try {
409
- cookies.set(name, decodeURIComponent(encoded));
410
- }
411
- catch {
412
- // Ignore a malformed unrelated cookie.
413
- }
414
- }
415
- }
416
- const encodedScope = headers.get(COVERAGE_SCOPE_HEADER) ?? cookies.get(COVERAGE_SCOPE_COOKIE);
417
- const rawPhaseId = headers.get(COVERAGE_PHASE_HEADER) ?? cookies.get(COVERAGE_PHASE_COOKIE);
418
- const scope = decodeCoverageScope(typeof encodedScope === "string" ? encodedScope : undefined);
419
- const phaseId = typeof rawPhaseId === "string" && rawPhaseId.length > 0
420
- ? rawPhaseId
421
- : undefined;
465
+ if (!value || typeof value !== "object")
466
+ return void 0;
467
+ const directHeaders = value.headers;
468
+ const request = directHeaders && typeof directHeaders === "object" ? value : value.request;
469
+ if (!request || typeof request !== "object")
470
+ return void 0;
471
+ const headers = request.headers;
472
+ if (!headers || typeof headers !== "object")
473
+ return void 0;
474
+ const get = headers.get;
475
+ if (typeof get === "function")
422
476
  return {
423
- ...(scope ? { scope } : {}),
424
- ...(phaseId ? { phaseId } : {}),
477
+ get(name) {
478
+ return Reflect.apply(get, headers, [name]);
479
+ }
425
480
  };
481
+ const values = headers;
482
+ return Object.keys(values).length > 0 ? {
483
+ get(name) {
484
+ var _a8;
485
+ return (_a8 = values[name]) != null ? _a8 : values[name.toLowerCase()];
486
+ }
487
+ } : void 0;
426
488
  }
427
- export function withRequestPhase(handler) {
428
- if (!serverPhaseStorage)
429
- return handler;
430
- return function coverageRequestPhase(...args) {
431
- const requestContext = args
432
- .map((argument) => requestCoverageContext(argument))
433
- .find((context) => context.scope || context.phaseId) ?? {};
434
- const inheritedContext = currentRequestContext();
435
- const context = {
436
- ...(requestContext.scope ?? inheritedContext.scope
437
- ? { scope: requestContext.scope ?? inheritedContext.scope }
438
- : {}),
439
- ...(requestContext.phaseId ?? inheritedContext.phaseId
440
- ? { phaseId: requestContext.phaseId ?? inheritedContext.phaseId }
441
- : {}),
442
- };
443
- const invoke = () => Reflect.apply(handler, this, args);
444
- return context.scope || context.phaseId
445
- ? serverPhaseStorage.run(context, invoke)
446
- : invoke();
447
- };
489
+ function requestCoverageContext(value) {
490
+ var _a8, _b;
491
+ const headers = requestHeaders(value);
492
+ if (!headers)
493
+ return {};
494
+ const rawCookie = headers.get("cookie");
495
+ const cookies = /* @__PURE__ */ new Map();
496
+ if (typeof rawCookie === "string") {
497
+ for (const part of rawCookie.split(";")) {
498
+ const separator = part.indexOf("=");
499
+ if (separator < 0)
500
+ continue;
501
+ const name = part.slice(0, separator).trim();
502
+ const encoded = part.slice(separator + 1).trim();
503
+ try {
504
+ cookies.set(name, decodeURIComponent(encoded));
505
+ } catch (e) {
506
+ }
507
+ }
508
+ }
509
+ const encodedScope = (_a8 = headers.get(COVERAGE_SCOPE_HEADER)) != null ? _a8 : cookies.get(COVERAGE_SCOPE_COOKIE);
510
+ const rawPhaseId = (_b = headers.get(COVERAGE_PHASE_HEADER)) != null ? _b : cookies.get(COVERAGE_PHASE_COOKIE);
511
+ const scope = decodeCoverageScope(typeof encodedScope === "string" ? encodedScope : void 0);
512
+ const phaseId = typeof rawPhaseId === "string" && rawPhaseId.length > 0 ? rawPhaseId : void 0;
513
+ return __spreadValues(__spreadValues({}, scope ? { scope } : {}), phaseId ? { phaseId } : {});
514
+ }
515
+ function withRequestPhase(handler) {
516
+ if (!serverPhaseStorage)
517
+ return handler;
518
+ return function coverageRequestPhase(...args) {
519
+ var _a8, _b, _c, _d, _e;
520
+ const requestContext = (_a8 = args.map((argument) => requestCoverageContext(argument)).find((context2) => context2.scope || context2.phaseId)) != null ? _a8 : {};
521
+ const inheritedContext = currentRequestContext();
522
+ const context = __spreadValues(__spreadValues({}, ((_b = requestContext.scope) != null ? _b : inheritedContext.scope) ? { scope: (_c = requestContext.scope) != null ? _c : inheritedContext.scope } : {}), ((_d = requestContext.phaseId) != null ? _d : inheritedContext.phaseId) ? { phaseId: (_e = requestContext.phaseId) != null ? _e : inheritedContext.phaseId } : {});
523
+ const invoke = () => Reflect.apply(handler, this, args);
524
+ return context.scope || context.phaseId ? serverPhaseStorage.run(context, invoke) : invoke();
525
+ };
448
526
  }
449
527
  function eventKey(event) {
450
- const suffix = event.type === "decision"
451
- ? `${event.id}:${vectorKey(event.vector)}`
452
- : event.id;
453
- return `${event.phaseId ?? "unscoped"}:${event.type}:${suffix}`;
528
+ var _a8;
529
+ const suffix = event.type === "decision" ? `${event.id}:${vectorKey(event.vector)}` : event.id;
530
+ return `${(_a8 = event.phaseId) != null ? _a8 : "unscoped"}:${event.type}:${suffix}`;
454
531
  }
455
532
  function recordBrowserEvent(event) {
456
- const key = eventKey(event);
457
- if (state.eventKeys.has(key))
458
- return false;
459
- state.eventKeys.add(key);
460
- state.events.push(event);
461
- return true;
462
- }
463
- export function coverageHit(id) {
464
- state.hits.add(id);
465
- const timestampMs = Date.now();
466
- const phaseId = currentPhaseId();
467
- if (isBrowser) {
468
- if (recordBrowserEvent({
469
- type: "hit",
470
- id,
471
- timestampMs,
472
- ...(phaseId ? { phaseId } : {}),
473
- environment: "browser",
474
- }))
475
- persistBrowser();
476
- }
477
- else {
478
- // Request servers retain repeated executions for phase-window correlation.
479
- // Local runner adapters explicitly buffer and de-duplicate per test/phase.
480
- appendServer({
481
- type: "hit",
482
- id,
483
- timestampMs,
484
- ...(phaseId ? { phaseId } : {}),
485
- });
486
- }
487
- }
488
- export function selectionBegin(shortId, rightId) {
489
- return { shortId, rightId, rightEvaluated: false };
533
+ const key = eventKey(event);
534
+ if (state.eventKeys.has(key))
535
+ return false;
536
+ state.eventKeys.add(key);
537
+ state.events.push(event);
538
+ return true;
539
+ }
540
+ function coverageHit(id) {
541
+ state.hits.add(id);
542
+ const timestampMs = Date.now();
543
+ const phaseId = currentPhaseId();
544
+ if (isBrowser) {
545
+ if (recordBrowserEvent(__spreadProps(__spreadValues({
546
+ type: "hit",
547
+ id,
548
+ timestampMs
549
+ }, phaseId ? { phaseId } : {}), {
550
+ environment: "browser"
551
+ })))
552
+ persistBrowser();
553
+ } else {
554
+ appendServer(__spreadValues({
555
+ type: "hit",
556
+ id,
557
+ timestampMs
558
+ }, phaseId ? { phaseId } : {}));
559
+ }
560
+ }
561
+ function selectionBegin(shortId, rightId) {
562
+ return { shortId, rightId, rightEvaluated: false };
490
563
  }
491
564
  function applyInferredName(value, inferredName) {
492
- if (inferredName &&
493
- typeof value === "function" &&
494
- value.name === "") {
495
- Object.defineProperty(value, "name", {
496
- value: inferredName,
497
- configurable: true,
498
- });
499
- }
500
- return value;
501
- }
502
- export function selectionRight(frame, value, inferredName) {
503
- frame.rightEvaluated = true;
504
- return applyInferredName(value, inferredName);
505
- }
506
- export function selectionEnd(frame, value) {
507
- coverageHit(frame.rightEvaluated ? frame.rightId : frame.shortId);
508
- return value;
509
- }
510
- export function optionalSelect(shortId, continuedId, value) {
511
- coverageHit(value === null || value === undefined ? shortId : continuedId);
512
- return value;
513
- }
514
- export function defaultSelected(defaultId, value, inferredName) {
515
- pendingDefaults.set(defaultId, (pendingDefaults.get(defaultId) ?? 0) + 1);
516
- return applyInferredName(value, inferredName);
517
- }
518
- export function defaultEntered(defaultId, providedId) {
519
- const pending = pendingDefaults.get(defaultId) ?? 0;
520
- if (pending > 0) {
521
- pendingDefaults.set(defaultId, pending - 1);
522
- coverageHit(defaultId);
523
- }
524
- else {
525
- coverageHit(providedId);
526
- }
527
- }
528
- export function tryBegin(successId, catchId) {
529
- return { successId, catchId, caught: false };
530
- }
531
- export function tryCatch(frame, value) {
532
- frame.caught = true;
533
- return value;
534
- }
535
- export function tryEnd(frame) {
536
- coverageHit(frame.caught ? frame.catchId : frame.successId);
537
- }
538
- export function loopBegin(zeroId, enteredId) {
539
- return { zeroId, enteredId, entered: false };
540
- }
541
- export function loopEntered(frame) {
542
- frame.entered = true;
543
- }
544
- export function loopEnd(frame) {
545
- coverageHit(frame.entered ? frame.enteredId : frame.zeroId);
546
- }
547
- export function mcdcBegin(id, meta) {
548
- if (!state.decisions.has(id)) {
549
- state.decisions.set(id, { meta, vectors: new Map() });
550
- }
551
- return {
552
- meta,
553
- values: Array.from({ length: meta.conditions.length }, () => null),
554
- };
555
- }
556
- export function mcdcCondition(frame, index, value) {
557
- frame.values[index] = Boolean(value);
558
- return value;
559
- }
560
- export function mcdcEnd(frame, value) {
561
- const decision = state.decisions.get(frame.meta.id);
562
- if (!decision)
563
- return value;
564
- const vector = { values: frame.values, outcome: Boolean(value) };
565
- const key = vectorKey(vector);
566
- decision.vectors.set(key, vector);
567
- const timestampMs = Date.now();
568
- const phaseId = currentPhaseId();
569
- if (isBrowser) {
570
- if (recordBrowserEvent({
571
- type: "decision",
572
- id: decision.meta.id,
573
- vector,
574
- timestampMs,
575
- ...(phaseId ? { phaseId } : {}),
576
- environment: "browser",
577
- }))
578
- persistBrowser();
579
- }
580
- else {
581
- appendServer({
582
- type: "decision",
583
- meta: decision.meta,
584
- vector,
585
- timestampMs,
586
- ...(phaseId ? { phaseId } : {}),
587
- });
588
- }
565
+ if (inferredName && typeof value === "function" && value.name === "") {
566
+ Object.defineProperty(value, "name", {
567
+ value: inferredName,
568
+ configurable: true
569
+ });
570
+ }
571
+ return value;
572
+ }
573
+ function selectionRight(frame, value, inferredName) {
574
+ frame.rightEvaluated = true;
575
+ return applyInferredName(value, inferredName);
576
+ }
577
+ function selectionEnd(frame, value) {
578
+ coverageHit(frame.rightEvaluated ? frame.rightId : frame.shortId);
579
+ return value;
580
+ }
581
+ function optionalSelect(shortId, continuedId, value) {
582
+ coverageHit(value === null || value === void 0 ? shortId : continuedId);
583
+ return value;
584
+ }
585
+ function defaultSelected(defaultId, value, inferredName) {
586
+ var _a8;
587
+ pendingDefaults.set(defaultId, ((_a8 = pendingDefaults.get(defaultId)) != null ? _a8 : 0) + 1);
588
+ return applyInferredName(value, inferredName);
589
+ }
590
+ function defaultEntered(defaultId, providedId) {
591
+ var _a8;
592
+ const pending = (_a8 = pendingDefaults.get(defaultId)) != null ? _a8 : 0;
593
+ if (pending > 0) {
594
+ pendingDefaults.set(defaultId, pending - 1);
595
+ coverageHit(defaultId);
596
+ } else {
597
+ coverageHit(providedId);
598
+ }
599
+ }
600
+ function tryBegin(successId, catchId) {
601
+ return { successId, catchId, caught: false };
602
+ }
603
+ function tryCatch(frame, value) {
604
+ frame.caught = true;
605
+ return value;
606
+ }
607
+ function tryEnd(frame) {
608
+ coverageHit(frame.caught ? frame.catchId : frame.successId);
609
+ }
610
+ function loopBegin(zeroId, enteredId) {
611
+ return { zeroId, enteredId, entered: false };
612
+ }
613
+ function loopEntered(frame) {
614
+ frame.entered = true;
615
+ }
616
+ function loopEnd(frame) {
617
+ coverageHit(frame.entered ? frame.enteredId : frame.zeroId);
618
+ }
619
+ function mcdcBegin(id, meta) {
620
+ if (!state.decisions.has(id)) {
621
+ state.decisions.set(id, { meta, vectors: /* @__PURE__ */ new Map() });
622
+ }
623
+ return {
624
+ meta,
625
+ values: Array.from({ length: meta.conditions.length }, () => null)
626
+ };
627
+ }
628
+ function mcdcCondition(frame, index, value) {
629
+ frame.values[index] = Boolean(value);
630
+ return value;
631
+ }
632
+ function mcdcEnd(frame, value) {
633
+ const decision = state.decisions.get(frame.meta.id);
634
+ if (!decision)
589
635
  return value;
590
- }
591
- //# sourceMappingURL=runtime.js.map
636
+ const vector = { values: frame.values, outcome: Boolean(value) };
637
+ const key = vectorKey(vector);
638
+ decision.vectors.set(key, vector);
639
+ const timestampMs = Date.now();
640
+ const phaseId = currentPhaseId();
641
+ if (isBrowser) {
642
+ if (recordBrowserEvent(__spreadProps(__spreadValues({
643
+ type: "decision",
644
+ id: decision.meta.id,
645
+ vector,
646
+ timestampMs
647
+ }, phaseId ? { phaseId } : {}), {
648
+ environment: "browser"
649
+ })))
650
+ persistBrowser();
651
+ } else {
652
+ appendServer(__spreadValues({
653
+ type: "decision",
654
+ meta: decision.meta,
655
+ vector,
656
+ timestampMs
657
+ }, phaseId ? { phaseId } : {}));
658
+ }
659
+ return value;
660
+ }
661
+ export {
662
+ beginBufferedServerEvidence,
663
+ bindCoverageContext,
664
+ coverageCarrier,
665
+ coverageContextEnvironment,
666
+ coverageContextHeaders,
667
+ coverageHit,
668
+ coverageSnapshot,
669
+ defaultEntered,
670
+ defaultSelected,
671
+ enableRuntimeSnapshotEvidence,
672
+ flushBufferedServerEvidence,
673
+ loopBegin,
674
+ loopEnd,
675
+ loopEntered,
676
+ mcdcBegin,
677
+ mcdcCondition,
678
+ mcdcEnd,
679
+ optionalSelect,
680
+ resetCoverage,
681
+ selectionBegin,
682
+ selectionEnd,
683
+ selectionRight,
684
+ tryBegin,
685
+ tryCatch,
686
+ tryEnd,
687
+ withCoverageCarrier,
688
+ withRequestPhase,
689
+ writeExclusiveBackgroundRecord
690
+ };