@mark1russell7/harness 0.16.3 → 0.16.5

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/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as Prediction, A as HostSysctl, At as Stage, B as LoadPlan, C as GroupPrediction, Ct as RunRoute, D as HopPlace, Dt as SentinelStage, E as HopEvent, Et as SentinelEvent, F as KafkaPause, Ft as Toxic, G as MiddleboxForm, H as LoadStream, I as KernelRecord, It as WsProbe, J as Pair, K as Observer, L as LineCount, Lt as environmentProblems, M as ImageSource, Mt as Subject, N as Jitter, Nt as Target, O as HopSignal, Ot as Shipped, P as Kafka, Pt as Topology, Q as PortsPrediction, R as LineMatch, Rt as isHopPlace, S as GroupPlace, St as RunPause, T as Hop, Tt as RunTopology, U as MiddleboxEvent, V as LoadPrediction, W as MiddleboxExpectation, X as PausePrediction, Y as PauseBand, Z as PinnedImage, _ as Fabric, _t as RunBackup, a as ClientCapability, at as QueueEnd, b as FaultPlace, bt as RunGroup, c as ClusterClientAt, ct as Recovers, d as CountBand, dt as ReplicaSetStage, et as ProbeEvent, f as DeliveryPrediction, ft as Replies, g as DriverStep, gt as Run, h as DriverBand, ht as RttRange, i as Client, it as QueueConnection, j as HttpProbe, jt as StageBand, k as HopWrite, kt as ShippedImage, l as ClusterStage, lt as Reference, m as DrillRoom, mt as RouterHop, n as CLIENT_CAPABILITIES, nt as ProxyTime, o as ClientImage, ot as QueuePrediction, p as Drill, pt as RequestPrediction, q as Outcomes, r as Cell, rt as QueueBand, s as Cluster, st as Reconnects, t as BuildImage, tt as ProxyHop, u as ConntrackPrediction, ut as ReplicaSet, v as FabricManifest, vt as RunDrill, w as GroupRole, wt as RunStream, x as Group, xt as RunPart, y as Fault, yt as RunFabric, z as LoadBand, zt as latestEndOf } from "./cell-CXxqXp1q.js";
1
+ import { $ as Prediction, A as HostSysctl, At as Stage, B as LoadPlan, C as GroupPrediction, Ct as RunRoute, D as HopPlace, Dt as SentinelStage, E as HopEvent, Et as SentinelEvent, F as KafkaPause, Ft as Toxic, G as MiddleboxForm, H as LoadStream, I as KernelRecord, It as WsProbe, J as Pair, K as Observer, L as LineCount, Lt as environmentProblems, M as ImageSource, Mt as Subject, N as Jitter, Nt as Target, O as HopSignal, Ot as Shipped, P as Kafka, Pt as Topology, Q as PortsPrediction, R as LineMatch, Rt as isHopPlace, S as GroupPlace, St as RunPause, T as Hop, Tt as RunTopology, U as MiddleboxEvent, V as LoadPrediction, W as MiddleboxExpectation, X as PausePrediction, Y as PauseBand, Z as PinnedImage, _ as Fabric, _t as RunBackup, a as ClientCapability, at as QueueEnd, b as FaultPlace, bt as RunGroup, c as ClusterClientAt, ct as Recovers, d as CountBand, dt as ReplicaSetStage, et as ProbeEvent, f as DeliveryPrediction, ft as Replies, g as DriverStep, gt as Run, h as DriverBand, ht as RttRange, i as Client, it as QueueConnection, j as HttpProbe, jt as StageBand, k as HopWrite, kt as ShippedImage, l as ClusterStage, lt as Reference, m as DrillRoom, mt as RouterHop, n as CLIENT_CAPABILITIES, nt as ProxyTime, o as ClientImage, ot as QueuePrediction, p as Drill, pt as RequestPrediction, q as Outcomes, r as Cell, rt as QueueBand, s as Cluster, st as Reconnects, t as BuildImage, tt as ProxyHop, u as ConntrackPrediction, ut as ReplicaSet, v as FabricManifest, vt as RunDrill, w as GroupRole, wt as RunStream, x as Group, xt as RunPart, y as Fault, yt as RunFabric, z as LoadBand, zt as latestEndOf } from "./cell-Ckoqr7Xc.js";
2
2
  import { Quantity } from "@mark1russell7/quantity";
3
- import { LoadMeasure, Schedule } from "@mark1russell7/rigor-chaos";
3
+ import { DiskFault, LoadMeasure, Schedule } from "@mark1russell7/rigor-chaos";
4
4
  import { StartedTestContainer } from "testcontainers";
5
5
  /**
6
6
  * This module reads the acts of the program of the observer: its heartbeat, its drop of the
@@ -892,8 +892,10 @@ interface FaultOptions {
892
892
  /** This length is the longest segment in bytes that an MTU drop lets through. */
893
893
  readonly above?: number;
894
894
  /**
895
- * This value lets each SYN of a reset pass. The connect then succeeds, and the next segment of
896
- * the peer gets the reset. Without it, the SYN also gets the reset.
895
+ * This value lets each SYN of a reset pass, and each segment with no data. The connect then
896
+ * succeeds, the target accepts the connection, and the first segment of the peer with data gets
897
+ * the reset. Without it, the SYN also gets the reset. The match needs an IP header of an odd
898
+ * number of words: a header with no options has 5, as in each lab.
897
899
  */
898
900
  readonly handshake?: "pass";
899
901
  /** These are the addresses that the rule faces, in place of the peer of its place. */
@@ -2423,6 +2425,128 @@ export declare const DEBUG = "the record is of a local debug run, and no page re
2423
2425
  * of a schedule refuses it. A commit with changes to tracked files is not a pin.
2424
2426
  */
2425
2427
  export declare const recordProblems: (record: Pinnable) => string[];
2428
+ /**
2429
+ * The disk tier applies a disk plan of `@mark1russell7/rigor-chaos` to the files of a program. Each fault starts one new
2430
+ * container of the shipped image `lazyfs`. LazyFS is a FUSE file system that keeps each write in its cache until an
2431
+ * fsync.
2432
+ *
2433
+ * The writer of the subject writes its files on the mount of LazyFS, and the fault stops it at its point. Then
2434
+ * `lazyfs::clear-cache` loses each write of data after the last fsync: the state of the disk after a power cut. LazyFS
2435
+ * applies each new file, each rename and each unlink at once, so the cut keeps each directory entry. This is the rule
2436
+ * of the kind `lose-unsynced`. The check of the subject reads the files that the disk kept, and writes one JSON value. The record
2437
+ * keeps that value.
2438
+ *
2439
+ * A point at a step uses the stop points of `@mark1russell7/rigor-testkit/stop` in the writer: the writer stops itself
2440
+ * at the step with `SIGKILL`. A point at a time stops the writer with `SIGKILL` after that time from its start.
2441
+ *
2442
+ * The container is privileged: it needs `/dev/fuse` and a mount. The AppArmor profile of Docker refuses a FUSE mount in
2443
+ * a container that is not privileged. Thus the tier operates only in CI, in the workflow `disk.yml`.
2444
+ */
2445
+ /** The folder of the subject in the container. */
2446
+ export declare const DISK_SUBJECT = "/opt/subject";
2447
+ /** The mount of LazyFS in the container. The writer operates in this folder. */
2448
+ export declare const DISK_MOUNT = "/mnt/disk";
2449
+ /** The folder that holds the files under the mount. The check operates in this folder after the fault. */
2450
+ export declare const DISK_ROOT = "/var/disk";
2451
+ /** The format of a record of the disk tier. */
2452
+ export declare const DISK_RECORD_FORMAT = "harness-disk/1";
2453
+ /** The subject of the disk tier: a folder with a writer and a check. */
2454
+ interface DiskSubject {
2455
+ /** The name of the subject, for the record. */
2456
+ readonly name: string;
2457
+ /** The folder of the subject on this machine. The tier copies it to `DISK_SUBJECT` in each container. */
2458
+ readonly folder: string;
2459
+ /** The argv of the writer, with no shell. It operates in `DISK_MOUNT`. An example is `["node", "/opt/subject/writer.mjs"]`. */
2460
+ readonly writer: readonly [string, ...string[]];
2461
+ /** The argv of the check, with no shell. It operates in `DISK_ROOT` after the fault, and writes one JSON value. */
2462
+ readonly check: readonly [string, ...string[]];
2463
+ /** The variables of the environment of the writer and of the check. */
2464
+ readonly env?: Readonly<Record<string, string>>;
2465
+ /** The time in ms for the writer of a fault at a step. The default is 60 000. After it, the writer gets `SIGKILL`. */
2466
+ readonly timeoutMs?: number;
2467
+ }
2468
+ /** The options of `openDiskLab`. */
2469
+ interface DiskLabOptions {
2470
+ readonly subject: DiskSubject;
2471
+ /** The commit of the code that operates, and if its tracked files have changes. The record keeps it. */
2472
+ readonly code: RecordCode;
2473
+ }
2474
+ /** The image of the disk tier: its tag, and the record of its build. */
2475
+ interface DiskImage {
2476
+ readonly tag: string;
2477
+ readonly build?: BuildRecord;
2478
+ }
2479
+ /** A disk lab holds the parts that stay the same from one fault of a plan to the next. */
2480
+ interface DiskLab {
2481
+ readonly subject: DiskSubject;
2482
+ /** The sha256 of the path and the content of each file of the subject folder. */
2483
+ readonly digest: string;
2484
+ readonly image: DiskImage;
2485
+ readonly code: RecordCode;
2486
+ readonly substrate: Substrate;
2487
+ }
2488
+ /** The record of the writer of one fault. */
2489
+ interface DiskWriterRecord {
2490
+ /** The exit code of the writer. A stop with `SIGKILL` gives 137. */
2491
+ readonly exit: number;
2492
+ /** This value is `true` when the fault stopped the writer at its point. A writer that ends first gives `false`. */
2493
+ readonly stopped: boolean;
2494
+ /** The number of the stop points that the writer got to. */
2495
+ readonly steps: number;
2496
+ /** The last stop point that the writer got to, or `null` when it got to no point. */
2497
+ readonly lastStep: number | null;
2498
+ readonly lastLabel: string | null;
2499
+ /** The time in ms from the start of the writer to its end. */
2500
+ readonly ms: number;
2501
+ /** The last characters of the output of the writer. */
2502
+ readonly output: string;
2503
+ }
2504
+ /** The record of one fault of a disk plan. */
2505
+ interface DiskRecord {
2506
+ readonly format: typeof DISK_RECORD_FORMAT;
2507
+ readonly fault: DiskFault;
2508
+ readonly subject: {
2509
+ readonly name: string;
2510
+ readonly digest: string;
2511
+ };
2512
+ /** The image: its tag, the id of the image of the container, and the record of its build. */
2513
+ readonly image: DiskImage & {
2514
+ readonly id: string;
2515
+ };
2516
+ readonly code: RecordCode;
2517
+ readonly substrate: Substrate;
2518
+ readonly writer: DiskWriterRecord;
2519
+ /** The JSON value that the check wrote: what the disk kept. */
2520
+ readonly persisted: unknown;
2521
+ /** The time when `runDiskFault` started the fault, in ISO 8601. */
2522
+ readonly at: string;
2523
+ }
2524
+ /** This function gives each problem of a subject of the disk tier. An empty list means that the subject is correct. */
2525
+ export declare const diskSubjectProblems: (subject: DiskSubject) => string[];
2526
+ /** This function gives the sha256 of the path and the content of each file under a folder, in a stable sequence. */
2527
+ export declare const folderDigest: (folder: string) => string;
2528
+ /**
2529
+ * This function builds the image `lazyfs` once, and gives the lab of a subject. It throws a `RangeError` for a subject
2530
+ * with problems. The lab reads the substrate of this machine: a container lab is the layer E1.
2531
+ */
2532
+ export declare const openDiskLab: (options: DiskLabOptions) => Promise<DiskLab>;
2533
+ /**
2534
+ * This function applies one fault of a disk plan in one new container, and gives its record. It throws a `RangeError`
2535
+ * for a fault with problems. The promise rejects when LazyFS does not clear its cache, or when the check does not end
2536
+ * with the code 0 and one JSON value. Thus a check that cannot read the disk gives no record. The time limit of the
2537
+ * cut also covers the write of the command to LazyFS: that write waits when LazyFS did not start.
2538
+ */
2539
+ export declare const runDiskFault: (lab: DiskLab, fault: DiskFault) => Promise<DiskRecord>;
2540
+ /** These are the parts of a disk record that tell if it pins its code and its image. */
2541
+ interface DiskPinnable {
2542
+ readonly code?: RecordCode | undefined;
2543
+ readonly image: DiskImage;
2544
+ }
2545
+ /**
2546
+ * This function gives each problem of the pins of a disk record. The pins are the commit of the code and the image with
2547
+ * its build record. A checkout with changes is also a problem. A record with a problem is not a record.
2548
+ */
2549
+ export declare const diskRecordProblems: (record: DiskPinnable) => string[];
2426
2550
  /**
2427
2551
  * This function does one run of a recovery drill:
2428
2552
  * - The set converges, and it loses its writes. The tenants get their data, and a hash reads it.
@@ -2775,4 +2899,4 @@ export declare const environmentCounts: (cell: Cell, runs: number) => number[];
2775
2899
  * Each environment does a warm-up first, and the result keeps it apart from the counted runs.
2776
2900
  */
2777
2901
  export declare const runCell: (cell: Cell, say?: (line: string) => void) => Promise<CellResult>;
2778
- export { type Agent, type BuildImage, type BuildRecord, CLIENT_CAPABILITIES, type CallReading, type Cell, type CellResult, type Client, type ClientCapability, type ClientImage, type ClockPair, type Cloud, type Cluster, type ClusterClientAt, type ClusterLab, type ClusterStage, type ConntrackPrediction, type ConntrackReading, type ContextFile, type CountBand, type Crossings, type Cut, type Decision, type DeliveryPrediction, type DeliveryReading, type DeliveryStream, type Drill, type DrillRoom, type DriverBand, type DriverSocket, type DriverStep, type DriverStepTime, type ErrorOnTheWay, type EstimateVerdict, type Fabric, type FabricLab, type FabricManifest, type FabricParts, type Fault, type FaultOptions, type FaultPlace, type FaultSide, type Group, type GroupClient, type GroupLab, type GroupMeasured, type GroupNetworkFault, type GroupPlace, type GroupPrediction, type GroupReading, type GroupRole, type GroupVerdict, type GroupView, type Hop, type HopEvent, type HopPlace, type HopSignal, type HopWrite, type Host, type HostSetting, type HostSysctl, type HttpProbe, type ImagePlan, type ImageSource, type Interval, type Jitter, type Kafka, type KafkaLab, type KafkaMember, type KafkaPause, type KernelRecord, type Lab, type Layer, type LeafViews, type LineCount, type LineMatch, type LoadBand, type LoadJudgement, type LoadPlan, type LoadPrediction, type LoadSpread, type LoadStream, type LoadVerdict, type Manifest, type ManifestHop, type Measured, type MemberLine, type MiddleboxEvent, type MiddleboxExpectation, type MiddleboxForm, type NetworkFault, type NodeLine, type Observer, type OplogRead, type OplogTime, type Outcome, type Outcomes, type Pair, type PairSets, type Pairing, type PartitionView, type PauseBand, type PauseCommit, type PausePrediction, type PauseReading, type Pinnable, type PinnedImage, type PortsPrediction, type PortsReading, type Prediction, type Probe, type ProbeEvent, type ProgramEvent, type ProxyHop, type ProxyTime, type QueueBand, type QueueConnection, type QueueConnectionReading, type QueueEnd, type QueuePrediction, type QueueReading, type ReconnectReading, type ReconnectVerdict, type Reconnects, type RecordCode, type Recovers, type RecoveryMeasured, type Reference, type Reordering, type ReplicaSet, type ReplicaSetLab, type ReplicaSetStage, type Replies, type RequestPrediction, type RequestReading, type RouteLine, type RouterHop, type RttRange, type Run, type RunBackup, type RunDrill, type RunEstimate, type RunFabric, type RunGroup, type RunLoad, type RunPart, type RunPause, type RunRoute, type RunStream, type RunTopology, type SentinelEvent, type SentinelStage, type Shipped, type ShippedImage, type Sibling, type SocketPlace, type Spread, type Stage, type StageBand, type StageVerdict, type StallReading, type Stamp, type Status, type StatusRow, type Subject, type Substrate, type SubstrateSource, type Target, type TimeFromFault, type Topology, type Toxic, type Verdict, type WallStamp, type Writes, type WsProbe, environmentProblems, isHopPlace, latestEndOf };
2902
+ export { type Agent, type BuildImage, type BuildRecord, CLIENT_CAPABILITIES, type CallReading, type Cell, type CellResult, type Client, type ClientCapability, type ClientImage, type ClockPair, type Cloud, type Cluster, type ClusterClientAt, type ClusterLab, type ClusterStage, type ConntrackPrediction, type ConntrackReading, type ContextFile, type CountBand, type Crossings, type Cut, type Decision, type DeliveryPrediction, type DeliveryReading, type DeliveryStream, type DiskImage, type DiskLab, type DiskLabOptions, type DiskPinnable, type DiskRecord, type DiskSubject, type DiskWriterRecord, type Drill, type DrillRoom, type DriverBand, type DriverSocket, type DriverStep, type DriverStepTime, type ErrorOnTheWay, type EstimateVerdict, type Fabric, type FabricLab, type FabricManifest, type FabricParts, type Fault, type FaultOptions, type FaultPlace, type FaultSide, type Group, type GroupClient, type GroupLab, type GroupMeasured, type GroupNetworkFault, type GroupPlace, type GroupPrediction, type GroupReading, type GroupRole, type GroupVerdict, type GroupView, type Hop, type HopEvent, type HopPlace, type HopSignal, type HopWrite, type Host, type HostSetting, type HostSysctl, type HttpProbe, type ImagePlan, type ImageSource, type Interval, type Jitter, type Kafka, type KafkaLab, type KafkaMember, type KafkaPause, type KernelRecord, type Lab, type Layer, type LeafViews, type LineCount, type LineMatch, type LoadBand, type LoadJudgement, type LoadPlan, type LoadPrediction, type LoadSpread, type LoadStream, type LoadVerdict, type Manifest, type ManifestHop, type Measured, type MemberLine, type MiddleboxEvent, type MiddleboxExpectation, type MiddleboxForm, type NetworkFault, type NodeLine, type Observer, type OplogRead, type OplogTime, type Outcome, type Outcomes, type Pair, type PairSets, type Pairing, type PartitionView, type PauseBand, type PauseCommit, type PausePrediction, type PauseReading, type Pinnable, type PinnedImage, type PortsPrediction, type PortsReading, type Prediction, type Probe, type ProbeEvent, type ProgramEvent, type ProxyHop, type ProxyTime, type QueueBand, type QueueConnection, type QueueConnectionReading, type QueueEnd, type QueuePrediction, type QueueReading, type ReconnectReading, type ReconnectVerdict, type Reconnects, type RecordCode, type Recovers, type RecoveryMeasured, type Reference, type Reordering, type ReplicaSet, type ReplicaSetLab, type ReplicaSetStage, type Replies, type RequestPrediction, type RequestReading, type RouteLine, type RouterHop, type RttRange, type Run, type RunBackup, type RunDrill, type RunEstimate, type RunFabric, type RunGroup, type RunLoad, type RunPart, type RunPause, type RunRoute, type RunStream, type RunTopology, type SentinelEvent, type SentinelStage, type Shipped, type ShippedImage, type Sibling, type SocketPlace, type Spread, type Stage, type StageBand, type StageVerdict, type StallReading, type Stamp, type Status, type StatusRow, type Subject, type Substrate, type SubstrateSource, type Target, type TimeFromFault, type Topology, type Toxic, type Verdict, type WallStamp, type Writes, type WsProbe, environmentProblems, isHopPlace, latestEndOf };
package/build/index.js CHANGED
@@ -1,15 +1,16 @@
1
- import { A as unlockedManifests, B as environmentProblems, C as programOf, D as subjectProblems, E as subjectClient, F as jarVersions, H as latestEndOf, I as locksOf, L as npmVersions, M as LOCK_NAMES, N as cargoVersions, O as targetImageOf, P as goVersions, R as versionsOf, S as planOf, T as shippedSource, U as requestFirst, V as isHopPlace, _ as kafkaClientImage, a as SHIPPED_NAMES, b as nodeHttpImage, c as buildRecordOf, d as harnessImage, f as harnessVersion, g as inContext, h as imageProblems, i as SHIPPED_CLIENTS, j as unpinnedBases, k as targetSourceOf, l as goHttpImage, m as imageOf, n as PINNED, o as amqpClientImage, p as hikariClientImage, r as REPOSITORY, s as basesOf, t as CLIENT_NAMES, u as grpcClientImage, v as mongoClientImage, w as routerImage, x as pgClientImage, y as nodeClientImage, z as CLIENT_CAPABILITIES } from "./image-D509StXX.js";
1
+ import { A as targetSourceOf, B as CLIENT_CAPABILITIES, C as programOf, D as subjectClient, E as sources, F as goVersions, H as isHopPlace, I as jarVersions, L as locksOf, M as unpinnedBases, N as LOCK_NAMES, O as subjectProblems, P as cargoVersions, R as npmVersions, S as planOf, T as shippedSource, U as latestEndOf, V as environmentProblems, W as requestFirst, _ as kafkaClientImage, a as SHIPPED_NAMES, b as nodeHttpImage, c as buildRecordOf, d as harnessImage, f as harnessVersion, g as inContext, h as imageProblems, i as SHIPPED_CLIENTS, j as unlockedManifests, k as targetImageOf, l as goHttpImage, m as imageOf, n as PINNED, o as amqpClientImage, p as hikariClientImage, r as REPOSITORY, s as basesOf, t as CLIENT_NAMES, u as grpcClientImage, v as mongoClientImage, w as routerImage, x as pgClientImage, y as nodeClientImage, z as versionsOf } from "./image-Bs5hV85M.js";
2
2
  import { quantity, valueIn } from "@mark1russell7/quantity";
3
3
  import { median, medianInterval as medianInterval$1, quantile, quantileSorted } from "@mark1russell7/rigor-statistics";
4
4
  import { rungVerdict } from "@mark1russell7/rigor-bench";
5
- import { closedLoopPlan, measureLoad, schedule, scheduleHeld } from "@mark1russell7/rigor-chaos";
5
+ import { checkDiskFault, closedLoopPlan, measureLoad, schedule, scheduleHeld, stopTriggerOf } from "@mark1russell7/rigor-chaos";
6
6
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
7
7
  import { createHash, randomBytes } from "node:crypto";
8
8
  import { execFile } from "node:child_process";
9
9
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
10
10
  import { release, tmpdir } from "node:os";
11
- import { join } from "node:path";
12
- import { existsSync, readFileSync } from "node:fs";
11
+ import { join, relative, resolve } from "node:path";
12
+ import { existsSync, readFileSync, statSync } from "node:fs";
13
+ import { STOP_ENV, parseProgress, stopOrderOf } from "@mark1russell7/rigor-testkit/stop";
13
14
  // src/load.ts
14
15
  /**
15
16
  * The measure and the verdict of an open-loop cell (SYS-68). A client on a schedule sends each
@@ -5387,6 +5388,190 @@ const recordProblems = (record) => [.../* @__PURE__ */ new Set([
5387
5388
  ...record.manifests.flatMap((manifest) => manifestProblems(manifest)),
5388
5389
  ...record.debug === true ? [DEBUG] : []
5389
5390
  ])];
5391
+ // src/disk.ts
5392
+ /**
5393
+ * The disk tier applies a disk plan of `@mark1russell7/rigor-chaos` to the files of a program. Each fault starts one new
5394
+ * container of the shipped image `lazyfs`. LazyFS is a FUSE file system that keeps each write in its cache until an
5395
+ * fsync.
5396
+ *
5397
+ * The writer of the subject writes its files on the mount of LazyFS, and the fault stops it at its point. Then
5398
+ * `lazyfs::clear-cache` loses each write of data after the last fsync: the state of the disk after a power cut. LazyFS
5399
+ * applies each new file, each rename and each unlink at once, so the cut keeps each directory entry. This is the rule
5400
+ * of the kind `lose-unsynced`. The check of the subject reads the files that the disk kept, and writes one JSON value. The record
5401
+ * keeps that value.
5402
+ *
5403
+ * A point at a step uses the stop points of `@mark1russell7/rigor-testkit/stop` in the writer: the writer stops itself
5404
+ * at the step with `SIGKILL`. A point at a time stops the writer with `SIGKILL` after that time from its start.
5405
+ *
5406
+ * The container is privileged: it needs `/dev/fuse` and a mount. The AppArmor profile of Docker refuses a FUSE mount in
5407
+ * a container that is not privileged. Thus the tier operates only in CI, in the workflow `disk.yml`.
5408
+ */
5409
+ /** The folder of the subject in the container. */
5410
+ const DISK_SUBJECT = "/opt/subject";
5411
+ /** The mount of LazyFS in the container. The writer operates in this folder. */
5412
+ const DISK_MOUNT = "/mnt/disk";
5413
+ /** The folder that holds the files under the mount. The check operates in this folder after the fault. */
5414
+ const DISK_ROOT = "/var/disk";
5415
+ /** The format of a record of the disk tier. */
5416
+ const DISK_RECORD_FORMAT = "harness-disk/1";
5417
+ const FAULTS = "/run/lazyfs/faults.fifo";
5418
+ const DONE = "/run/lazyfs/done.fifo";
5419
+ const PROGRESS = "/tmp/rigor-progress.jsonl";
5420
+ /** The default time in ms for the writer of a fault at a step. */
5421
+ const WRITER_MS = 6e4;
5422
+ /** The time in s for the clear of the cache. */
5423
+ const CLEAR_S = 30;
5424
+ const isArgv = (value) => Array.isArray(value) && value.length > 0 && value.every((part) => typeof part === "string" && part.length > 0);
5425
+ /** This function gives each problem of a subject of the disk tier. An empty list means that the subject is correct. */
5426
+ const diskSubjectProblems = (subject) => {
5427
+ const problems = [];
5428
+ if (typeof subject.name !== "string" || subject.name.length === 0) problems.push("the subject has no name");
5429
+ if (typeof subject.folder !== "string" || subject.folder.length === 0) problems.push("the subject has no folder");
5430
+ else if (!statSync(subject.folder, { throwIfNoEntry: false })?.isDirectory()) problems.push(`the folder ${subject.folder} of the subject is not a folder`);
5431
+ if (!isArgv(subject.writer)) problems.push("the writer is not an argv: a list of one or more texts");
5432
+ if (!isArgv(subject.check)) problems.push("the check is not an argv: a list of one or more texts");
5433
+ const timeoutMs = subject.timeoutMs;
5434
+ if (timeoutMs !== void 0 && !(Number.isFinite(timeoutMs) && timeoutMs > 0)) problems.push(`the timeoutMs of the subject is a positive number of ms, not ${String(timeoutMs)}`);
5435
+ return problems;
5436
+ };
5437
+ /** This function gives the sha256 of the path and the content of each file under a folder, in a stable sequence. */
5438
+ const folderDigest = (folder) => {
5439
+ const root = resolve(folder);
5440
+ const hash = createHash("sha256");
5441
+ for (const file of sources(root)) {
5442
+ hash.update(`${relative(root, file).replaceAll("\\", "/")}\n`);
5443
+ hash.update(createHash("sha256").update(readFileSync(file)).digest("hex"));
5444
+ hash.update("\n");
5445
+ }
5446
+ return `sha256:${hash.digest("hex")}`;
5447
+ };
5448
+ /**
5449
+ * This function builds the image `lazyfs` once, and gives the lab of a subject. It throws a `RangeError` for a subject
5450
+ * with problems. The lab reads the substrate of this machine: a container lab is the layer E1.
5451
+ */
5452
+ const openDiskLab = async (options) => {
5453
+ const problems = diskSubjectProblems(options.subject);
5454
+ if (problems.length > 0) throw new RangeError(`openDiskLab: ${problems.join("; ")}`);
5455
+ const source = shippedSource("lazyfs");
5456
+ const tag = await imageOf(source);
5457
+ const build = buildRecordOf(source);
5458
+ return {
5459
+ subject: options.subject,
5460
+ digest: folderDigest(options.subject.folder),
5461
+ image: {
5462
+ tag,
5463
+ ...build === void 0 ? {} : { build }
5464
+ },
5465
+ code: options.code,
5466
+ substrate: substrateHere("E1")
5467
+ };
5468
+ };
5469
+ const tail = (text) => text.slice(-4e3);
5470
+ /**
5471
+ * This function applies one fault of a disk plan in one new container, and gives its record. It throws a `RangeError`
5472
+ * for a fault with problems. The promise rejects when LazyFS does not clear its cache, or when the check does not end
5473
+ * with the code 0 and one JSON value. Thus a check that cannot read the disk gives no record. The time limit of the
5474
+ * cut also covers the write of the command to LazyFS: that write waits when LazyFS did not start.
5475
+ */
5476
+ const runDiskFault = async (lab, fault) => {
5477
+ const problems = checkDiskFault(fault);
5478
+ if (problems.length > 0) throw new RangeError(`runDiskFault: ${problems.join(" ")}`);
5479
+ const trigger = stopTriggerOf(fault.at);
5480
+ if (trigger === void 0) throw new RangeError(`runDiskFault: the point of the fault is not a step or a time.`);
5481
+ const at = (/* @__PURE__ */ new Date()).toISOString();
5482
+ const { GenericContainer, Wait, getContainerRuntimeClient } = await containers();
5483
+ const container = await new GenericContainer(lab.image.tag).withPrivilegedMode().withCopyDirectoriesToContainer([{
5484
+ source: resolve(lab.subject.folder),
5485
+ target: DISK_SUBJECT
5486
+ }]).withWaitStrategy(Wait.forSuccessfulCommand(`mountpoint -q ${DISK_MOUNT}`).withStartupTimeout(6e4)).start();
5487
+ try {
5488
+ const runtime = await getContainerRuntimeClient();
5489
+ const id = (await runtime.container.inspect(runtime.container.getById(container.getId()))).Image;
5490
+ const env = lab.subject.env ?? {};
5491
+ const order = stopOrderOf({
5492
+ at: fault.at,
5493
+ signal: "SIGKILL"
5494
+ }, PROGRESS);
5495
+ const seconds = trigger.measure === "ms" ? trigger.value / 1e3 : (lab.subject.timeoutMs ?? WRITER_MS) / 1e3;
5496
+ const started = performance.now();
5497
+ const write = await container.exec([
5498
+ "timeout",
5499
+ "-s",
5500
+ "KILL",
5501
+ String(seconds),
5502
+ ...lab.subject.writer
5503
+ ], {
5504
+ workingDir: DISK_MOUNT,
5505
+ env: {
5506
+ ...env,
5507
+ [STOP_ENV]: JSON.stringify(order)
5508
+ }
5509
+ });
5510
+ const ms = performance.now() - started;
5511
+ const cut = await container.exec([
5512
+ "timeout",
5513
+ String(CLEAR_S),
5514
+ "sh",
5515
+ "-c",
5516
+ `printf 'lazyfs::clear-cache\\n' > ${FAULTS} && head -n 1 ${DONE}`
5517
+ ]);
5518
+ if (cut.exitCode !== 0 || cut.stdout.trim() !== "finished::clear-cache") {
5519
+ const limit = cut.exitCode === 124 ? `, the limit of ${CLEAR_S} s` : "";
5520
+ throw new Error(`runDiskFault: LazyFS did not clear its cache (exit ${cut.exitCode}${limit}): ${tail(cut.output.trim())}`);
5521
+ }
5522
+ const progress = await container.exec(["cat", PROGRESS]);
5523
+ const lines = parseProgress(progress.exitCode === 0 ? progress.stdout : "");
5524
+ const last = lines.at(-1);
5525
+ const check = await container.exec([...lab.subject.check], {
5526
+ workingDir: DISK_ROOT,
5527
+ env: { ...env }
5528
+ });
5529
+ if (check.exitCode !== 0) throw new Error(`runDiskFault: the check ended with the code ${check.exitCode}: ${tail(check.output.trim())}`);
5530
+ let persisted;
5531
+ try {
5532
+ persisted = JSON.parse(check.stdout);
5533
+ } catch (error) {
5534
+ throw new Error(`runDiskFault: the output of the check is not one JSON value: ${tail(check.stdout.trim())}`, { cause: error });
5535
+ }
5536
+ const stopped = trigger.measure === "step" ? lines.some((line) => line.stop === true) : write.exitCode === 137;
5537
+ return {
5538
+ format: DISK_RECORD_FORMAT,
5539
+ fault,
5540
+ subject: {
5541
+ name: lab.subject.name,
5542
+ digest: lab.digest
5543
+ },
5544
+ image: {
5545
+ ...lab.image,
5546
+ id
5547
+ },
5548
+ code: lab.code,
5549
+ substrate: lab.substrate,
5550
+ writer: {
5551
+ exit: write.exitCode,
5552
+ stopped,
5553
+ steps: lines.length,
5554
+ lastStep: last?.step ?? null,
5555
+ lastLabel: last?.label ?? null,
5556
+ ms,
5557
+ output: tail(write.output)
5558
+ },
5559
+ persisted,
5560
+ at
5561
+ };
5562
+ } finally {
5563
+ await container.stop(STOP);
5564
+ }
5565
+ };
5566
+ /**
5567
+ * This function gives each problem of the pins of a disk record. The pins are the commit of the code and the image with
5568
+ * its build record. A checkout with changes is also a problem. A record with a problem is not a record.
5569
+ */
5570
+ const diskRecordProblems = (record) => [.../* @__PURE__ */ new Set([
5571
+ ...commitProblems(record.code?.commit),
5572
+ ...record.code?.dirty === true ? [DIRTY] : [],
5573
+ ...imagePinProblems("the image lazyfs", record.image.tag, record.image.build)
5574
+ ])];
5390
5575
  // src/group.ts
5391
5576
  /** This function gives the configuration file of a member: its port, its settings, and the primary that a replica follows. */
5392
5577
  const memberConfig = (group, primary) => [
@@ -9312,6 +9497,6 @@ const runCell = async (cell, say = () => {}) => {
9312
9497
  target = larger;
9313
9498
  }
9314
9499
  };
9315
- export { AWS_FROM, CLIENT_CAPABILITIES, CLIENT_NAMES, CLOSED_TOLERANCE, CLOUDS, CLUSTER_STAGES, CONVERGE_MS, DAEMONS, DEBUG, DIRTY, DROP_HANDLING, FABRIC_CLIENT, FABRIC_DEVICE, FABRIC_TARGET, FRR_IMAGE, GIVES_AWAY, HASH_SCRIPT, INJECT, INSERT, KAFKA_TAIL_MS, KEPT, LAYERS, LINGER_MS, LISTING, LOAD_FORMAT, LOAD_PATH, LOCK_NAMES, LOSS_MARGIN, MEMBER_MARKS, MONITOR_DOWN, NODE_MARKS, NOISE, PINNED, PUMP, PUMP_SLACK, QUIET_MS, RELATIVE, REPLICA_SET_STAGES, REPOSITORY, RESTART, ROUTERS, SCHEDULE_PATH, SEED_DOCUMENT, SHIPPED_CLIENTS, SHIPPED_NAMES, STAGES, STANDBY_READY, STATUS_SCRIPT, STEPS, STEP_DOWN, amqpClientImage, basesOf, bootstrapOf, brokerEnv, buildOf, buildRecordOf, callOf, cancelsOf, cargoVersions, clockOffsetOf, closeOrExit, cloudOf, clusterArgs, clusterConf, clusterCutOf, clusterHostsOf, clusterOnce, clusterStagesOf, clusterViewOf, commitProblems, commitVoid, comparable, controllerEnv, crossingsOf, cutOf, deadlineOf, delayVoids, deliveryFinding, deliveryOf, deviceOf, drillOnce, drillSpan, dropFinding, dropOf, endpointAfter, envOf, environmentCounts, environmentProblems, errorsOf, estimateOf, estimateVerdict, exitOf, fieldOf, fieldsOf, firstUnanswered, frrConf, goHttpImage, goVersions, groupOnce, groupVerdictOf, grpcClientImage, harnessImage, harnessRecord, harnessVersion, hashOf, highestHeld, hikariClientImage, hzOf, imageOf, imagePinProblems, imageProblems, inContext, infoOf, initiateScript, isFenceLine, isHopPlace, jarVersions, jitterOf, jitterOfLines, judge, kafkaArgs, kafkaClientImage, kafkaCutOf, kafkaOnce, kafkaPauseOnce, kafkaViewOf, lagsOf, laterMove, latestEndOf, leafLacks, leftAfter, loadOf, loadPlanOf, loadVerdict, locksOf, logNameOf, logTimeOf, manifestProblems, matches, measure, measureConntrack, measureDriver, measureGroup, measurePause, measurePorts, measureQueue, medianInterval, memAvailableOf, memberCommand, memberConfig, memberLineOf, mongoClientImage, monotonicAt, monotonicOf, namesGroup, nodeClientImage, nodeCommand, nodeHttpImage, nodeIdOf, nodeLineOf, nodeNameOf, nodesOnMonotonic, noiseOf, npmVersions, numbersOf, onMonotonic, openClusterLab, openFabric, openGroupLab, openKafkaLab, openLab, openReplicaSetLab, openStandby, pairArgs, pairOnce, pairingOf, pairingsOf, pauseReady, peersOf, pgClientImage, pingsOf, plainOf, planOf, pongsOf, poolOf, programLines, programOf, quantileOf, readCpu, readHost, readOplog, reconnectFinding, reconnectOf, recordProblems, recoveryFindings, recoveryOf, referenceOf, reorderingOf, replicaSetArgs, replicaSetOnce, replicaSetStagesOf, requestOf, requestWords, restamped, roomNeeded, roomVoidOf, routeLine, routerImage, routesOf, runCell, seedScript, sentinelConfig, sessionsOf, shippedClientRecord, shippedSource, sliceQuery, socketAt, socketOf, socketsOf, spread, spreadOf, stagesOf, standaloneCommand, standbyCommand, statusViewOf, stealShare, stopScript, streamEnded, streamOf, streamsLoadOf, subjectClient, subjectProblems, subscriptionsOf, substrateHere, substrateKey, substrateOf, substrateOn, targetImageOf, targetSourceOf, templated, toolJsonOf, topicOf, topologyOf, toxicBody, unlockedManifests, unpinnedBases, unpoolable, verdictOf, versionsOf, viewOf, writesOf };
9500
+ export { AWS_FROM, CLIENT_CAPABILITIES, CLIENT_NAMES, CLOSED_TOLERANCE, CLOUDS, CLUSTER_STAGES, CONVERGE_MS, DAEMONS, DEBUG, DIRTY, DISK_MOUNT, DISK_RECORD_FORMAT, DISK_ROOT, DISK_SUBJECT, DROP_HANDLING, FABRIC_CLIENT, FABRIC_DEVICE, FABRIC_TARGET, FRR_IMAGE, GIVES_AWAY, HASH_SCRIPT, INJECT, INSERT, KAFKA_TAIL_MS, KEPT, LAYERS, LINGER_MS, LISTING, LOAD_FORMAT, LOAD_PATH, LOCK_NAMES, LOSS_MARGIN, MEMBER_MARKS, MONITOR_DOWN, NODE_MARKS, NOISE, PINNED, PUMP, PUMP_SLACK, QUIET_MS, RELATIVE, REPLICA_SET_STAGES, REPOSITORY, RESTART, ROUTERS, SCHEDULE_PATH, SEED_DOCUMENT, SHIPPED_CLIENTS, SHIPPED_NAMES, STAGES, STANDBY_READY, STATUS_SCRIPT, STEPS, STEP_DOWN, amqpClientImage, basesOf, bootstrapOf, brokerEnv, buildOf, buildRecordOf, callOf, cancelsOf, cargoVersions, clockOffsetOf, closeOrExit, cloudOf, clusterArgs, clusterConf, clusterCutOf, clusterHostsOf, clusterOnce, clusterStagesOf, clusterViewOf, commitProblems, commitVoid, comparable, controllerEnv, crossingsOf, cutOf, deadlineOf, delayVoids, deliveryFinding, deliveryOf, deviceOf, diskRecordProblems, diskSubjectProblems, drillOnce, drillSpan, dropFinding, dropOf, endpointAfter, envOf, environmentCounts, environmentProblems, errorsOf, estimateOf, estimateVerdict, exitOf, fieldOf, fieldsOf, firstUnanswered, folderDigest, frrConf, goHttpImage, goVersions, groupOnce, groupVerdictOf, grpcClientImage, harnessImage, harnessRecord, harnessVersion, hashOf, highestHeld, hikariClientImage, hzOf, imageOf, imagePinProblems, imageProblems, inContext, infoOf, initiateScript, isFenceLine, isHopPlace, jarVersions, jitterOf, jitterOfLines, judge, kafkaArgs, kafkaClientImage, kafkaCutOf, kafkaOnce, kafkaPauseOnce, kafkaViewOf, lagsOf, laterMove, latestEndOf, leafLacks, leftAfter, loadOf, loadPlanOf, loadVerdict, locksOf, logNameOf, logTimeOf, manifestProblems, matches, measure, measureConntrack, measureDriver, measureGroup, measurePause, measurePorts, measureQueue, medianInterval, memAvailableOf, memberCommand, memberConfig, memberLineOf, mongoClientImage, monotonicAt, monotonicOf, namesGroup, nodeClientImage, nodeCommand, nodeHttpImage, nodeIdOf, nodeLineOf, nodeNameOf, nodesOnMonotonic, noiseOf, npmVersions, numbersOf, onMonotonic, openClusterLab, openDiskLab, openFabric, openGroupLab, openKafkaLab, openLab, openReplicaSetLab, openStandby, pairArgs, pairOnce, pairingOf, pairingsOf, pauseReady, peersOf, pgClientImage, pingsOf, plainOf, planOf, pongsOf, poolOf, programLines, programOf, quantileOf, readCpu, readHost, readOplog, reconnectFinding, reconnectOf, recordProblems, recoveryFindings, recoveryOf, referenceOf, reorderingOf, replicaSetArgs, replicaSetOnce, replicaSetStagesOf, requestOf, requestWords, restamped, roomNeeded, roomVoidOf, routeLine, routerImage, routesOf, runCell, runDiskFault, seedScript, sentinelConfig, sessionsOf, shippedClientRecord, shippedSource, sliceQuery, socketAt, socketOf, socketsOf, spread, spreadOf, stagesOf, standaloneCommand, standbyCommand, statusViewOf, stealShare, stopScript, streamEnded, streamOf, streamsLoadOf, subjectClient, subjectProblems, subscriptionsOf, substrateHere, substrateKey, substrateOf, substrateOn, targetImageOf, targetSourceOf, templated, toolJsonOf, topicOf, topologyOf, toxicBody, unlockedManifests, unpinnedBases, unpoolable, verdictOf, versionsOf, viewOf, writesOf };
9316
9501
 
9317
9502
  //# sourceMappingURL=index.js.map