@abide/harness 0.3.2 → 0.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abide/harness",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "Ratios against hand-written code, counts of the work an op did, and gates whose revert can be run — three measurement lanes for anything that renders, on bun",
6
6
  "license": "MIT",
@@ -50,15 +50,14 @@
50
50
  "./package.json": "./package.json"
51
51
  },
52
52
  "scripts": {
53
- "typecheck": "bun check",
54
- "build:injectable": "bun scripts/buildInjectable.ts"
53
+ "typecheck": "bun check"
55
54
  },
56
55
  "dependencies": {
57
- "@happy-dom/global-registrator": "^20.14.6"
56
+ "@happy-dom/global-registrator": "^21.0.4"
58
57
  },
59
58
  "peerDependencies": {
60
59
  "@playwright/test": "^1.64.0",
61
- "@abide/abide": ">=0.125.0"
60
+ "@abide/abide": ">=0.127.0"
62
61
  },
63
62
  "peerDependenciesMeta": {
64
63
  "@playwright/test": {
@@ -1,27 +1,24 @@
1
- // Builds the measure lane into ONE file the browser arm is injected with. The bytes
1
+ // Builds the measure lane into ONE IIFE the browser arm is injected with. The bytes
2
2
  // playwright injects and the bytes `bun test` imports have to be the same code, or
3
3
  // the lane's one claim — the only lane in both substrates — is a claim about two
4
4
  // different instruments.
5
5
  //
6
- // `bun scripts/buildInjectable.ts` prints the path; a spec injects that file with
7
- // `addInitScript` and reads `__HARNESS_MEASURE__` off the page.
6
+ // A spec injects the source with `addInitScript({ content })` and reads
7
+ // `__HARNESS_MEASURE__` off the page. Built in memory rather than into `dist/`: every
8
+ // spec loads in both engine projects at once, and two workers writing one file is a
9
+ // reader that can catch it half-written.
8
10
 
9
11
  const ENTRY = new URL('../src/measure/injectable.ts', import.meta.url).pathname
10
- const OUT_DIR = new URL('../dist/', import.meta.url).pathname
11
12
 
12
- /** Builds the measure lane's injectable into `dist/measure.js` and returns its path. */
13
+ /** Builds the measure lane's injectable and returns its source. */
13
14
  export async function buildInjectable(): Promise<string> {
14
15
  const built = await Bun.build({
15
16
  entrypoints: [ENTRY],
16
- outdir: OUT_DIR,
17
- naming: 'measure.js',
18
17
  format: 'iife',
19
18
  target: 'browser',
20
19
  minify: false,
21
20
  })
22
21
  if (!built.success)
23
22
  throw new AggregateError(built.logs, 'measure did not build')
24
- return `${OUT_DIR}measure.js`
23
+ return (built.outputs[0] as Blob).text()
25
24
  }
26
-
27
- if (import.meta.main) console.log(await buildInjectable())
@@ -3,9 +3,6 @@
3
3
  // Read over CDP, so chromium only, and driven from the playwright side — an engine
4
4
  // number is not available inside a case body, and that is a property of the lane
5
5
  // rather than a gap.
6
- //
7
- // `harness/report` is a FOURTH entry and is not a fourth lane: a lane is a DEPENDENCY
8
- // partition, and the leaf depends on nothing.
9
6
 
10
7
  export {
11
8
  durationOf,
@@ -47,11 +47,8 @@ export type Shares = {
47
47
  }
48
48
 
49
49
  /** Every measure in the trace with this name, in trace order. */
50
- export function measuresNamed(
51
- trace: Trace,
52
- name: string,
53
- ): { startNanoseconds: number; endNanoseconds: number }[] {
54
- const found: { startNanoseconds: number; endNanoseconds: number }[] = []
50
+ export function measuresNamed(trace: Trace, name: string): Trace['measures'] {
51
+ const found: Trace['measures'] = []
55
52
  for (const measure of trace.measures)
56
53
  if (measure.name === name) found.push(measure)
57
54
  return found
@@ -78,22 +75,13 @@ export function durationOf(trace: Trace, name: string): number {
78
75
  /**
79
76
  * The fraction of one op a named layer took, with the op as the stated denominator.
80
77
  *
81
- * Throws on a withdrawn `within`, a denominator that is not exactly one measure, a missing
78
+ * Throws on a denominator that is not exactly one measure, a missing
82
79
  * layer, a layer running outside the op, or an op of zero length.
83
80
  */
84
81
  export function shares(trace: Trace, spec: SharesSpec): Shares {
85
- // `within` is WITHDRAWN, and it is refused rather than ignored. It was there to
86
- // compose — a fraction of click -> paint times a fraction of navigation -> paint
87
- // — but the reconcile does not run inside navigation -> paint; hydration does.
88
- // Multiplying a fraction of an INTERACTION op by a fraction of a FIRST-LOAD op
89
- // produces a number describing no op at all, and the two chains never meet.
90
- if ('within' in spec)
91
- throw new Error(
92
- `shares("${spec.of}") was given a \`within\`. Composition is sound down ONE nesting chain, and first load and interaction are two: a first-load ceiling and an interaction ceiling are separate numbers, and neither bounds the other.`,
93
- )
94
-
95
82
  const denominators = measuresNamed(trace, spec.of)
96
- if (denominators.length !== 1)
83
+ const [op] = denominators
84
+ if (op === undefined || denominators.length !== 1)
97
85
  throw new Error(
98
86
  `shares("${spec.of}") found ${denominators.length} measures named "${spec.of}" in the trace of "${trace.op}". The denominator is one op somebody waits on.`,
99
87
  )
@@ -103,12 +91,7 @@ export function shares(trace: Trace, spec: SharesSpec): Shares {
103
91
  `shares("${spec.of}") found no measure named "${spec.layer}". The code under test emits the marks; the sampler at ~1 ms cannot resolve a layer inside a 1.45 ms op.`,
104
92
  )
105
93
 
106
- const op = denominators[0] as {
107
- startNanoseconds: number
108
- endNanoseconds: number
109
- }
110
- // CONTAINMENT IS CHECKED, not assumed — the assumption the withdrawn `within`
111
- // violated silently. A layer that also runs OUTSIDE the op — a second flush, an
94
+ // CONTAINMENT IS CHECKED, not assumed. A layer that also runs OUTSIDE the op — a second flush, an
112
95
  // idle pass — is a throw, not a smaller fraction.
113
96
  let layerNanoseconds = 0
114
97
  for (const run of numerators) {
@@ -119,15 +119,15 @@ async function traced(
119
119
  })),
120
120
  )
121
121
 
122
- const since = (name: string): number =>
123
- ((after[name] ?? 0) - (before[name] ?? 0)) * 1e9
122
+ const delta = (name: string): number =>
123
+ (after[name] ?? 0) - (before[name] ?? 0)
124
+ const since = (name: string): number => delta(name) * 1e9
124
125
  return {
125
126
  op,
126
127
  measures,
127
128
  counters: {
128
- recalcStyle:
129
- (after.RecalcStyleCount ?? 0) - (before.RecalcStyleCount ?? 0),
130
- layout: (after.LayoutCount ?? 0) - (before.LayoutCount ?? 0),
129
+ recalcStyle: delta('RecalcStyleCount'),
130
+ layout: delta('LayoutCount'),
131
131
  paint,
132
132
  forcedLayout,
133
133
  },
@@ -11,11 +11,10 @@ const DEFAULT_TIMEOUT_MILLISECONDS = 30_000
11
11
  * all under `--parallel`. So a gate on either refusal cannot be taken in the suite that states
12
12
  * it: it is taken in a child.
13
13
  *
14
- * PART OF THE VOCABULARY RATHER THAN OF THIS PACKAGE'S TESTS, which is where it started and where
15
- * it could not do its job. Every allocation gate in the framework needs this same preload-free
16
- * invocation, and a helper sitting in `packages/harness/tests/` is one `packages/abide/tests/` can
17
- * only reach by copying. It belongs beside `gate()` for the same reason `gate()` is a fifth
18
- * entry: both need `bun:test`, and neither is a lane.
14
+ * PART OF THE VOCABULARY RATHER THAN OF THIS PACKAGE'S TESTS: a gate needing this same
15
+ * preload-free invocation in another package could only reach a helper sitting in
16
+ * `packages/harness/tests/` by copying it. It sits beside `gate()` because both need `bun:test`,
17
+ * and neither is a lane.
19
18
  *
20
19
  * It is also the only place a HANG can be gated. `bun test`'s own per-test timeout is a timer, so
21
20
  * a body that starves the event loop outruns it and the suite reports nothing at all — no failed
package/src/gate/index.ts CHANGED
@@ -49,8 +49,8 @@ export type GateSpec = {
49
49
  worth: Record<string, number | string>
50
50
  }
51
51
 
52
- // The reverts double the gate count and some are not cheap, so they are opt-in.
53
- // Whether that becomes a nightly rather than a flag is not decided here.
52
+ // The reverts double the gate count and some are not cheap, so they are opt-in:
53
+ // `bun run test:gates` sets `HARNESS_VERIFY_GATES`.
54
54
  const VERIFYING = process.env.HARNESS_VERIFY_GATES === '1'
55
55
 
56
56
  /**
@@ -3,9 +3,6 @@
3
3
  // is what lets a hand-written arm and the arm under test share one clock and one
4
4
  // batch size. This lane has nothing under test in its import graph, and that is
5
5
  // the whole reason the harness is a package of its own.
6
- //
7
- // `harness/report` is a FOURTH entry and is not a fourth lane: a lane is a DEPENDENCY
8
- // partition, and the leaf depends on nothing.
9
6
 
10
7
  import { batch, type Batched, type BatchSpec } from '../report/batch.ts'
11
8
  import { emulatedDom, underBun } from '../report/environment.ts'
@@ -30,10 +30,9 @@
30
30
  import type { Work } from './Work.ts'
31
31
 
32
32
  type Role =
33
- | 'insertArgs'
33
+ | 'eachArg'
34
34
  | 'insertFirstArg'
35
35
  | 'insertSecondArg'
36
- | 'removeArgs'
37
36
  | 'removeReceiver'
38
37
  | 'replaceChild'
39
38
  | 'replaceReceiver'
@@ -55,31 +54,31 @@ type Role =
55
54
  // both-substrates gate compares the two.
56
55
  const DECLARED: [interfaceName: string, member: string, role: Role][] = [
57
56
  ['Node', 'insertBefore', 'insertFirstArg'],
58
- ['Node', 'appendChild', 'insertArgs'],
59
- ['Node', 'removeChild', 'removeArgs'],
57
+ ['Node', 'appendChild', 'eachArg'],
58
+ ['Node', 'removeChild', 'eachArg'],
60
59
  ['Node', 'replaceChild', 'replaceChild'],
61
60
  ['Node', 'cloneNode', 'clone'],
62
61
  ['Node', 'textContent', 'textContent'],
63
62
  ['Element', 'textContent', 'textContent'],
64
63
  ['CharacterData', 'textContent', 'textContent'],
65
64
  ['Element', 'remove', 'removeReceiver'],
66
- ['Element', 'before', 'insertArgs'],
67
- ['Element', 'after', 'insertArgs'],
65
+ ['Element', 'before', 'eachArg'],
66
+ ['Element', 'after', 'eachArg'],
68
67
  ['Element', 'replaceWith', 'replaceReceiver'],
69
68
  ['CharacterData', 'remove', 'removeReceiver'],
70
- ['CharacterData', 'before', 'insertArgs'],
71
- ['CharacterData', 'after', 'insertArgs'],
69
+ ['CharacterData', 'before', 'eachArg'],
70
+ ['CharacterData', 'after', 'eachArg'],
72
71
  ['CharacterData', 'replaceWith', 'replaceReceiver'],
73
- ['Element', 'append', 'insertArgs'],
74
- ['Element', 'prepend', 'insertArgs'],
72
+ ['Element', 'append', 'eachArg'],
73
+ ['Element', 'prepend', 'eachArg'],
75
74
  ['Element', 'replaceChildren', 'replaceChildren'],
76
75
  // A KEYED REORDER IN CHROMIUM IS THIS CALL (`moveNode`), so leaving it off read
77
76
  // every reorder there as 0 moves. One node moves, as with `insertBefore`.
78
77
  ['Element', 'moveBefore', 'insertFirstArg'],
79
78
  ['Document', 'moveBefore', 'insertFirstArg'],
80
79
  ['DocumentFragment', 'moveBefore', 'insertFirstArg'],
81
- ['Document', 'append', 'insertArgs'],
82
- ['Document', 'prepend', 'insertArgs'],
80
+ ['Document', 'append', 'eachArg'],
81
+ ['Document', 'prepend', 'eachArg'],
83
82
  ['Document', 'replaceChildren', 'replaceChildren'],
84
83
  ['Element', 'setAttribute', 'attribute'],
85
84
  ['Element', 'setAttributeNS', 'attribute'],
@@ -204,6 +203,12 @@ const TEXT_NODE = 3
204
203
  const COMMENT_NODE = 8
205
204
  const DOCUMENT_FRAGMENT_NODE = 11
206
205
 
206
+ /** A write to a text node's or a comment's data, and whether it wrote what was already there. */
207
+ function tallyDataWrite(receiver: CharacterData, value: unknown): void {
208
+ live.dataWrites += 1
209
+ if (receiver.data === String(value)) live.redundantDataWrites += 1
210
+ }
211
+
207
212
  function tallyNode(node: unknown): void {
208
213
  if (typeof node === 'string') {
209
214
  // A string handed to `append` becomes a text node the call created.
@@ -280,7 +285,7 @@ function tallyBefore(
280
285
  member: string,
281
286
  ): void {
282
287
  switch (role) {
283
- case 'insertArgs':
288
+ case 'eachArg':
284
289
  for (const argument of args) tallyNode(argument)
285
290
  return
286
291
  case 'insertFirstArg':
@@ -291,9 +296,6 @@ function tallyBefore(
291
296
  case 'insertSecondArg':
292
297
  tallyNode(args[1])
293
298
  return
294
- case 'removeArgs':
295
- for (const argument of args) tallyNode(argument)
296
- return
297
299
  case 'removeReceiver':
298
300
  tallyNode(receiver)
299
301
  return
@@ -325,19 +327,14 @@ function tallyBefore(
325
327
  case 'styleObject':
326
328
  // Counted by the proxy the getter hands back, not here.
327
329
  return
328
- case 'data': {
329
- live.dataWrites += 1
330
- if ((receiver as CharacterData).data === String(args[0]))
331
- live.redundantDataWrites += 1
330
+ case 'data':
331
+ tallyDataWrite(receiver as CharacterData, args[0])
332
332
  return
333
- }
334
333
  case 'textContent': {
335
334
  // On a text node or a comment this IS a data write, and counting it as a
336
335
  // subtree replacement would report a creation that never happened.
337
336
  if (isCharacterData(receiver)) {
338
- live.dataWrites += 1
339
- if ((receiver as CharacterData).data === String(args[0]))
340
- live.redundantDataWrites += 1
337
+ tallyDataWrite(receiver as CharacterData, args[0])
341
338
  return
342
339
  }
343
340
  tallyChildren(receiver)
@@ -1,4 +1,4 @@
1
- // A CASE IS ARMED AND DISARMED, and `measure()` is those two around a body.
1
+ // A CASE IS ARMED AND DISARMED around a body, with the published counters zeroed before and copied after.
2
2
 
3
3
  import { arm, blankWork, disarm } from './install.ts'
4
4
  import { PUBLISHED_WORK_KEY, type PublishedWork } from './PUBLISHED_WORK.ts'
@@ -18,17 +18,14 @@ function sources(): PublishedWork | null {
18
18
  return record as PublishedWork
19
19
  }
20
20
 
21
- let openCase: Work | null = null
22
-
23
21
  /**
24
- * Opens a case: starts counting DOM calls and zeroes every published counter.
22
+ * Zeroes every published counter as a case opens.
25
23
  *
26
24
  * ONLY A FIELD THAT IS THERE AND IS A NUMBER IS ZEROED. Writing a field the source never declared
27
25
  * would create it at 0 and read it back at 0, and every gate asserting it would pass against a
28
26
  * counter nothing increments — so a missing field stays missing, and `publishedBy` names it.
29
27
  */
30
- function armCase(): void {
31
- const record = blankWork()
28
+ function zeroPublished(): void {
32
29
  const published = sources()
33
30
  if (published)
34
31
  for (const source in published) {
@@ -36,16 +33,10 @@ function armCase(): void {
36
33
  for (const field in counters)
37
34
  if (typeof counters[field] === 'number') counters[field] = 0
38
35
  }
39
- openCase = record
40
- arm(record)
41
36
  }
42
37
 
43
- /** Closes the open case and returns its `Work`, with every published source copied in. */
44
- function disarmCase(): Work {
45
- const record = openCase
46
- if (!record) throw new Error('disarmCase() was called with no case armed.')
47
- disarm()
48
- openCase = null
38
+ /** Copies every published source's numbers into `record` as its case closes. */
39
+ function copyPublished(record: Work): void {
49
40
  const published = sources()
50
41
  if (published) {
51
42
  const copied: PublishedWork = {}
@@ -60,21 +51,22 @@ function disarmCase(): Work {
60
51
  }
61
52
  record.published = copied
62
53
  }
63
- return record
64
54
  }
65
55
 
66
56
  /** Runs `body` inside an armed case and returns the `Work` it did. */
67
57
  export function measure(body: () => void): Work {
68
- armCase()
58
+ const record = blankWork()
59
+ zeroPublished()
60
+ arm(record)
61
+ // The case is closed before a throw leaves, or the next `measure()` reports that one is
62
+ // already armed and the real failure is two frames down.
69
63
  try {
70
64
  body()
71
- } catch (error) {
72
- // The case is closed before the throw leaves, or the next `measure()` reports
73
- // that one is already armed and the real failure is two frames down.
74
- disarmCase()
75
- throw error
65
+ } finally {
66
+ disarm()
76
67
  }
77
- return disarmCase()
68
+ copyPublished(record)
69
+ return record
78
70
  }
79
71
 
80
72
  /**
@@ -1,12 +1,6 @@
1
1
  // Registers a DOM as globals for `bun test`, and installs the measure lane's patches
2
2
  // beside it. Wired from the root bunfig.toml, so it runs once per test process and
3
- // before any suite imports.
4
- //
5
- // The patches land HERE rather than around a case body. Removing them per case cannot
6
- // be done in the browser arm at all — `addInitScript` runs at document-start and has
7
- // no removal hook — and re-patching per case invalidates the inline caches on those
8
- // members once per case, for the process. `arm()`/`disarm()` swap the record instead,
9
- // so the prototype shape is fixed for the process lifetime.
3
+ // before any suite imports. Why the patches land once rather than per case: install.ts.
10
4
  import { GlobalRegistrator } from '@happy-dom/global-registrator'
11
5
 
12
6
  import { install } from './install.ts'
@@ -39,13 +33,12 @@ const native: Record<string, unknown> = {}
39
33
  for (const name of WIRE) native[name] = globalThis[name]
40
34
  // 43.35 — a document a test parses names its stylesheets and scripts, and a DOM that fetched them
41
35
  // would fetch them from a host nothing answers, in whichever test file happened to parse one.
36
+ // happy-dom fetches neither unless told to — a stylesheet needs `enableCSSFileLoading`, a script
37
+ // `enableJavaScriptEvaluation` — so what is set here is that a load it skipped fires `load`, as a
38
+ // fetched one would, rather than `error` and a logged `NotSupportedError`.
42
39
  GlobalRegistrator.register({
43
40
  url: 'http://localhost/',
44
- settings: {
45
- disableCSSFileLoading: true,
46
- disableJavaScriptFileLoading: true,
47
- handleDisabledFileLoadingAsSuccess: true,
48
- },
41
+ settings: { handleDisabledFileLoadingAsSuccess: true },
49
42
  })
50
43
  for (const name of WIRE) Object.assign(globalThis, { [name]: native[name] })
51
44
  install()
@@ -24,7 +24,7 @@ const MIN_CLOCK_MULTIPLE = 100
24
24
  // CLEARING THE CLOCK IS NOT THE SAME AS BEING WARM, and the bar only knows about the
25
25
  // clock. Bun's is ~41 ns, so the bar is ~4 µs a sample and a 40 ns op clears it at
26
26
  // n in the hundreds — which is below where JSC promotes the body out of its baseline
27
- // tier. Measured on one publish into a capped ring (a case since removed with the ring): 85.5 ns a call at n=488 and 4.4 at
27
+ // tier. Measured on one publish into a capped ring: 85.5 ns a call at n=488 and 4.4 at
28
28
  // n=2,000,000, the SAME code, a 19x spread chosen by the sample size.
29
29
  //
30
30
  // IT IS NOT A UNIFORM BIAS, so it cannot be divided out. Swept across n, a write with one
@@ -75,7 +75,7 @@ export type Batched = {
75
75
  n: number
76
76
  reps: number
77
77
  warmup: number
78
- substrate: ReturnType<typeof substrate>
78
+ substrate: Sample['substrate']
79
79
  /**
80
80
  * |control ratio − 1|.
81
81
  *
@@ -207,21 +207,18 @@ export function batch(spec: BatchSpec): Batched {
207
207
  const reps = spec.reps ?? DEFAULT_REPS
208
208
  const warmup = spec.warmup ?? DEFAULT_WARMUP
209
209
 
210
- // GROW UNTIL THE SAMPLE CLEARS THE BAR, and the growth probe is the run itself.
211
- // A probe taken BEFORE the warm-up reps grows against cold code and then the
212
- // timed reps come in under the bar anyway — measured: an arm that needed n=512
213
- // cold reported 1208 ns warm, a third of the bar, and the batcher would have
214
- // thrown on a sample size it had chosen itself.
215
- // A CHEAP PROBE FINDS THE STARTING n, and the full run is what proves it. Growing
216
- // by rerunning warm-up and every rep at each step costs the whole rep set once
217
- // per doubling — it is what made the browser case unfinishable — and growing off
218
- // a COLD probe alone undershoots, because the timed reps come back faster than
219
- // the probe that chose n. So: probe cheaply, run fully, and grow again if the run
220
- // misses the bar.
221
210
  // BEFORE THE GROWTH PROBE, so the probe chooses n against warm code too — a probe
222
- // taken cold picks an n the warm run then comes in under.
211
+ // taken cold picks an n the warm run then comes in under. Measured: an arm that
212
+ // needed n=512 cold reported 1208 ns warm, a third of the bar, and the batcher
213
+ // would have thrown on a sample size it had chosen itself.
223
214
  for (const lane of lanes) warm(lane.body)
224
215
 
216
+ // GROW UNTIL THE SAMPLE CLEARS THE BAR: a CHEAP PROBE FINDS THE STARTING n, and
217
+ // the full run is what proves it. Growing by rerunning warm-up and every rep at
218
+ // each step costs the whole rep set once per doubling — it is what made the
219
+ // browser case unfinishable — and growing off a probe alone undershoots, because
220
+ // the timed reps come back faster than the probe that chose n. So: probe cheaply,
221
+ // run fully, and grow again if the run misses the bar.
225
222
  let n = spec.n ?? 1
226
223
  if (spec.n === undefined) {
227
224
  while (n < MAX_N) {
@@ -1,14 +1,8 @@
1
1
  // NOT A LANE. All three lanes need every name in here, in both
2
2
  // substrates, and they ship into the browser injectable — so a lane is a DEPENDENCY
3
3
  // partition and this depends on nothing, which makes it a leaf rather than a fourth
4
- // question.
5
- //
6
- // What is NOT here: the LOC counter and the `example.json` writer. Both run once, on
7
- // bun, from a script, and both touch the filesystem — a `Bun.Glob` parked here would
8
- // make the leaf bun-only, contradicting the one property it is justified by, and an
9
- // import edge is priced by the module it lands on, so `measure` reaching for a clock
10
- // would drag a glob into the module the injectable is built from. They live in
11
- // `bun run bench`.
4
+ // question. Nothing here touches the filesystem: a `Bun.Glob` parked here would make the
5
+ // leaf bun-only, contradicting the one property it is justified by.
12
6
 
13
7
  export { type Batched, type BatchSpec, batch } from './batch.ts'
14
8
  export { emulatedDom } from './environment.ts'
@@ -1,4 +1,5 @@
1
1
  import { underBun } from './environment.ts'
2
+ import type { Sample } from './Sample.ts'
2
3
 
3
4
  /**
4
5
  * Which JS engine this is, read off the user agent rather than probed.
@@ -14,7 +15,7 @@ import { underBun } from './environment.ts'
14
15
  * panel that measures in the reader's own browser meets all three engines. Reporting `v8` for
15
16
  * Safari would let `ratio()` compare two of them.
16
17
  */
17
- export function substrate(): 'jsc' | 'v8' | 'spidermonkey' | 'unknown' {
18
+ export function substrate(): Sample['substrate'] {
18
19
  // Bun IS JSC, and it is the one case with no user agent worth reading.
19
20
  if (underBun()) return 'jsc'
20
21
  const agent = globalThis.navigator?.userAgent ?? ''
package/src/rows/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- // WHAT THE BENCH AND TESTS PAGES READ, AND WHAT THE TWO RUNNERS WRITE. Both runners are
2
- // subprocesses printing one JSON row per line; the docs app pipes those lines to the page without
3
- // reading them, so this module is the whole of the contract between the two packages.
1
+ // WHAT A ROW RUNNER WRITES AND A PAGE READS. A runner is a subprocess printing one JSON row per
2
+ // line; the docs app pipes those lines to the page without reading them, so this module is the
3
+ // whole of the contract between the two packages.
4
4
  //
5
5
  // PURE, AND IMPORTED BY THE PAGE: the filter a reader types and the filter the runner applies are
6
6
  // this one function, so "run what I can see" runs exactly the rows on screen.
@@ -10,27 +10,11 @@ export type RowItem = { id: string; section: string; name: string }
10
10
  /**
11
11
  * Where a row is in its run.
12
12
  *
13
- * `broken` is the RUNNER failing — no report, a thrown bench — and is not a red result.
13
+ * `broken` is the RUNNER failing — no report, or a suite stopped at its deadline (43.27) — and is
14
+ * not a red result.
14
15
  */
15
16
  export type RowState = 'queued' | 'running' | 'done' | 'broken'
16
17
 
17
- export type BenchRow = {
18
- id: string
19
- state: RowState
20
- unit: string
21
- /** The code under measurement's figure, in `unit`. */
22
- subject: number | null
23
- /** The hand-written arm's figure, in `unit`. */
24
- handWritten: number | null
25
- /** subject / handWritten as the lane is allowed to say it: a number, or why there is none. */
26
- claim: string
27
- /** The operations batched into one sample — `null` for a row that counts rather than times. */
28
- n: number | null
29
- /** The A/A floor as a fraction — `null` for a row that counts rather than times. */
30
- floor: number | null
31
- note: string
32
- }
33
-
34
18
  export type TestRow = {
35
19
  id: string
36
20
  state: RowState
@@ -55,18 +39,6 @@ export type TestCase = {
55
39
  failure: string | null
56
40
  }
57
41
 
58
- /**
59
- * The line the docs app writes after the rows it did send when a runner died part way.
60
- *
61
- * A stream whose head has gone out cannot fail with a status, and cut off it reads as a network
62
- * error that says nothing of the runner's own.
63
- */
64
- export type RunnerFailure = { failure: string }
65
-
66
- export function isRunnerFailure(line: object): line is RunnerFailure {
67
- return typeof (line as { failure?: unknown }).failure === 'string'
68
- }
69
-
70
42
  /**
71
43
  * Whether `item` falls in `scope`: `all`, `section:<name>`, `item:<id>`, or nothing at all.
72
44
  *
@@ -3,7 +3,7 @@
3
3
  // block each, and exit 1 after listing every arm over its ceiling and every ceiling naming no arm
4
4
  // or no bench.
5
5
 
6
- import { runBenches } from './runBenches.ts'
6
+ import { milliseconds, runBenches } from './runBenches.ts'
7
7
 
8
8
  const over: string[] = []
9
9
  for (const bench of await runBenches(process.cwd(), process.argv[2])) {
@@ -13,7 +13,7 @@ for (const bench of await runBenches(process.cwd(), process.argv[2])) {
13
13
  if (bench.case === '') continue
14
14
  let times = ''
15
15
  for (const [arm, nanoseconds] of Object.entries(bench.arms))
16
- times += `${times === '' ? '' : ' · '}${arm} ${(nanoseconds / 1e6).toFixed(3)} ms`
16
+ times += `${times === '' ? '' : ' · '}${arm} ${milliseconds(nanoseconds)}`
17
17
  console.log(
18
18
  `${bench.file} ${bench.name}: ${bench.case}\n ${times}\n ${bench.claim}`,
19
19
  )
@@ -1,6 +1,7 @@
1
1
  import { type Batched, claimOf, ratio } from '../report/index.ts'
2
2
 
3
- const milliseconds = (nanoseconds: number) =>
3
+ /** `nanoseconds` as the milliseconds a bench line prints. */
4
+ export const milliseconds = (nanoseconds: number) =>
4
5
  `${(nanoseconds / 1e6).toFixed(3)} ms`
5
6
 
6
7
  /**
@@ -8,7 +8,8 @@
8
8
  // whole job is showing what is red cannot fall over when something is. It throws only when the
9
9
  // runner produced no report at all, which is a different thing and one the page has to say out
10
10
  // loud: a suite that HANGS reports nothing, and "0 failures" read off an absent file is the worst
11
- // answer available.
11
+ // answer available. So a hung suite is STOPPED at a deadline rather than waited on — its row would
12
+ // otherwise read "running" for as long as the page stays open (RULEBOOK 43.27).
12
13
 
13
14
  import { tmpdir } from 'node:os' // bun has no temporary-directory lookup of its own
14
15
 
@@ -30,6 +31,19 @@ import type { TestCase } from '../rows/index.ts'
30
31
  // INSTALLED WITH THE FIRST SUITE rather than on import: a process that only reads this module's
31
32
  // parser has no suite to pass a signal on to, and is not this module's to exit.
32
33
  const LIVE = new Set<Bun.Subprocess>()
34
+
35
+ // Several times the slowest file on record — a docs spec across both of its projects, ~1.2 min.
36
+ const SUITE_DEADLINE_MILLISECONDS = 10 * 60_000
37
+ // What a suite gets to tear down its own servers after SIGINT before its group is killed outright.
38
+ const TEARDOWN_MILLISECONDS = 10_000
39
+
40
+ function signalGroup(child: Bun.Subprocess, signal: NodeJS.Signals): void {
41
+ try {
42
+ process.kill(-child.pid, signal)
43
+ } catch {
44
+ // The group emptied between its suite ending and this signal.
45
+ }
46
+ }
33
47
  let passingSignals = false
34
48
  function passSignalsOn(): void {
35
49
  if (passingSignals) return
@@ -39,13 +53,7 @@ function passSignalsOn(): void {
39
53
  ['SIGINT', 130],
40
54
  ] as const)
41
55
  process.on(signal, () => {
42
- for (const child of LIVE) {
43
- try {
44
- process.kill(-child.pid, 'SIGINT')
45
- } catch {
46
- // The group emptied between its suite ending and this signal.
47
- }
48
- }
56
+ for (const child of LIVE) signalGroup(child, 'SIGINT')
49
57
  process.exit(code)
50
58
  })
51
59
  }
@@ -141,18 +149,23 @@ export const PLAYWRIGHT_REPORT: ReportTo = (path) => ({
141
149
  /**
142
150
  * Runs one test command with a JUnit reporter and returns its parsed suites and wall time.
143
151
  *
144
- * A red run resolves; only a missing report throws — see the file header.
152
+ * A red run resolves; a missing report throws, and so does a run past `deadline` — see the file
153
+ * header.
145
154
  */
146
155
  export async function runSuite(spec: {
147
156
  command: string[]
148
157
  reportTo: ReportTo
149
158
  cwd: string
150
159
  environment?: Record<string, string>
160
+ deadline?: number
151
161
  }): Promise<{ suites: Suite[]; milliseconds: number }> {
162
+ const deadline = spec.deadline ?? SUITE_DEADLINE_MILLISECONDS
152
163
  const report = `${tmpdir()}/abide-suite-${crypto.randomUUID()}.xml`
153
164
  const pointed = spec.reportTo(report)
154
165
  passSignalsOn()
155
166
  const startedAt = Bun.nanoseconds()
167
+ // Not `spawned`: a suite leads a detached group, and a deadline signals that whole group
168
+ // SIGINT then SIGKILL — the teardown playwright's `webServer` needs — where `spawned` kills one pid.
156
169
  const child = Bun.spawn({
157
170
  cmd: [...spec.command, ...pointed.args],
158
171
  cwd: spec.cwd,
@@ -162,12 +175,28 @@ export async function runSuite(spec: {
162
175
  detached: true,
163
176
  })
164
177
  LIVE.add(child)
178
+ let pastDeadline = false
179
+ let killing: Timer | undefined
180
+ const stopping = setTimeout(() => {
181
+ pastDeadline = true
182
+ signalGroup(child, 'SIGINT')
183
+ killing = setTimeout(
184
+ () => signalGroup(child, 'SIGKILL'),
185
+ TEARDOWN_MILLISECONDS,
186
+ )
187
+ }, deadline)
165
188
  const [stderr] = await Promise.all([
166
189
  new Response(child.stderr).text(),
167
190
  child.exited,
168
191
  ])
192
+ clearTimeout(stopping)
193
+ clearTimeout(killing)
169
194
  LIVE.delete(child)
170
195
  const milliseconds = (Bun.nanoseconds() - startedAt) / 1e6
196
+ if (pastDeadline)
197
+ throw new Error(
198
+ `the suite ran past its ${deadline} ms deadline and was stopped.\n${stderr.slice(-2000)}`,
199
+ )
171
200
 
172
201
  const file = Bun.file(report)
173
202
  if (!(await file.exists()))
@@ -1,9 +1,6 @@
1
1
  // Lane 3 of 3 — bytes, microtask turns and allocations, on bun.
2
2
  // The lane that prices what ships and what the server spends getting it there.
3
3
  //
4
- // `harness/report` is a FOURTH entry and is not a fourth lane: a lane is a DEPENDENCY
5
- // partition, and the leaf depends on nothing.
6
- //
7
4
  // There is no `calls()` here. `bun:test` already ships one —
8
5
  // `spyOn(checker, 'check').mock.calls.length` is the compiler's wave gate exactly,
9
6
  // with `mockRestore` for the teardown — and a second spelling would be a rename with