@piwitests/reporter 0.71.0 → 0.73.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/dist/index.js CHANGED
@@ -538,8 +538,8 @@ function readPrivateFile(file) {
538
538
  const fd = fs3.openSync(file, fs3.constants.O_RDONLY | NO_FOLLOW | NO_WAIT);
539
539
  try {
540
540
  const stat2 = fs3.fstatSync(fd);
541
- const opened = untrustedReason(stat2);
542
- if (opened) return { untrusted: opened };
541
+ const opened2 = untrustedReason(stat2);
542
+ if (opened2) return { untrusted: opened2 };
543
543
  return { text: fs3.readFileSync(fd, "utf8"), mode: stat2.mode };
544
544
  } finally {
545
545
  fs3.closeSync(fd);
@@ -3280,7 +3280,9 @@ var RUN_REF_ENV = "PIWI_RUN_REF";
3280
3280
  var TERMINAL_REF_PREFIX = "terminal-";
3281
3281
  var UNATTENDED_REF_SUFFIX = "-unattended";
3282
3282
  var RUN_HOLDS = ["failure"];
3283
- var RUN_FEATURES = ["view-lane", "give-up", "front", "layers", "trace"];
3283
+ var RUN_FEATURES = ["view-lane", "give-up", "front", "layers", "trace", "positions"];
3284
+ var POSITIONS_PER_SECOND = 4;
3285
+ var MAX_POSITION_TITLE = 300;
3284
3286
  var MAX_WAITING_TITLE = 500;
3285
3287
  var RUN_INTENTS = ["pick", "record", "assert", "assert-region"];
3286
3288
  var RUN_TAKES = [
@@ -3454,6 +3456,8 @@ function parseHubToRun(line) {
3454
3456
  const layers = readLaneLayers(value.layers);
3455
3457
  return layers ? { type: "layers", layers } : null;
3456
3458
  }
3459
+ case "positions":
3460
+ return typeof value.on === "boolean" ? { type: "positions", on: value.on } : null;
3457
3461
  case "share": {
3458
3462
  if (typeof value.on !== "boolean") return null;
3459
3463
  return isInt2(value.after, 1) ? { type: "share", on: value.on, after: value.after } : { type: "share", on: value.on };
@@ -7470,10 +7474,10 @@ var StreamManager = class {
7470
7474
  next ? "The run is open on the dashboard: streaming live steps." : "Nobody is watching the run: live steps are not sent."
7471
7475
  );
7472
7476
  }
7473
- const opened = next === true && this.watched !== true;
7477
+ const opened2 = next === true && this.watched !== true;
7474
7478
  const unwatched = next === false && this.watched !== false;
7475
7479
  this.watched = next;
7476
- if (opened) this.onWatched?.();
7480
+ if (opened2) this.onWatched?.();
7477
7481
  if (unwatched && this.heartbeatTimer) {
7478
7482
  clearTimeout(this.heartbeatTimer);
7479
7483
  this.heartbeatTimer = null;
@@ -8820,6 +8824,14 @@ async function checkBaseUrls(config, options = {}) {
8820
8824
  var fs17 = __toESM(require("fs"));
8821
8825
  var path17 = __toESM(require("path"));
8822
8826
 
8827
+ // ../core/src/deployed-commit.ts
8828
+ var DEPLOYED_COMMIT = /^[0-9a-f]{7,40}$/i;
8829
+ function deployedCommitOf(raw) {
8830
+ if (typeof raw !== "string") return null;
8831
+ const value = raw.trim();
8832
+ return DEPLOYED_COMMIT.test(value) ? value.toLowerCase() : null;
8833
+ }
8834
+
8823
8835
  // src/internal/transport/backend-request.ts
8824
8836
  var http2 = __toESM(require("http"));
8825
8837
  var https2 = __toESM(require("https"));
@@ -8972,6 +8984,7 @@ function parseServerEnvironment(text2) {
8972
8984
  globalization: cutField(o.globalization),
8973
8985
  environmentName: cutField(o.environmentName),
8974
8986
  appVersion: cutField(o.appVersion),
8987
+ appCommit: deployedCommitOf(o.appCommit),
8975
8988
  hostname: cutField(o.hostname),
8976
8989
  instance: cutField(o.instance),
8977
8990
  startedAt: cutField(o.startedAt),
@@ -10298,6 +10311,13 @@ function fulfillHeaders(responseHeaders, contentType) {
10298
10311
  if (contentType) headers["content-type"] = contentType;
10299
10312
  return headers;
10300
10313
  }
10314
+ function isMainFrameRequest(page, request3) {
10315
+ try {
10316
+ return request3.frame() === page.mainFrame();
10317
+ } catch {
10318
+ return false;
10319
+ }
10320
+ }
10301
10321
  function originOf2(url) {
10302
10322
  try {
10303
10323
  const origin = new URL(url).origin;
@@ -10342,25 +10362,31 @@ async function installRouteRules(page, rules) {
10342
10362
  });
10343
10363
  return { state };
10344
10364
  }
10345
- async function installProbeInterception(page, item) {
10365
+ async function installProbeInterception(page, item, baseURL = null) {
10346
10366
  if (!isFaultAllowed(item.level ?? "client", item.fault)) {
10347
10367
  return { applied: () => false, appliedFault: () => null, serverError: () => false };
10348
10368
  }
10349
10369
  let applied = false;
10350
10370
  let appliedFault = null;
10351
10371
  let serverError = false;
10352
- let appOrigin = null;
10372
+ const appOrigins = /* @__PURE__ */ new Set();
10373
+ const baseOrigin = baseURL ? originOf2(baseURL) : null;
10374
+ if (baseOrigin) appOrigins.add(baseOrigin);
10375
+ let firstOpened = false;
10353
10376
  const probeSecret = process.env[PIWI_PROBE_ENV.secret];
10354
- page.on("framenavigated", (frame) => {
10355
- if (frame === page.mainFrame()) {
10356
- const origin = originOf2(page.url());
10357
- if (origin) appOrigin = origin;
10358
- }
10377
+ page.on("request", (request3) => {
10378
+ if (firstOpened || !request3.isNavigationRequest() || request3.redirectedFrom()) return;
10379
+ if (!isMainFrameRequest(page, request3)) return;
10380
+ const origin = originOf2(request3.url());
10381
+ if (!origin) return;
10382
+ firstOpened = true;
10383
+ appOrigins.add(origin);
10359
10384
  });
10360
10385
  const handle = async (route, startedAt) => {
10361
10386
  const request3 = route.request();
10362
10387
  if (item.level === "server") {
10363
- if (!probeSecret || appOrigin !== null && originOf2(request3.url()) !== appOrigin) {
10388
+ const origin = originOf2(request3.url());
10389
+ if (!probeSecret || origin === null || !appOrigins.has(origin)) {
10364
10390
  await route.fallback();
10365
10391
  return;
10366
10392
  }
@@ -10368,7 +10394,8 @@ async function installProbeInterception(page, item) {
10368
10394
  if (item.dependency) spec.dependency = item.dependency;
10369
10395
  try {
10370
10396
  const response = await route.fetch({
10371
- headers: { ...request3.headers(), "x-piwi-probe": buildProbeHeader(probeSecret, spec) }
10397
+ headers: { ...request3.headers(), "x-piwi-probe": buildProbeHeader(probeSecret, spec) },
10398
+ maxRedirects: 0
10372
10399
  });
10373
10400
  const trace = parseProbeTrace(response.headers()["x-piwi-trace"]);
10374
10401
  appliedFault = trace.appliedFault;
@@ -12387,6 +12414,7 @@ function captureCallerLocation(stack = new Error().stack ?? "") {
12387
12414
  }
12388
12415
 
12389
12416
  // src/internal/capture/quiet-capture.ts
12417
+ var import_node_async_hooks = require("async_hooks");
12390
12418
  var import_node_module2 = require("module");
12391
12419
  var path23 = __toESM(require("path"));
12392
12420
  var BOXED_PREFIX_EXPORTS = [
@@ -12447,6 +12475,7 @@ function boxCaptureFrames(extraPrefixes = []) {
12447
12475
  function callMethod(target, prop, args) {
12448
12476
  return target[prop](...args);
12449
12477
  }
12478
+ var outsideCalls = import_node_async_hooks.AsyncResource.bind((run) => run());
12450
12479
  function internalCall(owner, run) {
12451
12480
  const wrap = owner?._wrapApiCall;
12452
12481
  if (typeof wrap !== "function") return run();
@@ -12900,16 +12929,16 @@ var PageReader = class {
12900
12929
  let session = this.sessions.get(page);
12901
12930
  if (!session) {
12902
12931
  session = internalCall(page, async () => {
12903
- const opened2 = await page.context().newCDPSession(page);
12904
- await opened2.send("Performance.enable", { timeDomain: "threadTicks" });
12905
- return opened2;
12932
+ const opened3 = await page.context().newCDPSession(page);
12933
+ await opened3.send("Performance.enable", { timeDomain: "threadTicks" });
12934
+ return opened3;
12906
12935
  }).catch(() => null);
12907
12936
  this.sessions.set(page, session);
12908
12937
  }
12909
- const opened = await session;
12910
- if (!opened) return null;
12938
+ const opened2 = await session;
12939
+ if (!opened2) return null;
12911
12940
  try {
12912
- const result = await internalCall(page, () => opened.send("Performance.getMetrics"));
12941
+ const result = await internalCall(page, () => opened2.send("Performance.getMetrics"));
12913
12942
  const values = new Map((result.metrics ?? []).map((metric) => [metric.name, metric.value]));
12914
12943
  const main = {
12915
12944
  cpuMs: Math.round((values.get("TaskDuration") ?? 0) * 1e3),
@@ -12917,7 +12946,7 @@ var PageReader = class {
12917
12946
  nodes: values.get("Nodes") ?? 0,
12918
12947
  listeners: values.get("JSEventListeners") ?? 0
12919
12948
  };
12920
- const elements = await this.countElements(page, opened);
12949
+ const elements = await this.countElements(page, opened2);
12921
12950
  if (elements !== null) main.elements = elements;
12922
12951
  return main;
12923
12952
  } catch {
@@ -12963,6 +12992,18 @@ var PERSISTENT_CALL = /launchPersistentContext$/;
12963
12992
  var CLOSE_TIMEOUT_MS = 5e3;
12964
12993
  var PAGE_READ_CAP = 50;
12965
12994
  var PAGE_READ_TIMEOUT_MS = 1e3;
12995
+ var callPageListeners = /* @__PURE__ */ new Set();
12996
+ function pageOfCall(object) {
12997
+ for (let owner = object; owner; owner = owner._parent) {
12998
+ if (owner._type === "Page") return owner;
12999
+ if (owner._type === "Frame" && owner._page) return owner._page;
13000
+ }
13001
+ return null;
13002
+ }
13003
+ function onTestCallPage(listener) {
13004
+ callPageListeners.add(listener);
13005
+ return () => callPageListeners.delete(listener);
13006
+ }
12966
13007
  var HOOK_PHASES = /* @__PURE__ */ new Set(["beforeAll", "afterAll", "beforeEach", "afterEach"]);
12967
13008
  var KIND_ORDER = { browser: 0, context: 1, page: 2, request: 3 };
12968
13009
  function relativePath(file, cwd = process.cwd(), windows = process.platform === "win32") {
@@ -13221,6 +13262,7 @@ var ResourceLedger = class {
13221
13262
  }
13222
13263
  if (options?.internal || !options?.frames?.length || TRAFFIC_TYPES.has(String(object._type))) return;
13223
13264
  if (CLOSE_METHODS.has(String(method))) return this.noteClosing(object);
13265
+ this.tellCallPage(object);
13224
13266
  const site = zoneSite(options);
13225
13267
  this.touch(object, site);
13226
13268
  if (result && typeof result.then === "function") {
@@ -13237,6 +13279,7 @@ var ResourceLedger = class {
13237
13279
  const id = info?.waitId;
13238
13280
  if (id === void 0) return;
13239
13281
  if (info?.phase === "before" && !options?.internal && options?.frames?.length) {
13282
+ this.tellCallPage(object);
13240
13283
  if (this.waits.size >= WAITS_CAP) this.waits.clear();
13241
13284
  const site = zoneSite(options);
13242
13285
  this.waits.set(id, { object, site });
@@ -13247,6 +13290,12 @@ var ResourceLedger = class {
13247
13290
  if (waited) this.touch(waited.object, waited.site);
13248
13291
  }
13249
13292
  }
13293
+ /** Tell the listeners of `onTestCallPage` the page a call of the test lands on, when it lands on one. */
13294
+ tellCallPage(object) {
13295
+ if (!callPageListeners.size) return;
13296
+ const page = pageOfCall(object);
13297
+ if (page) for (const listener of callPageListeners) this.guard(() => outsideCalls(() => listener(page)));
13298
+ }
13250
13299
  /**
13251
13300
  * Mark an object, and the page, context and browser it belongs to, used now
13252
13301
  * by the call at `site`. A close that began before it did not end: the
@@ -13875,18 +13924,18 @@ function tallyLifecycleSteps(attempt3, steps, source2) {
13875
13924
  walk(step.steps ?? [], blockHook(step, source2), fixture);
13876
13925
  continue;
13877
13926
  }
13878
- const opened = OPEN_STEPS[step.title];
13927
+ const opened2 = OPEN_STEPS[step.title];
13879
13928
  const closed = CLOSE_STEPS[step.title];
13880
- if (step.category === "pw:api" && !step.error && (opened || closed)) {
13929
+ if (step.category === "pw:api" && !step.error && (opened2 || closed)) {
13881
13930
  const { location } = step;
13882
13931
  const site = location ? `${relativeFile(location.file)}:${location.line}` : null;
13883
- const method = opened?.method ?? "close";
13932
+ const method = opened2?.method ?? "close";
13884
13933
  const key = location ? `${location.file}:${location.line}:${location.column}:${method}` : "";
13885
13934
  const nth = seen.get(key) ?? 0;
13886
13935
  seen.set(key, nth + 1);
13887
13936
  const names = namesAt(step, source2, method, nth);
13888
13937
  const call = { site, block, fixture: fixture !== null, on: names.on };
13889
- if (opened) calls.push({ op: "open", kind: opened.kind, ...call, name: fixture ?? names.name });
13938
+ if (opened2) calls.push({ op: "open", kind: opened2.kind, ...call, name: fixture ?? names.name });
13890
13939
  else calls.push({ op: "close", kind: closed, ...call, name: fixture });
13891
13940
  }
13892
13941
  walk(step.steps ?? [], block, step.category === "fixture" ? fixtureName(step) : fixture);
@@ -13996,9 +14045,10 @@ function buildResourceReport(input2) {
13996
14045
  findings.push(...groupIdle(idle, input2.fixturesByTest ?? /* @__PURE__ */ new Map()));
13997
14046
  findings.push(...groupLingering(lingering, all, spans));
13998
14047
  findings.push(...probableFindings(input2.tallies ?? []));
14048
+ const leftOpenPages = leaked.filter((leak) => leak.tracked.birth.kind === "page" && leak.to > leak.from).map((leak) => ({ worker: leak.tracked.worker, from: leak.from, to: leak.to }));
13999
14049
  const counts = { leaked: 0, lingering: 0, idle: 0, piling: 0, handle: 0, probable: 0 };
14000
14050
  for (const finding of findings) counts[finding.verdict] += finding.verdict === "idle" ? finding.count : 1;
14001
- return { findings, counts, spans: spans.sort((a, b) => a.from - b.from) };
14051
+ return { findings, counts, spans: spans.sort((a, b) => a.from - b.from), leftOpenPages };
14002
14052
  }
14003
14053
  function sameFile(birth, ref) {
14004
14054
  return !!ref && !!birth.test && ref.file === birth.test.file;
@@ -14452,12 +14502,12 @@ function unpairedOpens(attempts) {
14452
14502
  (o) => o.call.name === null && o.counted,
14453
14503
  (o) => o.call.name === null
14454
14504
  ] : [(o) => o.counted, () => true];
14455
- const levels = [
14505
+ const levels2 = [
14456
14506
  (o) => o.scope === scope,
14457
14507
  (o) => o.scope === "block",
14458
14508
  (o) => o.counted
14459
14509
  ];
14460
- for (const level of levels) {
14510
+ for (const level of levels2) {
14461
14511
  for (const rank2 of ranks) {
14462
14512
  const open4 = latest((o) => free(o) && level(o) && rank2(o));
14463
14513
  if (open4) return open4;
@@ -15425,20 +15475,35 @@ function pagesOverTime(censuses, live = false) {
15425
15475
  for (const close2 of census.closed) if (pages.has(close2.id)) changes2.push([close2.at, -1]);
15426
15476
  }
15427
15477
  if (changes2.length === 0) continue;
15428
- changes2.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
15429
- const events = [];
15430
- let open4 = 0;
15431
- for (const [at, delta] of changes2) {
15432
- open4 = Math.max(0, open4 + delta);
15433
- const last = events[events.length - 1];
15434
- if (last && last[0] === at) last[1] = open4;
15435
- else events.push([at, open4]);
15436
- }
15478
+ const events = levels(changes2);
15479
+ const open4 = events[events.length - 1][1];
15437
15480
  if (!live && open4 > 0 && lastAt >= events[events.length - 1][0]) events.push([lastAt, 0]);
15438
15481
  out.push({ worker, events });
15439
15482
  }
15440
15483
  return out;
15441
15484
  }
15485
+ function levels(changes2) {
15486
+ const sorted = [...changes2].sort((a, b) => a[0] - b[0] || b[1] - a[1]);
15487
+ const events = [];
15488
+ let open4 = 0;
15489
+ for (const [at, delta] of sorted) {
15490
+ open4 = Math.max(0, open4 + delta);
15491
+ const last = events[events.length - 1];
15492
+ if (last && last[0] === at) last[1] = open4;
15493
+ else events.push([at, open4]);
15494
+ }
15495
+ return events;
15496
+ }
15497
+ function leftOpenOverTime(pages) {
15498
+ const byWorker = /* @__PURE__ */ new Map();
15499
+ for (const { worker, from, to } of pages) {
15500
+ if (to <= from) continue;
15501
+ const changes2 = byWorker.get(worker) ?? [];
15502
+ changes2.push([from, 1], [to, -1]);
15503
+ byWorker.set(worker, changes2);
15504
+ }
15505
+ return new Map([...byWorker].map(([worker, changes2]) => [worker, levels(changes2)]));
15506
+ }
15442
15507
  function workerTreesByIndex(samples, censuses) {
15443
15508
  const byPid = /* @__PURE__ */ new Map();
15444
15509
  for (const census of censuses) {
@@ -15479,8 +15544,9 @@ function wireSpan(span, startedAt) {
15479
15544
  ...span.test ? { test: span.test } : {}
15480
15545
  };
15481
15546
  }
15482
- function resourceTimeline(samples, censuses, spans = []) {
15547
+ function resourceTimeline(samples, censuses, spans = [], leftOpenPages = []) {
15483
15548
  const workers = pagesOverTime(censuses);
15549
+ const leftOpen = leftOpenOverTime(leftOpenPages);
15484
15550
  const hasSamples = samples !== null && (samples.cpuPct.length > 0 || samples.memoryBytes.length > 0);
15485
15551
  const kept = keptSpans(spans);
15486
15552
  if (!hasSamples && workers.length === 0 && kept.length === 0) return null;
@@ -15489,6 +15555,11 @@ function resourceTimeline(samples, censuses, spans = []) {
15489
15555
  for (const span of kept) startedAt = Math.min(startedAt, span.from);
15490
15556
  const shift = hasSamples ? samples.startedAt - startedAt : 0;
15491
15557
  const relative11 = (points, by) => points.map(([at, value]) => [Math.round(at + by), value]);
15558
+ const level = (events) => {
15559
+ const points = relative11(events, -startedAt);
15560
+ const last = points.pop();
15561
+ return [...downsamplePoints(points, TIMELINE_WORKER_POINTS_CAP - 1, "max"), last];
15562
+ };
15492
15563
  const trees = hasSamples ? workerTreesByIndex(samples, censuses) : [];
15493
15564
  const perWorker = Math.max(
15494
15565
  60,
@@ -15499,9 +15570,8 @@ function resourceTimeline(samples, censuses, spans = []) {
15499
15570
  cpuPct: hasSamples ? downsamplePoints(relative11(samples.cpuPct, shift), TIMELINE_SERIES_CAP, "mean") : [],
15500
15571
  memoryBytes: hasSamples ? downsamplePoints(relative11(samples.memoryBytes, shift), TIMELINE_SERIES_CAP, "max") : [],
15501
15572
  pages: workers.map(({ worker, events }) => {
15502
- const points = relative11(events, -startedAt);
15503
- const last = points.pop();
15504
- return { worker, points: [...downsamplePoints(points, TIMELINE_WORKER_POINTS_CAP - 1, "max"), last] };
15573
+ const left = leftOpen.get(worker);
15574
+ return { worker, points: level(events), ...left?.length ? { leftOpen: level(left) } : {} };
15505
15575
  }),
15506
15576
  workers: trees.map((tree) => ({
15507
15577
  worker: tree.worker,
@@ -15522,7 +15592,7 @@ function resourceReportWire(input2) {
15522
15592
  workers: openPagesByWorker(input2.censuses),
15523
15593
  artifactBytes: nonZero(input2.artifacts) ?? {},
15524
15594
  workerHealth: workerHealthOf(input2.censuses),
15525
- timeline: resourceTimeline(input2.samples ?? null, input2.censuses, report?.spans ?? [])
15595
+ timeline: resourceTimeline(input2.samples ?? null, input2.censuses, report?.spans ?? [], report?.leftOpenPages ?? [])
15526
15596
  };
15527
15597
  }
15528
15598
 
@@ -23870,13 +23940,14 @@ async function keptResponse(id) {
23870
23940
  var CLOSE_MS2 = 1e3;
23871
23941
  var test = null;
23872
23942
  var stop = null;
23943
+ var opened = [];
23873
23944
  var subscribers = /* @__PURE__ */ new Set();
23874
23945
  var pageListeners = /* @__PURE__ */ new Set();
23875
23946
  var pageTold;
23876
23947
  var source = null;
23877
23948
  var closingOf = /* @__PURE__ */ new WeakMap();
23878
23949
  function laneTestBegan(id) {
23879
- test = { id, fixture: null, seen: [] };
23950
+ test = { id, fixture: null, called: null };
23880
23951
  void sync();
23881
23952
  tellPage();
23882
23953
  }
@@ -23887,9 +23958,23 @@ function lanePage(page) {
23887
23958
  tellPage();
23888
23959
  }
23889
23960
  function laneSawPage(page) {
23890
- if (!test || test.seen.includes(page)) return;
23891
- test.seen.push(page);
23892
- if (!source) void sync();
23961
+ if (opened.includes(page)) return;
23962
+ opened.push(page);
23963
+ if (typeof page.once === "function") {
23964
+ page.once("close", () => {
23965
+ const at = opened.indexOf(page);
23966
+ if (at >= 0) opened.splice(at, 1);
23967
+ tellPage();
23968
+ });
23969
+ }
23970
+ if (!test) return;
23971
+ void sync();
23972
+ tellPage();
23973
+ }
23974
+ function laneCalled(page) {
23975
+ if (!test || test.called === page || !opened.includes(page)) return;
23976
+ test.called = page;
23977
+ void sync();
23893
23978
  tellPage();
23894
23979
  }
23895
23980
  async function laneTestEnded() {
@@ -23929,7 +24014,9 @@ function tellPage() {
23929
24014
  }
23930
24015
  if (page === pageTold) return;
23931
24016
  pageTold = page;
23932
- for (const listener of pageListeners) listener();
24017
+ outsideCalls(() => {
24018
+ for (const listener of pageListeners) listener();
24019
+ });
23933
24020
  }
23934
24021
  function restamp() {
23935
24022
  const kept = source?.latest;
@@ -23950,7 +24037,14 @@ function lanePageShown() {
23950
24037
  const own = open4(stop?.page ?? null);
23951
24038
  if (own) return own;
23952
24039
  if (!test) return null;
23953
- return open4(test.fixture) ?? test.seen.find((page) => !page.isClosed()) ?? null;
24040
+ return open4(test.fixture) ?? open4(test.called) ?? lastOpened();
24041
+ }
24042
+ function lastOpened() {
24043
+ for (let at = opened.length - 1; at >= 0; at--) {
24044
+ const page = opened[at];
24045
+ if (!page.isClosed()) return page;
24046
+ }
24047
+ return null;
23954
24048
  }
23955
24049
  function pacerOf(own) {
23956
24050
  return new LatestPacer({
@@ -23994,11 +24088,7 @@ function subscribeLane(sink) {
23994
24088
  return subscribers.has(own) && kept && !("refused" in kept) && current2(kept) ? kept : null;
23995
24089
  },
23996
24090
  refresh: () => {
23997
- for (const subscriber of subscribers) {
23998
- subscriber.last = null;
23999
- subscriber.pacer.close();
24000
- subscriber.pacer = pacerOf(subscriber);
24001
- }
24091
+ for (const subscriber of subscribers) forgetFrames(subscriber);
24002
24092
  if (source) source.latest = null;
24003
24093
  void source?.view.then((view3) => view3?.refresh());
24004
24094
  },
@@ -24028,14 +24118,22 @@ function asked() {
24028
24118
  shotMs: Math.min(...sinks.map((sink) => sink.shotMs))
24029
24119
  };
24030
24120
  }
24121
+ function forgetFrames(subscriber) {
24122
+ subscriber.last = null;
24123
+ subscriber.pacer.close();
24124
+ subscriber.pacer = pacerOf(subscriber);
24125
+ }
24031
24126
  function sync() {
24032
24127
  const page = subscribers.size ? lanePageShown() : null;
24033
24128
  const options = page ? asked() : null;
24034
24129
  const key = options ? JSON.stringify(options) : "";
24035
24130
  if (source && source.page === page && source.asked === key) return Promise.resolve();
24036
- const closed = source ? close(source) : Promise.resolve();
24037
- source = page && options ? open2(page, options, key) : null;
24038
- return closed;
24131
+ if (source && source.page !== page) for (const subscriber of subscribers) forgetFrames(subscriber);
24132
+ return outsideCalls(() => {
24133
+ const closed = source ? close(source) : Promise.resolve();
24134
+ source = page && options ? open2(page, options, key) : null;
24135
+ return closed;
24136
+ });
24039
24137
  }
24040
24138
  function close(shown2) {
24041
24139
  if (source === shown2) source = null;
@@ -24856,6 +24954,7 @@ function shownInFull(own) {
24856
24954
  return own.asked?.full ?? true;
24857
24955
  }
24858
24956
  var link = null;
24957
+ var unhearLane = null;
24859
24958
  var missing = null;
24860
24959
  var changes = /* @__PURE__ */ new Set();
24861
24960
  var shareTurn = Promise.resolve();
@@ -24961,6 +25060,7 @@ function openLiveView(worker, env = process.env, ci = detectCi(env)) {
24961
25060
  asked: null
24962
25061
  };
24963
25062
  if (link.sharing) connect2(link);
25063
+ unhearLane = onLanePage(lanePageChanged);
24964
25064
  inspectSent.clear();
24965
25065
  filmstrip?.close();
24966
25066
  filmstrip = new LaneFilmstrip(watchedLane, (kept, test2) => {
@@ -24976,6 +25076,8 @@ function closeLiveView() {
24976
25076
  link = null;
24977
25077
  running = null;
24978
25078
  missing = null;
25079
+ unhearLane?.();
25080
+ unhearLane = null;
24979
25081
  filmstrip?.close();
24980
25082
  filmstrip = null;
24981
25083
  thumbPosts.queue = [];
@@ -25021,15 +25123,24 @@ async function stopSharing() {
25021
25123
  }
25022
25124
  function liveViewTestBegan(title, call, mayPause2 = false) {
25023
25125
  if (!link) return;
25024
- running = { title, page: null, call, mayPause: mayPause2, began: Date.now() };
25126
+ running = { title, call, mayPause: mayPause2, began: Date.now() };
25025
25127
  textGeneration++;
25026
25128
  filmstrip?.forget();
25027
25129
  thumbPosts.queue = [];
25130
+ lanePageChanged();
25028
25131
  }
25029
- function liveViewPage(page) {
25030
- if (!link || !running || running.page) return;
25031
- running.page = page;
25032
- if (link.viewers > 0 && active(link)) startView();
25132
+ function lanePageChanged() {
25133
+ const own = link;
25134
+ if (!own || !running || !active(own) || own.viewers === 0) return;
25135
+ const page = lanePageNow();
25136
+ if (view?.page === page) return;
25137
+ if (!view) {
25138
+ if (page) startView();
25139
+ } else if (!page) {
25140
+ void stopView();
25141
+ } else {
25142
+ moveView(own, page);
25143
+ }
25033
25144
  }
25034
25145
  async function liveViewTestEnded(status) {
25035
25146
  if (!running) return;
@@ -25355,14 +25466,15 @@ function startThumbPosts(own) {
25355
25466
  }
25356
25467
  function startView() {
25357
25468
  const own = link;
25358
- const page = running?.page ?? null;
25469
+ const page = running ? lanePageNow() : null;
25359
25470
  if (!own || !active(own) || view) return;
25360
25471
  if (!page || page.isClosed()) {
25361
25472
  void post(own, { type: "frame", ...own.id, refused: NO_PAGE });
25362
25473
  return;
25363
25474
  }
25364
- const live = () => view?.page === page && link === own && active(own) && own.viewers > 0;
25365
- const frames = subscribeLane({
25475
+ let frames = null;
25476
+ const live = () => !!frames && view?.frames === frames && link === own && active(own) && own.viewers > 0;
25477
+ frames = subscribeLane({
25366
25478
  get maxWidth() {
25367
25479
  return own.asked?.width ?? LIVE_FRAME_WIDTH;
25368
25480
  },
@@ -25387,14 +25499,26 @@ function startView() {
25387
25499
  if (live()) void post(own, { type: "frame", ...own.id, refused: why ?? TOO_HEAVY });
25388
25500
  }
25389
25501
  });
25390
- const onClose = () => {
25391
- if (view?.page === page) void stopView();
25392
- };
25502
+ const onClose = () => lanePageChanged();
25393
25503
  page.once("close", onClose);
25394
25504
  view = { page, frames, onClose, following: null };
25395
25505
  followCalls(own);
25396
25506
  applyLayers(own, /* @__PURE__ */ new Set());
25397
25507
  }
25508
+ function moveView(own, page) {
25509
+ const shown2 = view;
25510
+ if (!shown2) return;
25511
+ shown2.page.off("close", shown2.onClose);
25512
+ void shown2.following?.then((stop2) => stop2?.());
25513
+ shown2.following = null;
25514
+ forgetLog(own);
25515
+ shown2.page = page;
25516
+ page.once("close", shown2.onClose);
25517
+ textGeneration++;
25518
+ void stopInspect();
25519
+ followCalls(own);
25520
+ applyLayers(own, new Set((own.asked?.layers ?? []).filter((layer) => layer !== "text")));
25521
+ }
25398
25522
  function followCalls(own) {
25399
25523
  const shown2 = view;
25400
25524
  if (!shown2 || own !== link) return;
@@ -25406,7 +25530,7 @@ function followCalls(own) {
25406
25530
  page,
25407
25531
  running.began,
25408
25532
  (log) => {
25409
- if (view === shown2 && link === own && active(own) && own.viewers > 0) postLog(own, log);
25533
+ if (view === shown2 && shown2.page === page && link === own && active(own) && own.viewers > 0) postLog(own, log);
25410
25534
  },
25411
25535
  { source: source2, titleOf: layersTitleOf, secrets: knownSecrets }
25412
25536
  ).catch(() => null);
@@ -25582,6 +25706,11 @@ var pickingAt = false;
25582
25706
  var runName = "";
25583
25707
  var eventsOn = false;
25584
25708
  var testRunning = false;
25709
+ var runningTestId = null;
25710
+ var positionsOn = false;
25711
+ var positionToldAt = -Infinity;
25712
+ var pendingPosition = null;
25713
+ var positionTimer = null;
25585
25714
  var eventRate = new RateWindow(MAX_RUN_EVENT_RATE);
25586
25715
  var droppedEvents = 0;
25587
25716
  var agentTurn = Promise.resolve();
@@ -25604,7 +25733,7 @@ async function openRunChannel(worker, handlers, env = process.env) {
25604
25733
  if (socket || !channel || !ref) return false;
25605
25734
  const opening = net4.connect(channel.path);
25606
25735
  opening.setEncoding("utf8");
25607
- const opened = await new Promise((resolve15) => {
25736
+ const opened2 = await new Promise((resolve15) => {
25608
25737
  const timer = setTimeout(() => resolve15(false), CONNECT_MS);
25609
25738
  opening.once("connect", () => {
25610
25739
  clearTimeout(timer);
@@ -25615,7 +25744,7 @@ async function openRunChannel(worker, handlers, env = process.env) {
25615
25744
  resolve15(false);
25616
25745
  });
25617
25746
  });
25618
- if (!opened || opening.destroyed) {
25747
+ if (!opened2 || opening.destroyed) {
25619
25748
  opening.destroy();
25620
25749
  return false;
25621
25750
  }
@@ -25624,6 +25753,9 @@ async function openRunChannel(worker, handlers, env = process.env) {
25624
25753
  shown = /* @__PURE__ */ new Set();
25625
25754
  runName = `piwi-${ref}-w${worker.workerIndex}`;
25626
25755
  eventsOn = false;
25756
+ positionsOn = false;
25757
+ positionToldAt = -Infinity;
25758
+ dropPendingPosition();
25627
25759
  layersAsked = /* @__PURE__ */ new Set();
25628
25760
  host = null;
25629
25761
  opening.unref();
@@ -25724,11 +25856,15 @@ function runChannelOpen() {
25724
25856
  function tellHub(message) {
25725
25857
  if (message.type === "test-begin") {
25726
25858
  testRunning = true;
25859
+ runningTestId = message.testId;
25860
+ dropPendingPosition();
25727
25861
  laneGeneration++;
25728
25862
  filmstrip2?.forget();
25729
25863
  }
25730
25864
  if (message.type === "test-end") {
25731
25865
  testRunning = false;
25866
+ runningTestId = null;
25867
+ dropPendingPosition();
25732
25868
  void unbind();
25733
25869
  }
25734
25870
  if (socket && !socket.destroyed) socket.write(`${JSON.stringify(message)}
@@ -25737,6 +25873,32 @@ function tellHub(message) {
25737
25873
  function tellActing(stop2, what) {
25738
25874
  if (held?.stop === stop2) tellHub({ type: "acting", stop: stop2, what });
25739
25875
  }
25876
+ function positionsWanted() {
25877
+ return positionsOn && testRunning && runningTestId !== null && runChannelOpen();
25878
+ }
25879
+ function tellPosition(title, place) {
25880
+ if (!positionsWanted()) return;
25881
+ pendingPosition = { title, place };
25882
+ if (positionTimer) return;
25883
+ const wait = positionToldAt + 1e3 / POSITIONS_PER_SECOND - performance.now();
25884
+ if (wait <= 0) return sendPendingPosition();
25885
+ positionTimer = setTimeout(sendPendingPosition, wait);
25886
+ positionTimer.unref?.();
25887
+ }
25888
+ function sendPendingPosition() {
25889
+ if (positionTimer) clearTimeout(positionTimer);
25890
+ positionTimer = null;
25891
+ const position = pendingPosition;
25892
+ pendingPosition = null;
25893
+ if (!position || !positionsWanted()) return;
25894
+ positionToldAt = performance.now();
25895
+ tellHub({ type: "position", testId: runningTestId, title: position.title, place: position.place });
25896
+ }
25897
+ function dropPendingPosition() {
25898
+ pendingPosition = null;
25899
+ if (positionTimer) clearTimeout(positionTimer);
25900
+ positionTimer = null;
25901
+ }
25740
25902
  function runEventsWanted() {
25741
25903
  return eventsOn && testRunning && runChannelOpen();
25742
25904
  }
@@ -26040,20 +26202,20 @@ function startView2(holding) {
26040
26202
  const started = (async () => {
26041
26203
  if (view2) await stopView2();
26042
26204
  const opening = openView2(page, holding.stop);
26043
- const opened = await answerWithin(opening, PAGE_ANSWER_MS, "late");
26044
- if (opened === "late") {
26205
+ const opened2 = await answerWithin(opening, PAGE_ANSWER_MS, "late");
26206
+ if (opened2 === "late") {
26045
26207
  void opening.then((late) => late?.close());
26046
26208
  return { ok: false, message: NO_ANSWER };
26047
26209
  }
26048
- if (!opened) return { ok: false, message: "The page could not be shown: it closed, or does not answer." };
26210
+ if (!opened2) return { ok: false, message: "The page could not be shown: it closed, or does not answer." };
26049
26211
  if (held !== holding || page.isClosed()) {
26050
- await within5(opened.close(), VIEW_END_MS2);
26212
+ await within5(opened2.close(), VIEW_END_MS2);
26051
26213
  return { ok: false, message: WENT_ON };
26052
26214
  }
26053
- view2 = opened;
26215
+ view2 = opened2;
26054
26216
  return {
26055
26217
  ok: true,
26056
- message: opened.screencast ? "The live view is on." : "The live view is on, as images of the page twice a second: the page's screencast is in use."
26218
+ message: opened2.screencast ? "The live view is on." : "The live view is on, as images of the page twice a second: the page's screencast is in use."
26057
26219
  };
26058
26220
  })().finally(() => {
26059
26221
  if (viewStarting?.started === started) viewStarting = null;
@@ -26074,8 +26236,8 @@ async function openView2(page, stop2) {
26074
26236
  if (ours(at)) tellHub({ type: "frame", stop: stop2, refused: why ?? TOO_HEAVY2 });
26075
26237
  }
26076
26238
  });
26077
- const opened = await subscription.ready();
26078
- if (!opened) {
26239
+ const opened2 = await subscription.ready();
26240
+ if (!opened2) {
26079
26241
  await subscription.close();
26080
26242
  return null;
26081
26243
  }
@@ -26085,7 +26247,7 @@ async function openView2(page, stop2) {
26085
26247
  page.once("close", onClose);
26086
26248
  return {
26087
26249
  stop: stop2,
26088
- screencast: opened.screencast,
26250
+ screencast: opened2.screencast,
26089
26251
  resend: subscription.resend,
26090
26252
  close: async () => {
26091
26253
  page.off("close", onClose);
@@ -26256,6 +26418,10 @@ function onMessage(message) {
26256
26418
  eventRate = new RateWindow(MAX_RUN_EVENT_RATE);
26257
26419
  droppedEvents = 0;
26258
26420
  return;
26421
+ case "positions":
26422
+ positionsOn = message.on;
26423
+ if (!message.on) dropPendingPosition();
26424
+ return;
26259
26425
  case "layers": {
26260
26426
  const before = layersAsked;
26261
26427
  layersAsked = new Set(message.layers);
@@ -26510,7 +26676,7 @@ function callPlace(frames, cwd = process.cwd(), windows = process.platform === "
26510
26676
  function callTitle(zone, channel) {
26511
26677
  const selector = typeof channel?.params?.selector === "string" ? ` ${channel.params.selector}` : "";
26512
26678
  const title = zone.title || `${zone.apiName || "call"}${selector}`;
26513
- return hideSecretsInText(hideTypedText(title)).slice(0, 300);
26679
+ return hideSecretsInText(hideTypedText(title)).slice(0, MAX_POSITION_TITLE);
26514
26680
  }
26515
26681
  function errorText(error) {
26516
26682
  const message = error instanceof Error ? error.message : String(error);
@@ -26524,6 +26690,10 @@ function watchCalls(playwright) {
26524
26690
  const titles = /* @__PURE__ */ new WeakMap();
26525
26691
  instrumentation.addListener({
26526
26692
  onApiCallBegin: (zone, channel) => {
26693
+ if (positionsWanted()) {
26694
+ const place = callPlace(zone.frames);
26695
+ if (place) tellPosition(callTitle(zone, channel), place);
26696
+ }
26527
26697
  if (!runEventsWanted()) return;
26528
26698
  begun.set(zone, Date.now());
26529
26699
  titles.set(zone, callTitle(zone, channel));
@@ -27306,7 +27476,7 @@ function readPageInteraction() {
27306
27476
  const doc = globalThis.document;
27307
27477
  const SKIPPED_TEXT = ["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"];
27308
27478
  const pathOf = (el) => {
27309
- const levels = [];
27479
+ const levels2 = [];
27310
27480
  for (let node = el; node; ) {
27311
27481
  const steps = [];
27312
27482
  let root = null;
@@ -27318,10 +27488,10 @@ function readPageInteraction() {
27318
27488
  steps.unshift(`${cur.localName}:${position}`);
27319
27489
  if (!cur.parentElement) root = cur.parentNode;
27320
27490
  }
27321
- levels.unshift(steps.join("/"));
27491
+ levels2.unshift(steps.join("/"));
27322
27492
  node = root && root.host ? root.host : null;
27323
27493
  }
27324
- return levels.join("|");
27494
+ return levels2.join("|");
27325
27495
  };
27326
27496
  const isField = (el) => /^(input|textarea|select)$/.test(el.localName) || !!el.isContentEditable;
27327
27497
  const label = (el) => {
@@ -29076,7 +29246,7 @@ function instrumentPage(page) {
29076
29246
  laneSawPage(page);
29077
29247
  const probeSink = currentSink;
29078
29248
  if (probeSink?.probeItem && !probeSink.probeInterception) {
29079
- void installProbeInterception(page, probeSink.probeItem).then((interception) => {
29249
+ void installProbeInterception(page, probeSink.probeItem, probeSink.baseURL).then((interception) => {
29080
29250
  probeSink.probeInterception = interception;
29081
29251
  }).catch(() => {
29082
29252
  });
@@ -29772,13 +29942,16 @@ var piwiFixtures = {
29772
29942
  observeApiRequests(playwright, apiCallRecorder);
29773
29943
  openLiveView(workerInfo);
29774
29944
  if (liveViewOpen()) trackCalls(playwright);
29775
- if (await openRunChannel(workerInfo, runControl)) {
29945
+ const channel = await openRunChannel(workerInfo, runControl);
29946
+ if (channel) {
29776
29947
  watchCalls(playwright);
29777
29948
  trackCalls(playwright);
29778
29949
  }
29950
+ const unhearCallPages = liveViewOpen() || channel ? onTestCallPage((page) => laneCalled(page)) : () => void 0;
29779
29951
  try {
29780
29952
  await use();
29781
29953
  } finally {
29954
+ unhearCallPages();
29782
29955
  closeLiveView();
29783
29956
  closeRunChannel();
29784
29957
  stopResourceLedger();
@@ -29807,7 +29980,6 @@ var piwiFixtures = {
29807
29980
  await awaitFlakeConditions();
29808
29981
  await maybeStartCodeReach(page);
29809
29982
  lanePage(page);
29810
- liveViewPage(page);
29811
29983
  await use(page);
29812
29984
  const sink = currentSink;
29813
29985
  if (sink) await holdFailure(sink, page);