ostia 0.4.0 → 0.6.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.
Files changed (64) hide show
  1. package/README.md +31 -30
  2. package/docs/agent-protocol.md +13 -9
  3. package/docs/cli.md +174 -126
  4. package/docs/config.md +2 -2
  5. package/docs/document-schema.md +15 -12
  6. package/docs/library.md +32 -21
  7. package/docs/preload-recipes.md +4 -4
  8. package/docs/statistics.md +14 -13
  9. package/index.d.ts +202 -60
  10. package/package.json +1 -1
  11. package/src/ab/ab-runner.ts +6 -6
  12. package/src/ab/index.ts +56 -6
  13. package/src/ab/unpaired.ts +54 -0
  14. package/src/bench/index.ts +40 -3
  15. package/src/bench/registry.ts +6 -4
  16. package/src/bench/run-tasks.ts +16 -2
  17. package/src/bench/runner.ts +10 -3
  18. package/src/bench/support.ts +8 -4
  19. package/src/bench/sweep.ts +2 -2
  20. package/src/cache/fingerprint.ts +2 -2
  21. package/src/capture/bunflags.ts +2 -2
  22. package/src/capture/cpu.ts +2 -2
  23. package/src/capture/heap-parse.ts +2 -2
  24. package/src/ci/index.ts +39 -48
  25. package/src/cli/agent.ts +54 -0
  26. package/src/cli/flags.ts +58 -9
  27. package/src/cli/help.ts +670 -245
  28. package/src/cli/main.ts +2 -3
  29. package/src/cli/output.ts +17 -14
  30. package/src/cli/run.ts +317 -92
  31. package/src/compare/index.ts +4 -4
  32. package/src/config/index.ts +14 -10
  33. package/src/config/validate.ts +4 -4
  34. package/src/glob.ts +2 -2
  35. package/src/index.ts +3 -2
  36. package/src/ir/document.ts +2 -2
  37. package/src/ir/types.ts +49 -24
  38. package/src/measure/alloc.ts +2 -2
  39. package/src/measure/cpu.ts +2 -2
  40. package/src/measure/environment.ts +11 -6
  41. package/src/measure/inprocess.ts +14 -10
  42. package/src/measure/instructions.ts +2 -2
  43. package/src/measure/noise.ts +51 -13
  44. package/src/measure/paired.ts +2 -2
  45. package/src/measure/peak.ts +4 -4
  46. package/src/measure/timing.ts +27 -6
  47. package/src/profile.ts +6 -4
  48. package/src/renderers/collapsed.ts +2 -2
  49. package/src/renderers/concise.ts +148 -0
  50. package/src/renderers/format.ts +13 -4
  51. package/src/renderers/human.ts +402 -0
  52. package/src/renderers/index.ts +9 -2
  53. package/src/renderers/markdown.ts +2 -2
  54. package/src/renderers/mermaid.ts +2 -2
  55. package/src/renderers/minimal.ts +8 -7
  56. package/src/renderers/relative.ts +2 -2
  57. package/src/renderers/select.ts +2 -2
  58. package/src/renderers/terminal.ts +1178 -383
  59. package/src/renderers/types.ts +3 -0
  60. package/src/spawn/index.ts +47 -14
  61. package/src/stats/bootstrap.ts +2 -2
  62. package/src/stats/index.ts +2 -2
  63. package/src/terminal.ts +321 -0
  64. package/src/time.ts +124 -20
@@ -0,0 +1,54 @@
1
+ // Why `ab` paired nothing, in words a person can act on: each side's task
2
+ // count, then the likeliest cause.
3
+
4
+ // A suite that imports `group` or `task` by a relative path, as one
5
+ // inside ostia's own repository does, has the base ref's copy register
6
+ // its tasks with the base tree's copy of ostia, which the runner never
7
+ // reads, so that side has none.
8
+ const RELATIVE_HARNESS =
9
+ /import\s*\{[^}]*\b(?:group|task)\b[^}]*\}\s*from\s*["']\.{1,2}\/[^"']*["']/;
10
+
11
+ export const importsHarnessRelatively = (suiteText: string): boolean =>
12
+ RELATIVE_HARNESS.test(suiteText);
13
+
14
+ export interface Unpaired {
15
+ /** The failure: each side's task count. */
16
+ what: string;
17
+ /** The likeliest cause, and what to do. */
18
+ next: string;
19
+ }
20
+
21
+ export function unpairedReason(input: {
22
+ ref: string;
23
+ base: number;
24
+ cand: number;
25
+ /** Every suite is new: none exists at `ref`. */
26
+ allNew: boolean;
27
+ relativeHarness: boolean;
28
+ }): Unpaired {
29
+ const { ref, base, cand } = input;
30
+ const tasks = (n: number) => `${n} ${n === 1 ? "task" : "tasks"}`;
31
+ const what = `Nothing paired: ${ref} has ${tasks(base)}, the working tree ${tasks(cand)}`;
32
+ if (input.allNew) {
33
+ return {
34
+ what,
35
+ next: `no suite exists at ${ref}; time new suites with ostia bench`,
36
+ };
37
+ }
38
+ if (base === 0 && cand > 0 && input.relativeHarness) {
39
+ return {
40
+ what,
41
+ next: `the suite imports ostia by a relative path, so ${ref}'s copy registers with ${ref}'s own ostia; import it as "ostia", or by an absolute path`,
42
+ };
43
+ }
44
+ if (base === 0) {
45
+ return { what, next: `${ref}'s copy of the suite registered no task` };
46
+ }
47
+ if (cand === 0) {
48
+ return { what, next: "the working tree's suite registered no task" };
49
+ }
50
+ return {
51
+ what,
52
+ next: "no task name is on both sides; a renamed task pairs with nothing",
53
+ };
54
+ }
@@ -15,6 +15,7 @@ import { stampDrift } from "../measure/environment.ts";
15
15
  import type { PeakMemResult } from "../measure/peak.ts";
16
16
  import { assertSamplingOptions } from "../measure/timing.ts";
17
17
  import { type SuiteLaunch, suiteLauncher } from "./projects.ts";
18
+ import type { TaskProgress } from "./run-tasks.ts";
18
19
  import type { RunnerOpts } from "./runner.ts";
19
20
  import {
20
21
  absolutePath,
@@ -94,6 +95,8 @@ export interface BenchOptions {
94
95
  * Measure this machine's noise floor once, before any suite runs
95
96
  * (default: true), and stamp it on the document as `environment`. */
96
97
  noiseCheck?: boolean;
98
+ /** Sample the noise floor for exactly this many ms instead. */
99
+ noiseBudgetMs?: number;
97
100
  /**
98
101
  * SIGKILLs a suite file's subprocess (or, under `isolate`, one task's)
99
102
  * that hasn't finished after this many ms. No default. */
@@ -104,6 +107,20 @@ export interface BenchOptions {
104
107
  * `aborted` warning on the last measurement. A suite killed mid-run is
105
108
  * dropped entirely: it only writes its result once, at the end. */
106
109
  signal?: AbortSignal;
110
+ /** Called before each task is measured, for a progress line. */
111
+ onProgress?: (progress: BenchProgress) => void;
112
+ }
113
+
114
+ /** What `bench()` is doing, for `onProgress`. Counts start at 1. */
115
+ export interface BenchProgress {
116
+ suite: number;
117
+ suites: number;
118
+ /** The suite file, as given. */
119
+ file: string;
120
+ /** The task, among the ones its process measures. */
121
+ task: number;
122
+ tasks: number;
123
+ label: string;
107
124
  }
108
125
 
109
126
  const RUNNER_PATH = new URL("./runner.ts", import.meta.url).pathname;
@@ -132,6 +149,7 @@ export interface BenchCliOverrides {
132
149
  bunFlags: string[];
133
150
  outDir?: string;
134
151
  noiseCheck: boolean;
152
+ noiseBudgetMs?: number;
135
153
  timeoutMs?: number;
136
154
  }
137
155
 
@@ -190,6 +208,9 @@ export async function resolveBenchOptions(
190
208
  ...(projects !== undefined && { projects }),
191
209
  ...(outDir !== undefined && { outDir }),
192
210
  noiseCheck: cli.noiseCheck,
211
+ ...(cli.noiseBudgetMs !== undefined && {
212
+ noiseBudgetMs: cli.noiseBudgetMs,
213
+ }),
193
214
  ...(timeoutMs !== undefined && { timeoutMs }),
194
215
  cwd,
195
216
  };
@@ -274,7 +295,10 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
274
295
  const path = absolutePath(cwd, given);
275
296
  return { given, path, ...launch(path) };
276
297
  });
277
- const { environment, noiseWarning } = captureRunEnvironment(opts.noiseCheck);
298
+ const { environment, noiseWarning } = captureRunEnvironment(
299
+ opts.noiseCheck,
300
+ opts.noiseBudgetMs,
301
+ );
278
302
 
279
303
  const measureOpts: RunnerOpts = {
280
304
  ...(opts.budgetMs !== undefined && { budgetMs: opts.budgetMs }),
@@ -292,6 +316,8 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
292
316
  noiseCheck: false,
293
317
  };
294
318
  const filter = opts.filter !== undefined && { filter: opts.filter };
319
+ const onProgress = opts.onProgress;
320
+ const progress = onProgress !== undefined && { progress: true };
295
321
 
296
322
  const outPath = (tag: string, suite: Suite, ...rest: unknown[]) =>
297
323
  `${tmpDir}/${fp(tag, suite.path, ...rest)}.json`;
@@ -329,6 +355,15 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
329
355
  timeoutMs: opts.timeoutMs,
330
356
  signal: opts.signal,
331
357
  inFlight,
358
+ ...(job.runnerOpts.progress && {
359
+ ipc: (message: TaskProgress) =>
360
+ onProgress?.({
361
+ suite: suites.indexOf(job.suite) + 1,
362
+ suites: suites.length,
363
+ file: job.suite.given,
364
+ ...message,
365
+ }),
366
+ }),
332
367
  },
333
368
  );
334
369
  if (!ran) return;
@@ -362,6 +397,7 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
362
397
  ...measureOpts,
363
398
  ...filter,
364
399
  ...(opts.isolate !== undefined && { isolate: opts.isolate }),
400
+ ...progress,
365
401
  preload: p.suite.preload,
366
402
  planPath: p.planPath,
367
403
  },
@@ -405,6 +441,7 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
405
441
  runnerOpts: {
406
442
  ...measureOpts,
407
443
  workloadIds: [item.task.workloadId],
444
+ ...progress,
408
445
  preload: item.suite.preload,
409
446
  markIsolated: true,
410
447
  },
@@ -466,8 +503,8 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
466
503
 
467
504
  // Plan order (registration order, filtered) within a suite, suites in
468
505
  // command-line order. Measurements are matched by workload id, not
469
- // position, because a task.skip()'d task has a workload but no
470
- // measurement.
506
+ // position, because a task.skip()'d task has a workload but
507
+ // no measurement.
471
508
  const workloads: Workload[] = [];
472
509
  const measurements: Measurement[] = [];
473
510
  for (const { suite, tasks, doc: sharedDoc } of plans) {
@@ -29,8 +29,9 @@ export interface TaskOptions {
29
29
  aliases?: string[];
30
30
  /**
31
31
  * What this task measures and why. Flows into `Workload.description` so
32
- * the intent travels with the numbers instead of living only in a source
33
- * comment. */
32
+ * the intent travels with the numbers instead of living only in a
33
+ * source comment.
34
+ */
34
35
  description?: string;
35
36
  /**
36
37
  * Give this task its own subprocess instead of sharing its suite file's,
@@ -210,8 +211,9 @@ type GroupRegistrar = (
210
211
  export interface GroupFn extends GroupRegistrar {
211
212
  /**
212
213
  * Registers every task inside as skipped: the runner never measures
213
- * them, but the document still carries their workloads (marked
214
- * `Workload.skipped`). */
214
+ * them, but the document still carries their workloads
215
+ * (marked `Workload.skipped`).
216
+ */
215
217
  skip: GroupRegistrar;
216
218
  /**
217
219
  * When any task or group in the suite uses `.only`, the runner restricts
@@ -49,8 +49,8 @@ export interface MeasureTasksOpts extends InprocessTimingOptions {
49
49
  noiseCheck?: boolean;
50
50
  }
51
51
 
52
- // Shared by every runner so a task has the same id under `bench()` and
53
- // `ab()`.
52
+ // Shared by every runner so a task has the same id under `bench()`
53
+ // and `ab()`.
54
54
  export function taskWorkload(
55
55
  suiteFile: string,
56
56
  t: RegisteredTask,
@@ -77,12 +77,22 @@ export function taskWorkload(
77
77
  });
78
78
  }
79
79
 
80
+ /**
81
+ * Sent before each task is measured, for a progress line. `task` counts
82
+ * the measured tasks from 1; skipped ones aren't counted. */
83
+ export interface TaskProgress {
84
+ task: number;
85
+ tasks: number;
86
+ label: string;
87
+ }
88
+
80
89
  // The caller has already selected `tasks` and handled isolation, so
81
90
  // neither happens here.
82
91
  export async function measureTasks(
83
92
  suiteFile: string,
84
93
  tasks: readonly RegisteredTask[],
85
94
  opts: MeasureTasksOpts,
95
+ onTask?: (progress: TaskProgress) => void,
86
96
  ): Promise<ProfileDocument> {
87
97
  const willMeasure = tasks.some((t) => !t.skipped);
88
98
  const { environment, noiseWarning } = captureRunEnvironment(
@@ -92,11 +102,15 @@ export async function measureTasks(
92
102
 
93
103
  const workloads: Workload[] = [];
94
104
  const measurements: Measurement[] = [];
105
+ const measuredCount = tasks.filter((t) => !t.skipped).length;
106
+ let started = 0;
95
107
  for (const [idx, t] of tasks.entries()) {
96
108
  const workload = taskWorkload(suiteFile, t, opts.markIsolated);
97
109
  workloads.push(workload);
98
110
 
99
111
  if (t.skipped) continue;
112
+ started++;
113
+ onTask?.({ task: started, tasks: measuredCount, label: taskIdOf(t) });
100
114
 
101
115
  const { enter, leave } = edges(idx);
102
116
  await runGroupHooks(t, "before", enter);
@@ -55,10 +55,12 @@ export interface RunnerOpts extends MeasureTasksOpts {
55
55
  * Scripts imported, in order, before the suite file, in this same process
56
56
  * (so globals or `Bun.plugin()` loaders they install reach the suite). */
57
57
  preload?: string[];
58
+ /** Send a `TaskProgress` message over IPC before each task. */
59
+ progress?: boolean;
58
60
  }
59
61
 
60
- // The parent serializes a `RunnerOpts`; only that it's an object is
61
- // checked.
62
+ // The parent serializes a `RunnerOpts`; only that it's an object
63
+ // is checked.
62
64
  function isRunnerOpts(value: unknown): value is RunnerOpts {
63
65
  return typeof value === "object" && value !== null && !Array.isArray(value);
64
66
  }
@@ -154,7 +156,12 @@ async function main(): Promise<number> {
154
156
  ? tasks
155
157
  : tasks.filter((t) => !taskIsolate(t, opts.isolate ?? false));
156
158
 
157
- const doc = await measureTasks(suiteFile, toRun, opts);
159
+ const doc = await measureTasks(
160
+ suiteFile,
161
+ toRun,
162
+ opts,
163
+ opts.progress ? (progress) => process.send?.(progress) : undefined,
164
+ );
158
165
  await saveDocument(doc, outputPath);
159
166
  return 0;
160
167
  }
@@ -56,8 +56,8 @@ export async function loadIfExists(
56
56
  return (await Bun.file(path).exists()) ? loadDocument(path) : undefined;
57
57
  }
58
58
 
59
- // invariant: a `--peak-mem` reading is the median of this many fresh
60
- // processes.
59
+ // invariant: a `--peak-mem` reading is the median of this many
60
+ // fresh processes.
61
61
  export const PEAK_MEM_PROCESSES = 3;
62
62
  // Slack below this is what any suite that loads fixtures leaves behind
63
63
  // (8MB for caligula's), so it's too common to warn about.
@@ -76,11 +76,15 @@ export function peakHiddenWarning(
76
76
  };
77
77
  }
78
78
 
79
- export function captureRunEnvironment(noiseCheck: boolean | undefined): {
79
+ export function captureRunEnvironment(
80
+ noiseCheck: boolean | undefined,
81
+ noiseBudgetMs?: number,
82
+ ): {
80
83
  environment: Environment | undefined;
81
84
  noiseWarning: Warning | undefined;
82
85
  } {
83
- const environment = noiseCheck === false ? undefined : captureEnvironment();
86
+ const environment =
87
+ noiseCheck === false ? undefined : captureEnvironment(noiseBudgetMs);
84
88
  return {
85
89
  environment,
86
90
  noiseWarning: environment && noisyMachineWarning(environment),
@@ -25,9 +25,9 @@ export function sweep<T extends Record<string, readonly unknown[]>>(
25
25
  const key = keys[index];
26
26
  if (key === undefined) {
27
27
  withCurrentParams(
28
- // eslint-disable-next-line typescript/consistent-type-assertions, no-restricted-syntax -- `dims` may hold any value, and params carry the point as given
28
+ // eslint-disable-next-line typescript/consistent-type-assertions -- `dims` may hold any value, and params carry the point as given
29
29
  point as Record<string, string | number | boolean>,
30
- // eslint-disable-next-line typescript/consistent-type-assertions, no-restricted-syntax -- every key of `dims` is set by now, which TS can't follow through a mapped type
30
+ // eslint-disable-next-line typescript/consistent-type-assertions -- every key of `dims` is set by now, which TS can't follow through a mapped type
31
31
  () => fn(point as SweepPoint<T>),
32
32
  );
33
33
  return;
@@ -45,8 +45,8 @@ export async function computeInputsDigest(
45
45
  const k = next++;
46
46
  const path = paths[k];
47
47
  if (path === undefined) continue;
48
- // `resolve`, not a join, since absolute patterns scan to absolute
49
- // paths.
48
+ // `resolve`, not a join, since absolute patterns scan to
49
+ // absolute paths.
50
50
  const buf = await Bun.file(resolve(cwd, path)).arrayBuffer();
51
51
  entries[k] = {
52
52
  path,
@@ -2,8 +2,8 @@ import { processEnv } from "../config/env.ts";
2
2
  import type { Warning } from "../ir/types.ts";
3
3
 
4
4
  // BUN_OPTIONS is split on whitespace; a backslash escapes a space or quote
5
- // (Bun doesn't honour quoting, and a literal backslash can't be
6
- // expressed).
5
+ // (Bun doesn't honour quoting, and a literal backslash can't
6
+ // be expressed).
7
7
  function escapeBunOption(flag: string): string {
8
8
  return flag.replace(/[\s"']/g, "\\$&");
9
9
  }
@@ -14,8 +14,8 @@ interface CpuCaptureResult {
14
14
  warnings: Warning[];
15
15
  }
16
16
 
17
- // BUN_CPU_PROFILE is documented but doesn't work on Bun 1.4.0, hence
18
- // flags/BUN_OPTIONS.
17
+ // BUN_CPU_PROFILE is documented but doesn't work on Bun 1.4.0,
18
+ // hence flags/BUN_OPTIONS.
19
19
  export async function runCpuCapture(
20
20
  opts: CpuCaptureOptions,
21
21
  ): Promise<CpuCaptureResult> {
@@ -12,8 +12,8 @@ export interface RawHeapSnapshot {
12
12
  strings: string[];
13
13
  }
14
14
 
15
- // Checks only the arrays `parseHeapSnapshot` walks and the count it
16
- // reports.
15
+ // Checks only the arrays `parseHeapSnapshot` walks and the count
16
+ // it reports.
17
17
  export function isRawHeapSnapshot(value: unknown): value is RawHeapSnapshot {
18
18
  if (typeof value !== "object" || value === null) return false;
19
19
  if (!("nodes" in value) || !Array.isArray(value.nodes)) return false;
package/src/ci/index.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { bench, resolveBenchOptions } from "../bench/index.ts";
1
+ import {
2
+ bench,
3
+ type BenchProgress,
4
+ resolveBenchOptions,
5
+ } from "../bench/index.ts";
2
6
  import { captureRunEnvironment } from "../bench/support.ts";
3
7
  import { computeCacheKey, computeInputsDigest } from "../cache/fingerprint.ts";
4
8
  import { readCachedRun, writeCachedRun } from "../cache/store.ts";
@@ -27,7 +31,6 @@ import type {
27
31
  } from "../ir/types.ts";
28
32
  import { stampDrift } from "../measure/environment.ts";
29
33
  import { isHarnessFailure, runTimingPhase } from "../measure/timing.ts";
30
- import { formatSignedPct, workloadLabel } from "../renderers/format.ts";
31
34
  import { abortedWarning } from "../time.ts";
32
35
  import { TOOL_VERSION } from "../version.ts";
33
36
 
@@ -38,11 +41,17 @@ interface CiOptions {
38
41
  /**
39
42
  * Abort kills in-flight trials and suite processes and stops scheduling
40
43
  * workloads. `runCi` then resolves with `aborted: true`: the document
41
- * holds what completed, nothing is compared, and no run is written to the
42
- * cache. */
44
+ * holds what completed, nothing is compared, and no run is written to
45
+ * the cache.
46
+ */
43
47
  signal?: AbortSignal;
48
+ /** Called as each workload (and each suite task) starts. */
49
+ onProgress?: CiProgress;
44
50
  }
45
51
 
52
+ /** A progress line's step text, and how far the run is, 0 to 1. */
53
+ type CiProgress = (step: string, doneRatio: number) => void;
54
+
46
55
  // So a hung workload times out instead of blocking a CI job;
47
56
  // `WorkloadConfig.timeoutMs` / `BenchConfig.timeoutMs` override this.
48
57
  const DEFAULT_CI_TIMEOUT_MS = 600_000;
@@ -83,8 +92,8 @@ interface CiSummary {
83
92
  }
84
93
 
85
94
  /**
86
- * Base of the two baseline errors, so the CLI reports either as
87
- * `baseline-missing`.
95
+ * Base of the two baseline errors, so the CLI reports either
96
+ * as `baseline-missing`.
88
97
  */
89
98
  export class BaselineError extends OstiaUsageError {}
90
99
 
@@ -135,6 +144,7 @@ async function measureSuiteWorkloads(
135
144
  suites: string[],
136
145
  noiseWarning: Warning | undefined,
137
146
  signal: AbortSignal | undefined,
147
+ onProgress?: (progress: BenchProgress) => void,
138
148
  ): Promise<MeasuredWorkload[]> {
139
149
  // Always executes: a suite file's task ids (so its cache keys) are unknown
140
150
  // without importing it.
@@ -145,8 +155,8 @@ async function measureSuiteWorkloads(
145
155
  `Workload suites ${JSON.stringify(suites)} matched no files.`,
146
156
  );
147
157
  }
148
- // Same CLI-over-config resolution as `ostia bench`; only the defaults
149
- // differ.
158
+ // Same CLI-over-config resolution as `ostia bench`; only the
159
+ // defaults differ.
150
160
  const benchOpts = await resolveBenchOptions(
151
161
  { suites: suiteFiles, preload: [], bunFlags: [], noiseCheck: false },
152
162
  config.bench,
@@ -156,6 +166,7 @@ async function measureSuiteWorkloads(
156
166
  outDir: benchOpts.outDir ?? config.outDir,
157
167
  timeoutMs: wc.timeoutMs ?? benchOpts.timeoutMs ?? DEFAULT_CI_TIMEOUT_MS,
158
168
  ...(signal && { signal }),
169
+ ...(onProgress && { onProgress }),
159
170
  });
160
171
  const results: MeasuredWorkload[] = [];
161
172
  for (const workload of doc.workloads) {
@@ -255,14 +266,21 @@ export async function measureConfigWorkloads(
255
266
  config: OstiaConfig,
256
267
  full: boolean,
257
268
  signal?: AbortSignal,
269
+ onProgress?: CiProgress,
258
270
  ): Promise<MeasureConfigWorkloadsResult> {
259
271
  // Stamped on every measurement taken now, never on a cached one.
260
272
  const { environment, noiseWarning } = captureRunEnvironment(
261
273
  config.noiseCheck,
262
274
  );
263
275
  const results: MeasuredWorkload[] = [];
264
- for (const wc of config.workloads) {
276
+ const count = config.workloads.length;
277
+ for (const [i, wc] of config.workloads.entries()) {
265
278
  if (signal?.aborted) break;
279
+ const step = `ci ${i + 1} of ${count}`;
280
+ onProgress?.(
281
+ `${step} · ${wc.label ?? wc.command?.join(" ") ?? wc.suites?.join(", ") ?? ""}`,
282
+ i / count,
283
+ );
266
284
  if (wc.suites) {
267
285
  results.push(
268
286
  ...(await measureSuiteWorkloads(
@@ -271,6 +289,12 @@ export async function measureConfigWorkloads(
271
289
  wc.suites,
272
290
  noiseWarning,
273
291
  signal,
292
+ onProgress &&
293
+ ((p) =>
294
+ onProgress(
295
+ `${step} · ${p.label}`,
296
+ (i + (p.suite - 1 + (p.task - 1) / p.tasks) / p.suites) / count,
297
+ )),
274
298
  )),
275
299
  );
276
300
  } else if (wc.command) {
@@ -320,7 +344,12 @@ export async function runCi(opts: CiOptions): Promise<{
320
344
  results: measured,
321
345
  environment,
322
346
  aborted,
323
- } = await measureConfigWorkloads(config, opts.full, opts.signal);
347
+ } = await measureConfigWorkloads(
348
+ config,
349
+ opts.full,
350
+ opts.signal,
351
+ opts.onProgress,
352
+ );
324
353
  const results: CiWorkloadResult[] = measured.map((m) => ({ ...m }));
325
354
  const executed = results.filter((r) => r.status === "executed").length;
326
355
  const candidateDoc = createDocument(
@@ -400,41 +429,3 @@ export async function runCi(opts: CiOptions): Promise<{
400
429
  aborted: false,
401
430
  };
402
431
  }
403
-
404
- export function renderCiReport(summary: CiSummary): string {
405
- const lines = [
406
- `${summary.total} workloads`,
407
- `${summary.cached} cached`,
408
- `${summary.executed} executed`,
409
- ];
410
- if (summary.missingBaseline > 0) {
411
- lines.push(
412
- `${summary.missingBaseline} skipped (no matching baseline workload)`,
413
- );
414
- }
415
- if (summary.failed > 0) {
416
- const failedLabels = summary.results
417
- .filter((r) => r.harnessFailed)
418
- .map((r) => workloadLabel(r.workload));
419
- lines.push(
420
- `${summary.failed} failed (harness error, a command exited non-zero or produced no samples: ${failedLabels.join(", ")})`,
421
- );
422
- }
423
-
424
- const regressionDetails = summary.results
425
- .filter((r) => r.comparison?.verdict === "fail")
426
- .map((r) => {
427
- const t = r.comparison?.timing;
428
- const label = workloadLabel(r.workload);
429
- return t
430
- ? `${formatSignedPct(t.medianDeltaPct)} median on ${label}`
431
- : label;
432
- });
433
-
434
- lines.push(
435
- `${summary.passed} passed ${summary.regressed} regressed${regressionDetails.length > 0 ? ` (${regressionDetails.join(", ")})` : ""}`,
436
- "",
437
- `Profile CI: ${summary.regressed > 0 || summary.failed > 0 ? "✗" : "✓"}`,
438
- );
439
- return `${lines.join("\n")}\n`;
440
- }
@@ -0,0 +1,54 @@
1
+ import { processEnv } from "../config/env.ts";
2
+
3
+ // The variables a coding agent sets, as svelte-typecheck and svelte-lint
4
+ // read them, after `bun check`: `AGENT` and `CLAUDECODE`, `AI_AGENT`, the
5
+ // shared name, and Codex's `CODEX_CI` and `CODEX_THREAD_ID`. Kept the same
6
+ // so the three tools agree on what an agent is (metonym/ostia#53).
7
+ const AGENT_ENV = [
8
+ "AGENT",
9
+ "AI_AGENT",
10
+ "CLAUDECODE",
11
+ "CODEX_CI",
12
+ "CODEX_THREAD_ID",
13
+ ] as const;
14
+
15
+ type Env = Readonly<Record<string, string | undefined>>;
16
+
17
+ // The first agent variable set to anything but empty or `0`, which a
18
+ // person sets to say "not an agent" without unsetting it.
19
+ export function agentVariable(env: Env = processEnv()): string | undefined {
20
+ return AGENT_ENV.find((name) => {
21
+ const value = env[name];
22
+ return value !== undefined && value !== "" && value !== "0";
23
+ });
24
+ }
25
+
26
+ function asksForFormat(argv: readonly string[]): boolean {
27
+ return argv.some(
28
+ (arg) =>
29
+ arg === "--format" ||
30
+ arg.startsWith("--format=") ||
31
+ arg === "--json" ||
32
+ arg.startsWith("--json="),
33
+ );
34
+ }
35
+
36
+ // `argv` with the format to use when it names none: `OSTIA_FORMAT` when
37
+ // set, else `concise` for a coding agent, with a line saying so, so a
38
+ // person reading the agent's log knows why the table is missing.
39
+ export function withDefaultFormat(
40
+ argv: readonly string[],
41
+ env: Env = processEnv(),
42
+ ): { argv: string[]; notice?: string } {
43
+ if (asksForFormat(argv)) return { argv: [...argv] };
44
+ const chosen = env.OSTIA_FORMAT;
45
+ if (chosen !== undefined && chosen !== "") {
46
+ return { argv: [...argv, "--format", chosen] };
47
+ }
48
+ const agent = agentVariable(env);
49
+ if (agent === undefined) return { argv: [...argv] };
50
+ return {
51
+ argv: [...argv, "--format", "concise"],
52
+ notice: `ostia: ${agent} is set, so --format concise; pass --format or set OSTIA_FORMAT for another.\n`,
53
+ };
54
+ }