@abide/harness 0.6.0 → 0.7.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.6.0",
3
+ "version": "0.7.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",
@@ -30,8 +30,7 @@
30
30
  "provenance": true
31
31
  },
32
32
  "files": [
33
- "src",
34
- "scripts/buildInjectable.ts"
33
+ "src"
35
34
  ],
36
35
  "bin": {
37
36
  "harness-bench": "./src/runner/harnessBench.ts"
@@ -57,7 +56,7 @@
57
56
  },
58
57
  "peerDependencies": {
59
58
  "@playwright/test": "^1.64.0",
60
- "@abide/abide": ">=0.142.0"
59
+ "@abide/abide": ">=0.144.0"
61
60
  },
62
61
  "peerDependenciesMeta": {
63
62
  "@playwright/test": {
@@ -29,8 +29,7 @@ export type Shares = {
29
29
  /**
30
30
  * The share, which is also the CPU ceiling.
31
31
  *
32
- * An optimization is capped by the fraction of the op it touches. One number, not two — the
33
- * sketch returned the fraction twice, once as `layer` and once as `ceilingCpu`.
32
+ * An optimization is capped by the fraction of the op it touches.
34
33
  */
35
34
  ceilingCpu: number
36
35
  /**
@@ -21,7 +21,9 @@ const TRACE_CATEGORIES = [
21
21
 
22
22
  type TraceEvent = {
23
23
  name: string
24
- args?: { beginData?: { stackTrace?: unknown }; data?: unknown }
24
+ args?:
25
+ | { beginData?: { stackTrace?: unknown } | undefined; data?: unknown }
26
+ | undefined
25
27
  }
26
28
 
27
29
  type Metrics = Record<string, number>
package/src/gate/index.ts CHANGED
@@ -84,7 +84,7 @@ export function gate(
84
84
  `gate("${name}") passed with the mechanism out. A case reporting the same number either way distinguishes nothing, and this gate is worth nothing.`,
85
85
  )
86
86
  const reported = String(
87
- (failure as { message?: string }).message ?? failure,
87
+ (failure as { message?: string | undefined }).message ?? failure,
88
88
  )
89
89
  for (const [counter, value] of Object.entries(spec.worth)) {
90
90
  if (reported.includes(String(value))) continue
@@ -12,9 +12,9 @@ const DEFAULT_DEADLINE_MILLISECONDS = 60_000
12
12
  export async function spawned(
13
13
  command: string[],
14
14
  options: {
15
- cwd?: string
16
- env?: Record<string, string | undefined>
17
- deadline?: number
15
+ cwd?: string | undefined
16
+ env?: Record<string, string | undefined> | undefined
17
+ deadline?: number | undefined
18
18
  } = {},
19
19
  ): Promise<{ exitCode: number; stdout: string; stderr: string }> {
20
20
  const child = Bun.spawn(command, {
@@ -13,9 +13,11 @@ import { measure } from './measure.ts'
13
13
  install()
14
14
  ;(
15
15
  globalThis as {
16
- __HARNESS_MEASURE__?: {
17
- measure: typeof measure
18
- patchSet: typeof patchSet
19
- }
16
+ __HARNESS_MEASURE__?:
17
+ | {
18
+ measure: typeof measure
19
+ patchSet: typeof patchSet
20
+ }
21
+ | undefined
20
22
  }
21
23
  ).__HARNESS_MEASURE__ = { measure, patchSet }
@@ -428,10 +428,9 @@ function counting(
428
428
  original: AnyFunction,
429
429
  ): AnyFunction {
430
430
  return function (this: unknown, ...args: unknown[]): unknown {
431
- // Nested inside an already-counted call: the outermost one has already said
432
- // what this op did.
433
- if (depth > 0) return original.apply(this, args)
434
- if (!armed) return original.apply(this, args)
431
+ // Nested inside an already-counted call, the outermost one has already said what this
432
+ // op did.
433
+ if (depth > 0 || !armed) return original.apply(this, args)
435
434
  depth = 1
436
435
  try {
437
436
  tallyBefore(role, this, args, member)
@@ -451,8 +450,11 @@ function prototypeNamed(
451
450
  let proto: object | null = Object.getPrototypeOf(instance)
452
451
  while (proto) {
453
452
  if (
454
- (proto as { constructor?: { name?: string } }).constructor?.name ===
455
- interfaceName
453
+ (
454
+ proto as {
455
+ constructor?: { name?: string | undefined } | undefined
456
+ }
457
+ ).constructor?.name === interfaceName
456
458
  )
457
459
  return proto
458
460
  proto = Object.getPrototypeOf(proto)
@@ -62,11 +62,15 @@ const DEFAULT_BUDGET_NANOSECONDS = 2_000_000_000
62
62
  // `bun:jsc` is a specifier a browser bundler must resolve and nothing stands in for it.
63
63
  // Read by the MEMBER, so a browser — which has no `Bun` — gets `undefined` here and
64
64
  // `collectGarbage` does nothing, rather than a TypeError in the middle of a timing run.
65
- const BUN_GC = (globalThis as { Bun?: { gc?(sync: boolean): void } }).Bun?.gc
65
+ const BUN_GC = (
66
+ globalThis as { Bun?: { gc?(sync: boolean): void } | undefined }
67
+ ).Bun?.gc
66
68
 
67
69
  // `bun run test` is `--parallel`, and bun marks a worker process with this.
68
70
  const WORKER_ID = (
69
- globalThis as { process?: { env: Record<string, string | undefined> } }
71
+ globalThis as {
72
+ process?: { env: Record<string, string | undefined> } | undefined
73
+ }
70
74
  ).process?.env?.BUN_TEST_WORKER_ID
71
75
 
72
76
  /** What `batch()` returns: one `Sample` per arm, and the A/A floor they were measured against. */
@@ -108,17 +112,18 @@ export type BatchSpec = {
108
112
  * Counting and timing are mutually exclusive passes over the same body — the counter runs
109
113
  * inside the path it counts — so the work cannot come off this run and is handed in.
110
114
  */
111
- work?: Readonly<Record<string, Readonly<Record<string, number>>>>
115
+ work?:
116
+ Readonly<Record<string, Readonly<Record<string, number>>>> | undefined
112
117
  /**
113
118
  * Fixed batch size, when a second `batch()` call has to match a first.
114
119
  *
115
120
  * Left out, it grows until the sample clears the bar.
116
121
  */
117
- n?: number
118
- reps?: number
119
- warmup?: number
122
+ n?: number | undefined
123
+ reps?: number | undefined
124
+ warmup?: number | undefined
120
125
  /** Wall clock for the whole call. A page has a reader waiting on it. */
121
- budgetNanoseconds?: number
126
+ budgetNanoseconds?: number | undefined
122
127
  }
123
128
 
124
129
  function collectGarbage(): void {
@@ -4,7 +4,7 @@
4
4
  // than the name of a global anything could define.
5
5
 
6
6
  const UNDER_BUN =
7
- typeof (globalThis as { Bun?: { nanoseconds?: unknown } }).Bun
7
+ typeof (globalThis as { Bun?: { nanoseconds?: unknown } | undefined }).Bun
8
8
  ?.nanoseconds === 'function'
9
9
 
10
10
  /** Whether this is bun, rather than a browser. */
@@ -48,7 +48,7 @@ export type RatioSpec = {
48
48
  * Byte-identical page source ran 4.5x apart because one arm shipped a stylesheet and the
49
49
  * other was therefore not doing the work at all.
50
50
  */
51
- workFactor?: number
51
+ workFactor?: number | undefined
52
52
  }
53
53
 
54
54
  const DEFAULT_WORK_FACTOR = 1.05
@@ -7,5 +7,5 @@
7
7
  // nothing itself.
8
8
 
9
9
  export { rowsCommand } from './rowsCommand.ts'
10
- export { runBenches } from './runBenches.ts'
10
+ export { type Bench, runBenches } from './runBenches.ts'
11
11
  export { type TestSuite, testRows } from './testRows.ts'
@@ -4,6 +4,21 @@ import { type Batched, claimOf, ratio } from '../report/index.ts'
4
4
  export const milliseconds = (nanoseconds: number) =>
5
5
  `${(nanoseconds / 1e6).toFixed(3)} ms`
6
6
 
7
+ /** One bench `runBenches` ran: its file, its case, and each arm's time per operation. */
8
+ export type Bench = {
9
+ file: string
10
+ name: string
11
+ case: string
12
+ n: number
13
+ floor: number
14
+ /** Nanoseconds per operation, by arm. */
15
+ arms: Record<string, number>
16
+ /** The last arm over the first, as the harness is allowed to say it; '' for one arm. */
17
+ claim: string
18
+ /** An arm over its ceiling, and a ceiling naming no arm or no bench. */
19
+ over: string[]
20
+ }
21
+
7
22
  /**
8
23
  * Every bench beside the code, `src/**\/*.bench.ts` under `root`, run in this process one after
9
24
  * another: each function a file exports is one bench, and its `CEILINGS` names the most each arm
@@ -15,21 +30,7 @@ export const milliseconds = (nanoseconds: number) =>
15
30
  export async function runBenches(
16
31
  root: string,
17
32
  only?: string,
18
- ): Promise<
19
- {
20
- file: string
21
- name: string
22
- case: string
23
- n: number
24
- floor: number
25
- /** Nanoseconds per operation, by arm. */
26
- arms: Record<string, number>
27
- /** The last arm over the first, as the harness is allowed to say it; '' for one arm. */
28
- claim: string
29
- /** An arm over its ceiling, and a ceiling naming no arm or no bench. */
30
- over: string[]
31
- }[]
32
- > {
33
+ ): Promise<Bench[]> {
33
34
  const base = root.endsWith('/') ? root : `${root}/`
34
35
  const files = [...new Bun.Glob('src/**/*.bench.ts').scanSync(base)].sort()
35
36
  const benches = []
@@ -38,7 +39,7 @@ export async function runBenches(
38
39
  const { CEILINGS = {}, ...exported } = (await import(
39
40
  Bun.pathToFileURL(`${base}${file}`).href
40
41
  )) as {
41
- CEILINGS?: Record<string, Record<string, number>>
42
+ CEILINGS?: Record<string, Record<string, number>> | undefined
42
43
  } & Record<string, unknown>
43
44
  for (const [name, priced] of Object.entries(exported)) {
44
45
  if (typeof priced !== 'function') continue
@@ -156,8 +156,8 @@ export async function runSuite(spec: {
156
156
  command: string[]
157
157
  reportTo: ReportTo
158
158
  cwd: string
159
- environment?: Record<string, string>
160
- deadline?: number
159
+ environment?: Record<string, string> | undefined
160
+ deadline?: number | undefined
161
161
  }): Promise<{ suites: Suite[]; milliseconds: number }> {
162
162
  const deadline = spec.deadline ?? SUITE_DEADLINE_MILLISECONDS
163
163
  const report = `${tmpdir()}/abide-suite-${crypto.randomUUID()}.xml`
@@ -22,13 +22,18 @@ const BUN_WIDTH = 8
22
22
  * replaces either glob, relative to `root`.
23
23
  */
24
24
  export type TestSuite =
25
- | { section: string; root: string; runner: 'bun'; pattern?: string }
25
+ | {
26
+ section: string
27
+ root: string
28
+ runner: 'bun'
29
+ pattern?: string | undefined
30
+ }
26
31
  | {
27
32
  section: string
28
33
  root: string
29
34
  runner: 'playwright'
30
35
  projects: string[]
31
- pattern?: string
36
+ pattern?: string | undefined
32
37
  }
33
38
 
34
39
  type TestItem = RowItem & { command: string[]; browser: boolean }
@@ -1,39 +0,0 @@
1
- // Builds the measure lane into ONE IIFE the browser arm is injected with. The bytes
2
- // playwright injects and the bytes `bun test` imports have to be the same code, or
3
- // the lane's one claim — the only lane in both substrates — is a claim about two
4
- // different instruments.
5
- //
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.
10
-
11
- import type { Page } from '@playwright/test'
12
-
13
- const ENTRY = new URL('../src/measure/injectable.ts', import.meta.url).pathname
14
-
15
- /** Builds the measure lane's injectable — or another entry's, the same way — and returns its source. */
16
- export async function buildInjectable(entry = ENTRY): Promise<string> {
17
- const built = await Bun.build({
18
- entrypoints: [entry],
19
- format: 'iife',
20
- target: 'browser',
21
- minify: false,
22
- })
23
- if (!built.success)
24
- throw new AggregateError(built.logs, `${entry} did not build`)
25
- return (built.outputs[0] as Blob).text()
26
- }
27
-
28
- /**
29
- * Opens a blank page `page` runs `source` in first.
30
- *
31
- * NAVIGATED, NOT JUST SET: `setContent` on a page still on its initial `about:blank` reruns no init
32
- * script — nothing navigated — so the injection would be silently absent, and every counter read
33
- * undefined: the gate failing on the instrument rather than on the claim.
34
- */
35
- export async function openInjected(page: Page, source: string): Promise<void> {
36
- await page.addInitScript({ content: source })
37
- await page.goto('about:blank')
38
- await page.setContent('<!doctype html><html><body></body></html>')
39
- }