@operad-io/dev 0.1.0 → 0.2.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/src/flaky.ts CHANGED
@@ -15,8 +15,8 @@ import { isAbsolute, join, relative } from "node:path";
15
15
  import type { ObjectStore, StoredObject } from "@operad-io/engine";
16
16
  import { isRecord, messageOf, type SecretStore } from "@operad-io/engine";
17
17
  import type { MachineLoad } from "@operad-io/engine/platform";
18
- import type { CheckLoad } from "./notcode.ts";
19
- import { bareId, changeClock, isOpenTask, keyRepository, listAll, parseId, planData, planState, splitBrief, taskData, type PlanData, type RepositoryData } from "./model.ts";
18
+ import { underLoad, type CheckLoad, type CheckLoadReading } from "./check-load.ts";
19
+ import { idOfKey, changeClock, isOpenTask, keyRepository, listAll, parseId, planData, planState, splitBrief, taskData, type PlanData, type RepositoryData } from "./model.ts";
20
20
  import { anchoredPattern, shellQuote } from "./rerun.ts";
21
21
  import type { FailedRerun } from "./settings.ts";
22
22
  import { addConfirmedPlanLocked, addTaskLocked, withRepoLock } from "./service.ts";
@@ -70,7 +70,7 @@ export interface FlakyOccurrence {
70
70
  * recorded and never counts toward a task: a rerun on a busy machine says
71
71
  * little about the test.
72
72
  */
73
- readonly load?: MachineLoad | undefined;
73
+ readonly load?: CheckLoadReading | undefined;
74
74
  }
75
75
 
76
76
  /** The passes that count toward a task: the ones seen on an idle machine. */
@@ -83,23 +83,23 @@ export function flakyLoadLimitOf(configured: number | undefined, load: MachineLo
83
83
  return configured ?? load.cores * 2;
84
84
  }
85
85
 
86
- /** True when a reading is above the limit. */
87
- function overLimit(load: MachineLoad, configured: number | undefined): boolean {
88
- return load.load1 > flakyLoadLimitOf(configured, load);
86
+ /** True when a reading is above the limit. An unknown reading is not busy. */
87
+ function overLimit(load: CheckLoadReading, configured: number | undefined): boolean {
88
+ return load.unknown !== true && load.load1 > flakyLoadLimitOf(configured, load);
89
89
  }
90
90
 
91
91
  /** The load readings a check handed over: the start and the end of each run. */
92
92
  interface LoadInput {
93
- readonly load?: MachineLoad | undefined;
94
- readonly startLoad?: MachineLoad | undefined;
95
- readonly endLoad?: MachineLoad | undefined;
93
+ readonly load?: CheckLoadReading | undefined;
94
+ readonly startLoad?: CheckLoadReading | undefined;
95
+ readonly endLoad?: CheckLoadReading | undefined;
96
96
  readonly loads?: readonly CheckLoad[] | undefined;
97
97
  readonly loadLimit?: number | undefined;
98
98
  }
99
99
 
100
100
  /** The first reading above the limit, or undefined when the check ran idle. */
101
- function busyLoad(input: LoadInput): MachineLoad | undefined {
102
- const readings: MachineLoad[] = [];
101
+ function busyLoad(input: LoadInput): CheckLoadReading | undefined {
102
+ const readings: CheckLoadReading[] = [];
103
103
  for (const run of input.loads ?? []) readings.push(run.start, run.end);
104
104
  if (input.startLoad !== undefined) readings.push(input.startLoad);
105
105
  if (input.endLoad !== undefined) readings.push(input.endLoad);
@@ -108,8 +108,8 @@ function busyLoad(input: LoadInput): MachineLoad | undefined {
108
108
  }
109
109
 
110
110
  /** The history and check-log line for a failure skipped as seen under load. */
111
- function skippedNotice(name: string, load: MachineLoad): string {
112
- return `flaky test "${name}" skipped: seen under load ${load.load1} on ${load.cores} cores`;
111
+ function skippedNotice(name: string, load: CheckLoadReading): string {
112
+ return `flaky test "${name}" skipped: seen ${underLoad(load)}`;
113
113
  }
114
114
 
115
115
  /** Adds the skip line to the check's own log; a log that cannot be written stays as it is. */
@@ -143,7 +143,14 @@ function occurrenceOf(value: unknown): FlakyOccurrence | undefined {
143
143
  if (typeof task !== "string" || typeof at !== "number") return undefined;
144
144
  return {
145
145
  ...(isRecord(load) && typeof load.load1 === "number" && typeof load.cores === "number"
146
- ? { load: { load1: load.load1, cores: load.cores } }
146
+ ? {
147
+ load: {
148
+ load1: load.load1,
149
+ cores: load.cores,
150
+ ...(typeof load.host === "string" ? { host: load.host } : {}),
151
+ ...(load.unknown === true ? { unknown: true } : {}),
152
+ },
153
+ }
147
154
  : {}),
148
155
  task,
149
156
  at,
@@ -178,7 +185,16 @@ function writableOf(record: FlakyRecord): Record<string, unknown> {
178
185
  task: entry.task,
179
186
  at: entry.at,
180
187
  excerpt: entry.excerpt,
181
- ...(entry.load === undefined ? {} : { load: { load1: entry.load.load1, cores: entry.load.cores } }),
188
+ ...(entry.load === undefined
189
+ ? {}
190
+ : {
191
+ load: {
192
+ load1: entry.load.load1,
193
+ cores: entry.load.cores,
194
+ ...(entry.load.host === undefined ? {} : { host: entry.load.host }),
195
+ ...(entry.load.unknown === true ? { unknown: true } : {}),
196
+ },
197
+ }),
182
198
  ...(entry.file === undefined ? {} : { file: entry.file }),
183
199
  ...(entry.stress === undefined ? {} : { stress: entry.stress }),
184
200
  ...(entry.rule === undefined ? {} : { rule: entry.rule }),
@@ -353,7 +369,7 @@ async function newestConfirmedPlan(
353
369
  for (const object of await listAll(store, "plan")) {
354
370
  const plan = planData(object.data);
355
371
  if (plan.repository !== repository || plan.status !== "confirmed") continue;
356
- const number = parseId(bareId(object.id), "plan")?.number ?? -1;
372
+ const number = parseId(idOfKey(object.id), "plan")?.number ?? -1;
357
373
  if (best === undefined || number > best.number) best = { object, number };
358
374
  }
359
375
  return best?.object;
@@ -380,7 +396,7 @@ async function flakyPlanFor(
380
396
  ): Promise<{ readonly plan: StoredObject; readonly missing: string | undefined }> {
381
397
  let missing: string | undefined;
382
398
  if (configured !== undefined) {
383
- const named = await store.get("plan", `${repository.name}/${bareId(configured)}`);
399
+ const named = await store.get("plan", `${repository.name}/${idOfKey(configured)}`);
384
400
  if (named !== undefined) {
385
401
  const data = planData(named.data);
386
402
  if (data.repository === repository.name && !isEnded(data)) {
@@ -394,13 +410,13 @@ async function flakyPlanFor(
394
410
  const data = planData(object.data);
395
411
  return (
396
412
  data.repository === repository.name &&
397
- parseId(bareId(object.id), "plan")?.slug === FLAKY_PLAN_SLUG &&
413
+ parseId(idOfKey(object.id), "plan")?.slug === FLAKY_PLAN_SLUG &&
398
414
  !isEnded(data)
399
415
  );
400
416
  })
401
417
  .sort(
402
418
  (x, y) =>
403
- (parseId(bareId(y.id), "plan")?.number ?? -1) - (parseId(bareId(x.id), "plan")?.number ?? -1),
419
+ (parseId(idOfKey(y.id), "plan")?.number ?? -1) - (parseId(idOfKey(x.id), "plan")?.number ?? -1),
404
420
  )[0];
405
421
  if (own !== undefined) return { plan: own, missing };
406
422
  const model = await newestConfirmedPlan(store, repository.name);
@@ -469,10 +485,10 @@ export interface FlakyInput {
469
485
  /** The check log, which still holds the first run's output. */
470
486
  readonly log: string | undefined;
471
487
  /** One load reading for the check, when the caller has only that. */
472
- readonly load?: MachineLoad | undefined;
488
+ readonly load?: CheckLoadReading | undefined;
473
489
  /** The load at the start and the end of the check, when it is one run. */
474
- readonly startLoad?: MachineLoad | undefined;
475
- readonly endLoad?: MachineLoad | undefined;
490
+ readonly startLoad?: CheckLoadReading | undefined;
491
+ readonly endLoad?: CheckLoadReading | undefined;
476
492
  /** The load at the start and the end of each run of the check. */
477
493
  readonly loads?: readonly CheckLoad[] | undefined;
478
494
  /** `check.flakyLoadLimit`: the load above which a failure is not a flaky test. */
@@ -528,7 +544,7 @@ export async function trackFlakyTests(input: FlakyInput): Promise<string | undef
528
544
  // the count restarts when that task ends, however few passes came before.
529
545
  const existing = await namingTask(store, fresh.name, name);
530
546
  if (existing !== undefined) {
531
- record = { ...record, task: bareId(existing.id) };
547
+ record = { ...record, task: idOfKey(existing.id) };
532
548
  await store.put(FLAKY_TYPE, key, writableOf(record), "dev:flaky-task");
533
549
  }
534
550
  }
@@ -579,7 +595,7 @@ async function propose(
579
595
  await store.put(
580
596
  FLAKY_TYPE,
581
597
  key,
582
- writableOf({ ...record, task: bareId(existing.id) }),
598
+ writableOf({ ...record, task: idOfKey(existing.id) }),
583
599
  "dev:flaky-task",
584
600
  );
585
601
  return undefined;
@@ -589,7 +605,7 @@ async function propose(
589
605
  const fallback =
590
606
  missing === undefined
591
607
  ? undefined
592
- : `check.flakyPlan "${missing}" does not name an open plan of this repository; the task went into "${bareId(plan.id)}"`;
608
+ : `check.flakyPlan "${missing}" does not name an open plan of this repository; the task went into "${idOfKey(plan.id)}"`;
593
609
  try {
594
610
  const task = await addTaskLocked(
595
611
  store,
@@ -605,7 +621,7 @@ async function propose(
605
621
  await store.put(
606
622
  FLAKY_TYPE,
607
623
  key,
608
- writableOf({ ...record, task: bareId(task.id) }),
624
+ writableOf({ ...record, task: idOfKey(task.id) }),
609
625
  "dev:flaky-task",
610
626
  );
611
627
  return fallback;
@@ -652,9 +668,9 @@ export interface FlakyReport {
652
668
  readonly taskId: string;
653
669
  readonly threshold: number;
654
670
  readonly flakyPlan?: string | undefined;
655
- readonly load?: MachineLoad | undefined;
656
- readonly startLoad?: MachineLoad | undefined;
657
- readonly endLoad?: MachineLoad | undefined;
671
+ readonly load?: CheckLoadReading | undefined;
672
+ readonly startLoad?: CheckLoadReading | undefined;
673
+ readonly endLoad?: CheckLoadReading | undefined;
658
674
  readonly loads?: readonly CheckLoad[] | undefined;
659
675
  readonly loadLimit?: number | undefined;
660
676
  readonly check: {