@abide/harness 0.4.0 → 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.4.0",
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.126.2"
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) {
@@ -11,10 +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. A gate needing this same preload-free invocation in another package
16
- * could only reach a helper sitting in `packages/harness/tests/` by copying it. It belongs beside `gate()` for the same reason `gate()` is a fifth
17
- * 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.
18
18
  *
19
19
  * It is also the only place a HANG can be gated. `bun test`'s own per-test timeout is a timer, so
20
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'
@@ -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
@@ -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) {
@@ -164,6 +164,8 @@ export async function runSuite(spec: {
164
164
  const pointed = spec.reportTo(report)
165
165
  passSignalsOn()
166
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.
167
169
  const child = Bun.spawn({
168
170
  cmd: [...spec.command, ...pointed.args],
169
171
  cwd: spec.cwd,
@@ -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