@apiquest/fracture 1.0.4 → 1.0.6

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 (87) hide show
  1. package/README.md +90 -2
  2. package/dist/CollectionRunner.d.ts +3 -0
  3. package/dist/CollectionRunner.d.ts.map +1 -1
  4. package/dist/CollectionRunner.js +249 -154
  5. package/dist/CollectionRunner.js.map +1 -1
  6. package/dist/CollectionValidator.d.ts.map +1 -1
  7. package/dist/CollectionValidator.js +11 -0
  8. package/dist/CollectionValidator.js.map +1 -1
  9. package/dist/ConsoleReporter.d.ts.map +1 -1
  10. package/dist/ConsoleReporter.js +9 -6
  11. package/dist/ConsoleReporter.js.map +1 -1
  12. package/dist/DagScheduler.d.ts.map +1 -1
  13. package/dist/DagScheduler.js +11 -0
  14. package/dist/DagScheduler.js.map +1 -1
  15. package/dist/LibraryLoader.d.ts +49 -0
  16. package/dist/LibraryLoader.d.ts.map +1 -0
  17. package/dist/LibraryLoader.js +198 -0
  18. package/dist/LibraryLoader.js.map +1 -0
  19. package/dist/PluginLoader.d.ts.map +1 -1
  20. package/dist/PluginLoader.js +9 -6
  21. package/dist/PluginLoader.js.map +1 -1
  22. package/dist/PluginManager.d.ts.map +1 -1
  23. package/dist/PluginManager.js +11 -7
  24. package/dist/PluginManager.js.map +1 -1
  25. package/dist/PluginResolver.d.ts +1 -1
  26. package/dist/PluginResolver.d.ts.map +1 -1
  27. package/dist/PluginResolver.js +1 -1
  28. package/dist/PluginResolver.js.map +1 -1
  29. package/dist/QuestAPI.d.ts.map +1 -1
  30. package/dist/QuestAPI.js +114 -217
  31. package/dist/QuestAPI.js.map +1 -1
  32. package/dist/ScriptEngine.d.ts +2 -1
  33. package/dist/ScriptEngine.d.ts.map +1 -1
  34. package/dist/ScriptEngine.js +15 -8
  35. package/dist/ScriptEngine.js.map +1 -1
  36. package/dist/TaskGraph.d.ts +2 -1
  37. package/dist/TaskGraph.d.ts.map +1 -1
  38. package/dist/TaskGraph.js +28 -26
  39. package/dist/TaskGraph.js.map +1 -1
  40. package/dist/VariableResolver.d.ts +1 -1
  41. package/dist/VariableResolver.js +10 -10
  42. package/dist/VariableResolver.js.map +1 -1
  43. package/dist/cli/index.js +35 -3
  44. package/dist/cli/index.js.map +1 -1
  45. package/dist/cli/plugin-commands.d.ts.map +1 -1
  46. package/dist/cli/plugin-commands.js +47 -81
  47. package/dist/cli/plugin-commands.js.map +1 -1
  48. package/dist/cli/plugin-installer.d.ts +48 -0
  49. package/dist/cli/plugin-installer.d.ts.map +1 -0
  50. package/dist/cli/plugin-installer.js +136 -0
  51. package/dist/cli/plugin-installer.js.map +1 -0
  52. package/dist/cli/plugin-registry.d.ts +17 -0
  53. package/dist/cli/plugin-registry.d.ts.map +1 -0
  54. package/dist/cli/plugin-registry.js +77 -0
  55. package/dist/cli/plugin-registry.js.map +1 -0
  56. package/package.json +1 -1
  57. package/tsconfig.json +1 -0
  58. package/tsconfig.test.json +3 -0
  59. package/dist/QuestAPI.types.d.ts +0 -35
  60. package/dist/QuestAPI.types.d.ts.map +0 -1
  61. package/dist/QuestAPI.types.js +0 -3
  62. package/dist/QuestAPI.types.js.map +0 -1
  63. package/src/CollectionAnalyzer.ts +0 -102
  64. package/src/CollectionRunner.ts +0 -1423
  65. package/src/CollectionRunner.types.ts +0 -9
  66. package/src/CollectionValidator.ts +0 -289
  67. package/src/ConsoleReporter.ts +0 -143
  68. package/src/CookieJar.ts +0 -258
  69. package/src/DagScheduler.ts +0 -439
  70. package/src/Logger.ts +0 -85
  71. package/src/PluginLoader.ts +0 -126
  72. package/src/PluginManager.ts +0 -208
  73. package/src/PluginResolver.ts +0 -154
  74. package/src/QuestAPI.ts +0 -764
  75. package/src/QuestAPI.types.ts +0 -33
  76. package/src/QuestTestAPI.ts +0 -164
  77. package/src/RequestFilter.ts +0 -224
  78. package/src/ScriptEngine.ts +0 -219
  79. package/src/ScriptValidator.ts +0 -428
  80. package/src/TaskGraph.ts +0 -598
  81. package/src/TestCounter.ts +0 -109
  82. package/src/VariableResolver.ts +0 -114
  83. package/src/cli/index.ts +0 -480
  84. package/src/cli/plugin-commands.ts +0 -342
  85. package/src/cli/plugin-discovery.ts +0 -44
  86. package/src/index.ts +0 -24
  87. package/src/utils.ts +0 -52
@@ -1,428 +0,0 @@
1
- import * as acorn from 'acorn';
2
- import * as walk from 'acorn-walk';
3
- import { ValidationError, ScriptType, PluginEventDefinition, IProtocolPlugin } from '@apiquest/types';
4
-
5
- /**
6
- * ScriptValidator provides AST-based validation and analysis of collection scripts
7
- * - Validates quest.test() placement (disallowed in pre-scripts, certain plugin events)
8
- * - Validates quest.expectMessages() placement (only in preRequestScript)
9
- * - Detects conditional test declarations (breaks determinism)
10
- * - Counts expected tests for progress reporting
11
- */
12
- export class ScriptValidator {
13
- /**
14
- * Validate that quest.test() calls are only in allowed script types
15
- * @param script - JavaScript code to validate
16
- * @param scriptType - Type of script (collection-pre, request-post, etc.)
17
- * @param path - Request path for error reporting
18
- * @returns Array of validation errors (empty if valid)
19
- */
20
- static validateTestLocation(
21
- script: string,
22
- scriptType: ScriptType,
23
- path: string
24
- ): ValidationError[] {
25
- const errors: ValidationError[] = [];
26
-
27
- // Disallow quest.test() in these script types
28
- const disallowedTypes = [
29
- ScriptType.CollectionPre,
30
- ScriptType.CollectionPost,
31
- ScriptType.FolderPre,
32
- ScriptType.FolderPost,
33
- ScriptType.PreRequest,
34
- ];
35
-
36
- if (!disallowedTypes.includes(scriptType)) {
37
- return []; // Allowed in PostRequest and some PluginEvent scripts
38
- }
39
-
40
- // Parse and check for quest.test() calls
41
- try {
42
- const ast = acorn.parse(script, { ecmaVersion: 2022, sourceType: 'module', locations: true });
43
-
44
- walk.simple(ast, {
45
- CallExpression(node: acorn.CallExpression) {
46
- if (
47
- node.callee.type === 'MemberExpression' &&
48
- (node.callee).object.type === 'Identifier' &&
49
- ((node.callee).object).name === 'quest' &&
50
- (node.callee).property.type === 'Identifier' &&
51
- ((node.callee).property).name === 'test'
52
- ) {
53
- errors.push({
54
- message: `quest.test() is not allowed in ${scriptType} scripts`,
55
- location: path,
56
- source: 'script',
57
- scriptType,
58
- details: {
59
- line: node.loc?.start.line,
60
- column: node.loc?.start.column,
61
- suggestion: 'Move tests to postRequestScript or use quest.skip() inside tests',
62
- },
63
- });
64
- }
65
- },
66
- });
67
- } catch (error) {
68
- const err = error as { message?: string; loc?: { line?: number; column?: number } };
69
- errors.push({
70
- message: `Syntax error in script: ${err.message ?? String(error)}`,
71
- location: path,
72
- source: 'script',
73
- scriptType,
74
- details: {
75
- line: err.loc?.line,
76
- column: err.loc?.column,
77
- },
78
- });
79
- }
80
-
81
- return errors;
82
- }
83
-
84
- /**
85
- * Validate that quest.test() is NOT inside conditional statements (breaks determinism)
86
- * @param script - JavaScript code to validate
87
- * @param scriptType - Type of script
88
- * @param path - Request path for error reporting
89
- * @returns Array of validation errors (empty if valid)
90
- */
91
- static validateNoConditionalTests(
92
- script: string,
93
- scriptType: ScriptType,
94
- path: string
95
- ): ValidationError[] {
96
- const errors: ValidationError[] = [];
97
-
98
- try {
99
- const ast = acorn.parse(script, { ecmaVersion: 2022, sourceType: 'module', locations: true });
100
-
101
- walk.ancestor(ast, {
102
- CallExpression(node: acorn.CallExpression, ancestors: acorn.Node[]) {
103
- if (
104
- node.callee.type === 'MemberExpression' &&
105
- (node.callee).object.type === 'Identifier' &&
106
- ((node.callee).object).name === 'quest' &&
107
- (node.callee).property.type === 'Identifier' &&
108
- ((node.callee).property).name === 'test'
109
- ) {
110
- const insideConditional = ancestors.some(
111
- (ancestor) =>
112
- ancestor.type === 'IfStatement' ||
113
- ancestor.type === 'ConditionalExpression' ||
114
- ancestor.type === 'LogicalExpression' ||
115
- ancestor.type === 'TryStatement'
116
- );
117
-
118
- if (insideConditional) {
119
- errors.push({
120
- message: 'quest.test() cannot be declared conditionally (breaks deterministic test counting)',
121
- location: path,
122
- source: 'script',
123
- scriptType,
124
- details: {
125
- line: node.loc?.start.line,
126
- column: node.loc?.start.column,
127
- suggestion: 'Use quest.skip() inside the test, or use request.condition field for request-level control',
128
- },
129
- });
130
- }
131
- }
132
- },
133
- });
134
- } catch (error) {
135
- // Syntax errors already caught by validateTestLocation
136
- }
137
-
138
- return errors;
139
- }
140
-
141
- /**
142
- * Validate quest.expectMessages() is only called in preRequestScript
143
- * and validates protocol supports plugin events with canHaveTests
144
- * @param script - JavaScript code to validate
145
- * @param scriptType - Type of script
146
- * @param path - Request path for error reporting
147
- * @param protocolPlugin - Protocol plugin to check for event support (optional)
148
- * @param eventName - Specific event name if this is a plugin event script (optional)
149
- * @returns Array of validation errors (empty if valid)
150
- */
151
- static validateExpectMessages(
152
- script: string,
153
- scriptType: ScriptType,
154
- path: string,
155
- protocolPlugin?: IProtocolPlugin,
156
- eventName?: string
157
- ): ValidationError[] {
158
- const errors: ValidationError[] = [];
159
-
160
- try {
161
- const ast = acorn.parse(script, { ecmaVersion: 2022, sourceType: 'module', locations: true });
162
-
163
- walk.simple(ast, {
164
- CallExpression(node: acorn.CallExpression) {
165
- if (
166
- node.callee.type === 'MemberExpression' &&
167
- (node.callee).object.type === 'Identifier' &&
168
- ((node.callee).object).name === 'quest' &&
169
- (node.callee).property.type === 'Identifier' &&
170
- ((node.callee).property).name === 'expectMessages'
171
- ) {
172
- if (scriptType !== ScriptType.PreRequest) {
173
- errors.push({
174
- message: 'quest.expectMessages() can only be called in preRequestScript',
175
- location: path,
176
- source: 'script',
177
- scriptType,
178
- details: {
179
- line: node.loc?.start.line,
180
- column: node.loc?.start.column,
181
- },
182
- });
183
- return;
184
- }
185
-
186
- if (node.arguments.length > 0) {
187
- const arg = node.arguments[0];
188
- if (arg.type === 'Literal' && typeof (arg).value === 'number') {
189
- const numValue = (arg).value;
190
- if (!Number.isInteger(numValue) || numValue <= 0) {
191
- errors.push({
192
- message: 'quest.expectMessages() requires a positive integer count',
193
- location: path,
194
- source: 'script',
195
- scriptType,
196
- details: {
197
- line: node.loc?.start.line,
198
- column: node.loc?.start.column,
199
- suggestion: 'Use a positive integer like quest.expectMessages(10)',
200
- },
201
- });
202
- }
203
- } else if (arg.type === 'UnaryExpression' && (arg).operator === '-') {
204
- errors.push({
205
- message: 'quest.expectMessages() requires a positive integer count',
206
- location: path,
207
- source: 'script',
208
- scriptType,
209
- details: {
210
- line: node.loc?.start.line,
211
- column: node.loc?.start.column,
212
- suggestion: 'Use a positive integer like quest.expectMessages(10)',
213
- },
214
- });
215
- }
216
- }
217
-
218
- if (protocolPlugin !== undefined) {
219
- if (eventName !== undefined) {
220
- const eventDef = protocolPlugin.events?.find(
221
- (event: PluginEventDefinition) => event.name === eventName
222
- );
223
- if (eventDef !== undefined && eventDef.canHaveTests !== true) {
224
- errors.push({
225
- message: `quest.expectMessages() is not supported for event '${eventName}' (canHaveTests is false)`,
226
- location: path,
227
- source: 'script',
228
- scriptType,
229
- details: {
230
- line: node.loc?.start.line,
231
- column: node.loc?.start.column,
232
- suggestion: 'quest.expectMessages() can only be used with events that support tests',
233
- },
234
- });
235
- }
236
- } else {
237
- const hasTestableEvents = protocolPlugin.events?.some(
238
- (event: PluginEventDefinition) => event.canHaveTests === true
239
- ) ?? false;
240
-
241
- if (hasTestableEvents === false) {
242
- errors.push({
243
- message: `quest.expectMessages() is not supported for protocol '${protocolPlugin.protocols[0]}' (no plugin events with canHaveTests)`,
244
- location: path,
245
- source: 'script',
246
- scriptType,
247
- details: {
248
- line: node.loc?.start.line,
249
- column: node.loc?.start.column,
250
- suggestion: 'quest.expectMessages() is only for streaming protocols (websocket, sse, grpc)',
251
- },
252
- });
253
- }
254
- }
255
- }
256
- }
257
- },
258
- });
259
- } catch (error) {
260
- // Syntax errors already caught by validateTestLocation
261
- }
262
-
263
- return errors;
264
- }
265
-
266
- /**
267
- * Validate plugin event script can have tests (based on PluginEventDefinition)
268
- * @param script - JavaScript code to validate
269
- * @param eventDefinition - Plugin event definition with canHaveTests flag
270
- * @param path - Request path for error reporting
271
- * @returns Array of validation errors (empty if valid)
272
- */
273
- static validatePluginEventScript(
274
- script: string,
275
- eventDefinition: PluginEventDefinition,
276
- path: string
277
- ): ValidationError[] {
278
- const errors: ValidationError[] = [];
279
-
280
- if (eventDefinition.canHaveTests) {
281
- return []; // Tests are allowed
282
- }
283
-
284
- // Check for quest.test() calls when not allowed
285
- try {
286
- const ast = acorn.parse(script, { ecmaVersion: 2022, sourceType: 'module', locations: true });
287
-
288
- walk.simple(ast, {
289
- CallExpression(node: acorn.CallExpression) {
290
- if (
291
- node.callee.type === 'MemberExpression' &&
292
- (node.callee).object.type === 'Identifier' &&
293
- ((node.callee).object).name === 'quest' &&
294
- (node.callee).property.type === 'Identifier' &&
295
- ((node.callee).property).name === 'test'
296
- ) {
297
- errors.push({
298
- message: `quest.test() is not allowed in plugin event '${eventDefinition.name}' (canHaveTests: false)`,
299
- location: path,
300
- source: 'script',
301
- scriptType: ScriptType.PluginEvent,
302
- details: {
303
- line: node.loc?.start.line,
304
- column: node.loc?.start.column,
305
- suggestion: `Only use quest.test() in plugin events that allow tests (check plugin.events[].canHaveTests)`,
306
- },
307
- });
308
- }
309
- },
310
- });
311
- } catch (error) {
312
- // Syntax errors already caught by validateTestLocation
313
- }
314
-
315
- return errors;
316
- }
317
-
318
- /**
319
- * Count total quest.test() calls in a script (for deterministic test counting)
320
- * @param script - JavaScript code to analyze
321
- * @returns Number of quest.test() calls found
322
- */
323
- static countTests(script: string): number {
324
- let count = 0;
325
-
326
- try {
327
- const ast = acorn.parse(script, { ecmaVersion: 2022, sourceType: 'module' });
328
-
329
- walk.simple(ast, {
330
- CallExpression(node: acorn.CallExpression) {
331
- if (
332
- node.callee.type === 'MemberExpression' &&
333
- (node.callee).object.type === 'Identifier' &&
334
- ((node.callee).object).name === 'quest' &&
335
- (node.callee).property.type === 'Identifier' &&
336
- ((node.callee).property).name === 'test'
337
- ) {
338
- count++;
339
- }
340
- },
341
- });
342
- } catch (error) {
343
- // If script has syntax errors, return 0 (will be caught by validation)
344
- return 0;
345
- }
346
-
347
- return count;
348
- }
349
-
350
- /**
351
- * Extract expected message count from quest.expectMessages() call in preRequestScript
352
- * @param script - JavaScript code to analyze (must be preRequestScript)
353
- * @returns Expected message count, or null if not specified
354
- */
355
- static extractExpectedMessages(script: string): number | null {
356
- let expectedCount: number | null = null;
357
-
358
- try {
359
- const ast = acorn.parse(script, { ecmaVersion: 2022, sourceType: 'module' });
360
-
361
- walk.simple(ast, {
362
- CallExpression(node: acorn.CallExpression) {
363
- if (
364
- node.callee.type === 'MemberExpression' &&
365
- (node.callee).object.type === 'Identifier' &&
366
- ((node.callee).object).name === 'quest' &&
367
- (node.callee).property.type === 'Identifier' &&
368
- ((node.callee).property).name === 'expectMessages'
369
- ) {
370
- if (node.arguments.length > 0) {
371
- const firstArg = node.arguments[0];
372
- if (firstArg.type === 'Literal' && typeof (firstArg).value === 'number') {
373
- expectedCount = (firstArg).value;
374
- }
375
- }
376
- }
377
- },
378
- });
379
- } catch (error) {
380
- // If script has syntax errors, return null
381
- return null;
382
- }
383
-
384
- return expectedCount;
385
- }
386
-
387
- /**
388
- * Validate all aspects of a script (comprehensive validation)
389
- * @param script - JavaScript code to validate
390
- * @param scriptType - Type of script
391
- * @param path - Request path for error reporting
392
- * @param eventDefinition - Optional plugin event definition (for PluginEvent scripts)
393
- * @param protocolPlugin - Optional protocol plugin for protocol-specific validation
394
- * @returns Array of validation errors (empty if valid)
395
- */
396
- static validateScript(
397
- script: string,
398
- scriptType: ScriptType,
399
- path: string,
400
- eventDefinition?: PluginEventDefinition,
401
- protocolPlugin?: IProtocolPlugin,
402
- strictMode: boolean = true
403
- ): ValidationError[] {
404
- const errors: ValidationError[] = [];
405
-
406
- // 1. Validate test location
407
- errors.push(...this.validateTestLocation(script, scriptType, path));
408
-
409
- if (strictMode === true && (scriptType === ScriptType.PostRequest || eventDefinition?.canHaveTests === true)) {
410
- errors.push(...this.validateNoConditionalTests(script, scriptType, path));
411
- }
412
-
413
- // 3. Validate quest.expectMessages() placement
414
- errors.push(...this.validateExpectMessages(
415
- script,
416
- scriptType,
417
- path,
418
- protocolPlugin,
419
- eventDefinition?.name // Pass event name if this is a plugin event script
420
- ));
421
-
422
- if (scriptType === ScriptType.PluginEvent && eventDefinition !== undefined) {
423
- errors.push(...this.validatePluginEventScript(script, eventDefinition, path));
424
- }
425
-
426
- return errors;
427
- }
428
- }