@suffolklitlab/alkiln 5.13.2 → 5.13.3-feat-random-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.
Files changed (51) hide show
  1. package/.github/workflows/github_server.yml +10 -8
  2. package/.github/workflows/playground.yml +5 -2
  3. package/.github/workflows/unit_tests.yml +1 -1
  4. package/CHANGELOG.md +32 -1
  5. package/_alkiln_meta/shift_logs.js +75 -0
  6. package/action.yml +89 -31
  7. package/action_for_github_server/action.yml +65 -29
  8. package/docs/4_environments.md +243 -0
  9. package/docs/artifacts_folder_name.md +135 -0
  10. package/docs/constrained_random_tests.md +254 -0
  11. package/docs/decisions/006_which_log_level_to_pick_2024_09_5.md +70 -0
  12. package/docs/decisions/007_getting_and_storing_logs.md +179 -0
  13. package/docs/decisions/move_runtime_config_to_sources_folder.md +5 -0
  14. package/docs/decisions/reports_and_logs_2024_08_11.md +161 -0
  15. package/docs/kinds_of_errors.md +26 -0
  16. package/docs/prioritize_constrained_random_tests.md +60 -0
  17. package/lib/docassemble/docassemble_api_interface.js +77 -51
  18. package/lib/docassemble/server_install.js +32 -9
  19. package/lib/docassemble/setup.js +40 -25
  20. package/lib/docassemble/takedown.js +33 -10
  21. package/lib/globals.js +10 -0
  22. package/lib/run_cucumber.js +141 -69
  23. package/lib/scope.js +101 -77
  24. package/lib/setup/TestGenerator.js +1755 -0
  25. package/lib/setup/artifacts.js +20 -0
  26. package/lib/setup/generate.js +42 -0
  27. package/lib/setup/get_Gherkin_AST.js +26 -0
  28. package/lib/setup/validate.js +89 -0
  29. package/lib/steps.js +132 -54
  30. package/lib/utils/Log.js +1145 -0
  31. package/lib/utils/_alkiln-constrained_random_tests_old.js +1776 -0
  32. package/lib/utils/files.js +18 -11
  33. package/lib/utils/get_error_stacks.js +16 -0
  34. package/lib/utils/reports.js +100 -34
  35. package/lib/utils/session_vars.js +107 -73
  36. package/lib/utils/set_sources_paths.js +98 -0
  37. package/lib/utils/time.js +44 -0
  38. package/package.json +18 -7
  39. package/tests/log_codes/check_codes.sh +18 -13
  40. package/tests/log_codes/log_code_expected_instances.txt +91 -9
  41. package/tests/unit_tests/constrained_random_answers/invalid.fixtures.js +177 -0
  42. package/tests/unit_tests/constrained_random_answers/invalid.test.js +251 -0
  43. package/tests/unit_tests/constrained_random_answers/valid.fixtures.js +936 -0
  44. package/tests/unit_tests/constrained_random_answers/valid.test.js +541 -0
  45. package/tests/unit_tests/example_of_chai_test_lifecycle.js +78 -0
  46. package/tests/unit_tests/getAllFields.test.js +5 -0
  47. package/tests/unit_tests/getMatchingRows.test.js +5 -0
  48. package/tests/unit_tests/log.test.js +557 -0
  49. package/tests/unit_tests/normalizeTable.test.js +5 -0
  50. package/lib/utils/log.js +0 -96
  51. /package/docs/{expected_inernal_results.md → expected_internal_results.md} +0 -0
@@ -0,0 +1,251 @@
1
+ const chai = require(`chai`);
2
+ const expect = chai.expect;
3
+
4
+ const TestGenerator = require(`../../../lib/setup/TestGenerator.js`);
5
+ const Log = require(`../../../lib/utils/Log.js`);
6
+ const fixtures = require(`./invalid.fixtures.js`);
7
+
8
+
9
+ function get_error_codes({ errors }) {
10
+ /** Returns a list of ALKiln ALK#### codes from Error stacks
11
+ *
12
+ * @param {object} obj - Named arguments
13
+ * @param {[Error]} obj.errors - List of Error instances
14
+ *
15
+ * @returns {[str]} - List of ALKiln log codes in the errors
16
+ * */
17
+ let codes = [];
18
+ for ( let error of errors ) {
19
+ let matches = error.stack.match(/ALK\d\d\d\d/gm);
20
+ if ( matches ) {
21
+ codes.push( ...matches );
22
+ }
23
+ }
24
+
25
+ return codes;
26
+ };
27
+
28
+
29
+ function get_log_codes({ logger }) {
30
+ /** Returns a list of ALKiln codes from arguments sent to a Log instance
31
+ *
32
+ * @params {object} obj - Named arguments
33
+ * @params {Log} obj.logger - An instance of Log
34
+ * @params {object} obj.logger.opts - Options passed to the Log instance
35
+ * @params {str} obj.logger.opts.code - ALK#### formatted log code
36
+ * @params {[str]} obj.logger.logs - Additional messages to be logged
37
+ *
38
+ * @returns {[str]} - List of ALKiln log codes in the collection of logs
39
+ * */
40
+ let codes = [];
41
+
42
+ for ( let record of logger.internal_log_records ) {
43
+ codes.push( record.opts.code );
44
+ }
45
+
46
+ return codes;
47
+ }
48
+
49
+ /** Variables that will change their values for each `it()` */
50
+ const logger = new Log({ context: `invalid generators unit tests` });
51
+ let fixture = null;
52
+ let new_contents = null;
53
+ let errors = null;
54
+ let actual = null;
55
+ function mutate_globals_with({ testing_vals }) {
56
+ /** Set up values for parsing, parse, record values. Mutates in-scope
57
+ * variables in a way that helps chaijs (mocha really) get the right
58
+ * values to the right places.
59
+ *
60
+ * @params {object} testing_vals - Arguments to pass to the function and
61
+ * expected values
62
+ *
63
+ * @returns {undefined}
64
+ * */
65
+ // Reset log codes
66
+ logger.clear_internal_log_records();
67
+
68
+ // Fresh namespace
69
+ let generator = new TestGenerator();
70
+ // Mutates `fixture`
71
+ fixture = testing_vals;
72
+ // Mutates `new_contents` and `error`
73
+ ({ new_contents, errors } = generator.parse_file({
74
+ file_text: fixture.arg,
75
+ generator_path: `used_in_warning_logs`,
76
+ logger
77
+ }) );
78
+ };
79
+
80
+ describe(`Constrained random answers parser,`, function () {
81
+
82
+ describe(`when given a missing Feature keyword`, function () {
83
+
84
+ before(function () { mutate_globals_with({ testing_vals: fixtures.generator_missing_Feature }); });
85
+
86
+ let outer = fixtures.generator_missing_Feature;
87
+
88
+ it(`returns \`null\` for contents value`, function () {
89
+ expect( new_contents ).to.equal( fixture.expected );
90
+ });
91
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
92
+ expect( get_error_codes({ errors: errors }) )
93
+ .to.have.all.members( fixture.error_codes );
94
+ });
95
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
96
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
97
+ });
98
+
99
+ });
100
+
101
+ describe(`when given an empty string`, function () {
102
+
103
+ before(function () { mutate_globals_with({ testing_vals: fixtures.generator_missing_contents }); });
104
+
105
+ let outer = fixtures.generator_missing_contents;
106
+
107
+ it(`returns \`null\` for contents value`, function () {
108
+ expect( new_contents ).to.equal( fixture.expected );
109
+ });
110
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
111
+ expect( get_error_codes({ errors: errors }) )
112
+ .to.have.all.members( fixture.error_codes );
113
+ });
114
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
115
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
116
+ });
117
+
118
+ });
119
+
120
+ describe(`when given generator text missing Scenarios`, function () {
121
+
122
+ before(function () { mutate_globals_with({ testing_vals: fixtures.generator_0_Scenarios }); });
123
+
124
+ let outer = fixtures.generator_0_Scenarios;
125
+
126
+ it(`returns \`null\` for contents value`, function () {
127
+ expect( new_contents ).to.equal( fixture.expected );
128
+ });
129
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
130
+ expect( get_error_codes({ errors: errors }) )
131
+ .to.have.all.members( fixture.error_codes );
132
+ });
133
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
134
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
135
+ });
136
+
137
+ });
138
+
139
+ describe(`when given an invalid generator Scenario`, function () {
140
+
141
+ describe(`where a num tests fore Step is missing keywords,`, function () {
142
+
143
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_fore_Step_keywords }); });
144
+
145
+ let outer = fixtures.missing_fore_Step_keywords;
146
+
147
+ it(`returns \`null\` for contents value`, function () {
148
+ expect( new_contents ).to.equal( fixture.expected );
149
+ });
150
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
151
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
152
+ });
153
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
154
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
155
+ });
156
+
157
+ });
158
+
159
+ describe(`where a constraints Step is missing keywords,`, function () {
160
+
161
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_constraints_Step_keywords }); });
162
+
163
+ let outer = fixtures.missing_constraints_Step_keywords;
164
+
165
+ it(`returns \`null\` for contents value`, function () {
166
+ expect( new_contents ).to.equal( fixture.expected );
167
+ });
168
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
169
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
170
+ });
171
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
172
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
173
+ });
174
+
175
+ });
176
+
177
+ describe(`that is missing a table,`, function () {
178
+
179
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_table }); });
180
+
181
+ let outer = fixtures.missing_table;
182
+
183
+ it(`returns \`null\` for contents value`, function () {
184
+ expect( new_contents ).to.equal( fixture.expected );
185
+ });
186
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
187
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
188
+ });
189
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
190
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
191
+ });
192
+
193
+ });
194
+
195
+ describe(`that has no quoted ids,`, function () {
196
+
197
+ before(function () { mutate_globals_with({ testing_vals: fixtures.missing_ids }); });
198
+
199
+ let outer = fixtures.missing_ids;
200
+
201
+ it(`returns \`null\` for contents value`, function () {
202
+ expect( new_contents ).to.equal( fixture.expected );
203
+ });
204
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
205
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
206
+ });
207
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
208
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
209
+ });
210
+
211
+ });
212
+
213
+ describe(`that has no header row,`, function () {
214
+
215
+ before(function () { mutate_globals_with({ testing_vals: fixtures.only_row_is_header }); });
216
+
217
+ let outer = fixtures.only_row_is_header;
218
+
219
+ it(`returns \`null\` for contents value`, function () {
220
+ expect( new_contents ).to.equal( fixture.expected );
221
+ });
222
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
223
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
224
+ });
225
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
226
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
227
+ });
228
+
229
+ });
230
+
231
+ describe(`that has multiple Scenarios,`, function () {
232
+
233
+ before(function () { mutate_globals_with({ testing_vals: fixtures.multiple_scenarios }); });
234
+
235
+ let outer = fixtures.multiple_scenarios;
236
+
237
+ it(`returns \`null\` for contents value`, function () {
238
+ expect( new_contents ).to.equal( fixture.expected );
239
+ });
240
+ it(`has these exact error codes: ${ JSON.stringify( outer.error_codes )}`, function () {
241
+ expect( get_error_codes({ errors: errors }) ).to.have.all.members( fixture.error_codes );
242
+ });
243
+ it(`has these exact _log_ codes: ${ JSON.stringify( outer.log_codes )}`, function () {
244
+ expect( get_log_codes({ logger }) ).to.have.all.members( fixture.log_codes );
245
+ });
246
+
247
+ });
248
+
249
+ });
250
+
251
+ });