@http-forge/core 1.0.2 → 1.0.4
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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +215 -769
- package/dist/index.mjs +215 -769
- package/dist/infrastructure/collection/agents-md.d.ts +6 -1
- package/dist/infrastructure/collection/folder-io.d.ts +6 -0
- package/dist/infrastructure/execution/collection-request-executor-interfaces.d.ts +5 -0
- package/dist/infrastructure/execution/collection-request-executor.d.ts +13 -0
- package/dist/infrastructure/script/interfaces.d.ts +29 -4
- package/dist/infrastructure/script/module-loader.d.ts +1 -1
- package/dist/infrastructure/script/request-script-session.d.ts +11 -10
- package/dist/infrastructure/script/script-executor.d.ts +15 -1
- package/dist/infrastructure/script/script-utils.d.ts +18 -1
- package/dist/infrastructure/test-suite/interfaces.d.ts +8 -4
- package/dist/runtime/mcp-handlers/documentation.d.ts +7 -0
- package/dist/runtime/mcp-handlers/types.d.ts +2 -0
- package/dist/runtime/mcp-tool-schemas.d.ts +2 -0
- package/dist/templates/AGENTS.md +314 -0
- package/dist/templates/http-forge-globals.d.ts +675 -0
- package/dist/templates/jsconfig.json +22 -0
- package/dist/templates/lib-package.json +26 -0
- package/dist/templates/llms.txt +23 -0
- package/dist/types/environment-config.d.ts +1 -0
- package/dist/types/types.d.ts +6 -3
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* user customizations are never silently lost.
|
|
15
15
|
*/
|
|
16
16
|
/** Current template version. Bump when `buildAgentsMdContent()` changes. */
|
|
17
|
-
export declare const AGENTS_MD_VERSION =
|
|
17
|
+
export declare const AGENTS_MD_VERSION = 6;
|
|
18
18
|
export declare const AGENTS_MD_FILENAME = "AGENTS.md";
|
|
19
19
|
export declare const AGENTS_MD_BACKUP_FILENAME = "AGENTS.md.bak";
|
|
20
20
|
/** Absolute path of the guide inside a `.http-forge/` directory. */
|
|
@@ -51,6 +51,11 @@ export declare function refreshAgentsMd(forgeDir: string): AgentsMdRefreshResult
|
|
|
51
51
|
* file was created, false when it already existed (never overwrites).
|
|
52
52
|
*/
|
|
53
53
|
export declare function ensureAgentsMdFile(forgeDir: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Ensure the supporting files that make a `.http-forge` workspace usable from
|
|
56
|
+
* VS Code are present. This is write-once: existing files are never overwritten.
|
|
57
|
+
*/
|
|
58
|
+
export declare function ensureForgeWorkspaceFiles(forgeDir: string): void;
|
|
54
59
|
/**
|
|
55
60
|
* Build the current `.http-forge/AGENTS.md` template. The file teaches AI
|
|
56
61
|
* assistants (GitHub Copilot, Claude, Cursor, …) the folder layout and schema
|
|
@@ -41,6 +41,8 @@ export declare const SCRIPTS_DIR = "scripts";
|
|
|
41
41
|
export interface ScriptsData {
|
|
42
42
|
preRequest?: string;
|
|
43
43
|
postResponse?: string;
|
|
44
|
+
preRequestPath?: string;
|
|
45
|
+
postResponsePath?: string;
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Read scripts from a scripts/ directory.
|
|
@@ -50,6 +52,10 @@ export declare function readScriptsFromDir(scriptsPath: string): ScriptsData | u
|
|
|
50
52
|
/**
|
|
51
53
|
* Write scripts to a scripts/ directory.
|
|
52
54
|
* If a script is empty/undefined, the corresponding file is deleted.
|
|
55
|
+
*
|
|
56
|
+
* The passed object is updated with the absolute file paths (and stale paths
|
|
57
|
+
* are cleared) so in-memory objects stay consistent with disk immediately
|
|
58
|
+
* after a save, mirroring `readScriptsFromDir` at load time.
|
|
53
59
|
*/
|
|
54
60
|
export declare function writeScriptsToDir(scriptsPath: string, scripts: ScriptsData): Promise<void>;
|
|
55
61
|
/**
|
|
@@ -30,6 +30,11 @@ export type ConsoleOutputCallback = (output: string[], source: ConsoleOutputSour
|
|
|
30
30
|
* pre-request/post-response script chain support.
|
|
31
31
|
*/
|
|
32
32
|
export interface ICollectionRequestExecutor {
|
|
33
|
+
/**
|
|
34
|
+
* Set the current data-file row for a data-driven run. Exposed to scripts
|
|
35
|
+
* as `pm.iterationData` and the legacy `data` object.
|
|
36
|
+
*/
|
|
37
|
+
setIterationData(iterationData: Record<string, any>): void;
|
|
33
38
|
/**
|
|
34
39
|
* Execute a request with full Postman parity.
|
|
35
40
|
*
|
|
@@ -39,6 +39,19 @@ export declare class CollectionRequestExecutor implements ICollectionRequestExec
|
|
|
39
39
|
private readonly webSocketClient?;
|
|
40
40
|
private readonly socketIoClient?;
|
|
41
41
|
constructor(httpService: IHttpRequestService, scriptExecutor: IScriptExecutor, envConfigService: IEnvironmentConfigService, requestPreparer: IRequestPreparer, environment: string, cookieJar?: ICookieJar | undefined, collectionScripts?: RequestScripts | undefined, folderScriptsChain?: (RequestScripts | RequestScripts[]) | undefined, onConsoleOutput?: ConsoleOutputCallback | undefined, collectionName?: string | undefined, collectionAuth?: RequestAuth | undefined, iteration?: number | undefined, iterationCount?: number | undefined, webSocketClient?: IWebSocketClient | undefined, socketIoClient?: ISocketIoClient | undefined);
|
|
42
|
+
private collectionVariables;
|
|
43
|
+
private iterationData;
|
|
44
|
+
/**
|
|
45
|
+
* Seed the `pm.collectionVariables` scope for this execution. Callers that
|
|
46
|
+
* own a collection should pass the collection file values plus any runtime
|
|
47
|
+
* locals so scripts can read them and unsets can be detected.
|
|
48
|
+
*/
|
|
49
|
+
setCollectionVariables(collectionVariables: Record<string, string>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Seed the `pm.iterationData` scope for data-driven runs. The row is the
|
|
52
|
+
* raw data-file row (Postman-compatible), not the merged variable context.
|
|
53
|
+
*/
|
|
54
|
+
setIterationData(iterationData: Record<string, any>): void;
|
|
42
55
|
/**
|
|
43
56
|
* Execute a request with full Postman parity.
|
|
44
57
|
*/
|
|
@@ -106,7 +106,9 @@ export interface PreRequestScriptResult {
|
|
|
106
106
|
* Globals are excluded because they are tracked separately via runtimeGlobals in createResolver,
|
|
107
107
|
* and including the session snapshot would risk shadowing a fresh value from a previous request.
|
|
108
108
|
*/
|
|
109
|
-
|
|
109
|
+
nonGlobalVariables?: Record<string, string>;
|
|
110
|
+
/** Only the request-local `pm.variables` scope writes from this script phase. */
|
|
111
|
+
requestLocalWrites?: Record<string, string>;
|
|
110
112
|
modifiedCollectionVariables?: Record<string, string>;
|
|
111
113
|
modifiedGlobals?: Record<string, string>;
|
|
112
114
|
modifiedEnvironmentVariables?: Record<string, string>;
|
|
@@ -123,7 +125,9 @@ export interface PostResponseScriptResult {
|
|
|
123
125
|
testResults: TestAssertion[];
|
|
124
126
|
consoleOutput?: string[];
|
|
125
127
|
modifiedVariables?: Record<string, string>;
|
|
126
|
-
|
|
128
|
+
nonGlobalVariables?: Record<string, string>;
|
|
129
|
+
/** Only the request-local `pm.variables` scope writes from this script phase. */
|
|
130
|
+
requestLocalWrites?: Record<string, string>;
|
|
127
131
|
modifiedEnvironmentVariables?: Record<string, string>;
|
|
128
132
|
modifiedGlobals?: Record<string, string>;
|
|
129
133
|
modifiedCollectionVariables?: Record<string, string>;
|
|
@@ -154,6 +158,27 @@ export interface IScriptExecutor {
|
|
|
154
158
|
* (Postman-compatible behavior)
|
|
155
159
|
*/
|
|
156
160
|
createRequestSession(context: PreRequestScriptContext): IRequestScriptSession;
|
|
161
|
+
/**
|
|
162
|
+
* Start a run-scoped module refresh boundary.
|
|
163
|
+
*
|
|
164
|
+
* Custom module files (and their local dependencies) are re-read from disk
|
|
165
|
+
* for the first request of a run, then cached for the remainder of that run
|
|
166
|
+
* so all requests in the run use one consistent version.
|
|
167
|
+
*/
|
|
168
|
+
beginRun?(): void;
|
|
169
|
+
/**
|
|
170
|
+
* End a run-scoped module refresh boundary.
|
|
171
|
+
*/
|
|
172
|
+
endRun?(): void;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A script segment with its source code and filename for debugging.
|
|
176
|
+
* Each segment is executed as its own `vm.Script` so file-based breakpoints
|
|
177
|
+
* resolve to the file the user opened. Inline scripts use a synthetic filename.
|
|
178
|
+
*/
|
|
179
|
+
export interface ScriptSource {
|
|
180
|
+
code: string;
|
|
181
|
+
filename: string;
|
|
157
182
|
}
|
|
158
183
|
/**
|
|
159
184
|
* Request Script Session Interface
|
|
@@ -164,11 +189,11 @@ export interface IRequestScriptSession {
|
|
|
164
189
|
/**
|
|
165
190
|
* Execute pre-request scripts in the shared session
|
|
166
191
|
*/
|
|
167
|
-
executePreRequest(script:
|
|
192
|
+
executePreRequest(script: ScriptSource | ScriptSource[]): Promise<PreRequestScriptResult>;
|
|
168
193
|
/**
|
|
169
194
|
* Update the session with response data and execute post-response scripts
|
|
170
195
|
*/
|
|
171
|
-
executePostResponse(script:
|
|
196
|
+
executePostResponse(script: ScriptSource | ScriptSource[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
|
|
172
197
|
/**
|
|
173
198
|
* Clean up the session (optional - for resource management)
|
|
174
199
|
*/
|
|
@@ -99,7 +99,7 @@ export declare class ModuleLoader {
|
|
|
99
99
|
hasCustomModules(): boolean;
|
|
100
100
|
/** Get list of available module names (built-ins + workspace) */
|
|
101
101
|
getAvailableModules(): string[];
|
|
102
|
-
/** Clear module cache */
|
|
102
|
+
/** Clear module cache and the Node require cache for this module directory */
|
|
103
103
|
clearCache(): void;
|
|
104
104
|
/** Get cache statistics */
|
|
105
105
|
getCacheStats(): {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import * as vm from 'vm';
|
|
11
11
|
import { SandboxTimers } from './async-drain';
|
|
12
|
-
import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, PreRequestScriptContext, PreRequestScriptResult, ResponseContext } from './interfaces';
|
|
12
|
+
import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, PreRequestScriptContext, PreRequestScriptResult, ResponseContext, ScriptSource } from './interfaces';
|
|
13
13
|
/**
|
|
14
14
|
* Dependencies injected from ScriptExecutor
|
|
15
15
|
* Interface Segregation: Only the methods needed by the session
|
|
@@ -39,13 +39,14 @@ export declare class RequestScriptSession implements IRequestScriptSession {
|
|
|
39
39
|
private modifiedRequest;
|
|
40
40
|
private assertions;
|
|
41
41
|
private consoleMessages;
|
|
42
|
-
private
|
|
43
|
-
private
|
|
44
|
-
private
|
|
45
|
-
private
|
|
46
|
-
private
|
|
47
|
-
private
|
|
48
|
-
private
|
|
42
|
+
private _initialVariables;
|
|
43
|
+
private _initialCollectionVariables;
|
|
44
|
+
private _initialGlobals;
|
|
45
|
+
private _initialEnvironment;
|
|
46
|
+
private _runtimeEnvironment;
|
|
47
|
+
private _runtimeGlobals;
|
|
48
|
+
private _runtimeCollectionVariables;
|
|
49
|
+
private _runtimeVariables;
|
|
49
50
|
private _nextRequest;
|
|
50
51
|
private _skipRequest;
|
|
51
52
|
private _visualizerData;
|
|
@@ -75,12 +76,12 @@ export declare class RequestScriptSession implements IRequestScriptSession {
|
|
|
75
76
|
/**
|
|
76
77
|
* Execute pre-request scripts in the shared session
|
|
77
78
|
*/
|
|
78
|
-
executePreRequest(script:
|
|
79
|
+
executePreRequest(script: ScriptSource | ScriptSource[]): Promise<PreRequestScriptResult>;
|
|
79
80
|
/**
|
|
80
81
|
* Execute post-response scripts in the shared session
|
|
81
82
|
* The response data is injected into the existing VM context
|
|
82
83
|
*/
|
|
83
|
-
executePostResponse(script:
|
|
84
|
+
executePostResponse(script: ScriptSource | ScriptSource[], responseContext: ResponseContext): Promise<PostResponseScriptResult>;
|
|
84
85
|
/**
|
|
85
86
|
* Compare two RequestBody objects for equality
|
|
86
87
|
*/
|
|
@@ -27,9 +27,23 @@ export declare class ScriptExecutor implements IScriptExecutor {
|
|
|
27
27
|
private readonly secretRegistry?;
|
|
28
28
|
private readonly scopeMode;
|
|
29
29
|
private readonly scriptTimeoutMs;
|
|
30
|
-
private readonly
|
|
30
|
+
private readonly baseModuleLoader;
|
|
31
|
+
private runModuleLoader;
|
|
32
|
+
private runDepth;
|
|
33
|
+
private readonly modulePaths;
|
|
31
34
|
private readonly variableScopes;
|
|
32
35
|
constructor(httpService?: IHttpRequestService | undefined, modulePaths?: string[], secretRegistry?: SecretResolverRegistry | undefined, scopeMode?: 'shared' | 'isolated', scriptTimeoutMs?: number);
|
|
36
|
+
/**
|
|
37
|
+
* Start a run-scoped module loader. The first beginRun() in a run creates a
|
|
38
|
+
* fresh loader (and clears cached local module files); nested calls reuse it.
|
|
39
|
+
*/
|
|
40
|
+
beginRun(): void;
|
|
41
|
+
/**
|
|
42
|
+
* End a run-scoped module loader. When the outermost run finishes, the next
|
|
43
|
+
* beginRun() will create a fresh loader.
|
|
44
|
+
*/
|
|
45
|
+
endRun(): void;
|
|
46
|
+
private get moduleLoader();
|
|
33
47
|
/**
|
|
34
48
|
* Create a request execution session
|
|
35
49
|
* Factory method implementing IScriptExecutor
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Single Responsibility: Pure utility functions for script execution
|
|
5
5
|
* These are stateless helper functions with no side effects
|
|
6
6
|
*/
|
|
7
|
-
import { TestAssertion } from '../../types/types';
|
|
7
|
+
import { RequestScripts, TestAssertion } from '../../types/types';
|
|
8
8
|
import { Cookie } from '../cookie/interfaces';
|
|
9
|
+
import type { ScriptSource } from './interfaces';
|
|
9
10
|
/**
|
|
10
11
|
* Console message structure for script output
|
|
11
12
|
*/
|
|
@@ -13,6 +14,22 @@ export interface ConsoleMessage {
|
|
|
13
14
|
level: 'log' | 'info' | 'warn' | 'error';
|
|
14
15
|
args: any[];
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert string | string[] to ScriptSource[] for execution.
|
|
19
|
+
* Inline scripts (tests, flow nodes, webview drafts) have no real file, so they
|
|
20
|
+
* get a synthetic filename; file-based callers should build ScriptSource
|
|
21
|
+
* objects with the real absolute path instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toScriptSources(script: string | string[] | undefined | null, defaultFilename: string): ScriptSource[];
|
|
24
|
+
/**
|
|
25
|
+
* Build the ScriptSource[] for one phase of a RequestScripts object.
|
|
26
|
+
*
|
|
27
|
+
* File-backed scripts carry the absolute path recorded by the loader
|
|
28
|
+
* (`preRequestPath` / `postResponsePath`), so breakpoints resolve to the file
|
|
29
|
+
* the user edited. Callers must not synthesize a filename when a real path is
|
|
30
|
+
* available; the synthetic fallback only covers inline/draft scripts.
|
|
31
|
+
*/
|
|
32
|
+
export declare function requestScriptSources(scripts: RequestScripts | undefined, phase: 'preRequest' | 'postResponse'): ScriptSource[];
|
|
16
33
|
/**
|
|
17
34
|
* Concatenate multiple scripts into one program.
|
|
18
35
|
*
|
|
@@ -108,10 +108,14 @@ export interface SuiteConfig {
|
|
|
108
108
|
delayBetweenRequests: number;
|
|
109
109
|
/** Stop execution on first error */
|
|
110
110
|
stopOnError: boolean;
|
|
111
|
-
/**
|
|
112
|
-
readFromSharedSession
|
|
113
|
-
/**
|
|
114
|
-
writeToSharedSession
|
|
111
|
+
/** @deprecated Use `loadPersistedEnvironmentValues`. Kept for backward compatibility. */
|
|
112
|
+
readFromSharedSession?: boolean;
|
|
113
|
+
/** @deprecated Use `usePersistentCookieJar`. Kept for backward compatibility. */
|
|
114
|
+
writeToSharedSession?: boolean;
|
|
115
|
+
/** Load persisted environment Current Values from previous runs */
|
|
116
|
+
loadPersistedEnvironmentValues?: boolean;
|
|
117
|
+
/** Use the persistent cookie jar across runs */
|
|
118
|
+
usePersistentCookieJar?: boolean;
|
|
115
119
|
/** Data file path for variable injection */
|
|
116
120
|
dataFilePath?: string;
|
|
117
121
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Documentation tool handlers — list and fetch HTTP Forge documentation.
|
|
3
|
+
*
|
|
4
|
+
* Lets MCP-connected AI agents discover and read the user-guide docs on demand.
|
|
5
|
+
*/
|
|
6
|
+
import type { McpToolHandler } from './types';
|
|
7
|
+
export declare const documentationHandlers: McpToolHandler[];
|
|
@@ -15,6 +15,8 @@ export interface McpDispatchServices {
|
|
|
15
15
|
environmentConfig: import('../../types/environment-config').IEnvironmentConfigService;
|
|
16
16
|
/** Absolute path to the workspace folder — used by AI-native tools. */
|
|
17
17
|
workspaceFolder?: string;
|
|
18
|
+
/** Absolute path to bundled documentation (e.g. extension resources/docs) — used by documentation tools. */
|
|
19
|
+
docsPath?: string;
|
|
18
20
|
/**
|
|
19
21
|
* Optional AI provider. When supplied, AI-flavoured tools (e.g. assertion
|
|
20
22
|
* suggestion, failure explanation) call a real LLM and fall back to their
|
|
@@ -254,6 +254,8 @@ export declare const GENERIC_TOOL_NAMES: {
|
|
|
254
254
|
readonly unsetEnvironmentVariable: "unset_environment_variable";
|
|
255
255
|
readonly setGlobalVariable: "set_global_variable";
|
|
256
256
|
readonly getGlobals: "get_globals";
|
|
257
|
+
readonly listDocumentation: "list_documentation";
|
|
258
|
+
readonly getDocumentation: "get_documentation";
|
|
257
259
|
readonly scaffoldCollectionFromOpenApi: "scaffold_collection_from_openapi";
|
|
258
260
|
readonly suggestAssertions: "suggest_assertions";
|
|
259
261
|
readonly explainFailure: "explain_failure";
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
<!-- http-forge-agents-md-version: {{VERSION}} -->
|
|
2
|
+
# HTTP Forge — AI Agent Guide
|
|
3
|
+
|
|
4
|
+
This folder is the **HTTP Forge workspace root**. Do not create a nested `.http-forge/`.
|
|
5
|
+
|
|
6
|
+
> **Copilot tip:** Add `See .http-forge/AGENTS.md for the HTTP Forge AI guide.` to `.github/copilot-instructions.md`.
|
|
7
|
+
> **Refresh:** `http-forge refresh-agents-md --apply` (backs up to `AGENTS.md.bak`).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Contents
|
|
12
|
+
|
|
13
|
+
- [Quick Reference](#quick-reference) — commands, paths, syntax, globals
|
|
14
|
+
- [Decision Tree](#decision-tree) — CLI vs MCP routing
|
|
15
|
+
- [Workflow](#workflow-design--discover--generate--edit--run--report--fix)
|
|
16
|
+
- [Folder Structure](#folder-structure)
|
|
17
|
+
- [Business Knowledge](#business-knowledge-httpforgeknowledge) / [Same-Workspace Code and Docs](#same-workspace-code-and-docs--read-before-generating)
|
|
18
|
+
- [JSON Schemas](#json-schemas)
|
|
19
|
+
- [Authoring by Direct File Editing](#authoring-by-direct-file-editing)
|
|
20
|
+
- [Test Generation Best Practices](#test-generation-best-practices)
|
|
21
|
+
- [AI Test Generation](#ai-test-generation)
|
|
22
|
+
- [Scripts & Assertions](#scripts--assertions)
|
|
23
|
+
- [Recipes](#recipes-step-by-step)
|
|
24
|
+
- [How AI Should Run Tests](#how-ai-should-run-tests)
|
|
25
|
+
- [Debugging Scripts](#debugging-scripts)
|
|
26
|
+
- [Documentation](#documentation)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quick Reference
|
|
31
|
+
|
|
32
|
+
### Most-used commands
|
|
33
|
+
```
|
|
34
|
+
http-forge run collection <name> --env <env> --json
|
|
35
|
+
http-forge run suite <name> --json
|
|
36
|
+
http-forge run request <name> --collection <ref> --json
|
|
37
|
+
http-forge discover --path <project> --output json
|
|
38
|
+
http-forge generate-suite --path <project> --collection <ref> [--run]
|
|
39
|
+
http-forge architect "intent" --apply
|
|
40
|
+
http-forge qa --path <project> --collection <ref> --base-url <url>
|
|
41
|
+
http-forge drift --path <project>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Key paths
|
|
45
|
+
```
|
|
46
|
+
assets/collections/{slug}/request.json — request definition
|
|
47
|
+
assets/collections/{slug}/scripts/*.js — pre-request / post-response scripts
|
|
48
|
+
assets/environments/{env}.json — environment variables
|
|
49
|
+
assets/suites/{name}.suite.json — test suite
|
|
50
|
+
.http-forge/knowledge/**/*.md — business context for AI
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Template syntax
|
|
54
|
+
```
|
|
55
|
+
{{variableName}} — variable
|
|
56
|
+
{{variable | upper | trim}} — filter chain
|
|
57
|
+
{{$guid}} / {{$timestamp}} — dynamic variable
|
|
58
|
+
{{variable | date:'YYYY-MM-DD'}} — filter with argument
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Script globals
|
|
62
|
+
`pm` (also `ctx`, `hf`), `request`, `response`, `responseBody`, `tests`, `postman`, `CryptoJS`, `moment`, `_` (lodash), `querystring`, `require`, `console`, `Buffer`, `URL`, `atob`/`btoa`
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Decision Tree
|
|
67
|
+
|
|
68
|
+
| Task | Approach |
|
|
69
|
+
|---|---|
|
|
70
|
+
| Discover structure | Read JSON files directly (zero token cost) |
|
|
71
|
+
| Execute request/collection/suite | CLI if installed (`http-forge run ...`), else MCP (`run_request`, etc.) |
|
|
72
|
+
| Async/long-running execution | MCP with `async: true`, poll `get_run_status` |
|
|
73
|
+
| Diagnose failures / suggest assertions | MCP `explain_failure`, `suggest_assertions` |
|
|
74
|
+
| Design new API from intent | CLI `http-forge architect` or MCP `design_api_from_intent` |
|
|
75
|
+
| Verify existing backend E2E | CLI `http-forge qa` or MCP `qa_api` |
|
|
76
|
+
| Discover endpoints from source | CLI `http-forge discover` or MCP `create_request_from_endpoint` |
|
|
77
|
+
|
|
78
|
+
**Rule:** Never use MCP/CLI to discover structure — read the JSON files directly.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Workflow: Design → Discover → Generate → Edit → Run → Report → Fix
|
|
83
|
+
|
|
84
|
+
1. **Design** — create API manually or from intent: `http-forge architect "..." --apply` / MCP `design_api_from_intent`
|
|
85
|
+
2. **Discover** — scan backend source: `http-forge discover --path <project>` / MCP `create_request_from_endpoint`
|
|
86
|
+
3. **Generate** — endpoints → requests/suites/flows: `http-forge generate-suite --path <project> --collection <ref>` / MCP `generate_test_suite`
|
|
87
|
+
4. **Edit** — refine requests, bodies, assertions, environments (direct file edit, zero token cost)
|
|
88
|
+
5. **Run** — execute: `http-forge run collection <name> --env <env> --json` / MCP `run_collection`
|
|
89
|
+
6. **Report** — inspect results: `--include report` (HTML) / MCP `get_run_summary`, `explain_failure`
|
|
90
|
+
7. **Fix** — heal assertions (`heal_assertions`), regenerate stale suites (`propose_update`), re-run
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Folder Structure
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
assets/
|
|
98
|
+
collections/{slug}/
|
|
99
|
+
collection.json (id, name, variables, auth, order)
|
|
100
|
+
scripts/ (pre-request.js, post-response.js)
|
|
101
|
+
{folder-slug}/
|
|
102
|
+
folder.json
|
|
103
|
+
{request-slug}/
|
|
104
|
+
request.json (method, url, headers, auth, body, scripts…)
|
|
105
|
+
body.json / body.txt / body.graphql
|
|
106
|
+
doc.md (business docs, fed to AI)
|
|
107
|
+
scripts/ (pre-request.js, post-response.js)
|
|
108
|
+
environments/
|
|
109
|
+
_global.json (global vars + defaultHeaders)
|
|
110
|
+
{env}.json (per-env vars)
|
|
111
|
+
{env}.local.json (gitignored overrides)
|
|
112
|
+
suites/
|
|
113
|
+
{name}.suite.json (test suite with control-flow nodes)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Business Knowledge (`.http-forge/knowledge/`)
|
|
119
|
+
|
|
120
|
+
Drop markdown files into `.http-forge/knowledge/` (any depth). All `*.md` files are loaded and included in AI prompts, along with `README.md` and `AGENTS.md`. Per-request docs can live as `doc.md` next to `request.json`.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Same-Workspace Code and Docs — Read Before Generating
|
|
125
|
+
|
|
126
|
+
Before generating tests, read the workspace for requirements:
|
|
127
|
+
1. `README.md`, `docs/**`, `openapi.*` — contracts and ACs.
|
|
128
|
+
2. `.http-forge/knowledge/**/*.md`, `doc.md` — Confluence exports, Jira ACs, ADRs.
|
|
129
|
+
3. API source code — route/controller files, DTOs, auth middleware (ground truth for paths, methods, status codes, validation rules).
|
|
130
|
+
4. Derive tests from what you read; name sources (file + AC id) in request descriptions.
|
|
131
|
+
5. When code and docs disagree, prefer implementation but flag drift to user.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## JSON Schemas
|
|
136
|
+
|
|
137
|
+
Every file has a `$schema` field. Schema base: `https://raw.githubusercontent.com/hsl1230/http-forge/main/resources/`
|
|
138
|
+
Files: `collection.schema.json`, `folder.schema.json`, `request.schema.json`, `environment.schema.json`, `global-environment.schema.json`, `suite.schema.json`
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Authoring by Direct File Editing
|
|
143
|
+
|
|
144
|
+
- **Create request:** create dir `assets/collections/{slug}/{folder}/{request}/`, write `request.json`, add slug to parent `order`.
|
|
145
|
+
- **Edit request:** read `request.json`, modify, write back. Variables: `{{name}}`. Filters: `{{value | upper}}`.
|
|
146
|
+
- **Bulk update:** find-and-replace across `assets/collections/`.
|
|
147
|
+
- **Environment:** edit `assets/environments/{env}.json`.
|
|
148
|
+
- **Suite:** write/edit `assets/suites/{name}.suite.json` (nodes: request, block, if/elseif/else, for, while, switch, script).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Test Generation Best Practices
|
|
153
|
+
|
|
154
|
+
### Collection requests (smoke)
|
|
155
|
+
- 1-2 assertions: status code + schema shape. Keep bodies minimal.
|
|
156
|
+
- Assert status first, then Content-Type, then top-level fields. No volatile fields (timestamps, IDs).
|
|
157
|
+
|
|
158
|
+
### Test suites (integration/E2E/acceptance/regression)
|
|
159
|
+
- Suites reference requests by `collectionId` + `requestId` (no duplication).
|
|
160
|
+
- **Integration/E2E (CRUD):** request nodes in sequence, pass IDs via `pm.variables`/`pm.environment`, always cleanup + verify 404.
|
|
161
|
+
- **Acceptance:** one request node per AC, full assertions on status/body/error shapes, AC ID in test name.
|
|
162
|
+
- **Regression:** block/if nodes gating by env/flag; for/while for pagination.
|
|
163
|
+
- **Sanity:** minimal status + Content-Type, health-check endpoints, <1s.
|
|
164
|
+
- **Data-driven:** iterations + CSV/JSON data file; read via `pm.iterationData.toObject()`.
|
|
165
|
+
|
|
166
|
+
### Assertion depth
|
|
167
|
+
- Collection request: status + top-level schema.
|
|
168
|
+
- Suite node: full AC verification (field values, error messages, headers).
|
|
169
|
+
- Use `pm.response.to.have.jsonSchema(...)` for contract checks.
|
|
170
|
+
|
|
171
|
+
### Naming & traceability
|
|
172
|
+
- Requests: `GET /users/:id`. Suite nodes: `1. Create user`, `2. Get user`.
|
|
173
|
+
- Store AC IDs in `description` or `doc.md`. Mark generated suites with `ai_generated: true` + `derived_from`.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## AI Test Generation
|
|
178
|
+
|
|
179
|
+
### Auto-inferable (do not ask)
|
|
180
|
+
Endpoints, schemas, auth, params, env vars, base URL, business rules (from code/docs/knowledge), test data.
|
|
181
|
+
|
|
182
|
+
### Must ask user
|
|
183
|
+
Test types, ACs (if not in code), edge-case scope, target environment, auth credentials, CI/CD context, iteration data file, scope (all or subset).
|
|
184
|
+
|
|
185
|
+
### Prompt template
|
|
186
|
+
```
|
|
187
|
+
Generate tests for [endpoint or "all discovered endpoints"].
|
|
188
|
+
Infer from code/docs: endpoints, schemas, auth, business context.
|
|
189
|
+
Confirm: 1) test types 2) environment 3) auth 4) edge cases 5) ACs 6) data file
|
|
190
|
+
Constraints: collection requests = smoke only; suites = full AC verification; mark ai_generated: true; use pm.* API only
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Scripts & Assertions
|
|
196
|
+
|
|
197
|
+
### Template
|
|
198
|
+
```javascript
|
|
199
|
+
pm.test('Status is 200', () => pm.response.to.have.status(200));
|
|
200
|
+
pm.test('Content-Type is JSON', () => pm.response.to.have.header('Content-Type', /application\/json/));
|
|
201
|
+
pm.test('Has required fields', () => {
|
|
202
|
+
const json = pm.response.json();
|
|
203
|
+
pm.expect(json).to.have.property('id');
|
|
204
|
+
pm.expect(json).to.have.property('name');
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Expect chain reference
|
|
209
|
+
- `pm.response.to.have.status(code)` — HTTP status
|
|
210
|
+
- `pm.response.to.have.header(name, value?)` — header exists/equals
|
|
211
|
+
- `pm.response.to.have.body(value?)` / `.jsonBody(value?)` / `.jsonSchema(schema)`
|
|
212
|
+
- `pm.response.to.be.ok / .success / .error / .clientError / .serverError`
|
|
213
|
+
- `pm.expect(v).to.equal(x)` / `.eql(x)` / `.have.property(n, v?)` / `.have.jsonSchema(s)`
|
|
214
|
+
- `pm.expect(v).to.be.ok / .true / .false / .null / .empty` / `.to.not...`
|
|
215
|
+
- `pm.response.responseTime` (ms), `.json()`, `.text()`, `.getHeader(name)`
|
|
216
|
+
- `pm.response.cookies.get(name)` / `.one(name)` / `.has(name)` / `.toObject()`
|
|
217
|
+
- `pm.execution.setNextRequest(name)` / `.skipRequest()` / `.runRequest(target, cb?)`
|
|
218
|
+
- `pm.visualizer.set(template, data)` / `.clear()`
|
|
219
|
+
- `pm.test(name, fn)` / `.skip()` / `.fail()` / `.index()`
|
|
220
|
+
- `pm.setNextRequest(name)` (top-level alias)
|
|
221
|
+
|
|
222
|
+
### Auth & variables
|
|
223
|
+
- `pm.environment.get/set/has/unset/clear/toObject/replaceIn`
|
|
224
|
+
- `pm.globals.*`, `pm.collectionVariables.*`, `pm.variables.*` (merged), `pm.iterationData`
|
|
225
|
+
- `pm.cookies.get/set/has/list/toObject/jar`
|
|
226
|
+
- `pm.request` (method, url, body, headers), `pm.response` (code, status, body, headers, cookies, responseTime)
|
|
227
|
+
- Legacy: `postman.setGlobalVariable()`, `postman.setEnvironmentVariable()`, `postman.getResponseHeader()`
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Recipes (step-by-step)
|
|
232
|
+
|
|
233
|
+
### Generate a collection from an OpenAPI spec
|
|
234
|
+
1. `http-forge import openapi spec.yaml --collection "My API"` (or MCP `scaffold_collection_from_openapi`)
|
|
235
|
+
2. Review generated requests in `assets/collections/{slug}/`
|
|
236
|
+
3. Run: `http-forge run collection "My API" --env dev --json`
|
|
237
|
+
|
|
238
|
+
### Generate tests for a discovered backend
|
|
239
|
+
1. `http-forge discover --path ./backend --output json` (see endpoints)
|
|
240
|
+
2. `http-forge qa --path ./backend --collection "My API" --base-url http://localhost:3000` (one-shot: discover → generate → run → report)
|
|
241
|
+
3. Or step by step: `http-forge generate-suite --path ./backend --collection "My API" --run`
|
|
242
|
+
4. Review generated suites in `assets/suites/`, refine assertions
|
|
243
|
+
|
|
244
|
+
### Generate a collection from natural language (AI)
|
|
245
|
+
1. MCP: `design_api_from_intent(intent: "I need a shopping cart with products and checkout")`
|
|
246
|
+
2. Review the designed OpenAPI spec + collection + suite
|
|
247
|
+
3. Pass `apply: true` to persist the suite and byproducts
|
|
248
|
+
4. Or CLI: `http-forge architect "I need a shopping cart" --apply`
|
|
249
|
+
|
|
250
|
+
### Create an environment
|
|
251
|
+
1. Create `assets/environments/dev.json` with `{ "name": "dev", "variables": { "baseUrl": "http://localhost:3000" } }`
|
|
252
|
+
2. Or use MCP: `create_environment(name: "dev")` then `set_environment_variable`
|
|
253
|
+
3. Use `{{baseUrl}}` in requests; reference with `--env dev`
|
|
254
|
+
|
|
255
|
+
### Write assertions for a request
|
|
256
|
+
1. Use MCP `suggest_assertions(collection, request)` for AI-generated assertions
|
|
257
|
+
2. Or write manually in `post-response.js`:
|
|
258
|
+
```javascript
|
|
259
|
+
pm.test('Status is 200', () => pm.response.to.have.status(200));
|
|
260
|
+
pm.test('Has id', () => pm.expect(pm.response.json()).to.have.property('id'));
|
|
261
|
+
```
|
|
262
|
+
3. Use `pm.response.json()` to parse, `pm.expect().to.equal()` for values
|
|
263
|
+
|
|
264
|
+
### Fix a failing request
|
|
265
|
+
1. Run: `http-forge run request <name> --collection <ref> --json`
|
|
266
|
+
2. Check status, headers, body in output
|
|
267
|
+
3. MCP: `explain_failure` for AI root-cause analysis
|
|
268
|
+
4. MCP: `heal_assertions` to auto-fix broken assertions
|
|
269
|
+
5. Fix and re-run
|
|
270
|
+
|
|
271
|
+
### Generate a test suite from discovered endpoints
|
|
272
|
+
1. `http-forge generate-suite --path ./backend --collection "My API"`
|
|
273
|
+
2. Review `assets/suites/{name}.suite.json`
|
|
274
|
+
3. Run: `http-forge run suite <name> --json`
|
|
275
|
+
4. Add assertions to request `post-response.js` files
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## How AI Should Run Tests
|
|
280
|
+
|
|
281
|
+
### Decision: CLI vs MCP
|
|
282
|
+
|
|
283
|
+
| Situation | Use |
|
|
284
|
+
|---|---|
|
|
285
|
+
| CLI installed + shell access | CLI (lower token cost) |
|
|
286
|
+
| No CLI or no shell | MCP tools |
|
|
287
|
+
| Async / long-running | MCP with `async: true`, poll `get_run_status` |
|
|
288
|
+
| Failure diagnosis / assertions | MCP `explain_failure`, `suggest_assertions` |
|
|
289
|
+
|
|
290
|
+
**Rule:** Never use MCP/CLI to discover structure — read JSON files directly.
|
|
291
|
+
|
|
292
|
+
### CLI commands
|
|
293
|
+
See Quick Reference above for the full list. Add `--include report` for HTML report. Add `--exit-code` for CI.
|
|
294
|
+
|
|
295
|
+
### MCP tools
|
|
296
|
+
- **Execution:** `run_request`, `run_folder`, `run_collection`, `run_suite` (add `async: true`)
|
|
297
|
+
- **Polling:** `get_run_status`, `get_run_summary`, `get_failed_requests`, `get_request_result`, `cancel_run`
|
|
298
|
+
- **Analysis:** `explain_failure`, `suggest_assertions`, `analyze_coverage`, `ai_analyze_coverage`
|
|
299
|
+
- **Discovery:** `create_request_from_endpoint`, `generate_test_suite`, `suggest_workflow`, `generate_workflow`, `check_drift`, `propose_update`
|
|
300
|
+
- **QA:** `qa_api`
|
|
301
|
+
- **Design:** `design_api_from_intent`
|
|
302
|
+
- **Management:** `list_collections`, `list_requests`, `get_request`, `create_request`, `update_request`, `create_suite`, `add_suite_requests`
|
|
303
|
+
|
|
304
|
+
### Reports
|
|
305
|
+
- CLI: `--include report` (HTML) or `--reporter junit` (JUnit XML)
|
|
306
|
+
- MCP: pass `include: ["report"]`, open `report.uri`
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## Documentation
|
|
311
|
+
|
|
312
|
+
Key docs: https://github.com/hsl1230/http-forge/tree/main/docs/user-guide
|
|
313
|
+
Script API types: `.http-forge/assets/http-forge-globals.d.ts`
|
|
314
|
+
|