@http-forge/core 0.1.0 → 0.2.1

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 (135) hide show
  1. package/README.md +217 -43
  2. package/dist/auth/interfaces.d.ts +63 -0
  3. package/dist/auth/oauth2-token-manager.d.ts +103 -0
  4. package/dist/collection/collection-loader-factory.d.ts +20 -0
  5. package/dist/{services → collection}/collection-loader.d.ts +3 -3
  6. package/dist/collection/collection-service-interfaces.d.ts +119 -0
  7. package/dist/collection/collection-service.d.ts +75 -0
  8. package/dist/collection/collection-store.d.ts +109 -0
  9. package/dist/collection/folder-collection-loader.d.ts +45 -0
  10. package/dist/collection/folder-collection-store.d.ts +175 -0
  11. package/dist/collection/folder-io.d.ts +113 -0
  12. package/dist/collection/interfaces.d.ts +32 -0
  13. package/dist/collection/json-collection-loader.d.ts +95 -0
  14. package/dist/{services → collection}/parser-registry.d.ts +1 -2
  15. package/dist/config/config-service.d.ts +79 -0
  16. package/dist/config/config.interface.d.ts +140 -0
  17. package/dist/config/default-config.d.ts +29 -0
  18. package/dist/config/index.d.ts +6 -0
  19. package/dist/container.d.ts +26 -19
  20. package/dist/{implementations → cookie}/cookie-jar.d.ts +2 -3
  21. package/dist/cookie/cookie-service.d.ts +98 -0
  22. package/dist/{implementations → cookie}/cookie-utils.d.ts +1 -2
  23. package/dist/cookie/in-memory-cookie-jar.d.ts +44 -0
  24. package/dist/{interfaces/cookie.d.ts → cookie/interfaces.d.ts} +22 -3
  25. package/dist/cookie/persistent-cookie-jar.d.ts +35 -0
  26. package/dist/di/core-bootstrap.d.ts +25 -0
  27. package/dist/di/index.d.ts +11 -0
  28. package/dist/di/platform-adapters.d.ts +53 -0
  29. package/dist/di/service-container.d.ts +97 -0
  30. package/dist/di/service-identifiers.d.ts +34 -0
  31. package/dist/environment/environment-config-service.d.ts +98 -0
  32. package/dist/environment/environment-file-loader.d.ts +42 -0
  33. package/dist/{services → environment}/environment-resolver.d.ts +6 -5
  34. package/dist/{services → environment}/forge-env.d.ts +1 -2
  35. package/dist/environment/interfaces.d.ts +139 -0
  36. package/dist/environment/variable-interpolator.d.ts +100 -0
  37. package/dist/execution/collection-request-executor-interfaces.d.ts +36 -0
  38. package/dist/execution/collection-request-executor.d.ts +78 -0
  39. package/dist/{services → execution}/request-executor.d.ts +23 -11
  40. package/dist/execution/request-preparer-interfaces.d.ts +36 -0
  41. package/dist/execution/request-preparer.d.ts +35 -0
  42. package/dist/graphql/graphql-completion-provider.d.ts +39 -0
  43. package/dist/graphql/graphql-schema-service.d.ts +89 -0
  44. package/dist/{interfaces/history.d.ts → history/history-interfaces.d.ts} +29 -6
  45. package/dist/history/request-history-service-interfaces.d.ts +43 -0
  46. package/dist/history/request-history-service.d.ts +133 -0
  47. package/dist/{implementations → history}/request-history.d.ts +2 -3
  48. package/dist/{implementations → http}/fetch-http-client.d.ts +4 -5
  49. package/dist/http/http-request-service.d.ts +36 -0
  50. package/dist/{implementations → http}/interceptor-chain.d.ts +1 -2
  51. package/dist/http/interfaces.d.ts +25 -0
  52. package/dist/http/merge-request-settings.d.ts +12 -0
  53. package/dist/{implementations → http}/native-http-client.d.ts +6 -15
  54. package/dist/{implementations → http}/request-preprocessor.d.ts +1 -2
  55. package/dist/{services → http}/url-builder.d.ts +7 -10
  56. package/dist/import-export/import-postman-environment.d.ts +21 -0
  57. package/dist/import-export/rest-client-export.d.ts +35 -0
  58. package/dist/index.d.ts +94 -6
  59. package/dist/index.js +262 -35
  60. package/dist/index.mjs +262 -35
  61. package/dist/openapi/example-generator.d.ts +26 -0
  62. package/dist/openapi/history-analyzer.d.ts +29 -0
  63. package/dist/openapi/index.d.ts +16 -0
  64. package/dist/openapi/interfaces.d.ts +42 -0
  65. package/dist/openapi/openapi-exporter.d.ts +73 -0
  66. package/dist/openapi/openapi-importer.d.ts +72 -0
  67. package/dist/openapi/ref-resolver.d.ts +28 -0
  68. package/dist/openapi/schema-inference-service.d.ts +40 -0
  69. package/dist/openapi/schema-inferrer.d.ts +26 -0
  70. package/dist/openapi/script-analyzer.d.ts +41 -0
  71. package/dist/parsers/http-forge-parser.d.ts +2 -3
  72. package/dist/parsers/index.d.ts +0 -1
  73. package/dist/{implementations → platform}/data-file-parser.d.ts +0 -1
  74. package/dist/{implementations → platform}/node-file-system.d.ts +1 -2
  75. package/dist/script/interfaces.d.ts +161 -0
  76. package/dist/script/module-loader.d.ts +115 -0
  77. package/dist/script/request-script-session.d.ts +73 -0
  78. package/dist/script/script-executor.d.ts +60 -0
  79. package/dist/script/script-factories.d.ts +94 -0
  80. package/dist/script/script-utils.d.ts +42 -0
  81. package/dist/test-suite/index.d.ts +10 -0
  82. package/dist/test-suite/interfaces.d.ts +164 -0
  83. package/dist/test-suite/result-storage-service.d.ts +70 -0
  84. package/dist/test-suite/result-storage.d.ts +296 -0
  85. package/dist/test-suite/statistics-service.d.ts +51 -0
  86. package/dist/test-suite/test-suite-service.d.ts +97 -0
  87. package/dist/test-suite/test-suite-store.d.ts +155 -0
  88. package/dist/types/console-service.d.ts +40 -0
  89. package/dist/types/platform.d.ts +206 -0
  90. package/dist/{interfaces → types}/types.d.ts +289 -12
  91. package/dist/utils/dynamic-variables.d.ts +38 -0
  92. package/dist/utils/expression-evaluator.d.ts +34 -0
  93. package/dist/utils/filter-engine.d.ts +47 -0
  94. package/dist/utils/helpers.d.ts +47 -0
  95. package/package.json +12 -4
  96. package/dist/container.d.ts.map +0 -1
  97. package/dist/implementations/cookie-jar.d.ts.map +0 -1
  98. package/dist/implementations/cookie-utils.d.ts.map +0 -1
  99. package/dist/implementations/data-file-parser.d.ts.map +0 -1
  100. package/dist/implementations/fetch-http-client.d.ts.map +0 -1
  101. package/dist/implementations/index.d.ts +0 -22
  102. package/dist/implementations/index.d.ts.map +0 -1
  103. package/dist/implementations/interceptor-chain.d.ts.map +0 -1
  104. package/dist/implementations/module-loader.d.ts +0 -74
  105. package/dist/implementations/module-loader.d.ts.map +0 -1
  106. package/dist/implementations/native-http-client.d.ts.map +0 -1
  107. package/dist/implementations/node-file-system.d.ts.map +0 -1
  108. package/dist/implementations/request-history.d.ts.map +0 -1
  109. package/dist/implementations/request-preprocessor.d.ts.map +0 -1
  110. package/dist/implementations/variable-interpolator.d.ts +0 -55
  111. package/dist/implementations/variable-interpolator.d.ts.map +0 -1
  112. package/dist/implementations/vm2-script-runner.d.ts +0 -76
  113. package/dist/implementations/vm2-script-runner.d.ts.map +0 -1
  114. package/dist/index.d.ts.map +0 -1
  115. package/dist/interfaces/cookie.d.ts.map +0 -1
  116. package/dist/interfaces/history.d.ts.map +0 -1
  117. package/dist/interfaces/index.d.ts +0 -170
  118. package/dist/interfaces/index.d.ts.map +0 -1
  119. package/dist/interfaces/types.d.ts.map +0 -1
  120. package/dist/parsers/http-forge-parser.d.ts.map +0 -1
  121. package/dist/parsers/index.d.ts.map +0 -1
  122. package/dist/services/collection-loader.d.ts.map +0 -1
  123. package/dist/services/environment-resolver.d.ts.map +0 -1
  124. package/dist/services/folder-collection-loader.d.ts +0 -91
  125. package/dist/services/folder-collection-loader.d.ts.map +0 -1
  126. package/dist/services/forge-env.d.ts.map +0 -1
  127. package/dist/services/index.d.ts +0 -20
  128. package/dist/services/index.d.ts.map +0 -1
  129. package/dist/services/parser-registry.d.ts.map +0 -1
  130. package/dist/services/request-executor.d.ts.map +0 -1
  131. package/dist/services/script-pipeline.d.ts +0 -43
  132. package/dist/services/script-pipeline.d.ts.map +0 -1
  133. package/dist/services/script-session.d.ts +0 -66
  134. package/dist/services/script-session.d.ts.map +0 -1
  135. package/dist/services/url-builder.d.ts.map +0 -1
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Module Loader Implementation
3
+ *
4
+ * Single Responsibility: Load custom modules from workspace for script execution
5
+ *
6
+ * Provides consistent module loading behavior across all packages:
7
+ * - VS Code Extension
8
+ * - @http-forge/standalone
9
+ * - @http-forge/playwright
10
+ *
11
+ * All packages provide module paths, resulting in identical behavior.
12
+ *
13
+ * SECURITY NOTE: This loader is designed to work within Node.js vm sandbox.
14
+ * The returned require function should ONLY be exposed within the vm context.
15
+ */
16
+ /**
17
+ * Module loader configuration options
18
+ */
19
+ export interface ModuleLoaderOptions {
20
+ /** Whether to allow loading custom modules (default: true) */
21
+ allowCustomModules?: boolean;
22
+ /** Maximum module resolution depth (prevents circular dependencies) */
23
+ maxResolveDepth?: number;
24
+ /** Output channel for logging (VS Code environment) */
25
+ outputChannel?: {
26
+ appendLine: (message: string) => void;
27
+ };
28
+ }
29
+ /**
30
+ * Create a lightweight moment.js replacement (when not available)
31
+ */
32
+ export declare function createMomentShim(): any;
33
+ /**
34
+ * Create a lightweight lodash replacement (when not available)
35
+ */
36
+ export declare function createLodashShim(): any;
37
+ /**
38
+ * ModuleLoader handles loading custom modules from the workspace's modules/ folder.
39
+ *
40
+ * Directory structure:
41
+ * ```
42
+ * http-forge-assets/modules/ ← modulePath
43
+ * ├── package.json ← Declares dependencies
44
+ * ├── global-setup.js ← Global exports injected into sandbox
45
+ * └── auth-helpers.js ← User's custom code
46
+ * ```
47
+ *
48
+ * SECURITY IMPORTANT:
49
+ * 1. The require function returned by createRequireFunction() should ONLY be used inside vm sandbox
50
+ * 2. Built-in modules are carefully whitelisted - review before adding new ones
51
+ * 3. Relative paths are restricted to modules/ directory subtree
52
+ */
53
+ export declare class ModuleLoader {
54
+ private availableModules;
55
+ private customModulesRequire?;
56
+ private globalSetupExports?;
57
+ private options;
58
+ private modulesPath;
59
+ private moduleCache;
60
+ private resolveStack;
61
+ /**
62
+ * Built-in modules with fallback loading support
63
+ */
64
+ private readonly builtinModules;
65
+ /**
66
+ * Create a new ModuleLoader
67
+ *
68
+ * @param modulePaths - Array of paths to modules directories. First valid path is used.
69
+ * @param options - Configuration options
70
+ */
71
+ constructor(modulePaths?: string[], options?: ModuleLoaderOptions);
72
+ /**
73
+ * Unified fallback module loader
74
+ */
75
+ private loadOptionalModule;
76
+ private logModuleWarning;
77
+ private getModuleInstallInstructions;
78
+ /**
79
+ * Initialize modules from the resolved path
80
+ * @returns true if successfully initialized
81
+ */
82
+ private initializeModules;
83
+ private loadAvailableModules;
84
+ private loadGlobalSetup;
85
+ /**
86
+ * Create require function for use in VM sandbox
87
+ *
88
+ * Resolution order:
89
+ * 1. Built-in modules (lodash, moment, crypto, etc.)
90
+ * 2. Relative paths (./helpers, ../utils) - restricted to modules/ directory
91
+ * 3. Workspace dependencies from modules/package.json
92
+ */
93
+ createRequireFunction(): (moduleName: string) => any;
94
+ private getModuleSuggestions;
95
+ private cacheModule;
96
+ /** Get global setup exports for sandbox injection */
97
+ getGlobalSetupExports(): Record<string, any> | undefined;
98
+ /** Check if custom modules are available */
99
+ hasCustomModules(): boolean;
100
+ /** Get list of available module names (built-ins + workspace) */
101
+ getAvailableModules(): string[];
102
+ /** Clear module cache */
103
+ clearCache(): void;
104
+ /** Get cache statistics */
105
+ getCacheStats(): {
106
+ size: number;
107
+ hits: number;
108
+ };
109
+ private logDebug;
110
+ private logError;
111
+ }
112
+ /**
113
+ * Factory function: create a pre-configured ModuleLoader instance
114
+ */
115
+ export declare function createModuleLoader(modulePaths: string[], options?: ModuleLoaderOptions): ModuleLoader;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Request Script Session
3
+ *
4
+ * Single Responsibility: Manage shared VM context between pre-request and post-response scripts
5
+ *
6
+ * This class creates a single VM sandbox that persists across both script phases,
7
+ * allowing JavaScript variables declared in pre-request to be accessible in post-response.
8
+ * This matches Postman's behavior for per-request script execution.
9
+ */
10
+ import * as vm from 'vm';
11
+ import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, PreRequestScriptContext, PreRequestScriptResult, ResponseContext } from './interfaces';
12
+ /**
13
+ * Dependencies injected from ScriptExecutor
14
+ * Interface Segregation: Only the methods needed by the session
15
+ */
16
+ export interface SessionDependencies {
17
+ createVM: (ctx: any, scriptConsole: any) => vm.Context;
18
+ createCommonContext: (context: CommonScriptContext, eventName: 'prerequest' | 'test') => any;
19
+ }
20
+ /**
21
+ * Request Script Session Implementation
22
+ *
23
+ * Manages a shared VM context for executing pre-request and post-response scripts.
24
+ * Variables declared in pre-request are accessible in post-response.
25
+ */
26
+ export declare class RequestScriptSession implements IRequestScriptSession {
27
+ private readonly deps;
28
+ private readonly initialContext;
29
+ private vmContext;
30
+ private ctx;
31
+ private modifiedRequest;
32
+ private assertions;
33
+ private consoleMessages;
34
+ private _variables;
35
+ private _collectionVariables;
36
+ private _globals;
37
+ private _sessionVariables;
38
+ private _environmentVariables;
39
+ private _nextRequest;
40
+ private _skipRequest;
41
+ private _visualizerData;
42
+ constructor(deps: SessionDependencies, initialContext: PreRequestScriptContext);
43
+ /**
44
+ * Initialize the shared VM context
45
+ */
46
+ private initializeSession;
47
+ /**
48
+ * Create shared context object that will be augmented with response data later
49
+ */
50
+ private createSharedContext;
51
+ /**
52
+ * Create request object with getters/setters for modification tracking
53
+ * Maps HTTP Forge body types to Postman modes for script API compatibility
54
+ */
55
+ private createRequestObject;
56
+ /**
57
+ * Execute pre-request scripts in the shared session
58
+ */
59
+ executePreRequest(script: string | string[]): Promise<PreRequestScriptResult>;
60
+ /**
61
+ * Execute post-response scripts in the shared session
62
+ * The response data is injected into the existing VM context
63
+ */
64
+ executePostResponse(script: string | string[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
65
+ /**
66
+ * Compare two RequestBody objects for equality
67
+ */
68
+ private bodiesEqual;
69
+ /**
70
+ * Clean up the session resources
71
+ */
72
+ dispose(): void;
73
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Script Executor
3
+ *
4
+ * Single Responsibility: Orchestrate script execution and VM configuration
5
+ * Open/Closed: Uses composition to delegate to specialized modules
6
+ * Dependency Inversion: Depends on abstractions (IRequestScriptSession, IScriptExecutor)
7
+ *
8
+ * This is the main entry point for script execution.
9
+ * It configures the VM sandbox and delegates session management to RequestScriptSession.
10
+ */
11
+ import { IHttpRequestService } from '../http/interfaces';
12
+ import { IRequestScriptSession, IScriptExecutor, PreRequestScriptContext } from './interfaces';
13
+ /**
14
+ * Script Executor Implementation
15
+ *
16
+ * Orchestrates script execution by:
17
+ * - Configuring VM sandbox with built-in libraries
18
+ * - Creating common context for variable scopes
19
+ * - Delegating session management to RequestScriptSession
20
+ */
21
+ export declare class ScriptExecutor implements IScriptExecutor {
22
+ private readonly httpService?;
23
+ private readonly moduleLoader;
24
+ constructor(httpService?: IHttpRequestService | undefined, modulePaths?: string[]);
25
+ /**
26
+ * Create a request execution session
27
+ * Factory method implementing IScriptExecutor
28
+ */
29
+ createRequestSession(context: PreRequestScriptContext): IRequestScriptSession;
30
+ /**
31
+ * Create VM context with sandbox configuration
32
+ * Returns a context object that can be used with vm.runInContext()
33
+ */
34
+ private createVM;
35
+ /**
36
+ * Create common context object for variable scopes
37
+ * Used by RequestScriptSession for pre-request and test scripts
38
+ */
39
+ private createCommonContext;
40
+ /**
41
+ * Create a basic variable scope with get/set/has/unset/clear/toObject
42
+ */
43
+ private createVariableScope;
44
+ /**
45
+ * Create merged variable scope (Postman-style cascading lookup)
46
+ */
47
+ private createMergedVariableScope;
48
+ /**
49
+ * Create environment variable scope with change callbacks
50
+ */
51
+ private createEnvironmentScope;
52
+ /**
53
+ * Create session variable scope with change callbacks
54
+ */
55
+ private createSessionScope;
56
+ /**
57
+ * Create sendRequest function using httpService
58
+ */
59
+ private createSendRequest;
60
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Script Factories
3
+ *
4
+ * Single Responsibility: Create objects used in script execution contexts
5
+ * Open/Closed: New factory methods can be added without modifying existing ones
6
+ */
7
+ import { ResponseContext } from './interfaces';
8
+ /**
9
+ * Response object interface for script context
10
+ */
11
+ export interface ScriptResponse {
12
+ status: number;
13
+ code: number;
14
+ statusText: string;
15
+ headers: Record<string, string>;
16
+ body: any;
17
+ cookies: Record<string, string>;
18
+ responseTime?: number;
19
+ responseSize?: number;
20
+ getHeader(name: string): string | undefined;
21
+ getCookie(name: string): string | undefined;
22
+ reason(): string;
23
+ json(): any;
24
+ text(): string;
25
+ cookie(name: string): string | undefined;
26
+ hasCookie(name: string): boolean;
27
+ to: ResponseAssertions;
28
+ }
29
+ /**
30
+ * Response assertion helpers (Postman-style)
31
+ * Note: be.ok/error/etc. are getters that execute assertions on property access
32
+ */
33
+ export interface ResponseAssertions {
34
+ have: {
35
+ status(expectedStatus: number): void;
36
+ header(headerName: string, expectedValue?: string): void;
37
+ body(expectedBody?: string): void;
38
+ jsonBody(expectedJson?: any): void;
39
+ };
40
+ be: {
41
+ readonly ok: any;
42
+ readonly success: any;
43
+ readonly error: any;
44
+ readonly clientError: any;
45
+ readonly serverError: any;
46
+ };
47
+ }
48
+ /**
49
+ * Create response object with helper methods for script context
50
+ * Provides Postman-compatible response API
51
+ */
52
+ export declare function createResponseObject(response: ResponseContext): ScriptResponse;
53
+ /**
54
+ * Expect chain interface for Chai-style assertions
55
+ */
56
+ export interface ExpectChain {
57
+ _value: any;
58
+ _negated: boolean;
59
+ _deep: boolean;
60
+ not: ExpectChain;
61
+ to: ExpectChain;
62
+ be: ExpectChain;
63
+ have: ExpectChain;
64
+ deep: ExpectChain;
65
+ equal(expected: any): ExpectChain;
66
+ eql(expected: any): ExpectChain;
67
+ property(name: string, value?: any): ExpectChain;
68
+ ok: ExpectChain;
69
+ exist: ExpectChain;
70
+ include(value: any): ExpectChain;
71
+ oneOf(values: any[]): ExpectChain;
72
+ match(pattern: RegExp): ExpectChain;
73
+ above(num: number): ExpectChain;
74
+ below(num: number): ExpectChain;
75
+ greaterThan(num: number): ExpectChain;
76
+ lessThan(num: number): ExpectChain;
77
+ within(start: number, end: number): ExpectChain;
78
+ a(type: string): ExpectChain;
79
+ an(type: string): ExpectChain;
80
+ true: ExpectChain;
81
+ false: ExpectChain;
82
+ null: ExpectChain;
83
+ undefined: ExpectChain;
84
+ empty: ExpectChain;
85
+ length(len: number): ExpectChain;
86
+ lengthOf(len: number): ExpectChain;
87
+ members(arr: any[]): ExpectChain;
88
+ keys(...args: any[]): ExpectChain;
89
+ string(substr: string): ExpectChain;
90
+ }
91
+ /**
92
+ * Create Chai-style expect chain for assertions
93
+ */
94
+ export declare function createExpectChain(value: any): ExpectChain;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Script Utilities
3
+ *
4
+ * Single Responsibility: Pure utility functions for script execution
5
+ * These are stateless helper functions with no side effects
6
+ */
7
+ import { TestAssertion } from '../types/types';
8
+ /**
9
+ * Console message structure for script output
10
+ */
11
+ export interface ConsoleMessage {
12
+ level: 'log' | 'info' | 'warn' | 'error';
13
+ args: any[];
14
+ }
15
+ /**
16
+ * Concatenate multiple scripts into one with clear separators
17
+ * Enables variables defined in earlier scripts to be accessible in later scripts
18
+ */
19
+ export declare function concatenateScripts(scripts: string | string[]): string;
20
+ /**
21
+ * Check if an object has changed from its original value
22
+ * Uses JSON serialization for deep comparison
23
+ */
24
+ export declare function hasChanged(current: any, original: any): boolean;
25
+ /**
26
+ * Format console messages into output strings
27
+ */
28
+ export declare function formatConsoleOutput(messages: ConsoleMessage[]): string[];
29
+ /**
30
+ * Create a script console that captures output
31
+ */
32
+ export declare function createScriptConsole(messages: ConsoleMessage[]): Console;
33
+ /**
34
+ * Create a test function that records assertions
35
+ * Supports both sync and async test functions (Postman-compatible)
36
+ */
37
+ export declare function createTestFunction(assertions: TestAssertion[]): any;
38
+ /**
39
+ * Normalize HTTP headers to Record<string, string>
40
+ * Converts multi-value headers (string[]) to comma-separated strings
41
+ */
42
+ export declare function normalizeHeaders(headers: Record<string, string | string[]>): Record<string, string>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Test Suite Services
3
+ */
4
+ export * from './interfaces';
5
+ export * from './result-storage';
6
+ export { ResultStorageService } from './result-storage-service';
7
+ export { StatisticsService } from './statistics-service';
8
+ export { TestSuiteService } from './test-suite-service';
9
+ export { TestSuiteStore } from './test-suite-store';
10
+ export type { ITestSuiteStore, SuiteRequestEntry } from './test-suite-store';
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Test Suite Interfaces
3
+ *
4
+ * Defines data structures for Test Suite functionality
5
+ */
6
+ /**
7
+ * Request reference within a Test Suite
8
+ * References a request from a Collection (not a copy)
9
+ */
10
+ export interface SuiteRequest {
11
+ /** Collection ID where the request lives */
12
+ collectionId: string;
13
+ /** Collection name for display purposes */
14
+ collectionName: string;
15
+ /** Request ID within the collection */
16
+ requestId: string;
17
+ /** Cached display info (avoid querying collection each time) */
18
+ name: string;
19
+ method: string;
20
+ folderPath: string;
21
+ /** Whether this request is enabled for execution */
22
+ enabled?: boolean;
23
+ }
24
+ /**
25
+ * Test Suite run configuration
26
+ */
27
+ export interface SuiteConfig {
28
+ /** Number of iterations to run */
29
+ iterations: number;
30
+ /** Delay between requests in milliseconds */
31
+ delayBetweenRequests: number;
32
+ /** Stop execution on first error */
33
+ stopOnError: boolean;
34
+ /** Read variables from shared session */
35
+ readFromSharedSession: boolean;
36
+ /** Write variables to shared session */
37
+ writeToSharedSession: boolean;
38
+ /** Data file path for variable injection */
39
+ dataFilePath?: string;
40
+ }
41
+ /**
42
+ * Test Suite definition
43
+ */
44
+ export interface TestSuite {
45
+ /** Unique identifier */
46
+ id: string;
47
+ /** Suite name */
48
+ name: string;
49
+ /** Optional description */
50
+ description?: string;
51
+ /** Ordered list of request references */
52
+ requests: SuiteRequest[];
53
+ /** Run configuration */
54
+ config: SuiteConfig;
55
+ /** Whether this is a temporary suite (not saved) */
56
+ isTemporary?: boolean;
57
+ /** Creation timestamp */
58
+ createdAt: number;
59
+ /** Last update timestamp */
60
+ updatedAt: number;
61
+ }
62
+ /**
63
+ * Per-request statistics
64
+ */
65
+ export interface RequestStatistics {
66
+ /** Request name */
67
+ name: string;
68
+ /** Number of executions */
69
+ count: number;
70
+ /** Number of passed executions */
71
+ passed: number;
72
+ /** Number of failed executions */
73
+ failed: number;
74
+ /** Number of skipped executions */
75
+ skipped: number;
76
+ /** Minimum response time (ms) */
77
+ min: number;
78
+ /** Maximum response time (ms) */
79
+ max: number;
80
+ /** Average response time (ms) */
81
+ avg: number;
82
+ /** 50th percentile (median) */
83
+ p50: number;
84
+ /** 90th percentile */
85
+ p90: number;
86
+ /** 95th percentile */
87
+ p95: number;
88
+ /** 99th percentile */
89
+ p99: number;
90
+ /** Raw duration data for recalculation */
91
+ durations: number[];
92
+ }
93
+ /**
94
+ * Run statistics summary
95
+ */
96
+ export interface RunSummary {
97
+ /** Total requests executed */
98
+ totalRequests: number;
99
+ /** Number of passed requests */
100
+ passed: number;
101
+ /** Number of failed requests */
102
+ failed: number;
103
+ /** Number of skipped requests */
104
+ skipped: number;
105
+ /** Pass rate percentage */
106
+ passRate: number;
107
+ /** Total duration in milliseconds */
108
+ duration: number;
109
+ /** Whether run is still in progress */
110
+ isRunning: boolean;
111
+ }
112
+ /**
113
+ * Error summary entry
114
+ */
115
+ export interface ErrorSummary {
116
+ /** Error message or status */
117
+ message: string;
118
+ /** Number of occurrences */
119
+ count: number;
120
+ }
121
+ /**
122
+ * Complete run statistics
123
+ */
124
+ export interface RunStatistics {
125
+ /** Summary statistics */
126
+ summary: RunSummary;
127
+ /** Statistics grouped by request name */
128
+ byRequest: Map<string, RequestStatistics>;
129
+ /** Overall statistics across all requests */
130
+ overall: RequestStatistics;
131
+ /** Error summary */
132
+ errors: ErrorSummary[];
133
+ }
134
+ /**
135
+ * Test Suite Service Interface
136
+ */
137
+ export interface ITestSuiteService {
138
+ createSuite(name: string, requests?: SuiteRequest[]): Promise<TestSuite>;
139
+ getSuite(id: string): Promise<TestSuite | undefined>;
140
+ getAllSuites(): Promise<TestSuite[]>;
141
+ updateSuite(suite: TestSuite): Promise<void>;
142
+ deleteSuite(id: string): Promise<boolean>;
143
+ createTempSuiteFromCollection(collectionId: string): Promise<TestSuite | undefined>;
144
+ saveTempSuite(suite: TestSuite, name: string): Promise<TestSuite>;
145
+ }
146
+ /**
147
+ * Statistics Service Interface
148
+ */
149
+ export interface IStatisticsService {
150
+ /** Add a result and update statistics */
151
+ addResult(requestName: string, duration: number, passed: boolean, skipped: boolean, error?: string): void;
152
+ /** Get current statistics */
153
+ getStatistics(): RunStatistics;
154
+ /** Reset statistics for a new run */
155
+ reset(): void;
156
+ /** Mark run as complete */
157
+ complete(): void;
158
+ /** Set start time for duration tracking */
159
+ start(): void;
160
+ }
161
+ /**
162
+ * Default suite configuration
163
+ */
164
+ export declare const DEFAULT_SUITE_CONFIG: SuiteConfig;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Result Storage Service for Test Suite
3
+ *
4
+ * Architecture (JMeter-inspired):
5
+ * - Append-only index pages for fast writes
6
+ * - Individual JSON files for full details
7
+ * - Aggregated stats in memory (constant size)
8
+ * - On-demand result loading
9
+ */
10
+ import { IConfigService } from '../config';
11
+ import { ExecutionResult } from '../types/types';
12
+ import { FullResultDetails, IndexPage, IResultStorageService, RecentError, RequestStats, ResultSummary, RunConfig, RunManifest, RunStats } from './result-storage';
13
+ /**
14
+ * File-based Result Storage Service for Test Suite
15
+ */
16
+ export declare class ResultStorageService implements IResultStorageService {
17
+ private configService;
18
+ private basePath;
19
+ private currentRunPath;
20
+ private currentRunId;
21
+ private currentSuiteId;
22
+ private currentManifest;
23
+ private currentIndexPage;
24
+ private currentPageNumber;
25
+ private readonly indexPageSize;
26
+ private recentErrors;
27
+ private readonly recentErrorsLimit;
28
+ private resultIndex;
29
+ private requestDurations;
30
+ constructor(configService: IConfigService);
31
+ /**
32
+ * Get the base path for result storage
33
+ */
34
+ getBasePath(): string;
35
+ /**
36
+ * Initialize a new run
37
+ */
38
+ initializeRun(suiteId: string, suiteName: string, environment: string, config: RunConfig): Promise<string>;
39
+ /**
40
+ * Save a request result
41
+ * Returns lightweight summary for UI
42
+ */
43
+ saveResult(iteration: number, result: ExecutionResult): Promise<ResultSummary>;
44
+ /**
45
+ * Finalize run
46
+ */
47
+ finalizeRun(status?: 'completed' | 'aborted' | 'error'): Promise<void>;
48
+ getCurrentStats(): {
49
+ stats: RunStats;
50
+ requestStats: Record<string, RequestStats>;
51
+ recentErrors: RecentError[];
52
+ } | null;
53
+ getCurrentRunId(): string | null;
54
+ getCurrentSuiteId(): string | null;
55
+ getResultDetails(suiteId: string, runId: string, resultFile: string): Promise<FullResultDetails>;
56
+ getIndexPage(suiteId: string, runId: string, page: number): Promise<IndexPage>;
57
+ getManifest(suiteId: string, runId: string): Promise<RunManifest>;
58
+ listRuns(suiteId: string): Promise<RunManifest[]>;
59
+ listSuites(): Promise<string[]>;
60
+ deleteRun(suiteId: string, runId: string): Promise<void>;
61
+ cleanupOldRuns(): Promise<{
62
+ deleted: number;
63
+ freed: number;
64
+ }>;
65
+ private generateRunId;
66
+ private saveManifest;
67
+ private writeCurrentIndexPage;
68
+ private updateStats;
69
+ private getDirectorySize;
70
+ }