@operad-io/dev 0.0.1 → 0.1.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/settings.ts CHANGED
@@ -123,6 +123,8 @@ export interface WorkSettings {
123
123
  export interface GateSettings {
124
124
  readonly commands: readonly CheckCommand[];
125
125
  readonly commandTimeoutSecs: number;
126
+ /** How long a gate command may write nothing; unset turns the limit off. */
127
+ readonly stallSecs?: number;
126
128
  /** The most checks of this repository that run at once; unset means no limit of its own. */
127
129
  readonly places?: number;
128
130
  }
@@ -204,8 +206,11 @@ export interface ReviewerSettings {
204
206
  * reviewer's own for that review. Every later review uses the reviewer's.
205
207
  */
206
208
  readonly first?: ReviewerFirst | undefined;
207
- /** The step used when the primary reviewer is unavailable. */
208
- readonly fallback?: ReviewerFallback | undefined;
209
+ /**
210
+ * The step, or the steps in order, used when the primary reviewer is
211
+ * unavailable or does not write the report.
212
+ */
213
+ readonly fallback?: ReviewerFallback | readonly ReviewerFallback[] | undefined;
209
214
  readonly timeoutSecs: number;
210
215
  /** How long a review may print nothing; unset uses the harness default. */
211
216
  readonly stallSecs?: number | undefined;
@@ -610,7 +615,12 @@ function gateSettings(value: unknown, field: string): GateSettings {
610
615
  throw new DevError(field, "must be an object");
611
616
  }
612
617
  for (const key of Object.keys(value)) {
613
- if (key !== "commands" && key !== "commandTimeoutSecs" && key !== "places") {
618
+ if (
619
+ key !== "commands" &&
620
+ key !== "commandTimeoutSecs" &&
621
+ key !== "stallSecs" &&
622
+ key !== "places"
623
+ ) {
614
624
  throw new DevError(`${field}.${key}`, "is not a gate setting");
615
625
  }
616
626
  }
@@ -623,6 +633,9 @@ function gateSettings(value: unknown, field: string): GateSettings {
623
633
  value.commandTimeoutSecs === undefined
624
634
  ? DEFAULT_DEV_SETTINGS.gate.commandTimeoutSecs
625
635
  : positiveSeconds(value.commandTimeoutSecs, `${field}.commandTimeoutSecs`),
636
+ ...(value.stallSecs === undefined
637
+ ? {}
638
+ : { stallSecs: positiveSeconds(value.stallSecs, `${field}.stallSecs`) }),
626
639
  ...(value.places === undefined
627
640
  ? {}
628
641
  : { places: positiveCount(value.places, `${field}.places`) }),
@@ -718,6 +731,25 @@ function fixLevelOf(value: unknown, field: string): FixLevel {
718
731
  return value;
719
732
  }
720
733
 
734
+ /** The fallbacks of a reviewer in the order they are tried. */
735
+ export function reviewerFallbacks(
736
+ fallback: ReviewerFallback | readonly ReviewerFallback[] | undefined,
737
+ ): readonly ReviewerFallback[] {
738
+ if (fallback === undefined) return [];
739
+ return Array.isArray(fallback) ? fallback : [fallback as ReviewerFallback];
740
+ }
741
+
742
+ function reviewerFallbackSetting(
743
+ value: unknown,
744
+ field: string,
745
+ ): ReviewerFallback | readonly ReviewerFallback[] {
746
+ if (!Array.isArray(value)) return reviewerFallback(value, field);
747
+ if (value.length === 0) throw new DevError(field, "must not be an empty list");
748
+ return value.map((entry, index) =>
749
+ reviewerFallback(entry, `${field}[${index}]`),
750
+ );
751
+ }
752
+
721
753
  function reviewerFallback(value: unknown, field: string): ReviewerFallback {
722
754
  if (!isRecord(value)) {
723
755
  throw new DevError(field, "must be an object");
@@ -800,7 +832,7 @@ function reviewerSettings(value: unknown, field: string): ReviewerSettings {
800
832
  const fallback =
801
833
  value.fallback === undefined
802
834
  ? undefined
803
- : reviewerFallback(value.fallback, `${field}.fallback`);
835
+ : reviewerFallbackSetting(value.fallback, `${field}.fallback`);
804
836
  return {
805
837
  use:
806
838
  value.use === undefined