theprogrammablemind 7.5.8-beta.65 → 7.5.8-beta.67

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 (3) hide show
  1. package/client.js +51 -11
  2. package/lines.js +2 -2
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -13,6 +13,22 @@ const { appendNoDups, InitCalls, updateQueries } = require('./src/helpers')
13
13
  const runtime = require('./runtime')
14
14
  const sortJson = runtime.sortJson
15
15
 
16
+ const getConfig_getObjectCheck = (testConfig) => {
17
+ return (testConfig.checks && testConfig.checks.objects) || testConfig.check || []
18
+ }
19
+
20
+ const getConfig_getContextCheck = (testConfig) => {
21
+ return (testConfig.checks && testConfig.checks.context) || []
22
+ }
23
+
24
+ const pickContext = (testConfig) => (context) => {
25
+ const picked = {}
26
+ for (let prop of getConfig_getContextCheck(testConfig)) {
27
+ picked[prop] = context[prop]
28
+ }
29
+ return sortJson(picked, { depth: 25 })
30
+ }
31
+
16
32
  const getAsk = (config) => (uuid) => (asks) => {
17
33
  for (let ask of asks) {
18
34
  config.addSemantic({
@@ -788,6 +804,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
788
804
  const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
789
805
  let failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
790
806
  let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
807
+ // TODO fix the naming conventions: camelcase + use actual instead of result
791
808
  const failed_responses = !matching(result.responses, expected.responses)
792
809
  const failed_contexts = !matching(result.contexts, expected.contexts)
793
810
  const failed_objects = !matching(actual_objects, expected_objects)
@@ -797,14 +814,18 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
797
814
  failed_generatedParenthesized = false
798
815
  }
799
816
 
817
+ const pickedResultContexts = result.contexts.map(pickContext(testConfig))
818
+ const pickedExpectedContexts = expected.contexts.map(pickContext(testConfig))
819
+ const failedCheckedContexts = !matching(pickedResultContexts, pickedExpectedContexts)
820
+
800
821
  const pickEm = (getObjects) => {
801
822
  const picked = {}
802
- for (let prop of (testConfig.check || [])) {
823
+ for (let prop of getConfig_getObjectCheck(testConfig)) {
803
824
  if (prop.km) {
804
825
  c = config.getConfig(prop.km)
805
826
  o = getObjects(prop.km)
806
827
  picked[prop.km] = {}
807
- for (let p of c.testConfig.check) {
828
+ for (let p of getConfig_getObjectCheck(c.testConfig)) {
808
829
  if (p.km) {
809
830
  continue
810
831
  }
@@ -822,11 +843,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
822
843
  }
823
844
  return expected.objects.namespaced[expected.objects.nameToUUID[name]]
824
845
  }
825
- try {
826
- sortJson(pickEm(expectedGetObjects), { depth: 25 })
827
- } catch ( e ) {
828
- debugger
829
- }
846
+ sortJson(pickEm(expectedGetObjects), { depth: 25 })
830
847
  const expected_checked = sortJson(pickEm(expectedGetObjects), { depth: 25 })
831
848
  const actualGetObjects = (name) => {
832
849
  if (!name) {
@@ -842,7 +859,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
842
859
  const actual_config = sortJson(convertToStable(getConfigForTest(config, testConfig)), { depth: 25 })
843
860
  const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
844
861
  const failed_config = !matching(actual_config, expected_config)
845
- let failed = failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked
862
+ let failed = failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked || failedCheckedContexts
846
863
 
847
864
  if (expected.metadata && result.metadata && failed) {
848
865
  const priorities = analyzeMetaData(expected.metadata, result.metadata)
@@ -861,6 +878,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
861
878
  generatedParenthesized: expected.generatedParenthesized,
862
879
  results: expected.contexts,
863
880
  checked: expected_checked,
881
+ checkedContexts: pickedExpectedContexts,
864
882
  objects: expected_objects,
865
883
  config: expected.config
866
884
  },
@@ -871,6 +889,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
871
889
  generatedParenthesized: result.generatedParenthesized,
872
890
  results: result.contexts,
873
891
  checked: actual_checked,
892
+ checkedContexts: pickedResultContexts,
874
893
  objects: actual_objects,
875
894
  config: actual_config
876
895
  }
@@ -1130,7 +1149,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1130
1149
  const pickEm = () => {
1131
1150
  const picked = {}
1132
1151
  const namespaced = config.get('objects')['namespaced']
1133
- for (let prop of (config.testConfig.check || [])) {
1152
+ for (let prop of getConfig_getObjectCheck(config.testConfig)) {
1134
1153
  if (prop.km) {
1135
1154
  /*
1136
1155
  const objects = namespaced[prop.km]]
@@ -1380,10 +1399,10 @@ const knowledgeModule = async ({
1380
1399
  test = test.name
1381
1400
  }
1382
1401
  } else {
1383
- if (typeof runtime.fs == 'function' && runtime.fs.existsSync(test)) {
1402
+ if (runtime.fs && runtime.fs.existsSync(test)) {
1384
1403
  config.tests = JSON.parse(runtime.fs.readFileSync(test))
1385
1404
  } else {
1386
- config.tests = []
1405
+ config.tests = {}
1387
1406
  }
1388
1407
  }
1389
1408
  config.setTestConfig(testConfig)
@@ -1674,6 +1693,9 @@ const knowledgeModule = async ({
1674
1693
  if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1675
1694
  hasError = true
1676
1695
  }
1696
+ if (JSON.stringify(result.expected.checkedContexts) !== JSON.stringify(result.actual.checkedContexts)) {
1697
+ hasError = true
1698
+ }
1677
1699
  }
1678
1700
 
1679
1701
  if (hasError) {
@@ -1737,6 +1759,24 @@ const knowledgeModule = async ({
1737
1759
  newError = true
1738
1760
  headerShown = true
1739
1761
  }
1762
+ if (JSON.stringify(result.expected.checkedContexts) !== JSON.stringify(result.actual.checkedContexts)) {
1763
+ if (!headerShown) {
1764
+ console.log(' Failure')
1765
+ }
1766
+ const widths = [4, 18, 72]
1767
+ const lines = new Lines(widths)
1768
+ lines.setElement(1, 1, 'expected checkedContexts', true)
1769
+ lines.setElement(2, 2, JSON.stringify(result.expected.checkedContexts, null, 2))
1770
+ lines.log()
1771
+ lines.setElement(1, 1, 'actual checkedContexts', true)
1772
+ lines.setElement(2, 2, JSON.stringify(result.actual.checkedContexts, null, 2))
1773
+ lines.log()
1774
+ if (args.vimdiff) {
1775
+ vimdiff(result.actual.checkedContexts, result.expected.checkedContexts)
1776
+ }
1777
+ newError = true
1778
+ headerShown = true
1779
+ }
1740
1780
  }
1741
1781
  } else {
1742
1782
  if (results.length > 0 && args.vimdiff) {
package/lines.js CHANGED
@@ -10,12 +10,12 @@ class Lines {
10
10
  }
11
11
 
12
12
  // will wrap to next line within the column
13
- setElement (row, column, value) {
13
+ setElement (row, column, value, fullWidth = false) {
14
14
  const values = value.toString().split('\n')
15
15
  if (column >= this.widths.length) {
16
16
  throw new Error("Column out of range.")
17
17
  }
18
- const width = this.widths[column]
18
+ const width = fullWidth ? value.length: this.widths[column]
19
19
  let index = 0
20
20
  for (value of values) {
21
21
  while (value.length > 0) {
package/package.json CHANGED
@@ -63,6 +63,6 @@
63
63
  "json-stable-stringify": "^1.0.1",
64
64
  "node-fetch": "^2.6.1"
65
65
  },
66
- "version": "7.5.8-beta.65",
66
+ "version": "7.5.8-beta.67",
67
67
  "license": "ISC"
68
68
  }