@hestia-earth/engine-models 0.76.1 → 0.76.2

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.
@@ -1,29 +1,31 @@
1
1
  import { describe, expect, test } from '@jest/globals';
2
- import { NodeType } from '@hestia-earth/schema';
3
2
 
4
- import { validateConfig } from './validate-config';
3
+ import {
4
+ validateConfigOrder,
5
+ validateConfigDuplicates
6
+ } from './validate-config';
7
+ import { allowedTypes } from './config';
5
8
 
6
9
  describe('validate-config', () => {
7
- describe('validateConfig', () => {
8
- describe(NodeType.Cycle, () => {
9
- test('should be valid', () => {
10
- const results = validateConfig(NodeType.Cycle);
11
- expect(results).toEqual([]);
10
+ describe('validateConfigOrder', () => {
11
+ for (const nodeType of allowedTypes) {
12
+ describe(nodeType, () => {
13
+ test('should not have broken dependencies', () => {
14
+ const results = validateConfigOrder(nodeType);
15
+ expect(results).toEqual([]);
16
+ });
12
17
  });
13
- });
14
-
15
- describe(NodeType.ImpactAssessment, () => {
16
- test('should be valid', () => {
17
- const results = validateConfig(NodeType.ImpactAssessment);
18
- expect(results).toEqual([]);
19
- });
20
- });
18
+ }
19
+ });
21
20
 
22
- describe(NodeType.Site, () => {
23
- test('should be valid', () => {
24
- const results = validateConfig(NodeType.Site);
25
- expect(results).toEqual([]);
21
+ describe('validateConfigDuplicates', () => {
22
+ for (const nodeType of allowedTypes) {
23
+ describe(nodeType, () => {
24
+ test('should not have duplicates', () => {
25
+ const results = validateConfigDuplicates(nodeType);
26
+ expect(results).toEqual([]);
27
+ });
26
28
  });
27
- });
29
+ }
28
30
  });
29
31
  });
@@ -57,7 +57,13 @@ const matchDependencies =
57
57
  };
58
58
  };
59
59
 
60
- export const validateConfig = (nodeType: allowedType) => {
60
+ /**
61
+ * Use inter-dependencies to detect models that are in the wrong order.
62
+ *
63
+ * @param nodeType Cycle, Site, or ImpactAssessment
64
+ * @returns List of models that have dependencies that could not be found prior to running.
65
+ */
66
+ export const validateConfigOrder = (nodeType: allowedType) => {
61
67
  const config = loadConfig(nodeType);
62
68
  // flatten all models to process one by one, starting with the last one
63
69
  const models = config.models.flat();
@@ -66,3 +72,32 @@ export const validateConfig = (nodeType: allowedType) => {
66
72
 
67
73
  return results.filter((r) => r.missing.length > 0);
68
74
  };
75
+
76
+ const findDuplicatedConfigs = (models: IOrchestratorModelConfig[]) => {
77
+ const modelsByValue = models.reduce(
78
+ (prev, curr) => ({
79
+ ...prev,
80
+ [curr.value]: [...(prev[curr.value] || []), curr]
81
+ }),
82
+ {} as Record<string, IOrchestratorModelConfig[]>
83
+ );
84
+ return Object.values(modelsByValue)
85
+ .map((values) => values.filter((v) => !v.mergeArgs?.sameMethodModel))
86
+ .filter((values) => values.length > 1);
87
+ };
88
+
89
+ /**
90
+ * Detect multiple models running in parallel when they should not.
91
+ * Note: we use the `mergeArgs` to handle special cases when multiple identical models CAN run in parallel
92
+ *
93
+ * @param nodeType Cycle, Site, or ImpactAssessment
94
+ */
95
+ export const validateConfigDuplicates = (nodeType: allowedType) => {
96
+ const config = loadConfig(nodeType);
97
+
98
+ const duplicates = config.models
99
+ .map((value) => (Array.isArray(value) ? findDuplicatedConfigs(value) : []))
100
+ .flat(2);
101
+
102
+ return duplicates;
103
+ };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const ENGINE_VERSION = '0.76.1';
1
+ export const ENGINE_VERSION = '0.76.2';