theprogrammablemind_4wp 7.5.0-beta.3 → 7.5.0-beta.30

Sign up to get free protection for your applications and to get access to all the features.
package/client.js CHANGED
@@ -78,7 +78,15 @@ const listable = (hierarchy) => (c, type) => {
78
78
  return false
79
79
  }
80
80
 
81
- const isA = (hierarchy) => (child, parent) => hierarchy.isA(child, parent)
81
+ const isA = (hierarchy) => (child, parent) => {
82
+ if (child.marker) {
83
+ child = child.marker
84
+ }
85
+ if (parent.marker) {
86
+ parent = parent.marker
87
+ }
88
+ return hierarchy.isA(child, parent)
89
+ }
82
90
 
83
91
  const asList = (context) => {
84
92
  if (context.marker === 'list') {
@@ -670,9 +678,12 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug
670
678
  defaultErrorHandler(error)
671
679
  }
672
680
 
673
- const objects = getObjects(config.config.objects)(config.uuid)
681
+ let objects = getObjects(config.config.objects)(config.uuid)
682
+ if (testConfig.testModuleName) {
683
+ objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
684
+ }
674
685
  config.beforeQuery({ query: test, isModule: false, objects })
675
- config.resetMotivations()
686
+ // config.resetMotivations()
676
687
  try {
677
688
  const result = await _process(config, test, { errorHandler, isTest: true })
678
689
  result.query = test
@@ -783,7 +794,7 @@ const runTests = async (config, testFile, juicyBits) => {
783
794
  const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
784
795
  config.rebuild()
785
796
  const objects = getObjects(config.config.objects)(config.uuid)
786
- config.resetMotivations()
797
+ //config.resetMotivations()
787
798
  config.beforeQuery({ query: test, isModule: false, objects })
788
799
  console.log(test)
789
800
  const result = await _process(config, test, { isTest: true })
@@ -1252,7 +1263,7 @@ const knowledgeModule = async ({
1252
1263
  description: 'Entodicton knowledge module'
1253
1264
  })
1254
1265
 
1255
- parser.add_argument('-tfn', '--testFileName', { help: 'Override the test file for the module when the tests are being run' })
1266
+ parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
1256
1267
  parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
1257
1268
  parser.add_argument('-tv', '--testVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. Create tests by running with the --query or --loop with the --save flag' })
1258
1269
  parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag' })
@@ -1267,7 +1278,7 @@ const knowledgeModule = async ({
1267
1278
  parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1268
1279
  parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
1269
1280
  parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
1270
- parser.add_argument('-td', '--testDelete', { help: 'Delete the specified query from the tests file.' })
1281
+ parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
1271
1282
  parser.add_argument('-c', '--clean', { help: 'Remove data from the test files. a === association' })
1272
1283
  parser.add_argument('-od', '--objectDiff', { action: 'store_true', help: 'When showing the objects use a colour diff' })
1273
1284
  parser.add_argument('-daa', '--dontAddAssociations', { action: 'store_true', help: 'Do not add associations from the tests.' })
@@ -1306,11 +1317,11 @@ const knowledgeModule = async ({
1306
1317
  return
1307
1318
  }
1308
1319
 
1309
- if (args.testDelete) {
1320
+ if (args.deleteTest) {
1310
1321
  let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
1311
- tests = tests.filter( (test) => test.query !== args.testDelete );
1322
+ tests = tests.filter( (test) => test.query !== args.deleteTest );
1312
1323
  writeTestFile(testConfig.name, tests)
1313
- console.log(`Remove the test for "${args.testDelete}"`)
1324
+ console.log(`Remove the test for "${args.deleteTest}"`)
1314
1325
  return
1315
1326
  }
1316
1327
 
@@ -1466,7 +1477,15 @@ const knowledgeModule = async ({
1466
1477
  }
1467
1478
  return
1468
1479
  }
1469
- runTests(config, args.testFileName ? `${args.testFileName}.test.json` : test, { debug: args.debug, testConfig: testConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
1480
+ let useTestConfig = testConfig
1481
+ if (args.testModuleName) {
1482
+ useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
1483
+ useTestConfig.testModuleName = args.testModuleName
1484
+ test = useTestConfig.name
1485
+
1486
+ }
1487
+ // runTests(config, args.testFileName ? `${args.testFileName}.test.json` : test, { debug: args.debug, testConfig: testConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
1488
+ runTests(config, test, { debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
1470
1489
  if (results.length > 0 && args.vimdiff) {
1471
1490
  for (const result of results) {
1472
1491
  vimdiff(result.expected, result.actual)
@@ -1515,19 +1534,25 @@ const knowledgeModule = async ({
1515
1534
  if (!headerShown) {
1516
1535
  console.log(' Failure')
1517
1536
  }
1518
- console.log(' expected checked', result.expected.checked)
1519
- console.log(' actual checked ', result.actual.checked)
1537
+ const widths = [4, 18, 72]
1538
+ const lines = new Lines(widths)
1539
+ lines.setElement(1, 1, 'expected checked')
1540
+ lines.setElement(2, 2, JSON.stringify(result.expected.checked, null, 2))
1541
+ lines.log()
1542
+ lines.setElement(1, 1, 'actual checked')
1543
+ lines.setElement(2, 2, JSON.stringify(result.actual.checked, null, 2))
1544
+ lines.log()
1520
1545
  newError = true
1521
1546
  headerShown = true
1522
1547
  }
1523
1548
  }
1524
1549
  }
1525
1550
  if (!headerShown) {
1526
- if (!(testConfig.check && testConfig.check.length > 0)) {
1551
+ if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1527
1552
  console.log('There are failures due to things other than paraphrases, responses and checked properties being different. They are not shown because you ran -tv or -tva which only shows difference in paraphrase and results. Usually what I do is -s and do a diff to make sure there are no other problems. If the paraphrases or results were different they would have shown here.')
1528
1553
  }
1529
1554
  }
1530
- if (!(testConfig.check && testConfig.check.length > 0)) {
1555
+ if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1531
1556
  console.log('use -v arg to write files expected.json and actual.json in the current directory for detailed comparison. Or do -s and then git diff the changes.')
1532
1557
  // console.log(JSON.stringify(contexts))
1533
1558
  console.log('**************************** ERRORS ************************')
@@ -1589,6 +1614,7 @@ const knowledgeModule = async ({
1589
1614
  }
1590
1615
  } else {
1591
1616
  config.addAssociationsFromTests(config.tests);
1617
+ config.setTestConfig(testConfig)
1592
1618
  //for (let query in config.tests) {
1593
1619
  // config.addAssociations(config.tests[query].associations || []);
1594
1620
  //}
package/lines.js CHANGED
@@ -12,6 +12,9 @@ class Lines {
12
12
  // will wrap to next line within the column
13
13
  setElement (row, column, value) {
14
14
  const values = value.toString().split('\n')
15
+ if (column >= this.widths.length) {
16
+ throw "Column out of range."
17
+ }
15
18
  const width = this.widths[column]
16
19
  let index = 0
17
20
  for (value of values) {
package/package.json CHANGED
@@ -61,6 +61,6 @@
61
61
  "json-stable-stringify": "^1.0.1",
62
62
  "node-fetch": "^2.6.1"
63
63
  },
64
- "version": "7.5.0-beta.3",
64
+ "version": "7.5.0-beta.30",
65
65
  "license": "ISC"
66
66
  }
package/src/config.js CHANGED
@@ -330,6 +330,17 @@ class Config {
330
330
  return `${maybeName}${counter}`
331
331
  }
332
332
 
333
+ setTestConfig(testConfig) {
334
+ if (this.name == 'ui') {
335
+ console.log('ui setting testConfig')
336
+ }
337
+ this.testConfig = testConfig
338
+ }
339
+
340
+ getTestConfig() {
341
+ return this.testConfig
342
+ }
343
+
333
344
  defaultConfig () {
334
345
  this.config = {
335
346
  operators: [], // TODO
@@ -1090,7 +1101,7 @@ class Config {
1090
1101
  config = _.cloneDeep(config)
1091
1102
  this.config = config
1092
1103
  for (let bridge of this.config.bridges) {
1093
- const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generators', 'id', 'inverted', 'isA',
1104
+ const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generators', 'id', 'implicit', 'inverted', 'isA', 'children', 'parents',
1094
1105
  'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy' ]
1095
1106
  helpers.validProps(valid, bridge, 'bridge')
1096
1107
  /*
@@ -1101,6 +1112,16 @@ class Config {
1101
1112
  })
1102
1113
  }
1103
1114
  */
1115
+ if (bridge.children) {
1116
+ for (let child of bridge.children) {
1117
+ this.addHierarchy(child, bridge.id)
1118
+ }
1119
+ }
1120
+ if (bridge.parents) {
1121
+ for (let parent of bridge.parents) {
1122
+ this.addHierarchy(bridge.id, parent)
1123
+ }
1124
+ }
1104
1125
  if (bridge.isA) {
1105
1126
  for (let parent of bridge.isA) {
1106
1127
  this.addHierarchy(bridge.id, parent)
@@ -1379,12 +1400,13 @@ class Config {
1379
1400
  cp.name = this.name
1380
1401
  cp.description = this.description
1381
1402
  cp.tests = this.tests
1382
- cp.motivations = this.motivations
1403
+ cp.motivations = [...this.motivations]
1383
1404
  cp.isModule = this.isModule
1384
1405
  cp.loadedForTesting = this.loadedForTesting
1385
1406
  cp.initInstances = this.initInstances.slice()
1386
1407
  cp.instances = this.instances.slice()
1387
1408
  cp.configCounter = this.configCounter
1409
+ cp.testConfig = this.testConfig
1388
1410
 
1389
1411
  cp.initConfig = _.cloneDeep(this.initConfig)
1390
1412
  cp.defaultConfig()
@@ -1747,6 +1769,7 @@ class Config {
1747
1769
  }
1748
1770
  this.config.objects.namespaced = {}
1749
1771
  this.resetWasInitialized()
1772
+ this.resetMotivations()
1750
1773
 
1751
1774
  // reorder configs base on load ordering
1752
1775
  {
package/src/generators.js CHANGED
@@ -195,10 +195,12 @@ class Generators {
195
195
  } catch( e ) {
196
196
  // the next if handle this
197
197
  generated = null
198
+ e.retryCall = () => generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
199
+ const help = 'The error has a retryCall property that will recall the function that failed.'
198
200
  if (e.stack && e.message) {
199
- errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}`
201
+ errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}. ${help}`
200
202
  } else if (e.error) {
201
- errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.error.join()}. Generator is ${generator.toString()}`
203
+ errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.error.join()}. Generator is ${generator.toString()}. ${help}`
202
204
  } else {
203
205
  errorMessage = e.toString()
204
206
  }
package/src/semantics.js CHANGED
@@ -189,10 +189,12 @@ class Semantics {
189
189
  } catch( e ) {
190
190
  contextPrime = null
191
191
  let errorMessage
192
+ e.retryCall = () => semantic.apply(args, context, s, log, options)
193
+ const help = 'The error has a retryCall property that will recall the function that failed.'
192
194
  if (e.stack && e.message) {
193
- errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.toString()} stack is ${e.stack}. Semantic is ${semantic.toString()}`
195
+ errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.toString()} stack is ${e.stack}. Semantic is ${semantic.toString()}. ${help}`
194
196
  } else if (e.error) {
195
- errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.error.join()}. Semantic is ${semantic.toString()}`
197
+ errorMessage = `Error applying semantics '${semantic.notes}'. Error is ${e.error.join()}. Semantic is ${semantic.toString()}. ${help}`
196
198
  } else {
197
199
  errorMessage = e.toString();
198
200
  }